@vrplatform/api 1.3.1-preview.4563 → 1.3.1-preview.6162
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/embed-lifecycle.d.ts +140 -0
- package/build/main/embed-lifecycle.js +93 -0
- package/build/main/embed-lifecycle.js.map +1 -0
- package/build/main/error.d.ts +1 -1
- package/build/main/error.js.map +1 -1
- package/build/main/generated/v1.d.ts +24645 -13598
- package/build/main/generated/v1.js.map +1 -1
- package/build/main/index.d.ts +1 -0
- package/build/main/index.js +1 -0
- package/build/main/index.js.map +1 -1
- package/build/main/routing.d.ts +5 -0
- package/build/main/routing.js +22 -0
- package/build/main/routing.js.map +1 -1
- 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 +1 -1
- package/build/module/error.js.map +1 -1
- package/build/module/generated/v1.d.ts +24645 -13598
- package/build/module/generated/v1.js.map +1 -1
- package/build/module/index.d.ts +1 -0
- package/build/module/index.js +1 -0
- package/build/module/index.js.map +1 -1
- package/build/module/routing.d.ts +5 -0
- package/build/module/routing.js +21 -0
- package/build/module/routing.js.map +1 -1
- package/package.json +3 -3
- package/src/embed-lifecycle.ts +96 -0
- package/src/error.ts +1 -1
- package/src/generated/v1.ts +24645 -13598
- package/src/index.ts +1 -0
- package/src/routing.ts +30 -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/module/index.d.ts
CHANGED
package/build/module/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AAExB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC","sourcesContent":["import type { ApiClient } from './types';\n\nexport * from './client';\nexport * from './error';\nexport type * from './generated/v1';\nexport * from './routing';\nexport * from './sec';\nexport * from './types';\n\nexport type VRPlatformApi = ApiClient;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AAExB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC","sourcesContent":["import type { ApiClient } from './types';\n\nexport * from './client';\nexport * from './embed-lifecycle';\nexport * from './error';\nexport type * from './generated/v1';\nexport * from './routing';\nexport * from './sec';\nexport * from './types';\n\nexport type VRPlatformApi = ApiClient;\n"]}
|
|
@@ -14,4 +14,9 @@ export declare function resolveTenantRouting({ connectionId, slug, tenantId, aut
|
|
|
14
14
|
slug?: string;
|
|
15
15
|
tenantId?: string;
|
|
16
16
|
}): Promise<TenantRouting>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a tenant's home region and return an API client configured for that
|
|
19
|
+
* regional API. The resolved tenant id is applied to every regional request.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useResolvedApiClient({ connectionId, slug, tenantId, auth, ...apiClientOptions }: Parameters<typeof resolveTenantRouting>[0]): Promise<import("./types").ApiClient>;
|
|
17
22
|
export {};
|
package/build/module/routing.js
CHANGED
|
@@ -34,4 +34,25 @@ export async function resolveTenantRouting({ connectionId, slug, tenantId, auth,
|
|
|
34
34
|
apiBaseUrl: new URL(response.apiBaseUrl).toString().replace(/\/$/, ''),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve a tenant's home region and return an API client configured for that
|
|
39
|
+
* regional API. The resolved tenant id is applied to every regional request.
|
|
40
|
+
*/
|
|
41
|
+
export async function useResolvedApiClient({ connectionId, slug, tenantId, auth, ...apiClientOptions }) {
|
|
42
|
+
const routing = await resolveTenantRouting({
|
|
43
|
+
...apiClientOptions,
|
|
44
|
+
connectionId,
|
|
45
|
+
slug,
|
|
46
|
+
tenantId,
|
|
47
|
+
auth,
|
|
48
|
+
});
|
|
49
|
+
return useApiClient({
|
|
50
|
+
...apiClientOptions,
|
|
51
|
+
baseUrl: routing.apiBaseUrl,
|
|
52
|
+
auth: () => ({
|
|
53
|
+
...(typeof auth === 'function' ? auth() : (auth ?? {})),
|
|
54
|
+
tenantId: routing.id,
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
37
58
|
//# sourceMappingURL=routing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"src/","sources":["routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,GAAG,gBAAgB,EAKpB;IACC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,CAC3B,MAAM,YAAY,CAAC;QACjB,GAAG,gBAAgB;QACnB,IAAI,EAAE,QAAQ;YACZ,CAAC,CAAC,GAAG,EAAE;gBACH,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;gBACnE,OAAO;oBACL,GAAG,OAAO;oBACV,QAAQ;iBACe,CAAC;YAC5B,CAAC;YACH,CAAC,CAAC,IAAI;KACT,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE;QACvB,MAAM,EAAE;YACN,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE;SAC9D;KACF,CAAC,CACH,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,UAAU,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC","sourcesContent":["import { useApiClient } from './client';\nimport { throwIfError } from './error';\nimport type { ApiClientAuth, ResponseData } from './types';\n\nexport type TenantRouting = Pick<\n ResponseData<'get:/teams/resolve'>,\n 'id' | 'slug' | 'dataRegion' | 'apiBaseUrl'\n>;\n\ntype ApiClientOptions = Parameters<typeof useApiClient>[0];\n\n/**\n * Resolve a tenant's region and regional `apiBaseUrl` from a connection id,\n * slug, or tenant id — the client entry point for non-API runtimes that need\n * to reach a tenant's home region. Each call is a `/teams/resolve` round trip;\n * hot-loop callers should cache the result (placement changes only on an\n * explicit tenant migration).\n */\nexport async function resolveTenantRouting({\n connectionId,\n slug,\n tenantId,\n auth,\n ...apiClientOptions\n}: ApiClientOptions & {\n connectionId?: string;\n slug?: string;\n tenantId?: string;\n}): Promise<TenantRouting> {\n if (!connectionId && !slug && !tenantId) {\n throw new Error('connectionId, slug, or tenantId is required');\n }\n\n const response = throwIfError(\n await useApiClient({\n ...apiClientOptions,\n auth: tenantId\n ? () => {\n const current = typeof auth === 'function' ? auth() : (auth ?? {});\n return {\n ...current,\n tenantId,\n } satisfies ApiClientAuth;\n }\n : auth,\n }).GET('/teams/resolve', {\n params: {\n query: slug ? { slug } : connectionId ? { connectionId } : {},\n },\n })\n );\n\n return {\n id: response.id,\n slug: response.slug,\n dataRegion: response.dataRegion,\n apiBaseUrl: new URL(response.apiBaseUrl).toString().replace(/\\/$/, ''),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"src/","sources":["routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,GAAG,gBAAgB,EAKpB;IACC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,CAC3B,MAAM,YAAY,CAAC;QACjB,GAAG,gBAAgB;QACnB,IAAI,EAAE,QAAQ;YACZ,CAAC,CAAC,GAAG,EAAE;gBACH,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;gBACnE,OAAO;oBACL,GAAG,OAAO;oBACV,QAAQ;iBACe,CAAC;YAC5B,CAAC;YACH,CAAC,CAAC,IAAI;KACT,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE;QACvB,MAAM,EAAE;YACN,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE;SAC9D;KACF,CAAC,CACH,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,UAAU,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,GAAG,gBAAgB,EACwB;IAC3C,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;QACzC,GAAG,gBAAgB;QACnB,YAAY;QACZ,IAAI;QACJ,QAAQ;QACR,IAAI;KACL,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;QAClB,GAAG,gBAAgB;QACnB,OAAO,EAAE,OAAO,CAAC,UAAU;QAC3B,IAAI,EAAE,GAAG,EAAE,CACT,CAAC;YACC,GAAG,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YACvD,QAAQ,EAAE,OAAO,CAAC,EAAE;SACrB,CAAyB;KAC7B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useApiClient } from './client';\nimport { throwIfError } from './error';\nimport type { ApiClientAuth, ResponseData } from './types';\n\nexport type TenantRouting = Pick<\n ResponseData<'get:/teams/resolve'>,\n 'id' | 'slug' | 'dataRegion' | 'apiBaseUrl'\n>;\n\ntype ApiClientOptions = Parameters<typeof useApiClient>[0];\n\n/**\n * Resolve a tenant's region and regional `apiBaseUrl` from a connection id,\n * slug, or tenant id — the client entry point for non-API runtimes that need\n * to reach a tenant's home region. Each call is a `/teams/resolve` round trip;\n * hot-loop callers should cache the result (placement changes only on an\n * explicit tenant migration).\n */\nexport async function resolveTenantRouting({\n connectionId,\n slug,\n tenantId,\n auth,\n ...apiClientOptions\n}: ApiClientOptions & {\n connectionId?: string;\n slug?: string;\n tenantId?: string;\n}): Promise<TenantRouting> {\n if (!connectionId && !slug && !tenantId) {\n throw new Error('connectionId, slug, or tenantId is required');\n }\n\n const response = throwIfError(\n await useApiClient({\n ...apiClientOptions,\n auth: tenantId\n ? () => {\n const current = typeof auth === 'function' ? auth() : (auth ?? {});\n return {\n ...current,\n tenantId,\n } satisfies ApiClientAuth;\n }\n : auth,\n }).GET('/teams/resolve', {\n params: {\n query: slug ? { slug } : connectionId ? { connectionId } : {},\n },\n })\n );\n\n return {\n id: response.id,\n slug: response.slug,\n dataRegion: response.dataRegion,\n apiBaseUrl: new URL(response.apiBaseUrl).toString().replace(/\\/$/, ''),\n };\n}\n\n/**\n * Resolve a tenant's home region and return an API client configured for that\n * regional API. The resolved tenant id is applied to every regional request.\n */\nexport async function useResolvedApiClient({\n connectionId,\n slug,\n tenantId,\n auth,\n ...apiClientOptions\n}: Parameters<typeof resolveTenantRouting>[0]) {\n const routing = await resolveTenantRouting({\n ...apiClientOptions,\n connectionId,\n slug,\n tenantId,\n auth,\n });\n\n return useApiClient({\n ...apiClientOptions,\n baseUrl: routing.apiBaseUrl,\n auth: () =>\n ({\n ...(typeof auth === 'function' ? auth() : (auth ?? {})),\n tenantId: routing.id,\n }) satisfies ApiClientAuth,\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.3.1-preview.
|
|
6
|
+
"version": "1.3.1-preview.6162",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "build/main/index.js",
|
|
9
9
|
"module": "build/module/index.js",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"generate-client": "bun generate:schema && bun generate:client",
|
|
21
21
|
"generate:schema": "NODE_ENV=generator bun ./openapi.ts",
|
|
22
22
|
"generate:client": "bunx --bun openapi-typescript ./openapi.json -o ./src/generated/v1.ts",
|
|
23
|
-
"tsgo": "tsc
|
|
23
|
+
"tsgo": "tsc -b tsconfig.src.json tsconfig.test.json"
|
|
24
24
|
},
|
|
25
25
|
"author": "",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"openapi-fetch": "0.15.0",
|
|
29
29
|
"openapi-typescript": "^7.13.0",
|
|
30
|
-
"
|
|
30
|
+
"zod": "^4.4.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@vrplatform/utils": "*",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const protocol = 'vrplatform.embed.lifecycle';
|
|
4
|
+
const version = 1;
|
|
5
|
+
const envelope = {
|
|
6
|
+
channelId: z.uuid(),
|
|
7
|
+
protocol: z.literal(protocol),
|
|
8
|
+
version: z.literal(version),
|
|
9
|
+
};
|
|
10
|
+
const channelRequestSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
...envelope,
|
|
13
|
+
requestId: z.uuid(),
|
|
14
|
+
type: z.literal('channel.request'),
|
|
15
|
+
})
|
|
16
|
+
.strict();
|
|
17
|
+
const channelConnectSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
...envelope,
|
|
20
|
+
replyTo: z.uuid(),
|
|
21
|
+
type: z.literal('channel.connect'),
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
24
|
+
const iframeMessageSchema = z.discriminatedUnion('type', [
|
|
25
|
+
z
|
|
26
|
+
.object({
|
|
27
|
+
...envelope,
|
|
28
|
+
type: z.literal('ready'),
|
|
29
|
+
})
|
|
30
|
+
.strict(),
|
|
31
|
+
z
|
|
32
|
+
.object({
|
|
33
|
+
...envelope,
|
|
34
|
+
code: z.enum([
|
|
35
|
+
'authentication_failed',
|
|
36
|
+
'access_denied',
|
|
37
|
+
'session_expired',
|
|
38
|
+
'renewal_failed',
|
|
39
|
+
'unsupported_version',
|
|
40
|
+
'internal_error',
|
|
41
|
+
]),
|
|
42
|
+
correlationId: z.string().min(1).max(128),
|
|
43
|
+
recoverable: z.boolean(),
|
|
44
|
+
replyTo: z.uuid().optional(),
|
|
45
|
+
type: z.literal('error'),
|
|
46
|
+
})
|
|
47
|
+
.strict(),
|
|
48
|
+
z
|
|
49
|
+
.object({
|
|
50
|
+
...envelope,
|
|
51
|
+
expiresAt: z.iso.datetime({ offset: true }),
|
|
52
|
+
requestId: z.uuid(),
|
|
53
|
+
type: z.literal('session.expiring'),
|
|
54
|
+
})
|
|
55
|
+
.strict(),
|
|
56
|
+
z
|
|
57
|
+
.object({
|
|
58
|
+
...envelope,
|
|
59
|
+
expiresAt: z.iso.datetime({ offset: true }),
|
|
60
|
+
replyTo: z.uuid(),
|
|
61
|
+
type: z.literal('session.renewed'),
|
|
62
|
+
})
|
|
63
|
+
.strict(),
|
|
64
|
+
z
|
|
65
|
+
.object({
|
|
66
|
+
...envelope,
|
|
67
|
+
height: z.number().int().positive(),
|
|
68
|
+
type: z.literal('resize'),
|
|
69
|
+
})
|
|
70
|
+
.strict(),
|
|
71
|
+
]);
|
|
72
|
+
const parentMessageSchema = z.discriminatedUnion('type', [
|
|
73
|
+
z
|
|
74
|
+
.object({
|
|
75
|
+
...envelope,
|
|
76
|
+
embedUrl: z.url(),
|
|
77
|
+
replyTo: z.uuid(),
|
|
78
|
+
requestId: z.uuid(),
|
|
79
|
+
type: z.literal('session.renew'),
|
|
80
|
+
})
|
|
81
|
+
.strict(),
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
export const embedLifecycle = {
|
|
85
|
+
channelConnectSchema,
|
|
86
|
+
channelRequestSchema,
|
|
87
|
+
iframeMessageSchema,
|
|
88
|
+
parentMessageSchema,
|
|
89
|
+
protocol,
|
|
90
|
+
version,
|
|
91
|
+
} as const;
|
|
92
|
+
|
|
93
|
+
export type EmbedLifecycleChannelConnect = z.infer<typeof channelConnectSchema>;
|
|
94
|
+
export type EmbedLifecycleChannelRequest = z.infer<typeof channelRequestSchema>;
|
|
95
|
+
export type EmbedLifecycleIframeMessage = z.infer<typeof iframeMessageSchema>;
|
|
96
|
+
export type EmbedLifecycleParentMessage = z.infer<typeof parentMessageSchema>;
|
package/src/error.ts
CHANGED