@vrplatform/api 1.3.1-preview.2571 → 1.3.1-preview.4532

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.
@@ -2,5 +2,7 @@ import type { ApiClient } from './types';
2
2
  export * from './client';
3
3
  export * from './error';
4
4
  export type * from './generated/v1';
5
+ export * from './routing';
6
+ export * from './sec';
5
7
  export * from './types';
6
8
  export type VRPlatformApi = ApiClient;
@@ -1,4 +1,6 @@
1
1
  export * from './client';
2
2
  export * from './error';
3
+ export * from './routing';
4
+ export * from './sec';
3
5
  export * from './types';
4
6
  //# sourceMappingURL=index.js.map
@@ -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,SAAS,CAAC","sourcesContent":["import type { ApiClient } from './types';\n\nexport * from './client';\nexport * from './error';\nexport type * from './generated/v1';\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,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"]}
@@ -0,0 +1,17 @@
1
+ import { useApiClient } from './client';
2
+ import type { ResponseData } from './types';
3
+ export type TenantRouting = Pick<ResponseData<'get:/teams/resolve'>, 'id' | 'slug' | 'dataRegion' | 'apiBaseUrl'>;
4
+ type ApiClientOptions = Parameters<typeof useApiClient>[0];
5
+ /**
6
+ * Resolve a tenant's region and regional `apiBaseUrl` from a connection id,
7
+ * slug, or tenant id — the client entry point for non-API runtimes that need
8
+ * to reach a tenant's home region. Each call is a `/teams/resolve` round trip;
9
+ * hot-loop callers should cache the result (placement changes only on an
10
+ * explicit tenant migration).
11
+ */
12
+ export declare function resolveTenantRouting({ connectionId, slug, tenantId, auth, ...apiClientOptions }: ApiClientOptions & {
13
+ connectionId?: string;
14
+ slug?: string;
15
+ tenantId?: string;
16
+ }): Promise<TenantRouting>;
17
+ export {};
@@ -0,0 +1,37 @@
1
+ import { useApiClient } from './client';
2
+ import { throwIfError } from './error';
3
+ /**
4
+ * Resolve a tenant's region and regional `apiBaseUrl` from a connection id,
5
+ * slug, or tenant id — the client entry point for non-API runtimes that need
6
+ * to reach a tenant's home region. Each call is a `/teams/resolve` round trip;
7
+ * hot-loop callers should cache the result (placement changes only on an
8
+ * explicit tenant migration).
9
+ */
10
+ export async function resolveTenantRouting({ connectionId, slug, tenantId, auth, ...apiClientOptions }) {
11
+ if (!connectionId && !slug && !tenantId) {
12
+ throw new Error('connectionId, slug, or tenantId is required');
13
+ }
14
+ const response = throwIfError(await useApiClient({
15
+ ...apiClientOptions,
16
+ auth: tenantId
17
+ ? () => {
18
+ const current = typeof auth === 'function' ? auth() : (auth ?? {});
19
+ return {
20
+ ...current,
21
+ tenantId,
22
+ };
23
+ }
24
+ : auth,
25
+ }).GET('/teams/resolve', {
26
+ params: {
27
+ query: slug ? { slug } : connectionId ? { connectionId } : {},
28
+ },
29
+ }));
30
+ return {
31
+ id: response.id,
32
+ slug: response.slug,
33
+ dataRegion: response.dataRegion,
34
+ apiBaseUrl: new URL(response.apiBaseUrl).toString().replace(/\/$/, ''),
35
+ };
36
+ }
37
+ //# sourceMappingURL=routing.js.map
@@ -0,0 +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 +1 @@
1
- {"version":3,"file":"sec.js","sourceRoot":"src/","sources":["sec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EACxB;IACjB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC7C,KAAK,EACL,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EACtB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAC1E,IAAI,EACJ,EAAE,CACH,CAAC;IAEF,OAAO,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;AAAA,CAC/B","sourcesContent":["export async function generateApiKeySec(\n secret: string,\n timestamp = Math.floor(Date.now() / 1000)\n): Promise<string> {\n const encoder = new TextEncoder();\n const secretKey = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign']\n );\n\n const message = encoder.encode(`${timestamp}`);\n const signature = await crypto.subtle.sign('HMAC', secretKey, message);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=/g,\n ''\n );\n\n return `${timestamp}.${hash}`;\n}\n"]}
1
+ {"version":3,"file":"sec.js","sourceRoot":"src/","sources":["sec.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAEzC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC7C,KAAK,EACL,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EACtB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAC1E,IAAI,EACJ,EAAE,CACH,CAAC;IAEF,OAAO,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;AAChC,CAAC","sourcesContent":["export async function generateApiKeySec(\n secret: string,\n timestamp = Math.floor(Date.now() / 1000)\n): Promise<string> {\n const encoder = new TextEncoder();\n const secretKey = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign']\n );\n\n const message = encoder.encode(`${timestamp}`);\n const signature = await crypto.subtle.sign('HMAC', secretKey, message);\n const hash = btoa(String.fromCharCode(...new Uint8Array(signature))).replace(\n /=/g,\n ''\n );\n\n return `${timestamp}.${hash}`;\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.2571",
6
+ "version": "1.3.1-preview.4532",
7
7
  "description": "",
8
8
  "main": "build/main/index.js",
9
9
  "module": "build/module/index.js",
@@ -14,20 +14,20 @@
14
14
  "npmpub:production": "npm publish package.tgz --tag latest",
15
15
  "npmpub:preview": "npm publish package.tgz --tag preview",
16
16
  "build": "bun run generate-client && bun build:main && bun build:module",
17
- "build:main": "tsgo -b tsconfig.main.json",
18
- "build:module": "tsgo -b tsconfig.esm.json",
17
+ "build:main": "tsc -b tsconfig.main.json",
18
+ "build:module": "tsc -b tsconfig.esm.json",
19
19
  "dev": "NODE_ENV=generator bun --watch ./generate.ts",
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": "tsgo --noEmit"
23
+ "tsgo": "tsc --noEmit"
24
24
  },
25
25
  "author": "",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "openapi-fetch": "0.17.0",
28
+ "openapi-fetch": "0.15.0",
29
29
  "openapi-typescript": "^7.13.0",
30
- "openapi-typescript-helpers": "^0.1.0"
30
+ "openapi-typescript-helpers": "^0.0.15"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@vrplatform/utils": "*",
package/src/client.ts CHANGED
@@ -9,6 +9,8 @@ import type { paths } from './generated/v1';
9
9
  import { generateApiKeySec } from './sec';
10
10
  import type { ApiClient, ApiClientAuth } from './types';
11
11
 
12
+ const DEFAULT_API_CLIENT_ATTEMPTS = 5;
13
+
12
14
  export function useApiClient({
13
15
  baseUrl: base,
14
16
  local,
@@ -45,6 +47,7 @@ export function useApiClient({
45
47
 
46
48
  const retryableFetch = useRetryableFetch({
47
49
  ...retryableFetchParams,
50
+ attempts: retryableFetchParams.attempts ?? DEFAULT_API_CLIENT_ATTEMPTS,
48
51
  onRetry(arg) {
49
52
  cache.invalidate();
50
53
  if (retryableFetchParams.onRetry) retryableFetchParams.onRetry(arg);