@vrplatform/api 1.2.31 → 1.2.33

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 (38) hide show
  1. package/build/main/fetcher.d.ts +18 -0
  2. package/build/main/fetcher.js +68 -0
  3. package/build/main/fetcher.js.map +1 -0
  4. package/build/main/generated/v1.d.ts +12334 -11416
  5. package/build/main/generated/v1.js.map +1 -1
  6. package/build/main/headers.d.ts +18 -0
  7. package/build/main/headers.js +25 -0
  8. package/build/main/headers.js.map +1 -0
  9. package/build/main/ingest-compat/index.d.ts +1 -2
  10. package/build/main/ingest-compat/index.js.map +1 -1
  11. package/build/main/ingest-compat/map.js.map +1 -1
  12. package/build/main/ingest-compat/types.d.ts +4 -12
  13. package/build/main/ingest-compat/types.js.map +1 -1
  14. package/build/main/retryable-errors.d.ts +9 -0
  15. package/build/main/retryable-errors.js +38 -0
  16. package/build/main/retryable-errors.js.map +1 -0
  17. package/build/module/fetcher.d.ts +18 -0
  18. package/build/module/fetcher.js +63 -0
  19. package/build/module/fetcher.js.map +1 -0
  20. package/build/module/generated/v1.d.ts +12334 -11416
  21. package/build/module/generated/v1.js.map +1 -1
  22. package/build/module/headers.d.ts +18 -0
  23. package/build/module/headers.js +23 -0
  24. package/build/module/headers.js.map +1 -0
  25. package/build/module/ingest-compat/index.d.ts +1 -2
  26. package/build/module/ingest-compat/index.js +1 -1
  27. package/build/module/ingest-compat/index.js.map +1 -1
  28. package/build/module/ingest-compat/map.js.map +1 -1
  29. package/build/module/ingest-compat/types.d.ts +4 -12
  30. package/build/module/ingest-compat/types.js.map +1 -1
  31. package/build/module/retryable-errors.d.ts +9 -0
  32. package/build/module/retryable-errors.js +34 -0
  33. package/build/module/retryable-errors.js.map +1 -0
  34. package/package.json +1 -5
  35. package/src/generated/v1.ts +12334 -11416
  36. package/src/ingest-compat/index.ts +7 -2
  37. package/src/ingest-compat/map.ts +10 -10
  38. package/src/ingest-compat/types.ts +4 -66
