@playdrop/playdrop-cli 0.7.15 → 0.7.16
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/config/client-meta.json +1 -1
- package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
- package/node_modules/@playdrop/ai-client/package.json +1 -1
- package/node_modules/@playdrop/api-client/dist/client.js +903 -882
- package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
- package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
- package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
- package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
- package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
- package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
- package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
- package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
- package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
- package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
- package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
- package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
- package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
- package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
- package/node_modules/@playdrop/api-client/dist/index.js +993 -552
- package/node_modules/@playdrop/api-client/package.json +1 -1
- package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
- package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
- package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
- package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
- package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
- package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
- package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
- package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
- package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
- package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
- package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
- package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
- package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
- package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
- package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
- package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
- package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
- package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
- package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
- package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
- package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
- package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
- package/node_modules/@playdrop/boxel-three/package.json +1 -1
- package/node_modules/@playdrop/config/client-meta.json +1 -1
- package/node_modules/@playdrop/types/dist/api.js +289 -203
- package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
- package/node_modules/@playdrop/types/dist/app.js +91 -45
- package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
- package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
- package/node_modules/@playdrop/types/dist/asset.js +186 -108
- package/node_modules/@playdrop/types/dist/content-license.js +49 -15
- package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
- package/node_modules/@playdrop/types/dist/ecs.js +102 -82
- package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
- package/node_modules/@playdrop/types/dist/entity.js +63 -53
- package/node_modules/@playdrop/types/dist/graph.js +116 -80
- package/node_modules/@playdrop/types/dist/index.js +47 -20
- package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
- package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
- package/node_modules/@playdrop/types/dist/realtime.js +27 -7
- package/node_modules/@playdrop/types/dist/version.js +182 -124
- package/node_modules/@playdrop/types/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,49 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var errors_exports = {};
|
|
19
|
+
__export(errors_exports, {
|
|
20
|
+
handleApiError: () => handleApiError,
|
|
21
|
+
parseUnsupportedError: () => parseUnsupportedError
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
|
+
var import_api = require("@playdrop/types/api");
|
|
25
|
+
function parseUnsupportedError(status, payload) {
|
|
26
|
+
if (status !== 426 && status !== 400) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const data = payload && typeof payload === "object" ? payload : null;
|
|
30
|
+
const code = typeof data?.["error"] === "string" ? data["error"] : void 0;
|
|
31
|
+
const unsupportedCodes = /* @__PURE__ */ new Set([
|
|
32
|
+
"unsupported_client",
|
|
33
|
+
"unsupported_client_version",
|
|
34
|
+
"unsupported_client_build",
|
|
35
|
+
"unsupported_platform_version",
|
|
36
|
+
"missing_client_metadata"
|
|
37
|
+
]);
|
|
38
|
+
const isGuardResponse = status === 426 || status === 400 && code !== void 0 && unsupportedCodes.has(code);
|
|
39
|
+
if (!isGuardResponse) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const message = typeof data?.["message"] === "string" ? data["message"] : "Unsupported client version";
|
|
43
|
+
return new import_api.UnsupportedClientError(code ?? "unsupported_client", message, data ?? null);
|
|
21
44
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
message = payload["error"];
|
|
38
|
-
if (typeof payload["errorPath"] === 'string') {
|
|
39
|
-
message = `${payload["error"]}: ${payload["errorPath"]}`;
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(payload["missing"]) && payload["missing"].length > 0) {
|
|
42
|
-
message = `${payload["error"]}: missing exports [${payload["missing"].join(', ')}]`;
|
|
43
|
-
}
|
|
45
|
+
function handleApiError(response, context) {
|
|
46
|
+
const unsupported = parseUnsupportedError(response.status, response.body);
|
|
47
|
+
if (unsupported) {
|
|
48
|
+
throw unsupported;
|
|
49
|
+
}
|
|
50
|
+
const payload = response.body && typeof response.body === "object" ? response.body : {};
|
|
51
|
+
const details = response.body && typeof response.body === "object" ? response.body : null;
|
|
52
|
+
const code = typeof payload["error"] === "string" ? payload["error"] : context;
|
|
53
|
+
let message;
|
|
54
|
+
if (typeof payload["message"] === "string") {
|
|
55
|
+
message = payload["message"];
|
|
56
|
+
} else if (typeof payload["error"] === "string") {
|
|
57
|
+
message = payload["error"];
|
|
58
|
+
if (typeof payload["errorPath"] === "string") {
|
|
59
|
+
message = `${payload["error"]}: ${payload["errorPath"]}`;
|
|
44
60
|
}
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
if (Array.isArray(payload["missing"]) && payload["missing"].length > 0) {
|
|
62
|
+
message = `${payload["error"]}: missing exports [${payload["missing"].join(", ")}]`;
|
|
47
63
|
}
|
|
48
|
-
|
|
64
|
+
} else {
|
|
65
|
+
message = `${context} failed`;
|
|
66
|
+
}
|
|
67
|
+
throw new import_api.ApiError(message, response.status, code, details);
|
|
49
68
|
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
handleApiError,
|
|
72
|
+
parseUnsupportedError
|
|
73
|
+
});
|
|
@@ -1,181 +1,210 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var request_exports = {};
|
|
19
|
+
__export(request_exports, {
|
|
20
|
+
DEFAULT_REQUEST_TIMEOUT_MS: () => DEFAULT_REQUEST_TIMEOUT_MS,
|
|
21
|
+
buildBrowserCredentialsInit: () => buildBrowserCredentialsInit,
|
|
22
|
+
createBaseUrlResolver: () => createBaseUrlResolver,
|
|
23
|
+
createRequestExecutor: () => createRequestExecutor,
|
|
24
|
+
parseResponseBody: () => parseResponseBody,
|
|
25
|
+
resolveRequestTimeoutMs: () => resolveRequestTimeoutMs,
|
|
26
|
+
resolveUrl: () => resolveUrl
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(request_exports);
|
|
29
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 15e3;
|
|
30
|
+
function resolveRequestTimeoutMs(value) {
|
|
31
|
+
if (value === void 0) {
|
|
32
|
+
return DEFAULT_REQUEST_TIMEOUT_MS;
|
|
33
|
+
}
|
|
34
|
+
const parsed = Number(value);
|
|
35
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
36
|
+
throw new Error("invalid_api_request_timeout_ms");
|
|
37
|
+
}
|
|
38
|
+
return Math.floor(parsed);
|
|
11
39
|
}
|
|
12
40
|
function trimTrailingSlash(value) {
|
|
13
|
-
|
|
41
|
+
return value.replace(/\/+$/, "");
|
|
14
42
|
}
|
|
15
43
|
function normalizeHostname(value) {
|
|
16
|
-
|
|
44
|
+
return value.trim().toLowerCase();
|
|
17
45
|
}
|
|
18
46
|
function isLoopbackHostname(hostname) {
|
|
19
|
-
|
|
20
|
-
|| hostname === '127.0.0.1'
|
|
21
|
-
|| hostname === '0.0.0.0';
|
|
47
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0";
|
|
22
48
|
}
|
|
23
49
|
function resolvePlaydropSurface(hostname) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
if (hostname === "playdrop.ai" || hostname === "www.playdrop.ai") {
|
|
51
|
+
return "prod";
|
|
52
|
+
}
|
|
53
|
+
if (hostname === "preview.playdrop.ai") {
|
|
54
|
+
return "preview";
|
|
55
|
+
}
|
|
56
|
+
if (hostname === "blue.playdrop.ai") {
|
|
57
|
+
return "blue";
|
|
58
|
+
}
|
|
59
|
+
if (hostname === "green.playdrop.ai") {
|
|
60
|
+
return "green";
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
37
63
|
}
|
|
38
64
|
function buildPlaydropApiOrigin(protocol, surface) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: `api.${surface}.playdrop.ai`;
|
|
42
|
-
return `${protocol}//${host}`;
|
|
65
|
+
const host = surface === "prod" ? "api.playdrop.ai" : `api.${surface}.playdrop.ai`;
|
|
66
|
+
return `${protocol}//${host}`;
|
|
43
67
|
}
|
|
44
68
|
function resolveBrowserApiBaseUrl() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
const { protocol, hostname } = window.location;
|
|
70
|
+
const normalizedProtocol = protocol === "https:" ? "https:" : "http:";
|
|
71
|
+
const normalizedHostname = normalizeHostname(hostname);
|
|
72
|
+
if (isLoopbackHostname(normalizedHostname)) {
|
|
73
|
+
return "http://localhost:4000";
|
|
74
|
+
}
|
|
75
|
+
if (normalizedHostname === "www.localhost") {
|
|
76
|
+
return `${normalizedProtocol}//api.localhost`;
|
|
77
|
+
}
|
|
78
|
+
if (normalizedHostname === "play.local") {
|
|
79
|
+
return `${normalizedProtocol}//api.local`;
|
|
80
|
+
}
|
|
81
|
+
if (normalizedHostname.endsWith(".localhost")) {
|
|
82
|
+
return `${normalizedProtocol}//api.${normalizedHostname.slice(0, -".localhost".length)}.localhost`;
|
|
83
|
+
}
|
|
84
|
+
if (normalizedHostname.endsWith(".local")) {
|
|
85
|
+
return `${normalizedProtocol}//api.${normalizedHostname.slice(0, -".local".length)}.local`;
|
|
86
|
+
}
|
|
87
|
+
const playdropSurface = resolvePlaydropSurface(normalizedHostname);
|
|
88
|
+
if (playdropSurface) {
|
|
89
|
+
return buildPlaydropApiOrigin(normalizedProtocol, playdropSurface);
|
|
90
|
+
}
|
|
91
|
+
if (normalizedHostname.startsWith("www.") && normalizedHostname.includes(".")) {
|
|
92
|
+
return `${normalizedProtocol}//api.${normalizedHostname.slice("www.".length)}`;
|
|
93
|
+
}
|
|
94
|
+
return `${normalizedProtocol}//${normalizedHostname}:4000`;
|
|
95
|
+
}
|
|
96
|
+
function createBaseUrlResolver(baseUrl) {
|
|
97
|
+
return () => {
|
|
98
|
+
if (baseUrl) {
|
|
99
|
+
return baseUrl;
|
|
62
100
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return buildPlaydropApiOrigin(normalizedProtocol, playdropSurface);
|
|
101
|
+
if (typeof window !== "undefined") {
|
|
102
|
+
return resolveBrowserApiBaseUrl();
|
|
66
103
|
}
|
|
67
|
-
if (
|
|
68
|
-
|
|
104
|
+
if (typeof process !== "undefined" && process.env["NEXT_PUBLIC_API_BASE"]) {
|
|
105
|
+
return trimTrailingSlash(process.env["NEXT_PUBLIC_API_BASE"]);
|
|
69
106
|
}
|
|
70
|
-
return
|
|
107
|
+
return "http://localhost:4000";
|
|
108
|
+
};
|
|
71
109
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
if (typeof process !== 'undefined' && process.env["NEXT_PUBLIC_API_BASE"]) {
|
|
81
|
-
return trimTrailingSlash(process.env["NEXT_PUBLIC_API_BASE"]);
|
|
82
|
-
}
|
|
83
|
-
return 'http://localhost:4000';
|
|
84
|
-
};
|
|
110
|
+
function resolveUrl(base, path) {
|
|
111
|
+
if (/^https?:/i.test(path)) {
|
|
112
|
+
return path;
|
|
113
|
+
}
|
|
114
|
+
const normalizedBase = base.endsWith("/") ? base : `${base}/`;
|
|
115
|
+
const trimmedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
116
|
+
return new URL(trimmedPath, normalizedBase).toString();
|
|
85
117
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const trimmedPath = path.startsWith('/') ? path.slice(1) : path;
|
|
92
|
-
return new URL(trimmedPath, normalizedBase).toString();
|
|
118
|
+
function buildBrowserCredentialsInit(includeBrowserCredentials) {
|
|
119
|
+
if (!includeBrowserCredentials || typeof window === "undefined") {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
return { credentials: "include" };
|
|
93
123
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
export async function parseResponseBody(response) {
|
|
101
|
-
if (response.status === 204 || response.status === 205 || response.status === 304) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
const contentType = response.headers.get('content-type') || '';
|
|
105
|
-
if (contentType.includes('application/json')) {
|
|
106
|
-
try {
|
|
107
|
-
return (await response.clone().json());
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
// fall through to text if parsing fails
|
|
111
|
-
}
|
|
112
|
-
}
|
|
124
|
+
async function parseResponseBody(response) {
|
|
125
|
+
if (response.status === 204 || response.status === 205 || response.status === 304) {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
const contentType = response.headers.get("content-type") || "";
|
|
129
|
+
if (contentType.includes("application/json")) {
|
|
113
130
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
return await response.clone().json();
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const text = await response.clone().text();
|
|
137
|
+
return text;
|
|
138
|
+
} catch {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
120
141
|
}
|
|
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
|
-
if (req.body !== undefined && req.body !== null && req.method !== 'GET') {
|
|
149
|
-
init.body = typeof req.body === 'string' ? req.body : JSON.stringify(req.body);
|
|
150
|
-
}
|
|
151
|
-
let timeoutHandle = null;
|
|
152
|
-
let controller = null;
|
|
153
|
-
if (typeof AbortController !== 'undefined') {
|
|
154
|
-
controller = new AbortController();
|
|
155
|
-
init.signal = controller.signal;
|
|
156
|
-
timeoutHandle = setTimeout(() => {
|
|
157
|
-
controller?.abort();
|
|
158
|
-
}, requestTimeoutMs);
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const response = await fetchImpl(targetUrl, init);
|
|
162
|
-
const parsed = await parseResponseBodyInput(response);
|
|
163
|
-
return {
|
|
164
|
-
status: response.status,
|
|
165
|
-
body: parsed,
|
|
166
|
-
headers: response.headers,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
if (controller?.signal.aborted) {
|
|
171
|
-
throw new Error(`api_request_timeout:${req.method}:${req.path}`);
|
|
172
|
-
}
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
finally {
|
|
176
|
-
if (timeoutHandle) {
|
|
177
|
-
clearTimeout(timeoutHandle);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
142
|
+
function createRequestExecutor(input) {
|
|
143
|
+
const { fetchImpl, resolveBaseUrl, resolveUrl: resolveUrlInput, parseResponseBody: parseResponseBodyInput, resolveToken, getClientHeaders, requestTimeoutMs, includeBrowserCredentials } = input;
|
|
144
|
+
return async function request(req) {
|
|
145
|
+
const base = resolveBaseUrl();
|
|
146
|
+
const targetUrl = resolveUrlInput(base, req.path);
|
|
147
|
+
const headers = new Headers();
|
|
148
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
149
|
+
headers.set(key, value);
|
|
150
|
+
}
|
|
151
|
+
headers.set("accept", "application/json");
|
|
152
|
+
if (req.body !== void 0 && req.body !== null && req.method !== "GET") {
|
|
153
|
+
headers.set("content-type", "application/json");
|
|
154
|
+
}
|
|
155
|
+
if (req.headers) {
|
|
156
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
157
|
+
headers.set(key, value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const token = await resolveToken();
|
|
161
|
+
if (token) {
|
|
162
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
163
|
+
}
|
|
164
|
+
const init = {
|
|
165
|
+
method: req.method,
|
|
166
|
+
headers,
|
|
167
|
+
...buildBrowserCredentialsInit(includeBrowserCredentials)
|
|
180
168
|
};
|
|
169
|
+
if (req.body !== void 0 && req.body !== null && req.method !== "GET") {
|
|
170
|
+
init.body = typeof req.body === "string" ? req.body : JSON.stringify(req.body);
|
|
171
|
+
}
|
|
172
|
+
let timeoutHandle = null;
|
|
173
|
+
let controller = null;
|
|
174
|
+
if (typeof AbortController !== "undefined") {
|
|
175
|
+
controller = new AbortController();
|
|
176
|
+
init.signal = controller.signal;
|
|
177
|
+
timeoutHandle = setTimeout(() => {
|
|
178
|
+
controller?.abort();
|
|
179
|
+
}, requestTimeoutMs);
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const response = await fetchImpl(targetUrl, init);
|
|
183
|
+
const parsed = await parseResponseBodyInput(response);
|
|
184
|
+
return {
|
|
185
|
+
status: response.status,
|
|
186
|
+
body: parsed,
|
|
187
|
+
headers: response.headers
|
|
188
|
+
};
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (controller?.signal.aborted) {
|
|
191
|
+
throw new Error(`api_request_timeout:${req.method}:${req.path}`);
|
|
192
|
+
}
|
|
193
|
+
throw error;
|
|
194
|
+
} finally {
|
|
195
|
+
if (timeoutHandle) {
|
|
196
|
+
clearTimeout(timeoutHandle);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
181
200
|
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
204
|
+
buildBrowserCredentialsInit,
|
|
205
|
+
createBaseUrlResolver,
|
|
206
|
+
createRequestExecutor,
|
|
207
|
+
parseResponseBody,
|
|
208
|
+
resolveRequestTimeoutMs,
|
|
209
|
+
resolveUrl
|
|
210
|
+
});
|