@wix/astro 0.0.1-experimental-react-component → 0.0.1-experimental
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/fsevents-X6WP4TKM.node +0 -0
- package/build/index.d.ts +3 -2
- package/build/index.js +17329 -26
- package/build/index.js.map +1 -1
- package/build-browser-runtime/setup.d.ts +5 -0
- package/build-browser-runtime/setup.js +963 -0
- package/build-runtime/auth.d.ts +5 -0
- package/build-runtime/auth.js +3557 -0
- package/build-runtime/chunk-24J7STEA.js +8 -0
- package/build-runtime/chunk-B6RICTPP.js +94 -0
- package/build-runtime/chunk-C3QOE2TZ.js +7 -0
- package/build-runtime/chunk-EK7YZVWJ.js +353 -0
- package/build-runtime/chunk-FR26HCAT.js +471 -0
- package/build-runtime/chunk-HDTWPOIV.js +811 -0
- package/build-runtime/chunk-HPW4ZAEJ.js +23 -0
- package/build-runtime/chunk-JODQ44LE.js +1079 -0
- package/build-runtime/chunk-MLKGABMK.js +9 -0
- package/build-runtime/chunk-NVTQFGTR.js +7 -0
- package/build-runtime/chunk-PSHIUVP2.js +131 -0
- package/build-runtime/chunk-Q3KPY4P2.js +3104 -0
- package/build-runtime/chunk-QRPWKJ4C.js +41 -0
- package/build-runtime/chunk-RKE6XT5Z.js +3104 -0
- package/build-runtime/chunk-UZPSWWI5.js +13 -0
- package/build-runtime/chunk-VMS3NKCF.js +18 -0
- package/build-runtime/chunk-W73LN534.js +24 -0
- package/build-runtime/chunk-WYNC47R3.js +7 -0
- package/build-runtime/chunk-YMZMZCBN.js +4063 -0
- package/build-runtime/chunk-YX6EVX5Q.js +11 -0
- package/build-runtime/context/elevated.d.ts +2 -0
- package/build-runtime/context/elevated.js +25 -0
- package/build-runtime/context/non-elevated.d.ts +2 -0
- package/build-runtime/context/non-elevated.js +32 -0
- package/build-runtime/context/nonElevated.d.ts +2 -0
- package/build-runtime/context/nonElevated.js +38 -0
- package/build-runtime/context/setupServicePlugin.d.ts +5 -0
- package/build-runtime/context/setupServicePlugin.js +16 -0
- package/build-runtime/context/setupWebhook.d.ts +5 -0
- package/build-runtime/context/setupWebhook.js +16 -0
- package/build-runtime/middleware/auth.d.ts +5 -0
- package/build-runtime/middleware/auth.js +74 -0
- package/build-runtime/middleware/html-embeds.d.ts +5 -0
- package/build-runtime/middleware/html-embeds.js +166 -0
- package/build-runtime/routes/auth/callback.d.ts +5 -0
- package/build-runtime/routes/auth/callback.js +52 -0
- package/build-runtime/routes/auth/login.d.ts +5 -0
- package/build-runtime/routes/auth/login.js +45 -0
- package/build-runtime/routes/auth/logout-callback.d.ts +5 -0
- package/build-runtime/routes/auth/logout-callback.js +23 -0
- package/build-runtime/routes/auth/logout.d.ts +5 -0
- package/build-runtime/routes/auth/logout.js +32 -0
- package/build-runtime/routes/paylink/checkout.d.ts +5 -0
- package/build-runtime/routes/paylink/checkout.js +35 -0
- package/build-runtime/routes/paylink/paylink.d.ts +5 -0
- package/build-runtime/routes/paylink/paylink.js +34 -0
- package/build-runtime/routes/robots/robots.d.ts +5 -0
- package/build-runtime/routes/robots/robots.js +44 -0
- package/build-runtime/routes/service-plugins.d.ts +5 -0
- package/build-runtime/routes/service-plugins.js +11 -0
- package/build-runtime/routes/servicePluginsDevRoute.d.ts +5 -0
- package/build-runtime/routes/servicePluginsDevRoute.js +13 -0
- package/build-runtime/routes/webhooks.d.ts +5 -0
- package/build-runtime/routes/webhooks.js +11 -0
- package/build-runtime/routes/webhooksDevRoute.d.ts +5 -0
- package/build-runtime/routes/webhooksDevRoute.js +13 -0
- package/build-runtime/routes/wix-apis/api.d.ts +5 -0
- package/build-runtime/routes/wix-apis/api.js +34 -0
- package/package.json +45 -19
- package/runtime/entry.astro +26 -0
- package/build/builders.d.ts +0 -5
- package/build/builders.js +0 -40
- package/build/builders.js.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authAsyncLocalStorage
|
|
3
|
+
} from "./chunk-NVTQFGTR.js";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/@wix/headless-node/dist/esm/headers/common-config-header.js
|
|
6
|
+
var COMMON_CONFIG_HEADER_NAME = "commonConfig";
|
|
7
|
+
var BSI_COOKIE_NAME = "bSession";
|
|
8
|
+
var getCommonConfigHeader = (req) => {
|
|
9
|
+
let value = req.headers.get(COMMON_CONFIG_HEADER_NAME);
|
|
10
|
+
if (!value) {
|
|
11
|
+
const cookies = req.headers.get("cookie");
|
|
12
|
+
const bsiCookie = cookies == null ? void 0 : cookies.split(";").find((keyValue) => keyValue.trim().startsWith(`${BSI_COOKIE_NAME}=`));
|
|
13
|
+
value = bsiCookie ? encodeURIComponent(JSON.stringify({
|
|
14
|
+
BSI: bsiCookie.split("=")[1]
|
|
15
|
+
})) : "";
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
[COMMON_CONFIG_HEADER_NAME]: value
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/@wix/headless-node/dist/esm/headers/index.js
|
|
23
|
+
var getPassThroughHeaders = (req) => {
|
|
24
|
+
if (!req) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
const headers = [getCommonConfigHeader(req)];
|
|
28
|
+
return headers.reduce((res, header) => {
|
|
29
|
+
const entries = Object.entries(header).filter((_ref) => {
|
|
30
|
+
let [_, value] = _ref;
|
|
31
|
+
return !!value;
|
|
32
|
+
});
|
|
33
|
+
res = {
|
|
34
|
+
...res,
|
|
35
|
+
...Object.fromEntries(entries)
|
|
36
|
+
};
|
|
37
|
+
return res;
|
|
38
|
+
}, {});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/@wix/headless-node/dist/esm/host-module.js
|
|
42
|
+
var createHostModule = () => {
|
|
43
|
+
return {
|
|
44
|
+
__type: "host",
|
|
45
|
+
create: () => {
|
|
46
|
+
return {};
|
|
47
|
+
},
|
|
48
|
+
host: function(_temp) {
|
|
49
|
+
let {
|
|
50
|
+
req
|
|
51
|
+
} = _temp === void 0 ? {} : _temp;
|
|
52
|
+
const passThroughHeaders = getPassThroughHeaders(req);
|
|
53
|
+
return {
|
|
54
|
+
essentials: {
|
|
55
|
+
passThroughHeaders
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ../../node_modules/@wix/headless-node/dist/esm/index.js
|
|
63
|
+
var headlessNode = createHostModule();
|
|
64
|
+
|
|
65
|
+
// src/context/hostProxy.ts
|
|
66
|
+
var createHostWithCurrentRequest = () => {
|
|
67
|
+
const store = authAsyncLocalStorage.getStore();
|
|
68
|
+
return headlessNode.host({ req: store?.request });
|
|
69
|
+
};
|
|
70
|
+
var createHostProxy = () => {
|
|
71
|
+
return new Proxy(
|
|
72
|
+
{},
|
|
73
|
+
{
|
|
74
|
+
get(target, prop) {
|
|
75
|
+
const host = createHostWithCurrentRequest();
|
|
76
|
+
const value = host[prop];
|
|
77
|
+
if (typeof value !== "function") {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
return function(...args) {
|
|
81
|
+
const anotherHost = createHostWithCurrentRequest();
|
|
82
|
+
return anotherHost[prop].apply(
|
|
83
|
+
anotherHost,
|
|
84
|
+
args
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
createHostProxy
|
|
94
|
+
};
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import {
|
|
2
|
+
contextualizeRESTModuleV2
|
|
3
|
+
} from "./chunk-PSHIUVP2.js";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/@wix/sdk-runtime/build/constants.js
|
|
6
|
+
var SDKRequestToRESTRequestRenameMap = {
|
|
7
|
+
_id: "id",
|
|
8
|
+
_createdDate: "createdDate",
|
|
9
|
+
_updatedDate: "updatedDate"
|
|
10
|
+
};
|
|
11
|
+
var RESTResponseToSDKResponseRenameMap = {
|
|
12
|
+
id: "_id",
|
|
13
|
+
createdDate: "_createdDate",
|
|
14
|
+
updatedDate: "_updatedDate"
|
|
15
|
+
};
|
|
16
|
+
var ITEMS_RESULT_PROPERTY_NAME = "items";
|
|
17
|
+
var PAGING_METADATA_RESULT_PROPERTY_NAME = "pagingMetadata";
|
|
18
|
+
var DEFAULT_LIMIT = 50;
|
|
19
|
+
|
|
20
|
+
// ../../node_modules/@wix/sdk-runtime/build/utils.js
|
|
21
|
+
function constantCase(input) {
|
|
22
|
+
return split(input).map((part) => part.toLocaleUpperCase()).join("_");
|
|
23
|
+
}
|
|
24
|
+
var SPLIT_LOWER_UPPER_RE = new RegExp("([\\p{Ll}\\d])(\\p{Lu})", "gu");
|
|
25
|
+
var SPLIT_UPPER_UPPER_RE = new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])", "gu");
|
|
26
|
+
var SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
27
|
+
var DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
28
|
+
function split(value) {
|
|
29
|
+
let result = value.trim();
|
|
30
|
+
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
31
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
32
|
+
let start = 0;
|
|
33
|
+
let end = result.length;
|
|
34
|
+
while (result.charAt(start) === "\0") {
|
|
35
|
+
start++;
|
|
36
|
+
}
|
|
37
|
+
if (start === end) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
while (result.charAt(end - 1) === "\0") {
|
|
41
|
+
end--;
|
|
42
|
+
}
|
|
43
|
+
return result.slice(start, end).split(/\0/g);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/@wix/sdk-runtime/build/transform-error.js
|
|
47
|
+
var isValidationError = (httpClientError) => "validationError" in (httpClientError.response?.data?.details ?? {});
|
|
48
|
+
var isApplicationError = (httpClientError) => "applicationError" in (httpClientError.response?.data?.details ?? {});
|
|
49
|
+
var isClientError = (httpClientError) => (httpClientError.response?.status ?? -1) >= 400 && (httpClientError.response?.status ?? -1) < 500;
|
|
50
|
+
function transformError(httpClientError, pathsToArguments = {
|
|
51
|
+
explicitPathsToArguments: {},
|
|
52
|
+
spreadPathsToArguments: {},
|
|
53
|
+
singleArgumentUnchanged: false
|
|
54
|
+
}, argumentNames = []) {
|
|
55
|
+
if (typeof httpClientError !== "object" || httpClientError === null) {
|
|
56
|
+
throw httpClientError;
|
|
57
|
+
}
|
|
58
|
+
if (isValidationError(httpClientError)) {
|
|
59
|
+
return buildValidationError(httpClientError, pathsToArguments, argumentNames);
|
|
60
|
+
}
|
|
61
|
+
if (isApplicationError(httpClientError)) {
|
|
62
|
+
return buildApplicationError(httpClientError);
|
|
63
|
+
}
|
|
64
|
+
if (isClientError(httpClientError)) {
|
|
65
|
+
const status = httpClientError.response?.status;
|
|
66
|
+
const statusText = httpClientError.response?.statusText ?? "UNKNOWN";
|
|
67
|
+
const message = httpClientError.response?.data?.message ?? statusText;
|
|
68
|
+
const details = {
|
|
69
|
+
applicationError: {
|
|
70
|
+
description: statusText,
|
|
71
|
+
code: constantCase(statusText),
|
|
72
|
+
data: {}
|
|
73
|
+
},
|
|
74
|
+
requestId: httpClientError.requestId
|
|
75
|
+
};
|
|
76
|
+
return wrapError(httpClientError, {
|
|
77
|
+
message: JSON.stringify({
|
|
78
|
+
message,
|
|
79
|
+
details
|
|
80
|
+
}, null, 2),
|
|
81
|
+
extraProperties: {
|
|
82
|
+
details,
|
|
83
|
+
status
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return buildSystemError(httpClientError);
|
|
88
|
+
}
|
|
89
|
+
var buildValidationError = (httpClientError, pathsToArguments, argumentNames) => {
|
|
90
|
+
const validationErrorResponse = httpClientError.response?.data;
|
|
91
|
+
const requestId = httpClientError.requestId;
|
|
92
|
+
const { fieldViolations } = validationErrorResponse.details.validationError;
|
|
93
|
+
const transformedFieldViolations = violationsWithRenamedFields(pathsToArguments, fieldViolations, argumentNames)?.sort((a, b) => a.field < b.field ? -1 : 1);
|
|
94
|
+
const message = `INVALID_ARGUMENT: ${transformedFieldViolations?.map(({ field, description }) => `"${field}" ${description}`)?.join(", ")}`;
|
|
95
|
+
const details = {
|
|
96
|
+
validationError: { fieldViolations: transformedFieldViolations },
|
|
97
|
+
requestId
|
|
98
|
+
};
|
|
99
|
+
return wrapError(httpClientError, {
|
|
100
|
+
message: JSON.stringify({ message, details }, null, 2),
|
|
101
|
+
extraProperties: {
|
|
102
|
+
details,
|
|
103
|
+
status: httpClientError.response?.status,
|
|
104
|
+
requestId
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
var wrapError = (baseError, { message, extraProperties }) => {
|
|
109
|
+
return Object.assign(baseError, {
|
|
110
|
+
...extraProperties,
|
|
111
|
+
message
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
var buildApplicationError = (httpClientError) => {
|
|
115
|
+
const status = httpClientError.response?.status;
|
|
116
|
+
const statusText = httpClientError.response?.statusText ?? "UNKNOWN";
|
|
117
|
+
const message = httpClientError.response?.data?.message ?? statusText;
|
|
118
|
+
const description = httpClientError.response?.data?.details?.applicationError?.description ?? statusText;
|
|
119
|
+
const code = httpClientError.response?.data?.details?.applicationError?.code ?? constantCase(statusText);
|
|
120
|
+
const data = httpClientError.response?.data?.details?.applicationError?.data ?? {};
|
|
121
|
+
const combinedMessage = message === description ? message : `${message}: ${description}`;
|
|
122
|
+
const details = {
|
|
123
|
+
applicationError: {
|
|
124
|
+
description,
|
|
125
|
+
code,
|
|
126
|
+
data
|
|
127
|
+
},
|
|
128
|
+
requestId: httpClientError.requestId
|
|
129
|
+
};
|
|
130
|
+
return wrapError(httpClientError, {
|
|
131
|
+
message: JSON.stringify({ message: combinedMessage, details }, null, 2),
|
|
132
|
+
extraProperties: {
|
|
133
|
+
details,
|
|
134
|
+
status,
|
|
135
|
+
requestId: httpClientError.requestId
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
var buildSystemError = (httpClientError) => {
|
|
140
|
+
const message = httpClientError.requestId ? `System error occurred, request-id: ${httpClientError.requestId}` : `System error occurred: ${JSON.stringify(httpClientError)}`;
|
|
141
|
+
return wrapError(httpClientError, {
|
|
142
|
+
message,
|
|
143
|
+
extraProperties: {
|
|
144
|
+
requestId: httpClientError.requestId,
|
|
145
|
+
status: httpClientError.response?.status,
|
|
146
|
+
code: constantCase(httpClientError.response?.statusText ?? "UNKNOWN"),
|
|
147
|
+
...!httpClientError.response && {
|
|
148
|
+
runtimeError: httpClientError
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
var violationsWithRenamedFields = ({ spreadPathsToArguments, explicitPathsToArguments, singleArgumentUnchanged }, fieldViolations, argumentNames) => {
|
|
154
|
+
const allPathsToArguments = {
|
|
155
|
+
...spreadPathsToArguments,
|
|
156
|
+
...explicitPathsToArguments
|
|
157
|
+
};
|
|
158
|
+
const allPathsToArgumentsKeys = Object.keys(allPathsToArguments);
|
|
159
|
+
return fieldViolations?.filter((fieldViolation) => {
|
|
160
|
+
const containedInAMoreSpecificViolationField = fieldViolations.some((anotherViolation) => anotherViolation.field.length > fieldViolation.field.length && anotherViolation.field.startsWith(fieldViolation.field) && allPathsToArgumentsKeys.includes(anotherViolation.field));
|
|
161
|
+
return !containedInAMoreSpecificViolationField;
|
|
162
|
+
}).map((fieldViolation) => {
|
|
163
|
+
const exactMatchArgumentExpression = explicitPathsToArguments[fieldViolation.field];
|
|
164
|
+
if (exactMatchArgumentExpression) {
|
|
165
|
+
return {
|
|
166
|
+
...fieldViolation,
|
|
167
|
+
field: withRenamedArgument(exactMatchArgumentExpression, argumentNames)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const longestPartialPathMatch = allPathsToArgumentsKeys?.sort((a, b) => b.length - a.length)?.find((path) => fieldViolation.field.startsWith(path));
|
|
171
|
+
if (longestPartialPathMatch) {
|
|
172
|
+
const partialMatchArgumentExpression = allPathsToArguments[longestPartialPathMatch];
|
|
173
|
+
if (partialMatchArgumentExpression) {
|
|
174
|
+
return {
|
|
175
|
+
...fieldViolation,
|
|
176
|
+
field: fieldViolation.field.replace(longestPartialPathMatch, withRenamedArgument(partialMatchArgumentExpression, argumentNames))
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (singleArgumentUnchanged) {
|
|
181
|
+
return {
|
|
182
|
+
...fieldViolation,
|
|
183
|
+
field: `${argumentNames[0]}.${fieldViolation.field}`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return fieldViolation;
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
var withRenamedArgument = (fieldValue, argumentNames) => {
|
|
190
|
+
const argIndex = getArgumentIndex(fieldValue);
|
|
191
|
+
if (argIndex !== null && typeof argIndex !== "undefined") {
|
|
192
|
+
return fieldValue.replace(`$[${argIndex}]`, argumentNames[argIndex]);
|
|
193
|
+
}
|
|
194
|
+
return fieldValue;
|
|
195
|
+
};
|
|
196
|
+
var getArgumentIndex = (s) => {
|
|
197
|
+
const match = s.match(/\$\[(?<argIndex>\d+)\]/);
|
|
198
|
+
return match && match.groups && Number(match.groups.argIndex);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// ../../node_modules/@wix/sdk-runtime/build/rename-all-nested-keys.js
|
|
202
|
+
function renameAllNestedKeys(payload, renameMap, ignorePaths) {
|
|
203
|
+
const isIgnored = (path) => ignorePaths.includes(path);
|
|
204
|
+
const traverse = (obj, path) => {
|
|
205
|
+
if (Array.isArray(obj)) {
|
|
206
|
+
obj.forEach((item) => {
|
|
207
|
+
traverse(item, path);
|
|
208
|
+
});
|
|
209
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
210
|
+
const objAsRecord = obj;
|
|
211
|
+
Object.keys(objAsRecord).forEach((key) => {
|
|
212
|
+
const newPath = path === "" ? key : `${path}.${key}`;
|
|
213
|
+
if (isIgnored(newPath)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (key in renameMap && !(renameMap[key] in objAsRecord)) {
|
|
217
|
+
objAsRecord[renameMap[key]] = objAsRecord[key];
|
|
218
|
+
delete objAsRecord[key];
|
|
219
|
+
}
|
|
220
|
+
traverse(objAsRecord[key], newPath);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
traverse(payload, "");
|
|
225
|
+
return payload;
|
|
226
|
+
}
|
|
227
|
+
function renameKeysFromSDKRequestToRESTRequest(payload, ignorePaths = []) {
|
|
228
|
+
return renameAllNestedKeys(payload, SDKRequestToRESTRequestRenameMap, ignorePaths);
|
|
229
|
+
}
|
|
230
|
+
function renameKeysFromRESTResponseToSDKResponse(payload, ignorePaths = []) {
|
|
231
|
+
return renameAllNestedKeys(payload, RESTResponseToSDKResponseRenameMap, ignorePaths);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ../../node_modules/@wix/sdk-runtime/build/rest-modules.js
|
|
235
|
+
function createRESTModule(descriptor, elevated = false) {
|
|
236
|
+
return contextualizeRESTModuleV2(descriptor, elevated);
|
|
237
|
+
}
|
|
238
|
+
function toURLSearchParams(params, isComplexRequest) {
|
|
239
|
+
const flatten = flattenParams(params);
|
|
240
|
+
const isPayloadNonSerializableAsUrlSearchParams = Object.entries(flatten).some(([key, value]) => key.includes(".") || Array.isArray(value) && value.some((v) => typeof v === "object"));
|
|
241
|
+
const shouldSerializeToRParam = isComplexRequest && isPayloadNonSerializableAsUrlSearchParams;
|
|
242
|
+
if (shouldSerializeToRParam) {
|
|
243
|
+
return new URLSearchParams({ ".r": base64Encode(JSON.stringify(params)) });
|
|
244
|
+
} else {
|
|
245
|
+
return Object.entries(flatten).reduce((urlSearchParams, [key, value]) => {
|
|
246
|
+
const keyParams = Array.isArray(value) ? value : [value];
|
|
247
|
+
keyParams.forEach((param) => {
|
|
248
|
+
if (param === void 0 || param === null || Array.isArray(value) && typeof param === "object") {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
urlSearchParams.append(key, param);
|
|
252
|
+
});
|
|
253
|
+
return urlSearchParams;
|
|
254
|
+
}, new URLSearchParams());
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function resolveUrl(opts) {
|
|
258
|
+
const domain = resolveDomain(opts.host);
|
|
259
|
+
const mappings = resolveMappingsByDomain(domain, opts.domainToMappings);
|
|
260
|
+
const path = injectDataIntoProtoPath(opts.protoPath, opts.data || {});
|
|
261
|
+
return resolvePathFromMappings(path, mappings);
|
|
262
|
+
}
|
|
263
|
+
function flattenParams(data, path = "") {
|
|
264
|
+
const params = {};
|
|
265
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
266
|
+
const isObject = value !== null && typeof value === "object" && !Array.isArray(value);
|
|
267
|
+
const fieldPath = resolvePath(path, key);
|
|
268
|
+
if (isObject) {
|
|
269
|
+
const serializedObject = flattenParams(value, fieldPath);
|
|
270
|
+
Object.assign(params, serializedObject);
|
|
271
|
+
} else {
|
|
272
|
+
params[fieldPath] = value;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return params;
|
|
276
|
+
}
|
|
277
|
+
function resolvePath(path, key) {
|
|
278
|
+
return `${path}${path ? "." : ""}${key}`;
|
|
279
|
+
}
|
|
280
|
+
var base64Encode = (value) => {
|
|
281
|
+
const base64 = typeof btoa !== "undefined" ? btoa(value) : Buffer.from(value, "utf-8").toString("base64");
|
|
282
|
+
return base64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
283
|
+
};
|
|
284
|
+
var DOMAINS = ["wix.com", "editorx.com"];
|
|
285
|
+
var USER_DOMAIN = "_";
|
|
286
|
+
var REGEX_CAPTURE_DOMAINS = new RegExp(`\\.(${DOMAINS.join("|")})$`);
|
|
287
|
+
var WIX_API_DOMAINS = ["42.wixprod.net", "uw2-edt-1.wixprod.net"];
|
|
288
|
+
var DEV_WIX_CODE_DOMAIN = "dev.wix-code.com";
|
|
289
|
+
var REGEX_CAPTURE_PROTO_FIELD = /{(.*)}/;
|
|
290
|
+
var REGEX_CAPTURE_API_DOMAINS = new RegExp(`\\.(${WIX_API_DOMAINS.join("|")})$`);
|
|
291
|
+
var REGEX_CAPTURE_DEV_WIX_CODE_DOMAIN = new RegExp(`.*\\.${DEV_WIX_CODE_DOMAIN}$`);
|
|
292
|
+
function resolveDomain(host) {
|
|
293
|
+
const resolvedHost = fixHostExceptions(host);
|
|
294
|
+
return resolvedHost.replace(REGEX_CAPTURE_DOMAINS, "._base_domain_").replace(REGEX_CAPTURE_API_DOMAINS, "._api_base_domain_").replace(REGEX_CAPTURE_DEV_WIX_CODE_DOMAIN, "*.dev.wix-code.com");
|
|
295
|
+
}
|
|
296
|
+
function fixHostExceptions(host) {
|
|
297
|
+
return host.replace("create.editorx.com", "editor.editorx.com");
|
|
298
|
+
}
|
|
299
|
+
function resolveMappingsByDomain(domain, domainToMappings) {
|
|
300
|
+
const mappings = domainToMappings[domain] || domainToMappings[USER_DOMAIN];
|
|
301
|
+
if (!mappings) {
|
|
302
|
+
if (isBaseDomain(domain)) {
|
|
303
|
+
return domainToMappings[wwwBaseDomain];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return mappings;
|
|
307
|
+
}
|
|
308
|
+
function isBaseDomain(domain) {
|
|
309
|
+
return !!domain.match(/\._base_domain_$/);
|
|
310
|
+
}
|
|
311
|
+
var wwwBaseDomain = "www._base_domain_";
|
|
312
|
+
function injectDataIntoProtoPath(protoPath, data) {
|
|
313
|
+
return protoPath.split("/").map((path) => maybeProtoPathToData(path, data)).join("/");
|
|
314
|
+
}
|
|
315
|
+
function maybeProtoPathToData(protoPath, data) {
|
|
316
|
+
const protoRegExpMatch = protoPath.match(REGEX_CAPTURE_PROTO_FIELD) || [];
|
|
317
|
+
const field = protoRegExpMatch[1];
|
|
318
|
+
if (field) {
|
|
319
|
+
const suffix = protoPath.replace(protoRegExpMatch[0], "");
|
|
320
|
+
return findByPath(data, field, protoPath, suffix);
|
|
321
|
+
}
|
|
322
|
+
return protoPath;
|
|
323
|
+
}
|
|
324
|
+
function findByPath(obj, path, defaultValue, suffix) {
|
|
325
|
+
let result = obj;
|
|
326
|
+
for (const field of path.split(".")) {
|
|
327
|
+
if (!result) {
|
|
328
|
+
return defaultValue;
|
|
329
|
+
}
|
|
330
|
+
result = result[field];
|
|
331
|
+
}
|
|
332
|
+
return `${result}${suffix}`;
|
|
333
|
+
}
|
|
334
|
+
function resolvePathFromMappings(protoPath, mappings) {
|
|
335
|
+
const mapping = mappings?.find((m) => protoPath.startsWith(m.destPath));
|
|
336
|
+
if (!mapping) {
|
|
337
|
+
return protoPath;
|
|
338
|
+
}
|
|
339
|
+
return mapping.srcPath + protoPath.slice(mapping.destPath.length);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export {
|
|
343
|
+
SDKRequestToRESTRequestRenameMap,
|
|
344
|
+
ITEMS_RESULT_PROPERTY_NAME,
|
|
345
|
+
PAGING_METADATA_RESULT_PROPERTY_NAME,
|
|
346
|
+
DEFAULT_LIMIT,
|
|
347
|
+
transformError,
|
|
348
|
+
renameKeysFromSDKRequestToRESTRequest,
|
|
349
|
+
renameKeysFromRESTResponseToSDKResponse,
|
|
350
|
+
createRESTModule,
|
|
351
|
+
toURLSearchParams,
|
|
352
|
+
resolveUrl
|
|
353
|
+
};
|