@playdrop/playdrop-cli 0.7.15 → 0.7.17

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.
Files changed (70) hide show
  1. package/config/client-meta.json +1 -1
  2. package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
  3. package/node_modules/@playdrop/ai-client/package.json +1 -1
  4. package/node_modules/@playdrop/api-client/dist/client.js +903 -882
  5. package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
  6. package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
  7. package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
  8. package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
  9. package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
  10. package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
  11. package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
  12. package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
  13. package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
  14. package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
  15. package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
  16. package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
  17. package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
  18. package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
  19. package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
  20. package/node_modules/@playdrop/api-client/dist/index.js +993 -552
  21. package/node_modules/@playdrop/api-client/package.json +1 -1
  22. package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
  23. package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
  24. package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
  25. package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
  26. package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
  27. package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
  28. package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
  29. package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
  30. package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
  31. package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
  32. package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
  33. package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
  34. package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
  35. package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
  36. package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
  37. package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
  38. package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
  39. package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
  40. package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
  41. package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
  42. package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
  43. package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
  44. package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
  45. package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
  46. package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
  47. package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
  48. package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
  49. package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
  50. package/node_modules/@playdrop/boxel-three/package.json +1 -1
  51. package/node_modules/@playdrop/config/client-meta.json +1 -1
  52. package/node_modules/@playdrop/types/dist/api.js +289 -203
  53. package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
  54. package/node_modules/@playdrop/types/dist/app.js +91 -45
  55. package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
  56. package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
  57. package/node_modules/@playdrop/types/dist/asset.js +186 -108
  58. package/node_modules/@playdrop/types/dist/content-license.js +49 -15
  59. package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
  60. package/node_modules/@playdrop/types/dist/ecs.js +102 -82
  61. package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
  62. package/node_modules/@playdrop/types/dist/entity.js +63 -53
  63. package/node_modules/@playdrop/types/dist/graph.js +116 -80
  64. package/node_modules/@playdrop/types/dist/index.js +47 -20
  65. package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
  66. package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
  67. package/node_modules/@playdrop/types/dist/realtime.js +27 -7
  68. package/node_modules/@playdrop/types/dist/version.js +182 -124
  69. package/node_modules/@playdrop/types/package.json +1 -1
  70. package/package.json +1 -1
