@vrplatform/api 1.2.33-stage.943 → 1.2.34
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/client.d.ts +1 -1
- package/build/main/client.js +1 -1
- package/build/main/client.js.map +1 -1
- package/build/main/error.js +1 -1
- package/build/main/error.js.map +1 -1
- package/build/main/generated/v1.d.ts +745 -657
- package/build/main/generated/v1.js.map +1 -1
- package/build/main/index.d.ts +4 -4
- package/build/main/index.js +0 -1
- package/build/main/index.js.map +1 -1
- package/build/main/ingest/index.d.ts +0 -1
- package/build/main/ingest/index.js.map +1 -1
- package/build/main/ingest/types.d.ts +1 -1
- package/build/main/ingest/types.js.map +1 -1
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/module/client.d.ts +1 -1
- package/build/module/client.js +1 -1
- package/build/module/client.js.map +1 -1
- package/build/module/error.js +1 -1
- package/build/module/error.js.map +1 -1
- package/build/module/generated/v1.d.ts +745 -657
- package/build/module/generated/v1.js.map +1 -1
- package/build/module/index.d.ts +4 -4
- package/build/module/index.js +0 -1
- package/build/module/index.js.map +1 -1
- package/build/module/ingest/index.d.ts +0 -1
- package/build/module/ingest/index.js.map +1 -1
- package/build/module/ingest/types.d.ts +1 -1
- package/build/module/ingest/types.js.map +1 -1
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +8 -6
- package/src/client.ts +4 -1
- package/src/error.ts +1 -1
- package/src/generated/v1.ts +745 -657
- package/src/index.ts +5 -10
- package/src/ingest/index.ts +0 -2
- package/src/ingest/types.ts +1 -1
- package/src/ingest-compat/index.ts +0 -98
- package/src/ingest-compat/map.ts +0 -111
- package/src/ingest-compat/types.ts +0 -9
package/build/main/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { useIngest } from './ingest';
|
|
2
|
+
import type { ApiClient } from './types';
|
|
1
3
|
export * from './client';
|
|
2
4
|
export * from './error';
|
|
3
5
|
export * from './generated/v1';
|
|
4
6
|
export * from './ingest';
|
|
5
|
-
export * from './ingest-compat';
|
|
6
7
|
export * from './types';
|
|
7
|
-
export type ApiIngest = ReturnType<typeof
|
|
8
|
-
export type
|
|
9
|
-
export type VRPlatformApi = import('./types').ApiClient;
|
|
8
|
+
export type ApiIngest = ReturnType<typeof useIngest>;
|
|
9
|
+
export type VRPlatformApi = ApiClient;
|
package/build/main/index.js
CHANGED
|
@@ -18,6 +18,5 @@ __exportStar(require("./client"), exports);
|
|
|
18
18
|
__exportStar(require("./error"), exports);
|
|
19
19
|
__exportStar(require("./generated/v1"), exports);
|
|
20
20
|
__exportStar(require("./ingest"), exports);
|
|
21
|
-
__exportStar(require("./ingest-compat"), exports);
|
|
22
21
|
__exportStar(require("./types"), exports);
|
|
23
22
|
//# sourceMappingURL=index.js.map
|
package/build/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,2CAAyB;AACzB,0CAAwB;AACxB,iDAA+B;AAC/B,2CAAyB;AACzB,0CAAwB","sourcesContent":["import type { useIngest } from './ingest';\nimport type { ApiClient } from './types';\n\nexport * from './client';\nexport * from './error';\nexport * from './generated/v1';\nexport * from './ingest';\nexport * from './types';\n\nexport type ApiIngest = ReturnType<typeof useIngest>;\nexport type VRPlatformApi = ApiClient;\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ApiClient, RequestBody } from '../types';
|
|
2
2
|
import type * as t from './types';
|
|
3
|
-
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
4
3
|
export * from './types';
|
|
5
4
|
export declare function usePostSources(api: ApiClient, config: t.IngestArg): <T = undefined>(data: RequestBody<"post:/sources/batch">["data"], configOverwrites?: t.IngestFnArg) => Promise<t.TypedResponseData<T>[]>;
|
|
6
5
|
export declare function useIngest(api: ApiClient, config: t.IngestArg): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["ingest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyBA,wCAiBC;AAED,8BAwLC;AApOD,oCAAwC;AAMxC,0CAAwB;AAExB,SAAS,WAAW,CAClB,IAAS,EACT,MAAmB,EACnB,gBAAgC;IAEhC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE,GAAG,gBAAgB,CAAC;QAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC;YACvD,IAAI,KAAK;gBAAE,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC/B,IAAI,aAAa;YAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,aAAa,CAAC;IACjE,CAAC;IACD,IAAI,MAAM,CAAC,SAAS;QAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;IAEjE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,cAAc,CAAC,GAAc,EAAE,MAAmB;IAChE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC;IAC/C,KAAK,UAAU,IAAI,CACjB,IAAgD,EAChD,gBAAgC;QAEhC,MAAM,IAAI,GAAuC;YAC/C,GAAG,UAAU;YACb,IAAI;SACL,CAAC;QACF,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,IAAA,oBAAY,EAC3B,MAAM,GAAG,CAAC,IAAI,CAAC,gBAAgB,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AAO,MAAM,IAAI,CACf,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE;gBACvC,OAAO;oBACL,GAAG,MAAM;oBACT,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,SAAS;oBAC9B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI;oBACjD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,KAAM;oBAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,QAAQ;oBACjC,SAAS,EAAE;wBACT,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,SAAS;qBAChB;iBACF,CAAC;YACJ,CAAC,CAAC,EACF,gBAAgB,CACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { throwIfError } from '../error';\nimport type { ApiClient, RequestBody } from '../types';\nimport type * as t from './types';\n\nexport type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\nexport * from './types';\n\nfunction mergeConfig(\n body: any,\n config: t.IngestArg,\n configOverwrites?: t.IngestFnArg\n) {\n const headers: Record<string, string> = {};\n if (configOverwrites) {\n const { correlationId, ...restOverwrites } = configOverwrites;\n for (const [key, value] of Object.entries(restOverwrites))\n if (value) body[key] = value;\n if (correlationId) headers['X-Correlation-Id'] = correlationId;\n }\n if (config.sessionId) headers['X-Session-Id'] = config.sessionId;\n\n return headers;\n}\n\nexport function usePostSources(api: ApiClient, config: t.IngestArg) {\n const { sessionId: _, ...restConfig } = config;\n async function post<T = undefined>(\n data: RequestBody<'post:/sources/batch'>['data'],\n configOverwrites?: t.IngestFnArg\n ): Promise<t.TypedResponseData<T>[]> {\n const body: RequestBody<'post:/sources/batch'> = {\n ...restConfig,\n data,\n };\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.POST('/sources/batch', { body, headers })\n );\n return response.data as any;\n }\n return post;\n}\n\nexport function useIngest(api: ApiClient, config: t.IngestArg) {\n const post = usePostSources(api, config);\n return {\n api,\n get sessionId() {\n return api.sessionId;\n },\n async sources(\n changes: t.IngestSourceInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post(changes, configOverwrites);\n },\n async updateSources(\n data: RequestBody<'put:/sources/batch'>['data'],\n configOverwrites?: t.IngestFnArg\n ) {\n const { sessionId: _, ...restConfig } = config;\n const body: RequestBody<'put:/sources/batch'> = {\n ...restConfig,\n data,\n };\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.PUT('/sources/batch', { body, headers })\n );\n return response.data;\n },\n async reservations(\n changes: t.IngestReservationInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return [];\n return await post<t.ReservationParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'reservation',\n description: source.description || transform.confirmationCode,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n date: source.date || transform.bookedAt,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'reservation',\n },\n };\n }),\n configOverwrites\n );\n },\n async payments(\n changes: t.IngestPaymentInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.PaymentParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'payment',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n date: source.date || transform.paidAt,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'payment',\n },\n };\n }),\n configOverwrites\n );\n },\n async listings(\n changes: t.IngestListingInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.ListingParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'listing',\n description: source.description || transform.name,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'listing',\n },\n };\n }),\n configOverwrites\n );\n },\n async cleanup(\n type: string | 'listing',\n configOverwrites?: t.IngestFnArg & {\n whereRange?: RequestBody<'put:/sources/cleanup'>['whereRange'];\n }\n ) {\n const body: RequestBody<'put:/sources/cleanup'> = {\n syncId: configOverwrites?.syncId || config.syncId,\n connectionId: configOverwrites?.connectionId || config.connectionId,\n type,\n };\n if (configOverwrites?.whereRange) {\n body.whereRange = configOverwrites.whereRange;\n }\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.PUT('/sources/cleanup', { body, headers })\n );\n return response.ok as any;\n },\n async bankRecords(\n changes: t.IngestBankRecordInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.BankRecordParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'bankRecord',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'bankRecord',\n },\n };\n }),\n configOverwrites\n );\n },\n async transactions(\n changes: t.IngestTransactionInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.TransactionParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'transaction',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'transaction',\n },\n };\n }),\n configOverwrites\n );\n },\n async contacts(\n changes: t.IngestContactInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.ContactParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'contact',\n description: source.description || transform.name,\n uniqueRef: source.uniqueRef || transform.email!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'contact',\n },\n };\n }),\n configOverwrites\n );\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["ingest/index.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I,IAAI,SAAS;oBAC9B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI;oBACjD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,KAAM;oBAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,QAAQ;oBACjC,SAAS,EAAE;wBACT,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,SAAS;qBAChB;iBACF,CAAC;YACJ,CAAC,CAAC,EACF,gBAAgB,CACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { throwIfError } from '../error';\nimport type { ApiClient, RequestBody } from '../types';\nimport type * as t from './types';\n\nexport * from './types';\n\nfunction mergeConfig(\n body: any,\n config: t.IngestArg,\n configOverwrites?: t.IngestFnArg\n) {\n const headers: Record<string, string> = {};\n if (configOverwrites) {\n const { correlationId, ...restOverwrites } = configOverwrites;\n for (const [key, value] of Object.entries(restOverwrites))\n if (value) body[key] = value;\n if (correlationId) headers['X-Correlation-Id'] = correlationId;\n }\n if (config.sessionId) headers['X-Session-Id'] = config.sessionId;\n\n return headers;\n}\n\nexport function usePostSources(api: ApiClient, config: t.IngestArg) {\n const { sessionId: _, ...restConfig } = config;\n async function post<T = undefined>(\n data: RequestBody<'post:/sources/batch'>['data'],\n configOverwrites?: t.IngestFnArg\n ): Promise<t.TypedResponseData<T>[]> {\n const body: RequestBody<'post:/sources/batch'> = {\n ...restConfig,\n data,\n };\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.POST('/sources/batch', { body, headers })\n );\n return response.data as any;\n }\n return post;\n}\n\nexport function useIngest(api: ApiClient, config: t.IngestArg) {\n const post = usePostSources(api, config);\n return {\n api,\n get sessionId() {\n return api.sessionId;\n },\n async sources(\n changes: t.IngestSourceInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post(changes, configOverwrites);\n },\n async updateSources(\n data: RequestBody<'put:/sources/batch'>['data'],\n configOverwrites?: t.IngestFnArg\n ) {\n const { sessionId: _, ...restConfig } = config;\n const body: RequestBody<'put:/sources/batch'> = {\n ...restConfig,\n data,\n };\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.PUT('/sources/batch', { body, headers })\n );\n return response.data;\n },\n async reservations(\n changes: t.IngestReservationInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return [];\n return await post<t.ReservationParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'reservation',\n description: source.description || transform.confirmationCode,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n date: source.date || transform.bookedAt,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'reservation',\n },\n };\n }),\n configOverwrites\n );\n },\n async payments(\n changes: t.IngestPaymentInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.PaymentParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'payment',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n date: source.date || transform.paidAt,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'payment',\n },\n };\n }),\n configOverwrites\n );\n },\n async listings(\n changes: t.IngestListingInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.ListingParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'listing',\n description: source.description || transform.name,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'listing',\n },\n };\n }),\n configOverwrites\n );\n },\n async cleanup(\n type: string | 'listing',\n configOverwrites?: t.IngestFnArg & {\n whereRange?: RequestBody<'put:/sources/cleanup'>['whereRange'];\n }\n ) {\n const body: RequestBody<'put:/sources/cleanup'> = {\n syncId: configOverwrites?.syncId || config.syncId,\n connectionId: configOverwrites?.connectionId || config.connectionId,\n type,\n };\n if (configOverwrites?.whereRange) {\n body.whereRange = configOverwrites.whereRange;\n }\n const headers = mergeConfig(body, config, configOverwrites);\n const response = throwIfError(\n await api.PUT('/sources/cleanup', { body, headers })\n );\n return response.ok as any;\n },\n async bankRecords(\n changes: t.IngestBankRecordInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.BankRecordParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'bankRecord',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'bankRecord',\n },\n };\n }),\n configOverwrites\n );\n },\n async transactions(\n changes: t.IngestTransactionInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.TransactionParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'transaction',\n description: source.description || transform.description,\n uniqueRef: source.uniqueRef || transform.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'transaction',\n },\n };\n }),\n configOverwrites\n );\n },\n async contacts(\n changes: t.IngestContactInput[],\n configOverwrites?: t.IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<t.ContactParam>(\n changes.map(({ source, ...transform }) => {\n return {\n ...source,\n type: source.type || 'contact',\n description: source.description || transform.name,\n uniqueRef: source.uniqueRef || transform.email!,\n status: source.status || 'active',\n transform: {\n data: transform,\n type: 'contact',\n },\n };\n }),\n configOverwrites\n );\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PartialBy } from '@
|
|
1
|
+
import type { PartialBy } from '@vrplatform/utils';
|
|
2
2
|
import type { RequestBody, ResponseData } from '../types';
|
|
3
3
|
export type ReservationParam = Omit<RequestBody<'post:/reservations/batch'>['data'][0], 'sourceId'>;
|
|
4
4
|
export type PaymentParam = Omit<RequestBody<'post:/payments/batch'>['data'][0], 'sourceId'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["ingest/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PartialBy } from '@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["ingest/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PartialBy } from '@vrplatform/utils';\nimport type { RequestBody, ResponseData } from '../types';\n\nexport type ReservationParam = Omit<\n RequestBody<'post:/reservations/batch'>['data'][0],\n 'sourceId'\n>;\nexport type PaymentParam = Omit<\n RequestBody<'post:/payments/batch'>['data'][0],\n 'sourceId'\n>;\nexport type ListingParam = Omit<\n RequestBody<'post:/listings/batch'>['data'][0],\n 'sourceId'\n>;\nexport type BankRecordParam = Omit<\n RequestBody<'post:/bank-records/batch'>['data'][0],\n 'sourceId'\n>;\nexport type TransactionParam = Omit<\n RequestBody<'post:/transactions/batch'>['data'][0],\n 'sourceId'\n>;\nexport type ContactParam = Omit<\n RequestBody<'post:/contacts/batch'>['data'][0],\n 'sourceId'\n>;\ntype _SourceWithoutTransform = Omit<\n RequestBody<'post:/sources/batch'>['data'][number],\n 'transform'\n> & {\n // this is ONLY for ecosystem ingestion, can be removed once ecosystem does not rely on ingest, but calls batch endpoints\n fileStorageId?: string;\n};\ntype _SourceWithTransform<T> = _SourceWithoutTransform & {\n transform: { type: string; data: T };\n};\nexport type Source<T = undefined> = T extends undefined\n ? _SourceWithoutTransform\n : _SourceWithTransform<T>;\n\nexport type IngestArg = Omit<RequestBody<'post:/sources/batch'>, 'data'> & {\n sessionId?: string;\n tenantId: string;\n};\nexport type IngestFnArg = Omit<Partial<IngestArg>, 'sessionId'> & {\n correlationId?: string;\n};\n\nexport type BatchResponseData = ResponseData<'post:/sources/batch'>['data'][0];\nexport type TypedResponseData<T = undefined> = Omit<\n BatchResponseData,\n 'transform'\n> &\n (T extends undefined\n ? { transform?: never }\n : {\n transform: Omit<BatchResponseData['transform'], 'data'> & {\n data: T;\n };\n });\n\nexport type Impossible<K extends keyof any> = {\n [P in K]: never;\n};\nexport type NoExtraProperties<T, U extends T = T> = U &\n Impossible<Exclude<keyof U, keyof T>>;\n\nexport type ObjectWithSource<T = undefined> = T & {\n source: PartialBy<_SourceWithoutTransform, 'type'>;\n};\n\nexport type IngestReservationInput = NoExtraProperties<\n ObjectWithSource<ReservationParam>\n>;\nexport type IngestPaymentInput = NoExtraProperties<\n ObjectWithSource<PaymentParam>\n>;\nexport type IngestListingInput = NoExtraProperties<\n ObjectWithSource<ListingParam>\n>;\nexport type IngestBankRecordInput = NoExtraProperties<\n ObjectWithSource<BankRecordParam>\n>;\nexport type IngestTransactionInput = NoExtraProperties<\n ObjectWithSource<TransactionParam>\n>;\nexport type IngestContactInput = NoExtraProperties<\n ObjectWithSource<ContactParam>\n>;\nexport type IngestSourceInput = NoExtraProperties<Source>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/cache.ts","../../src/client.ts","../../src/error.ts","../../src/index.ts","../../src/sec.ts","../../src/types.ts","../../src/generated/openapi-fetch.ts","../../src/generated/v1.ts","../../src/ingest/index.ts","../../src/ingest/types.ts"
|
|
1
|
+
{"root":["../../src/cache.ts","../../src/client.ts","../../src/error.ts","../../src/index.ts","../../src/sec.ts","../../src/types.ts","../../src/generated/openapi-fetch.ts","../../src/generated/v1.ts","../../src/ingest/index.ts","../../src/ingest/types.ts"],"version":"5.9.3"}
|
package/build/module/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RetryableFetchParams } from '@
|
|
1
|
+
import { type RetryableFetchParams } from '@vrplatform/utils';
|
|
2
2
|
import type { ApiClient, ApiClientAuth } from './types';
|
|
3
3
|
export declare function useApiClient({ baseUrl: base, local, auth, sessionId: sid, testing, headers: h, ...retryableFetchParams }: {
|
|
4
4
|
attempts?: number;
|
package/build/module/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRetryableFetch } from '@finalytic/utils';
|
|
2
1
|
import * as Sentry from '@sentry/core';
|
|
2
|
+
import { useRetryableFetch, } from '@vrplatform/utils';
|
|
3
3
|
import createClient from 'openapi-fetch';
|
|
4
4
|
import { useCache } from './cache';
|
|
5
5
|
import { generateApiKeySec } from './sec';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAEL,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG1C,MAAM,UAAU,YAAY,CAAC,EAC3B,OAAO,EAAE,IAAI,EACb,KAAK,EACL,IAAI,EACJ,SAAS,EAAE,GAAG;AACd,cAAc;AACd,OAAO,EACP,OAAO,EAAE,CAAC,EACV,GAAG,oBAAoB,EAYD;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,QAAQ,CACpB,KAAK,EAAE,CAAS,EAAE,EAAE,CAClB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,EAAE,CAAC,EAC1D,MAAM,CACP,CAAC;IAEF,MAAM,cAAc,GAAG,iBAAiB,CAAC;QACvC,GAAG,oBAAoB;QACv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W,CAAC,UAAU,CAAC,SAAS,CAAC;wBACjC,CAAC,CAAC,CAAC,CAAC,WAAW;wBACf,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAC9B,CAAC;gBACJ,MAAM,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvE,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;oBACpC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;gBACjD,CAAC;gBAED,IAAI,KAAK,CAAC,cAAc,CAAC;oBACvB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;gBAC3D,IAAI,KAAK,CAAC,OAAO;oBAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;gBAE/D,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,aAAa,GAAc,MAAa,CAAC;IAC/C,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;IACpC,OAAO,aAAa,CAAC;AACvB,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 type { paths } from './generated/v1';\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 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 retryableFetch = useRetryableFetch({\n ...retryableFetchParams,\n onRetry(arg) {\n cache.invalidate();\n if (retryableFetchParams.onRetry) retryableFetchParams.onRetry(arg);\n },\n });\n\n const trace = Sentry.getTraceData();\n const client = createClient<paths>({\n baseUrl,\n fetch(req) {\n return retryableFetch(async () => {\n let clone: Request = req.clone() as any;\n if (testing?.overwriteUri)\n clone = new Request(testing.overwriteUri, clone);\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 const sessionClient: ApiClient = client as any;\n sessionClient.sessionId = sessionId;\n return sessionClient;\n}\n"]}
|
package/build/module/error.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAY7C,MAAM,OAAO,cAAe,SAAQ,KAAK;IAMpB;IALnB,IAAI,CAAS;IACb,MAAM,CAEF;IACJ,OAAO,CAAM;IACb,YAAmB,KAAQ;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO;YAChB,KAAK,CAAC,OAAO,GAAG;gBACd,KAAK,CAAC,IAAI;gBACV,KAAK,CAAC,MAAM;oBACV,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACV,CAAC,CAAC,CAAC,OAAO,EAAG,CAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;qBACrC,MAAM,CAAC,QAAQ,CAAC;qBAChB,IAAI,CAAC,MAAM,CAAC,CAChB;qBACA,IAAI,CAAC,IAAI,CAAC;aACd;iBACE,MAAM,CAAC,QAAQ,CAAC;iBAChB,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAdJ,UAAK,GAAL,KAAK,CAAG;QAgBzB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC5C,CAAC;CACF;AAOD,MAAM,UAAU,YAAY,CAC1B,QAAwB;IAExB,IAAI,QAAQ,YAAY,OAAO,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YAChC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAChD,CAAC;YAED,MAAM,KAAK,GAAM,QAAQ,CAAC,KAAK,CAAC;YAEhC,IAAI,KAAK;gBAAE,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,GAAM,QAAQ,CAAC,KAAK,CAAC;IAEhC,IAAI,KAAK;QAAE,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import { hasValue } from '@vrplatform/utils';\nimport type { FetchResponse } from './generated/openapi-fetch';\n\ntype E = {\n code: string;\n message: string;\n issues?: {\n message: string;\n }[];\n context?: any;\n stack?: any;\n};\nexport class ApiClientError extends Error {\n code: string;\n issues: {\n message: string;\n }[];\n context: any;\n constructor(public error: E) {\n if (!error.message)\n error.message = [\n error.code,\n error.issues\n ?.map((x) =>\n [x.message, (x as any).path?.join('->')]\n .filter(hasValue)\n .join(' on ')\n )\n .join(', '),\n ]\n .filter(hasValue)\n .join(': ');\n super(error.message);\n\n this.code = error.code;\n this.issues = error.issues || [];\n this.context = error.context || {};\n if (error.stack) this.stack = error.stack;\n }\n}\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: T\n): NonNullable<T['data']>;\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: Promise<T>\n): Promise<NonNullable<T['data']>>;\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: Promise<T> | T\n): Promise<NonNullable<T['data']>> | NonNullable<T['data']> {\n if (response instanceof Promise) {\n return response.then((response) => {\n if (response.response.status === 503) {\n throw new Error('Worker resources exceeded.');\n }\n\n const error: E = response.error;\n\n if (error) throw new ApiClientError(error);\n return response.data;\n });\n }\n\n const error: E = response.error;\n\n if (error) throw new ApiClientError(error);\n return response.data;\n}\n"]}
|