Skip to content

Commit e6efe1e

Browse files
committed
Add createItemLive and createItemForMultipleLocales APIs to manual wrapper to avoid having to pass id parameter in the request object
1 parent c853efb commit e6efe1e

File tree

1 file changed

+224
-6
lines changed

1 file changed

+224
-6
lines changed

src/wrapper/ItemsClient.ts

Lines changed: 224 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as errors from "../errors";
77
import * as serializers from "../serialization";
88

99
// Client adapts the base client to permit extra properties in
10-
// the client.Collections.Items.createItem request.
10+
// the client.Collections.Items.createItem, createItemLive, and createItemForMultipleLocales request.
1111
export class Client extends Items {
1212
constructor(protected readonly _options: Items.Options) {
1313
super(_options);
@@ -44,27 +44,29 @@ export class Client extends Items {
4444
const _response = await core.fetcher({
4545
url: urlJoin(
4646
(await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default,
47-
`collections/${collectionId}/items`
47+
`collections/${encodeURIComponent(collectionId)}/items`
4848
),
4949
method: "POST",
5050
headers: {
5151
Authorization: await this._getAuthorizationHeader(),
5252
"X-Fern-Language": "JavaScript",
5353
"X-Fern-SDK-Name": "webflow-api",
54-
"X-Fern-SDK-Version": "v2.3.7",
55-
"User-Agent": "webflow-api/2.3.7",
54+
"X-Fern-SDK-Version": "2.4.0",
55+
"User-Agent": "webflow-api/2.4.0",
5656
"X-Fern-Runtime": core.RUNTIME.type,
5757
"X-Fern-Runtime-Version": core.RUNTIME.version,
5858
},
5959
contentType: "application/json",
60-
body: await serializers.CollectionItem.jsonOrThrow(request, {
60+
requestType: "json",
61+
body: serializers.CollectionItem.jsonOrThrow(request, {
6162
unrecognizedObjectKeys: "passthrough",
6263
allowUnrecognizedUnionMembers: true,
6364
allowUnrecognizedEnumValues: true,
6465
skipValidation: true,
6566
}),
6667
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
6768
maxRetries: requestOptions?.maxRetries,
69+
abortSignal: requestOptions?.abortSignal,
6870
});
6971
if (_response.ok) {
7072
return serializers.CollectionItem.parseOrThrow(_response.body, {
@@ -86,7 +88,223 @@ export class Client extends Items {
8688
throw new Webflow.NotFoundError(_response.error.body);
8789
case 429:
8890
throw new Webflow.TooManyRequestsError(
89-
await serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, {
91+
serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, {
92+
unrecognizedObjectKeys: "passthrough",
93+
allowUnrecognizedUnionMembers: true,
94+
allowUnrecognizedEnumValues: true,
95+
skipValidation: true,
96+
breadcrumbsPrefix: ["response"],
97+
})
98+
);
99+
case 500:
100+
throw new Webflow.InternalServerError(_response.error.body);
101+
default:
102+
throw new errors.WebflowError({
103+
statusCode: _response.error.statusCode,
104+
body: _response.error.body,
105+
});
106+
}
107+
}
108+
109+
switch (_response.error.reason) {
110+
case "non-json":
111+
throw new errors.WebflowError({
112+
statusCode: _response.error.statusCode,
113+
body: _response.error.rawBody,
114+
});
115+
case "timeout":
116+
throw new errors.WebflowTimeoutError();
117+
case "unknown":
118+
throw new errors.WebflowError({
119+
message: _response.error.errorMessage,
120+
});
121+
}
122+
}
123+
124+
/**
125+
* Create live Item in a Collection. This Item will be published to the live site. </br></br> To create items across multiple locales, <a href="https://developers.webflow.com/data/reference/create-item-for-multiple-locales"> please use this endpoint.</a> </br></br> Required scope | `CMS:write`
126+
*
127+
* @param {string} collectionId - Unique identifier for a Collection
128+
* @param {Webflow.CollectionItem} request
129+
* @param {Items.RequestOptions} requestOptions - Request-specific configuration.
130+
*
131+
* @throws {@link Webflow.BadRequestError}
132+
* @throws {@link Webflow.UnauthorizedError}
133+
* @throws {@link Webflow.NotFoundError}
134+
* @throws {@link Webflow.TooManyRequestsError}
135+
* @throws {@link Webflow.InternalServerError}
136+
*
137+
* @example
138+
* await client.collections.items.createItemLive("580e63fc8c9a982ac9b8b745", {
139+
* id: "42b720ef280c7a7a3be8cabe",
140+
* cmsLocaleId: "653ad57de882f528b32e810e",
141+
* lastPublished: "2022-11-29T16:22:43.159Z",
142+
* lastUpdated: "2022-11-17T17:19:43.282Z",
143+
* createdOn: "2022-11-17T17:11:57.148Z",
144+
* isArchived: false,
145+
* isDraft: false,
146+
* fieldData: {
147+
* name: "Pan Galactic Gargle Blaster Recipe",
148+
* slug: "pan-galactic-gargle-blaster"
149+
* }
150+
* })
151+
*/
152+
public async createItemLive(
153+
collectionId: string,
154+
request: Webflow.CollectionItem,
155+
requestOptions?: Items.RequestOptions
156+
): Promise<Webflow.CollectionItem> {
157+
const _response = await core.fetcher({
158+
url: urlJoin(
159+
(await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default,
160+
`collections/${encodeURIComponent(collectionId)}/items/live`
161+
),
162+
method: "POST",
163+
headers: {
164+
Authorization: await this._getAuthorizationHeader(),
165+
"X-Fern-Language": "JavaScript",
166+
"X-Fern-SDK-Name": "webflow-api",
167+
"X-Fern-SDK-Version": "2.4.0",
168+
"User-Agent": "webflow-api/2.4.0",
169+
"X-Fern-Runtime": core.RUNTIME.type,
170+
"X-Fern-Runtime-Version": core.RUNTIME.version,
171+
},
172+
contentType: "application/json",
173+
requestType: "json",
174+
body: serializers.CollectionItem.jsonOrThrow(request, {
175+
unrecognizedObjectKeys: "passthrough",
176+
allowUnrecognizedUnionMembers: true,
177+
allowUnrecognizedEnumValues: true,
178+
skipValidation: true,
179+
}),
180+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
181+
maxRetries: requestOptions?.maxRetries,
182+
abortSignal: requestOptions?.abortSignal,
183+
});
184+
if (_response.ok) {
185+
return serializers.CollectionItem.parseOrThrow(_response.body, {
186+
unrecognizedObjectKeys: "passthrough",
187+
allowUnrecognizedUnionMembers: true,
188+
allowUnrecognizedEnumValues: true,
189+
skipValidation: true,
190+
breadcrumbsPrefix: ["response"],
191+
});
192+
}
193+
194+
if (_response.error.reason === "status-code") {
195+
switch (_response.error.statusCode) {
196+
case 400:
197+
throw new Webflow.BadRequestError(_response.error.body);
198+
case 401:
199+
throw new Webflow.UnauthorizedError(_response.error.body);
200+
case 404:
201+
throw new Webflow.NotFoundError(_response.error.body);
202+
case 429:
203+
throw new Webflow.TooManyRequestsError(
204+
serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, {
205+
unrecognizedObjectKeys: "passthrough",
206+
allowUnrecognizedUnionMembers: true,
207+
allowUnrecognizedEnumValues: true,
208+
skipValidation: true,
209+
breadcrumbsPrefix: ["response"],
210+
})
211+
);
212+
case 500:
213+
throw new Webflow.InternalServerError(_response.error.body);
214+
default:
215+
throw new errors.WebflowError({
216+
statusCode: _response.error.statusCode,
217+
body: _response.error.body,
218+
});
219+
}
220+
}
221+
222+
switch (_response.error.reason) {
223+
case "non-json":
224+
throw new errors.WebflowError({
225+
statusCode: _response.error.statusCode,
226+
body: _response.error.rawBody,
227+
});
228+
case "timeout":
229+
throw new errors.WebflowTimeoutError();
230+
case "unknown":
231+
throw new errors.WebflowError({
232+
message: _response.error.errorMessage,
233+
});
234+
}
235+
}
236+
237+
/**
238+
* Create single Item in a Collection with multiple corresponding locales. </br></br> Required scope | `CMS:write`
239+
*
240+
* @param {string} collectionId - Unique identifier for a Collection
241+
* @param {Webflow.BulkCollectionItem} request
242+
* @param {Items.RequestOptions} requestOptions - Request-specific configuration.
243+
*
244+
* @throws {@link Webflow.BadRequestError}
245+
* @throws {@link Webflow.UnauthorizedError}
246+
* @throws {@link Webflow.NotFoundError}
247+
* @throws {@link Webflow.TooManyRequestsError}
248+
* @throws {@link Webflow.InternalServerError}
249+
*
250+
* @example
251+
* await client.collections.items.createItemForMultipleLocales("580e63fc8c9a982ac9b8b745", {
252+
* id: "580e64008c9a982ac9b8b754"
253+
* })
254+
*/
255+
public async createItemForMultipleLocales(
256+
collectionId: string,
257+
request: Webflow.BulkCollectionItem,
258+
requestOptions?: Items.RequestOptions
259+
): Promise<Webflow.BulkCollectionItem> {
260+
const _response = await core.fetcher({
261+
url: urlJoin(
262+
(await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.Default,
263+
`collections/${encodeURIComponent(collectionId)}/items/bulk`
264+
),
265+
method: "POST",
266+
headers: {
267+
Authorization: await this._getAuthorizationHeader(),
268+
"X-Fern-Language": "JavaScript",
269+
"X-Fern-SDK-Name": "webflow-api",
270+
"X-Fern-SDK-Version": "2.4.0",
271+
"User-Agent": "webflow-api/2.4.0",
272+
"X-Fern-Runtime": core.RUNTIME.type,
273+
"X-Fern-Runtime-Version": core.RUNTIME.version,
274+
},
275+
contentType: "application/json",
276+
requestType: "json",
277+
body: serializers.CollectionItem.jsonOrThrow(request, {
278+
unrecognizedObjectKeys: "passthrough",
279+
allowUnrecognizedUnionMembers: true,
280+
allowUnrecognizedEnumValues: true,
281+
skipValidation: true,
282+
}),
283+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
284+
maxRetries: requestOptions?.maxRetries,
285+
abortSignal: requestOptions?.abortSignal,
286+
});
287+
if (_response.ok) {
288+
return serializers.BulkCollectionItem.parseOrThrow(_response.body, {
289+
unrecognizedObjectKeys: "passthrough",
290+
allowUnrecognizedUnionMembers: true,
291+
allowUnrecognizedEnumValues: true,
292+
skipValidation: true,
293+
breadcrumbsPrefix: ["response"],
294+
});
295+
}
296+
297+
if (_response.error.reason === "status-code") {
298+
switch (_response.error.statusCode) {
299+
case 400:
300+
throw new Webflow.BadRequestError(_response.error.body);
301+
case 401:
302+
throw new Webflow.UnauthorizedError(_response.error.body);
303+
case 404:
304+
throw new Webflow.NotFoundError(_response.error.body);
305+
case 429:
306+
throw new Webflow.TooManyRequestsError(
307+
serializers.TooManyRequestsErrorBody.parseOrThrow(_response.error.body, {
90308
unrecognizedObjectKeys: "passthrough",
91309
allowUnrecognizedUnionMembers: true,
92310
allowUnrecognizedEnumValues: true,

0 commit comments

Comments
 (0)