diff --git a/src/wrapper/CollectionsClient.ts b/src/wrapper/CollectionsClient.ts deleted file mode 100644 index 3d0e425..0000000 --- a/src/wrapper/CollectionsClient.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Collections } from "../api/resources/collections/client/Client"; -import { Client as Items } from "./ItemsClient"; - -// Client adapts the base client to permit extra properties in -// the client.Collections.Items.createItem request. -export class Client extends Collections { - constructor(protected readonly _options: Collections.Options) { - super(_options); - } - - protected _items: Items | undefined; - - public get items(): Items { - return (this._items ??= new Items(this._options)); - } -} diff --git a/src/wrapper/ItemsClient.ts b/src/wrapper/ItemsClient.ts deleted file mode 100644 index e1a11ca..0000000 --- a/src/wrapper/ItemsClient.ts +++ /dev/null @@ -1,339 +0,0 @@ -import urlJoin from "url-join"; -import * as Webflow from "../api"; -import { Items } from "../api/resources/collections/resources/items/client/Client"; -import * as core from "../core"; -import * as environments from "../environments"; -import * as errors from "../errors"; -import * as serializers from "../serialization"; - -// Client adapts the base client to permit extra properties in -// the client.Collections.Items.createItem, createItemLive, and createItemForMultipleLocales request. -export class Client extends Items { - constructor(protected readonly _options: Items.Options) { - super(_options); - } - - /** - * Create Item in a Collection.

To create items across multiple locales, please use this endpoint.

