Skip to content

Commit e4de24f

Browse files
committed
Add override for Pages client to preserve old request body type. Bump to minor version
1 parent 48c08a2 commit e4de24f

File tree

8 files changed

+239
-6
lines changed

8 files changed

+239
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webflow-api",
3-
"version": "3.1.5",
3+
"version": "3.2.0",
44
"private": false,
55
"repository": "https://github.com/webflow/js-webflow-api",
66
"main": "./index.js",

src/Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export class WebflowClient {
7070
{
7171
"X-Fern-Language": "JavaScript",
7272
"X-Fern-SDK-Name": "webflow-api",
73-
"X-Fern-SDK-Version": "3.1.5",
74-
"User-Agent": "webflow-api/3.1.5",
73+
"X-Fern-SDK-Version": "3.2.0",
74+
"User-Agent": "webflow-api/3.2.0",
7575
"X-Fern-Runtime": core.RUNTIME.type,
7676
"X-Fern-Runtime-Version": core.RUNTIME.version,
7777
},

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const SDK_VERSION = "3.1.5";
1+
export const SDK_VERSION = "3.2.0";

src/wrapper/CollectionsClient.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import { Collections } from "../api/resources/collections/client/Client";
42
import { Client as Items } from "./ItemsClient";
53

src/wrapper/PagesClient.ts

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import urlJoin from "url-join";
2+
import { Pages } from "../api/resources/pages/client/Client";
3+
import * as core from "../core";
4+
import * as Webflow from "../api";
5+
import * as environments from "../environments";
6+
import * as errors from "../errors";
7+
import * as serializers from "../serialization";
8+
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../core/headers.js";
9+
import * as SchemaOverrides from "./schemas";
10+
11+
declare module "../api/resources/pages/client/Client" {
12+
export namespace Pages {}
13+
}
14+
15+
// Client adapts the base client to override extra properties in
16+
// the client.pages.updatePageSettings request.
17+
// Overriding to preserve ability to use `body` in request to prevent breaking change
18+
export class Client extends Pages {
19+
constructor(protected readonly _options: Pages.Options) {
20+
super(_options);
21+
}
22+
23+
/**
24+
* Update Page-level metadata, including SEO and Open Graph fields.
25+
*
26+
* <Note>
27+
* Note: When updating Page Metadata in secondary locales, you may only add `slug` to the request if your Site has the [Advanced or Enterprise Localization](https://webflow.com/localization) add-on.
28+
* </Note>
29+
*
30+
* Required scope | `pages:write`
31+
*
32+
* @param {string} pageId - Unique identifier for a Page
33+
* @param {Webflow.PageMetadataWrite | SchemaOverrides.PageMetadataWriteBody} request
34+
* @param {Pages.RequestOptions} requestOptions - Request-specific configuration.
35+
*
36+
* @throws {@link Webflow.BadRequestError}
37+
* @throws {@link Webflow.UnauthorizedError}
38+
* @throws {@link Webflow.NotFoundError}
39+
* @throws {@link Webflow.TooManyRequestsError}
40+
* @throws {@link Webflow.InternalServerError}
41+
*
42+
* @example
43+
* await client.pages.updatePageSettings("63c720f9347c2139b248e552", {
44+
* localeId: "65427cf400e02b306eaa04a0",
45+
* title: "Guide to the Galaxy",
46+
* slug: "guide-to-the-galaxy",
47+
* seo: {
48+
* title: "The Ultimate Hitchhiker's Guide to the Galaxy",
49+
* description: "Everything you need to know about the galaxy, from avoiding Vogon poetry to the importance of towels."
50+
* },
51+
* openGraph: {
52+
* title: "Explore the Cosmos with The Ultimate Guide",
53+
* titleCopied: false,
54+
* description: "Dive deep into the mysteries of the universe with your guide to everything galactic.",
55+
* descriptionCopied: false
56+
* }
57+
* })
58+
*/
59+
public updatePageSettings(
60+
pageId: string,
61+
request: (Webflow.PageMetadataWrite | SchemaOverrides.PageMetadataWriteBody) = {},
62+
requestOptions?: Pages.RequestOptions,
63+
): core.HttpResponsePromise<Webflow.Page> {
64+
return core.HttpResponsePromise.fromPromise(this.__updatePageSettingsOverride(pageId, request, requestOptions));
65+
}
66+
67+
private async __updatePageSettingsOverride(
68+
pageId: string,
69+
request: (Webflow.PageMetadataWrite | SchemaOverrides.PageMetadataWriteBody) = {},
70+
requestOptions?: Pages.RequestOptions,
71+
): Promise<core.WithRawResponse<Webflow.Page>> {
72+
const { localeId, ..._body } = request;
73+
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
74+
if (localeId != null) {
75+
_queryParams["localeId"] = localeId;
76+
}
77+
78+
const _response = await core.fetcher({
79+
url: urlJoin(
80+
(await core.Supplier.get(this._options.baseUrl)) ??
81+
((await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.DataApi)
82+
.base,
83+
`pages/${encodeURIComponent(pageId)}`,
84+
),
85+
method: "PUT",
86+
headers: mergeHeaders(
87+
this._options?.headers,
88+
mergeOnlyDefinedHeaders({ Authorization: await this._getAuthorizationHeader() }),
89+
requestOptions?.headers,
90+
),
91+
contentType: "application/json",
92+
queryParameters: _queryParams,
93+
requestType: "json",
94+
body: serializers.PageMetadataWrite.jsonOrThrow(_body, {
95+
unrecognizedObjectKeys: "passthrough",
96+
allowUnrecognizedUnionMembers: true,
97+
allowUnrecognizedEnumValues: true,
98+
}),
99+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
100+
maxRetries: requestOptions?.maxRetries,
101+
abortSignal: requestOptions?.abortSignal,
102+
});
103+
if (_response.ok) {
104+
return {
105+
data: serializers.Page.parseOrThrow(_response.body, {
106+
unrecognizedObjectKeys: "passthrough",
107+
allowUnrecognizedUnionMembers: true,
108+
allowUnrecognizedEnumValues: true,
109+
skipValidation: true,
110+
breadcrumbsPrefix: ["response"],
111+
}),
112+
rawResponse: _response.rawResponse,
113+
};
114+
}
115+
116+
if (_response.error.reason === "status-code") {
117+
switch (_response.error.statusCode) {
118+
case 400:
119+
throw new Webflow.BadRequestError(_response.error.body, _response.rawResponse);
120+
case 401:
121+
throw new Webflow.UnauthorizedError(
122+
serializers.Error_.parseOrThrow(_response.error.body, {
123+
unrecognizedObjectKeys: "passthrough",
124+
allowUnrecognizedUnionMembers: true,
125+
allowUnrecognizedEnumValues: true,
126+
skipValidation: true,
127+
breadcrumbsPrefix: ["response"],
128+
}),
129+
_response.rawResponse,
130+
);
131+
case 404:
132+
throw new Webflow.NotFoundError(
133+
serializers.Error_.parseOrThrow(_response.error.body, {
134+
unrecognizedObjectKeys: "passthrough",
135+
allowUnrecognizedUnionMembers: true,
136+
allowUnrecognizedEnumValues: true,
137+
skipValidation: true,
138+
breadcrumbsPrefix: ["response"],
139+
}),
140+
_response.rawResponse,
141+
);
142+
case 429:
143+
throw new Webflow.TooManyRequestsError(
144+
serializers.Error_.parseOrThrow(_response.error.body, {
145+
unrecognizedObjectKeys: "passthrough",
146+
allowUnrecognizedUnionMembers: true,
147+
allowUnrecognizedEnumValues: true,
148+
skipValidation: true,
149+
breadcrumbsPrefix: ["response"],
150+
}),
151+
_response.rawResponse,
152+
);
153+
case 500:
154+
throw new Webflow.InternalServerError(
155+
serializers.Error_.parseOrThrow(_response.error.body, {
156+
unrecognizedObjectKeys: "passthrough",
157+
allowUnrecognizedUnionMembers: true,
158+
allowUnrecognizedEnumValues: true,
159+
skipValidation: true,
160+
breadcrumbsPrefix: ["response"],
161+
}),
162+
_response.rawResponse,
163+
);
164+
default:
165+
throw new errors.WebflowError({
166+
statusCode: _response.error.statusCode,
167+
body: _response.error.body,
168+
rawResponse: _response.rawResponse,
169+
});
170+
}
171+
}
172+
173+
switch (_response.error.reason) {
174+
case "non-json":
175+
throw new errors.WebflowError({
176+
statusCode: _response.error.statusCode,
177+
body: _response.error.rawBody,
178+
rawResponse: _response.rawResponse,
179+
});
180+
case "timeout":
181+
throw new errors.WebflowTimeoutError("Timeout exceeded when calling PUT /pages/{page_id}.");
182+
case "unknown":
183+
throw new errors.WebflowError({
184+
message: _response.error.errorMessage,
185+
rawResponse: _response.rawResponse,
186+
});
187+
}
188+
}
189+
}

src/wrapper/WebflowClient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SDK_VERSION } from "../version";
77
import { Client as Webhooks } from "./WebhooksClient";
88
import { Client as Assets } from "./AssetsClient";
99
import { Client as Collections } from "./CollectionsClient";
10+
import { Client as Pages } from "./PagesClient";
1011

1112
export class WebflowClient extends FernClient {
1213
constructor(protected readonly _options: FernClient.Options) {
@@ -19,6 +20,8 @@ export class WebflowClient extends FernClient {
1920

2021
protected _collections: Collections | undefined;
2122

23+
protected _pages: Pages | undefined;
24+
2225
public get webhooks(): Webhooks {
2326
return (this._webhooks ??= new Webhooks(this._options));
2427
}
@@ -31,6 +34,10 @@ export class WebflowClient extends FernClient {
3134
return (this._collections ??= new Collections(this._options));
3235
}
3336

37+
public get pages(): Pages {
38+
return (this._pages ??= new Pages(this._options));
39+
}
40+
3441
/**
3542
* @param clientId The OAuth client ID
3643
* @param state The state
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Webflow } from "../../index";
2+
3+
/**
4+
* @example
5+
* {
6+
* localeId: "65427cf400e02b306eaa04a0",
7+
* body: {
8+
* title: "Guide to the Galaxy",
9+
* slug: "guide-to-the-galaxy",
10+
* seo: {
11+
* title: "The Ultimate Hitchhiker's Guide to the Galaxy",
12+
* description: "Everything you need to know about the galaxy, from avoiding Vogon poetry to the importance of towels."
13+
* },
14+
* openGraph: {
15+
* title: "Explore the Cosmos with The Ultimate Guide",
16+
* titleCopied: false,
17+
* description: "Dive deep into the mysteries of the universe with your guide to everything galactic.",
18+
* descriptionCopied: false
19+
* }
20+
* }
21+
* }
22+
*/
23+
export interface PageMetadataWriteBody {
24+
/**
25+
* Unique identifier for a specific locale. Applicable, when using localization.
26+
*/
27+
localeId?: string;
28+
body: {
29+
/** Title for the page */
30+
title?: string;
31+
/** Slug for the page */
32+
slug?: string;
33+
/** SEO-related fields for the Page */
34+
seo?: Webflow.PageMetadataWriteSeo;
35+
/** Open Graph fields for the Page */
36+
openGraph?: Webflow.PageMetadataWriteOpenGraph;
37+
}
38+
}

src/wrapper/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./ItemsCreateItemRequest";
22
export * from "./ItemsUpdateItemRequest";
33
export * from "./ItemsCreateItemLiveRequest";
44
export * from "./ItemsUpdateItemLiveRequest";
5+
export * from "./PageMetadataWrite";

0 commit comments

Comments
 (0)