@vrplatform/api 1.3.1-stage.4239 → 1.3.1-stage.42426776106
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/main/cache.js +10 -7
- package/build/main/cache.js.map +1 -1
- package/build/main/client.d.ts +6 -2
- package/build/main/client.js +18 -15
- package/build/main/client.js.map +1 -1
- package/build/main/control-plane-routing.d.ts +6 -0
- package/build/main/control-plane-routing.js +34 -0
- package/build/main/control-plane-routing.js.map +1 -0
- package/build/main/embed-lifecycle.d.ts +140 -0
- package/build/main/embed-lifecycle.js +126 -0
- package/build/main/embed-lifecycle.js.map +1 -0
- package/build/main/error.d.ts +32 -17
- package/build/main/error.js +56 -32
- package/build/main/error.js.map +1 -1
- package/build/main/generated/routing.d.ts +11 -0
- package/build/main/generated/routing.js +292 -0
- package/build/main/generated/routing.js.map +1 -0
- package/build/main/generated/v1.d.ts +4 -74851
- package/build/main/generated/v1.js.map +4 -1
- package/build/main/index.d.ts +7 -0
- package/build/main/index.js +7 -0
- package/build/main/index.js.map +1 -1
- package/build/main/is-test-team.d.ts +18 -0
- package/build/main/is-test-team.js +27 -0
- package/build/main/is-test-team.js.map +1 -0
- package/build/main/is-test-user.d.ts +4 -0
- package/build/main/is-test-user.js +31 -0
- package/build/main/is-test-user.js.map +1 -0
- package/build/main/is-vrp-member.d.ts +4 -0
- package/build/main/is-vrp-member.js +33 -0
- package/build/main/is-vrp-member.js.map +1 -0
- package/build/main/retarget-request.d.ts +7 -0
- package/build/main/retarget-request.js +21 -0
- package/build/main/retarget-request.js.map +1 -0
- package/build/main/routing.d.ts +7 -0
- package/build/main/routing.js +22 -0
- package/build/main/routing.js.map +1 -1
- package/build/main/sec.js.map +1 -1
- package/build/main/types.d.ts +2 -0
- package/build/main/types.js.map +1 -1
- package/build/main/vrt-mcp.d.ts +216 -0
- package/build/main/vrt-mcp.js +201 -0
- package/build/main/vrt-mcp.js.map +1 -0
- package/build/module/cache.js +10 -7
- package/build/module/cache.js.map +1 -1
- package/build/module/client.d.ts +6 -2
- package/build/module/client.js +18 -15
- package/build/module/client.js.map +1 -1
- package/build/module/control-plane-routing.d.ts +6 -0
- package/build/module/control-plane-routing.js +30 -0
- package/build/module/control-plane-routing.js.map +1 -0
- package/build/module/embed-lifecycle.d.ts +140 -0
- package/build/module/embed-lifecycle.js +90 -0
- package/build/module/embed-lifecycle.js.map +1 -0
- package/build/module/error.d.ts +32 -17
- package/build/module/error.js +59 -31
- package/build/module/error.js.map +1 -1
- package/build/module/generated/routing.d.ts +11 -0
- package/build/module/generated/routing.js +289 -0
- package/build/module/generated/routing.js.map +1 -0
- package/build/module/generated/v1.d.ts +4 -74851
- package/build/module/generated/v1.js.map +4 -1
- package/build/module/index.d.ts +7 -0
- package/build/module/index.js +7 -0
- package/build/module/index.js.map +1 -1
- package/build/module/is-test-team.d.ts +18 -0
- package/build/module/is-test-team.js +22 -0
- package/build/module/is-test-team.js.map +1 -0
- package/build/module/is-test-user.d.ts +4 -0
- package/build/module/is-test-user.js +27 -0
- package/build/module/is-test-user.js.map +1 -0
- package/build/module/is-vrp-member.d.ts +4 -0
- package/build/module/is-vrp-member.js +29 -0
- package/build/module/is-vrp-member.js.map +1 -0
- package/build/module/retarget-request.d.ts +7 -0
- package/build/module/retarget-request.js +18 -0
- package/build/module/retarget-request.js.map +1 -0
- package/build/module/routing.d.ts +7 -0
- package/build/module/routing.js +21 -0
- package/build/module/routing.js.map +1 -1
- package/build/module/types.d.ts +2 -0
- package/build/module/types.js.map +1 -1
- package/build/module/vrt-mcp.d.ts +216 -0
- package/build/module/vrt-mcp.js +165 -0
- package/build/module/vrt-mcp.js.map +1 -0
- package/package.json +10 -9
- package/src/cache.ts +11 -8
- package/src/client.ts +20 -17
- package/src/control-plane-routing.ts +46 -0
- package/src/embed-lifecycle.ts +96 -0
- package/src/error.ts +105 -56
- package/src/generated/routing.ts +292 -0
- package/src/generated/v1.ts +4 -74852
- package/src/index.ts +7 -0
- package/src/is-test-team.ts +50 -0
- package/src/is-test-user.ts +39 -0
- package/src/is-vrp-member.ts +38 -0
- package/src/retarget-request.ts +17 -0
- package/src/routing.ts +30 -0
- package/src/types.ts +8 -0
- package/src/vrt-mcp.ts +192 -0
- package/build/main/generated/openapi-fetch.d.ts +0 -224
- package/build/main/generated/openapi-fetch.js +0 -14
- package/build/main/generated/openapi-fetch.js.map +0 -1
- package/build/module/generated/openapi-fetch.d.ts +0 -224
- package/build/module/generated/openapi-fetch.js +0 -2
- package/build/module/generated/openapi-fetch.js.map +0 -1
- package/src/generated/openapi-fetch.ts +0 -433
package/build/main/cache.js
CHANGED
|
@@ -17,18 +17,21 @@ function useCache(fetchFn, expiryTimeMs) {
|
|
|
17
17
|
if (existingPromise)
|
|
18
18
|
return existingPromise;
|
|
19
19
|
// Start new fetch
|
|
20
|
+
const promise = fetchFn(arg);
|
|
21
|
+
fetchPromises.set(cacheKey, promise);
|
|
20
22
|
try {
|
|
21
|
-
const promise = fetchFn(arg);
|
|
22
|
-
fetchPromises.set(cacheKey, promise);
|
|
23
23
|
const freshValue = await promise;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (fetchPromises.get(cacheKey) === promise) {
|
|
25
|
+
cacheMap.set(cacheKey, {
|
|
26
|
+
value: freshValue,
|
|
27
|
+
expiresAt: Date.now() + expiryTimeMs,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
28
30
|
return freshValue;
|
|
29
31
|
}
|
|
30
32
|
finally {
|
|
31
|
-
fetchPromises.
|
|
33
|
+
if (fetchPromises.get(cacheKey) === promise)
|
|
34
|
+
fetchPromises.delete(cacheKey);
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
37
|
return {
|
package/build/main/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"src/","sources":["cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"src/","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,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,GAAG,EAAE;YACf,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,aAAa,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QACD,OAAO,EAAE,cAAc;KACxB,CAAC;AACJ,CAAC","sourcesContent":["type CacheEntry<T> = {\n value: T;\n expiresAt: number;\n};\n\ntype CacheResult<T, A> = {\n current: (arg: A) => Promise<T>;\n invalidate: () => void;\n};\n\nexport function useCache<T, A>(\n fetchFn: (arg: A) => Promise<T>,\n expiryTimeMs: number\n): CacheResult<T, A> {\n const cacheMap = new Map<string, CacheEntry<T>>();\n const fetchPromises = new Map<string, Promise<T>>();\n\n const getCachedValue = async (arg: A): Promise<T> => {\n const cacheKey = JSON.stringify(arg);\n const now = Date.now();\n\n // If cache is valid, return cached value\n const cachedEntry = cacheMap.get(cacheKey);\n if (cachedEntry && now <= cachedEntry.expiresAt) {\n return cachedEntry.value;\n }\n\n // If there's already a fetch in progress for this key, return its promise\n const existingPromise = fetchPromises.get(cacheKey);\n if (existingPromise) return existingPromise;\n\n // Start new fetch\n const promise = fetchFn(arg);\n fetchPromises.set(cacheKey, promise);\n\n try {\n const freshValue = await promise;\n if (fetchPromises.get(cacheKey) === promise) {\n cacheMap.set(cacheKey, {\n value: freshValue,\n expiresAt: Date.now() + expiryTimeMs,\n });\n }\n\n return freshValue;\n } finally {\n if (fetchPromises.get(cacheKey) === promise)\n fetchPromises.delete(cacheKey);\n }\n };\n\n return {\n invalidate: () => {\n cacheMap.clear();\n fetchPromises.clear();\n },\n current: getCachedValue,\n };\n}\n"]}
|
package/build/main/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type RetryableFetchParams } from '@vrplatform/utils';
|
|
2
|
-
import type {
|
|
2
|
+
import type { paths } from './generated/v1';
|
|
3
|
+
import type { ApiClientAuth } from './types';
|
|
3
4
|
export declare function useApiClient({ baseUrl: base, local, auth, sessionId: sid, testing, headers: h, ...retryableFetchParams }: {
|
|
5
|
+
/** Maximum attempts for GET, HEAD, and OPTIONS. Writes are attempted once. */
|
|
4
6
|
attempts?: number;
|
|
5
7
|
auth?: ApiClientAuth | (() => ApiClientAuth);
|
|
6
8
|
baseUrl?: string;
|
|
@@ -11,4 +13,6 @@ export declare function useApiClient({ baseUrl: base, local, auth, sessionId: si
|
|
|
11
13
|
overwriteUri?: string;
|
|
12
14
|
getOverwriteTimestamp?: () => number | undefined;
|
|
13
15
|
};
|
|
14
|
-
} & RetryableFetchParams):
|
|
16
|
+
} & RetryableFetchParams): import("openapi-fetch").Client<paths, `${string}/${string}`> & {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
};
|
package/build/main/client.js
CHANGED
|
@@ -41,8 +41,9 @@ const Sentry = __importStar(require("@sentry/core"));
|
|
|
41
41
|
const utils_1 = require("@vrplatform/utils");
|
|
42
42
|
const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
|
|
43
43
|
const cache_1 = require("./cache");
|
|
44
|
+
const control_plane_routing_1 = require("./control-plane-routing");
|
|
45
|
+
const retarget_request_1 = require("./retarget-request");
|
|
44
46
|
const sec_1 = require("./sec");
|
|
45
|
-
const DEFAULT_API_CLIENT_ATTEMPTS = 5;
|
|
46
47
|
function useApiClient({ baseUrl: base, local, auth, sessionId: sid,
|
|
47
48
|
// headers: h,
|
|
48
49
|
testing, headers: h, ...retryableFetchParams }) {
|
|
@@ -52,15 +53,6 @@ testing, headers: h, ...retryableFetchParams }) {
|
|
|
52
53
|
const sessionId = sid || crypto.randomUUID();
|
|
53
54
|
// cache the sec key for 1 minute (its valid for 5 minutes on the API)
|
|
54
55
|
const cache = (0, cache_1.useCache)(async (v) => (0, sec_1.generateApiKeySec)(v, testing?.getOverwriteTimestamp?.()), 60000);
|
|
55
|
-
const retryableFetch = (0, utils_1.useRetryableFetch)({
|
|
56
|
-
...retryableFetchParams,
|
|
57
|
-
attempts: retryableFetchParams.attempts ?? DEFAULT_API_CLIENT_ATTEMPTS,
|
|
58
|
-
onRetry(arg) {
|
|
59
|
-
cache.invalidate();
|
|
60
|
-
if (retryableFetchParams.onRetry)
|
|
61
|
-
retryableFetchParams.onRetry(arg);
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
56
|
const trace = Sentry.getTraceData();
|
|
65
57
|
const client = (0, openapi_fetch_1.default)({
|
|
66
58
|
baseUrl,
|
|
@@ -71,10 +63,23 @@ testing, headers: h, ...retryableFetchParams }) {
|
|
|
71
63
|
},
|
|
72
64
|
},
|
|
73
65
|
fetch(req) {
|
|
74
|
-
|
|
66
|
+
const isRead = ['GET', 'HEAD', 'OPTIONS'].includes(req.method);
|
|
67
|
+
return (0, utils_1.useRetryableFetch)({
|
|
68
|
+
...retryableFetchParams,
|
|
69
|
+
attempts: isRead ? (retryableFetchParams.attempts ?? 5) : 1,
|
|
70
|
+
assertOnLastAttempt: retryableFetchParams.assertOnLastAttempt ??
|
|
71
|
+
(!isRead && retryableFetchParams.assertResponse !== undefined),
|
|
72
|
+
onRetry(arg) {
|
|
73
|
+
cache.invalidate();
|
|
74
|
+
return retryableFetchParams.onRetry?.(arg);
|
|
75
|
+
},
|
|
76
|
+
})(async () => {
|
|
75
77
|
let clone = req.clone();
|
|
78
|
+
const url = (0, control_plane_routing_1.getControlPlaneRequestUrl)(req.method, new URL(req.url));
|
|
79
|
+
if (url.href !== req.url)
|
|
80
|
+
clone = await (0, retarget_request_1.retargetRequest)(clone, url);
|
|
76
81
|
if (testing?.overwriteUri)
|
|
77
|
-
clone =
|
|
82
|
+
clone = await (0, retarget_request_1.retargetRequest)(clone, testing.overwriteUri);
|
|
78
83
|
const a = (typeof auth === 'function' ? auth() : auth) || {};
|
|
79
84
|
if (sessionId)
|
|
80
85
|
clone.headers.set('X-Session-Id', sessionId);
|
|
@@ -100,8 +105,6 @@ testing, headers: h, ...retryableFetchParams }) {
|
|
|
100
105
|
});
|
|
101
106
|
},
|
|
102
107
|
});
|
|
103
|
-
|
|
104
|
-
sessionClient.sessionId = sessionId;
|
|
105
|
-
return sessionClient;
|
|
108
|
+
return Object.assign(client, { sessionId });
|
|
106
109
|
}
|
|
107
110
|
//# sourceMappingURL=client.js.map
|
package/build/main/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,MAAM,yCAAqB;AACvC,6CAG2B;AAC3B,kEAAyC;AACzC,mCAAmC;AACnC,mEAAoE;AAEpE,yDAAqD;AACrD,+BAA0C;AAG1C,sBAA6B,EAC3B,OAAO,EAAE,IAAI,EACb,KAAK,EACL,IAAI,EACJ,SAAS,EAAE,GAAG;AACd,cAAc;AACd,OAAO,EACP,OAAO,EAAE,CAAC,EACV,GAAG,oBAAoB,EAaD;IACtB,MAAM,OAAO,GACX,CAAC,KAAK;QACJ,CAAC,CAAC,oBAAoB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;QAChE,CAAC,CAAC,IAAI,CAAC,IAAI,4BAA4B,CAAC;IAE5C,MAAM,SAAS,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7C,sEAAsE;IACtE,MAAM,KAAK,GAAG,IAAA,gBAAQ,EACpB,KAAK,EAAE,CAAS,EAAE,EAAE,CAClB,IAAA,uBAAiB,EAAC,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,EAAE,CAAC,EAC1D,KAAM,CACP,CAAC;IAEF,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,IAAA,uBAAY,EAAQ;QACjC,OAAO;QACP,eAAe,EAAE;YACf,KAAK,EAA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C,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;gBAE/D,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAqB,CAAC;AAClE,CAAC","sourcesContent":["import * as Sentry from '@sentry/core';\nimport {\n type RetryableFetchParams,\n useRetryableFetch,\n} from '@vrplatform/utils';\nimport createClient from 'openapi-fetch';\nimport { useCache } from './cache';\nimport { getControlPlaneRequestUrl } from './control-plane-routing';\nimport type { paths } from './generated/v1';\nimport { retargetRequest } from './retarget-request';\nimport { generateApiKeySec } from './sec';\nimport type { ApiClient, ApiClientAuth } from './types';\n\nexport function useApiClient({\n baseUrl: base,\n local,\n auth,\n sessionId: sid,\n // headers: h,\n testing,\n headers: h,\n ...retryableFetchParams\n}: {\n /** Maximum attempts for GET, HEAD, and OPTIONS. Writes are attempted once. */\n attempts?: number;\n auth?: ApiClientAuth | (() => ApiClientAuth);\n baseUrl?: string;\n sessionId?: string;\n local?: boolean | number;\n headers?: Record<string, string> | (() => Record<string, string>);\n testing?: {\n overwriteUri?: string;\n getOverwriteTimestamp?: () => number | undefined;\n };\n} & RetryableFetchParams) {\n const baseUrl =\n (local\n ? `http://localhost:${typeof local === 'number' ? local : 8877}`\n : base) || 'https://api.vrplatform.app';\n\n const sessionId = sid || crypto.randomUUID();\n // cache the sec key for 1 minute (its valid for 5 minutes on the API)\n const cache = useCache(\n async (v: string) =>\n generateApiKeySec(v, testing?.getOverwriteTimestamp?.()),\n 60_000\n );\n\n const trace = Sentry.getTraceData();\n const client = createClient<paths>({\n baseUrl,\n querySerializer: {\n array: {\n explode: false,\n style: 'form',\n },\n },\n fetch(req) {\n const isRead = ['GET', 'HEAD', 'OPTIONS'].includes(req.method);\n return useRetryableFetch({\n ...retryableFetchParams,\n attempts: isRead ? (retryableFetchParams.attempts ?? 5) : 1,\n assertOnLastAttempt:\n retryableFetchParams.assertOnLastAttempt ??\n (!isRead && retryableFetchParams.assertResponse !== undefined),\n onRetry(arg) {\n cache.invalidate();\n return retryableFetchParams.onRetry?.(arg);\n },\n })(async () => {\n let clone = req.clone() as Request;\n const url = getControlPlaneRequestUrl(req.method, new URL(req.url));\n if (url.href !== req.url) clone = await retargetRequest(clone, url);\n if (testing?.overwriteUri)\n clone = await retargetRequest(clone, testing.overwriteUri);\n\n const a = (typeof auth === 'function' ? auth() : auth) || {};\n if (sessionId) clone.headers.set('X-Session-Id', sessionId);\n if (a.sec)\n clone.headers.set('X-Api-Key', `Sec ${await cache.current(a.sec)}`);\n if (a.apiKey) clone.headers.set('X-Api-Key', a.apiKey);\n if (a.tenantId) clone.headers.set('X-Team-Id', a.tenantId);\n if (a.accessToken)\n clone.headers.set(\n 'Authorization',\n a.accessToken.startsWith('Bearer ')\n ? a.accessToken\n : `Bearer ${a.accessToken}`\n );\n const additionalHeaders = h ? (typeof h === 'function' ? h() : h) : {};\n for (const key in additionalHeaders) {\n clone.headers.set(key, additionalHeaders[key]);\n }\n\n if (trace['sentry-trace'])\n clone.headers.set('sentry-trace', trace['sentry-trace']);\n if (trace.baggage) clone.headers.set('baggage', trace.baggage);\n\n return clone;\n });\n },\n });\n\n return Object.assign(client, { sessionId }) satisfies ApiClient;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getControlPlaneRequestUrl(method: string, url: URL): URL;
|
|
2
|
+
/**
|
|
3
|
+
* Whether the API places this request by its `x-data-region` header or its
|
|
4
|
+
* path instead of the `x-team-id` team's own region.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isRequestRegionRoute(method: string, url: URL): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getControlPlaneRequestUrl = getControlPlaneRequestUrl;
|
|
4
|
+
exports.isRequestRegionRoute = isRequestRegionRoute;
|
|
5
|
+
const routing_1 = require("./generated/routing");
|
|
6
|
+
const toMatchers = (routeList) => routeList.map(({ method, endpoint }) => ({
|
|
7
|
+
method,
|
|
8
|
+
pattern: new RegExp(`^${endpoint
|
|
9
|
+
.split('/')
|
|
10
|
+
.map((segment) => segment.startsWith('{') && segment.endsWith('}')
|
|
11
|
+
? '[^/]+'
|
|
12
|
+
: segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
13
|
+
.join('/')}$`),
|
|
14
|
+
}));
|
|
15
|
+
const routes = toMatchers(routing_1.controlPlaneRouting.routes);
|
|
16
|
+
const regionRoutes = toMatchers(routing_1.requestRegionRoutes);
|
|
17
|
+
function getControlPlaneRequestUrl(method, url) {
|
|
18
|
+
const origin = routing_1.controlPlaneRouting.origins[url.origin];
|
|
19
|
+
if (!origin ||
|
|
20
|
+
!routes.some((route) => route.method === method && route.pattern.test(url.pathname))) {
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
const target = new URL(url);
|
|
24
|
+
target.host = new URL(origin).host;
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether the API places this request by its `x-data-region` header or its
|
|
29
|
+
* path instead of the `x-team-id` team's own region.
|
|
30
|
+
*/
|
|
31
|
+
function isRequestRegionRoute(method, url) {
|
|
32
|
+
return regionRoutes.some((route) => route.method === method && route.pattern.test(url.pathname));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=control-plane-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-plane-routing.js","sourceRoot":"src/","sources":["control-plane-routing.ts"],"names":[],"mappings":";;;;AAAA,iDAA+E;AAE/E,MAAM,UAAU,GAAG,CACjB,SAA0D,EAC1D,EAAE,CACF,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM;IACN,OAAO,EA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C","sourcesContent":["import { controlPlaneRouting, requestRegionRoutes } from './generated/routing';\n\nconst toMatchers = (\n routeList: readonly { method: string; endpoint: string }[]\n) =>\n routeList.map(({ method, endpoint }) => ({\n method,\n pattern: new RegExp(\n `^${endpoint\n .split('/')\n .map((segment) =>\n segment.startsWith('{') && segment.endsWith('}')\n ? '[^/]+'\n : segment.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n )\n .join('/')}$`\n ),\n }));\n\nconst routes = toMatchers(controlPlaneRouting.routes);\nconst regionRoutes = toMatchers(requestRegionRoutes);\n\nexport function getControlPlaneRequestUrl(method: string, url: URL): URL {\n const origin = controlPlaneRouting.origins[url.origin];\n if (\n !origin ||\n !routes.some(\n (route) => route.method === method && route.pattern.test(url.pathname)\n )\n ) {\n return url;\n }\n const target = new URL(url);\n target.host = new URL(origin).host;\n return target;\n}\n\n/**\n * Whether the API places this request by its `x-data-region` header or its\n * path instead of the `x-team-id` team's own region.\n */\nexport function isRequestRegionRoute(method: string, url: URL) {\n return regionRoutes.some(\n (route) => route.method === method && route.pattern.test(url.pathname)\n );\n}\n"]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
declare const channelRequestSchema: z.ZodObject<{
|
|
3
|
+
channelId: z.ZodUUID;
|
|
4
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
5
|
+
version: z.ZodLiteral<1>;
|
|
6
|
+
requestId: z.ZodUUID;
|
|
7
|
+
type: z.ZodLiteral<"channel.request">;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
declare const channelConnectSchema: z.ZodObject<{
|
|
10
|
+
channelId: z.ZodUUID;
|
|
11
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
12
|
+
version: z.ZodLiteral<1>;
|
|
13
|
+
replyTo: z.ZodUUID;
|
|
14
|
+
type: z.ZodLiteral<"channel.connect">;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
declare const iframeMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
17
|
+
channelId: z.ZodUUID;
|
|
18
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
19
|
+
version: z.ZodLiteral<1>;
|
|
20
|
+
type: z.ZodLiteral<"ready">;
|
|
21
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
22
|
+
channelId: z.ZodUUID;
|
|
23
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
24
|
+
version: z.ZodLiteral<1>;
|
|
25
|
+
code: z.ZodEnum<{
|
|
26
|
+
access_denied: "access_denied";
|
|
27
|
+
authentication_failed: "authentication_failed";
|
|
28
|
+
internal_error: "internal_error";
|
|
29
|
+
renewal_failed: "renewal_failed";
|
|
30
|
+
session_expired: "session_expired";
|
|
31
|
+
unsupported_version: "unsupported_version";
|
|
32
|
+
}>;
|
|
33
|
+
correlationId: z.ZodString;
|
|
34
|
+
recoverable: z.ZodBoolean;
|
|
35
|
+
replyTo: z.ZodOptional<z.ZodUUID>;
|
|
36
|
+
type: z.ZodLiteral<"error">;
|
|
37
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
38
|
+
channelId: z.ZodUUID;
|
|
39
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
40
|
+
version: z.ZodLiteral<1>;
|
|
41
|
+
expiresAt: z.ZodISODateTime;
|
|
42
|
+
requestId: z.ZodUUID;
|
|
43
|
+
type: z.ZodLiteral<"session.expiring">;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
channelId: z.ZodUUID;
|
|
46
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
47
|
+
version: z.ZodLiteral<1>;
|
|
48
|
+
expiresAt: z.ZodISODateTime;
|
|
49
|
+
replyTo: z.ZodUUID;
|
|
50
|
+
type: z.ZodLiteral<"session.renewed">;
|
|
51
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
52
|
+
channelId: z.ZodUUID;
|
|
53
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
54
|
+
version: z.ZodLiteral<1>;
|
|
55
|
+
height: z.ZodNumber;
|
|
56
|
+
type: z.ZodLiteral<"resize">;
|
|
57
|
+
}, z.core.$strict>], "type">;
|
|
58
|
+
declare const parentMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
59
|
+
channelId: z.ZodUUID;
|
|
60
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
61
|
+
version: z.ZodLiteral<1>;
|
|
62
|
+
embedUrl: z.ZodURL;
|
|
63
|
+
replyTo: z.ZodUUID;
|
|
64
|
+
requestId: z.ZodUUID;
|
|
65
|
+
type: z.ZodLiteral<"session.renew">;
|
|
66
|
+
}, z.core.$strict>], "type">;
|
|
67
|
+
export declare const embedLifecycle: {
|
|
68
|
+
readonly channelConnectSchema: z.ZodObject<{
|
|
69
|
+
channelId: z.ZodUUID;
|
|
70
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
71
|
+
version: z.ZodLiteral<1>;
|
|
72
|
+
replyTo: z.ZodUUID;
|
|
73
|
+
type: z.ZodLiteral<"channel.connect">;
|
|
74
|
+
}, z.core.$strict>;
|
|
75
|
+
readonly channelRequestSchema: z.ZodObject<{
|
|
76
|
+
channelId: z.ZodUUID;
|
|
77
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
78
|
+
version: z.ZodLiteral<1>;
|
|
79
|
+
requestId: z.ZodUUID;
|
|
80
|
+
type: z.ZodLiteral<"channel.request">;
|
|
81
|
+
}, z.core.$strict>;
|
|
82
|
+
readonly iframeMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
83
|
+
channelId: z.ZodUUID;
|
|
84
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
85
|
+
version: z.ZodLiteral<1>;
|
|
86
|
+
type: z.ZodLiteral<"ready">;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
channelId: z.ZodUUID;
|
|
89
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
90
|
+
version: z.ZodLiteral<1>;
|
|
91
|
+
code: z.ZodEnum<{
|
|
92
|
+
access_denied: "access_denied";
|
|
93
|
+
authentication_failed: "authentication_failed";
|
|
94
|
+
internal_error: "internal_error";
|
|
95
|
+
renewal_failed: "renewal_failed";
|
|
96
|
+
session_expired: "session_expired";
|
|
97
|
+
unsupported_version: "unsupported_version";
|
|
98
|
+
}>;
|
|
99
|
+
correlationId: z.ZodString;
|
|
100
|
+
recoverable: z.ZodBoolean;
|
|
101
|
+
replyTo: z.ZodOptional<z.ZodUUID>;
|
|
102
|
+
type: z.ZodLiteral<"error">;
|
|
103
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
104
|
+
channelId: z.ZodUUID;
|
|
105
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
106
|
+
version: z.ZodLiteral<1>;
|
|
107
|
+
expiresAt: z.ZodISODateTime;
|
|
108
|
+
requestId: z.ZodUUID;
|
|
109
|
+
type: z.ZodLiteral<"session.expiring">;
|
|
110
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
111
|
+
channelId: z.ZodUUID;
|
|
112
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
113
|
+
version: z.ZodLiteral<1>;
|
|
114
|
+
expiresAt: z.ZodISODateTime;
|
|
115
|
+
replyTo: z.ZodUUID;
|
|
116
|
+
type: z.ZodLiteral<"session.renewed">;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
channelId: z.ZodUUID;
|
|
119
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
120
|
+
version: z.ZodLiteral<1>;
|
|
121
|
+
height: z.ZodNumber;
|
|
122
|
+
type: z.ZodLiteral<"resize">;
|
|
123
|
+
}, z.core.$strict>], "type">;
|
|
124
|
+
readonly parentMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
125
|
+
channelId: z.ZodUUID;
|
|
126
|
+
protocol: z.ZodLiteral<"vrplatform.embed.lifecycle">;
|
|
127
|
+
version: z.ZodLiteral<1>;
|
|
128
|
+
embedUrl: z.ZodURL;
|
|
129
|
+
replyTo: z.ZodUUID;
|
|
130
|
+
requestId: z.ZodUUID;
|
|
131
|
+
type: z.ZodLiteral<"session.renew">;
|
|
132
|
+
}, z.core.$strict>], "type">;
|
|
133
|
+
readonly protocol: "vrplatform.embed.lifecycle";
|
|
134
|
+
readonly version: 1;
|
|
135
|
+
};
|
|
136
|
+
export type EmbedLifecycleChannelConnect = z.infer<typeof channelConnectSchema>;
|
|
137
|
+
export type EmbedLifecycleChannelRequest = z.infer<typeof channelRequestSchema>;
|
|
138
|
+
export type EmbedLifecycleIframeMessage = z.infer<typeof iframeMessageSchema>;
|
|
139
|
+
export type EmbedLifecycleParentMessage = z.infer<typeof parentMessageSchema>;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.embedLifecycle = void 0;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
38
|
+
const protocol = 'vrplatform.embed.lifecycle';
|
|
39
|
+
const version = 1;
|
|
40
|
+
const envelope = {
|
|
41
|
+
channelId: z.uuid(),
|
|
42
|
+
protocol: z.literal(protocol),
|
|
43
|
+
version: z.literal(version),
|
|
44
|
+
};
|
|
45
|
+
const channelRequestSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
...envelope,
|
|
48
|
+
requestId: z.uuid(),
|
|
49
|
+
type: z.literal('channel.request'),
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
52
|
+
const channelConnectSchema = z
|
|
53
|
+
.object({
|
|
54
|
+
...envelope,
|
|
55
|
+
replyTo: z.uuid(),
|
|
56
|
+
type: z.literal('channel.connect'),
|
|
57
|
+
})
|
|
58
|
+
.strict();
|
|
59
|
+
const iframeMessageSchema = z.discriminatedUnion('type', [
|
|
60
|
+
z
|
|
61
|
+
.object({
|
|
62
|
+
...envelope,
|
|
63
|
+
type: z.literal('ready'),
|
|
64
|
+
})
|
|
65
|
+
.strict(),
|
|
66
|
+
z
|
|
67
|
+
.object({
|
|
68
|
+
...envelope,
|
|
69
|
+
code: z.enum([
|
|
70
|
+
'authentication_failed',
|
|
71
|
+
'access_denied',
|
|
72
|
+
'session_expired',
|
|
73
|
+
'renewal_failed',
|
|
74
|
+
'unsupported_version',
|
|
75
|
+
'internal_error',
|
|
76
|
+
]),
|
|
77
|
+
correlationId: z.string().min(1).max(128),
|
|
78
|
+
recoverable: z.boolean(),
|
|
79
|
+
replyTo: z.uuid().optional(),
|
|
80
|
+
type: z.literal('error'),
|
|
81
|
+
})
|
|
82
|
+
.strict(),
|
|
83
|
+
z
|
|
84
|
+
.object({
|
|
85
|
+
...envelope,
|
|
86
|
+
expiresAt: z.iso.datetime({ offset: true }),
|
|
87
|
+
requestId: z.uuid(),
|
|
88
|
+
type: z.literal('session.expiring'),
|
|
89
|
+
})
|
|
90
|
+
.strict(),
|
|
91
|
+
z
|
|
92
|
+
.object({
|
|
93
|
+
...envelope,
|
|
94
|
+
expiresAt: z.iso.datetime({ offset: true }),
|
|
95
|
+
replyTo: z.uuid(),
|
|
96
|
+
type: z.literal('session.renewed'),
|
|
97
|
+
})
|
|
98
|
+
.strict(),
|
|
99
|
+
z
|
|
100
|
+
.object({
|
|
101
|
+
...envelope,
|
|
102
|
+
height: z.number().int().positive(),
|
|
103
|
+
type: z.literal('resize'),
|
|
104
|
+
})
|
|
105
|
+
.strict(),
|
|
106
|
+
]);
|
|
107
|
+
const parentMessageSchema = z.discriminatedUnion('type', [
|
|
108
|
+
z
|
|
109
|
+
.object({
|
|
110
|
+
...envelope,
|
|
111
|
+
embedUrl: z.url(),
|
|
112
|
+
replyTo: z.uuid(),
|
|
113
|
+
requestId: z.uuid(),
|
|
114
|
+
type: z.literal('session.renew'),
|
|
115
|
+
})
|
|
116
|
+
.strict(),
|
|
117
|
+
]);
|
|
118
|
+
exports.embedLifecycle = {
|
|
119
|
+
channelConnectSchema,
|
|
120
|
+
channelRequestSchema,
|
|
121
|
+
iframeMessageSchema,
|
|
122
|
+
parentMessageSchema,
|
|
123
|
+
protocol,
|
|
124
|
+
version,
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=embed-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed-lifecycle.js","sourceRoot":"src/","sources":["embed-lifecycle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,CAAC,gCAAY;AAEzB,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,QAAQ,GAAG;IACf,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE;IACnB,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;CAC5B,CAAC;AACF,MAAM,oBAAoB,GAAG,CAAC;KAC3B,MAAM,CAAC;IACN,GAAG,QAAQ;IACX,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;CACnC,CAAC;KACD,MAAM,EAAE,CAAC;AACZ,MAAM,oBAAoB,GAAG,CAAC;KAC3B,MAAM,CAAC;IACN,GAAG,QAAQ;IACX,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;CACnC,CAAC;KACD,MAAM,EAAE,CAAC;AACZ,MAAM,mBAAmB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACvD,CAAC;SACE,MAAM,CAAC;QACN,GAAG,QAAQ;QACX,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;KACzB,CAAC;SACD,MAAM,EAAE;IACX,CAAC;SACE,MAAM,CAAC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AAC,kBAAkB,CAAC,MAAM,EAAE;IACvD,CAAC;SACE,MAAM,CAAC;QACN,GAAG,QAAQ;QACX,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;QACjB,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE;QACnB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;KACjC,CAAC;SACD,MAAM,EAAE;CACZ,CAAC,CAAC;AAEU,QAAA,cAAc,GAAG;IAC5B,oBAAoB;IACpB,oBAAoB;IACpB,mBAAmB;IACnB,mBAAmB;IACnB,QAAQ;IACR,OAAO;CACC,CAAC","sourcesContent":["import * as z from 'zod';\n\nconst protocol = 'vrplatform.embed.lifecycle';\nconst version = 1;\nconst envelope = {\n channelId: z.uuid(),\n protocol: z.literal(protocol),\n version: z.literal(version),\n};\nconst channelRequestSchema = z\n .object({\n ...envelope,\n requestId: z.uuid(),\n type: z.literal('channel.request'),\n })\n .strict();\nconst channelConnectSchema = z\n .object({\n ...envelope,\n replyTo: z.uuid(),\n type: z.literal('channel.connect'),\n })\n .strict();\nconst iframeMessageSchema = z.discriminatedUnion('type', [\n z\n .object({\n ...envelope,\n type: z.literal('ready'),\n })\n .strict(),\n z\n .object({\n ...envelope,\n code: z.enum([\n 'authentication_failed',\n 'access_denied',\n 'session_expired',\n 'renewal_failed',\n 'unsupported_version',\n 'internal_error',\n ]),\n correlationId: z.string().min(1).max(128),\n recoverable: z.boolean(),\n replyTo: z.uuid().optional(),\n type: z.literal('error'),\n })\n .strict(),\n z\n .object({\n ...envelope,\n expiresAt: z.iso.datetime({ offset: true }),\n requestId: z.uuid(),\n type: z.literal('session.expiring'),\n })\n .strict(),\n z\n .object({\n ...envelope,\n expiresAt: z.iso.datetime({ offset: true }),\n replyTo: z.uuid(),\n type: z.literal('session.renewed'),\n })\n .strict(),\n z\n .object({\n ...envelope,\n height: z.number().int().positive(),\n type: z.literal('resize'),\n })\n .strict(),\n]);\nconst parentMessageSchema = z.discriminatedUnion('type', [\n z\n .object({\n ...envelope,\n embedUrl: z.url(),\n replyTo: z.uuid(),\n requestId: z.uuid(),\n type: z.literal('session.renew'),\n })\n .strict(),\n]);\n\nexport const embedLifecycle = {\n channelConnectSchema,\n channelRequestSchema,\n iframeMessageSchema,\n parentMessageSchema,\n protocol,\n version,\n} as const;\n\nexport type EmbedLifecycleChannelConnect = z.infer<typeof channelConnectSchema>;\nexport type EmbedLifecycleChannelRequest = z.infer<typeof channelRequestSchema>;\nexport type EmbedLifecycleIframeMessage = z.infer<typeof iframeMessageSchema>;\nexport type EmbedLifecycleParentMessage = z.infer<typeof parentMessageSchema>;\n"]}
|
package/build/main/error.d.ts
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type
|
|
1
|
+
import type { paths } from './generated/v1';
|
|
2
|
+
type PublicError = paths['/account-connections']['get']['responses'][400]['content']['application/json'];
|
|
3
|
+
type ErrorEnvelope = Omit<PublicError, 'code' | 'issues'> & {
|
|
3
4
|
code: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
issues?: PublicError['issues'];
|
|
6
|
+
stack?: string;
|
|
7
|
+
};
|
|
8
|
+
type ApiResponse<T> = {
|
|
9
|
+
response: Response;
|
|
10
|
+
data?: T;
|
|
11
|
+
error?: unknown;
|
|
10
12
|
};
|
|
11
13
|
export declare class ApiClientError extends Error {
|
|
12
|
-
error:
|
|
13
|
-
code:
|
|
14
|
-
issues:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
error: ErrorEnvelope;
|
|
15
|
+
code: ErrorEnvelope['code'];
|
|
16
|
+
issues: PublicError['issues'];
|
|
17
|
+
context: PublicError['context'];
|
|
18
|
+
reason: PublicError['reason'];
|
|
19
|
+
links: PublicError['links'];
|
|
20
|
+
retryable: PublicError['retryable'];
|
|
21
|
+
constructor(error: ErrorEnvelope);
|
|
22
|
+
}
|
|
23
|
+
export declare class ApiClientResponseError extends Error {
|
|
24
|
+
status: number;
|
|
25
|
+
readonly details: {
|
|
26
|
+
contentType: string | null;
|
|
27
|
+
requestId: string | null;
|
|
28
|
+
cfRay: string | null;
|
|
29
|
+
};
|
|
30
|
+
constructor(message: string, status: number, details?: {
|
|
31
|
+
contentType: string | null;
|
|
32
|
+
requestId: string | null;
|
|
33
|
+
cfRay: string | null;
|
|
34
|
+
});
|
|
19
35
|
}
|
|
20
|
-
export declare function throwIfError<T extends
|
|
21
|
-
export declare function throwIfError<T extends FetchResponse<any, any, any>>(response: Promise<T>): Promise<NonNullable<T['data']>>;
|
|
36
|
+
export declare function throwIfError<T extends ApiResponse<unknown> | Promise<ApiResponse<unknown>>>(response: T): T extends Promise<ApiResponse<unknown>> ? Promise<NonNullable<Awaited<T>['data']>> : NonNullable<Awaited<T>['data']>;
|
|
22
37
|
export {};
|
package/build/main/error.js
CHANGED
|
@@ -1,49 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiClientError = void 0;
|
|
3
|
+
exports.ApiClientResponseError = exports.ApiClientError = void 0;
|
|
4
4
|
exports.throwIfError = throwIfError;
|
|
5
|
-
const utils_1 = require("@vrplatform/utils");
|
|
6
5
|
class ApiClientError extends Error {
|
|
7
6
|
constructor(error) {
|
|
8
|
-
|
|
9
|
-
[
|
|
10
|
-
error.code,
|
|
11
|
-
error.issues
|
|
12
|
-
?.map((x) => [x.message, x.path?.join('->')]
|
|
13
|
-
.filter(utils_1.hasValue)
|
|
14
|
-
.join(' on '))
|
|
15
|
-
.join(', '),
|
|
16
|
-
]
|
|
17
|
-
.filter(utils_1.hasValue)
|
|
18
|
-
.join(': ');
|
|
19
|
-
super(message);
|
|
7
|
+
super(error.message);
|
|
20
8
|
this.error = error;
|
|
21
9
|
this.code = error.code;
|
|
22
|
-
this.issues = error.issues
|
|
23
|
-
this.context = error.context
|
|
10
|
+
this.issues = error.issues ?? [];
|
|
11
|
+
this.context = error.context;
|
|
12
|
+
this.reason = error.reason;
|
|
13
|
+
this.links = error.links;
|
|
14
|
+
this.retryable = error.retryable;
|
|
24
15
|
if (error.stack)
|
|
25
16
|
this.stack = error.stack;
|
|
26
17
|
}
|
|
27
18
|
}
|
|
28
19
|
exports.ApiClientError = ApiClientError;
|
|
20
|
+
class ApiClientResponseError extends Error {
|
|
21
|
+
constructor(message, status, details = { contentType: null, requestId: null, cfRay: null }) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.status = status;
|
|
24
|
+
this.details = details;
|
|
25
|
+
this.name = 'ApiClientResponseError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ApiClientResponseError = ApiClientResponseError;
|
|
29
29
|
function throwIfError(response) {
|
|
30
|
-
if (response instanceof Promise)
|
|
31
|
-
return response.then((
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
code: 'SERVICE_UNAVAILABLE',
|
|
35
|
-
message: 'Worker resources exceeded.',
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const error = response.error;
|
|
39
|
-
if (error)
|
|
40
|
-
throw new ApiClientError(error);
|
|
41
|
-
return response.data;
|
|
42
|
-
});
|
|
30
|
+
if (response instanceof Promise)
|
|
31
|
+
return response.then((value) => throwIfError(value));
|
|
32
|
+
if (response.response.ok && response.error === undefined) {
|
|
33
|
+
return response.data;
|
|
43
34
|
}
|
|
44
35
|
const error = response.error;
|
|
45
|
-
if (error
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
if (typeof error !== 'object' ||
|
|
37
|
+
error === null ||
|
|
38
|
+
!('code' in error) ||
|
|
39
|
+
typeof error.code !== 'string' ||
|
|
40
|
+
!('message' in error) ||
|
|
41
|
+
typeof error.message !== 'string' ||
|
|
42
|
+
!('issues' in error) ||
|
|
43
|
+
!Array.isArray(error.issues) ||
|
|
44
|
+
!error.issues.every((issue) => typeof issue === 'object' &&
|
|
45
|
+
issue !== null &&
|
|
46
|
+
'message' in issue &&
|
|
47
|
+
typeof issue.message === 'string' &&
|
|
48
|
+
(!('path' in issue) ||
|
|
49
|
+
issue.path === undefined ||
|
|
50
|
+
(Array.isArray(issue.path) &&
|
|
51
|
+
issue.path.every((part) => typeof part === 'string' || typeof part === 'number'))) &&
|
|
52
|
+
(!('schema' in issue) ||
|
|
53
|
+
issue.schema === undefined ||
|
|
54
|
+
typeof issue.schema === 'string')) ||
|
|
55
|
+
('retryable' in error &&
|
|
56
|
+
error.retryable !== undefined &&
|
|
57
|
+
typeof error.retryable !== 'boolean') ||
|
|
58
|
+
('links' in error &&
|
|
59
|
+
error.links !== undefined &&
|
|
60
|
+
(typeof error.links !== 'object' ||
|
|
61
|
+
error.links === null ||
|
|
62
|
+
!('docs' in error.links) ||
|
|
63
|
+
typeof error.links.docs !== 'string' ||
|
|
64
|
+
!('schema' in error.links) ||
|
|
65
|
+
typeof error.links.schema !== 'string')))
|
|
66
|
+
throw new ApiClientResponseError('API response did not contain a valid error envelope', response.response.status, {
|
|
67
|
+
contentType: response.response.headers.get('content-type'),
|
|
68
|
+
requestId: response.response.headers.get('x-request-id'),
|
|
69
|
+
cfRay: response.response.headers.get('cf-ray'),
|
|
70
|
+
});
|
|
71
|
+
throw new ApiClientError(error);
|
|
48
72
|
}
|
|
49
73
|
//# sourceMappingURL=error.js.map
|