From 97f20b36611f805e86bace671cf3ceffeb0affd6 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 22 Jan 2024 21:25:52 +0700 Subject: [PATCH] fix: Use POST for all endpoints with params (#44) * Ensure post is used for all endpoints with parameters * ci: Generate code --------- Co-authored-by: Seam Bot --- generate-routes.ts | 9 ++++++-- .../seam/connect/routes/connected-accounts.ts | 14 +++++------- .../seam/connect/routes/user-identities.ts | 15 +++++-------- src/lib/seam/connect/routes/webhooks.ts | 14 +++++------- src/lib/seam/connect/routes/workspaces.ts | 22 ++++++++----------- 5 files changed, 31 insertions(+), 43 deletions(-) diff --git a/generate-routes.ts b/generate-routes.ts index c2b22b87..01b6f260 100644 --- a/generate-routes.ts +++ b/generate-routes.ts @@ -217,8 +217,11 @@ const deriveResourceFromSchema = (properties: object): string | null => Object.keys(properties).filter((key) => key !== 'ok')[0] ?? null const deriveSemanticMethod = (methods: string[]): Method => { - if (methods.includes('get')) return 'GET' + // UPSTREAM: This should return GET before POST. + // Blocked on https://github.com/seamapi/nextlove/issues/117 + // and https://github.com/seamapi/javascript-http/issues/43 if (methods.includes('post')) return 'POST' + if (methods.includes('get')) return 'GET' throw new Error(`Could not find valid method in ${methods.join(', ')}`) } @@ -458,7 +461,9 @@ const renderRequestType = ({ pascalCase(requestFormatToRequestType(name, namespace)), ].join('') -// UPSTREAM: Should be just requestFormat, but blocked on https://github.com/seamapi/nextlove/issues/117 +// UPSTREAM: This function is a workaround, as the request type should always match the request format. +// Blocked on https://github.com/seamapi/nextlove/issues/117 +// and https://github.com/seamapi/javascript-http/issues/43 const requestFormatToRequestType = ( name: string, _namespace: string, diff --git a/src/lib/seam/connect/routes/connected-accounts.ts b/src/lib/seam/connect/routes/connected-accounts.ts index 5a8dea1b..708fb6fe 100644 --- a/src/lib/seam/connect/routes/connected-accounts.ts +++ b/src/lib/seam/connect/routes/connected-accounts.ts @@ -3,11 +3,7 @@ * Do not edit this file or add other files to this directory. */ -import type { - RouteRequestBody, - RouteRequestParams, - RouteResponse, -} from '@seamapi/types/connect' +import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' import type { SetNonNullable } from 'type-fest' import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js' @@ -156,12 +152,12 @@ export class SeamHttpConnectedAccounts { } async list( - params?: ConnectedAccountsListParams, + body?: ConnectedAccountsListParams, ): Promise { const { data } = await this.client.request({ url: '/connected_accounts/list', - method: 'get', - params, + method: 'post', + data: body, }) return data.connected_accounts @@ -201,7 +197,7 @@ export type ConnectedAccountsGetResponse = SetNonNullable< export type ConnectedAccountsGetOptions = never export type ConnectedAccountsListParams = - RouteRequestParams<'/connected_accounts/list'> + RouteRequestBody<'/connected_accounts/list'> export type ConnectedAccountsListResponse = SetNonNullable< Required> diff --git a/src/lib/seam/connect/routes/user-identities.ts b/src/lib/seam/connect/routes/user-identities.ts index 9a7b09dc..997f0525 100644 --- a/src/lib/seam/connect/routes/user-identities.ts +++ b/src/lib/seam/connect/routes/user-identities.ts @@ -3,11 +3,7 @@ * Do not edit this file or add other files to this directory. */ -import type { - RouteRequestBody, - RouteRequestParams, - RouteResponse, -} from '@seamapi/types/connect' +import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' import type { SetNonNullable } from 'type-fest' import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js' @@ -186,12 +182,12 @@ export class SeamHttpUserIdentities { } async list( - params?: UserIdentitiesListParams, + body?: UserIdentitiesListParams, ): Promise { const { data } = await this.client.request({ url: '/user_identities/list', - method: 'get', - params, + method: 'post', + data: body, }) return data.user_identities @@ -292,8 +288,7 @@ export type UserIdentitiesGrantAccessToDeviceResponse = SetNonNullable< export type UserIdentitiesGrantAccessToDeviceOptions = never -export type UserIdentitiesListParams = - RouteRequestParams<'/user_identities/list'> +export type UserIdentitiesListParams = RouteRequestBody<'/user_identities/list'> export type UserIdentitiesListResponse = SetNonNullable< Required> diff --git a/src/lib/seam/connect/routes/webhooks.ts b/src/lib/seam/connect/routes/webhooks.ts index c7850bc3..0acee508 100644 --- a/src/lib/seam/connect/routes/webhooks.ts +++ b/src/lib/seam/connect/routes/webhooks.ts @@ -3,11 +3,7 @@ * Do not edit this file or add other files to this directory. */ -import type { - RouteRequestBody, - RouteRequestParams, - RouteResponse, -} from '@seamapi/types/connect' +import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' import type { SetNonNullable } from 'type-fest' import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js' @@ -166,12 +162,12 @@ export class SeamHttpWebhooks { } async list( - params?: WebhooksListParams, + body?: WebhooksListParams, ): Promise { const { data } = await this.client.request({ url: '/webhooks/list', - method: 'get', - params, + method: 'post', + data: body, }) return data.webhooks @@ -202,7 +198,7 @@ export type WebhooksGetResponse = SetNonNullable< export type WebhooksGetOptions = never -export type WebhooksListParams = RouteRequestParams<'/webhooks/list'> +export type WebhooksListParams = RouteRequestBody<'/webhooks/list'> export type WebhooksListResponse = SetNonNullable< Required> diff --git a/src/lib/seam/connect/routes/workspaces.ts b/src/lib/seam/connect/routes/workspaces.ts index ce283b31..0838c873 100644 --- a/src/lib/seam/connect/routes/workspaces.ts +++ b/src/lib/seam/connect/routes/workspaces.ts @@ -3,11 +3,7 @@ * Do not edit this file or add other files to this directory. */ -import type { - RouteRequestBody, - RouteRequestParams, - RouteResponse, -} from '@seamapi/types/connect' +import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' import type { SetNonNullable } from 'type-fest' import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js' @@ -148,24 +144,24 @@ export class SeamHttpWorkspaces { } async get( - params?: WorkspacesGetParams, + body?: WorkspacesGetParams, ): Promise { const { data } = await this.client.request({ url: '/workspaces/get', - method: 'get', - params, + method: 'post', + data: body, }) return data.workspace } async list( - params?: WorkspacesListParams, + body?: WorkspacesListParams, ): Promise { const { data } = await this.client.request({ url: '/workspaces/list', - method: 'get', - params, + method: 'post', + data: body, }) return data.workspaces @@ -188,7 +184,7 @@ export type WorkspacesCreateResponse = SetNonNullable< export type WorkspacesCreateOptions = never -export type WorkspacesGetParams = RouteRequestParams<'/workspaces/get'> +export type WorkspacesGetParams = RouteRequestBody<'/workspaces/get'> export type WorkspacesGetResponse = SetNonNullable< Required> @@ -196,7 +192,7 @@ export type WorkspacesGetResponse = SetNonNullable< export type WorkspacesGetOptions = never -export type WorkspacesListParams = RouteRequestParams<'/workspaces/list'> +export type WorkspacesListParams = RouteRequestBody<'/workspaces/list'> export type WorkspacesListResponse = SetNonNullable< Required>