Skip to content

Commit 614f6a9

Browse files
committed
persist existing listSubmissionsBySite API on forms to ensure backwards compatibility
1 parent 604fb36 commit 614f6a9

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed

src/wrapper/FormsClient.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import urlJoin from "url-join";
2+
import { Forms } from "../api/resources/forms/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+
10+
declare module "../api/resources/forms/client/Client" {
11+
export namespace Forms {}
12+
}
13+
14+
// Client adapts the base client to persist a deprecated `listSubmissionsBySite` method.
15+
// Overriding to preserve function and prevent breaking changes.
16+
export class Client extends Forms {
17+
constructor(protected readonly _options: Forms.Options) {
18+
super(_options);
19+
}
20+
21+
22+
/**
23+
* @deprecated Use `client.sites.forms.listSubmissionsBySite` instead.
24+
*
25+
* List form submissions for a given site. This endpoint differs from the existing [List Form Submissions endpoint](/data/reference/forms/form-submissions/list-submissions) by accepting `siteId` as a path parameter and `elementId` as a query parameter. You can get the `elementId` from the [List forms endpoint](/data/reference/forms/forms/list).
26+
*
27+
* Required scope | `forms:read`
28+
*
29+
* @param {string} siteId - Unique identifier for a Site
30+
* @param {Webflow.FormsListSubmissionsBySiteRequest} request
31+
* @param {Forms.RequestOptions} requestOptions - Request-specific configuration.
32+
*
33+
* @throws {@link Webflow.BadRequestError}
34+
* @throws {@link Webflow.UnauthorizedError}
35+
* @throws {@link Webflow.ForbiddenError}
36+
* @throws {@link Webflow.NotFoundError}
37+
* @throws {@link Webflow.TooManyRequestsError}
38+
* @throws {@link Webflow.InternalServerError}
39+
*
40+
* @example
41+
* await client.forms.listSubmissionsBySite("580e63e98c9a982ac9b8b741", {
42+
* elementId: "18259716-3e5a-646a-5f41-5dc4b9405aa0",
43+
* offset: 1.1,
44+
* limit: 1.1
45+
* })
46+
*/
47+
public listSubmissionsBySite(
48+
siteId: string,
49+
request: Webflow.sites.FormsListSubmissionsBySiteRequest = {},
50+
requestOptions?: Forms.RequestOptions,
51+
): core.HttpResponsePromise<Webflow.FormSubmissionList> {
52+
return core.HttpResponsePromise.fromPromise(this.__listSubmissionsBySite(siteId, request, requestOptions));
53+
}
54+
55+
private async __listSubmissionsBySite(
56+
siteId: string,
57+
request: Webflow.sites.FormsListSubmissionsBySiteRequest = {},
58+
requestOptions?: Forms.RequestOptions,
59+
): Promise<core.WithRawResponse<Webflow.FormSubmissionList>> {
60+
const { elementId, offset, limit } = request;
61+
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
62+
if (elementId != null) {
63+
_queryParams["elementId"] = elementId;
64+
}
65+
66+
if (offset != null) {
67+
_queryParams["offset"] = offset.toString();
68+
}
69+
70+
if (limit != null) {
71+
_queryParams["limit"] = limit.toString();
72+
}
73+
74+
const _response = await core.fetcher({
75+
url: urlJoin(
76+
(await core.Supplier.get(this._options.baseUrl)) ??
77+
((await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.DataApi)
78+
.base,
79+
`sites/${encodeURIComponent(siteId)}/form_submissions`,
80+
),
81+
method: "GET",
82+
headers: mergeHeaders(
83+
this._options?.headers,
84+
mergeOnlyDefinedHeaders({ Authorization: await this._getAuthorizationHeader() }),
85+
requestOptions?.headers,
86+
),
87+
queryParameters: _queryParams,
88+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
89+
maxRetries: requestOptions?.maxRetries,
90+
abortSignal: requestOptions?.abortSignal,
91+
});
92+
if (_response.ok) {
93+
return {
94+
data: serializers.FormSubmissionList.parseOrThrow(_response.body, {
95+
unrecognizedObjectKeys: "passthrough",
96+
allowUnrecognizedUnionMembers: true,
97+
allowUnrecognizedEnumValues: true,
98+
skipValidation: true,
99+
breadcrumbsPrefix: ["response"],
100+
}),
101+
rawResponse: _response.rawResponse,
102+
};
103+
}
104+
105+
if (_response.error.reason === "status-code") {
106+
switch (_response.error.statusCode) {
107+
case 400:
108+
throw new Webflow.BadRequestError(_response.error.body, _response.rawResponse);
109+
case 401:
110+
throw new Webflow.UnauthorizedError(
111+
serializers.Error_.parseOrThrow(_response.error.body, {
112+
unrecognizedObjectKeys: "passthrough",
113+
allowUnrecognizedUnionMembers: true,
114+
allowUnrecognizedEnumValues: true,
115+
skipValidation: true,
116+
breadcrumbsPrefix: ["response"],
117+
}),
118+
_response.rawResponse,
119+
);
120+
case 403:
121+
throw new Webflow.ForbiddenError(_response.error.body, _response.rawResponse);
122+
case 404:
123+
throw new Webflow.NotFoundError(
124+
serializers.Error_.parseOrThrow(_response.error.body, {
125+
unrecognizedObjectKeys: "passthrough",
126+
allowUnrecognizedUnionMembers: true,
127+
allowUnrecognizedEnumValues: true,
128+
skipValidation: true,
129+
breadcrumbsPrefix: ["response"],
130+
}),
131+
_response.rawResponse,
132+
);
133+
case 429:
134+
throw new Webflow.TooManyRequestsError(
135+
serializers.Error_.parseOrThrow(_response.error.body, {
136+
unrecognizedObjectKeys: "passthrough",
137+
allowUnrecognizedUnionMembers: true,
138+
allowUnrecognizedEnumValues: true,
139+
skipValidation: true,
140+
breadcrumbsPrefix: ["response"],
141+
}),
142+
_response.rawResponse,
143+
);
144+
case 500:
145+
throw new Webflow.InternalServerError(
146+
serializers.Error_.parseOrThrow(_response.error.body, {
147+
unrecognizedObjectKeys: "passthrough",
148+
allowUnrecognizedUnionMembers: true,
149+
allowUnrecognizedEnumValues: true,
150+
skipValidation: true,
151+
breadcrumbsPrefix: ["response"],
152+
}),
153+
_response.rawResponse,
154+
);
155+
default:
156+
throw new errors.WebflowError({
157+
statusCode: _response.error.statusCode,
158+
body: _response.error.body,
159+
rawResponse: _response.rawResponse,
160+
});
161+
}
162+
}
163+
164+
switch (_response.error.reason) {
165+
case "non-json":
166+
throw new errors.WebflowError({
167+
statusCode: _response.error.statusCode,
168+
body: _response.error.rawBody,
169+
rawResponse: _response.rawResponse,
170+
});
171+
case "timeout":
172+
throw new errors.WebflowTimeoutError(
173+
"Timeout exceeded when calling GET /sites/{site_id}/form_submissions.",
174+
);
175+
case "unknown":
176+
throw new errors.WebflowError({
177+
message: _response.error.errorMessage,
178+
rawResponse: _response.rawResponse,
179+
});
180+
}
181+
}
182+
}

src/wrapper/WebflowClient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Client as Webhooks } from "./WebhooksClient";
88
import { Client as Assets } from "./AssetsClient";
99
import { Client as Collections } from "./CollectionsClient";
1010
import { Client as Pages } from "./PagesClient";
11+
import { Client as Forms } from "./FormsClient";
1112

1213
export class WebflowClient extends FernClient {
1314
constructor(protected readonly _options: FernClient.Options) {
@@ -21,6 +22,8 @@ export class WebflowClient extends FernClient {
2122
protected _collections: Collections | undefined;
2223

2324
protected _pages: Pages | undefined;
25+
26+
protected _forms: Forms | undefined;
2427

2528
public get webhooks(): Webhooks {
2629
return (this._webhooks ??= new Webhooks(this._options));
@@ -38,6 +41,10 @@ export class WebflowClient extends FernClient {
3841
return (this._pages ??= new Pages(this._options));
3942
}
4043

44+
public get forms(): Forms {
45+
return (this._forms ??= new Forms(this._options));
46+
}
47+
4148
/**
4249
* @param clientId The OAuth client ID
4350
* @param state The state

0 commit comments

Comments
 (0)