diff --git a/__tests__/gen/oauth2-verify_oauth_account_linking.test.ts b/__tests__/gen/oauth2-verify_oauth_account_linking.test.ts new file mode 100644 index 00000000..a04204a6 --- /dev/null +++ b/__tests__/gen/oauth2-verify_oauth_account_linking.test.ts @@ -0,0 +1,19 @@ +import { oauth2, ApiError } from '../../src/index.js' + +async function example() { + const response = await oauth2.verify_oauth_account_linking({ + callback_url: 'string', + token: 'string', + }) + return response +} + +describe('Testing oauth2.verify_oauth_account_linking', () => { + it('should be truthy or throw', async () => { + try { + await example() + } catch (err) { + expect(err).toBeInstanceOf(ApiError) + } + }) +}) diff --git a/kittycad.ts.patch.json b/kittycad.ts.patch.json index 41b6eb6f..cd9f9275 100644 --- a/kittycad.ts.patch.json +++ b/kittycad.ts.patch.json @@ -1047,6 +1047,14 @@ "libDocsLink": "" } }, + { + "op": "add", + "path": "/paths/~1oauth2~1verify-account-linking/get/x-typescript", + "value": { + "example": "import { oauth2, ApiError } from '@kittycad/lib'\n\nasync function example() {\n const response = await oauth2.verify_oauth_account_linking({\n callback_url: 'string',\n token: 'string',\n })\n}\n\n// Error handling\ntry {\n const res = await example()\n} catch (e) {\n if (e instanceof ApiError) {\n console.error('status', e.status, 'code', e.body?.error_code)\n console.error('message', e.body?.message)\n console.error('request_id', e.body?.request_id)\n } else {\n throw e\n }\n}\n", + "libDocsLink": "" + } + }, { "op": "add", "path": "/paths/~1oauth2~1token~1revoke/post/x-typescript", diff --git a/package-lock.json b/package-lock.json index d2e6ca1e..267935a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kittycad/lib", - "version": "3.1.43", + "version": "3.1.44", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kittycad/lib", - "version": "3.1.43", + "version": "3.1.44", "license": "MIT", "dependencies": { "bson": "^7.1.1", diff --git a/package.json b/package.json index c0b2cd08..9e79b175 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kittycad/lib", - "version": "3.1.43", + "version": "3.1.44", "description": "Javascript library for KittyCAD API", "type": "module", "keywords": [ diff --git a/spec.json b/spec.json index 82a1d227..d9053bc3 100644 --- a/spec.json +++ b/spec.json @@ -7768,6 +7768,198 @@ } } }, + "/oauth2/verify-account-linking": { + "get": { + "tags": [ + "oauth2" + ], + "summary": "Verify OAuth account linking and complete the authentication.", + "description": "This endpoint is called when a user clicks the verification link sent to their email after attempting to log in with OAuth when an existing account with the same email was found. This endpoint validates the token, links the OAuth account to the user, and creates a session.", + "operationId": "verify_oauth_account_linking", + "parameters": [ + { + "in": "query", + "name": "callback_url", + "description": "Optional callback URL to redirect to after verification", + "schema": { + "nullable": true, + "type": "string" + } + }, + { + "in": "query", + "name": "token", + "description": "The verification token from the email", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "302": { + "description": "Temporary Redirect", + "headers": { + "Access-Control-Allow-Credentials": { + "description": "Access-Control-Allow-Credentials header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Headers": { + "description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Methods": { + "description": "Access-Control-Allow-Methods header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Origin": { + "description": "Access-Control-Allow-Origin header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Content-Location": { + "description": "The Content-Location header for responses that are not the final destination. This is used to indicate where the resource can be found, when it is finished.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Location": { + "description": "The location header for redirects and letting users know if there is a websocket they can listen to for status updates on their operation.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Set-Cookie": { + "description": "Set-Cookie header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "X-Api-Call-Id": { + "description": "ID for this request. We return it so that users can report this to us and help us debug their problems.", + "style": "simple", + "required": true, + "schema": { + "type": "string" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + }, + "options": { + "tags": [ + "hidden" + ], + "summary": "OPTIONS endpoint.", + "description": "This is necessary for some preflight requests, specifically POST, PUT, and DELETE.", + "operationId": "options_verify_oauth_account_linking", + "responses": { + "204": { + "description": "resource updated", + "headers": { + "Access-Control-Allow-Credentials": { + "description": "Access-Control-Allow-Credentials header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Headers": { + "description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Methods": { + "description": "Access-Control-Allow-Methods header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Access-Control-Allow-Origin": { + "description": "Access-Control-Allow-Origin header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Content-Location": { + "description": "The Content-Location header for responses that are not the final destination. This is used to indicate where the resource can be found, when it is finished.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Location": { + "description": "The location header for redirects and letting users know if there is a websocket they can listen to for status updates on their operation.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "Set-Cookie": { + "description": "Set-Cookie header.", + "style": "simple", + "schema": { + "nullable": true, + "type": "string" + } + }, + "X-Api-Call-Id": { + "description": "ID for this request. We return it so that users can report this to us and help us debug their problems.", + "style": "simple", + "required": true, + "schema": { + "type": "string" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + } + }, "/org": { "get": { "tags": [ @@ -25600,6 +25792,13 @@ "enum": [ "tencent" ] + }, + { + "description": "Test provider for integration tests (only available during testing).", + "type": "string", + "enum": [ + "test_provider" + ] } ] }, @@ -33423,6 +33622,11 @@ } ] }, + "sketch_solve": { + "description": "To handle the transition period between sketch 1 and sketch_solve, set a flag for sketch_solve, True for sketch_solve, false for sketch 1. Defaults to false", + "default": false, + "type": "boolean" + }, "source_ranges": { "description": "The source ranges the user suggested to change. If empty, the content (prompt) will be used and is required.", "type": "array", diff --git a/src/api/oauth2/verify_oauth_account_linking.ts b/src/api/oauth2/verify_oauth_account_linking.ts new file mode 100644 index 00000000..55e6733c --- /dev/null +++ b/src/api/oauth2/verify_oauth_account_linking.ts @@ -0,0 +1,65 @@ +import { Client, buildQuery } from '../../client.js' +import { throwIfNotOk } from '../../errors.js' + +import {} from '../../models.js' + +interface VerifyOauthAccountLinkingInput { + client?: Client + callback_url?: string + token: string +} + +type VerifyOauthAccountLinkingReturn = unknown + +/** + * Verify OAuth account linking and complete the authentication. + * + * This endpoint is called when a user clicks the verification link sent to their email after attempting to log in with OAuth when an existing account with the same email was found. This endpoint validates the token, links the OAuth account to the user, and creates a session. + * + * Tags: oauth2 + * + * @param params Function parameters. + * @property {Client} [client] Optional client with auth token. + * @property {string} callback_url Optional callback URL to redirect to after verification (query) + * @property {string} token The verification token from the email (query) + * @returns {Promise} Temporary Redirect + */ +export default async function verify_oauth_account_linking({ + client, + callback_url, + token, +}: VerifyOauthAccountLinkingInput): Promise { + const path = `/oauth2/verify-account-linking` + const qs = buildQuery({ callback_url: callback_url, token: token }) + const url = path + qs + // Backwards compatible for the BASE_URL env variable + // That used to exist in only this lib, ZOO_HOST exists in the all the other + // sdks and the CLI. + const urlBase = + client?.baseUrl || + process?.env?.ZOO_HOST || + process?.env?.BASE_URL || + 'https://api.zoo.dev' + const fullUrl = urlBase + url + // The other sdks use to use KITTYCAD_API_TOKEN, now they still do for + // backwards compatibility, but the new standard is ZOO_API_TOKEN. + // For some reason only this lib supported KITTYCAD_TOKEN, so we need to + // check for that as well. + const kittycadToken = client + ? client.token || process.env.ZOO_API_TOKEN || '' + : process.env.KITTYCAD_TOKEN || + process.env.KITTYCAD_API_TOKEN || + process.env.ZOO_API_TOKEN || + '' + const headers: Record = {} + if (kittycadToken) headers.Authorization = `Bearer ${kittycadToken}` + const fetchOptions: RequestInit = { + method: 'GET', + headers, + } + const _fetch = client?.fetch || fetch + const response = await _fetch(fullUrl, fetchOptions) + await throwIfNotOk(response) + const result = (await response.json()) as VerifyOauthAccountLinkingReturn + return result +} diff --git a/src/index.ts b/src/index.ts index 8c4894d1..509cbb51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -152,6 +152,7 @@ import oauth2_provider_callback from './api/oauth2/oauth2_provider_callback.js' import oauth2_provider_callback_post from './api/oauth2/oauth2_provider_callback_post.js' import oauth2_provider_consent from './api/oauth2/oauth2_provider_consent.js' import oauth2_token_revoke from './api/oauth2/oauth2_token_revoke.js' +import verify_oauth_account_linking from './api/oauth2/verify_oauth_account_linking.js' export const oauth2 = { device_access_token, device_auth_confirm, @@ -161,6 +162,7 @@ export const oauth2 = { oauth2_provider_callback_post, oauth2_provider_consent, oauth2_token_revoke, + verify_oauth_account_linking, } import create_org from './api/orgs/create_org.js' diff --git a/src/models.ts b/src/models.ts index 05e3d045..79604272 100644 --- a/src/models.ts +++ b/src/models.ts @@ -6,6 +6,7 @@ export type AccountProvider = | 'microsoft' | 'saml' | 'tencent' + | 'test_provider' export interface AddHoleFromOffset { /** @@ -3454,6 +3455,13 @@ export type MlCopilotClientMessage = project_name?: string /** nullable:true, description:Change the default or mode reasoning effort. */ reasoning_effort?: MlReasoningEffort + /** + * { + * "default": false, + * "description": "To handle the transition period between sketch 1 and sketch_solve, set a flag for sketch_solve, True for sketch_solve, false for sketch 1. Defaults to false" + * } + */ + sketch_solve?: boolean /** The source ranges the user suggested to change. If empty, the content (prompt) will be used and is required. */ source_ranges?: SourceRangePrompt[] type: 'user'