From 293456840629fe52ef37bd96f37b156a819a22ac Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:34:24 +0000 Subject: [PATCH] SDK regeneration --- .github/workflows/ci.yml | 8 +- package.json | 5 +- reference.md | 5788 +++++++++++++++++ src/Client.ts | 2 +- .../resources/accessGroups/client/Client.ts | 14 +- src/api/resources/assets/client/Client.ts | 88 +- .../resources/collections/client/Client.ts | 52 +- .../resources/fields/client/Client.ts | 28 +- .../resources/items/client/Client.ts | 170 +- .../resources/items/client/requests/index.ts | 1 - .../items/types/ItemsPublishItemResponse.ts | 8 + .../resources/items/types/index.ts | 2 +- src/api/resources/ecommerce/client/Client.ts | 14 +- src/api/resources/forms/client/Client.ts | 58 +- src/api/resources/index.ts | 3 +- src/api/resources/inventory/client/Client.ts | 26 +- src/api/resources/orders/client/Client.ts | 72 +- src/api/resources/pages/client/Client.ts | 69 +- .../client/requests/PagesGetContentRequest.ts | 4 +- .../requests/PagesGetMetadataRequest.ts | 4 +- .../pages/client/requests/PagesListRequest.ts | 4 +- .../requests/UpdatePageSettingsRequest.ts | 5 +- .../pages/resources/scripts/client/Client.ts | 34 +- src/api/resources/products/client/Client.ts | 72 +- src/api/resources/scripts/client/Client.ts | 38 +- src/api/resources/sites/client/Client.ts | 52 +- src/api/resources/sites/index.ts | 1 + .../resources/activityLogs/client/Client.ts | 14 +- .../sites/resources/scripts/client/Client.ts | 44 +- .../sites/types/SitesPublishResponse.ts | 12 + src/api/resources/sites/types/index.ts | 1 + src/api/resources/token/client/Client.ts | 16 +- src/api/resources/users/client/Client.ts | 56 +- src/api/resources/webhooks/client/Client.ts | 48 +- .../requests => types}/BulkCollectionItem.ts | 9 +- .../types/BulkCollectionItemFieldData.ts | 0 src/api/types/ConflictErrorBody.ts | 11 +- src/api/types/DuplicateUserEmail.ts | 11 +- src/api/types/MissingScopes.ts | 11 +- src/api/types/NotEnterprisePlanSite.ts | 11 +- src/api/types/Page.ts | 2 +- src/api/types/PageDetails.ts | 2 +- src/api/types/UserLimitReached.ts | 11 +- src/api/types/UsersNotEnabled.ts | 11 +- src/api/types/index.ts | 4 +- src/core/fetcher/Fetcher.ts | 205 +- src/core/fetcher/createRequestUrl.ts | 10 + src/core/fetcher/getFetchFn.ts | 25 + src/core/fetcher/getRequestBody.ts | 14 + src/core/fetcher/getResponseBody.ts | 32 + src/core/fetcher/makeRequest.ts | 44 + src/core/fetcher/requestWithRetries.ts | 21 + src/core/fetcher/signals.ts | 38 + .../Node18UniversalStreamWrapper.ts | 252 + .../stream-wrappers/NodePre18StreamWrapper.ts | 106 + .../stream-wrappers/UndiciStreamWrapper.ts | 239 + .../stream-wrappers/chooseStreamWrapper.ts | 33 + src/core/runtime/runtime.ts | 2 + src/core/schemas/Schema.ts | 12 +- src/core/schemas/builders/lazy/lazy.ts | 14 +- src/core/schemas/builders/lazy/lazyObject.ts | 4 +- src/core/schemas/builders/list/list.ts | 11 +- .../object-like/getObjectLikeUtils.ts | 4 +- src/core/schemas/builders/object/object.ts | 61 +- src/core/schemas/builders/object/types.ts | 4 +- src/core/schemas/builders/record/record.ts | 29 +- .../builders/schema-utils/getSchemaUtils.ts | 26 +- src/core/schemas/builders/set/set.ts | 8 +- .../undiscriminatedUnion.ts | 13 +- src/core/schemas/builders/union/union.ts | 19 +- src/core/schemas/utils/maybeSkipValidation.ts | 9 +- .../resources/items/client/requests/index.ts | 1 - .../items/types/ItemsPublishItemResponse.ts | 22 + .../resources/items/types/index.ts | 2 +- src/serialization/resources/index.ts | 3 +- src/serialization/resources/sites/index.ts | 1 + .../sites/types/SitesPublishResponse.ts | 23 + .../resources/sites/types/index.ts | 1 + .../requests => types}/BulkCollectionItem.ts | 14 +- .../types/BulkCollectionItemFieldData.ts | 10 +- src/serialization/types/ConflictErrorBody.ts | 19 +- src/serialization/types/DuplicateUserEmail.ts | 16 +- src/serialization/types/MissingScopes.ts | 16 +- .../types/NotEnterprisePlanSite.ts | 16 +- src/serialization/types/Page.ts | 4 +- src/serialization/types/PageDetails.ts | 4 +- src/serialization/types/UserLimitReached.ts | 16 +- src/serialization/types/UsersNotEnabled.ts | 16 +- src/serialization/types/index.ts | 4 +- tests/unit/auth/BasicAuth.test.ts | 22 + tests/unit/auth/BearerToken.test.ts | 14 + tests/unit/fetcher/Fetcher.test.ts | 25 + tests/unit/fetcher/createRequestUrl.test.ts | 51 + tests/unit/fetcher/getFetchFn.test.ts | 22 + tests/unit/fetcher/getRequestBody.test.ts | 81 + tests/unit/fetcher/getResponseBody.test.ts | 68 + tests/unit/fetcher/makeRequest.test.ts | 58 + tests/unit/fetcher/requestWithRetries.test.ts | 85 + tests/unit/fetcher/signals.test.ts | 69 + .../Node18UniversalStreamWrapper.test.ts | 178 + .../NodePre18StreamWrapper.test.ts | 124 + .../UndiciStreamWrapper.test.ts | 153 + .../chooseStreamWrapper.test.ts | 43 + tests/unit/zurg/date/date.test.ts | 31 + tests/unit/zurg/enum/enum.test.ts | 30 + tests/unit/zurg/lazy/lazy.test.ts | 57 + tests/unit/zurg/lazy/lazyObject.test.ts | 18 + tests/unit/zurg/lazy/recursive/a.ts | 7 + tests/unit/zurg/lazy/recursive/b.ts | 8 + tests/unit/zurg/list/list.test.ts | 41 + .../unit/zurg/literals/stringLiteral.test.ts | 21 + .../object-like/withParsedProperties.test.ts | 57 + tests/unit/zurg/object/extend.test.ts | 89 + tests/unit/zurg/object/object.test.ts | 255 + .../objectWithoutOptionalProperties.test.ts | 21 + tests/unit/zurg/primitives/any.test.ts | 6 + tests/unit/zurg/primitives/boolean.test.ts | 14 + tests/unit/zurg/primitives/number.test.ts | 14 + tests/unit/zurg/primitives/string.test.ts | 14 + tests/unit/zurg/primitives/unknown.test.ts | 6 + tests/unit/zurg/record/record.test.ts | 34 + .../zurg/schema-utils/getSchemaUtils.test.ts | 83 + tests/unit/zurg/schema.test.ts | 78 + tests/unit/zurg/set/set.test.ts | 48 + tests/unit/zurg/skipValidation.test.ts | 45 + .../undiscriminatedUnion.test.ts | 44 + tests/unit/zurg/union/union.test.ts | 113 + tests/unit/zurg/utils/itSchema.ts | 78 + tests/unit/zurg/utils/itValidate.ts | 56 + yarn.lock | 233 +- 130 files changed, 10004 insertions(+), 809 deletions(-) create mode 100644 reference.md create mode 100644 src/api/resources/collections/resources/items/types/ItemsPublishItemResponse.ts create mode 100644 src/api/resources/sites/types/SitesPublishResponse.ts create mode 100644 src/api/resources/sites/types/index.ts rename src/api/{resources/collections/resources/items/client/requests => types}/BulkCollectionItem.ts (68%) rename src/api/{resources/collections/resources/items => }/types/BulkCollectionItemFieldData.ts (100%) create mode 100644 src/core/fetcher/createRequestUrl.ts create mode 100644 src/core/fetcher/getFetchFn.ts create mode 100644 src/core/fetcher/getRequestBody.ts create mode 100644 src/core/fetcher/getResponseBody.ts create mode 100644 src/core/fetcher/makeRequest.ts create mode 100644 src/core/fetcher/requestWithRetries.ts create mode 100644 src/core/fetcher/signals.ts create mode 100644 src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts create mode 100644 src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts create mode 100644 src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts create mode 100644 src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts create mode 100644 src/serialization/resources/collections/resources/items/types/ItemsPublishItemResponse.ts create mode 100644 src/serialization/resources/sites/types/SitesPublishResponse.ts create mode 100644 src/serialization/resources/sites/types/index.ts rename src/serialization/{resources/collections/resources/items/client/requests => types}/BulkCollectionItem.ts (69%) rename src/serialization/{resources/collections/resources/items => }/types/BulkCollectionItemFieldData.ts (61%) create mode 100644 tests/unit/auth/BasicAuth.test.ts create mode 100644 tests/unit/auth/BearerToken.test.ts create mode 100644 tests/unit/fetcher/Fetcher.test.ts create mode 100644 tests/unit/fetcher/createRequestUrl.test.ts create mode 100644 tests/unit/fetcher/getFetchFn.test.ts create mode 100644 tests/unit/fetcher/getRequestBody.test.ts create mode 100644 tests/unit/fetcher/getResponseBody.test.ts create mode 100644 tests/unit/fetcher/makeRequest.test.ts create mode 100644 tests/unit/fetcher/requestWithRetries.test.ts create mode 100644 tests/unit/fetcher/signals.test.ts create mode 100644 tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts create mode 100644 tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts create mode 100644 tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts create mode 100644 tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts create mode 100644 tests/unit/zurg/date/date.test.ts create mode 100644 tests/unit/zurg/enum/enum.test.ts create mode 100644 tests/unit/zurg/lazy/lazy.test.ts create mode 100644 tests/unit/zurg/lazy/lazyObject.test.ts create mode 100644 tests/unit/zurg/lazy/recursive/a.ts create mode 100644 tests/unit/zurg/lazy/recursive/b.ts create mode 100644 tests/unit/zurg/list/list.test.ts create mode 100644 tests/unit/zurg/literals/stringLiteral.test.ts create mode 100644 tests/unit/zurg/object-like/withParsedProperties.test.ts create mode 100644 tests/unit/zurg/object/extend.test.ts create mode 100644 tests/unit/zurg/object/object.test.ts create mode 100644 tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts create mode 100644 tests/unit/zurg/primitives/any.test.ts create mode 100644 tests/unit/zurg/primitives/boolean.test.ts create mode 100644 tests/unit/zurg/primitives/number.test.ts create mode 100644 tests/unit/zurg/primitives/string.test.ts create mode 100644 tests/unit/zurg/primitives/unknown.test.ts create mode 100644 tests/unit/zurg/record/record.test.ts create mode 100644 tests/unit/zurg/schema-utils/getSchemaUtils.test.ts create mode 100644 tests/unit/zurg/schema.test.ts create mode 100644 tests/unit/zurg/set/set.test.ts create mode 100644 tests/unit/zurg/skipValidation.test.ts create mode 100644 tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts create mode 100644 tests/unit/zurg/union/union.test.ts create mode 100644 tests/unit/zurg/utils/itSchema.ts create mode 100644 tests/unit/zurg/utils/itValidate.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73509065..1a55fdb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,12 @@ jobs: - name: Publish to npm run: | npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} - npm publish --access public + if [[ ${GITHUB_REF} == *alpha* ]]; then + npm publish --access public --tag alpha + elif [[ ${GITHUB_REF} == *beta* ]]; then + npm publish --access public --tag beta + else + npm publish --access public + fi env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index a6b1ef49..ca120627 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webflow-api", - "version": "2.3.6", + "version": "2.3.7", "private": false, "repository": "https://github.com/webflow/js-webflow-api", "main": "./index.js", @@ -13,7 +13,7 @@ }, "dependencies": { "url-join": "4.0.1", - "form-data": "4.0.0", + "form-data": "^4.0.0", "formdata-node": "^6.0.3", "node-fetch": "2.7.0", "qs": "6.11.2", @@ -23,6 +23,7 @@ "@types/url-join": "4.0.1", "@types/qs": "6.9.8", "@types/node-fetch": "2.6.9", + "fetch-mock-jest": "^1.5.1", "jest": "29.7.0", "@types/jest": "29.5.5", "ts-jest": "29.1.1", diff --git a/reference.md b/reference.md new file mode 100644 index 00000000..a192e6f5 --- /dev/null +++ b/reference.md @@ -0,0 +1,5788 @@ +# Reference + +## Token + +
client.token.authorizedBy() -> Webflow.AuthorizedUser +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Information about the Authorized User