@@ -1,49 +1,73 @@
1
- import { ApiError, UnsupportedClientError } from '@playdrop/types/api';
2
- export function parseUnsupportedError(status, payload) {
3
- if (status !== 426 && status !== 400) {
4
- return null;
5
- }
6
- const data = (payload && typeof payload === 'object') ? payload : null;
7
- const code = typeof data?.["error"] === 'string' ? data["error"] : undefined;
8
- const unsupportedCodes = new Set([
9
- 'unsupported_client',
10
- 'unsupported_client_version',
11
- 'unsupported_client_build',
12
- 'unsupported_platform_version',
13
- 'missing_client_metadata',
14
- ]);
15
- const isGuardResponse = status === 426 || (status === 400 && code !== undefined && unsupportedCodes.has(code));
16
- if (!isGuardResponse) {
17
- return null;
18
- }
19
- const message = typeof data?.["message"] === 'string' ? data["message"] : 'Unsupported client version';
20
- return new UnsupportedClientError(code ?? 'unsupported_client', message, data ?? null);
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
- export function handleApiError(response, context) {
23
- const unsupported = parseUnsupportedError(response.status, response.body);
24
- if (unsupported) {
25
- throw unsupported;
26
- }
27
- const payload = response.body && typeof response.body === 'object' ? response.body : {};
28
- const details = response.body && typeof response.body === 'object'
29
- ? response.body
30
- : null;
31
- const code = typeof payload["error"] === 'string' ? payload["error"] : context;
32
- let message;
33
- if (typeof payload["message"] === 'string') {
34
- message = payload["message"];
35
- }
36
- else if (typeof payload["error"] === 'string') {
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
- else {
46
- message = `${context} failed`;
61
+ if (Array.isArray(payload["missing"]) && payload["missing"].length > 0) {
62
+ message = `${payload["error"]}: missing exports [${payload["missing"].join(", ")}]`;
47
63
  }
48
- throw new ApiError(message, response.status, code, details);
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
- export const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
2
- export function resolveRequestTimeoutMs(value) {
3
- if (value === undefined) {
4
- return DEFAULT_REQUEST_TIMEOUT_MS;
5
- }
6
- const parsed = Number(value);
7
- if (!Number.isFinite(parsed) || parsed <= 0) {
8
- throw new Error('invalid_api_request_timeout_ms');
9
- }
10
- return Math.floor(parsed);
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
- return value.replace(/\/+$/, '');
41
+ return value.replace(/\/+$/, "");
14
42
  }
15
43
  function normalizeHostname(value) {
16
- return value.trim().toLowerCase();
44
+ return value.trim().toLowerCase();
17
45
  }
18
46
  function isLoopbackHostname(hostname) {
19
- return hostname === 'localhost'
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
- if (hostname === 'playdrop.ai' || hostname === 'www.playdrop.ai') {
25
- return 'prod';
26
- }
27
- if (hostname === 'preview.playdrop.ai') {
28
- return 'preview';
29
- }
30
- if (hostname === 'blue.playdrop.ai') {
31
- return 'blue';
32
- }
33
- if (hostname === 'green.playdrop.ai') {
34
- return 'green';
35
- }
36
- return null;
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
- const host = surface === 'prod'
40
- ? 'api.playdrop.ai'
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
- const { protocol, hostname } = window.location;
46
- const normalizedProtocol = protocol === 'https:' ? 'https:' : 'http:';
47
- const normalizedHostname = normalizeHostname(hostname);
48
- if (isLoopbackHostname(normalizedHostname)) {
49
- return 'http://localhost:4000';
50
- }
51
- if (normalizedHostname === 'www.localhost') {
52
- return `${normalizedProtocol}//api.localhost`;
53
- }
54
- if (normalizedHostname === 'play.local') {
55
- return `${normalizedProtocol}//api.local`;
56
- }
57
- if (normalizedHostname.endsWith('.localhost')) {
58
- return `${normalizedProtocol}//api.${normalizedHostname.slice(0, -'.localhost'.length)}.localhost`;
59
- }
60
- if (normalizedHostname.endsWith('.local')) {
61
- return `${normalizedProtocol}//api.${normalizedHostname.slice(0, -'.local'.length)}.local`;
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
- const playdropSurface = resolvePlaydropSurface(normalizedHostname);
64
- if (playdropSurface) {
65
- return buildPlaydropApiOrigin(normalizedProtocol, playdropSurface);
101
+ if (typeof window !== "undefined") {
102
+ return resolveBrowserApiBaseUrl();
66
103
  }
67
- if (normalizedHostname.startsWith('www.') && normalizedHostname.includes('.')) {
68
- return `${normalizedProtocol}//api.${normalizedHostname.slice('www.'.length)}`;
104
+ if (typeof process !== "undefined" && process.env["NEXT_PUBLIC_API_BASE"]) {
105
+ return trimTrailingSlash(process.env["NEXT_PUBLIC_API_BASE"]);
69
106
  }
70
- return `${normalizedProtocol}//${normalizedHostname}:4000`;
107
+ return "http://localhost:4000";
108
+ };
71
109
  }
72
- export function createBaseUrlResolver(baseUrl) {
73
- return () => {
74
- if (baseUrl) {
75
- return baseUrl;
76
- }
77
- if (typeof window !== 'undefined') {
78
- return resolveBrowserApiBaseUrl();
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
- export function resolveUrl(base, path) {
87
- if (/^https?:/i.test(path)) {
88
- return path;
89
- }
90
- const normalizedBase = base.endsWith('/') ? base : `${base}/`;
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
- export function buildBrowserCredentialsInit(includeBrowserCredentials) {
95
- if (!includeBrowserCredentials || typeof window === 'undefined') {
96
- return {};
97
- }
98
- return { credentials: 'include' };
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
- const text = await response.clone().text();
115
- return text;
116
- }
117
- catch {
118
- return undefined;
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
- export function createRequestExecutor(input) {
122
- const { fetchImpl, resolveBaseUrl, resolveUrl: resolveUrlInput, parseResponseBody: parseResponseBodyInput, resolveToken, getClientHeaders, requestTimeoutMs, includeBrowserCredentials, } = input;
123
- return async function request(req) {
124
- const base = resolveBaseUrl();
125
- const targetUrl = resolveUrlInput(base, req.path);
126
- const headers = new Headers();
127
- for (const [key, value] of Object.entries(getClientHeaders())) {
128
- headers.set(key, value);
129
- }
130
- headers.set('accept', 'application/json');
131
- if (req.body !== undefined && req.body !== null && req.method !== 'GET') {
132
- headers.set('content-type', 'application/json');
133
- }
134
- if (req.headers) {
135
- for (const [key, value] of Object.entries(req.headers)) {
136
- headers.set(key, value);
137
- }
138
- }
139
- const token = await resolveToken();
140
- if (token) {
141
- headers.set('authorization', `Bearer ${token}`);
142
- }
143
- const init = {
144
- method: req.method,
145
- headers,
146
- ...buildBrowserCredentialsInit(includeBrowserCredentials),
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
+ });