@@ -0,0 +1,18 @@
1
+ import type { ClientOptions, HeadersOptions } from 'openapi-fetch';
2
+ import type { CacheResult } from './cache';
3
+ import type { ApiClientAuth } from './types';
4
+ export declare function createQueryFetcher({
5
+ attempts,
6
+ auth,
7
+ fetch: f,
8
+ sessionId,
9
+ headers: h,
10
+ cache,
11
+ }: {
12
+ attempts?: number;
13
+ auth?: ApiClientAuth | (() => ApiClientAuth);
14
+ sessionId: string;
15
+ fetch?: ClientOptions['fetch'];
16
+ headers?: HeadersOptions | (() => HeadersOptions);
17
+ cache: CacheResult<string, string>;
18
+ }): (req: Request) => Promise<Response>;
@@ -0,0 +1,68 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ exports.createQueryFetcher = createQueryFetcher;
3
+ const utils_1 = require('@finalytic/utils');
4
+ const error_1 = require('./error');
5
+ const headers_1 = require('./headers');
6
+ const retryable_errors_1 = require('./retryable-errors');
7
+ // Create query fetcher with retry logic
8
+ function createQueryFetcher({
9
+ attempts = 3,
10
+ auth,
11
+ fetch: f,
12
+ sessionId,
13
+ headers: h,
14
+ cache,
15
+ }) {
16
+ return async (req) => {
17
+ // Implement retry logic with exponential backoff
18
+ let lastError = null;
19
+ for (let attempt = 0; attempt < attempts; attempt++) {
20
+ const isLastAttempt = attempt === attempts - 1;
21
+ try {
22
+ const dup = new Request(req);
23
+ await (0, headers_1.injectHeaders)(dup.headers, {
24
+ auth,
25
+ headers: h,
26
+ sessionId,
27
+ cache,
28
+ });
29
+ const response = await (f || fetch)(dup);
30
+ if (!isLastAttempt)
31
+ (0, retryable_errors_1.assertRetryableResponse)(
32
+ response.status,
33
+ response.headers.has('Retry-After')
34
+ ? Number(response.headers.get('Retry-After')) * 1000
35
+ : undefined
36
+ );
37
+ return response;
38
+ } catch (e) {
39
+ const error = e instanceof Error ? e : new Error(String(e));
40
+ lastError = error;
41
+ // Only retry if this is a retryable error and we haven't exceeded max retries
42
+ if (
43
+ (0, retryable_errors_1.isRetryableError)(lastError) &&
44
+ !isLastAttempt
45
+ ) {
46
+ // Exponential backoff: 2^retries * 100ms + some random jitter
47
+ const backoff =
48
+ typeof lastError.retryAfterMs === 'number'
49
+ ? lastError.retryAfterMs
50
+ : Math.min(100 * 2 ** attempt + Math.random() * 100, 10000);
51
+ // Wait before the next retry
52
+ await (0, utils_1.waitFor)(backoff);
53
+ cache.invalidate();
54
+ } else break;
55
+ }
56
+ }
57
+ const e = lastError || new Error('Max retries exceeded');
58
+ const error = new error_1.ApiClientError({
59
+ code: 'FETCH_ERROR',
60
+ message: e.message,
61
+ context: e,
62
+ issues: [],
63
+ });
64
+ error.stack = e.stack;
65
+ throw error;
66
+ };
67
+ }
68
+ //# sourceMappingURL=fetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.js","sourceRoot":"src/","sources":["fetcher.ts"],"names":[],"mappings":";;AAaA,gDAkEC;AA/ED,4CAA2C;AAG3C,mCAAyC;AACzC,uCAA0C;AAC1C,yDAI4B;AAG5B,wCAAwC;AACxC,SAAgB,kBAAkB,CAAC,EACjC,QAAQ,GAAG,CAAC,EACZ,IAAI,EACJ,KAAK,EAAE,CAAC,EACR,SAAS,EACT,OAAO,EAAE,CAAC,EACV,KAAK,GAQN;IACC,OAAO,KAAK,EAAE,GAAY,EAAE,EAAE;QAC5B,iDAAiD;QACjD,IAAI,SAAS,GAAiB,IAAI,CAAC;QAEnC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC;YACpD,MAAM,aAAa,GAAG,OAAO,KAAK,QAAQ,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC7B,MAAM,IAAA,uBAAa,EAAC,GAAG,CAAC,OAAO,EAAE;oBAC/B,IAAI;oBACJ,OAAO,EAAE,CAAC;oBACV,SAAS;oBACT,KAAK;iBACN,CAAC,CAAC;gBACH,MAA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,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { waitFor } from '@finalytic/utils';\nimport type { ClientOptions, HeadersOptions } from 'openapi-fetch';\nimport type { CacheResult } from './cache';\nimport { ApiClientError } from './error';\nimport { injectHeaders } from './headers';\nimport {\n type RetryableError,\n assertRetryableResponse,\n isRetryableError,\n} from './retryable-errors';\nimport type { ApiClientAuth } from './types';\n\n// Create query fetcher with retry logic\nexport function createQueryFetcher({\n attempts = 3,\n auth,\n fetch: f,\n sessionId,\n headers: h,\n cache,\n}: {\n attempts?: number;\n auth?: ApiClientAuth | (() => ApiClientAuth);\n sessionId: string;\n fetch?: ClientOptions['fetch'];\n headers?: HeadersOptions | (() => HeadersOptions);\n cache: CacheResult<string, string>;\n}) {\n return async (req: Request) => {\n // Implement retry logic with exponential backoff\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < attempts; attempt++) {\n const isLastAttempt = attempt === attempts - 1;\n try {\n const dup = new Request(req);\n await injectHeaders(dup.headers, {\n auth,\n headers: h,\n sessionId,\n cache,\n });\n const response = await (f || fetch)(dup);\n if (!isLastAttempt)\n assertRetryableResponse(\n response.status,\n response.headers.has('Retry-After')\n ? Number(response.headers.get('Retry-After')) * 1000\n : undefined\n );\n return response;\n } catch (e: any) {\n const error = e instanceof Error ? e : new Error(String(e));\n lastError = error;\n\n // Only retry if this is a retryable error and we haven't exceeded max retries\n if (isRetryableError(lastError) && !isLastAttempt) {\n // Exponential backoff: 2^retries * 100ms + some random jitter\n const backoff =\n typeof (lastError as RetryableError).retryAfterMs === 'number'\n ? (lastError as RetryableError).retryAfterMs!\n : Math.min(100 * 2 ** attempt + Math.random() * 100, 10000);\n\n // Wait before the next retry\n await waitFor(backoff);\n cache.invalidate();\n } else break;\n }\n }\n const e = lastError || new Error('Max retries exceeded');\n const error = new ApiClientError({\n code: 'FETCH_ERROR',\n message: e.message,\n context: e,\n issues: [],\n });\n error.stack = e.stack;\n throw error;\n };\n}\n"]}