Required scope | `CMS:write` - * @throws {@link Webflow.BadRequestError} - * @throws {@link Webflow.UnauthorizedError} - * @throws {@link Webflow.NotFoundError} - * @throws {@link Webflow.TooManyRequestsError} - * @throws {@link Webflow.InternalServerError} - * - * @example - * await webflow.collections.items.createItem("collection_id", { - * id: "42b720ef280c7a7a3be8cabe", - * cmsLocaleId: "653ad57de882f528b32e810e", - * lastPublished: "2022-11-29T16:22:43.159Z", - * lastUpdated: "2022-11-17T17:19:43.282Z", - * createdOn: "2022-11-17T17:11:57.148Z", - * isArchived: false, - * isDraft: false, - * fieldData: { - * name: "Pan Galactic Gargle Blaster Recipe", - * slug: "pan-galactic-gargle-blaster" - * } - * }) - */ - public async createItem( - collectionId: string, - request: Webflow.CollectionItem, - requestOptions?: Items.RequestOptions - ): Promise { - const _response = await core.fetcher({ - url: urlJoin( - (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, - `collections/${encodeURIComponent(collectionId)}/items` - ), - method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.4.2", - "User-Agent": "webflow-api/2.4.2", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - }, - contentType: "application/json", - requestType: "json", - body: serializers.CollectionItem.jsonOrThrow(request, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - }), - timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, - maxRetries: requestOptions?.maxRetries, - abortSignal: requestOptions?.abortSignal, - }); - if (_response.ok) { - return serializers.CollectionItem.parseOrThrow(_response.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }); - } - - if (_response.error.reason === "status-code") { - switch (_response.error.statusCode) { - case 400: - throw new Webflow.BadRequestError(_response.error.body); - case 401: - throw new Webflow.UnauthorizedError(_response.error.body); - case 404: - throw new Webflow.NotFoundError(_response.error.body); - case 429: - throw new Webflow.TooManyRequestsError( - serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }) - ); - case 500: - throw new Webflow.InternalServerError(_response.error.body); - default: - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - }); - } - } - - switch (_response.error.reason) { - case "non-json": - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.rawBody, - }); - case "timeout": - throw new errors.WebflowTimeoutError(); - case "unknown": - throw new errors.WebflowError({ - message: _response.error.errorMessage, - }); - } - } - - /** - * Create live Item in a Collection. This Item will be published to the live site.

To create items across multiple locales, please use this endpoint.

Required scope | `CMS:write` - * - * @param {string} collectionId - Unique identifier for a Collection - * @param {Webflow.CollectionItem} request - * @param {Items.RequestOptions} requestOptions - Request-specific configuration. - * - * @throws {@link Webflow.BadRequestError} - * @throws {@link Webflow.UnauthorizedError} - * @throws {@link Webflow.NotFoundError} - * @throws {@link Webflow.TooManyRequestsError} - * @throws {@link Webflow.InternalServerError} - * - * @example - * await client.collections.items.createItemLive("580e63fc8c9a982ac9b8b745", { - * id: "42b720ef280c7a7a3be8cabe", - * cmsLocaleId: "653ad57de882f528b32e810e", - * lastPublished: "2022-11-29T16:22:43.159Z", - * lastUpdated: "2022-11-17T17:19:43.282Z", - * createdOn: "2022-11-17T17:11:57.148Z", - * isArchived: false, - * isDraft: false, - * fieldData: { - * name: "Pan Galactic Gargle Blaster Recipe", - * slug: "pan-galactic-gargle-blaster" - * } - * }) - */ - public async createItemLive( - collectionId: string, - request: Webflow.CollectionItem, - requestOptions?: Items.RequestOptions - ): Promise { - const _response = await core.fetcher({ - url: urlJoin( - (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, - `collections/${encodeURIComponent(collectionId)}/items/live` - ), - method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.4.2", - "User-Agent": "webflow-api/2.4.2", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - }, - contentType: "application/json", - requestType: "json", - body: serializers.CollectionItem.jsonOrThrow(request, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - }), - timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, - maxRetries: requestOptions?.maxRetries, - abortSignal: requestOptions?.abortSignal, - }); - if (_response.ok) { - return serializers.CollectionItem.parseOrThrow(_response.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }); - } - - if (_response.error.reason === "status-code") { - switch (_response.error.statusCode) { - case 400: - throw new Webflow.BadRequestError(_response.error.body); - case 401: - throw new Webflow.UnauthorizedError(_response.error.body); - case 404: - throw new Webflow.NotFoundError(_response.error.body); - case 429: - throw new Webflow.TooManyRequestsError( - serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }) - ); - case 500: - throw new Webflow.InternalServerError(_response.error.body); - default: - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - }); - } - } - - switch (_response.error.reason) { - case "non-json": - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.rawBody, - }); - case "timeout": - throw new errors.WebflowTimeoutError(); - case "unknown": - throw new errors.WebflowError({ - message: _response.error.errorMessage, - }); - } - } - - /** - * Create single Item in a Collection with multiple corresponding locales.

Required scope | `CMS:write` - * - * @param {string} collectionId - Unique identifier for a Collection - * @param {Webflow.BulkCollectionItem} request - * @param {Items.RequestOptions} requestOptions - Request-specific configuration. - * - * @throws {@link Webflow.BadRequestError} - * @throws {@link Webflow.UnauthorizedError} - * @throws {@link Webflow.NotFoundError} - * @throws {@link Webflow.TooManyRequestsError} - * @throws {@link Webflow.InternalServerError} - * - * @example - * await client.collections.items.createItemForMultipleLocales("580e63fc8c9a982ac9b8b745", { - * id: "580e64008c9a982ac9b8b754" - * }) - */ - public async createItemForMultipleLocales( - collectionId: string, - request: Webflow.BulkCollectionItem, - requestOptions?: Items.RequestOptions - ): Promise { - const _response = await core.fetcher({ - url: urlJoin( - (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, - `collections/${encodeURIComponent(collectionId)}/items/bulk` - ), - method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.4.2", - "User-Agent": "webflow-api/2.4.2", - "X-Fern-Runtime": core.RUNTIME.type, - "X-Fern-Runtime-Version": core.RUNTIME.version, - }, - contentType: "application/json", - requestType: "json", - body: serializers.CollectionItem.jsonOrThrow(request, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - }), - timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, - maxRetries: requestOptions?.maxRetries, - abortSignal: requestOptions?.abortSignal, - }); - if (_response.ok) { - return serializers.BulkCollectionItem.parseOrThrow(_response.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }); - } - - if (_response.error.reason === "status-code") { - switch (_response.error.statusCode) { - case 400: - throw new Webflow.BadRequestError(_response.error.body); - case 401: - throw new Webflow.UnauthorizedError(_response.error.body); - case 404: - throw new Webflow.NotFoundError(_response.error.body); - case 429: - throw new Webflow.TooManyRequestsError( - serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - skipValidation: true, - breadcrumbsPrefix: ["response"], - }) - ); - case 500: - throw new Webflow.InternalServerError(_response.error.body); - default: - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - }); - } - } - - switch (_response.error.reason) { - case "non-json": - throw new errors.WebflowError({ - statusCode: _response.error.statusCode, - body: _response.error.rawBody, - }); - case "timeout": - throw new errors.WebflowTimeoutError(); - case "unknown": - throw new errors.WebflowError({ - message: _response.error.errorMessage, - }); - } - } -} diff --git a/src/wrapper/WebflowClient.ts b/src/wrapper/WebflowClient.ts index 3e36de7..60b4f05 100644 --- a/src/wrapper/WebflowClient.ts +++ b/src/wrapper/WebflowClient.ts @@ -1,21 +1,14 @@ import qs from "qs"; import { WebflowClient as FernClient } from "../Client"; -import { OauthScope } from "../api/types"; +import { OauthScope } from "../api/types/OAuthScope"; import * as core from "../core"; import * as errors from "../errors"; -import { Client as Collections } from "./CollectionsClient"; export class WebflowClient extends FernClient { constructor(protected readonly _options: FernClient.Options) { super(_options); } - protected _collections: Collections | undefined; - - public get collections(): Collections { - return (this._collections ??= new Collections(this._options)); - } - /** * @param clientId The OAuth client ID * @param state The state @@ -107,7 +100,9 @@ export class WebflowClient extends FernClient { body: response.error.rawBody, }); case "timeout": - throw new errors.WebflowTimeoutError(); + throw new errors.WebflowTimeoutError( + "Timeout exceeded when calling POST /oauth/token" + ); case "unknown": throw new errors.WebflowError({ message: response.error.errorMessage,