Required Scope | `authorized_user:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.token.authorizedBy(); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**requestOptions:** `Token.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.token.introspect() -> Webflow.Authorization +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Information about the authorization token
Access to this endpoint requires a bearer token from a Data Client App.
+ +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.token.introspect(); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**requestOptions:** `Token.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Sites + +
client.sites.list() -> Webflow.Sites +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of all sites the provided access token is able to access.

Required scope | `sites:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.list(); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**requestOptions:** `Sites.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.get(siteId) -> Webflow.Site +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a site by site id

Required scope | `sites:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.get("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Sites.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.getCustomDomain(siteId) -> Webflow.Domains +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a list of all custom domains related to site.

Required scope | `sites:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.getCustomDomain("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Sites.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.publish(siteId, { ...params }) -> Webflow.SitesPublishResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Publish a site to one more more domains.

Required scope | `sites:write`

📘

Endpoint-specific rate limit

This endpoint has a limit of one successful publish queue per minute.

+ +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.publish("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.SitesPublishRequest` + +
+
+ +
+
+ +**requestOptions:** `Sites.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Sites ActivityLogs + +
client.sites.activityLogs.list(siteId, { ...params }) -> Webflow.SiteActivityLogResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieve Activity Logs for a specific Site. Requires Site to be on an Enterprise plan.

Required scope | `site_activity:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.activityLogs.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.sites.ActivityLogsListRequest` + +
+
+ +
+
+ +**requestOptions:** `ActivityLogs.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Collections + +
client.collections.list(siteId) -> Webflow.CollectionList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of all Collections within a Site.

Required scope | `cms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Collections.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.create(siteId, { ...params }) -> Webflow.Collection +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create a Collection for a site.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.create("580e63e98c9a982ac9b8b741", { + displayName: "Blog Posts", + singularName: "Blog Post", + slug: "posts", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.CollectionsCreateRequest` + +
+
+ +
+
+ +**requestOptions:** `Collections.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.get(collectionId) -> Webflow.Collection +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get the full details of a collection from its ID.

Required scope | `cms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.get("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**requestOptions:** `Collections.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.deleteCollection(collectionId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete a collection using its ID.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.deleteCollection("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**requestOptions:** `Collections.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.delete(collectionId, fieldId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete a custom field in a collection. This endpoint does not currently support bulk deletion.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.delete("580e63fc8c9a982ac9b8b745", "580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**fieldId:** `string` — Unique identifier for a Field in a collection + +
+
+ +
+
+ +**requestOptions:** `Collections.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Collections Fields + +
client.collections.fields.create(collectionId, { ...params }) -> Webflow.Field +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create a custom field in a collection.

Slugs must be all lowercase letters without spaces. If you pass a string with uppercase letters and/or spaces to the "Slug" property, Webflow will convert the slug to lowercase and replace spaces with "-."

Only some field types can be created through the API. This endpoint does not currently support bulk creation.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.fields.create("580e63fc8c9a982ac9b8b745", { + isRequired: false, + type: Webflow.FieldCreateType.RichText, + displayName: "Post Body", + helpText: "Add the body of your post here", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.collections.FieldCreate` + +
+
+ +
+
+ +**requestOptions:** `Fields.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.fields.update(collectionId, fieldId, { ...params }) -> Webflow.Field +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update a custom field in a collection.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.fields.update("580e63fc8c9a982ac9b8b745", "580e63fc8c9a982ac9b8b745", { + isRequired: false, + displayName: "Post Body", + helpText: "Add the body of your post here", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**fieldId:** `string` — Unique identifier for a Field in a collection + +
+
+ +
+
+ +**request:** `Webflow.collections.FieldUpdate` + +
+
+ +
+
+ +**requestOptions:** `Fields.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Collections Items + +
client.collections.items.listItems(collectionId, { ...params }) -> Webflow.CollectionItemList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of all Items within a Collection.

Required scope | `CMS:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.listItems("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsListItemsRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.createItem(collectionId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ + Create Item in a Collection.

To create items across multiple locales, please use the bulk item endpoint.

Required scope | CMS:write +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.createItem("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", + }, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.CollectionItem` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.listItemsLive(collectionId, { ...params }) -> Webflow.CollectionItemList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of all live Items within a Collection.

Required scope | `CMS:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.listItemsLive("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsListItemsLiveRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.createItemLive(collectionId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +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` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +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", + }, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.CollectionItem` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.createItemForMultipleLocales(collectionId, { ...params }) -> Webflow.BulkCollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create single Item in a Collection with multiple corresponding locales.

Required scope | `CMS:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.createItemForMultipleLocales("580e63fc8c9a982ac9b8b745", { + id: "580e64008c9a982ac9b8b754", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.BulkCollectionItem` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.getItem(collectionId, itemId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get details of a selected Collection Item.

Required scope | `CMS:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.getItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsGetItemRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.deleteItem(collectionId, itemId, { ...params }) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete an Item from a Collection. This endpoint does not currently support bulk deletion.

Required scope | `CMS:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.deleteItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsDeleteItemRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.updateItem(collectionId, itemId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update a selected Item in a Collection.

Required scope | `CMS:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.updateItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { + 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", + }, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.CollectionItem` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.getItemLive(collectionId, itemId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get details of a selected Collection live Item.

Required scope | `CMS:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.getItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsGetItemLiveRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.deleteItemLive(collectionId, itemId, { ...params }) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Remove a live item from the site. Removing a published item will unpublish the item from the live site and set it to draft. This endpoint does not currently support bulk deletion.

Required scope | `CMS:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.deleteItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsDeleteItemLiveRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.updateItemLive(collectionId, itemId, { ...params }) -> Webflow.CollectionItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update a selected live Item in a Collection. The updates for this Item will be published to the live site.

Required scope | `CMS:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.updateItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { + 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", + }, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.CollectionItem` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.collections.items.publishItem(collectionId, { ...params }) -> Webflow.ItemsPublishItemResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Publish an item or multiple items.

Required scope | `cms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.collections.items.publishItem("580e63fc8c9a982ac9b8b745", { + itemIds: ["itemIds"], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**request:** `Webflow.collections.ItemsPublishItemRequest` + +
+
+ +
+
+ +**requestOptions:** `Items.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Pages + +
client.pages.list(siteId, { ...params }) -> Webflow.PageList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of all pages for a site

Required scope | `pages:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.list("580e63e98c9a982ac9b8b741", { + locale: "65427cf400e02b306eaa04a0", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.PagesListRequest` + +
+
+ +
+
+ +**requestOptions:** `Pages.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.getMetadata(pageId, { ...params }) -> Webflow.PageDetails +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get metadata information for a single page

Required scope | `pages:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.getMetadata("63c720f9347c2139b248e552", { + locale: "65427cf400e02b306eaa04a0", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**request:** `Webflow.PagesGetMetadataRequest` + +
+
+ +
+
+ +**requestOptions:** `Pages.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.updatePageSettings(pageId, { ...params }) -> Webflow.PageDetails +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update Page-level metadata, including SEO and Open Graph fields.

Required scope | `pages:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.updatePageSettings("63c720f9347c2139b248e552", { + locale: "65427cf400e02b306eaa04a0", + body: { + id: "6596da6045e56dee495bcbba", + siteId: "6258612d1ee792848f805dcf", + title: "Guide to the Galaxy", + slug: "guide-to-the-galaxy", + parentId: "6419db964a9c435aa3af6251", + collectionId: "6390c49774a71f12831a08e3", + createdOn: "2024-03-11T10:42:00Z", + lastUpdated: "2024-03-11T10:42:42Z", + archived: false, + draft: false, + canBranch: true, + seo: { + title: "The Ultimate Hitchhiker's Guide to the Galaxy", + description: + "Everything you need to know about the galaxy, from avoiding Vogon poetry to the importance of towels.", + }, + openGraph: { + title: "Explore the Cosmos with The Ultimate Guide", + titleCopied: false, + description: "Dive deep into the mysteries of the universe with your guide to everything galactic.", + descriptionCopied: false, + }, + }, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**request:** `Webflow.UpdatePageSettingsRequest` + +
+
+ +
+
+ +**requestOptions:** `Pages.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.getContent(pageId, { ...params }) -> Webflow.Dom +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get static content from a static page.
If you do not provide a Locale ID in your request, the response will return any content that can be localized from the Primary locale

Required scope | `pages:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.getContent("63c720f9347c2139b248e552", { + locale: "65427cf400e02b306eaa04a0", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**request:** `Webflow.PagesGetContentRequest` + +
+
+ +
+
+ +**requestOptions:** `Pages.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.updateStaticContent(pageId, { ...params }) -> Webflow.UpdateStaticContentResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +This endpoint allows for updating static content on a static page within a secondary locale. It is designed specifically for localized pages and can handle up to 1000 nodes per request. + +

Note:This endpoint is specifically for localized pages. Ensure that the locale specified is a valid secondary locale for the site.

+ +Required scope | `pages:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.updateStaticContent("63c720f9347c2139b248e552", { + locale: "locale", + nodes: [ + { + nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad623", + text: "

The Hitchhiker's Guide to the Galaxy

", + }, + { + nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad627", + text: "

Don't Panic!

Always know where your towel is.

", + }, + { + nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad629", + text: "Marvin, the Paranoid Android", + }, + ], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**request:** `Webflow.DomWrite` + +
+
+ +
+
+ +**requestOptions:** `Pages.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Pages Scripts + +
client.pages.scripts.getCustomCode(pageId) -> Webflow.ScriptApplyList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get all registered scripts that have been applied to a specific Page.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.scripts.getCustomCode("63c720f9347c2139b248e552"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.scripts.upsertCustomCode(pageId, { ...params }) -> Webflow.ScriptApplyList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Add a registered script to a Page.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.scripts.upsertCustomCode("63c720f9347c2139b248e552", { + scripts: [ + { + id: "cms_slider", + location: Webflow.ScriptApplyLocation.Header, + version: "1.0.0", + attributes: { + "my-attribute": "some-value", + }, + }, + { + id: "alert", + location: Webflow.ScriptApplyLocation.Header, + version: "0.0.1", + }, + ], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**request:** `Webflow.ScriptApplyList` + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.pages.scripts.deleteCustomCode(pageId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete the custom code block that an app has created for a page

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.pages.scripts.deleteCustomCode("63c720f9347c2139b248e552"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**pageId:** `string` — Unique identifier for a Page + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Sites Scripts + +
client.sites.scripts.getCustomCode(siteId) -> Webflow.ScriptApplyList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get all registered scripts that have been applied to a specific Site.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.scripts.getCustomCode("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.scripts.upsertCustomCode(siteId, { ...params }) -> Webflow.ScriptApplyList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Add a registered script to a Site.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.scripts.upsertCustomCode("580e63e98c9a982ac9b8b741", { + scripts: [ + { + id: "cms_slider", + location: Webflow.ScriptApplyLocation.Header, + version: "1.0.0", + attributes: { + "my-attribute": "some-value", + }, + }, + { + id: "alert", + location: Webflow.ScriptApplyLocation.Header, + version: "0.0.1", + }, + ], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.ScriptApplyList` + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.scripts.deleteCustomCode(siteId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete the custom code block that an app created for a Site

Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.scripts.deleteCustomCode("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.sites.scripts.listCustomCodeBlocks(siteId, { ...params }) -> Webflow.ListCustomCodeBlocks +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get all instances of Custom Code applied to a Site or Pages.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.sites.scripts.listCustomCodeBlocks("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.sites.ScriptsListCustomCodeBlocksRequest` + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Scripts + +
client.scripts.list(siteId) -> Webflow.RegisteredScriptList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List of scripts registered to a Site.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints. Additionally, Scripts can be remotely hosted, or registered as inline snippets.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.scripts.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.scripts.registerHosted(siteId, { ...params }) -> Webflow.CustomCodeHostedResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Add a script to a Site's Custom Code registry.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints. Additionally, Scripts can be remotely hosted, or registered as inline snippets.
Access to this endpoint requires a bearer token from a Data Client App.


Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.scripts.registerHosted("580e63e98c9a982ac9b8b741", { + hostedLocation: "hostedLocation", + integrityHash: "integrityHash", + version: "version", + displayName: "displayName", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.CustomCodeHostedRequest` + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.scripts.registerInline(siteId, { ...params }) -> Webflow.CustomCodeInlineResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Add a script to a Site's Custom Code registry. Inline scripts can be between 1 and 2000 characters.

In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints.

Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `custom_code:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.scripts.registerInline("580e63e98c9a982ac9b8b741", { + sourceCode: "alert('hello world');", + version: "0.0.1", + displayName: "Alert", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.CustomCodeInlineRequest` + +
+
+ +
+
+ +**requestOptions:** `Scripts.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Assets + +
client.assets.list(siteId) -> Webflow.Assets +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List assets for a given site

Required scope | `assets:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.create(siteId, { ...params }) -> Webflow.AssetUpload +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create a new asset entry.

This endpoint generates a response with the following information: `uploadUrl` and `uploadDetails`. You can use these two properties to [upload the file to Amazon s3 by making a POST](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html) request to the `uploadUrl` with the `uploadDetails` object as your header information in the request.

Required scope | `assets:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.create("580e63e98c9a982ac9b8b741", { + fileName: "file.png", + fileHash: "3c7d87c9575702bc3b1e991f4d3c638e", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.AssetsCreateRequest` + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.get(assetId) -> Webflow.Asset +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get an Asset

Required scope | `assets:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.get("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**assetId:** `string` — Unique identifier for an Asset on a site + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.delete(assetId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete an Asset + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.delete("580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**assetId:** `string` — Unique identifier for an Asset on a site + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.update(assetId, { ...params }) -> Webflow.Asset +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update an Asset

Required scope | `assets:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.update("580e63fc8c9a982ac9b8b745", { + displayName: "bulldoze.png", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**assetId:** `string` — Unique identifier for an Asset on a site + +
+
+ +
+
+ +**request:** `Webflow.AssetsUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.listFolders(siteId) -> Webflow.AssetFolderList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List Asset Folders within a given site

Required scope | `assets:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.listFolders("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.createFolder(siteId, { ...params }) -> Webflow.AssetFolder +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create an Asset Folder within a given site

Required scope | `assets:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.createFolder("580e63e98c9a982ac9b8b741", { + displayName: "my asset folder", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.AssetsCreateFolderRequest` + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.assets.getFolder(assetFolderId) -> Webflow.AssetFolder +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get details about a specific Asset Folder

Required scope | `assets:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.assets.getFolder("6390c49774a71f0e3c1a08ee"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**assetFolderId:** `string` — Unique identifier for an Asset Folder + +
+
+ +
+
+ +**requestOptions:** `Assets.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Webhooks + +
client.webhooks.list(siteId) -> Webflow.WebhookList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List all App-created Webhooks registered for a given site

Required scope | `sites:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.webhooks.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Webhooks.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.webhooks.create(siteId, { ...params }) -> Webflow.Webhook +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create a new Webhook, to be notified when Webflow resources change. Limit of 75 registrations per `triggerType`, per site.
Access to this endpoint requires a bearer token from a Data Client App.
Required scope | `sites:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.webhooks.create("580e63e98c9a982ac9b8b741", { + id: "582266e0cd48de0f0e3c6d8b", + triggerType: Webflow.TriggerType.FormSubmission, + url: "https://webhook.site/7f7f7f7f-7f7f-7f7f-7f7f-7f7f7f7f7f7f", + workspaceId: "4f4e46fd476ea8c507000001", + siteId: "562ac0395358780a1f5e6fbd", + lastTriggered: "2023-02-08T23:59:28Z", + createdOn: "2022-11-08T23:59:28Z", +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.Webhook` + +
+
+ +
+
+ +**requestOptions:** `Webhooks.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.webhooks.get(webhookId) -> Webflow.Webhook +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a specific Webhook instance + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.webhooks.get("580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**webhookId:** `string` — Unique identifier for a Webhook + +
+
+ +
+
+ +**requestOptions:** `Webhooks.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.webhooks.delete(webhookId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Remove a Webhook + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.webhooks.delete("580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**webhookId:** `string` — Unique identifier for a Webhook + +
+
+ +
+
+ +**requestOptions:** `Webhooks.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Forms + +
client.forms.list(siteId, { ...params }) -> Webflow.FormList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List forms for a given site

Required scope | `forms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.forms.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.FormsListRequest` + +
+
+ +
+
+ +**requestOptions:** `Forms.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.forms.get(formId) -> Webflow.Form +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get information about a given form

Required scope | `forms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.forms.get("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**formId:** `string` — Unique identifier for a Form + +
+
+ +
+
+ +**requestOptions:** `Forms.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.forms.listSubmissions(formId, { ...params }) -> Webflow.FormSubmissionList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List form submissions for a given form

Required scope | `forms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.forms.listSubmissions("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**formId:** `string` — Unique identifier for a Form + +
+
+ +
+
+ +**request:** `Webflow.FormsListSubmissionsRequest` + +
+
+ +
+
+ +**requestOptions:** `Forms.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.forms.getSubmission(formSubmissionId) -> Webflow.FormSubmission +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get information about a given form submission

Required scope | `forms:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.forms.getSubmission("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**formSubmissionId:** `string` — Unique identifier for a Form Submission + +
+
+ +
+
+ +**requestOptions:** `Forms.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.forms.updateSubmission(formSubmissionId, { ...params }) -> Webflow.FormSubmission +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update hidden fields on a form submission

Required scope | `forms:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.forms.updateSubmission("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**formSubmissionId:** `string` — Unique identifier for a Form Submission + +
+
+ +
+
+ +**request:** `Webflow.FormsUpdateSubmissionRequest` + +
+
+ +
+
+ +**requestOptions:** `Forms.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Users + +
client.users.list(siteId, { ...params }) -> Webflow.UserList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a list of users for a site

Required scope | `users:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.users.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.UsersListRequest` + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.users.get(siteId, userId) -> Webflow.User +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a User by ID

Required scope | `users:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.users.get("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**userId:** `string` — Unique identifier for a User + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.users.delete(siteId, userId) -> void +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Delete a User by ID

Required scope | `users:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.users.delete("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**userId:** `string` — Unique identifier for a User + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.users.update(siteId, userId, { ...params }) -> Webflow.User +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Update a User by ID

Required scope | `users:write` + + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.users.update("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741", { + data: { + name: "Some One", + acceptPrivacy: false, + acceptCommunications: false, + }, + accessGroups: ["webflowers", "platinum", "free-tier"], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**userId:** `string` — Unique identifier for a User + +
+
+ +
+
+ +**request:** `Webflow.UsersUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.users.invite(siteId, { ...params }) -> Webflow.User +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create and invite a user with an email address. The user will be sent and invite via email, which they will need to accept in order to join paid Access Groups.

Required scope | `users:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.users.invite("580e63e98c9a982ac9b8b741", { + email: "some.one@home.com", + accessGroups: ["webflowers"], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.UsersInviteRequest` + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+ +## AccessGroups + +
client.accessGroups.list(siteId, { ...params }) -> Webflow.AccessGroupList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Get a list of access groups for a site

Required scope | `users:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.accessGroups.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.AccessGroupsListRequest` + +
+
+ +
+
+ +**requestOptions:** `AccessGroups.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Products + +
client.products.list(siteId, { ...params }) -> Webflow.ProductAndSkUsList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieve all products for a site. Use `limit` and `offset` to page through all products with subsequent requests. All SKUs for each product will also be fetched and returned. The `limit`, `offset` and `total` values represent Products only and do not include any SKUs. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.ProductsListRequest` + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.products.create(siteId, { ...params }) -> Webflow.ProductAndSkUs +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Creating a new Product involves creating both a Product and a SKU, since a Product Item has to have, at minimum, a single SKU. + +In order to create a Product with multiple SKUs - for example a T-shirt in sizes small, medium and large - you'll need to create `sku-properties`. In our T-shirt example, a single `sku-property` would be Color. Within that property, we'll need to list out the various colors a T-shirt could be as an array of `enum` values: `royal-blue`, `crimson-red`, and `forrest-green`. + +Once, you've created a Product and its `sku-properties` with `enum` values, you can create your default SKU, which will automatically be a combination of the first `sku-properties` you've created. In our example, the default SKU will be a Royal Blue T-Shirt, because our first `enum` of our Color `sku-property` is Royal Blue. After you've created your product, you can create additional SKUs using the Create SKU endpoint + +Upon creation, the default product type will be `Advanced`. The product type is used to determine which Product and SKU fields are shown to users in the `Designer` and the `Editor`. Setting it to `Advanced` ensures that all Product and SKU fields will be shown. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.create("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.ProductSkuCreate` + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.products.get(siteId, productId) -> Webflow.ProductAndSkUs +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieve a single product by its id. All of its SKUs will also be retrieved. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.get("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**productId:** `string` — Unique identifier for a Product + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.products.update(siteId, productId, { ...params }) -> Webflow.Product +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Updating an existing Product will set the product type to `Advanced`. The product type is used to determine which Product and SKU fields are shown to users in the `Designer` and the `Editor`. Setting it to `Advanced` ensures that all Product and SKU fields will be shown. The product type can be edited in the `Designer` or the `Editor`. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.update("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**productId:** `string` — Unique identifier for a Product + +
+
+ +
+
+ +**request:** `Webflow.ProductSkuUpdate` + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.products.createSku(siteId, productId, { ...params }) -> Webflow.ProductsCreateSkuResponse +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Create additional SKUs to cover every variant of your Product. The Default SKU already counts as one of the variants. + +Creating additional SKUs will set the product type to `Advanced` for the product associated with the SKUs. The product type is used to determine which Product and SKU fields are shown to users in the `Designer` and the `Editor`. Setting it to `Advanced` ensures that all Product and SKU fields will be shown. The product type can be edited in the `Designer` or the `Editor`. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.createSku("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", { + skus: [{}], +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**productId:** `string` — Unique identifier for a Product + +
+
+ +
+
+ +**request:** `Webflow.ProductsCreateSkuRequest` + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.products.updateSku(siteId, productId, skuId, { ...params }) -> Webflow.Sku +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Updating an existing SKU will set the product type to `Advanced` for the product associated with the SKU. The product type is used to determine which Product and SKU fields are shown to users in the `Designer` and the `Editor`. Setting it to `Advanced` ensures that all Product and SKU fields will be shown. The product type can be edited in the `Designer` or the `Editor`. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.products.updateSku("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", "5e8518516e147040726cc415", { + sku: {}, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**productId:** `string` — Unique identifier for a Product + +
+
+ +
+
+ +**skuId:** `string` — Unique identifier for a SKU + +
+
+ +
+
+ +**request:** `Webflow.ProductsUpdateSkuRequest` + +
+
+ +
+
+ +**requestOptions:** `Products.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Orders + +
client.orders.list(siteId, { ...params }) -> Webflow.OrderList +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List all orders created for a given site. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.list("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**request:** `Webflow.OrdersListRequest` + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.orders.get(siteId, orderId) -> Webflow.Order +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieve a single product by its id. All of its SKUs will also be retrieved. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.get("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**orderId:** `string` — Unique identifier for an Order + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.orders.update(siteId, orderId, { ...params }) -> Webflow.Order +
+
+ +#### 📝 Description + +
+
+ +
+
+ +This API lets you update the fields, `comment`, `shippingProvider`, and/or `shippingTracking` for a given order. All three fields can be updated simultaneously or independently. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.update("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**orderId:** `string` — Unique identifier for an Order + +
+
+ +
+
+ +**request:** `Webflow.OrdersUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.orders.updateFulfill(siteId, orderId, { ...params }) -> Webflow.Order +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Updates an order's status to fulfilled + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.updateFulfill("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**orderId:** `string` — Unique identifier for an Order + +
+
+ +
+
+ +**request:** `Webflow.OrdersUpdateFulfillRequest` + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.orders.updateUnfulfill(siteId, orderId) -> Webflow.Order +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Updates an order's status to unfulfilled + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.updateUnfulfill("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**orderId:** `string` — Unique identifier for an Order + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.orders.refund(siteId, orderId, { ...params }) -> Webflow.Order +
+
+ +#### 📝 Description + +
+
+ +
+
+ +This API will reverse a Stripe charge and refund an order back to a +customer. It will also set the order's status to `refunded`. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.orders.refund("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**orderId:** `string` — Unique identifier for an Order + +
+
+ +
+
+ +**request:** `Webflow.OrdersRefundRequest` + +
+
+ +
+
+ +**requestOptions:** `Orders.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Inventory + +
client.inventory.list(collectionId, itemId) -> Webflow.InventoryItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +List the current inventory levels for a particular SKU item. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.inventory.list("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**requestOptions:** `Inventory.RequestOptions` + +
+
+
+
+ +
+
+
+ +
client.inventory.update(collectionId, itemId, { ...params }) -> Webflow.InventoryItem +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Updates the current inventory levels for a particular SKU item. Updates may be given in one or two methods, absolutely or incrementally. Absolute updates are done by setting `quantity` directly. Incremental updates are by specifying the inventory delta in `updateQuantity` which is then added to the `quantity` stored on the server. + +Required scope | `ecommerce:write` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.inventory.update("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { + inventoryType: Webflow.InventoryUpdateRequestInventoryType.Infinite, +}); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**collectionId:** `string` — Unique identifier for a Collection + +
+
+ +
+
+ +**itemId:** `string` — Unique identifier for an Item + +
+
+ +
+
+ +**request:** `Webflow.InventoryUpdateRequest` + +
+
+ +
+
+ +**requestOptions:** `Inventory.RequestOptions` + +
+
+
+
+ +
+
+
+ +## Ecommerce + +
client.ecommerce.getSettings(siteId) -> Webflow.EcommerceSettings +
+
+ +#### 📝 Description + +
+
+ +
+
+ +Retrieve ecommerce settings for a site. + +Required scope | `ecommerce:read` + +
+
+
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741"); +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**siteId:** `string` — Unique identifier for a Site + +
+
+ +
+
+ +**requestOptions:** `Ecommerce.RequestOptions` + +
+
+
+
+ +
+
+
diff --git a/src/Client.ts b/src/Client.ts index e1e74c57..c4463291 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -22,7 +22,7 @@ import { Ecommerce } from "./api/resources/ecommerce/client/Client"; export declare namespace WebflowClient { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { diff --git a/src/api/resources/accessGroups/client/Client.ts b/src/api/resources/accessGroups/client/Client.ts index 9f302c27..3bb45235 100644 --- a/src/api/resources/accessGroups/client/Client.ts +++ b/src/api/resources/accessGroups/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace AccessGroups { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -43,7 +43,7 @@ export class AccessGroups { * @throws {@link Webflow.InternalServerError} * * @example - * await client.accessGroups.list("site_id") + * await client.accessGroups.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -74,18 +74,20 @@ export class AccessGroups { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AccessGroupList.parseOrThrow(_response.body, { + return serializers.AccessGroupList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -106,7 +108,7 @@ export class AccessGroups { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -140,6 +142,6 @@ export class AccessGroups { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/assets/client/Client.ts b/src/api/resources/assets/client/Client.ts index c7262cbb..7498786f 100644 --- a/src/api/resources/assets/client/Client.ts +++ b/src/api/resources/assets/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Assets { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.list("site_id") + * await client.assets.list("580e63e98c9a982ac9b8b741") */ public async list(siteId: string, requestOptions?: Assets.RequestOptions): Promise { const _response = await core.fetcher({ @@ -54,17 +54,19 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Assets.parseOrThrow(_response.body, { + return serializers.Assets.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -83,7 +85,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -130,7 +132,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.create("site_id", { + * await client.assets.create("580e63e98c9a982ac9b8b741", { * fileName: "file.png", * fileHash: "3c7d87c9575702bc3b1e991f4d3c638e" * }) @@ -150,18 +152,20 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.AssetsCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.AssetsCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AssetUpload.parseOrThrow(_response.body, { + return serializers.AssetUpload.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -180,7 +184,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -226,7 +230,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.get("asset_id") + * await client.assets.get("580e63fc8c9a982ac9b8b745") */ public async get(assetId: string, requestOptions?: Assets.RequestOptions): Promise { const _response = await core.fetcher({ @@ -239,17 +243,19 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Asset.parseOrThrow(_response.body, { + return serializers.Asset.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -268,7 +274,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -314,7 +320,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.delete("asset_id") + * await client.assets.delete("580e63fc8c9a982ac9b8b745") */ public async delete(assetId: string, requestOptions?: Assets.RequestOptions): Promise { const _response = await core.fetcher({ @@ -327,11 +333,13 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -350,7 +358,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -397,7 +405,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.update("asset_id", { + * await client.assets.update("580e63fc8c9a982ac9b8b745", { * displayName: "bulldoze.png" * }) */ @@ -416,18 +424,20 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.AssetsUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.AssetsUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Asset.parseOrThrow(_response.body, { + return serializers.Asset.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -446,7 +456,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -492,7 +502,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.listFolders("site_id") + * await client.assets.listFolders("580e63e98c9a982ac9b8b741") */ public async listFolders(siteId: string, requestOptions?: Assets.RequestOptions): Promise { const _response = await core.fetcher({ @@ -505,17 +515,19 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AssetFolderList.parseOrThrow(_response.body, { + return serializers.AssetFolderList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -534,7 +546,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -581,7 +593,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.createFolder("site_id", { + * await client.assets.createFolder("580e63e98c9a982ac9b8b741", { * displayName: "my asset folder" * }) */ @@ -600,18 +612,20 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.AssetsCreateFolderRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.AssetsCreateFolderRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AssetFolder.parseOrThrow(_response.body, { + return serializers.AssetFolder.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -630,7 +644,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -676,7 +690,7 @@ export class Assets { * @throws {@link Webflow.InternalServerError} * * @example - * await client.assets.getFolder("asset_folder_id") + * await client.assets.getFolder("6390c49774a71f0e3c1a08ee") */ public async getFolder( assetFolderId: string, @@ -692,17 +706,19 @@ export class Assets { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AssetFolder.parseOrThrow(_response.body, { + return serializers.AssetFolder.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -721,7 +737,7 @@ export class Assets { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -755,6 +771,6 @@ export class Assets { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/collections/client/Client.ts b/src/api/resources/collections/client/Client.ts index 61ff9ba3..4314f70b 100644 --- a/src/api/resources/collections/client/Client.ts +++ b/src/api/resources/collections/client/Client.ts @@ -14,7 +14,7 @@ import { Items } from "../resources/items/client/Client"; export declare namespace Collections { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -43,7 +43,7 @@ export class Collections { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.list("site_id") + * await client.collections.list("580e63e98c9a982ac9b8b741") */ public async list(siteId: string, requestOptions?: Collections.RequestOptions): Promise { const _response = await core.fetcher({ @@ -56,17 +56,19 @@ export class Collections { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionList.parseOrThrow(_response.body, { + return serializers.CollectionList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -85,7 +87,7 @@ export class Collections { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -132,7 +134,7 @@ export class Collections { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.create("site_id", { + * await client.collections.create("580e63e98c9a982ac9b8b741", { * displayName: "Blog Posts", * singularName: "Blog Post", * slug: "posts" @@ -153,18 +155,20 @@ export class Collections { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CollectionsCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CollectionsCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Collection.parseOrThrow(_response.body, { + return serializers.Collection.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -183,7 +187,7 @@ export class Collections { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -229,7 +233,7 @@ export class Collections { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.get("collection_id") + * await client.collections.get("580e63fc8c9a982ac9b8b745") */ public async get(collectionId: string, requestOptions?: Collections.RequestOptions): Promise { const _response = await core.fetcher({ @@ -242,17 +246,19 @@ export class Collections { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Collection.parseOrThrow(_response.body, { + return serializers.Collection.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -271,7 +277,7 @@ export class Collections { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -317,7 +323,7 @@ export class Collections { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.deleteCollection("collection_id") + * await client.collections.deleteCollection("580e63fc8c9a982ac9b8b745") */ public async deleteCollection(collectionId: string, requestOptions?: Collections.RequestOptions): Promise { const _response = await core.fetcher({ @@ -330,11 +336,13 @@ export class Collections { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -353,7 +361,7 @@ export class Collections { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -400,7 +408,7 @@ export class Collections { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.delete("collection_id", "field_id") + * await client.collections.delete("580e63fc8c9a982ac9b8b745", "580e63fc8c9a982ac9b8b745") */ public async delete( collectionId: string, @@ -417,11 +425,13 @@ export class Collections { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -440,7 +450,7 @@ export class Collections { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -486,6 +496,6 @@ export class Collections { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/collections/resources/fields/client/Client.ts b/src/api/resources/collections/resources/fields/client/Client.ts index 4aa9228f..624dd1b8 100644 --- a/src/api/resources/collections/resources/fields/client/Client.ts +++ b/src/api/resources/collections/resources/fields/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../../../errors/index"; export declare namespace Fields { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -42,7 +42,7 @@ export class Fields { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.fields.create("collection_id", { + * await client.collections.fields.create("580e63fc8c9a982ac9b8b745", { * isRequired: false, * type: Webflow.collections.FieldCreateType.RichText, * displayName: "Post Body", @@ -64,18 +64,20 @@ export class Fields { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.collections.FieldCreate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.collections.FieldCreate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Field.parseOrThrow(_response.body, { + return serializers.Field.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -94,7 +96,7 @@ export class Fields { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -142,7 +144,7 @@ export class Fields { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.fields.update("collection_id", "field_id", { + * await client.collections.fields.update("580e63fc8c9a982ac9b8b745", "580e63fc8c9a982ac9b8b745", { * isRequired: false, * displayName: "Post Body", * helpText: "Add the body of your post here" @@ -164,18 +166,20 @@ export class Fields { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.collections.FieldUpdate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.collections.FieldUpdate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Field.parseOrThrow(_response.body, { + return serializers.Field.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -194,7 +198,7 @@ export class Fields { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -228,6 +232,6 @@ export class Fields { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/collections/resources/items/client/Client.ts b/src/api/resources/collections/resources/items/client/Client.ts index 5e42538e..988b6a4f 100644 --- a/src/api/resources/collections/resources/items/client/Client.ts +++ b/src/api/resources/collections/resources/items/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../../../errors/index"; export declare namespace Items { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -42,7 +42,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.listItems("collection_id") + * await client.collections.items.listItems("580e63fc8c9a982ac9b8b745") */ public async listItems( collectionId: string, @@ -89,18 +89,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItemList.parseOrThrow(_response.body, { + return serializers.CollectionItemList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -119,7 +121,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -166,7 +168,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.createItem("collection_id", { + * await client.collections.items.createItem("580e63fc8c9a982ac9b8b745", { * id: "42b720ef280c7a7a3be8cabe", * cmsLocaleId: "653ad57de882f528b32e810e", * lastPublished: "2022-11-29T16:22:43.159Z", @@ -184,7 +186,7 @@ export class Items { collectionId: string, request: Webflow.CollectionItem, requestOptions?: Items.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, @@ -195,18 +197,26 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return; + return serializers.CollectionItem.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -219,7 +229,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -266,7 +276,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.listItemsLive("collection_id") + * await client.collections.items.listItemsLive("580e63fc8c9a982ac9b8b745") */ public async listItemsLive( collectionId: string, @@ -313,18 +323,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItemList.parseOrThrow(_response.body, { + return serializers.CollectionItemList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -343,7 +355,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -390,7 +402,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.createItemLive("collection_id", { + * await client.collections.items.createItemLive("580e63fc8c9a982ac9b8b745", { * id: "42b720ef280c7a7a3be8cabe", * cmsLocaleId: "653ad57de882f528b32e810e", * lastPublished: "2022-11-29T16:22:43.159Z", @@ -408,7 +420,7 @@ export class Items { collectionId: string, request: Webflow.CollectionItem, requestOptions?: Items.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, @@ -419,18 +431,26 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return; + return serializers.CollectionItem.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -443,7 +463,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -480,7 +500,7 @@ export class Items { * Create single Item in a Collection with multiple corresponding locales.

Required scope | `CMS:write` * * @param {string} collectionId - Unique identifier for a Collection - * @param {Webflow.collections.BulkCollectionItem} request + * @param {Webflow.BulkCollectionItem} request * @param {Items.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Webflow.BadRequestError} @@ -490,15 +510,15 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.createItemForMultipleLocales("collection_id", { + * await client.collections.items.createItemForMultipleLocales("580e63fc8c9a982ac9b8b745", { * id: "580e64008c9a982ac9b8b754" * }) */ public async createItemForMultipleLocales( collectionId: string, - request: Webflow.collections.BulkCollectionItem, + request: Webflow.BulkCollectionItem, requestOptions?: Items.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, @@ -509,20 +529,26 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.collections.BulkCollectionItem.jsonOrThrow(request, { - unrecognizedObjectKeys: "strip", - }), + requestType: "json", + body: serializers.BulkCollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return; + return serializers.BulkCollectionItem.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -535,7 +561,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -583,7 +609,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.getItem("collection_id", "item_id") + * await client.collections.items.getItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754") */ public async getItem( collectionId: string, @@ -607,18 +633,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItem.parseOrThrow(_response.body, { + return serializers.CollectionItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -637,7 +665,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -685,7 +713,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.deleteItem("collection_id", "item_id") + * await client.collections.items.deleteItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754") */ public async deleteItem( collectionId: string, @@ -709,12 +737,14 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -733,7 +763,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -781,7 +811,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.updateItem("collection_id", "item_id", { + * await client.collections.items.updateItem("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { * id: "42b720ef280c7a7a3be8cabe", * cmsLocaleId: "653ad57de882f528b32e810e", * lastPublished: "2022-11-29T16:22:43.159Z", @@ -811,18 +841,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItem.parseOrThrow(_response.body, { + return serializers.CollectionItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -841,7 +873,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -889,7 +921,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.getItemLive("collection_id", "item_id") + * await client.collections.items.getItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754") */ public async getItemLive( collectionId: string, @@ -913,18 +945,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItem.parseOrThrow(_response.body, { + return serializers.CollectionItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -943,7 +977,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -991,7 +1025,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.deleteItemLive("collection_id", "item_id") + * await client.collections.items.deleteItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754") */ public async deleteItemLive( collectionId: string, @@ -1015,12 +1049,14 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -1039,7 +1075,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1087,7 +1123,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.updateItemLive("collection_id", "item_id", { + * await client.collections.items.updateItemLive("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { * id: "42b720ef280c7a7a3be8cabe", * cmsLocaleId: "653ad57de882f528b32e810e", * lastPublished: "2022-11-29T16:22:43.159Z", @@ -1117,18 +1153,20 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CollectionItem.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CollectionItem.parseOrThrow(_response.body, { + return serializers.CollectionItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1147,7 +1185,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1194,7 +1232,7 @@ export class Items { * @throws {@link Webflow.InternalServerError} * * @example - * await client.collections.items.publishItem("collection_id", { + * await client.collections.items.publishItem("580e63fc8c9a982ac9b8b745", { * itemIds: ["itemIds"] * }) */ @@ -1202,7 +1240,7 @@ export class Items { collectionId: string, request: Webflow.collections.ItemsPublishItemRequest, requestOptions?: Items.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, @@ -1213,12 +1251,14 @@ export class Items { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.collections.ItemsPublishItemRequest.jsonOrThrow(request, { + requestType: "json", + body: serializers.collections.ItemsPublishItemRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip", }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, @@ -1226,7 +1266,13 @@ export class Items { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return; + return serializers.collections.ItemsPublishItemResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -1239,7 +1285,7 @@ export class Items { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -1273,6 +1319,6 @@ export class Items { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/collections/resources/items/client/requests/index.ts b/src/api/resources/collections/resources/items/client/requests/index.ts index 66c715e2..c5e6b062 100644 --- a/src/api/resources/collections/resources/items/client/requests/index.ts +++ b/src/api/resources/collections/resources/items/client/requests/index.ts @@ -1,6 +1,5 @@ export { type ItemsListItemsRequest } from "./ItemsListItemsRequest"; export { type ItemsListItemsLiveRequest } from "./ItemsListItemsLiveRequest"; -export { type BulkCollectionItem } from "./BulkCollectionItem"; export { type ItemsGetItemRequest } from "./ItemsGetItemRequest"; export { type ItemsDeleteItemRequest } from "./ItemsDeleteItemRequest"; export { type ItemsGetItemLiveRequest } from "./ItemsGetItemLiveRequest"; diff --git a/src/api/resources/collections/resources/items/types/ItemsPublishItemResponse.ts b/src/api/resources/collections/resources/items/types/ItemsPublishItemResponse.ts new file mode 100644 index 00000000..94e2b8c1 --- /dev/null +++ b/src/api/resources/collections/resources/items/types/ItemsPublishItemResponse.ts @@ -0,0 +1,8 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface ItemsPublishItemResponse { + publishedItemIds?: string[]; + errors?: string[]; +} diff --git a/src/api/resources/collections/resources/items/types/index.ts b/src/api/resources/collections/resources/items/types/index.ts index dcde450b..dce8a6ed 100644 --- a/src/api/resources/collections/resources/items/types/index.ts +++ b/src/api/resources/collections/resources/items/types/index.ts @@ -2,4 +2,4 @@ export * from "./ItemsListItemsRequestSortBy"; export * from "./ItemsListItemsRequestSortOrder"; export * from "./ItemsListItemsLiveRequestSortBy"; export * from "./ItemsListItemsLiveRequestSortOrder"; -export * from "./BulkCollectionItemFieldData"; +export * from "./ItemsPublishItemResponse"; diff --git a/src/api/resources/ecommerce/client/Client.ts b/src/api/resources/ecommerce/client/Client.ts index b0ada75d..808088c6 100644 --- a/src/api/resources/ecommerce/client/Client.ts +++ b/src/api/resources/ecommerce/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Ecommerce { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -45,7 +45,7 @@ export class Ecommerce { * @throws {@link Webflow.InternalServerError} * * @example - * await client.ecommerce.getSettings("site_id") + * await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741") */ public async getSettings( siteId: string, @@ -61,17 +61,19 @@ export class Ecommerce { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.EcommerceSettings.parseOrThrow(_response.body, { + return serializers.EcommerceSettings.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -94,7 +96,7 @@ export class Ecommerce { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -128,6 +130,6 @@ export class Ecommerce { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/forms/client/Client.ts b/src/api/resources/forms/client/Client.ts index 71c06aba..3f5f3dca 100644 --- a/src/api/resources/forms/client/Client.ts +++ b/src/api/resources/forms/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Forms { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -44,7 +44,7 @@ export class Forms { * @throws {@link Webflow.InternalServerError} * * @example - * await client.forms.list("site_id") + * await client.forms.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -71,18 +71,20 @@ export class Forms { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.FormList.parseOrThrow(_response.body, { + return serializers.FormList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -105,7 +107,7 @@ export class Forms { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -152,7 +154,7 @@ export class Forms { * @throws {@link Webflow.InternalServerError} * * @example - * await client.forms.get("form_id") + * await client.forms.get("580e63e98c9a982ac9b8b741") */ public async get(formId: string, requestOptions?: Forms.RequestOptions): Promise { const _response = await core.fetcher({ @@ -165,17 +167,19 @@ export class Forms { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Form.parseOrThrow(_response.body, { + return serializers.Form.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -196,7 +200,7 @@ export class Forms { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -244,7 +248,7 @@ export class Forms { * @throws {@link Webflow.InternalServerError} * * @example - * await client.forms.listSubmissions("form_id") + * await client.forms.listSubmissions("580e63e98c9a982ac9b8b741") */ public async listSubmissions( formId: string, @@ -271,18 +275,20 @@ export class Forms { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.FormSubmissionList.parseOrThrow(_response.body, { + return serializers.FormSubmissionList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -303,7 +309,7 @@ export class Forms { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -350,7 +356,7 @@ export class Forms { * @throws {@link Webflow.InternalServerError} * * @example - * await client.forms.getSubmission("form_submission_id") + * await client.forms.getSubmission("580e63e98c9a982ac9b8b741") */ public async getSubmission( formSubmissionId: string, @@ -366,17 +372,19 @@ export class Forms { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.FormSubmission.parseOrThrow(_response.body, { + return serializers.FormSubmission.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -397,7 +405,7 @@ export class Forms { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -446,7 +454,7 @@ export class Forms { * @throws {@link Webflow.InternalServerError} * * @example - * await client.forms.updateSubmission("form_submission_id") + * await client.forms.updateSubmission("580e63e98c9a982ac9b8b741") */ public async updateSubmission( formSubmissionId: string, @@ -463,20 +471,20 @@ export class Forms { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.FormsUpdateSubmissionRequest.jsonOrThrow(request, { - unrecognizedObjectKeys: "strip", - }), + requestType: "json", + body: serializers.FormsUpdateSubmissionRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.FormSubmission.parseOrThrow(_response.body, { + return serializers.FormSubmission.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -499,7 +507,7 @@ export class Forms { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -533,6 +541,6 @@ export class Forms { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/index.ts b/src/api/resources/index.ts index d1e4bb57..5cf3fc0a 100644 --- a/src/api/resources/index.ts +++ b/src/api/resources/index.ts @@ -1,3 +1,5 @@ +export * as sites from "./sites"; +export * from "./sites/types"; export * as collections from "./collections"; export * as pages from "./pages"; export * from "./pages/types"; @@ -12,7 +14,6 @@ export * from "./orders/types"; export * as inventory from "./inventory"; export * from "./inventory/types"; export * as token from "./token"; -export * as sites from "./sites"; export * as scripts from "./scripts"; export * as assets from "./assets"; export * as webhooks from "./webhooks"; diff --git a/src/api/resources/inventory/client/Client.ts b/src/api/resources/inventory/client/Client.ts index 7c782d3b..a663cf89 100644 --- a/src/api/resources/inventory/client/Client.ts +++ b/src/api/resources/inventory/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Inventory { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -46,7 +46,7 @@ export class Inventory { * @throws {@link Webflow.InternalServerError} * * @example - * await client.inventory.list("collection_id", "item_id") + * await client.inventory.list("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754") */ public async list( collectionId: string, @@ -63,17 +63,19 @@ export class Inventory { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.InventoryItem.parseOrThrow(_response.body, { + return serializers.InventoryItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -96,7 +98,7 @@ export class Inventory { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -148,7 +150,7 @@ export class Inventory { * @throws {@link Webflow.InternalServerError} * * @example - * await client.inventory.update("collection_id", "item_id", { + * await client.inventory.update("580e63fc8c9a982ac9b8b745", "580e64008c9a982ac9b8b754", { * inventoryType: Webflow.InventoryUpdateRequestInventoryType.Infinite * }) */ @@ -168,18 +170,20 @@ export class Inventory { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.InventoryUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.InventoryUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.InventoryItem.parseOrThrow(_response.body, { + return serializers.InventoryItem.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -202,7 +206,7 @@ export class Inventory { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -236,6 +240,6 @@ export class Inventory { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/orders/client/Client.ts b/src/api/resources/orders/client/Client.ts index 454c9b02..908a2267 100644 --- a/src/api/resources/orders/client/Client.ts +++ b/src/api/resources/orders/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Orders { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -46,7 +46,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.list("site_id") + * await client.orders.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -77,18 +77,20 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.OrderList.parseOrThrow(_response.body, { + return serializers.OrderList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -111,7 +113,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -162,7 +164,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.get("site_id", "order_id") + * await client.orders.get("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415") */ public async get(siteId: string, orderId: string, requestOptions?: Orders.RequestOptions): Promise { const _response = await core.fetcher({ @@ -175,17 +177,19 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Order.parseOrThrow(_response.body, { + return serializers.Order.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -208,7 +212,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -260,7 +264,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.update("site_id", "order_id") + * await client.orders.update("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415") */ public async update( siteId: string, @@ -278,18 +282,20 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.OrdersUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.OrdersUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Order.parseOrThrow(_response.body, { + return serializers.Order.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -312,7 +318,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -364,7 +370,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.updateFulfill("site_id", "order_id") + * await client.orders.updateFulfill("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415") */ public async updateFulfill( siteId: string, @@ -382,20 +388,20 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.OrdersUpdateFulfillRequest.jsonOrThrow(request, { - unrecognizedObjectKeys: "strip", - }), + requestType: "json", + body: serializers.OrdersUpdateFulfillRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Order.parseOrThrow(_response.body, { + return serializers.Order.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -418,7 +424,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -469,7 +475,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.updateUnfulfill("site_id", "order_id") + * await client.orders.updateUnfulfill("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415") */ public async updateUnfulfill( siteId: string, @@ -486,17 +492,19 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Order.parseOrThrow(_response.body, { + return serializers.Order.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -519,7 +527,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -572,7 +580,7 @@ export class Orders { * @throws {@link Webflow.InternalServerError} * * @example - * await client.orders.refund("site_id", "order_id") + * await client.orders.refund("580e63e98c9a982ac9b8b741", "5e8518516e147040726cc415") */ public async refund( siteId: string, @@ -590,18 +598,20 @@ export class Orders { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.OrdersRefundRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.OrdersRefundRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Order.parseOrThrow(_response.body, { + return serializers.Order.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -624,7 +634,7 @@ export class Orders { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -658,6 +668,6 @@ export class Orders { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/pages/client/Client.ts b/src/api/resources/pages/client/Client.ts index 8a232573..73f0bbad 100644 --- a/src/api/resources/pages/client/Client.ts +++ b/src/api/resources/pages/client/Client.ts @@ -13,7 +13,7 @@ import { Scripts } from "../resources/scripts/client/Client"; export declare namespace Pages { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -43,7 +43,9 @@ export class Pages { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.list("site_id") + * await client.pages.list("580e63e98c9a982ac9b8b741", { + * locale: "65427cf400e02b306eaa04a0" + * }) */ public async list( siteId: string, @@ -74,18 +76,20 @@ export class Pages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.PageList.parseOrThrow(_response.body, { + return serializers.PageList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -104,7 +108,7 @@ export class Pages { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -151,7 +155,9 @@ export class Pages { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.getMetadata("page_id") + * await client.pages.getMetadata("63c720f9347c2139b248e552", { + * locale: "65427cf400e02b306eaa04a0" + * }) */ public async getMetadata( pageId: string, @@ -174,18 +180,20 @@ export class Pages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.PageDetails.parseOrThrow(_response.body, { + return serializers.PageDetails.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -204,7 +212,7 @@ export class Pages { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -251,7 +259,8 @@ export class Pages { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.updatePageSettings("page_id", { + * await client.pages.updatePageSettings("63c720f9347c2139b248e552", { + * locale: "65427cf400e02b306eaa04a0", * body: { * id: "6596da6045e56dee495bcbba", * siteId: "6258612d1ee792848f805dcf", @@ -259,8 +268,8 @@ export class Pages { * slug: "guide-to-the-galaxy", * parentId: "6419db964a9c435aa3af6251", * collectionId: "6390c49774a71f12831a08e3", - * createdOn: new Date("2024-03-11T10:42:00.000Z"), - * lastUpdated: new Date("2024-03-11T10:42:42.000Z"), + * createdOn: "2024-03-11T10:42:00Z", + * lastUpdated: "2024-03-11T10:42:42Z", * archived: false, * draft: false, * canBranch: true, @@ -298,19 +307,21 @@ export class Pages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, - body: await serializers.Page.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.Page.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.PageDetails.parseOrThrow(_response.body, { + return serializers.PageDetails.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -329,7 +340,7 @@ export class Pages { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -377,7 +388,9 @@ export class Pages { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.getContent("page_id") + * await client.pages.getContent("63c720f9347c2139b248e552", { + * locale: "65427cf400e02b306eaa04a0" + * }) */ public async getContent( pageId: string, @@ -408,18 +421,20 @@ export class Pages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Dom.parseOrThrow(_response.body, { + return serializers.Dom.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -440,7 +455,7 @@ export class Pages { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -492,7 +507,7 @@ export class Pages { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.updateStaticContent("page_id", { + * await client.pages.updateStaticContent("63c720f9347c2139b248e552", { * locale: "locale", * nodes: [{ * nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad623", @@ -524,19 +539,21 @@ export class Pages { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, - body: await serializers.DomWrite.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.DomWrite.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.UpdateStaticContentResponse.parseOrThrow(_response.body, { + return serializers.UpdateStaticContentResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -557,7 +574,7 @@ export class Pages { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -597,6 +614,6 @@ export class Pages { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/pages/client/requests/PagesGetContentRequest.ts b/src/api/resources/pages/client/requests/PagesGetContentRequest.ts index e535566d..971e471c 100644 --- a/src/api/resources/pages/client/requests/PagesGetContentRequest.ts +++ b/src/api/resources/pages/client/requests/PagesGetContentRequest.ts @@ -4,7 +4,9 @@ /** * @example - * {} + * { + * locale: "65427cf400e02b306eaa04a0" + * } */ export interface PagesGetContentRequest { /** diff --git a/src/api/resources/pages/client/requests/PagesGetMetadataRequest.ts b/src/api/resources/pages/client/requests/PagesGetMetadataRequest.ts index 14692129..d4a4e72d 100644 --- a/src/api/resources/pages/client/requests/PagesGetMetadataRequest.ts +++ b/src/api/resources/pages/client/requests/PagesGetMetadataRequest.ts @@ -4,7 +4,9 @@ /** * @example - * {} + * { + * locale: "65427cf400e02b306eaa04a0" + * } */ export interface PagesGetMetadataRequest { /** diff --git a/src/api/resources/pages/client/requests/PagesListRequest.ts b/src/api/resources/pages/client/requests/PagesListRequest.ts index 69aa2aa5..b7ba9cf4 100644 --- a/src/api/resources/pages/client/requests/PagesListRequest.ts +++ b/src/api/resources/pages/client/requests/PagesListRequest.ts @@ -4,7 +4,9 @@ /** * @example - * {} + * { + * locale: "65427cf400e02b306eaa04a0" + * } */ export interface PagesListRequest { /** diff --git a/src/api/resources/pages/client/requests/UpdatePageSettingsRequest.ts b/src/api/resources/pages/client/requests/UpdatePageSettingsRequest.ts index e346b771..81be6019 100644 --- a/src/api/resources/pages/client/requests/UpdatePageSettingsRequest.ts +++ b/src/api/resources/pages/client/requests/UpdatePageSettingsRequest.ts @@ -7,6 +7,7 @@ import * as Webflow from "../../../../index"; /** * @example * { + * locale: "65427cf400e02b306eaa04a0", * body: { * id: "6596da6045e56dee495bcbba", * siteId: "6258612d1ee792848f805dcf", @@ -14,8 +15,8 @@ import * as Webflow from "../../../../index"; * slug: "guide-to-the-galaxy", * parentId: "6419db964a9c435aa3af6251", * collectionId: "6390c49774a71f12831a08e3", - * createdOn: new Date("2024-03-11T10:42:00.000Z"), - * lastUpdated: new Date("2024-03-11T10:42:42.000Z"), + * createdOn: "2024-03-11T10:42:00Z", + * lastUpdated: "2024-03-11T10:42:42Z", * archived: false, * draft: false, * canBranch: true, diff --git a/src/api/resources/pages/resources/scripts/client/Client.ts b/src/api/resources/pages/resources/scripts/client/Client.ts index 20a0781c..59e5d09a 100644 --- a/src/api/resources/pages/resources/scripts/client/Client.ts +++ b/src/api/resources/pages/resources/scripts/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../../../errors/index"; export declare namespace Scripts { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.scripts.getCustomCode("page_id") + * await client.pages.scripts.getCustomCode("63c720f9347c2139b248e552") */ public async getCustomCode( pageId: string, @@ -57,17 +57,19 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ScriptApplyList.parseOrThrow(_response.body, { + return serializers.ScriptApplyList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -86,7 +88,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -133,7 +135,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.scripts.upsertCustomCode("page_id", { + * await client.pages.scripts.upsertCustomCode("63c720f9347c2139b248e552", { * scripts: [{ * id: "cms_slider", * location: Webflow.ScriptApplyLocation.Header, @@ -163,18 +165,20 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ScriptApplyList.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ScriptApplyList.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ScriptApplyList.parseOrThrow(_response.body, { + return serializers.ScriptApplyList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -193,7 +197,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -239,7 +243,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.pages.scripts.deleteCustomCode("page_id") + * await client.pages.scripts.deleteCustomCode("63c720f9347c2139b248e552") */ public async deleteCustomCode(pageId: string, requestOptions?: Scripts.RequestOptions): Promise { const _response = await core.fetcher({ @@ -252,11 +256,13 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -275,7 +281,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -309,6 +315,6 @@ export class Scripts { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/products/client/Client.ts b/src/api/resources/products/client/Client.ts index d784f418..5f89fd7f 100644 --- a/src/api/resources/products/client/Client.ts +++ b/src/api/resources/products/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Products { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -46,7 +46,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.list("site_id") + * await client.products.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -73,18 +73,20 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ProductAndSkUsList.parseOrThrow(_response.body, { + return serializers.ProductAndSkUsList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -107,7 +109,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -164,7 +166,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.create("site_id") + * await client.products.create("580e63e98c9a982ac9b8b741") */ public async create( siteId: string, @@ -181,18 +183,20 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ProductSkuCreate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ProductSkuCreate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ProductAndSkUs.parseOrThrow(_response.body, { + return serializers.ProductAndSkUs.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -215,7 +219,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -266,7 +270,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.get("site_id", "product_id") + * await client.products.get("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745") */ public async get( siteId: string, @@ -283,17 +287,19 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ProductAndSkUs.parseOrThrow(_response.body, { + return serializers.ProductAndSkUs.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -316,7 +322,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -368,7 +374,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.update("site_id", "product_id") + * await client.products.update("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745") */ public async update( siteId: string, @@ -386,18 +392,20 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ProductSkuUpdate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ProductSkuUpdate.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Product.parseOrThrow(_response.body, { + return serializers.Product.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -420,7 +428,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -474,7 +482,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.createSku("site_id", "product_id", { + * await client.products.createSku("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", { * skus: [{}] * }) */ @@ -494,18 +502,20 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ProductsCreateSkuRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ProductsCreateSkuRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ProductsCreateSkuResponse.parseOrThrow(_response.body, { + return serializers.ProductsCreateSkuResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -528,7 +538,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -581,7 +591,7 @@ export class Products { * @throws {@link Webflow.InternalServerError} * * @example - * await client.products.updateSku("site_id", "product_id", "sku_id", { + * await client.products.updateSku("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", "5e8518516e147040726cc415", { * sku: {} * }) */ @@ -604,18 +614,20 @@ export class Products { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ProductsUpdateSkuRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ProductsUpdateSkuRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Sku.parseOrThrow(_response.body, { + return serializers.Sku.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -638,7 +650,7 @@ export class Products { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -672,6 +684,6 @@ export class Products { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/scripts/client/Client.ts b/src/api/resources/scripts/client/Client.ts index ab04dafe..ba0f5dff 100644 --- a/src/api/resources/scripts/client/Client.ts +++ b/src/api/resources/scripts/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Scripts { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.scripts.list("site_id") + * await client.scripts.list("580e63e98c9a982ac9b8b741") */ public async list(siteId: string, requestOptions?: Scripts.RequestOptions): Promise { const _response = await core.fetcher({ @@ -54,17 +54,19 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.RegisteredScriptList.parseOrThrow(_response.body, { + return serializers.RegisteredScriptList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -83,7 +85,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -130,7 +132,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.scripts.registerHosted("site_id", { + * await client.scripts.registerHosted("580e63e98c9a982ac9b8b741", { * hostedLocation: "hostedLocation", * integrityHash: "integrityHash", * version: "version", @@ -152,18 +154,20 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CustomCodeHostedRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CustomCodeHostedRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CustomCodeHostedResponse.parseOrThrow(_response.body, { + return serializers.CustomCodeHostedResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -182,7 +186,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -229,7 +233,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.scripts.registerInline("site_id", { + * await client.scripts.registerInline("580e63e98c9a982ac9b8b741", { * sourceCode: "alert('hello world');", * version: "0.0.1", * displayName: "Alert" @@ -250,18 +254,20 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.CustomCodeInlineRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.CustomCodeInlineRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.CustomCodeInlineResponse.parseOrThrow(_response.body, { + return serializers.CustomCodeInlineResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -280,7 +286,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -314,6 +320,6 @@ export class Scripts { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/sites/client/Client.ts b/src/api/resources/sites/client/Client.ts index 8ae993d0..3c661b9d 100644 --- a/src/api/resources/sites/client/Client.ts +++ b/src/api/resources/sites/client/Client.ts @@ -14,7 +14,7 @@ import { Scripts } from "../resources/scripts/client/Client"; export declare namespace Sites { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -53,17 +53,19 @@ export class Sites { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Sites.parseOrThrow(_response.body, { + return serializers.Sites.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -80,7 +82,7 @@ export class Sites { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -124,7 +126,7 @@ export class Sites { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.get("site_id") + * await client.sites.get("580e63e98c9a982ac9b8b741") */ public async get(siteId: string, requestOptions?: Sites.RequestOptions): Promise { const _response = await core.fetcher({ @@ -137,17 +139,19 @@ export class Sites { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Site.parseOrThrow(_response.body, { + return serializers.Site.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -166,7 +170,7 @@ export class Sites { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -212,7 +216,7 @@ export class Sites { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.getCustomDomain("site_id") + * await client.sites.getCustomDomain("580e63e98c9a982ac9b8b741") */ public async getCustomDomain(siteId: string, requestOptions?: Sites.RequestOptions): Promise { const _response = await core.fetcher({ @@ -225,17 +229,19 @@ export class Sites { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Domains.parseOrThrow(_response.body, { + return serializers.Domains.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -254,7 +260,7 @@ export class Sites { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -301,13 +307,13 @@ export class Sites { * @throws {@link Webflow.TooManyRequestsError} * * @example - * await client.sites.publish("site_id") + * await client.sites.publish("580e63e98c9a982ac9b8b741") */ public async publish( siteId: string, request: Webflow.SitesPublishRequest = {}, requestOptions?: Sites.RequestOptions - ): Promise { + ): Promise { const _response = await core.fetcher({ url: urlJoin( (await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default, @@ -318,18 +324,26 @@ export class Sites { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.SitesPublishRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.SitesPublishRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return; + return serializers.SitesPublishResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + skipValidation: true, + breadcrumbsPrefix: ["response"], + }); } if (_response.error.reason === "status-code") { @@ -344,7 +358,7 @@ export class Sites { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -388,6 +402,6 @@ export class Sites { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/sites/index.ts b/src/api/resources/sites/index.ts index 33a87f10..848e75ab 100644 --- a/src/api/resources/sites/index.ts +++ b/src/api/resources/sites/index.ts @@ -1,2 +1,3 @@ +export * from "./types"; export * from "./client"; export * from "./resources"; diff --git a/src/api/resources/sites/resources/activityLogs/client/Client.ts b/src/api/resources/sites/resources/activityLogs/client/Client.ts index 90d79bd9..5d7de277 100644 --- a/src/api/resources/sites/resources/activityLogs/client/Client.ts +++ b/src/api/resources/sites/resources/activityLogs/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../../../errors/index"; export declare namespace ActivityLogs { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class ActivityLogs { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.activityLogs.list("site_id") + * await client.sites.activityLogs.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -68,18 +68,20 @@ export class ActivityLogs { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.SiteActivityLogResponse.parseOrThrow(_response.body, { + return serializers.SiteActivityLogResponse.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -96,7 +98,7 @@ export class ActivityLogs { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -130,6 +132,6 @@ export class ActivityLogs { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/sites/resources/scripts/client/Client.ts b/src/api/resources/sites/resources/scripts/client/Client.ts index 3150517d..f20ba37b 100644 --- a/src/api/resources/sites/resources/scripts/client/Client.ts +++ b/src/api/resources/sites/resources/scripts/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../../../errors/index"; export declare namespace Scripts { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.scripts.getCustomCode("site_id") + * await client.sites.scripts.getCustomCode("580e63e98c9a982ac9b8b741") */ public async getCustomCode( siteId: string, @@ -57,17 +57,19 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ScriptApplyList.parseOrThrow(_response.body, { + return serializers.ScriptApplyList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -86,7 +88,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -133,7 +135,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.scripts.upsertCustomCode("site_id", { + * await client.sites.scripts.upsertCustomCode("580e63e98c9a982ac9b8b741", { * scripts: [{ * id: "cms_slider", * location: Webflow.ScriptApplyLocation.Header, @@ -163,18 +165,20 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.ScriptApplyList.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.ScriptApplyList.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ScriptApplyList.parseOrThrow(_response.body, { + return serializers.ScriptApplyList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -193,7 +197,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -239,7 +243,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.scripts.deleteCustomCode("site_id") + * await client.sites.scripts.deleteCustomCode("580e63e98c9a982ac9b8b741") */ public async deleteCustomCode(siteId: string, requestOptions?: Scripts.RequestOptions): Promise { const _response = await core.fetcher({ @@ -252,11 +256,13 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -275,7 +281,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -322,7 +328,7 @@ export class Scripts { * @throws {@link Webflow.InternalServerError} * * @example - * await client.sites.scripts.listCustomCodeBlocks("site_id") + * await client.sites.scripts.listCustomCodeBlocks("580e63e98c9a982ac9b8b741") */ public async listCustomCodeBlocks( siteId: string, @@ -349,18 +355,20 @@ export class Scripts { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.ListCustomCodeBlocks.parseOrThrow(_response.body, { + return serializers.ListCustomCodeBlocks.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -379,7 +387,7 @@ export class Scripts { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -413,6 +421,6 @@ export class Scripts { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/sites/types/SitesPublishResponse.ts b/src/api/resources/sites/types/SitesPublishResponse.ts new file mode 100644 index 00000000..e427b61a --- /dev/null +++ b/src/api/resources/sites/types/SitesPublishResponse.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as Webflow from "../../../index"; + +export interface SitesPublishResponse { + /** Array of domains objects */ + customDomains?: Webflow.Domain[]; + /** Flag for publishing to webflow.io subdomain */ + publishToWebflowSubdomain?: boolean; +} diff --git a/src/api/resources/sites/types/index.ts b/src/api/resources/sites/types/index.ts new file mode 100644 index 00000000..7708da86 --- /dev/null +++ b/src/api/resources/sites/types/index.ts @@ -0,0 +1 @@ +export * from "./SitesPublishResponse"; diff --git a/src/api/resources/token/client/Client.ts b/src/api/resources/token/client/Client.ts index 6343d00c..b7823d8f 100644 --- a/src/api/resources/token/client/Client.ts +++ b/src/api/resources/token/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Token { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -50,17 +50,19 @@ export class Token { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.AuthorizedUser.parseOrThrow(_response.body, { + return serializers.AuthorizedUser.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -119,17 +121,19 @@ export class Token { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Authorization.parseOrThrow(_response.body, { + return serializers.Authorization.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -166,6 +170,6 @@ export class Token { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/users/client/Client.ts b/src/api/resources/users/client/Client.ts index 6b8f1991..925555ae 100644 --- a/src/api/resources/users/client/Client.ts +++ b/src/api/resources/users/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Users { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -43,7 +43,7 @@ export class Users { * @throws {@link Webflow.InternalServerError} * * @example - * await client.users.list("site_id") + * await client.users.list("580e63e98c9a982ac9b8b741") */ public async list( siteId: string, @@ -74,18 +74,20 @@ export class Users { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", queryParameters: _queryParams, + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.UserList.parseOrThrow(_response.body, { + return serializers.UserList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -106,7 +108,7 @@ export class Users { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -154,7 +156,7 @@ export class Users { * @throws {@link Webflow.InternalServerError} * * @example - * await client.users.get("site_id", "user_id") + * await client.users.get("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741") */ public async get(siteId: string, userId: string, requestOptions?: Users.RequestOptions): Promise { const _response = await core.fetcher({ @@ -167,17 +169,19 @@ export class Users { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.User.parseOrThrow(_response.body, { + return serializers.User.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -198,7 +202,7 @@ export class Users { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -246,7 +250,7 @@ export class Users { * @throws {@link Webflow.InternalServerError} * * @example - * await client.users.delete("site_id", "user_id") + * await client.users.delete("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741") */ public async delete(siteId: string, userId: string, requestOptions?: Users.RequestOptions): Promise { const _response = await core.fetcher({ @@ -259,11 +263,13 @@ export class Users { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -284,7 +290,7 @@ export class Users { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -335,7 +341,7 @@ export class Users { * @throws {@link Webflow.InternalServerError} * * @example - * await client.users.update("site_id", "user_id", { + * await client.users.update("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741", { * data: { * name: "Some One", * acceptPrivacy: false, @@ -360,18 +366,20 @@ export class Users { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.UsersUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.UsersUpdateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.User.parseOrThrow(_response.body, { + return serializers.User.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -392,7 +400,7 @@ export class Users { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -441,7 +449,7 @@ export class Users { * @throws {@link Webflow.InternalServerError} * * @example - * await client.users.invite("site_id", { + * await client.users.invite("580e63e98c9a982ac9b8b741", { * email: "some.one@home.com", * accessGroups: ["webflowers"] * }) @@ -461,18 +469,20 @@ export class Users { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.UsersInviteRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.UsersInviteRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.User.parseOrThrow(_response.body, { + return serializers.User.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -495,7 +505,7 @@ export class Users { throw new Webflow.ConflictError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -529,6 +539,6 @@ export class Users { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/webhooks/client/Client.ts b/src/api/resources/webhooks/client/Client.ts index 7b0124b7..f11bfaec 100644 --- a/src/api/resources/webhooks/client/Client.ts +++ b/src/api/resources/webhooks/client/Client.ts @@ -12,7 +12,7 @@ import * as errors from "../../../../errors/index"; export declare namespace Webhooks { interface Options { environment?: core.Supplier; - accessToken: core.Supplier; + token: core.Supplier; } interface RequestOptions { @@ -41,7 +41,7 @@ export class Webhooks { * @throws {@link Webflow.InternalServerError} * * @example - * await client.webhooks.list("site_id") + * await client.webhooks.list("580e63e98c9a982ac9b8b741") */ public async list(siteId: string, requestOptions?: Webhooks.RequestOptions): Promise { const _response = await core.fetcher({ @@ -54,17 +54,19 @@ export class Webhooks { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.WebhookList.parseOrThrow(_response.body, { + return serializers.WebhookList.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -83,7 +85,7 @@ export class Webhooks { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -130,14 +132,14 @@ export class Webhooks { * @throws {@link Webflow.InternalServerError} * * @example - * await client.webhooks.create("site_id", { + * await client.webhooks.create("580e63e98c9a982ac9b8b741", { * id: "582266e0cd48de0f0e3c6d8b", * triggerType: Webflow.TriggerType.FormSubmission, * url: "https://webhook.site/7f7f7f7f-7f7f-7f7f-7f7f-7f7f7f7f7f7f", * workspaceId: "4f4e46fd476ea8c507000001", * siteId: "562ac0395358780a1f5e6fbd", - * lastTriggered: new Date("2023-02-08T23:59:28.000Z"), - * createdOn: new Date("2022-11-08T23:59:28.000Z") + * lastTriggered: "2023-02-08T23:59:28Z", + * createdOn: "2022-11-08T23:59:28Z" * }) */ public async create( @@ -155,18 +157,20 @@ export class Webhooks { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", - body: await serializers.Webhook.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + requestType: "json", + body: serializers.Webhook.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Webhook.parseOrThrow(_response.body, { + return serializers.Webhook.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -185,7 +189,7 @@ export class Webhooks { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -231,7 +235,7 @@ export class Webhooks { * @throws {@link Webflow.InternalServerError} * * @example - * await client.webhooks.get("webhook_id") + * await client.webhooks.get("580e64008c9a982ac9b8b754") */ public async get(webhookId: string, requestOptions?: Webhooks.RequestOptions): Promise { const _response = await core.fetcher({ @@ -244,17 +248,19 @@ export class Webhooks { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return await serializers.Webhook.parseOrThrow(_response.body, { + return serializers.Webhook.parseOrThrow(_response.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -273,7 +279,7 @@ export class Webhooks { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -319,7 +325,7 @@ export class Webhooks { * @throws {@link Webflow.InternalServerError} * * @example - * await client.webhooks.delete("webhook_id") + * await client.webhooks.delete("580e64008c9a982ac9b8b754") */ public async delete(webhookId: string, requestOptions?: Webhooks.RequestOptions): Promise { const _response = await core.fetcher({ @@ -332,11 +338,13 @@ export class Webhooks { Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "webflow-api", - "X-Fern-SDK-Version": "2.3.6", + "X-Fern-SDK-Version": "2.3.7", + "User-Agent": "webflow-api/2.3.7", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -355,7 +363,7 @@ export class Webhooks { throw new Webflow.NotFoundError(_response.error.body); case 429: throw new Webflow.TooManyRequestsError( - await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { + serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, { unrecognizedObjectKeys: "passthrough", allowUnrecognizedUnionMembers: true, allowUnrecognizedEnumValues: true, @@ -389,6 +397,6 @@ export class Webhooks { } protected async _getAuthorizationHeader(): Promise { - return `Bearer ${await core.Supplier.get(this._options.accessToken)}`; + return `Bearer ${await core.Supplier.get(this._options.token)}`; } } diff --git a/src/api/resources/collections/resources/items/client/requests/BulkCollectionItem.ts b/src/api/types/BulkCollectionItem.ts similarity index 68% rename from src/api/resources/collections/resources/items/client/requests/BulkCollectionItem.ts rename to src/api/types/BulkCollectionItem.ts index 5480c922..f2618ee6 100644 --- a/src/api/resources/collections/resources/items/client/requests/BulkCollectionItem.ts +++ b/src/api/types/BulkCollectionItem.ts @@ -2,13 +2,10 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as Webflow from "../../../../../../index"; +import * as Webflow from "../index"; /** - * @example - * { - * id: "580e64008c9a982ac9b8b754" - * } + * The fields that define the schema for a given Item are based on the Collection that Item belongs to. Beyond the user defined fields, there are a handful of additional fields that are automatically created for all items */ export interface BulkCollectionItem { /** Unique identifier for the Item */ @@ -25,5 +22,5 @@ export interface BulkCollectionItem { isArchived?: boolean; /** Boolean determining if the Item is set to draft */ isDraft?: boolean; - fieldData?: Webflow.collections.BulkCollectionItemFieldData; + fieldData?: Webflow.BulkCollectionItemFieldData; } diff --git a/src/api/resources/collections/resources/items/types/BulkCollectionItemFieldData.ts b/src/api/types/BulkCollectionItemFieldData.ts similarity index 100% rename from src/api/resources/collections/resources/items/types/BulkCollectionItemFieldData.ts rename to src/api/types/BulkCollectionItemFieldData.ts diff --git a/src/api/types/ConflictErrorBody.ts b/src/api/types/ConflictErrorBody.ts index 8479eb87..83105915 100644 --- a/src/api/types/ConflictErrorBody.ts +++ b/src/api/types/ConflictErrorBody.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type ConflictErrorBody = Webflow.DuplicateUserEmail | Webflow.UserLimitReached; +export interface ConflictErrorBody { + /** Error code */ + code?: "ecommerce_not_enabled"; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/DuplicateUserEmail.ts b/src/api/types/DuplicateUserEmail.ts index 13eacd9b..e714016e 100644 --- a/src/api/types/DuplicateUserEmail.ts +++ b/src/api/types/DuplicateUserEmail.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type DuplicateUserEmail = Webflow.Error_; +export interface DuplicateUserEmail { + /** Error code */ + code?: string; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/MissingScopes.ts b/src/api/types/MissingScopes.ts index 246e8df7..121a3a27 100644 --- a/src/api/types/MissingScopes.ts +++ b/src/api/types/MissingScopes.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type MissingScopes = Webflow.Error_; +export interface MissingScopes { + /** Error code */ + code?: "missing_scopes"; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/NotEnterprisePlanSite.ts b/src/api/types/NotEnterprisePlanSite.ts index a7e8beb2..23d6c370 100644 --- a/src/api/types/NotEnterprisePlanSite.ts +++ b/src/api/types/NotEnterprisePlanSite.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type NotEnterprisePlanSite = Webflow.Error_; +export interface NotEnterprisePlanSite { + /** Error code */ + code?: "missing_scopes"; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/Page.ts b/src/api/types/Page.ts index 9046a42b..4673fae9 100644 --- a/src/api/types/Page.ts +++ b/src/api/types/Page.ts @@ -9,7 +9,7 @@ import * as Webflow from "../index"; */ export interface Page { /** Unique identifier for the Page */ - id?: string; + id: string; /** Unique identifier for the Site */ siteId?: string; /** Title of the Page */ diff --git a/src/api/types/PageDetails.ts b/src/api/types/PageDetails.ts index f675071d..3954ac20 100644 --- a/src/api/types/PageDetails.ts +++ b/src/api/types/PageDetails.ts @@ -9,7 +9,7 @@ import * as Webflow from "../index"; */ export interface PageDetails { /** Unique identifier for the Page */ - id?: string; + id: string; /** Unique identifier for the Site */ siteId?: string; /** Title of the Page */ diff --git a/src/api/types/UserLimitReached.ts b/src/api/types/UserLimitReached.ts index 5e03d077..8e614bdd 100644 --- a/src/api/types/UserLimitReached.ts +++ b/src/api/types/UserLimitReached.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type UserLimitReached = Webflow.Error_; +export interface UserLimitReached { + /** Error code */ + code?: string; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/UsersNotEnabled.ts b/src/api/types/UsersNotEnabled.ts index 381e7beb..aa1d20a2 100644 --- a/src/api/types/UsersNotEnabled.ts +++ b/src/api/types/UsersNotEnabled.ts @@ -4,4 +4,13 @@ import * as Webflow from "../index"; -export type UsersNotEnabled = Webflow.Error_; +export interface UsersNotEnabled { + /** Error code */ + code?: string; + /** Error message */ + message?: string; + /** Link to more information */ + externalReference?: string; + /** Array of errors */ + details?: Webflow.ErrorDetailsItem[]; +} diff --git a/src/api/types/index.ts b/src/api/types/index.ts index ad6ecd4f..7e6bc072 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -3,6 +3,7 @@ export * from "./ForbiddenErrorBody"; export * from "./TooManyRequestsErrorBody"; export * from "./BadRequestErrorBody"; export * from "./ConflictErrorBody"; +export * from "./ErrorDetailsItem"; export * from "./AuthorizedUser"; export * from "./Application"; export * from "./AuthorizationAuthorizationAuthorizedTo"; @@ -21,7 +22,6 @@ export * from "./SiteActivityLogItemUser"; export * from "./SiteActivityLogItem"; export * from "./Pagination"; export * from "./SiteActivityLogResponse"; -export * from "./ErrorDetailsItem"; export * from "./Error_"; export * from "./MissingScopes"; export * from "./NotEnterprisePlanSite"; @@ -34,6 +34,8 @@ export * from "./CollectionItemFieldData"; export * from "./CollectionItem"; export * from "./CollectionItemListPagination"; export * from "./CollectionItemList"; +export * from "./BulkCollectionItemFieldData"; +export * from "./BulkCollectionItem"; export * from "./PageSeo"; export * from "./PageOpenGraph"; export * from "./Page"; diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index 51065681..d67bc042 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -1,6 +1,10 @@ -import qs from "qs"; -import { RUNTIME } from "../runtime"; import { APIResponse } from "./APIResponse"; +import { createRequestUrl } from "./createRequestUrl"; +import { getFetchFn } from "./getFetchFn"; +import { getRequestBody } from "./getRequestBody"; +import { getResponseBody } from "./getResponseBody"; +import { makeRequest } from "./makeRequest"; +import { requestWithRetries } from "./requestWithRetries"; export type FetchFunction = (args: Fetcher.Args) => Promise>; @@ -16,7 +20,9 @@ export declare namespace Fetcher { maxRetries?: number; withCredentials?: boolean; abortSignal?: AbortSignal; - responseType?: "json" | "blob" | "streaming" | "text"; + requestType?: "json" | "file" | "bytes"; + responseType?: "json" | "blob" | "sse" | "streaming" | "text"; + duplex?: "half"; } export type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError; @@ -43,11 +49,7 @@ export declare namespace Fetcher { } } -const INITIAL_RETRY_DELAY = 1; -const MAX_RETRY_DELAY = 60; -const DEFAULT_MAX_RETRIES = 2; - -async function fetcherImpl(args: Fetcher.Args): Promise> { +export async function fetcherImpl(args: Fetcher.Args): Promise> { const headers: Record = {}; if (args.body !== undefined && args.contentType != null) { headers["Content-Type"] = args.contentType; @@ -61,118 +63,35 @@ async function fetcherImpl(args: Fetcher.Args): Promise 0 - ? `${args.url}?${qs.stringify(args.queryParameters, { arrayFormat: "repeat" })}` - : args.url; - - let body: BodyInit | undefined = undefined; - const maybeStringifyBody = (body: any) => { - if (body instanceof Uint8Array) { - return body; - } else if (args.contentType === "application/x-www-form-urlencoded" && typeof args.body === "string") { - return args.body; - } else { - return JSON.stringify(body); - } - }; - - if (RUNTIME.type === "node") { - if (args.body instanceof (await import("formdata-node")).FormData) { - // @ts-expect-error - body = args.body; - } else { - body = maybeStringifyBody(args.body); - } - } else { - if (args.body instanceof (await import("form-data")).default) { - // @ts-expect-error - body = args.body; - } else { - body = maybeStringifyBody(args.body); - } - } - + const url = createRequestUrl(args.url, args.queryParameters); + let requestBody: BodyInit | undefined = await getRequestBody({ + body: args.body, + type: args.requestType === "json" ? "json" : "other", + }); const fetchFn = await getFetchFn(); - const makeRequest = async (): Promise => { - const signals: AbortSignal[] = []; - - // Add timeout signal - let timeoutAbortId: NodeJS.Timeout | undefined = undefined; - if (args.timeoutMs != null) { - const { signal, abortId } = getTimeoutSignal(args.timeoutMs); - timeoutAbortId = abortId; - signals.push(signal); - } - - // Add arbitrary signal - if (args.abortSignal != null) { - signals.push(args.abortSignal); - } - - const response = await fetchFn(url, { - method: args.method, - headers, - body, - signal: anySignal(signals), - credentials: args.withCredentials ? "include" : undefined, - }); - - if (timeoutAbortId != null) { - clearTimeout(timeoutAbortId); - } - - return response; - }; - try { - let response = await makeRequest(); - - for (let i = 0; i < (args.maxRetries ?? DEFAULT_MAX_RETRIES); ++i) { - if ( - response.status === 408 || - response.status === 409 || - response.status === 429 || - response.status >= 500 - ) { - const delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(i, 2), MAX_RETRY_DELAY); - await new Promise((resolve) => setTimeout(resolve, delay)); - response = await makeRequest(); - } else { - break; - } - } - - let body: unknown; - if (response.body != null && args.responseType === "blob") { - body = await response.blob(); - } else if (response.body != null && args.responseType === "streaming") { - body = response.body; - } else if (response.body != null && args.responseType === "text") { - body = await response.text(); - } else { - const text = await response.text(); - if (text.length > 0) { - try { - body = JSON.parse(text); - } catch (err) { - return { - ok: false, - error: { - reason: "non-json", - statusCode: response.status, - rawBody: text, - }, - }; - } - } - } + const response = await requestWithRetries( + async () => + makeRequest( + fetchFn, + url, + args.method, + headers, + requestBody, + args.timeoutMs, + args.abortSignal, + args.withCredentials, + args.duplex + ), + args.maxRetries + ); + let responseBody = await getResponseBody(response, args.responseType); if (response.status >= 200 && response.status < 400) { return { ok: true, - body: body as R, + body: responseBody as R, headers: response.headers, }; } else { @@ -181,7 +100,7 @@ async function fetcherImpl(args: Fetcher.Args): Promise(args: Fetcher.Args): Promise controller.abort(TIMEOUT), timeoutMs); - return { signal: controller.signal, abortId }; -} - -/** - * Returns an abort signal that is getting aborted when - * at least one of the specified abort signals is aborted. - * - * Requires at least node.js 18. - */ -function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal { - // Allowing signals to be passed either as array - // of signals or as multiple arguments. - const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args); - - const controller = new AbortController(); - - for (const signal of signals) { - if (signal.aborted) { - // Exiting early if one of the signals - // is already aborted. - controller.abort((signal as any)?.reason); - break; - } - - // Listening for signals and removing the listeners - // when at least one symbol is aborted. - signal.addEventListener("abort", () => controller.abort((signal as any)?.reason), { - signal: controller.signal, - }); - } - - return controller.signal; -} - -/** - * Returns a fetch function based on the runtime - */ -async function getFetchFn(): Promise { - // In Node.js environments, the SDK always uses`node-fetch`. - if (RUNTIME.type === "node") { - return (await import("node-fetch")).default as any; - } - - // Otherwise the SDK uses global fetch if available, - // and falls back to node-fetch. - if (typeof fetch == "function") { - return fetch; - } - - // Defaults to node `node-fetch` if global fetch isn't available - return (await import("node-fetch")).default as any; -} - export const fetcher: FetchFunction = fetcherImpl; diff --git a/src/core/fetcher/createRequestUrl.ts b/src/core/fetcher/createRequestUrl.ts new file mode 100644 index 00000000..9288a99b --- /dev/null +++ b/src/core/fetcher/createRequestUrl.ts @@ -0,0 +1,10 @@ +import qs from "qs"; + +export function createRequestUrl( + baseUrl: string, + queryParameters?: Record +): string { + return Object.keys(queryParameters ?? {}).length > 0 + ? `${baseUrl}?${qs.stringify(queryParameters, { arrayFormat: "repeat" })}` + : baseUrl; +} diff --git a/src/core/fetcher/getFetchFn.ts b/src/core/fetcher/getFetchFn.ts new file mode 100644 index 00000000..9fd9bfc4 --- /dev/null +++ b/src/core/fetcher/getFetchFn.ts @@ -0,0 +1,25 @@ +import { RUNTIME } from "../runtime"; + +/** + * Returns a fetch function based on the runtime + */ +export async function getFetchFn(): Promise { + // In Node.js 18+ environments, use native fetch + if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { + return fetch; + } + + // In Node.js 18 or lower environments, the SDK always uses`node-fetch`. + if (RUNTIME.type === "node") { + return (await import("node-fetch")).default as any; + } + + // Otherwise the SDK uses global fetch if available, + // and falls back to node-fetch. + if (typeof fetch == "function") { + return fetch; + } + + // Defaults to node `node-fetch` if global fetch isn't available + return (await import("node-fetch")).default as any; +} diff --git a/src/core/fetcher/getRequestBody.ts b/src/core/fetcher/getRequestBody.ts new file mode 100644 index 00000000..1138414b --- /dev/null +++ b/src/core/fetcher/getRequestBody.ts @@ -0,0 +1,14 @@ +export declare namespace GetRequestBody { + interface Args { + body: unknown; + type: "json" | "file" | "bytes" | "other"; + } +} + +export async function getRequestBody({ body, type }: GetRequestBody.Args): Promise { + if (type.includes("json")) { + return JSON.stringify(body); + } else { + return body as BodyInit; + } +} diff --git a/src/core/fetcher/getResponseBody.ts b/src/core/fetcher/getResponseBody.ts new file mode 100644 index 00000000..a7a9c508 --- /dev/null +++ b/src/core/fetcher/getResponseBody.ts @@ -0,0 +1,32 @@ +import { chooseStreamWrapper } from "./stream-wrappers/chooseStreamWrapper"; + +export async function getResponseBody(response: Response, responseType?: string): Promise { + if (response.body != null && responseType === "blob") { + return await response.blob(); + } else if (response.body != null && responseType === "sse") { + return response.body; + } else if (response.body != null && responseType === "streaming") { + return chooseStreamWrapper(response.body); + } else if (response.body != null && responseType === "text") { + return await response.text(); + } else { + const text = await response.text(); + if (text.length > 0) { + try { + let responseBody = JSON.parse(text); + return responseBody; + } catch (err) { + return { + ok: false, + error: { + reason: "non-json", + statusCode: response.status, + rawBody: text, + }, + }; + } + } else { + return undefined; + } + } +} diff --git a/src/core/fetcher/makeRequest.ts b/src/core/fetcher/makeRequest.ts new file mode 100644 index 00000000..8fb4bace --- /dev/null +++ b/src/core/fetcher/makeRequest.ts @@ -0,0 +1,44 @@ +import { anySignal, getTimeoutSignal } from "./signals"; + +export const makeRequest = async ( + fetchFn: (url: string, init: RequestInit) => Promise, + url: string, + method: string, + headers: Record, + requestBody: BodyInit | undefined, + timeoutMs?: number, + abortSignal?: AbortSignal, + withCredentials?: boolean, + duplex?: "half" +): Promise => { + const signals: AbortSignal[] = []; + + // Add timeout signal + let timeoutAbortId: NodeJS.Timeout | undefined = undefined; + if (timeoutMs != null) { + const { signal, abortId } = getTimeoutSignal(timeoutMs); + timeoutAbortId = abortId; + signals.push(signal); + } + + // Add arbitrary signal + if (abortSignal != null) { + signals.push(abortSignal); + } + let newSignals = anySignal(signals); + const response = await fetchFn(url, { + method: method, + headers, + body: requestBody, + signal: newSignals, + credentials: withCredentials ? "include" : undefined, + // @ts-ignore + duplex, + }); + + if (timeoutAbortId != null) { + clearTimeout(timeoutAbortId); + } + + return response; +}; diff --git a/src/core/fetcher/requestWithRetries.ts b/src/core/fetcher/requestWithRetries.ts new file mode 100644 index 00000000..ff5dc3bb --- /dev/null +++ b/src/core/fetcher/requestWithRetries.ts @@ -0,0 +1,21 @@ +const INITIAL_RETRY_DELAY = 1; +const MAX_RETRY_DELAY = 60; +const DEFAULT_MAX_RETRIES = 2; + +export async function requestWithRetries( + requestFn: () => Promise, + maxRetries: number = DEFAULT_MAX_RETRIES +): Promise { + let response: Response = await requestFn(); + + for (let i = 0; i < maxRetries; ++i) { + if ([408, 409, 429].includes(response.status) || response.status >= 500) { + const delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY); + await new Promise((resolve) => setTimeout(resolve, delay)); + response = await requestFn(); + } else { + break; + } + } + return response!; +} diff --git a/src/core/fetcher/signals.ts b/src/core/fetcher/signals.ts new file mode 100644 index 00000000..6c124ff7 --- /dev/null +++ b/src/core/fetcher/signals.ts @@ -0,0 +1,38 @@ +const TIMEOUT = "timeout"; + +export function getTimeoutSignal(timeoutMs: number): { signal: AbortSignal; abortId: NodeJS.Timeout } { + const controller = new AbortController(); + const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs); + return { signal: controller.signal, abortId }; +} + +/** + * Returns an abort signal that is getting aborted when + * at least one of the specified abort signals is aborted. + * + * Requires at least node.js 18. + */ +export function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal { + // Allowing signals to be passed either as array + // of signals or as multiple arguments. + const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args); + + const controller = new AbortController(); + + for (const signal of signals) { + if (signal.aborted) { + // Exiting early if one of the signals + // is already aborted. + controller.abort((signal as any)?.reason); + break; + } + + // Listening for signals and removing the listeners + // when at least one symbol is aborted. + signal.addEventListener("abort", () => controller.abort((signal as any)?.reason), { + signal: controller.signal, + }); + } + + return controller.signal; +} diff --git a/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts b/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts new file mode 100644 index 00000000..e5db8734 --- /dev/null +++ b/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts @@ -0,0 +1,252 @@ +import type { Writable } from "stream"; +import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; + +export class Node18UniversalStreamWrapper + implements + StreamWrapper | Writable | WritableStream, ReadFormat> +{ + private readableStream: ReadableStream; + private reader: ReadableStreamDefaultReader; + private events: Record; + private paused: boolean; + private resumeCallback: ((value?: unknown) => void) | null; + private encoding: string | null; + + constructor(readableStream: ReadableStream) { + this.readableStream = readableStream; + this.reader = this.readableStream.getReader(); + this.events = { + data: [], + end: [], + error: [], + readable: [], + close: [], + pause: [], + resume: [], + }; + this.paused = false; + this.resumeCallback = null; + this.encoding = null; + } + + public on(event: string, callback: EventCallback): void { + this.events[event]?.push(callback); + } + + public off(event: string, callback: EventCallback): void { + this.events[event] = this.events[event]?.filter((cb) => cb !== callback); + } + + public pipe( + dest: Node18UniversalStreamWrapper | Writable | WritableStream + ): Node18UniversalStreamWrapper | Writable | WritableStream { + this.on("data", async (chunk) => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._write(chunk); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.write(chunk).then(() => writer.releaseLock()); + } else { + dest.write(chunk); + } + }); + + this.on("end", async () => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._end(); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.close(); + } else { + dest.end(); + } + }); + + this.on("error", async (error) => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._error(error); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.abort(error); + } else { + dest.destroy(error); + } + }); + + this._startReading(); + + return dest; + } + + public pipeTo( + dest: Node18UniversalStreamWrapper | Writable | WritableStream + ): Node18UniversalStreamWrapper | Writable | WritableStream { + return this.pipe(dest); + } + + public unpipe(dest: Node18UniversalStreamWrapper | Writable | WritableStream): void { + this.off("data", async (chunk) => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._write(chunk); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.write(chunk).then(() => writer.releaseLock()); + } else { + dest.write(chunk); + } + }); + + this.off("end", async () => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._end(); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.close(); + } else { + dest.end(); + } + }); + + this.off("error", async (error) => { + if (dest instanceof Node18UniversalStreamWrapper) { + dest._error(error); + } else if (dest instanceof WritableStream) { + const writer = dest.getWriter(); + writer.abort(error); + } else { + dest.destroy(error); + } + }); + } + + public destroy(error?: Error): void { + this.reader + .cancel(error) + .then(() => { + this._emit("close"); + }) + .catch((err) => { + this._emit("error", err); + }); + } + + public pause(): void { + this.paused = true; + this._emit("pause"); + } + + public resume(): void { + if (this.paused) { + this.paused = false; + this._emit("resume"); + if (this.resumeCallback) { + this.resumeCallback(); + this.resumeCallback = null; + } + } + } + + public get isPaused(): boolean { + return this.paused; + } + + public async read(): Promise { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + + if (done) { + return undefined; + } + return value; + } + + public setEncoding(encoding: string): void { + this.encoding = encoding; + } + + public async text(): Promise { + const chunks: ReadFormat[] = []; + + while (true) { + const { done, value } = await this.reader.read(); + if (done) break; + if (value) chunks.push(value); + } + + const decoder = new TextDecoder(this.encoding || "utf-8"); + return decoder.decode(await new Blob(chunks).arrayBuffer()); + } + + public async json(): Promise { + const text = await this.text(); + return JSON.parse(text); + } + + private _write(chunk: ReadFormat): void { + this._emit("data", chunk); + } + + private _end(): void { + this._emit("end"); + } + + private _error(error: any): void { + this._emit("error", error); + } + + private _emit(event: string, data?: any): void { + if (this.events[event]) { + for (const callback of this.events[event] || []) { + callback(data); + } + } + } + + private async _startReading(): Promise { + try { + this._emit("readable"); + while (true) { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + if (done) { + this._emit("end"); + this._emit("close"); + break; + } + if (value) { + this._emit("data", value); + } + } + } catch (error) { + this._emit("error", error); + } + } + + [Symbol.asyncIterator](): AsyncIterableIterator { + return { + next: async () => { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + if (done) { + return { done: true, value: undefined }; + } + return { done: false, value }; + }, + [Symbol.asyncIterator]() { + return this; + }, + }; + } +} diff --git a/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts b/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts new file mode 100644 index 00000000..f9bead21 --- /dev/null +++ b/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts @@ -0,0 +1,106 @@ +import type { Readable, Writable } from "stream"; +import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; + +export class NodePre18StreamWrapper implements StreamWrapper { + private readableStream: Readable; + private encoding: string | undefined; + + constructor(readableStream: Readable) { + this.readableStream = readableStream; + } + + public on(event: string, callback: EventCallback): void { + this.readableStream.on(event, callback); + } + + public off(event: string, callback: EventCallback): void { + this.readableStream.off(event, callback); + } + + public pipe(dest: Writable): Writable { + this.readableStream.pipe(dest); + return dest; + } + + public pipeTo(dest: Writable): Writable { + return this.pipe(dest); + } + + public unpipe(dest?: Writable): void { + if (dest) { + this.readableStream.unpipe(dest); + } else { + this.readableStream.unpipe(); + } + } + + public destroy(error?: Error): void { + this.readableStream.destroy(error); + } + + public pause(): void { + this.readableStream.pause(); + } + + public resume(): void { + this.readableStream.resume(); + } + + public get isPaused(): boolean { + return this.readableStream.isPaused(); + } + + public async read(): Promise { + return new Promise((resolve, reject) => { + const chunk = this.readableStream.read(); + if (chunk) { + resolve(chunk); + } else { + this.readableStream.once("readable", () => { + const chunk = this.readableStream.read(); + resolve(chunk); + }); + this.readableStream.once("error", reject); + } + }); + } + + public setEncoding(encoding?: string): void { + this.readableStream.setEncoding(encoding as BufferEncoding); + this.encoding = encoding; + } + + public async text(): Promise { + const chunks: Uint8Array[] = []; + const encoder = new TextEncoder(); + this.readableStream.setEncoding((this.encoding || "utf-8") as BufferEncoding); + + for await (const chunk of this.readableStream) { + chunks.push(encoder.encode(chunk)); + } + + const decoder = new TextDecoder(this.encoding || "utf-8"); + return decoder.decode(Buffer.concat(chunks)); + } + + public async json(): Promise { + const text = await this.text(); + return JSON.parse(text); + } + + public [Symbol.asyncIterator](): AsyncIterableIterator { + const readableStream = this.readableStream; + const iterator = readableStream[Symbol.asyncIterator](); + + // Create and return an async iterator that yields buffers + return { + async next(): Promise> { + const { value, done } = await iterator.next(); + return { value: value as Buffer, done }; + }, + [Symbol.asyncIterator]() { + return this; + }, + }; + } +} diff --git a/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts b/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts new file mode 100644 index 00000000..7a52805d --- /dev/null +++ b/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts @@ -0,0 +1,239 @@ +import { StreamWrapper } from "./chooseStreamWrapper"; + +type EventCallback = (data?: any) => void; + +export class UndiciStreamWrapper + implements StreamWrapper | WritableStream, ReadFormat> +{ + private readableStream: ReadableStream; + private reader: ReadableStreamDefaultReader; + private events: Record; + private paused: boolean; + private resumeCallback: ((value?: unknown) => void) | null; + private encoding: string | null; + + constructor(readableStream: ReadableStream) { + this.readableStream = readableStream; + this.reader = this.readableStream.getReader(); + this.events = { + data: [], + end: [], + error: [], + readable: [], + close: [], + pause: [], + resume: [], + }; + this.paused = false; + this.resumeCallback = null; + this.encoding = null; + } + + public on(event: string, callback: EventCallback): void { + this.events[event]?.push(callback); + } + + public off(event: string, callback: EventCallback): void { + this.events[event] = this.events[event]?.filter((cb) => cb !== callback); + } + + public pipe( + dest: UndiciStreamWrapper | WritableStream + ): UndiciStreamWrapper | WritableStream { + this.on("data", (chunk) => { + if (dest instanceof UndiciStreamWrapper) { + dest._write(chunk); + } else { + const writer = dest.getWriter(); + writer.write(chunk).then(() => writer.releaseLock()); + } + }); + + this.on("end", () => { + if (dest instanceof UndiciStreamWrapper) { + dest._end(); + } else { + const writer = dest.getWriter(); + writer.close(); + } + }); + + this.on("error", (error) => { + if (dest instanceof UndiciStreamWrapper) { + dest._error(error); + } else { + const writer = dest.getWriter(); + writer.abort(error); + } + }); + + this._startReading(); + + return dest; + } + + public pipeTo( + dest: UndiciStreamWrapper | WritableStream + ): UndiciStreamWrapper | WritableStream { + return this.pipe(dest); + } + + public unpipe(dest: UndiciStreamWrapper | WritableStream): void { + this.off("data", (chunk) => { + if (dest instanceof UndiciStreamWrapper) { + dest._write(chunk); + } else { + const writer = dest.getWriter(); + writer.write(chunk).then(() => writer.releaseLock()); + } + }); + + this.off("end", () => { + if (dest instanceof UndiciStreamWrapper) { + dest._end(); + } else { + const writer = dest.getWriter(); + writer.close(); + } + }); + + this.off("error", (error) => { + if (dest instanceof UndiciStreamWrapper) { + dest._error(error); + } else { + const writer = dest.getWriter(); + writer.abort(error); + } + }); + } + + public destroy(error?: Error): void { + this.reader + .cancel(error) + .then(() => { + this._emit("close"); + }) + .catch((err) => { + this._emit("error", err); + }); + } + + public pause(): void { + this.paused = true; + this._emit("pause"); + } + + public resume(): void { + if (this.paused) { + this.paused = false; + this._emit("resume"); + if (this.resumeCallback) { + this.resumeCallback(); + this.resumeCallback = null; + } + } + } + + public get isPaused(): boolean { + return this.paused; + } + + public async read(): Promise { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + if (done) { + return undefined; + } + return value; + } + + public setEncoding(encoding: string): void { + this.encoding = encoding; + } + + public async text(): Promise { + const chunks: BlobPart[] = []; + + while (true) { + const { done, value } = await this.reader.read(); + if (done) break; + if (value) chunks.push(value); + } + + const decoder = new TextDecoder(this.encoding || "utf-8"); + return decoder.decode(await new Blob(chunks).arrayBuffer()); + } + + public async json(): Promise { + const text = await this.text(); + return JSON.parse(text); + } + + private _write(chunk: ReadFormat): void { + this._emit("data", chunk); + } + + private _end(): void { + this._emit("end"); + } + + private _error(error: any): void { + this._emit("error", error); + } + + private _emit(event: string, data?: any): void { + if (this.events[event]) { + for (const callback of this.events[event] || []) { + callback(data); + } + } + } + + private async _startReading(): Promise { + try { + this._emit("readable"); + while (true) { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + if (done) { + this._emit("end"); + this._emit("close"); + break; + } + if (value) { + this._emit("data", value); + } + } + } catch (error) { + this._emit("error", error); + } + } + + [Symbol.asyncIterator](): AsyncIterableIterator { + return { + next: async () => { + if (this.paused) { + await new Promise((resolve) => { + this.resumeCallback = resolve; + }); + } + const { done, value } = await this.reader.read(); + if (done) { + return { done: true, value: undefined }; + } + return { done: false, value }; + }, + [Symbol.asyncIterator]() { + return this; + }, + }; + } +} diff --git a/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts b/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts new file mode 100644 index 00000000..d60991da --- /dev/null +++ b/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts @@ -0,0 +1,33 @@ +import type { Readable } from "stream"; +import { RUNTIME } from "../../runtime"; + +export type EventCallback = (data?: any) => void; + +export interface StreamWrapper { + setEncoding(encoding?: string): void; + on(event: string, callback: EventCallback): void; + off(event: string, callback: EventCallback): void; + pipe(dest: WritableStream): WritableStream; + pipeTo(dest: WritableStream): WritableStream; + unpipe(dest?: WritableStream): void; + destroy(error?: Error): void; + pause(): void; + resume(): void; + get isPaused(): boolean; + read(): Promise; + text(): Promise; + json(): Promise; + [Symbol.asyncIterator](): AsyncIterableIterator; +} + +export async function chooseStreamWrapper(responseBody: any): Promise>> { + if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { + return new (await import("./Node18UniversalStreamWrapper")).Node18UniversalStreamWrapper( + responseBody as ReadableStream + ); + } else if (RUNTIME.type !== "node" && typeof fetch == "function") { + return new (await import("./UndiciStreamWrapper")).UndiciStreamWrapper(responseBody as ReadableStream); + } else { + return new (await import("./NodePre18StreamWrapper")).NodePre18StreamWrapper(responseBody as Readable); + } +} diff --git a/src/core/runtime/runtime.ts b/src/core/runtime/runtime.ts index 30fe0779..4d0687e8 100644 --- a/src/core/runtime/runtime.ts +++ b/src/core/runtime/runtime.ts @@ -69,6 +69,7 @@ export const RUNTIME: Runtime = evaluateRuntime(); export interface Runtime { type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd"; version?: string; + parsedVersion?: number; } function evaluateRuntime(): Runtime { @@ -109,6 +110,7 @@ function evaluateRuntime(): Runtime { return { type: "node", version: process.versions.node, + parsedVersion: Number(process.versions.node.split(".")[0]), }; } diff --git a/src/core/schemas/Schema.ts b/src/core/schemas/Schema.ts index 870f373b..19acc5dc 100644 --- a/src/core/schemas/Schema.ts +++ b/src/core/schemas/Schema.ts @@ -1,5 +1,4 @@ import { SchemaUtils } from "./builders"; -import { MaybePromise } from "./utils/MaybePromise"; export type Schema = BaseSchema & SchemaUtils; @@ -7,9 +6,9 @@ export type inferRaw = S extends Schema ? Raw export type inferParsed = S extends Schema ? Parsed : never; export interface BaseSchema { - parse: (raw: unknown, opts?: SchemaOptions) => MaybePromise>; - json: (parsed: unknown, opts?: SchemaOptions) => MaybePromise>; - getType: () => SchemaType | Promise; + parse: (raw: unknown, opts?: SchemaOptions) => MaybeValid; + json: (parsed: unknown, opts?: SchemaOptions) => MaybeValid; + getType: () => SchemaType | SchemaType; } export const SchemaType = { @@ -91,4 +90,9 @@ export interface SchemaOptions { * helpful for zurg's internal debug logging. */ breadcrumbsPrefix?: string[]; + + /** + * whether to send 'null' for optional properties explicitly set to 'undefined'. + */ + omitUndefined?: boolean; } diff --git a/src/core/schemas/builders/lazy/lazy.ts b/src/core/schemas/builders/lazy/lazy.ts index a665472d..835c61f8 100644 --- a/src/core/schemas/builders/lazy/lazy.ts +++ b/src/core/schemas/builders/lazy/lazy.ts @@ -1,7 +1,7 @@ import { BaseSchema, Schema } from "../../Schema"; import { getSchemaUtils } from "../schema-utils"; -export type SchemaGetter> = () => SchemaType | Promise; +export type SchemaGetter> = () => SchemaType; export function lazy(getter: SchemaGetter>): Schema { const baseSchema = constructLazyBaseSchema(getter); @@ -15,20 +15,18 @@ export function constructLazyBaseSchema( getter: SchemaGetter> ): BaseSchema { return { - parse: async (raw, opts) => (await getMemoizedSchema(getter)).parse(raw, opts), - json: async (parsed, opts) => (await getMemoizedSchema(getter)).json(parsed, opts), - getType: async () => (await getMemoizedSchema(getter)).getType(), + parse: (raw, opts) => getMemoizedSchema(getter).parse(raw, opts), + json: (parsed, opts) => getMemoizedSchema(getter).json(parsed, opts), + getType: () => getMemoizedSchema(getter).getType(), }; } type MemoizedGetter> = SchemaGetter & { __zurg_memoized?: SchemaType }; -export async function getMemoizedSchema>( - getter: SchemaGetter -): Promise { +export function getMemoizedSchema>(getter: SchemaGetter): SchemaType { const castedGetter = getter as MemoizedGetter; if (castedGetter.__zurg_memoized == null) { - castedGetter.__zurg_memoized = await getter(); + castedGetter.__zurg_memoized = getter(); } return castedGetter.__zurg_memoized; } diff --git a/src/core/schemas/builders/lazy/lazyObject.ts b/src/core/schemas/builders/lazy/lazyObject.ts index e48c0166..38c9e284 100644 --- a/src/core/schemas/builders/lazy/lazyObject.ts +++ b/src/core/schemas/builders/lazy/lazyObject.ts @@ -7,8 +7,8 @@ import { constructLazyBaseSchema, getMemoizedSchema, SchemaGetter } from "./lazy export function lazyObject(getter: SchemaGetter>): ObjectSchema { const baseSchema: BaseObjectSchema = { ...constructLazyBaseSchema(getter), - _getRawProperties: async () => (await getMemoizedSchema(getter))._getRawProperties(), - _getParsedProperties: async () => (await getMemoizedSchema(getter))._getParsedProperties(), + _getRawProperties: () => getMemoizedSchema(getter)._getRawProperties(), + _getParsedProperties: () => getMemoizedSchema(getter)._getParsedProperties(), }; return { diff --git a/src/core/schemas/builders/list/list.ts b/src/core/schemas/builders/list/list.ts index b333321b..e4c5c4a4 100644 --- a/src/core/schemas/builders/list/list.ts +++ b/src/core/schemas/builders/list/list.ts @@ -1,12 +1,11 @@ import { BaseSchema, MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; -import { MaybePromise } from "../../utils/MaybePromise"; import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; import { getSchemaUtils } from "../schema-utils"; export function list(schema: Schema): Schema { const baseSchema: BaseSchema = { - parse: async (raw, opts) => + parse: (raw, opts) => validateAndTransformArray(raw, (item, index) => schema.parse(item, { ...opts, @@ -29,10 +28,10 @@ export function list(schema: Schema): Schema( +function validateAndTransformArray( value: unknown, - transformItem: (item: Raw, index: number) => MaybePromise> -): Promise> { + transformItem: (item: Raw, index: number) => MaybeValid +): MaybeValid { if (!Array.isArray(value)) { return { ok: false, @@ -45,7 +44,7 @@ async function validateAndTransformArray( }; } - const maybeValidItems = await Promise.all(value.map((item, index) => transformItem(item, index))); + const maybeValidItems = value.map((item, index) => transformItem(item, index)); return maybeValidItems.reduce>( (acc, item) => { diff --git a/src/core/schemas/builders/object-like/getObjectLikeUtils.ts b/src/core/schemas/builders/object-like/getObjectLikeUtils.ts index 270ea170..8331d08d 100644 --- a/src/core/schemas/builders/object-like/getObjectLikeUtils.ts +++ b/src/core/schemas/builders/object-like/getObjectLikeUtils.ts @@ -20,8 +20,8 @@ export function withParsedProperties Properties[K]) } ): ObjectLikeSchema { const objectSchema: BaseSchema = { - parse: async (raw, opts) => { - const parsedObject = await objectLike.parse(raw, opts); + parse: (raw, opts) => { + const parsedObject = objectLike.parse(raw, opts); if (!parsedObject.ok) { return parsedObject; } diff --git a/src/core/schemas/builders/object/object.ts b/src/core/schemas/builders/object/object.ts index 6427678b..e00136d7 100644 --- a/src/core/schemas/builders/object/object.ts +++ b/src/core/schemas/builders/object/object.ts @@ -4,7 +4,6 @@ import { filterObject } from "../../utils/filterObject"; import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; import { isPlainObject } from "../../utils/isPlainObject"; import { keys } from "../../utils/keys"; -import { MaybePromise } from "../../utils/MaybePromise"; import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; import { partition } from "../../utils/partition"; import { getObjectLikeUtils } from "../object-like"; @@ -34,15 +33,12 @@ export function object > = { _getRawProperties: () => - Promise.resolve( - Object.entries(schemas).map(([parsedKey, propertySchema]) => - isProperty(propertySchema) ? propertySchema.rawKey : parsedKey - ) as unknown as (keyof inferRawObjectFromPropertySchemas)[] - ), - _getParsedProperties: () => - Promise.resolve(keys(schemas) as unknown as (keyof inferParsedObjectFromPropertySchemas)[]), + Object.entries(schemas).map(([parsedKey, propertySchema]) => + isProperty(propertySchema) ? propertySchema.rawKey : parsedKey + ) as unknown as (keyof inferRawObjectFromPropertySchemas)[], + _getParsedProperties: () => keys(schemas) as unknown as (keyof inferParsedObjectFromPropertySchemas)[], - parse: async (raw, opts) => { + parse: (raw, opts) => { const rawKeyToProperty: Record = {}; const requiredKeys: string[] = []; @@ -85,10 +81,11 @@ export function object { + json: (parsed, opts) => { const requiredKeys: string[] = []; for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) { @@ -106,9 +103,7 @@ export function object MaybePromise> } - | undefined => { + ): { transformedKey: string; transform: (propertyValue: unknown) => MaybeValid } | undefined => { const property = schemas[parsedKey as keyof T]; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition @@ -139,6 +134,7 @@ export function object({ +function validateAndTransformObject({ value, requiredKeys, getProperty, @@ -165,11 +161,12 @@ async function validateAndTransformObject({ requiredKeys: string[]; getProperty: ( preTransformedKey: string - ) => { transformedKey: string; transform: (propertyValue: unknown) => MaybePromise> } | undefined; + ) => { transformedKey: string; transform: (propertyValue: unknown) => MaybeValid } | undefined; unrecognizedObjectKeys: "fail" | "passthrough" | "strip" | undefined; skipValidation: boolean | undefined; breadcrumbsPrefix: string[] | undefined; -}): Promise> { + omitUndefined: boolean | undefined; +}): MaybeValid { if (!isPlainObject(value)) { return { ok: false, @@ -192,7 +189,7 @@ async function validateAndTransformObject({ if (property != null) { missingRequiredKeys.delete(preTransformedKey); - const value = await property.transform(preTransformedItemValue); + const value = property.transform(preTransformedItemValue); if (value.ok) { transformed[property.transformedKey] = value.value; } else { @@ -242,25 +239,19 @@ export function getObjectUtils(schema: BaseObjectSchema(extension: ObjectSchema) => { const baseSchema: BaseObjectSchema = { - _getParsedProperties: async () => [ - ...(await schema._getParsedProperties()), - ...(await extension._getParsedProperties()), - ], - _getRawProperties: async () => [ - ...(await schema._getRawProperties()), - ...(await extension._getRawProperties()), - ], - parse: async (raw, opts) => { + _getParsedProperties: () => [...schema._getParsedProperties(), ...extension._getParsedProperties()], + _getRawProperties: () => [...schema._getRawProperties(), ...extension._getRawProperties()], + parse: (raw, opts) => { return validateAndTransformExtendedObject({ - extensionKeys: await extension._getRawProperties(), + extensionKeys: extension._getRawProperties(), value: raw, transformBase: (rawBase) => schema.parse(rawBase, opts), transformExtension: (rawExtension) => extension.parse(rawExtension, opts), }); }, - json: async (parsed, opts) => { + json: (parsed, opts) => { return validateAndTransformExtendedObject({ - extensionKeys: await extension._getParsedProperties(), + extensionKeys: extension._getParsedProperties(), value: parsed, transformBase: (parsedBase) => schema.json(parsedBase, opts), transformExtension: (parsedExtension) => extension.json(parsedExtension, opts), @@ -279,7 +270,7 @@ export function getObjectUtils(schema: BaseObjectSchema({ +function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, @@ -287,16 +278,16 @@ async function validateAndTransformExtendedObject MaybePromise>; - transformExtension: (value: unknown) => MaybePromise>; -}): Promise> { + transformBase: (value: unknown) => MaybeValid; + transformExtension: (value: unknown) => MaybeValid; +}): MaybeValid { const extensionPropertiesSet = new Set(extensionKeys); const [extensionProperties, baseProperties] = partition(keys(value), (key) => extensionPropertiesSet.has(key as keyof PreTransformedExtension) ); - const transformedBase = await transformBase(filterObject(value, baseProperties)); - const transformedExtension = await transformExtension(filterObject(value, extensionProperties)); + const transformedBase = transformBase(filterObject(value, baseProperties)); + const transformedExtension = transformExtension(filterObject(value, extensionProperties)); if (transformedBase.ok && transformedExtension.ok) { return { diff --git a/src/core/schemas/builders/object/types.ts b/src/core/schemas/builders/object/types.ts index 17cff4f8..de9bb407 100644 --- a/src/core/schemas/builders/object/types.ts +++ b/src/core/schemas/builders/object/types.ts @@ -10,8 +10,8 @@ export type ObjectSchema = BaseObjectSchema & SchemaUtils; export interface BaseObjectSchema extends BaseSchema { - _getRawProperties: () => Promise<(keyof Raw)[]>; - _getParsedProperties: () => Promise<(keyof Parsed)[]>; + _getRawProperties: () => (keyof Raw)[]; + _getParsedProperties: () => (keyof Parsed)[]; } export interface ObjectUtils { diff --git a/src/core/schemas/builders/record/record.ts b/src/core/schemas/builders/record/record.ts index ac1cd22a..6683ac36 100644 --- a/src/core/schemas/builders/record/record.ts +++ b/src/core/schemas/builders/record/record.ts @@ -2,7 +2,6 @@ import { MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema"; import { entries } from "../../utils/entries"; import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; import { isPlainObject } from "../../utils/isPlainObject"; -import { MaybePromise } from "../../utils/MaybePromise"; import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; import { getSchemaUtils } from "../schema-utils"; import { BaseRecordSchema, RecordSchema } from "./types"; @@ -12,10 +11,10 @@ export function record ): RecordSchema { const baseSchema: BaseRecordSchema = { - parse: async (raw, opts) => { + parse: (raw, opts) => { return validateAndTransformRecord({ value: raw, - isKeyNumeric: (await keySchema.getType()) === SchemaType.NUMBER, + isKeyNumeric: keySchema.getType() === SchemaType.NUMBER, transformKey: (key) => keySchema.parse(key, { ...opts, @@ -29,10 +28,10 @@ export function record { + json: (parsed, opts) => { return validateAndTransformRecord({ value: parsed, - isKeyNumeric: (await keySchema.getType()) === SchemaType.NUMBER, + isKeyNumeric: keySchema.getType() === SchemaType.NUMBER, transformKey: (key) => keySchema.json(key, { ...opts, @@ -55,7 +54,7 @@ export function record({ +function validateAndTransformRecord({ value, isKeyNumeric, transformKey, @@ -64,10 +63,10 @@ async function validateAndTransformRecord MaybePromise>; - transformValue: (value: unknown, key: string | number) => MaybePromise>; + transformKey: (key: string | number) => MaybeValid; + transformValue: (value: unknown, key: string | number) => MaybeValid; breadcrumbsPrefix: string[] | undefined; -}): Promise>> { +}): MaybeValid> { if (!isPlainObject(value)) { return { ok: false, @@ -80,14 +79,14 @@ async function validateAndTransformRecord>>>( - async (accPromise, [stringKey, value]) => { + return entries(value).reduce>>( + (accPromise, [stringKey, value]) => { // skip nullish keys if (value == null) { return accPromise; } - const acc = await accPromise; + const acc = accPromise; let key: string | number = stringKey; if (isKeyNumeric) { @@ -96,9 +95,9 @@ async function validateAndTransformRecord }) + { ok: true, value: {} as Record } ); } diff --git a/src/core/schemas/builders/schema-utils/getSchemaUtils.ts b/src/core/schemas/builders/schema-utils/getSchemaUtils.ts index 0c0d379d..79ecad92 100644 --- a/src/core/schemas/builders/schema-utils/getSchemaUtils.ts +++ b/src/core/schemas/builders/schema-utils/getSchemaUtils.ts @@ -5,8 +5,8 @@ import { ParseError } from "./ParseError"; export interface SchemaUtils { optional: () => Schema; transform: (transformer: SchemaTransformer) => Schema; - parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Promise; - jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Promise; + parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Parsed; + jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Raw; } export interface SchemaTransformer { @@ -18,15 +18,15 @@ export function getSchemaUtils(schema: BaseSchema): Sc return { optional: () => optional(schema), transform: (transformer) => transform(schema, transformer), - parseOrThrow: async (raw, opts) => { - const parsed = await schema.parse(raw, opts); + parseOrThrow: (raw, opts) => { + const parsed = schema.parse(raw, opts); if (parsed.ok) { return parsed.value; } throw new ParseError(parsed.errors); }, - jsonOrThrow: async (parsed, opts) => { - const raw = await schema.json(parsed, opts); + jsonOrThrow: (parsed, opts) => { + const raw = schema.json(parsed, opts); if (raw.ok) { return raw.value; } @@ -53,6 +53,12 @@ export function optional( return schema.parse(raw, opts); }, json: (parsed, opts) => { + if (opts?.omitUndefined && parsed === undefined) { + return { + ok: true, + value: undefined, + }; + } if (parsed == null) { return { ok: true, @@ -75,8 +81,8 @@ export function transform( transformer: SchemaTransformer ): Schema { const baseSchema: BaseSchema = { - parse: async (raw, opts) => { - const parsed = await schema.parse(raw, opts); + parse: (raw, opts) => { + const parsed = schema.parse(raw, opts); if (!parsed.ok) { return parsed; } @@ -85,8 +91,8 @@ export function transform( value: transformer.transform(parsed.value), }; }, - json: async (transformed, opts) => { - const parsed = await transformer.untransform(transformed); + json: (transformed, opts) => { + const parsed = transformer.untransform(transformed); return schema.json(parsed, opts); }, getType: () => schema.getType(), diff --git a/src/core/schemas/builders/set/set.ts b/src/core/schemas/builders/set/set.ts index 3113bcba..e9e6bb7e 100644 --- a/src/core/schemas/builders/set/set.ts +++ b/src/core/schemas/builders/set/set.ts @@ -7,8 +7,8 @@ import { getSchemaUtils } from "../schema-utils"; export function set(schema: Schema): Schema> { const listSchema = list(schema); const baseSchema: BaseSchema> = { - parse: async (raw, opts) => { - const parsedList = await listSchema.parse(raw, opts); + parse: (raw, opts) => { + const parsedList = listSchema.parse(raw, opts); if (parsedList.ok) { return { ok: true, @@ -18,7 +18,7 @@ export function set(schema: Schema): Schema { + json: (parsed, opts) => { if (!(parsed instanceof Set)) { return { ok: false, @@ -30,7 +30,7 @@ export function set(schema: Schema): Schema SchemaType.SET, diff --git a/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts b/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts index 771dc6a7..21ed3df0 100644 --- a/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts +++ b/src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts @@ -1,5 +1,4 @@ import { BaseSchema, MaybeValid, Schema, SchemaOptions, SchemaType, ValidationError } from "../../Schema"; -import { MaybePromise } from "../../utils/MaybePromise"; import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; import { getSchemaUtils } from "../schema-utils"; import { inferParsedUnidiscriminatedUnionSchema, inferRawUnidiscriminatedUnionSchema } from "./types"; @@ -11,14 +10,14 @@ export function undiscriminatedUnion, ...Schem inferRawUnidiscriminatedUnionSchema, inferParsedUnidiscriminatedUnionSchema > = { - parse: async (raw, opts) => { + parse: (raw, opts) => { return validateAndTransformUndiscriminatedUnion>( (schema, opts) => schema.parse(raw, opts), schemas, opts ); }, - json: async (parsed, opts) => { + json: (parsed, opts) => { return validateAndTransformUndiscriminatedUnion>( (schema, opts) => schema.json(parsed, opts), schemas, @@ -34,14 +33,14 @@ export function undiscriminatedUnion, ...Schem }; } -async function validateAndTransformUndiscriminatedUnion( - transform: (schema: Schema, opts: SchemaOptions) => MaybePromise>, +function validateAndTransformUndiscriminatedUnion( + transform: (schema: Schema, opts: SchemaOptions) => MaybeValid, schemas: Schema[], opts: SchemaOptions | undefined -): Promise> { +): MaybeValid { const errors: ValidationError[] = []; for (const [index, schema] of schemas.entries()) { - const transformed = await transform(schema, { ...opts, skipValidation: false }); + const transformed = transform(schema, { ...opts, skipValidation: false }); if (transformed.ok) { return transformed; } else { diff --git a/src/core/schemas/builders/union/union.ts b/src/core/schemas/builders/union/union.ts index ed659beb..ab61475a 100644 --- a/src/core/schemas/builders/union/union.ts +++ b/src/core/schemas/builders/union/union.ts @@ -2,7 +2,6 @@ import { BaseSchema, MaybeValid, SchemaType } from "../../Schema"; import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType"; import { isPlainObject } from "../../utils/isPlainObject"; import { keys } from "../../utils/keys"; -import { MaybePromise } from "../../utils/MaybePromise"; import { maybeSkipValidation } from "../../utils/maybeSkipValidation"; import { enum_ } from "../enum"; import { ObjectSchema } from "../object"; @@ -25,7 +24,7 @@ export function union, U extends Union const discriminantValueSchema = enum_(keys(union) as string[]); const baseSchema: BaseSchema, inferParsedUnion> = { - parse: async (raw, opts) => { + parse: (raw, opts) => { return transformAndValidateUnion({ value: raw, discriminant: rawDiscriminant, @@ -42,7 +41,7 @@ export function union, U extends Union breadcrumbsPrefix: opts?.breadcrumbsPrefix, }); }, - json: async (parsed, opts) => { + json: (parsed, opts) => { return transformAndValidateUnion({ value: parsed, discriminant: parsedDiscriminant, @@ -69,7 +68,7 @@ export function union, U extends Union }; } -async function transformAndValidateUnion< +function transformAndValidateUnion< TransformedDiscriminant extends string, TransformedDiscriminantValue extends string, TransformedAdditionalProperties @@ -86,17 +85,15 @@ async function transformAndValidateUnion< value: unknown; discriminant: string; transformedDiscriminant: TransformedDiscriminant; - transformDiscriminantValue: (discriminantValue: unknown) => MaybePromise>; + transformDiscriminantValue: (discriminantValue: unknown) => MaybeValid; getAdditionalPropertiesSchema: (discriminantValue: string) => ObjectSchema | undefined; allowUnrecognizedUnionMembers: boolean | undefined; transformAdditionalProperties: ( additionalProperties: unknown, additionalPropertiesSchema: ObjectSchema - ) => MaybePromise>; + ) => MaybeValid; breadcrumbsPrefix: string[] | undefined; -}): Promise< - MaybeValid & TransformedAdditionalProperties> -> { +}): MaybeValid & TransformedAdditionalProperties> { if (!isPlainObject(value)) { return { ok: false, @@ -123,7 +120,7 @@ async function transformAndValidateUnion< }; } - const transformedDiscriminantValue = await transformDiscriminantValue(discriminantValue); + const transformedDiscriminantValue = transformDiscriminantValue(discriminantValue); if (!transformedDiscriminantValue.ok) { return { ok: false, @@ -155,7 +152,7 @@ async function transformAndValidateUnion< } } - const transformedAdditionalProperties = await transformAdditionalProperties( + const transformedAdditionalProperties = transformAdditionalProperties( additionalProperties, additionalPropertiesSchema ); diff --git a/src/core/schemas/utils/maybeSkipValidation.ts b/src/core/schemas/utils/maybeSkipValidation.ts index 99c02c32..86c07abf 100644 --- a/src/core/schemas/utils/maybeSkipValidation.ts +++ b/src/core/schemas/utils/maybeSkipValidation.ts @@ -1,5 +1,4 @@ import { BaseSchema, MaybeValid, SchemaOptions } from "../Schema"; -import { MaybePromise } from "./MaybePromise"; export function maybeSkipValidation, Raw, Parsed>(schema: S): S { return { @@ -10,10 +9,10 @@ export function maybeSkipValidation, Raw, Pars } function transformAndMaybeSkipValidation( - transform: (value: unknown, opts?: SchemaOptions) => MaybePromise> -): (value: unknown, opts?: SchemaOptions) => MaybePromise> { - return async (value, opts): Promise> => { - const transformed = await transform(value, opts); + transform: (value: unknown, opts?: SchemaOptions) => MaybeValid +): (value: unknown, opts?: SchemaOptions) => MaybeValid { + return (value, opts): MaybeValid => { + const transformed = transform(value, opts); const { skipValidation = false } = opts ?? {}; if (!transformed.ok && skipValidation) { // eslint-disable-next-line no-console diff --git a/src/serialization/resources/collections/resources/items/client/requests/index.ts b/src/serialization/resources/collections/resources/items/client/requests/index.ts index a28fc03e..a1b783c7 100644 --- a/src/serialization/resources/collections/resources/items/client/requests/index.ts +++ b/src/serialization/resources/collections/resources/items/client/requests/index.ts @@ -1,2 +1 @@ -export { BulkCollectionItem } from "./BulkCollectionItem"; export { ItemsPublishItemRequest } from "./ItemsPublishItemRequest"; diff --git a/src/serialization/resources/collections/resources/items/types/ItemsPublishItemResponse.ts b/src/serialization/resources/collections/resources/items/types/ItemsPublishItemResponse.ts new file mode 100644 index 00000000..70e6cc73 --- /dev/null +++ b/src/serialization/resources/collections/resources/items/types/ItemsPublishItemResponse.ts @@ -0,0 +1,22 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../../../index"; +import * as Webflow from "../../../../../../api/index"; +import * as core from "../../../../../../core"; + +export const ItemsPublishItemResponse: core.serialization.ObjectSchema< + serializers.collections.ItemsPublishItemResponse.Raw, + Webflow.collections.ItemsPublishItemResponse +> = core.serialization.object({ + publishedItemIds: core.serialization.list(core.serialization.string()).optional(), + errors: core.serialization.list(core.serialization.string()).optional(), +}); + +export declare namespace ItemsPublishItemResponse { + interface Raw { + publishedItemIds?: string[] | null; + errors?: string[] | null; + } +} diff --git a/src/serialization/resources/collections/resources/items/types/index.ts b/src/serialization/resources/collections/resources/items/types/index.ts index dcde450b..dce8a6ed 100644 --- a/src/serialization/resources/collections/resources/items/types/index.ts +++ b/src/serialization/resources/collections/resources/items/types/index.ts @@ -2,4 +2,4 @@ export * from "./ItemsListItemsRequestSortBy"; export * from "./ItemsListItemsRequestSortOrder"; export * from "./ItemsListItemsLiveRequestSortBy"; export * from "./ItemsListItemsLiveRequestSortOrder"; -export * from "./BulkCollectionItemFieldData"; +export * from "./ItemsPublishItemResponse"; diff --git a/src/serialization/resources/index.ts b/src/serialization/resources/index.ts index a0e25145..3faaed22 100644 --- a/src/serialization/resources/index.ts +++ b/src/serialization/resources/index.ts @@ -1,3 +1,5 @@ +export * as sites from "./sites"; +export * from "./sites/types"; export * as collections from "./collections"; export * as pages from "./pages"; export * from "./pages/types"; @@ -11,7 +13,6 @@ export * as orders from "./orders"; export * from "./orders/types"; export * as inventory from "./inventory"; export * from "./inventory/types"; -export * as sites from "./sites"; export * from "./sites/client/requests"; export * from "./collections/client/requests"; export * from "./pages/client/requests"; diff --git a/src/serialization/resources/sites/index.ts b/src/serialization/resources/sites/index.ts index 5ec76921..c9240f83 100644 --- a/src/serialization/resources/sites/index.ts +++ b/src/serialization/resources/sites/index.ts @@ -1 +1,2 @@ +export * from "./types"; export * from "./client"; diff --git a/src/serialization/resources/sites/types/SitesPublishResponse.ts b/src/serialization/resources/sites/types/SitesPublishResponse.ts new file mode 100644 index 00000000..e51c1c25 --- /dev/null +++ b/src/serialization/resources/sites/types/SitesPublishResponse.ts @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as serializers from "../../../index"; +import * as Webflow from "../../../../api/index"; +import * as core from "../../../../core"; +import { Domain } from "../../../types/Domain"; + +export const SitesPublishResponse: core.serialization.ObjectSchema< + serializers.SitesPublishResponse.Raw, + Webflow.SitesPublishResponse +> = core.serialization.object({ + customDomains: core.serialization.list(Domain).optional(), + publishToWebflowSubdomain: core.serialization.boolean().optional(), +}); + +export declare namespace SitesPublishResponse { + interface Raw { + customDomains?: Domain.Raw[] | null; + publishToWebflowSubdomain?: boolean | null; + } +} diff --git a/src/serialization/resources/sites/types/index.ts b/src/serialization/resources/sites/types/index.ts new file mode 100644 index 00000000..7708da86 --- /dev/null +++ b/src/serialization/resources/sites/types/index.ts @@ -0,0 +1 @@ +export * from "./SitesPublishResponse"; diff --git a/src/serialization/resources/collections/resources/items/client/requests/BulkCollectionItem.ts b/src/serialization/types/BulkCollectionItem.ts similarity index 69% rename from src/serialization/resources/collections/resources/items/client/requests/BulkCollectionItem.ts rename to src/serialization/types/BulkCollectionItem.ts index 35a5a271..a164b074 100644 --- a/src/serialization/resources/collections/resources/items/client/requests/BulkCollectionItem.ts +++ b/src/serialization/types/BulkCollectionItem.ts @@ -2,14 +2,14 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as serializers from "../../../../../../index"; -import * as Webflow from "../../../../../../../api/index"; -import * as core from "../../../../../../../core"; -import { BulkCollectionItemFieldData } from "../../types/BulkCollectionItemFieldData"; +import * as serializers from "../index"; +import * as Webflow from "../../api/index"; +import * as core from "../../core"; +import { BulkCollectionItemFieldData } from "./BulkCollectionItemFieldData"; -export const BulkCollectionItem: core.serialization.Schema< - serializers.collections.BulkCollectionItem.Raw, - Webflow.collections.BulkCollectionItem +export const BulkCollectionItem: core.serialization.ObjectSchema< + serializers.BulkCollectionItem.Raw, + Webflow.BulkCollectionItem > = core.serialization.object({ id: core.serialization.string(), cmsLocaleIds: core.serialization.list(core.serialization.string()).optional(), diff --git a/src/serialization/resources/collections/resources/items/types/BulkCollectionItemFieldData.ts b/src/serialization/types/BulkCollectionItemFieldData.ts similarity index 61% rename from src/serialization/resources/collections/resources/items/types/BulkCollectionItemFieldData.ts rename to src/serialization/types/BulkCollectionItemFieldData.ts index 79959c47..c8e08393 100644 --- a/src/serialization/resources/collections/resources/items/types/BulkCollectionItemFieldData.ts +++ b/src/serialization/types/BulkCollectionItemFieldData.ts @@ -2,13 +2,13 @@ * This file was auto-generated by Fern from our API Definition. */ -import * as serializers from "../../../../../index"; -import * as Webflow from "../../../../../../api/index"; -import * as core from "../../../../../../core"; +import * as serializers from "../index"; +import * as Webflow from "../../api/index"; +import * as core from "../../core"; export const BulkCollectionItemFieldData: core.serialization.ObjectSchema< - serializers.collections.BulkCollectionItemFieldData.Raw, - Webflow.collections.BulkCollectionItemFieldData + serializers.BulkCollectionItemFieldData.Raw, + Webflow.BulkCollectionItemFieldData > = core.serialization.object({ name: core.serialization.string().optional(), slug: core.serialization.string().optional(), diff --git a/src/serialization/types/ConflictErrorBody.ts b/src/serialization/types/ConflictErrorBody.ts index 5aed9236..b5050c4a 100644 --- a/src/serialization/types/ConflictErrorBody.ts +++ b/src/serialization/types/ConflictErrorBody.ts @@ -5,14 +5,23 @@ import * as serializers from "../index"; import * as Webflow from "../../api/index"; import * as core from "../../core"; -import { DuplicateUserEmail } from "./DuplicateUserEmail"; -import { UserLimitReached } from "./UserLimitReached"; +import { ErrorDetailsItem } from "./ErrorDetailsItem"; -export const ConflictErrorBody: core.serialization.Schema< +export const ConflictErrorBody: core.serialization.ObjectSchema< serializers.ConflictErrorBody.Raw, Webflow.ConflictErrorBody -> = core.serialization.undiscriminatedUnion([DuplicateUserEmail, UserLimitReached]); +> = core.serialization.object({ + code: core.serialization.stringLiteral("ecommerce_not_enabled").optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), +}); export declare namespace ConflictErrorBody { - type Raw = DuplicateUserEmail.Raw | UserLimitReached.Raw; + interface Raw { + code?: "ecommerce_not_enabled" | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/DuplicateUserEmail.ts b/src/serialization/types/DuplicateUserEmail.ts index 2cd21854..6f083835 100644 --- a/src/serialization/types/DuplicateUserEmail.ts +++ b/src/serialization/types/DuplicateUserEmail.ts @@ -5,13 +5,23 @@ import * as serializers from "../index"; import * as Webflow from "../../api/index"; import * as core from "../../core"; -import { Error_ } from "./Error_"; +import { ErrorDetailsItem } from "./ErrorDetailsItem"; export const DuplicateUserEmail: core.serialization.ObjectSchema< serializers.DuplicateUserEmail.Raw, Webflow.DuplicateUserEmail -> = Error_; +> = core.serialization.object({ + code: core.serialization.string().optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), +}); export declare namespace DuplicateUserEmail { - type Raw = Error_.Raw; + interface Raw { + code?: string | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/MissingScopes.ts b/src/serialization/types/MissingScopes.ts index 79ae084b..cb217762 100644 --- a/src/serialization/types/MissingScopes.ts +++ b/src/serialization/types/MissingScopes.ts @@ -5,11 +5,21 @@ import * as serializers from "../index"; import * as Webflow from "../../api/index"; import * as core from "../../core"; -import { Error_ } from "./Error_"; +import { ErrorDetailsItem } from "./ErrorDetailsItem"; export const MissingScopes: core.serialization.ObjectSchema = - Error_; + core.serialization.object({ + code: core.serialization.stringLiteral("missing_scopes").optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), + }); export declare namespace MissingScopes { - type Raw = Error_.Raw; + interface Raw { + code?: "missing_scopes" | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/NotEnterprisePlanSite.ts b/src/serialization/types/NotEnterprisePlanSite.ts index f412737f..98d40890 100644 --- a/src/serialization/types/NotEnterprisePlanSite.ts +++ b/src/serialization/types/NotEnterprisePlanSite.ts @@ -5,13 +5,23 @@ import * as serializers from "../index"; import * as Webflow from "../../api/index"; import * as core from "../../core"; -import { Error_ } from "./Error_"; +import { ErrorDetailsItem } from "./ErrorDetailsItem"; export const NotEnterprisePlanSite: core.serialization.ObjectSchema< serializers.NotEnterprisePlanSite.Raw, Webflow.NotEnterprisePlanSite -> = Error_; +> = core.serialization.object({ + code: core.serialization.stringLiteral("missing_scopes").optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), +}); export declare namespace NotEnterprisePlanSite { - type Raw = Error_.Raw; + interface Raw { + code?: "missing_scopes" | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/Page.ts b/src/serialization/types/Page.ts index 2f206f24..8aec3afe 100644 --- a/src/serialization/types/Page.ts +++ b/src/serialization/types/Page.ts @@ -9,7 +9,7 @@ import { PageSeo } from "./PageSeo"; import { PageOpenGraph } from "./PageOpenGraph"; export const Page: core.serialization.ObjectSchema = core.serialization.object({ - id: core.serialization.string().optional(), + id: core.serialization.string(), siteId: core.serialization.string().optional(), title: core.serialization.string().optional(), slug: core.serialization.string().optional(), @@ -27,7 +27,7 @@ export const Page: core.serialization.ObjectSchema = core.serialization.object({ - id: core.serialization.string().optional(), + id: core.serialization.string(), siteId: core.serialization.string().optional(), title: core.serialization.string().optional(), slug: core.serialization.string().optional(), @@ -30,7 +30,7 @@ export const PageDetails: core.serialization.ObjectSchema = Error_; +> = core.serialization.object({ + code: core.serialization.string().optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), +}); export declare namespace UserLimitReached { - type Raw = Error_.Raw; + interface Raw { + code?: string | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/UsersNotEnabled.ts b/src/serialization/types/UsersNotEnabled.ts index e5f78910..3de96c22 100644 --- a/src/serialization/types/UsersNotEnabled.ts +++ b/src/serialization/types/UsersNotEnabled.ts @@ -5,13 +5,23 @@ import * as serializers from "../index"; import * as Webflow from "../../api/index"; import * as core from "../../core"; -import { Error_ } from "./Error_"; +import { ErrorDetailsItem } from "./ErrorDetailsItem"; export const UsersNotEnabled: core.serialization.ObjectSchema< serializers.UsersNotEnabled.Raw, Webflow.UsersNotEnabled -> = Error_; +> = core.serialization.object({ + code: core.serialization.string().optional(), + message: core.serialization.string().optional(), + externalReference: core.serialization.string().optional(), + details: core.serialization.list(ErrorDetailsItem).optional(), +}); export declare namespace UsersNotEnabled { - type Raw = Error_.Raw; + interface Raw { + code?: string | null; + message?: string | null; + externalReference?: string | null; + details?: ErrorDetailsItem.Raw[] | null; + } } diff --git a/src/serialization/types/index.ts b/src/serialization/types/index.ts index ad6ecd4f..7e6bc072 100644 --- a/src/serialization/types/index.ts +++ b/src/serialization/types/index.ts @@ -3,6 +3,7 @@ export * from "./ForbiddenErrorBody"; export * from "./TooManyRequestsErrorBody"; export * from "./BadRequestErrorBody"; export * from "./ConflictErrorBody"; +export * from "./ErrorDetailsItem"; export * from "./AuthorizedUser"; export * from "./Application"; export * from "./AuthorizationAuthorizationAuthorizedTo"; @@ -21,7 +22,6 @@ export * from "./SiteActivityLogItemUser"; export * from "./SiteActivityLogItem"; export * from "./Pagination"; export * from "./SiteActivityLogResponse"; -export * from "./ErrorDetailsItem"; export * from "./Error_"; export * from "./MissingScopes"; export * from "./NotEnterprisePlanSite"; @@ -34,6 +34,8 @@ export * from "./CollectionItemFieldData"; export * from "./CollectionItem"; export * from "./CollectionItemListPagination"; export * from "./CollectionItemList"; +export * from "./BulkCollectionItemFieldData"; +export * from "./BulkCollectionItem"; export * from "./PageSeo"; export * from "./PageOpenGraph"; export * from "./Page"; diff --git a/tests/unit/auth/BasicAuth.test.ts b/tests/unit/auth/BasicAuth.test.ts new file mode 100644 index 00000000..fc35704e --- /dev/null +++ b/tests/unit/auth/BasicAuth.test.ts @@ -0,0 +1,22 @@ +import { BasicAuth } from "../../../src/core/auth/BasicAuth"; + +describe("BasicAuth", () => { + describe("toAuthorizationHeader", () => { + it("correctly converts to header", () => { + expect( + BasicAuth.toAuthorizationHeader({ + username: "username", + password: "password", + }) + ).toBe("Basic dXNlcm5hbWU6cGFzc3dvcmQ="); + }); + }); + describe("fromAuthorizationHeader", () => { + it("correctly parses header", () => { + expect(BasicAuth.fromAuthorizationHeader("Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).toEqual({ + username: "username", + password: "password", + }); + }); + }); +}); diff --git a/tests/unit/auth/BearerToken.test.ts b/tests/unit/auth/BearerToken.test.ts new file mode 100644 index 00000000..7757b87c --- /dev/null +++ b/tests/unit/auth/BearerToken.test.ts @@ -0,0 +1,14 @@ +import { BearerToken } from "../../../src/core/auth/BearerToken"; + +describe("BearerToken", () => { + describe("toAuthorizationHeader", () => { + it("correctly converts to header", () => { + expect(BearerToken.toAuthorizationHeader("my-token")).toBe("Bearer my-token"); + }); + }); + describe("fromAuthorizationHeader", () => { + it("correctly parses header", () => { + expect(BearerToken.fromAuthorizationHeader("Bearer my-token")).toBe("my-token"); + }); + }); +}); diff --git a/tests/unit/fetcher/Fetcher.test.ts b/tests/unit/fetcher/Fetcher.test.ts new file mode 100644 index 00000000..0e14a8c7 --- /dev/null +++ b/tests/unit/fetcher/Fetcher.test.ts @@ -0,0 +1,25 @@ +import fetchMock from "fetch-mock-jest"; +import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; + +describe("Test fetcherImpl", () => { + it("should handle successful request", async () => { + const mockArgs: Fetcher.Args = { + url: "https://httpbin.org/post", + method: "POST", + headers: { "X-Test": "x-test-header" }, + body: { data: "test" }, + contentType: "application/json", + requestType: "json", + }; + + fetchMock.mock("https://httpbin.org/post", 200, { + response: JSON.stringify({ data: "test" }), + }); + + const result = await fetcherImpl(mockArgs); + expect(result.ok).toBe(true); + if (result.ok) { + expect(result.body).toEqual({ data: "test" }); + } + }); +}); diff --git a/tests/unit/fetcher/createRequestUrl.test.ts b/tests/unit/fetcher/createRequestUrl.test.ts new file mode 100644 index 00000000..f2cd24b6 --- /dev/null +++ b/tests/unit/fetcher/createRequestUrl.test.ts @@ -0,0 +1,51 @@ +import { createRequestUrl } from "../../../src/core/fetcher/createRequestUrl"; + +describe("Test createRequestUrl", () => { + it("should return the base URL when no query parameters are provided", () => { + const baseUrl = "https://api.example.com"; + expect(createRequestUrl(baseUrl)).toBe(baseUrl); + }); + + it("should append simple query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { key: "value", another: "param" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?key=value&another=param"); + }); + + it("should handle array query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { items: ["a", "b", "c"] }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?items=a&items=b&items=c"); + }); + + it("should handle object query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { filter: { name: "John", age: 30 } }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?filter%5Bname%5D=John&filter%5Bage%5D=30" + ); + }); + + it("should handle mixed types of query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { + simple: "value", + array: ["x", "y"], + object: { key: "value" }, + }; + expect(createRequestUrl(baseUrl, queryParams)).toBe( + "https://api.example.com?simple=value&array=x&array=y&object%5Bkey%5D=value" + ); + }); + + it("should handle empty query parameters object", () => { + const baseUrl = "https://api.example.com"; + expect(createRequestUrl(baseUrl, {})).toBe(baseUrl); + }); + + it("should encode special characters in query parameters", () => { + const baseUrl = "https://api.example.com"; + const queryParams = { special: "a&b=c d" }; + expect(createRequestUrl(baseUrl, queryParams)).toBe("https://api.example.com?special=a%26b%3Dc%20d"); + }); +}); diff --git a/tests/unit/fetcher/getFetchFn.test.ts b/tests/unit/fetcher/getFetchFn.test.ts new file mode 100644 index 00000000..9b315ad0 --- /dev/null +++ b/tests/unit/fetcher/getFetchFn.test.ts @@ -0,0 +1,22 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getFetchFn } from "../../../src/core/fetcher/getFetchFn"; + +describe("Test for getFetchFn", () => { + it("should get node-fetch function", async () => { + if (RUNTIME.type == "node") { + if (RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { + expect(await getFetchFn()).toBe(fetch); + } else { + expect(await getFetchFn()).toEqual((await import("node-fetch")).default as any); + } + } + }); + + it("should get fetch function", async () => { + if (RUNTIME.type == "browser") { + const fetchFn = await getFetchFn(); + expect(typeof fetchFn).toBe("function"); + expect(fetchFn.name).toBe("fetch"); + } + }); +}); diff --git a/tests/unit/fetcher/getRequestBody.test.ts b/tests/unit/fetcher/getRequestBody.test.ts new file mode 100644 index 00000000..1b1462c5 --- /dev/null +++ b/tests/unit/fetcher/getRequestBody.test.ts @@ -0,0 +1,81 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test getRequestBody", () => { + it("should return FormData as is in Node environment", async () => { + if (RUNTIME.type === "node") { + const formData = new (await import("formdata-node")).FormData(); + formData.append("key", "value"); + const result = await getRequestBody({ + body: formData, + type: "file", + }); + expect(result).toBe(formData); + } + }); + + it("should stringify body if not FormData in Node environment", async () => { + if (RUNTIME.type === "node") { + const body = { key: "value" }; + const result = await getRequestBody({ + body, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + } + }); + + it("should return FormData in browser environment", async () => { + if (RUNTIME.type === "browser") { + const formData = new (await import("form-data")).default(); + formData.append("key", "value"); + const result = await getRequestBody({ + body: formData, + type: "file", + }); + expect(result).toBe(formData); + } + }); + + it("should stringify body if not FormData in browser environment", async () => { + if (RUNTIME.type === "browser") { + const body = { key: "value" }; + const result = await getRequestBody({ + body, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + } + }); + + it("should return the Uint8Array", async () => { + const input = new Uint8Array([1, 2, 3]); + const result = await getRequestBody({ + body: input, + type: "bytes", + }); + expect(result).toBe(input); + }); + + it("should return the input for content-type 'application/x-www-form-urlencoded'", async () => { + const input = "key=value&another=param"; + const result = await getRequestBody({ + body: input, + type: "other", + }); + expect(result).toBe(input); + }); + + it("should JSON stringify objects", async () => { + const input = { key: "value" }; + const result = await getRequestBody({ + body: input, + type: "json", + }); + expect(result).toBe('{"key":"value"}'); + }); +}); diff --git a/tests/unit/fetcher/getResponseBody.test.ts b/tests/unit/fetcher/getResponseBody.test.ts new file mode 100644 index 00000000..3510779e --- /dev/null +++ b/tests/unit/fetcher/getResponseBody.test.ts @@ -0,0 +1,68 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; +import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test getResponseBody", () => { + it("should handle blob response type", async () => { + const mockBlob = new Blob(["test"], { type: "text/plain" }); + const mockResponse = new Response(mockBlob); + const result = await getResponseBody(mockResponse, "blob"); + // @ts-expect-error + expect(result.constructor.name).toBe("Blob"); + }); + + it("should handle sse response type", async () => { + if (RUNTIME.type === "node") { + const mockStream = new ReadableStream(); + const mockResponse = new Response(mockStream); + const result = await getResponseBody(mockResponse, "sse"); + expect(result).toBe(mockStream); + } + }); + + it("should handle streaming response type", async () => { + if (RUNTIME.type === "node") { + const mockStream = new ReadableStream(); + const mockResponse = new Response(mockStream); + const result = await getResponseBody(mockResponse, "streaming"); + // need to reinstantiate string as a result of locked state in Readable Stream after registration with Response + expect(JSON.stringify(result)).toBe(JSON.stringify(await chooseStreamWrapper(new ReadableStream()))); + } + }); + + it("should handle text response type", async () => { + const mockResponse = new Response("test text"); + const result = await getResponseBody(mockResponse, "text"); + expect(result).toBe("test text"); + }); + + it("should handle JSON response", async () => { + const mockJson = { key: "value" }; + const mockResponse = new Response(JSON.stringify(mockJson)); + const result = await getResponseBody(mockResponse); + expect(result).toEqual(mockJson); + }); + + it("should handle empty response", async () => { + const mockResponse = new Response(""); + const result = await getResponseBody(mockResponse); + expect(result).toBeUndefined(); + }); + + it("should handle non-JSON response", async () => { + const mockResponse = new Response("invalid json"); + const result = await getResponseBody(mockResponse); + expect(result).toEqual({ + ok: false, + error: { + reason: "non-json", + statusCode: 200, + rawBody: "invalid json", + }, + }); + }); +}); diff --git a/tests/unit/fetcher/makeRequest.test.ts b/tests/unit/fetcher/makeRequest.test.ts new file mode 100644 index 00000000..5969d515 --- /dev/null +++ b/tests/unit/fetcher/makeRequest.test.ts @@ -0,0 +1,58 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { makeRequest } from "../../../src/core/fetcher/makeRequest"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test makeRequest", () => { + const mockPostUrl = "https://httpbin.org/post"; + const mockGetUrl = "https://httpbin.org/get"; + const mockHeaders = { "Content-Type": "application/json" }; + const mockBody = JSON.stringify({ key: "value" }); + + let mockFetch: jest.Mock; + + beforeEach(() => { + mockFetch = jest.fn(); + mockFetch.mockResolvedValue(new Response(JSON.stringify({ test: "successful" }), { status: 200 })); + }); + + it("should handle POST request correctly", async () => { + const response = await makeRequest(mockFetch, mockPostUrl, "POST", mockHeaders, mockBody); + const responseBody = await response.json(); + expect(responseBody).toEqual({ test: "successful" }); + expect(mockFetch).toHaveBeenCalledTimes(1); + const [calledUrl, calledOptions] = mockFetch.mock.calls[0]; + expect(calledUrl).toBe(mockPostUrl); + expect(calledOptions).toEqual( + expect.objectContaining({ + method: "POST", + headers: mockHeaders, + body: mockBody, + credentials: undefined, + }) + ); + expect(calledOptions.signal).toBeDefined(); + expect(calledOptions.signal).toBeInstanceOf(AbortSignal); + }); + + it("should handle GET request correctly", async () => { + const response = await makeRequest(mockFetch, mockGetUrl, "GET", mockHeaders, undefined); + const responseBody = await response.json(); + expect(responseBody).toEqual({ test: "successful" }); + expect(mockFetch).toHaveBeenCalledTimes(1); + const [calledUrl, calledOptions] = mockFetch.mock.calls[0]; + expect(calledUrl).toBe(mockGetUrl); + expect(calledOptions).toEqual( + expect.objectContaining({ + method: "GET", + headers: mockHeaders, + body: undefined, + credentials: undefined, + }) + ); + expect(calledOptions.signal).toBeDefined(); + expect(calledOptions.signal).toBeInstanceOf(AbortSignal); + }); +}); diff --git a/tests/unit/fetcher/requestWithRetries.test.ts b/tests/unit/fetcher/requestWithRetries.test.ts new file mode 100644 index 00000000..b53e0436 --- /dev/null +++ b/tests/unit/fetcher/requestWithRetries.test.ts @@ -0,0 +1,85 @@ +import { RUNTIME } from "../../../src/core/runtime"; +import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; + +if (RUNTIME.type === "browser") { + require("jest-fetch-mock").enableMocks(); +} + +describe("Test exponential backoff", () => { + let mockFetch: jest.Mock; + let originalSetTimeout: typeof setTimeout; + + beforeEach(() => { + mockFetch = jest.fn(); + originalSetTimeout = global.setTimeout; + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + global.setTimeout = originalSetTimeout; + }); + + it("should retry on 408, 409, 429, 500+", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 408 })) + .mockResolvedValueOnce(new Response("", { status: 409 })) + .mockResolvedValueOnce(new Response("", { status: 429 })) + .mockResolvedValueOnce(new Response("", { status: 500 })) + .mockResolvedValueOnce(new Response("", { status: 502 })) + .mockResolvedValueOnce(new Response("", { status: 200 })) + .mockResolvedValueOnce(new Response("", { status: 408 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 10); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(6); + expect(response.status).toBe(200); + }); + + it("should retry max 3 times", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 408 })) + .mockResolvedValueOnce(new Response("", { status: 409 })) + .mockResolvedValueOnce(new Response("", { status: 429 })) + .mockResolvedValueOnce(new Response("", { status: 429 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 3); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(4); + expect(response.status).toBe(429); + }); + it("should not retry on 200", async () => { + mockFetch + .mockResolvedValueOnce(new Response("", { status: 200 })) + .mockResolvedValueOnce(new Response("", { status: 409 })); + + const responsePromise = requestWithRetries(() => mockFetch(), 3); + + await jest.advanceTimersByTimeAsync(10000); + const response = await responsePromise; + + expect(mockFetch).toHaveBeenCalledTimes(1); + expect(response.status).toBe(200); + }); + + it("should retry with exponential backoff timing", async () => { + mockFetch.mockResolvedValue(new Response("", { status: 500 })); + const maxRetries = 7; + const responsePromise = requestWithRetries(() => mockFetch(), maxRetries); + expect(mockFetch).toHaveBeenCalledTimes(1); + + const delays = [1, 2, 4, 8, 16, 32, 64]; + for (let i = 0; i < delays.length; i++) { + await jest.advanceTimersByTimeAsync(delays[i] as number); + expect(mockFetch).toHaveBeenCalledTimes(Math.min(i + 2, maxRetries + 1)); + } + const response = await responsePromise; + expect(response.status).toBe(500); + }); +}); diff --git a/tests/unit/fetcher/signals.test.ts b/tests/unit/fetcher/signals.test.ts new file mode 100644 index 00000000..9cabfa07 --- /dev/null +++ b/tests/unit/fetcher/signals.test.ts @@ -0,0 +1,69 @@ +import { anySignal, getTimeoutSignal } from "../../../src/core/fetcher/signals"; + +describe("Test getTimeoutSignal", () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it("should return an object with signal and abortId", () => { + const { signal, abortId } = getTimeoutSignal(1000); + + expect(signal).toBeDefined(); + expect(abortId).toBeDefined(); + expect(signal).toBeInstanceOf(AbortSignal); + expect(signal.aborted).toBe(false); + }); + + it("should create a signal that aborts after the specified timeout", () => { + const timeoutMs = 5000; + const { signal } = getTimeoutSignal(timeoutMs); + + expect(signal.aborted).toBe(false); + + jest.advanceTimersByTime(timeoutMs - 1); + expect(signal.aborted).toBe(false); + + jest.advanceTimersByTime(1); + expect(signal.aborted).toBe(true); + }); +}); + +describe("Test anySignal", () => { + it("should return an AbortSignal", () => { + const signal = anySignal(new AbortController().signal); + expect(signal).toBeInstanceOf(AbortSignal); + }); + + it("should abort when any of the input signals is aborted", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + const signal = anySignal(controller1.signal, controller2.signal); + + expect(signal.aborted).toBe(false); + controller1.abort(); + expect(signal.aborted).toBe(true); + }); + + it("should handle an array of signals", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + const signal = anySignal([controller1.signal, controller2.signal]); + + expect(signal.aborted).toBe(false); + controller2.abort(); + expect(signal.aborted).toBe(true); + }); + + it("should abort immediately if one of the input signals is already aborted", () => { + const controller1 = new AbortController(); + const controller2 = new AbortController(); + controller1.abort(); + + const signal = anySignal(controller1.signal, controller2.signal); + expect(signal.aborted).toBe(true); + }); +}); diff --git a/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts new file mode 100644 index 00000000..e307b158 --- /dev/null +++ b/tests/unit/fetcher/stream-wrappers/Node18UniversalStreamWrapper.test.ts @@ -0,0 +1,178 @@ +import { Node18UniversalStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper"; + +describe("Node18UniversalStreamWrapper", () => { + it("should set encoding to utf-8", async () => { + const rawStream = new ReadableStream(); + const stream = new Node18UniversalStreamWrapper(rawStream); + const setEncodingSpy = jest.spyOn(stream, "setEncoding"); + + stream.setEncoding("utf-8"); + + expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); + }); + + it("should register an event listener for readable", async () => { + const rawStream = new ReadableStream(); + const stream = new Node18UniversalStreamWrapper(rawStream); + const onSpy = jest.spyOn(stream, "on"); + + stream.on("readable", () => {}); + + expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); + }); + + it("should remove an event listener for data", async () => { + const rawStream = new ReadableStream(); + const stream = new Node18UniversalStreamWrapper(rawStream); + const offSpy = jest.spyOn(stream, "off"); + + const fn = () => {}; + stream.on("data", fn); + stream.off("data", fn); + + expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); + }); + + it("should write to dest when calling pipe to writable stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + const dest = new WritableStream({ + write(chunk) { + expect(chunk).toEqual(new TextEncoder().encode("test")); + }, + }); + + stream.pipe(dest); + }); + + it("should write to dest when calling pipe to node writable stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + const dest = new (await import("stream")).Writable({ + write(chunk, encoding, callback) { + expect(chunk.toString()).toEqual("test"); + callback(); + }, + }); + + stream.pipe(dest); + }); + + it("should write nothing when calling pipe and unpipe", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + const buffer: Uint8Array[] = []; + const dest = new WritableStream({ + write(chunk) { + buffer.push(chunk); + }, + }); + + stream.pipe(dest); + stream.unpipe(dest); + expect(buffer).toEqual([]); + }); + + it("should destroy the stream", async () => { + const rawStream = new ReadableStream(); + const stream = new Node18UniversalStreamWrapper(rawStream); + const destroySpy = jest.spyOn(stream, "destroy"); + + stream.destroy(); + + expect(destroySpy).toHaveBeenCalled(); + }); + + it("should pause and resume the stream", async () => { + const rawStream = new ReadableStream(); + const stream = new Node18UniversalStreamWrapper(rawStream); + const pauseSpy = jest.spyOn(stream, "pause"); + const resumeSpy = jest.spyOn(stream, "resume"); + + expect(stream.isPaused).toBe(false); + stream.pause(); + expect(stream.isPaused).toBe(true); + stream.resume(); + + expect(pauseSpy).toHaveBeenCalled(); + expect(resumeSpy).toHaveBeenCalled(); + }); + + it("should read the stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + + expect(await stream.read()).toEqual(new TextEncoder().encode("test")); + expect(await stream.read()).toEqual(new TextEncoder().encode("test")); + }); + + it("should read the stream as text", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + + const data = await stream.text(); + + expect(data).toEqual("testtest"); + }); + + it("should read the stream as json", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode(JSON.stringify({ test: "test" }))); + controller.close(); + }, + }); + const stream = new Node18UniversalStreamWrapper(rawStream); + + const data = await stream.json(); + + expect(data).toEqual({ test: "test" }); + }); + + it("should allow use with async iteratable stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + let data = ""; + const stream = new Node18UniversalStreamWrapper(rawStream); + for await (const chunk of stream) { + data += new TextDecoder().decode(chunk); + } + + expect(data).toEqual("testtest"); + }); +}); diff --git a/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts new file mode 100644 index 00000000..861142a0 --- /dev/null +++ b/tests/unit/fetcher/stream-wrappers/NodePre18StreamWrapper.test.ts @@ -0,0 +1,124 @@ +import { NodePre18StreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/NodePre18StreamWrapper"; + +describe("NodePre18StreamWrapper", () => { + it("should set encoding to utf-8", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const setEncodingSpy = jest.spyOn(stream, "setEncoding"); + + stream.setEncoding("utf-8"); + + expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); + }); + + it("should register an event listener for readable", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const onSpy = jest.spyOn(stream, "on"); + + stream.on("readable", () => {}); + + expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); + }); + + it("should remove an event listener for data", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const offSpy = jest.spyOn(stream, "off"); + + const fn = () => {}; + stream.on("data", fn); + stream.off("data", fn); + + expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); + }); + + it("should write to dest when calling pipe to node writable stream", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const dest = new (await import("stream")).Writable({ + write(chunk, encoding, callback) { + expect(chunk.toString()).toEqual("test"); + callback(); + }, + }); + + stream.pipe(dest); + }); + + it("should write nothing when calling pipe and unpipe", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const buffer: Uint8Array[] = []; + const dest = new (await import("stream")).Writable({ + write(chunk, encoding, callback) { + buffer.push(chunk); + callback(); + }, + }); + stream.pipe(dest); + stream.unpipe(); + + expect(buffer).toEqual([]); + }); + + it("should destroy the stream", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const destroySpy = jest.spyOn(stream, "destroy"); + + stream.destroy(); + + expect(destroySpy).toHaveBeenCalledWith(); + }); + + it("should pause the stream and resume", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + const pauseSpy = jest.spyOn(stream, "pause"); + + stream.pause(); + expect(stream.isPaused).toBe(true); + stream.resume(); + expect(stream.isPaused).toBe(false); + + expect(pauseSpy).toHaveBeenCalledWith(); + }); + + it("should read the stream", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + + expect(await stream.read()).toEqual("test"); + expect(await stream.read()).toEqual("test"); + }); + + it("should read the stream as text", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + const stream = new NodePre18StreamWrapper(rawStream); + + const data = await stream.text(); + + expect(data).toEqual("testtest"); + }); + + it("should read the stream as json", async () => { + const rawStream = (await import("stream")).Readable.from([JSON.stringify({ test: "test" })]); + const stream = new NodePre18StreamWrapper(rawStream); + + const data = await stream.json(); + + expect(data).toEqual({ test: "test" }); + }); + + it("should allow use with async iteratable stream", async () => { + const rawStream = (await import("stream")).Readable.from(["test", "test"]); + let data = ""; + const stream = new NodePre18StreamWrapper(rawStream); + for await (const chunk of stream) { + data += chunk; + } + + expect(data).toEqual("testtest"); + }); +}); diff --git a/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts new file mode 100644 index 00000000..1d171ce6 --- /dev/null +++ b/tests/unit/fetcher/stream-wrappers/UndiciStreamWrapper.test.ts @@ -0,0 +1,153 @@ +import { UndiciStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/UndiciStreamWrapper"; + +describe("UndiciStreamWrapper", () => { + it("should set encoding to utf-8", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const setEncodingSpy = jest.spyOn(stream, "setEncoding"); + + stream.setEncoding("utf-8"); + + expect(setEncodingSpy).toHaveBeenCalledWith("utf-8"); + }); + + it("should register an event listener for readable", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const onSpy = jest.spyOn(stream, "on"); + + stream.on("readable", () => {}); + + expect(onSpy).toHaveBeenCalledWith("readable", expect.any(Function)); + }); + + it("should remove an event listener for data", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const offSpy = jest.spyOn(stream, "off"); + + const fn = () => {}; + stream.on("data", fn); + stream.off("data", fn); + + expect(offSpy).toHaveBeenCalledWith("data", expect.any(Function)); + }); + + it("should write to dest when calling pipe to writable stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new UndiciStreamWrapper(rawStream); + const dest = new WritableStream({ + write(chunk) { + expect(chunk).toEqual(new TextEncoder().encode("test")); + }, + }); + + stream.pipe(dest); + }); + + it("should write nothing when calling pipe and unpipe", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const buffer: Uint8Array[] = []; + const dest = new WritableStream({ + write(chunk) { + buffer.push(chunk); + }, + }); + stream.pipe(dest); + stream.unpipe(dest); + + expect(buffer).toEqual([]); + }); + + it("should destroy the stream", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const destroySpy = jest.spyOn(stream, "destroy"); + + stream.destroy(); + + expect(destroySpy).toHaveBeenCalled(); + }); + + it("should pause and resume the stream", async () => { + const rawStream = new ReadableStream(); + const stream = new UndiciStreamWrapper(rawStream); + const pauseSpy = jest.spyOn(stream, "pause"); + const resumeSpy = jest.spyOn(stream, "resume"); + + expect(stream.isPaused).toBe(false); + stream.pause(); + expect(stream.isPaused).toBe(true); + stream.resume(); + + expect(pauseSpy).toHaveBeenCalled(); + expect(resumeSpy).toHaveBeenCalled(); + }); + + it("should read the stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new UndiciStreamWrapper(rawStream); + + expect(await stream.read()).toEqual(new TextEncoder().encode("test")); + expect(await stream.read()).toEqual(new TextEncoder().encode("test")); + }); + + it("should read the stream as text", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + const stream = new UndiciStreamWrapper(rawStream); + + const data = await stream.text(); + + expect(data).toEqual("testtest"); + }); + + it("should read the stream as json", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode(JSON.stringify({ test: "test" }))); + controller.close(); + }, + }); + const stream = new UndiciStreamWrapper(rawStream); + + const data = await stream.json(); + + expect(data).toEqual({ test: "test" }); + }); + + it("should allow use with async iteratable stream", async () => { + const rawStream = new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode("test")); + controller.enqueue(new TextEncoder().encode("test")); + controller.close(); + }, + }); + let data = ""; + const stream = new UndiciStreamWrapper(rawStream); + for await (const chunk of stream) { + data += new TextDecoder().decode(chunk); + } + + expect(data).toEqual("testtest"); + }); +}); diff --git a/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts b/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts new file mode 100644 index 00000000..aff7579e --- /dev/null +++ b/tests/unit/fetcher/stream-wrappers/chooseStreamWrapper.test.ts @@ -0,0 +1,43 @@ +import { RUNTIME } from "../../../../src/core/runtime"; +import { chooseStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; +import { Node18UniversalStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper"; +import { NodePre18StreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/NodePre18StreamWrapper"; +import { UndiciStreamWrapper } from "../../../../src/core/fetcher/stream-wrappers/UndiciStreamWrapper"; + +describe("chooseStreamWrapper", () => { + beforeEach(() => { + RUNTIME.type = "unknown"; + RUNTIME.parsedVersion = 0; + }); + + it('should return a Node18UniversalStreamWrapper when RUNTIME.type is "node" and RUNTIME.parsedVersion is not null and RUNTIME.parsedVersion is greater than or equal to 18', async () => { + const expected = new Node18UniversalStreamWrapper(new ReadableStream()); + RUNTIME.type = "node"; + RUNTIME.parsedVersion = 18; + + const result = await chooseStreamWrapper(new ReadableStream()); + + expect(JSON.stringify(result)).toBe(JSON.stringify(expected)); + }); + + it('should return a NodePre18StreamWrapper when RUNTIME.type is "node" and RUNTIME.parsedVersion is not null and RUNTIME.parsedVersion is less than 18', async () => { + const stream = await import("stream"); + const expected = new NodePre18StreamWrapper(new stream.Readable()); + + RUNTIME.type = "node"; + RUNTIME.parsedVersion = 16; + + const result = await chooseStreamWrapper(new stream.Readable()); + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)); + }); + + it('should return a Undici when RUNTIME.type is not "node"', async () => { + const expected = new UndiciStreamWrapper(new ReadableStream()); + RUNTIME.type = "browser"; + + const result = await chooseStreamWrapper(new ReadableStream()); + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)); + }); +}); diff --git a/tests/unit/zurg/date/date.test.ts b/tests/unit/zurg/date/date.test.ts new file mode 100644 index 00000000..2790268a --- /dev/null +++ b/tests/unit/zurg/date/date.test.ts @@ -0,0 +1,31 @@ +import { date } from "../../../../src/core/schemas/builders/date"; +import { itSchema } from "../utils/itSchema"; +import { itValidateJson, itValidateParse } from "../utils/itValidate"; + +describe("date", () => { + itSchema("converts between raw ISO string and parsed Date", date(), { + raw: "2022-09-29T05:41:21.939Z", + parsed: new Date("2022-09-29T05:41:21.939Z"), + }); + + itValidateParse("non-string", date(), 42, [ + { + message: "Expected string. Received 42.", + path: [], + }, + ]); + + itValidateParse("non-ISO", date(), "hello world", [ + { + message: 'Expected ISO 8601 date string. Received "hello world".', + path: [], + }, + ]); + + itValidateJson("non-Date", date(), "hello", [ + { + message: 'Expected Date object. Received "hello".', + path: [], + }, + ]); +}); diff --git a/tests/unit/zurg/enum/enum.test.ts b/tests/unit/zurg/enum/enum.test.ts new file mode 100644 index 00000000..ab0df028 --- /dev/null +++ b/tests/unit/zurg/enum/enum.test.ts @@ -0,0 +1,30 @@ +import { enum_ } from "../../../../src/core/schemas/builders/enum"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("enum", () => { + itSchemaIdentity(enum_(["A", "B", "C"]), "A"); + + itSchemaIdentity(enum_(["A", "B", "C"]), "D" as any, { + opts: { allowUnrecognizedEnumValues: true }, + }); + + itValidate("invalid enum", enum_(["A", "B", "C"]), "D", [ + { + message: 'Expected enum. Received "D".', + path: [], + }, + ]); + + itValidate( + "non-string", + enum_(["A", "B", "C"]), + [], + [ + { + message: "Expected string. Received list.", + path: [], + }, + ] + ); +}); diff --git a/tests/unit/zurg/lazy/lazy.test.ts b/tests/unit/zurg/lazy/lazy.test.ts new file mode 100644 index 00000000..6906bf4c --- /dev/null +++ b/tests/unit/zurg/lazy/lazy.test.ts @@ -0,0 +1,57 @@ +import { Schema } from "../../../../src/core/schemas/Schema"; +import { lazy, list, object, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("lazy", () => { + it("doesn't run immediately", () => { + let wasRun = false; + lazy(() => { + wasRun = true; + return string(); + }); + expect(wasRun).toBe(false); + }); + + it("only runs first time", async () => { + let count = 0; + const schema = lazy(() => { + count++; + return string(); + }); + await schema.parse("hello"); + await schema.json("world"); + expect(count).toBe(1); + }); + + itSchemaIdentity( + lazy(() => object({})), + { foo: "hello" }, + { + title: "passes opts through", + opts: { unrecognizedObjectKeys: "passthrough" }, + } + ); + + itSchemaIdentity( + lazy(() => object({ foo: string() })), + { foo: "hello" } + ); + + // eslint-disable-next-line jest/expect-expect + it("self-referencial schema doesn't compile", () => { + () => { + // @ts-expect-error + const a = lazy(() => object({ foo: a })); + }; + }); + + // eslint-disable-next-line jest/expect-expect + it("self-referencial compiles with explicit type", () => { + () => { + interface TreeNode { + children: TreeNode[]; + } + const TreeNode: Schema = lazy(() => object({ children: list(TreeNode) })); + }; + }); +}); diff --git a/tests/unit/zurg/lazy/lazyObject.test.ts b/tests/unit/zurg/lazy/lazyObject.test.ts new file mode 100644 index 00000000..8813cc9f --- /dev/null +++ b/tests/unit/zurg/lazy/lazyObject.test.ts @@ -0,0 +1,18 @@ +import { lazyObject, number, object, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("lazy", () => { + itSchemaIdentity( + lazyObject(() => object({ foo: string() })), + { foo: "hello" } + ); + + itSchemaIdentity( + lazyObject(() => object({ foo: string() })).extend(object({ bar: number() })), + { + foo: "hello", + bar: 42, + }, + { title: "returned schema has object utils" } + ); +}); diff --git a/tests/unit/zurg/lazy/recursive/a.ts b/tests/unit/zurg/lazy/recursive/a.ts new file mode 100644 index 00000000..8b7d5e40 --- /dev/null +++ b/tests/unit/zurg/lazy/recursive/a.ts @@ -0,0 +1,7 @@ +import { object } from "../../../../../src/core/schemas/builders/object"; +import { schemaB } from "./b"; + +// @ts-expect-error +export const schemaA = object({ + b: schemaB, +}); diff --git a/tests/unit/zurg/lazy/recursive/b.ts b/tests/unit/zurg/lazy/recursive/b.ts new file mode 100644 index 00000000..fb219d54 --- /dev/null +++ b/tests/unit/zurg/lazy/recursive/b.ts @@ -0,0 +1,8 @@ +import { object } from "../../../../../src/core/schemas/builders/object"; +import { optional } from "../../../../../src/core/schemas/builders/schema-utils"; +import { schemaA } from "./a"; + +// @ts-expect-error +export const schemaB = object({ + a: optional(schemaA), +}); diff --git a/tests/unit/zurg/list/list.test.ts b/tests/unit/zurg/list/list.test.ts new file mode 100644 index 00000000..424ed642 --- /dev/null +++ b/tests/unit/zurg/list/list.test.ts @@ -0,0 +1,41 @@ +import { list, object, property, string } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("list", () => { + itSchemaIdentity(list(string()), ["hello", "world"], { + title: "functions as identity when item type is primitive", + }); + + itSchema( + "converts objects correctly", + list( + object({ + helloWorld: property("hello_world", string()), + }) + ), + { + raw: [{ hello_world: "123" }], + parsed: [{ helloWorld: "123" }], + } + ); + + itValidate("not a list", list(string()), 42, [ + { + path: [], + message: "Expected list. Received 42.", + }, + ]); + + itValidate( + "invalid item type", + list(string()), + [42], + [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ] + ); +}); diff --git a/tests/unit/zurg/literals/stringLiteral.test.ts b/tests/unit/zurg/literals/stringLiteral.test.ts new file mode 100644 index 00000000..fa6c8887 --- /dev/null +++ b/tests/unit/zurg/literals/stringLiteral.test.ts @@ -0,0 +1,21 @@ +import { stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("stringLiteral", () => { + itSchemaIdentity(stringLiteral("A"), "A"); + + itValidate("incorrect string", stringLiteral("A"), "B", [ + { + path: [], + message: 'Expected "A". Received "B".', + }, + ]); + + itValidate("non-string", stringLiteral("A"), 42, [ + { + path: [], + message: 'Expected "A". Received 42.', + }, + ]); +}); diff --git a/tests/unit/zurg/object-like/withParsedProperties.test.ts b/tests/unit/zurg/object-like/withParsedProperties.test.ts new file mode 100644 index 00000000..9f5dd0ed --- /dev/null +++ b/tests/unit/zurg/object-like/withParsedProperties.test.ts @@ -0,0 +1,57 @@ +import { object, property, string, stringLiteral } from "../../../../src/core/schemas/builders"; + +describe("withParsedProperties", () => { + it("Added properties included on parsed object", async () => { + const schema = object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }).withParsedProperties({ + printFoo: (parsed) => () => parsed.foo, + printHelloWorld: () => () => "Hello world", + helloWorld: "Hello world", + }); + + const parsed = await schema.parse({ raw_foo: "value of foo", bar: "bar" }); + if (!parsed.ok) { + throw new Error("Failed to parse"); + } + expect(parsed.value.printFoo()).toBe("value of foo"); + expect(parsed.value.printHelloWorld()).toBe("Hello world"); + expect(parsed.value.helloWorld).toBe("Hello world"); + }); + + it("Added property is removed on raw object", async () => { + const schema = object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }).withParsedProperties({ + printFoo: (parsed) => () => parsed.foo, + }); + + const original = { raw_foo: "value of foo", bar: "bar" } as const; + const parsed = await schema.parse(original); + if (!parsed.ok) { + throw new Error("Failed to parse()"); + } + + const raw = await schema.json(parsed.value); + + if (!raw.ok) { + throw new Error("Failed to json()"); + } + + expect(raw.value).toEqual(original); + }); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with non-object schema", () => { + () => + object({ + foo: string(), + }) + // @ts-expect-error + .withParsedProperties(42); + }); + }); +}); diff --git a/tests/unit/zurg/object/extend.test.ts b/tests/unit/zurg/object/extend.test.ts new file mode 100644 index 00000000..54fc8c4e --- /dev/null +++ b/tests/unit/zurg/object/extend.test.ts @@ -0,0 +1,89 @@ +import { boolean, object, property, string, stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; + +describe("extend", () => { + itSchemaIdentity( + object({ + foo: string(), + }).extend( + object({ + bar: stringLiteral("bar"), + }) + ), + { + foo: "", + bar: "bar", + } as const, + { + title: "extended properties are included in schema", + } + ); + + itSchemaIdentity( + object({ + foo: string(), + }) + .extend( + object({ + bar: stringLiteral("bar"), + }) + ) + .extend( + object({ + baz: boolean(), + }) + ), + { + foo: "", + bar: "bar", + baz: true, + } as const, + { + title: "extensions can be extended", + } + ); + + itSchema( + "converts nested object", + object({ + item: object({ + helloWorld: property("hello_world", string()), + }), + }).extend( + object({ + goodbye: property("goodbye_raw", string()), + }) + ), + { + raw: { item: { hello_world: "yo" }, goodbye_raw: "peace" }, + parsed: { item: { helloWorld: "yo" }, goodbye: "peace" }, + } + ); + + itSchema( + "extensions work with raw/parsed property name conversions", + object({ + item: property("item_raw", string()), + }).extend( + object({ + goodbye: property("goodbye_raw", string()), + }) + ), + { + raw: { item_raw: "hi", goodbye_raw: "peace" }, + parsed: { item: "hi", goodbye: "peace" }, + } + ); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with non-object schema", () => { + () => + object({ + foo: string(), + }) + // @ts-expect-error + .extend([]); + }); + }); +}); diff --git a/tests/unit/zurg/object/object.test.ts b/tests/unit/zurg/object/object.test.ts new file mode 100644 index 00000000..0acf0e24 --- /dev/null +++ b/tests/unit/zurg/object/object.test.ts @@ -0,0 +1,255 @@ +import { any, number, object, property, string, stringLiteral, unknown } from "../../../../src/core/schemas/builders"; +import { itJson, itParse, itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("object", () => { + itSchemaIdentity( + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { + foo: "", + bar: "bar", + }, + { + title: "functions as identity when values are primitives and property() isn't used", + } + ); + + itSchema( + "uses raw key from property()", + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { raw_foo: "foo", bar: "bar" }, + parsed: { foo: "foo", bar: "bar" }, + } + ); + + itSchema( + "keys with unknown type can be omitted", + object({ + foo: unknown(), + }), + { + raw: {}, + parsed: {}, + } + ); + + itSchema( + "keys with any type can be omitted", + object({ + foo: any(), + }), + { + raw: {}, + parsed: {}, + } + ); + + describe("unrecognizedObjectKeys", () => { + describe("parse", () => { + itParse( + 'includes unknown values when unrecognizedObjectKeys === "passthrough"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "passthrough", + }, + } + ); + + itParse( + 'strips unknown values when unrecognizedObjectKeys === "strip"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + }, + opts: { + unrecognizedObjectKeys: "strip", + }, + } + ); + }); + + describe("json", () => { + itJson( + 'includes unknown values when unrecognizedObjectKeys === "passthrough"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "passthrough", + }, + } + ); + + itJson( + 'strips unknown values when unrecognizedObjectKeys === "strip"', + object({ + foo: property("raw_foo", string()), + bar: stringLiteral("bar"), + }), + { + raw: { + raw_foo: "foo", + bar: "bar", + }, + parsed: { + foo: "foo", + bar: "bar", + // @ts-expect-error + baz: "yoyo", + }, + opts: { + unrecognizedObjectKeys: "strip", + }, + } + ); + }); + }); + + describe("nullish properties", () => { + itSchema("missing properties are not added", object({ foo: property("raw_foo", string().optional()) }), { + raw: {}, + parsed: {}, + }); + + itSchema("undefined properties are not dropped", object({ foo: property("raw_foo", string().optional()) }), { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + }); + + itSchema("null properties are not dropped", object({ foo: property("raw_foo", string().optional()) }), { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + }); + + describe("extensions", () => { + itSchema( + "undefined properties are not dropped", + object({}).extend(object({ foo: property("raw_foo", string().optional()) })), + { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + } + ); + + describe("parse()", () => { + itParse( + "null properties are not dropped", + object({}).extend(object({ foo: property("raw_foo", string().optional()) })), + { + raw: { raw_foo: null }, + parsed: { foo: undefined }, + } + ); + }); + }); + }); + + itValidate( + "missing property", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { foo: "hello" }, + [ + { + path: [], + message: 'Missing required key "bar"', + }, + ] + ); + + itValidate( + "extra property", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + { foo: "hello", bar: "bar", baz: 42 }, + [ + { + path: ["baz"], + message: 'Unexpected key "baz"', + }, + ] + ); + + itValidate( + "not an object", + object({ + foo: string(), + bar: stringLiteral("bar"), + }), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate( + "nested validation error", + object({ + foo: object({ + bar: number(), + }), + }), + { foo: { bar: "hello" } }, + [ + { + path: ["foo", "bar"], + message: 'Expected number. Received "hello".', + }, + ] + ); +}); diff --git a/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts b/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts new file mode 100644 index 00000000..d87a65fe --- /dev/null +++ b/tests/unit/zurg/object/objectWithoutOptionalProperties.test.ts @@ -0,0 +1,21 @@ +import { objectWithoutOptionalProperties, string, stringLiteral } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; + +describe("objectWithoutOptionalProperties", () => { + itSchema( + "all properties are required", + objectWithoutOptionalProperties({ + foo: string(), + bar: stringLiteral("bar").optional(), + }), + { + raw: { + foo: "hello", + }, + // @ts-expect-error + parsed: { + foo: "hello", + }, + } + ); +}); diff --git a/tests/unit/zurg/primitives/any.test.ts b/tests/unit/zurg/primitives/any.test.ts new file mode 100644 index 00000000..1adbbe2a --- /dev/null +++ b/tests/unit/zurg/primitives/any.test.ts @@ -0,0 +1,6 @@ +import { any } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("any", () => { + itSchemaIdentity(any(), true); +}); diff --git a/tests/unit/zurg/primitives/boolean.test.ts b/tests/unit/zurg/primitives/boolean.test.ts new file mode 100644 index 00000000..897a8295 --- /dev/null +++ b/tests/unit/zurg/primitives/boolean.test.ts @@ -0,0 +1,14 @@ +import { boolean } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("boolean", () => { + itSchemaIdentity(boolean(), true); + + itValidate("non-boolean", boolean(), {}, [ + { + path: [], + message: "Expected boolean. Received object.", + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/number.test.ts b/tests/unit/zurg/primitives/number.test.ts new file mode 100644 index 00000000..2d01415a --- /dev/null +++ b/tests/unit/zurg/primitives/number.test.ts @@ -0,0 +1,14 @@ +import { number } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("number", () => { + itSchemaIdentity(number(), 42); + + itValidate("non-number", number(), "hello", [ + { + path: [], + message: 'Expected number. Received "hello".', + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/string.test.ts b/tests/unit/zurg/primitives/string.test.ts new file mode 100644 index 00000000..57b23687 --- /dev/null +++ b/tests/unit/zurg/primitives/string.test.ts @@ -0,0 +1,14 @@ +import { string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("string", () => { + itSchemaIdentity(string(), "hello"); + + itValidate("non-string", string(), 42, [ + { + path: [], + message: "Expected string. Received 42.", + }, + ]); +}); diff --git a/tests/unit/zurg/primitives/unknown.test.ts b/tests/unit/zurg/primitives/unknown.test.ts new file mode 100644 index 00000000..4d17a7db --- /dev/null +++ b/tests/unit/zurg/primitives/unknown.test.ts @@ -0,0 +1,6 @@ +import { unknown } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; + +describe("unknown", () => { + itSchemaIdentity(unknown(), true); +}); diff --git a/tests/unit/zurg/record/record.test.ts b/tests/unit/zurg/record/record.test.ts new file mode 100644 index 00000000..7e4ba39c --- /dev/null +++ b/tests/unit/zurg/record/record.test.ts @@ -0,0 +1,34 @@ +import { number, record, string } from "../../../../src/core/schemas/builders"; +import { itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("record", () => { + itSchemaIdentity(record(string(), string()), { hello: "world" }); + itSchemaIdentity(record(number(), string()), { 42: "world" }); + + itValidate( + "non-record", + record(number(), string()), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate("invalid key type", record(number(), string()), { hello: "world" }, [ + { + path: ["hello (key)"], + message: 'Expected number. Received "hello".', + }, + ]); + + itValidate("invalid value type", record(string(), number()), { hello: "world" }, [ + { + path: ["hello"], + message: 'Expected number. Received "world".', + }, + ]); +}); diff --git a/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts b/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts new file mode 100644 index 00000000..da10086b --- /dev/null +++ b/tests/unit/zurg/schema-utils/getSchemaUtils.test.ts @@ -0,0 +1,83 @@ +import { object, string } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; + +describe("getSchemaUtils", () => { + describe("optional()", () => { + itSchema("optional fields allow original schema", string().optional(), { + raw: "hello", + parsed: "hello", + }); + + itSchema("optional fields are not required", string().optional(), { + raw: null, + parsed: undefined, + }); + }); + + describe("transform()", () => { + itSchema( + "transorm and untransform run correctly", + string().transform({ + transform: (x) => x + "X", + untransform: (x) => (x as string).slice(0, -1), + }), + { + raw: "hello", + parsed: "helloX", + } + ); + }); + + describe("parseOrThrow()", () => { + it("parses valid value", async () => { + const value = string().parseOrThrow("hello"); + expect(value).toBe("hello"); + }); + + it("throws on invalid value", async () => { + const value = () => object({ a: string(), b: string() }).parseOrThrow({ a: 24 }); + expect(value).toThrowError(new Error('a: Expected string. Received 24.; Missing required key "b"')); + }); + }); + + describe("jsonOrThrow()", () => { + it("serializes valid value", async () => { + const value = string().jsonOrThrow("hello"); + expect(value).toBe("hello"); + }); + + it("throws on invalid value", async () => { + const value = () => object({ a: string(), b: string() }).jsonOrThrow({ a: 24 }); + expect(value).toThrowError(new Error('a: Expected string. Received 24.; Missing required key "b"')); + }); + }); + + describe("omitUndefined", () => { + it("serializes undefined as null", async () => { + const value = object({ + a: string().optional(), + b: string().optional(), + }).jsonOrThrow({ + a: "hello", + b: undefined, + }); + expect(value).toEqual({ a: "hello", b: null }); + }); + + it("omits undefined values", async () => { + const value = object({ + a: string().optional(), + b: string().optional(), + }).jsonOrThrow( + { + a: "hello", + b: undefined, + }, + { + omitUndefined: true, + } + ); + expect(value).toEqual({ a: "hello" }); + }); + }); +}); diff --git a/tests/unit/zurg/schema.test.ts b/tests/unit/zurg/schema.test.ts new file mode 100644 index 00000000..94089a9a --- /dev/null +++ b/tests/unit/zurg/schema.test.ts @@ -0,0 +1,78 @@ +import { + boolean, + discriminant, + list, + number, + object, + string, + stringLiteral, + union, +} from "../../../src/core/schemas/builders"; +import { booleanLiteral } from "../../../src/core/schemas/builders/literals/booleanLiteral"; +import { property } from "../../../src/core/schemas/builders/object/property"; +import { itSchema } from "./utils/itSchema"; + +describe("Schema", () => { + itSchema( + "large nested object", + object({ + a: string(), + b: stringLiteral("b value"), + c: property( + "raw_c", + list( + object({ + animal: union(discriminant("type", "_type"), { + dog: object({ value: boolean() }), + cat: object({ value: property("raw_cat", number()) }), + }), + }) + ) + ), + d: property("raw_d", boolean()), + e: booleanLiteral(true), + }), + { + raw: { + a: "hello", + b: "b value", + raw_c: [ + { + animal: { + _type: "dog", + value: true, + }, + }, + { + animal: { + _type: "cat", + raw_cat: 42, + }, + }, + ], + raw_d: false, + e: true, + }, + parsed: { + a: "hello", + b: "b value", + c: [ + { + animal: { + type: "dog", + value: true, + }, + }, + { + animal: { + type: "cat", + value: 42, + }, + }, + ], + d: false, + e: true, + }, + } + ); +}); diff --git a/tests/unit/zurg/set/set.test.ts b/tests/unit/zurg/set/set.test.ts new file mode 100644 index 00000000..e17f908c --- /dev/null +++ b/tests/unit/zurg/set/set.test.ts @@ -0,0 +1,48 @@ +import { set, string } from "../../../../src/core/schemas/builders"; +import { itSchema } from "../utils/itSchema"; +import { itValidateJson, itValidateParse } from "../utils/itValidate"; + +describe("set", () => { + itSchema("converts between raw list and parsed Set", set(string()), { + raw: ["A", "B"], + parsed: new Set(["A", "B"]), + }); + + itValidateParse("not a list", set(string()), 42, [ + { + path: [], + message: "Expected list. Received 42.", + }, + ]); + + itValidateJson( + "not a Set", + set(string()), + [], + [ + { + path: [], + message: "Expected Set. Received list.", + }, + ] + ); + + itValidateParse( + "invalid item type", + set(string()), + [42], + [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ] + ); + + itValidateJson("invalid item type", set(string()), new Set([42]), [ + { + path: ["[0]"], + message: "Expected string. Received 42.", + }, + ]); +}); diff --git a/tests/unit/zurg/skipValidation.test.ts b/tests/unit/zurg/skipValidation.test.ts new file mode 100644 index 00000000..5dc88096 --- /dev/null +++ b/tests/unit/zurg/skipValidation.test.ts @@ -0,0 +1,45 @@ +/* eslint-disable no-console */ + +import { boolean, number, object, property, string, undiscriminatedUnion } from "../../../src/core/schemas/builders"; + +describe("skipValidation", () => { + it("allows data that doesn't conform to the schema", async () => { + const warningLogs: string[] = []; + const originalConsoleWarn = console.warn; + console.warn = (...args) => warningLogs.push(args.join(" ")); + + const schema = object({ + camelCase: property("snake_case", string()), + numberProperty: number(), + requiredProperty: boolean(), + anyPrimitive: undiscriminatedUnion([string(), number(), boolean()]), + }); + + const parsed = await schema.parse( + { + snake_case: "hello", + numberProperty: "oops", + anyPrimitive: true, + }, + { + skipValidation: true, + } + ); + + expect(parsed).toEqual({ + ok: true, + value: { + camelCase: "hello", + numberProperty: "oops", + anyPrimitive: true, + }, + }); + + expect(warningLogs).toEqual([ + `Failed to validate. + - numberProperty: Expected number. Received "oops".`, + ]); + + console.warn = originalConsoleWarn; + }); +}); diff --git a/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts b/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts new file mode 100644 index 00000000..0e664333 --- /dev/null +++ b/tests/unit/zurg/undiscriminated-union/undiscriminatedUnion.test.ts @@ -0,0 +1,44 @@ +import { number, object, property, string, undiscriminatedUnion } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; + +describe("undiscriminatedUnion", () => { + itSchemaIdentity(undiscriminatedUnion([string(), number()]), "hello world"); + + itSchemaIdentity(undiscriminatedUnion([object({ hello: string() }), object({ goodbye: string() })]), { + goodbye: "foo", + }); + + itSchema( + "Correctly transforms", + undiscriminatedUnion([object({ hello: string() }), object({ helloWorld: property("hello_world", string()) })]), + { + raw: { hello_world: "foo " }, + parsed: { helloWorld: "foo " }, + } + ); + + it("Returns errors for all variants", async () => { + const result = await undiscriminatedUnion([string(), number()]).parse(true); + if (result.ok) { + throw new Error("Unexpectedly passed validation"); + } + expect(result.errors).toEqual([ + { + message: "[Variant 0] Expected string. Received true.", + path: [], + }, + { + message: "[Variant 1] Expected number. Received true.", + path: [], + }, + ]); + }); + + describe("compile", () => { + // eslint-disable-next-line jest/expect-expect + it("doesn't compile with zero members", () => { + // @ts-expect-error + () => undiscriminatedUnion([]); + }); + }); +}); diff --git a/tests/unit/zurg/union/union.test.ts b/tests/unit/zurg/union/union.test.ts new file mode 100644 index 00000000..79018460 --- /dev/null +++ b/tests/unit/zurg/union/union.test.ts @@ -0,0 +1,113 @@ +import { boolean, discriminant, number, object, string, union } from "../../../../src/core/schemas/builders"; +import { itSchema, itSchemaIdentity } from "../utils/itSchema"; +import { itValidate } from "../utils/itValidate"; + +describe("union", () => { + itSchemaIdentity( + union("type", { + lion: object({ + meows: boolean(), + }), + giraffe: object({ + heightInInches: number(), + }), + }), + { type: "lion", meows: true }, + { title: "doesn't transform discriminant when it's a string" } + ); + + itSchema( + "transforms discriminant when it's a discriminant()", + union(discriminant("type", "_type"), { + lion: object({ meows: boolean() }), + giraffe: object({ heightInInches: number() }), + }), + { + raw: { _type: "lion", meows: true }, + parsed: { type: "lion", meows: true }, + } + ); + + describe("allowUnrecognizedUnionMembers", () => { + itSchema( + "transforms discriminant & passes through values when discriminant value is unrecognized", + union(discriminant("type", "_type"), { + lion: object({ meows: boolean() }), + giraffe: object({ heightInInches: number() }), + }), + { + // @ts-expect-error + raw: { _type: "moose", isAMoose: true }, + // @ts-expect-error + parsed: { type: "moose", isAMoose: true }, + opts: { + allowUnrecognizedUnionMembers: true, + }, + } + ); + }); + + describe("withParsedProperties", () => { + it("Added property is included on parsed object", async () => { + const schema = union("type", { + lion: object({}), + tiger: object({ value: string() }), + }).withParsedProperties({ + printType: (parsed) => () => parsed.type, + }); + + const parsed = await schema.parse({ type: "lion" }); + if (!parsed.ok) { + throw new Error("Failed to parse"); + } + expect(parsed.value.printType()).toBe("lion"); + }); + }); + + itValidate( + "non-object", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + [], + [ + { + path: [], + message: "Expected object. Received list.", + }, + ] + ); + + itValidate( + "missing discriminant", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + {}, + [ + { + path: [], + message: 'Missing discriminant ("type")', + }, + ] + ); + + itValidate( + "unrecognized discriminant value", + union("type", { + lion: object({}), + tiger: object({ value: string() }), + }), + { + type: "bear", + }, + [ + { + path: ["type"], + message: 'Expected enum. Received "bear".', + }, + ] + ); +}); diff --git a/tests/unit/zurg/utils/itSchema.ts b/tests/unit/zurg/utils/itSchema.ts new file mode 100644 index 00000000..67b6c928 --- /dev/null +++ b/tests/unit/zurg/utils/itSchema.ts @@ -0,0 +1,78 @@ +/* eslint-disable jest/no-export */ +import { Schema, SchemaOptions } from "../../../../src/core/schemas/Schema"; + +export function itSchemaIdentity( + schema: Schema, + value: T, + { title = "functions as identity", opts }: { title?: string; opts?: SchemaOptions } = {} +): void { + itSchema(title, schema, { raw: value, parsed: value, opts }); +} + +export function itSchema( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + only = false, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + only?: boolean; + } +): void { + // eslint-disable-next-line jest/valid-title + (only ? describe.only : describe)(title, () => { + itParse("parse()", schema, { raw, parsed, opts }); + itJson("json()", schema, { raw, parsed, opts }); + }); +} + +export function itParse( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + } +): void { + // eslint-disable-next-line jest/valid-title + it(title, () => { + const maybeValid = schema.parse(raw, opts); + if (!maybeValid.ok) { + throw new Error("Failed to parse() " + JSON.stringify(maybeValid.errors, undefined, 4)); + } + expect(maybeValid.value).toStrictEqual(parsed); + }); +} + +export function itJson( + title: string, + schema: Schema, + { + raw, + parsed, + opts, + }: { + raw: Raw; + parsed: Parsed; + opts?: SchemaOptions; + } +): void { + // eslint-disable-next-line jest/valid-title + it(title, () => { + const maybeValid = schema.json(parsed, opts); + if (!maybeValid.ok) { + throw new Error("Failed to json() " + JSON.stringify(maybeValid.errors, undefined, 4)); + } + expect(maybeValid.value).toStrictEqual(raw); + }); +} diff --git a/tests/unit/zurg/utils/itValidate.ts b/tests/unit/zurg/utils/itValidate.ts new file mode 100644 index 00000000..75b2c08b --- /dev/null +++ b/tests/unit/zurg/utils/itValidate.ts @@ -0,0 +1,56 @@ +/* eslint-disable jest/no-export */ +import { Schema, SchemaOptions, ValidationError } from "../../../../src/core/schemas/Schema"; + +export function itValidate( + title: string, + schema: Schema, + input: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + // eslint-disable-next-line jest/valid-title + describe("parse()", () => { + itValidateParse(title, schema, input, errors, opts); + }); + describe("json()", () => { + itValidateJson(title, schema, input, errors, opts); + }); +} + +export function itValidateParse( + title: string, + schema: Schema, + raw: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + describe("parse", () => { + // eslint-disable-next-line jest/valid-title + it(title, async () => { + const maybeValid = await schema.parse(raw, opts); + if (maybeValid.ok) { + throw new Error("Value passed validation"); + } + expect(maybeValid.errors).toStrictEqual(errors); + }); + }); +} + +export function itValidateJson( + title: string, + schema: Schema, + parsed: unknown, + errors: ValidationError[], + opts?: SchemaOptions +): void { + describe("json", () => { + // eslint-disable-next-line jest/valid-title + it(title, async () => { + const maybeValid = await schema.json(parsed, opts); + if (maybeValid.ok) { + throw new Error("Value passed validation"); + } + expect(maybeValid.errors).toStrictEqual(errors); + }); + }); +} diff --git a/yarn.lock b/yarn.lock index 2354fe4f..e8bd9494 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19,11 +19,11 @@ picocolors "^1.0.0" "@babel/compat-data@^7.25.2": - version "7.25.2" - resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.25.2.tgz#e41928bd33475305c586f6acbbb7e3ade7a6f7f5" - integrity sha512-bYcppcpKBvX4znYaPEeFau03bp89ShqNMLs+rmdptMw+heSZh9+z84d2YG+K7cYLbWwzdjtDoW/uqZmPjulClQ== + version "7.25.4" + resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.25.4.tgz#7d2a80ce229890edcf4cc259d4d696cb4dae2fcb" + integrity sha512-+LGRog6RAsCJrrrg/IO6LGmpphNe5DiK30dGjCoxxeGv49B10/3XYGxPsAwrDlMFcFEvdAUavDT8r9k/hSyQqQ== -"@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.23.9": +"@babel/core@^7.0.0", "@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.23.9": version "7.25.2" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.25.2.tgz#ed8eec275118d7613e77a352894cd12ded8eba77" integrity sha512-BBt3opiCOxUr9euZ5/ro/Xv8/V7yJ5bjYMqG/C1YAo8MIKAnumZalCN+msbci3Pigy4lIQfPUpfMM27HMGaYEA== @@ -44,12 +44,12 @@ json5 "^2.2.3" semver "^6.3.1" -"@babel/generator@^7.25.0", "@babel/generator@^7.7.2": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.25.0.tgz#f858ddfa984350bc3d3b7f125073c9af6988f18e" - integrity sha512-3LEEcj3PVW8pW2R1SR1M89g/qrYk/m/mB/tLqn7dn4sbBUQyTqnlod+II2U4dqiGtUmkcnAmkMDralTFZttRiw== +"@babel/generator@^7.25.0", "@babel/generator@^7.25.6", "@babel/generator@^7.7.2": + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.25.6.tgz#0df1ad8cb32fe4d2b01d8bf437f153d19342a87c" + integrity sha512-VPC82gr1seXOpkjAAKoLhP50vx4vGNlF4msF64dSFq1P8RfB+QAuJWGHPXXPc8QyfVWwwB/TNNU4+ayZmHNbZw== dependencies: - "@babel/types" "^7.25.0" + "@babel/types" "^7.25.6" "@jridgewell/gen-mapping" "^0.3.5" "@jridgewell/trace-mapping" "^0.3.25" jsesc "^2.5.1" @@ -83,7 +83,7 @@ "@babel/helper-validator-identifier" "^7.24.7" "@babel/traverse" "^7.25.2" -"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.24.7", "@babel/helper-plugin-utils@^7.8.0": +"@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.24.7", "@babel/helper-plugin-utils@^7.24.8", "@babel/helper-plugin-utils@^7.8.0": version "7.24.8" resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.8.tgz#94ee67e8ec0e5d44ea7baeb51e571bd26af07878" integrity sha512-FFWx5142D8h2Mgr/iPVGH5G7w6jDn4jUSpZTyDnQO0Yn7Ks2Kuz6Pci8H6MPCoUJegd/UZQ3tAvfLCxQSnWWwg== @@ -112,12 +112,12 @@ integrity sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q== "@babel/helpers@^7.25.0": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.25.0.tgz#e69beb7841cb93a6505531ede34f34e6a073650a" - integrity sha512-MjgLZ42aCm0oGjJj8CtSM3DB8NOOf8h2l7DCTePJs29u+v7yO/RBX9nShlKMgFnRks/Q4tBAe7Hxnov9VkGwLw== + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.25.6.tgz#57ee60141829ba2e102f30711ffe3afab357cc60" + integrity sha512-Xg0tn4HcfTijTwfDwYlvVCl43V6h4KyVVX2aEm4qdO/PC6L2YvzLHFdmxhoeSA3eslcE6+ZVXHgWwopXYLNq4Q== dependencies: "@babel/template" "^7.25.0" - "@babel/types" "^7.25.0" + "@babel/types" "^7.25.6" "@babel/highlight@^7.24.7": version "7.24.7" @@ -129,12 +129,12 @@ js-tokens "^4.0.0" picocolors "^1.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.25.0", "@babel/parser@^7.25.3": - version "7.25.3" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.25.3.tgz#91fb126768d944966263f0657ab222a642b82065" - integrity sha512-iLTJKDbJ4hMvFPgQwwsVoxtHyWpKKPBrxkANrSYewDPaPpT5py5yeVkgPIJ7XYXhndxJpaA3PyALSXQ7u8e/Dw== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.25.0", "@babel/parser@^7.25.6": + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.25.6.tgz#85660c5ef388cbbf6e3d2a694ee97a38f18afe2f" + integrity sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q== dependencies: - "@babel/types" "^7.25.2" + "@babel/types" "^7.25.6" "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -165,11 +165,11 @@ "@babel/helper-plugin-utils" "^7.14.5" "@babel/plugin-syntax-import-attributes@^7.24.7": - version "7.24.7" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.24.7.tgz#b4f9ea95a79e6912480c4b626739f86a076624ca" - integrity sha512-hbX+lKKeUMGihnK8nvKqmXBInriT3GVjzXKFriV3YC6APGxMbP8RZNFwy91+hocLXq90Mta+HshoB31802bb8A== + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.25.6.tgz#6d4c78f042db0e82fd6436cd65fec5dc78ad2bde" + integrity sha512-sXaDXaJN9SNLymBdlWFA+bjzBhFD617ZaFiY13dGt7TVslVvVgA6fkZOP7Ki3IGElC45lwHdOTrCtKZGVAWeLQ== dependencies: - "@babel/helper-plugin-utils" "^7.24.7" + "@babel/helper-plugin-utils" "^7.24.8" "@babel/plugin-syntax-import-meta@^7.10.4": version "7.10.4" @@ -249,11 +249,18 @@ "@babel/helper-plugin-utils" "^7.14.5" "@babel/plugin-syntax-typescript@^7.7.2": - version "7.24.7" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.7.tgz#58d458271b4d3b6bb27ee6ac9525acbb259bad1c" - integrity sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA== + version "7.25.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.4.tgz#04db9ce5a9043d9c635e75ae7969a2cd50ca97ff" + integrity sha512-uMOCoHVU52BsSWxPOMVv5qKRdeSlPuImUCB2dlPuBSU+W2/ROE7/Zg8F2Kepbk+8yBa68LlRKxO+xgEVWorsDg== dependencies: - "@babel/helper-plugin-utils" "^7.24.7" + "@babel/helper-plugin-utils" "^7.24.8" + +"@babel/runtime@^7.0.0": + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.6.tgz#9afc3289f7184d8d7f98b099884c26317b9264d2" + integrity sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ== + dependencies: + regenerator-runtime "^0.14.0" "@babel/template@^7.25.0", "@babel/template@^7.3.3": version "7.25.0" @@ -265,22 +272,22 @@ "@babel/types" "^7.25.0" "@babel/traverse@^7.24.7", "@babel/traverse@^7.25.2": - version "7.25.3" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.3.tgz#f1b901951c83eda2f3e29450ce92743783373490" - integrity sha512-HefgyP1x754oGCsKmV5reSmtV7IXj/kpaE1XYY+D9G5PvKKoFfSbiS4M77MdjuwlZKDIKFCffq9rPU+H/s3ZdQ== + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.6.tgz#04fad980e444f182ecf1520504941940a90fea41" + integrity sha512-9Vrcx5ZW6UwK5tvqsj0nGpp/XzqthkT0dqIc9g1AdtygFToNtTF67XzYS//dm+SAK9cp3B9R4ZO/46p63SCjlQ== dependencies: "@babel/code-frame" "^7.24.7" - "@babel/generator" "^7.25.0" - "@babel/parser" "^7.25.3" + "@babel/generator" "^7.25.6" + "@babel/parser" "^7.25.6" "@babel/template" "^7.25.0" - "@babel/types" "^7.25.2" + "@babel/types" "^7.25.6" debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.24.7", "@babel/types@^7.25.0", "@babel/types@^7.25.2", "@babel/types@^7.3.3": - version "7.25.2" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.2.tgz#55fb231f7dc958cd69ea141a4c2997e819646125" - integrity sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q== +"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.24.7", "@babel/types@^7.25.0", "@babel/types@^7.25.2", "@babel/types@^7.25.6", "@babel/types@^7.3.3": + version "7.25.6" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.6.tgz#893942ddb858f32ae7a004ec9d3a76b3463ef8e6" + integrity sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw== dependencies: "@babel/helper-string-parser" "^7.24.8" "@babel/helper-validator-identifier" "^7.24.7" @@ -640,9 +647,9 @@ form-data "^4.0.0" "@types/node@*": - version "22.4.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.4.1.tgz#9b595d292c65b94c20923159e2ce947731b6fdce" - integrity sha512-1tbpb9325+gPnKK0dMm+/LMriX0vKxf6RnB0SZUqfyVkQ4fMgUSySqhxE/y8Jvs4NyF1yHzTfG9KlnkIODxPKg== + version "22.5.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.4.tgz#83f7d1f65bc2ed223bdbf57c7884f1d5a4fa84e8" + integrity sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg== dependencies: undici-types "~6.19.2" @@ -905,9 +912,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001646: - version "1.0.30001651" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz#52de59529e8b02b1aedcaaf5c05d9e23c0c28138" - integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg== + version "1.0.30001658" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001658.tgz#b5f7be8ac748a049ab06aa1cf7a1408d83f074ec" + integrity sha512-N2YVqWbJELVdrnsW5p+apoQyYt51aBMSsBZki1XZEfeBCexcM/sf4xiAHcXQBkuOwJBXtWF7aW1sYX6tKebPHw== chalk@^2.4.2: version "2.4.2" @@ -937,9 +944,9 @@ ci-info@^3.2.0: integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ== cjs-module-lexer@^1.0.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.3.1.tgz#c485341ae8fd999ca4ee5af2d7a1c9ae01e0099c" - integrity sha512-a3KdPAANPbNE4ZUv9h6LckSl9zLsYOP4MBmhIPkRaeyybt+r4UghLvq+xw/YwUcC1gqylCkL4rdVs3Lwupjm4Q== + version "1.4.0" + resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.4.0.tgz#677de7ed7efff67cc40c9bf1897fea79d41b5215" + integrity sha512-N1NGmowPlGBLsOZLPvm48StN04V4YvQRL0i6b7ctrVY3epjP/ct7hFLOItz6pDIvRjwpfPxi52a2UWV2ziir8g== cliui@^8.0.1: version "8.0.1" @@ -1001,6 +1008,11 @@ convert-source-map@^2.0.0: resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a" integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg== +core-js@^3.0.0: + version "3.38.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.38.1.tgz#aa375b79a286a670388a1a363363d53677c0383e" + integrity sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw== + create-jest@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/create-jest/-/create-jest-29.7.0.tgz#a355c5b3cb1e1af02ba177fe7afd7feee49a5320" @@ -1050,11 +1062,11 @@ data-urls@^3.0.2: whatwg-url "^11.0.0" debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1: - version "4.3.6" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.6.tgz#2ab2c38fbaffebf8aa95fdfe6d88438c7a13c52b" - integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== dependencies: - ms "2.1.2" + ms "^2.1.3" decimal.js@^10.4.2: version "10.4.3" @@ -1103,9 +1115,9 @@ domexception@^4.0.0: webidl-conversions "^7.0.0" electron-to-chromium@^1.5.4: - version "1.5.11" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.11.tgz#258077f1077a1c72f2925cd5b326c470a7f5adef" - integrity sha512-R1CccCDYqndR25CaXFd6hp/u9RaaMcftMkphmvuepXr5b1vfLkRml6aWVeBhXJ7rbevHkKEMJtz8XqPf7ffmew== + version "1.5.17" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.17.tgz#292da718d3d96961d022e49bb843e0c4ea10be70" + integrity sha512-Q6Q+04tjC2KJ8qsSOSgovvhWcv5t+SmpH6/YfAWmhpE5/r+zw6KQy1/yWVFFNyEBvy68twTTXr2d5eLfCq7QIw== emittery@^0.13.1: version "0.13.1" @@ -1142,9 +1154,9 @@ es-errors@^1.3.0: integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== escalade@^3.1.1, escalade@^3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" - integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== + version "3.2.0" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5" + integrity sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA== escape-string-regexp@^1.0.5: version "1.0.5" @@ -1225,6 +1237,29 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" +fetch-mock-jest@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/fetch-mock-jest/-/fetch-mock-jest-1.5.1.tgz#0e13df990d286d9239e284f12b279ed509bf53cd" + integrity sha512-+utwzP8C+Pax1GSka3nFXILWMY3Er2L+s090FOgqVNrNCPp0fDqgXnAHAJf12PLHi0z4PhcTaZNTz8e7K3fjqQ== + dependencies: + fetch-mock "^9.11.0" + +fetch-mock@^9.11.0: + version "9.11.0" + resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-9.11.0.tgz#371c6fb7d45584d2ae4a18ee6824e7ad4b637a3f" + integrity sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q== + dependencies: + "@babel/core" "^7.0.0" + "@babel/runtime" "^7.0.0" + core-js "^3.0.0" + debug "^4.1.1" + glob-to-regexp "^0.4.0" + is-subset "^0.1.1" + lodash.isequal "^4.5.0" + path-to-regexp "^2.2.1" + querystring "^0.2.0" + whatwg-url "^6.5.0" + fill-range@^7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" @@ -1240,7 +1275,7 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -form-data@4.0.0, form-data@^4.0.0: +form-data@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== @@ -1300,6 +1335,11 @@ get-stream@^6.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== +glob-to-regexp@^0.4.0: + version "0.4.1" + resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" + integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== + glob@^7.1.3, glob@^7.1.4: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" @@ -1436,9 +1476,9 @@ is-arrayish@^0.2.1: integrity sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg== is-core-module@^2.13.0: - version "2.15.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.15.0.tgz#71c72ec5442ace7e76b306e9d48db361f22699ea" - integrity sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA== + version "2.15.1" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.15.1.tgz#a7363a25bee942fefab0de13bf6aa372c82dcc37" + integrity sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ== dependencies: hasown "^2.0.2" @@ -1467,6 +1507,11 @@ is-stream@^2.0.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg== +is-subset@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-subset/-/is-subset-0.1.1.tgz#8a59117d932de1de00f245fcdd39ce43f1e939a6" + integrity sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw== + isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" @@ -1984,11 +2029,21 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ== + lodash.memoize@4.x: version "4.1.2" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag== +lodash.sortby@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" + integrity sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA== + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -2021,9 +2076,9 @@ merge-stream@^2.0.0: integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== micromatch@^4.0.4: - version "4.0.7" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.7.tgz#33e8190d9fe474a9895525f5618eee136d46c2e5" - integrity sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q== + version "4.0.8" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" + integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== dependencies: braces "^3.0.3" picomatch "^2.3.1" @@ -2052,10 +2107,10 @@ minimatch@^3.0.4, minimatch@^3.1.1: dependencies: brace-expansion "^1.1.7" -ms@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +ms@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== natural-compare@^1.4.0: version "1.4.0" @@ -2178,10 +2233,15 @@ path-parse@^1.0.7: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== +path-to-regexp@^2.2.1: + version "2.4.0" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.4.0.tgz#35ce7f333d5616f1c1e1bfe266c3aba2e5b2e704" + integrity sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w== + picocolors@^1.0.0, picocolors@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1" - integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew== + version "1.1.0" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59" + integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw== picomatch@^2.0.4, picomatch@^2.2.3, picomatch@^2.3.1: version "2.3.1" @@ -2227,7 +2287,7 @@ psl@^1.1.33: resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag== -punycode@^2.1.1: +punycode@^2.1.0, punycode@^2.1.1: version "2.3.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5" integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg== @@ -2244,6 +2304,11 @@ qs@6.11.2: dependencies: side-channel "^1.0.4" +querystring@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd" + integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg== + querystringify@^2.1.1: version "2.2.0" resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" @@ -2254,6 +2319,11 @@ react-is@^18.0.0: resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== +regenerator-runtime@^0.14.0: + version "0.14.1" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f" + integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw== + require-directory@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" @@ -2492,6 +2562,13 @@ tough-cookie@^4.1.2: universalify "^0.2.0" url-parse "^1.5.3" +tr46@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09" + integrity sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA== + dependencies: + punycode "^2.1.0" + tr46@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/tr46/-/tr46-3.0.0.tgz#555c4e297a950617e8eeddef633c87d4d9d6cbf9" @@ -2592,6 +2669,11 @@ webidl-conversions@^3.0.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== +webidl-conversions@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" + integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg== + webidl-conversions@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a" @@ -2625,6 +2707,15 @@ whatwg-url@^5.0.0: tr46 "~0.0.3" webidl-conversions "^3.0.0" +whatwg-url@^6.5.0: + version "6.5.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8" + integrity sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ== + dependencies: + lodash.sortby "^4.7.0" + tr46 "^1.0.1" + webidl-conversions "^4.0.2" + which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"