-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathClient.ts
More file actions
159 lines (150 loc) · 6.95 KB
/
Client.ts
File metadata and controls
159 lines (150 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This file was auto-generated by Fern from our API Definition.
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient";
import * as core from "../../../../core";
import { mergeHeaders } from "../../../../core/headers";
import * as environments from "../../../../environments";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError";
import * as errors from "../../../../errors/index";
import * as serializers from "../../../../serialization/index";
import * as Webflow from "../../../index";
export declare namespace EcommerceClient {
export type Options = BaseClientOptions;
export interface RequestOptions extends BaseRequestOptions {}
}
export class EcommerceClient {
protected readonly _options: NormalizedClientOptionsWithAuth<EcommerceClient.Options>;
constructor(options: EcommerceClient.Options) {
this._options = normalizeClientOptionsWithAuth(options);
}
/**
* Retrieve ecommerce settings for a site.
*
* Required scope | `ecommerce:read`
*
* @param {string} site_id - Unique identifier for a Site
* @param {EcommerceClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Webflow.BadRequestError}
* @throws {@link Webflow.UnauthorizedError}
* @throws {@link Webflow.ForbiddenError}
* @throws {@link Webflow.NotFoundError}
* @throws {@link Webflow.ConflictError}
* @throws {@link Webflow.TooManyRequestsError}
* @throws {@link Webflow.InternalServerError}
*
* @example
* await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741")
*/
public getSettings(
site_id: string,
requestOptions?: EcommerceClient.RequestOptions,
): core.HttpResponsePromise<Webflow.EcommerceSettings> {
return core.HttpResponsePromise.fromPromise(this.__getSettings(site_id, requestOptions));
}
private async __getSettings(
site_id: string,
requestOptions?: EcommerceClient.RequestOptions,
): Promise<core.WithRawResponse<Webflow.EcommerceSettings>> {
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
requestOptions?.headers,
);
const _response = await core.fetcher({
url: core.url.join(
(await core.Supplier.get(this._options.baseUrl)) ??
((await core.Supplier.get(this._options.environment)) ?? environments.WebflowEnvironment.DataApi)
.base,
`sites/${core.url.encodePathParam(site_id)}/ecommerce/settings`,
),
method: "GET",
headers: _headers,
queryParameters: requestOptions?.queryParams,
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: serializers.EcommerceSettings.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Webflow.BadRequestError(_response.error.body, _response.rawResponse);
case 401:
throw new Webflow.UnauthorizedError(
serializers.Error_.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 403:
throw new Webflow.ForbiddenError(_response.error.body, _response.rawResponse);
case 404:
throw new Webflow.NotFoundError(
serializers.Error_.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 409:
throw new Webflow.ConflictError(_response.error.body, _response.rawResponse);
case 429:
throw new Webflow.TooManyRequestsError(
serializers.Error_.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
case 500:
throw new Webflow.InternalServerError(
serializers.Error_.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
default:
throw new errors.WebflowError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}
return handleNonStatusCodeError(
_response.error,
_response.rawResponse,
"GET",
"/sites/{site_id}/ecommerce/settings",
);
}
}