@vrplatform/api 1.3.1 → 2.0.0-experimental.1
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.d.ts +2 -5
- package/build/main/cache.js.map +1 -1
- package/build/main/client-v2.d.ts +15 -0
- package/build/main/client-v2.js +96 -0
- package/build/main/client-v2.js.map +1 -0
- package/build/main/client.js +0 -6
- package/build/main/client.js.map +1 -1
- package/build/main/error.d.ts +2 -1
- package/build/main/error.js +1 -3
- package/build/main/error.js.map +1 -1
- package/build/main/generated/v1.d.ts +18460 -14526
- package/build/main/generated/v1.js.map +1 -1
- package/build/main/generated/v2.d.ts +20289 -0
- package/build/main/generated/v2.js +7 -0
- package/build/main/generated/v2.js.map +1 -0
- package/build/main/index.d.ts +5 -3
- package/build/main/index.js +26 -1
- package/build/main/index.js.map +1 -1
- package/build/main/ingest-compat/index.d.ts +13 -0
- package/build/main/ingest-compat/index.js +92 -0
- package/build/main/ingest-compat/index.js.map +1 -0
- package/build/main/ingest-compat/map.d.ts +6 -0
- package/build/main/ingest-compat/map.js +67 -0
- package/build/main/ingest-compat/map.js.map +1 -0
- package/build/main/ingest-compat/types.d.ts +7 -0
- package/build/main/ingest-compat/types.js +3 -0
- package/build/main/ingest-compat/types.js.map +1 -0
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/main/types-v2.d.ts +60 -0
- package/build/main/types-v2.js +3 -0
- package/build/main/types-v2.js.map +1 -0
- package/build/module/cache.d.ts +2 -5
- package/build/module/cache.js.map +1 -1
- package/build/module/client-v2.d.ts +15 -0
- package/build/module/client-v2.js +57 -0
- package/build/module/client-v2.js.map +1 -0
- package/build/module/client.js +0 -6
- package/build/module/client.js.map +1 -1
- package/build/module/error.d.ts +2 -1
- package/build/module/error.js +1 -3
- package/build/module/error.js.map +1 -1
- package/build/module/generated/v1.d.ts +18460 -14526
- package/build/module/generated/v1.js.map +1 -1
- package/build/module/generated/v2.d.ts +20289 -0
- package/build/module/generated/v2.js +6 -0
- package/build/module/generated/v2.js.map +1 -0
- package/build/module/index.d.ts +5 -3
- package/build/module/index.js +3 -1
- package/build/module/index.js.map +1 -1
- package/build/module/ingest-compat/index.d.ts +13 -0
- package/build/module/ingest-compat/index.js +75 -0
- package/build/module/ingest-compat/index.js.map +1 -0
- package/build/module/ingest-compat/map.d.ts +6 -0
- package/build/module/ingest-compat/map.js +64 -0
- package/build/module/ingest-compat/map.js.map +1 -0
- package/build/module/ingest-compat/types.d.ts +7 -0
- package/build/module/ingest-compat/types.js +2 -0
- package/build/module/ingest-compat/types.js.map +1 -0
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/build/module/types-v2.d.ts +60 -0
- package/build/module/types-v2.js +2 -0
- package/build/module/types-v2.js.map +1 -0
- package/package.json +28 -21
- package/src/cache.ts +2 -2
- package/src/client-v2.ts +92 -0
- package/src/client.ts +2 -8
- package/src/error.ts +3 -4
- package/src/generated/v1.ts +18460 -14526
- package/src/generated/v2.ts +20290 -0
- package/src/index.ts +5 -3
- package/src/types-v2.ts +93 -0
- package/src/generated/openapi-fetch.ts +0 -433
- package/src/ingest/index.ts +0 -227
- package/src/ingest/types.ts +0 -91
package/build/module/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { useIngest } from './ingest';
|
|
2
1
|
import type { ApiClient } from './types';
|
|
2
|
+
import type { ApiClientV2 } from './types-v2';
|
|
3
3
|
export * from './client';
|
|
4
|
+
export * from './client-v2';
|
|
4
5
|
export * from './error';
|
|
5
6
|
export * from './generated/v1';
|
|
6
|
-
export * from './
|
|
7
|
+
export * as v2 from './generated/v2';
|
|
7
8
|
export * from './types';
|
|
8
|
-
export
|
|
9
|
+
export * from './types-v2';
|
|
9
10
|
export type VRPlatformApi = ApiClient;
|
|
11
|
+
export type VRPlatformApiV2 = ApiClientV2;
|
package/build/module/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './client';
|
|
2
|
+
export * from './client-v2';
|
|
2
3
|
export * from './error';
|
|
3
4
|
export * from './generated/v1';
|
|
4
|
-
export * from './
|
|
5
|
+
export * as v2 from './generated/v2';
|
|
5
6
|
export * from './types';
|
|
7
|
+
export * from './types-v2';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC","sourcesContent":["import type { ApiClient } from './types';\nimport type { ApiClientV2 } from './types-v2';\n\nexport * from './client';\nexport * from './client-v2';\nexport * from './error';\nexport * from './generated/v1';\nexport * as v2 from './generated/v2';\nexport * from './types';\nexport * from './types-v2';\n\nexport type VRPlatformApi = ApiClient;\nexport type VRPlatformApiV2 = ApiClientV2;\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IngestArg, type IngestFnArg, type PartialBy, type Source } from '../ingest';
|
|
2
|
+
import type { ApiClient } from '../types';
|
|
3
|
+
import type { ListingInput, PaymentInput, ReservationInput } from './types';
|
|
4
|
+
export * from './map';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export declare function useIngestCompat(api: ApiClient, config: IngestArg): {
|
|
7
|
+
api: ApiClient;
|
|
8
|
+
readonly sessionId: string;
|
|
9
|
+
sources(changes: Source[], configOverwrites?: IngestFnArg): Promise<import("../ingest").TypedResponseData<undefined>[] | undefined>;
|
|
10
|
+
reservations(changes: PartialBy<Source<ReservationInput>, "type">[], configOverwrites?: IngestFnArg): Promise<import("../ingest").TypedResponseData<ReservationInput>[]>;
|
|
11
|
+
payments(changes: PartialBy<Source<PaymentInput>, "type">[], configOverwrites?: IngestFnArg): Promise<import("../ingest").TypedResponseData<PaymentInput>[] | undefined>;
|
|
12
|
+
listings(changes: PartialBy<Source<ListingInput>, "type">[], configOverwrites?: IngestFnArg): Promise<import("../ingest").TypedResponseData<ListingInput>[] | undefined>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { usePostSources, } from '../ingest';
|
|
2
|
+
import { mapTransform } from './map';
|
|
3
|
+
export * from './map';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export function useIngestCompat(api, config) {
|
|
6
|
+
const post = usePostSources(api, config);
|
|
7
|
+
return {
|
|
8
|
+
api,
|
|
9
|
+
get sessionId() {
|
|
10
|
+
return api.sessionId;
|
|
11
|
+
},
|
|
12
|
+
async sources(changes, configOverwrites) {
|
|
13
|
+
if (!changes.length)
|
|
14
|
+
return undefined;
|
|
15
|
+
return await post(changes, configOverwrites);
|
|
16
|
+
},
|
|
17
|
+
async reservations(changes, configOverwrites) {
|
|
18
|
+
if (!changes.length)
|
|
19
|
+
return [];
|
|
20
|
+
return await post(changes.map(({ transform, ...source }) => {
|
|
21
|
+
const data = mapTransform.reservation(transform.data);
|
|
22
|
+
return {
|
|
23
|
+
...source,
|
|
24
|
+
type: source.type || 'reservation',
|
|
25
|
+
description: source.description || data.confirmationCode,
|
|
26
|
+
uniqueRef: source.uniqueRef || data.uniqueRef,
|
|
27
|
+
date: source.date || data.bookedAt,
|
|
28
|
+
status: source.status || 'active',
|
|
29
|
+
transform: {
|
|
30
|
+
data,
|
|
31
|
+
type: 'reservation',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}), configOverwrites);
|
|
35
|
+
},
|
|
36
|
+
async payments(changes, configOverwrites) {
|
|
37
|
+
if (!changes.length)
|
|
38
|
+
return undefined;
|
|
39
|
+
return await post(changes.map(({ transform, ...source }) => {
|
|
40
|
+
const data = mapTransform.payment(transform.data);
|
|
41
|
+
return {
|
|
42
|
+
...source,
|
|
43
|
+
type: source.type || 'payment',
|
|
44
|
+
description: source.description || data.description,
|
|
45
|
+
uniqueRef: source.uniqueRef || data.uniqueRef,
|
|
46
|
+
date: source.date || data.paidAt,
|
|
47
|
+
status: source.status || 'active',
|
|
48
|
+
transform: {
|
|
49
|
+
data,
|
|
50
|
+
type: 'payment',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}), configOverwrites);
|
|
54
|
+
},
|
|
55
|
+
async listings(changes, configOverwrites) {
|
|
56
|
+
if (!changes.length)
|
|
57
|
+
return undefined;
|
|
58
|
+
return await post(changes.map(({ transform, ...source }) => {
|
|
59
|
+
const data = mapTransform.listing(transform.data);
|
|
60
|
+
return {
|
|
61
|
+
...source,
|
|
62
|
+
type: source.type || 'listing',
|
|
63
|
+
description: source.description || data.name,
|
|
64
|
+
uniqueRef: source.uniqueRef || data.uniqueRef,
|
|
65
|
+
status: source.status || 'active',
|
|
66
|
+
transform: {
|
|
67
|
+
data,
|
|
68
|
+
type: 'listing',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}), configOverwrites);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["ingest-compat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,GACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AAExB,MAAM,UAAU,eAAe,CAAC,GAAc,EAAE,MAAiB;IAC/D,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;I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F,CAAC;AACJ,CAAC","sourcesContent":["import {\n type IngestArg,\n type IngestFnArg,\n type PartialBy,\n type Source,\n usePostSources,\n} from '../ingest';\nimport type { ApiClient } from '../types';\nimport { mapTransform } from './map';\nimport type { ListingInput, PaymentInput, ReservationInput } from './types';\n\nexport * from './map';\nexport * from './types';\n\nexport function useIngestCompat(api: ApiClient, config: IngestArg) {\n const post = usePostSources(api, config);\n return {\n api,\n get sessionId() {\n return api.sessionId;\n },\n async sources(changes: Source[], configOverwrites?: IngestFnArg) {\n if (!changes.length) return undefined;\n return await post(changes, configOverwrites);\n },\n async reservations(\n changes: PartialBy<Source<ReservationInput>, 'type'>[],\n configOverwrites?: IngestFnArg\n ) {\n if (!changes.length) return [];\n return await post<ReservationInput>(\n changes.map(({ transform, ...source }) => {\n const data = mapTransform.reservation(transform.data);\n return {\n ...source,\n type: source.type || 'reservation',\n description: source.description || data.confirmationCode,\n uniqueRef: source.uniqueRef || data.uniqueRef!,\n date: source.date || data.bookedAt,\n status: source.status || 'active',\n transform: {\n data,\n type: 'reservation',\n },\n };\n }),\n configOverwrites\n );\n },\n async payments(\n changes: PartialBy<Source<PaymentInput>, 'type'>[],\n configOverwrites?: IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<PaymentInput>(\n changes.map(({ transform, ...source }) => {\n const data = mapTransform.payment(transform.data);\n return {\n ...source,\n type: source.type || 'payment',\n description: source.description || data.description,\n uniqueRef: source.uniqueRef || data.uniqueRef!,\n date: source.date || data.paidAt,\n status: source.status || 'active',\n transform: {\n data,\n type: 'payment',\n },\n };\n }),\n configOverwrites\n );\n },\n async listings(\n changes: PartialBy<Source<ListingInput>, 'type'>[],\n configOverwrites?: IngestFnArg\n ) {\n if (!changes.length) return undefined;\n return await post<ListingInput>(\n changes.map(({ transform, ...source }) => {\n const data = mapTransform.listing(transform.data);\n return {\n ...source,\n type: source.type || 'listing',\n description: source.description || data.name,\n uniqueRef: source.uniqueRef || data.uniqueRef!,\n status: source.status || 'active',\n transform: {\n data,\n type: 'listing',\n },\n };\n }),\n configOverwrites\n );\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ListingInput, ListingOutput, PaymentInput, PaymentOutput, ReservationInput, ReservationOutput } from './types';
|
|
2
|
+
export declare const mapTransform: {
|
|
3
|
+
reservation: ({ id, uniqueRef, cancelledAt, status, listingConnectionId, listingConnectionRef, guestName, checkIn, checkOut, metadata, currency, bookedAt, bookingPlatform, pmsReferenceCode, bookerName, guests, confirmationCode, paymentLines, centTotal: _, nights: __, sourceId: ___, }: ReservationInput) => ReservationOutput;
|
|
4
|
+
payment: ({ currency, description, uniqueRef, payedAt, etaAt, metadata, lines, }: PaymentInput) => PaymentOutput;
|
|
5
|
+
listing: (item: ListingInput) => ListingOutput;
|
|
6
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const mapTransform = {
|
|
2
|
+
reservation: ({ id, uniqueRef, cancelledAt, status, listingConnectionId, listingConnectionRef, guestName, checkIn, checkOut, metadata, currency, bookedAt, bookingPlatform, pmsReferenceCode, bookerName, guests, confirmationCode, paymentLines, centTotal: _, nights: __, sourceId: ___, }) => ({
|
|
3
|
+
id,
|
|
4
|
+
uniqueRef,
|
|
5
|
+
cancelledAt,
|
|
6
|
+
status: status === 'inactive' ? null : status,
|
|
7
|
+
listingId: listingConnectionId?.toString() || listingConnectionRef?.toString(),
|
|
8
|
+
guestName,
|
|
9
|
+
checkIn,
|
|
10
|
+
checkOut,
|
|
11
|
+
metadata,
|
|
12
|
+
currency,
|
|
13
|
+
bookedAt,
|
|
14
|
+
bookingPlatform,
|
|
15
|
+
pmsReferenceCode,
|
|
16
|
+
bookerName,
|
|
17
|
+
guests,
|
|
18
|
+
confirmationCode,
|
|
19
|
+
lines: paymentLines?.map((line) => ({
|
|
20
|
+
type: line.type2,
|
|
21
|
+
amount: line.centTotal || 0,
|
|
22
|
+
uniqueRef: line.uniqueRef,
|
|
23
|
+
description: line.description,
|
|
24
|
+
metadata: line.metadata,
|
|
25
|
+
})) || [],
|
|
26
|
+
}),
|
|
27
|
+
payment: ({ currency, description, uniqueRef, payedAt, etaAt, metadata, lines, }) => ({
|
|
28
|
+
uniqueRef,
|
|
29
|
+
metadata,
|
|
30
|
+
currency,
|
|
31
|
+
paidAt: payedAt,
|
|
32
|
+
etaAt,
|
|
33
|
+
description: description ?? 'Payment',
|
|
34
|
+
lines: lines?.map((line) => ({
|
|
35
|
+
type: line.type2,
|
|
36
|
+
amount: line.centTotal || 0,
|
|
37
|
+
uniqueRef: line.uniqueRef,
|
|
38
|
+
description: line.description,
|
|
39
|
+
metadata: line.metadata,
|
|
40
|
+
})) || [],
|
|
41
|
+
}),
|
|
42
|
+
listing: (item) => {
|
|
43
|
+
let status = item.status === 'disabled'
|
|
44
|
+
? 'inactive'
|
|
45
|
+
: item.status === 'enabled'
|
|
46
|
+
? 'active'
|
|
47
|
+
: item.status;
|
|
48
|
+
if (!item.status && item.pmsStatus) {
|
|
49
|
+
status =
|
|
50
|
+
item.pmsStatus === 'disabled' || item.pmsStatus === 'inactive'
|
|
51
|
+
? 'inactive'
|
|
52
|
+
: item.pmsStatus === 'enabled' || item.pmsStatus === 'active'
|
|
53
|
+
? 'active'
|
|
54
|
+
: null;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
name: `${item.name}`,
|
|
58
|
+
status: status || 'active',
|
|
59
|
+
uniqueRef: item.uniqueRef,
|
|
60
|
+
defaultCurrency: item.defaultCurrency,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"src/","sources":["ingest-compat/map.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE,CAAC,EACZ,EAAE,EACF,SAAS,EACT,WAAW,EACX,MAAM,EACN,mBAAmB,EACnB,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IAAI,CAAC,KAAM;YACjB,MAAM,EAAE,IAAI,CAAC,SAAS,IAAI,CAAC;YAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC,IAAI,EAAE;KACZ,CAAC;IACF,OAAO,EAAE,CAAC,IAAkB,EAAiB,EAAE;QAC7C,IAAI,MAAM,GACR,IAAI,CAAC,MAAM,KAAK,UAAU;YACxB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;gBACzB,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnC,MAAM;gBACJ,IAAI,CAAC,SAAS,KAAK,UAAU,IAAI,IAAI,CAAC,SAAS,KAAK,UAAU;oBAC5D,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,QAAQ;wBAC3D,CAAC,CAAC,QAAQ;wBACV,CAAC,CAAC,IAAI,CAAC;QACf,CAAC;QACD,OAAO;YACL,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE;YACpB,MAAM,EAAE,MAAM,IAAI,QAAQ;YAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { RequestBody } from '../types';\nimport type {\n ListingInput,\n ListingOutput,\n PaymentInput,\n PaymentOutput,\n ReservationInput,\n ReservationOutput,\n} from './types';\n\nexport const mapTransform = {\n reservation: ({\n id,\n uniqueRef,\n cancelledAt,\n status,\n listingConnectionId,\n listingConnectionRef,\n guestName,\n checkIn,\n checkOut,\n metadata,\n currency,\n bookedAt,\n bookingPlatform,\n pmsReferenceCode,\n bookerName,\n guests,\n confirmationCode,\n paymentLines,\n centTotal: _,\n nights: __,\n sourceId: ___,\n }: ReservationInput): ReservationOutput => ({\n id,\n uniqueRef,\n cancelledAt,\n status: status === 'inactive' ? null : status,\n listingId:\n listingConnectionId?.toString() || listingConnectionRef?.toString(),\n guestName,\n checkIn,\n checkOut,\n metadata,\n currency,\n bookedAt,\n bookingPlatform,\n pmsReferenceCode,\n bookerName,\n guests,\n confirmationCode,\n lines:\n (paymentLines as any[])?.map<\n RequestBody<'post:/reservations/batch'>['data'][0]['lines'][0]\n >((line) => ({\n type: line.type2!,\n amount: line.centTotal || 0,\n uniqueRef: line.uniqueRef,\n description: line.description,\n metadata: line.metadata,\n })) || [],\n }),\n payment: ({\n currency,\n description,\n uniqueRef,\n payedAt,\n etaAt,\n metadata,\n lines,\n }: PaymentInput): PaymentOutput => ({\n uniqueRef,\n metadata,\n currency,\n paidAt: payedAt,\n etaAt,\n description: description ?? 'Payment',\n lines:\n (lines as any[])?.map<\n RequestBody<'post:/payments/batch'>['data'][0]['lines'][0]\n >((line) => ({\n type: line.type2!,\n amount: line.centTotal || 0,\n uniqueRef: line.uniqueRef,\n description: line.description,\n metadata: line.metadata,\n })) || [],\n }),\n listing: (item: ListingInput): ListingOutput => {\n let status =\n item.status === 'disabled'\n ? 'inactive'\n : item.status === 'enabled'\n ? 'active'\n : item.status;\n if (!item.status && item.pmsStatus) {\n status =\n item.pmsStatus === 'disabled' || item.pmsStatus === 'inactive'\n ? 'inactive'\n : item.pmsStatus === 'enabled' || item.pmsStatus === 'active'\n ? 'active'\n : null;\n }\n return {\n name: `${item.name}`,\n status: status || 'active',\n uniqueRef: item.uniqueRef,\n defaultCurrency: item.defaultCurrency,\n };\n },\n};\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RequestBody } from '../types';
|
|
2
|
+
export type ReservationInput = Record<string, any>;
|
|
3
|
+
export type ReservationOutput = RequestBody<'post:/reservations/batch'>['data'][0];
|
|
4
|
+
export type PaymentInput = Record<string, any>;
|
|
5
|
+
export type PaymentOutput = RequestBody<'post:/payments/batch'>['data'][0];
|
|
6
|
+
export type ListingInput = Record<string, any>;
|
|
7
|
+
export type ListingOutput = RequestBody<'post:/listings/batch'>['data'][0];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["ingest-compat/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RequestBody } from '../types';\n\nexport type ReservationInput = Record<string, any>;\nexport type ReservationOutput =\n RequestBody<'post:/reservations/batch'>['data'][0];\nexport type PaymentInput = Record<string, any>;\nexport type PaymentOutput = RequestBody<'post:/payments/batch'>['data'][0];\nexport type ListingInput = Record<string, any>;\nexport type ListingOutput = RequestBody<'post:/listings/batch'>['data'][0];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/cache.ts","../../src/client.ts","../../src/
|
|
1
|
+
{"root":["../../src/cache.ts","../../src/client-v2.ts","../../src/client.ts","../../src/error.ts","../../src/index.ts","../../src/sec.ts","../../src/types-v2.ts","../../src/types.ts","../../src/generated/v1.ts","../../src/generated/v2.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type createClient from 'openapi-fetch';
|
|
2
|
+
import type { paths as pathsV2 } from './generated/v2';
|
|
3
|
+
export type ApiClientV2 = ReturnType<typeof createClient<pathsV2>> & {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
};
|
|
6
|
+
type ResponseCombinationsV2 = {
|
|
7
|
+
[Path in keyof pathsV2]: {
|
|
8
|
+
[Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never ? never : pathsV2[Path][Method] extends {
|
|
9
|
+
responses: {
|
|
10
|
+
200: {
|
|
11
|
+
content: {
|
|
12
|
+
'application/json': unknown;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
} ? `${Method & string}:${Path}` : never;
|
|
17
|
+
}[keyof pathsV2[Path]];
|
|
18
|
+
}[keyof pathsV2];
|
|
19
|
+
export type ResponseDataV2<T extends ResponseCombinationsV2> = T extends `${infer Method}:${infer Path}` ? Path extends keyof pathsV2 ? Method extends keyof pathsV2[Path] ? pathsV2[Path][Method] extends {
|
|
20
|
+
responses: {
|
|
21
|
+
200: {
|
|
22
|
+
content: {
|
|
23
|
+
'application/json': infer Data;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
} ? Data : never : never : never : never;
|
|
28
|
+
type RequestBodyCombinationsV2 = {
|
|
29
|
+
[Path in keyof pathsV2]: {
|
|
30
|
+
[Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never ? never : pathsV2[Path][Method] extends {
|
|
31
|
+
requestBody: {
|
|
32
|
+
content: {
|
|
33
|
+
'application/json': unknown;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
} ? `${Method & string}:${Path}` : never;
|
|
37
|
+
}[keyof pathsV2[Path]];
|
|
38
|
+
}[keyof pathsV2];
|
|
39
|
+
export type RequestBodyV2<T extends RequestBodyCombinationsV2> = T extends `${infer Method}:${infer Path}` ? Path extends keyof pathsV2 ? Method extends keyof pathsV2[Path] ? pathsV2[Path][Method] extends {
|
|
40
|
+
requestBody: {
|
|
41
|
+
content: {
|
|
42
|
+
'application/json': infer Data;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
} ? Data : never : never : never : never;
|
|
46
|
+
type RequestParamCombinationsV2 = {
|
|
47
|
+
[Path in keyof pathsV2]: {
|
|
48
|
+
[Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never ? never : pathsV2[Path][Method] extends {
|
|
49
|
+
parameters: {
|
|
50
|
+
query?: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
} ? `${Method & string}:${Path}` : never;
|
|
53
|
+
}[keyof pathsV2[Path]];
|
|
54
|
+
}[keyof pathsV2];
|
|
55
|
+
export type RequestQueryV2<T extends RequestParamCombinationsV2> = T extends `${infer Method}:${infer Path}` ? Path extends keyof pathsV2 ? Method extends keyof pathsV2[Path] ? pathsV2[Path][Method] extends {
|
|
56
|
+
parameters: {
|
|
57
|
+
query?: infer Data;
|
|
58
|
+
};
|
|
59
|
+
} ? Data : never : never : never : never;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-v2.js","sourceRoot":"src/","sources":["types-v2.ts"],"names":[],"mappings":"","sourcesContent":["import type createClient from 'openapi-fetch';\nimport type { paths as pathsV2 } from './generated/v2';\n\nexport type ApiClientV2 = ReturnType<typeof createClient<pathsV2>> & {\n sessionId: string;\n};\n\ntype ResponseCombinationsV2 = {\n [Path in keyof pathsV2]: {\n [Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never\n ? never\n : pathsV2[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': unknown } };\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof pathsV2[Path]];\n}[keyof pathsV2];\n\nexport type ResponseDataV2<T extends ResponseCombinationsV2> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof pathsV2\n ? Method extends keyof pathsV2[Path]\n ? pathsV2[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': infer Data } };\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n\ntype RequestBodyCombinationsV2 = {\n [Path in keyof pathsV2]: {\n [Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never\n ? never\n : pathsV2[Path][Method] extends {\n requestBody: {\n content: { 'application/json': unknown };\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof pathsV2[Path]];\n}[keyof pathsV2];\n\nexport type RequestBodyV2<T extends RequestBodyCombinationsV2> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof pathsV2\n ? Method extends keyof pathsV2[Path]\n ? pathsV2[Path][Method] extends {\n requestBody: {\n content: { 'application/json': infer Data };\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n\ntype RequestParamCombinationsV2 = {\n [Path in keyof pathsV2]: {\n [Method in keyof pathsV2[Path]]: pathsV2[Path][Method] extends never\n ? never\n : pathsV2[Path][Method] extends {\n parameters: {\n query?: Record<string, unknown>;\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof pathsV2[Path]];\n}[keyof pathsV2];\n\nexport type RequestQueryV2<T extends RequestParamCombinationsV2> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof pathsV2\n ? Method extends keyof pathsV2[Path]\n ? pathsV2[Path][Method] extends {\n parameters: {\n query?: infer Data;\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n"]}
|
package/package.json
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrplatform/api",
|
|
3
3
|
"publishConfig": {
|
|
4
|
-
"access": "public"
|
|
4
|
+
"access": "public",
|
|
5
|
+
"main": "build/main/index.js",
|
|
6
|
+
"typings": "build/main/index.d.ts",
|
|
7
|
+
"module": "build/module/index.js"
|
|
5
8
|
},
|
|
6
|
-
"version": "
|
|
9
|
+
"version": "2.0.0-experimental.1",
|
|
7
10
|
"description": "",
|
|
8
11
|
"main": "build/main/index.js",
|
|
9
12
|
"module": "build/module/index.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"pub": "bun pm version patch --no-git-tag-version && bun run npmpub",
|
|
15
|
+
"npmpub": "bun run build && bunx vrp-deploy --prefix npmpub",
|
|
16
|
+
"npmpub:main": "vrp-publish --tag staging",
|
|
17
|
+
"npmpub:experimental": "vrp-publish --tag experimental",
|
|
18
|
+
"npmpub:release": "vrp-publish",
|
|
19
|
+
"build": "bun run generate && bun build:main && bun build:module",
|
|
20
|
+
"build:main": "tsc -b tsconfig.main.json",
|
|
21
|
+
"build:module": "tsc -b tsconfig.esm.json",
|
|
22
|
+
"dev": "NODE_ENV=generator bun --watch ./generate.ts",
|
|
23
|
+
"generate": "bun generate:schema && bun generate:client",
|
|
24
|
+
"generate:schema": "bun run --cwd ../../api generate",
|
|
25
|
+
"generate:client": "bun generate:client:v1 && bun generate:client:v2",
|
|
26
|
+
"generate:client:v1": "bunx --bun openapi-typescript ../../api/openapi.json -o ./src/generated/v1.ts",
|
|
27
|
+
"generate:client:v2": "bunx --bun openapi-typescript ../../api/openapi.v2.json -o ./src/generated/v2.ts",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"tsgo": "tsgo --noEmit"
|
|
30
|
+
},
|
|
10
31
|
"author": "",
|
|
11
32
|
"license": "ISC",
|
|
12
33
|
"dependencies": {
|
|
13
34
|
"openapi-fetch": "0.15.0",
|
|
14
|
-
"openapi-typescript": "^7.10.1"
|
|
15
|
-
"openapi-typescript-helpers": "^0.0.15"
|
|
35
|
+
"openapi-typescript": "^7.10.1"
|
|
16
36
|
},
|
|
17
37
|
"peerDependencies": {
|
|
18
|
-
"@vrplatform/utils": "
|
|
38
|
+
"@vrplatform/utils": "*",
|
|
19
39
|
"@sentry/core": "*"
|
|
20
40
|
},
|
|
21
41
|
"devDependencies": {
|
|
22
42
|
"@vrplatform/kysely": "*",
|
|
23
43
|
"@vrplatform/repository": "*",
|
|
24
|
-
"@vrplatform/common": "*"
|
|
44
|
+
"@vrplatform/common": "*",
|
|
45
|
+
"@vrplatform/bin": "*",
|
|
46
|
+
"@vrplatform/dispatch": "*"
|
|
25
47
|
},
|
|
26
48
|
"files": [
|
|
27
49
|
"build/main",
|
|
@@ -30,20 +52,5 @@
|
|
|
30
52
|
"!**/*.spec.*",
|
|
31
53
|
"LICENSE"
|
|
32
54
|
],
|
|
33
|
-
"scripts": {
|
|
34
|
-
"pub": "bunx bumpp --no-commit --no-git-check --no-verify --ignore-scripts --no-tag -p=false && bun run npmpub",
|
|
35
|
-
"npmpub": "bun run build && bunx vrp-deploy --prefix npmpub",
|
|
36
|
-
"npmpub:main": "pnpm publish --no-git-checks --tag staging",
|
|
37
|
-
"npmpub:release": "pnpm publish --no-git-checks",
|
|
38
|
-
"build": "bun run generate && bun build:main && bun build:module",
|
|
39
|
-
"build:main": "tsc -b tsconfig.main.json",
|
|
40
|
-
"build:module": "tsc -b tsconfig.esm.json",
|
|
41
|
-
"dev": "NODE_ENV=generator bun --watch ./generate.ts",
|
|
42
|
-
"generate": "bun generate:schema && bun generate:client",
|
|
43
|
-
"generate:schema": "bun run --cwd ../../api generate",
|
|
44
|
-
"generate:client": "bunx --bun openapi-typescript ../../api/openapi.json -o ./src/generated/v1.ts",
|
|
45
|
-
"typecheck": "tsc --noEmit",
|
|
46
|
-
"tsgo": "tsgo --noEmit"
|
|
47
|
-
},
|
|
48
55
|
"typings": "build/main/index.d.ts"
|
|
49
56
|
}
|
package/src/cache.ts
CHANGED
package/src/client-v2.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/core';
|
|
2
|
+
import {
|
|
3
|
+
type RetryableFetchParams,
|
|
4
|
+
useRetryableFetch,
|
|
5
|
+
} from '@vrplatform/utils';
|
|
6
|
+
import createClient from 'openapi-fetch';
|
|
7
|
+
import { useCache } from './cache';
|
|
8
|
+
import type { paths as pathsV2 } from './generated/v2';
|
|
9
|
+
import { generateApiKeySec } from './sec';
|
|
10
|
+
import type { ApiClientAuth } from './types';
|
|
11
|
+
import type { ApiClientV2 } from './types-v2';
|
|
12
|
+
|
|
13
|
+
export function useApiClientV2({
|
|
14
|
+
baseUrl: base,
|
|
15
|
+
local,
|
|
16
|
+
auth,
|
|
17
|
+
sessionId: sid,
|
|
18
|
+
testing,
|
|
19
|
+
headers: h,
|
|
20
|
+
...retryableFetchParams
|
|
21
|
+
}: {
|
|
22
|
+
attempts?: number;
|
|
23
|
+
auth?: ApiClientAuth | (() => ApiClientAuth);
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
local?: boolean | number;
|
|
27
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
28
|
+
testing?: {
|
|
29
|
+
overwriteUri?: string;
|
|
30
|
+
getOverwriteTimestamp?: () => number | undefined;
|
|
31
|
+
};
|
|
32
|
+
} & RetryableFetchParams): ApiClientV2 {
|
|
33
|
+
const baseUrl =
|
|
34
|
+
(local
|
|
35
|
+
? `http://localhost:${typeof local === 'number' ? local : 8877}`
|
|
36
|
+
: base) || 'https://api.vrplatform.app';
|
|
37
|
+
|
|
38
|
+
const sessionId = sid || crypto.randomUUID();
|
|
39
|
+
const cache = useCache(
|
|
40
|
+
async (v: string) =>
|
|
41
|
+
generateApiKeySec(v, testing?.getOverwriteTimestamp?.()),
|
|
42
|
+
60_000
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const retryableFetch = useRetryableFetch({
|
|
46
|
+
...retryableFetchParams,
|
|
47
|
+
onRetry(arg) {
|
|
48
|
+
cache.invalidate();
|
|
49
|
+
if (retryableFetchParams.onRetry) retryableFetchParams.onRetry(arg);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const trace = Sentry.getTraceData();
|
|
54
|
+
const client = createClient<pathsV2>({
|
|
55
|
+
baseUrl,
|
|
56
|
+
fetch(req: any) {
|
|
57
|
+
return retryableFetch(async () => {
|
|
58
|
+
let clone: any = req.clone();
|
|
59
|
+
if (testing?.overwriteUri)
|
|
60
|
+
clone = new Request(testing.overwriteUri, clone);
|
|
61
|
+
|
|
62
|
+
const a = (typeof auth === 'function' ? auth() : auth) || {};
|
|
63
|
+
if (sessionId) clone.headers.set('X-Session-Id', sessionId);
|
|
64
|
+
if (a.sec)
|
|
65
|
+
clone.headers.set('X-Api-Key', `Sec ${await cache.current(a.sec)}`);
|
|
66
|
+
if (a.apiKey) clone.headers.set('X-Api-Key', a.apiKey);
|
|
67
|
+
if (a.tenantId) clone.headers.set('X-Team-Id', a.tenantId);
|
|
68
|
+
if (a.accessToken)
|
|
69
|
+
clone.headers.set(
|
|
70
|
+
'Authorization',
|
|
71
|
+
a.accessToken.startsWith('Bearer ')
|
|
72
|
+
? a.accessToken
|
|
73
|
+
: `Bearer ${a.accessToken}`
|
|
74
|
+
);
|
|
75
|
+
const additionalHeaders = h ? (typeof h === 'function' ? h() : h) : {};
|
|
76
|
+
for (const key in additionalHeaders) {
|
|
77
|
+
clone.headers.set(key, additionalHeaders[key]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (trace['sentry-trace'])
|
|
81
|
+
clone.headers.set('sentry-trace', trace['sentry-trace']);
|
|
82
|
+
if (trace.baggage) clone.headers.set('baggage', trace.baggage);
|
|
83
|
+
|
|
84
|
+
return clone;
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return Object.assign(client, {
|
|
90
|
+
sessionId,
|
|
91
|
+
});
|
|
92
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -54,15 +54,9 @@ export function useApiClient({
|
|
|
54
54
|
const trace = Sentry.getTraceData();
|
|
55
55
|
const client = createClient<paths>({
|
|
56
56
|
baseUrl,
|
|
57
|
-
|
|
58
|
-
array: {
|
|
59
|
-
explode: false,
|
|
60
|
-
style: 'form',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
fetch(req) {
|
|
57
|
+
fetch(req: any) {
|
|
64
58
|
return retryableFetch(async () => {
|
|
65
|
-
let clone: any = req.clone()
|
|
59
|
+
let clone: any = req.clone();
|
|
66
60
|
if (testing?.overwriteUri)
|
|
67
61
|
clone = new Request(testing.overwriteUri, clone);
|
|
68
62
|
|
package/src/error.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { hasValue } from '@vrplatform/utils';
|
|
2
|
-
import type { FetchResponse } from '
|
|
2
|
+
import type { FetchResponse } from 'openapi-fetch';
|
|
3
3
|
|
|
4
4
|
type E = {
|
|
5
5
|
code: string;
|
|
6
6
|
message: string;
|
|
7
7
|
issues?: {
|
|
8
8
|
message: string;
|
|
9
|
+
path?: Array<string | number>;
|
|
9
10
|
}[];
|
|
10
11
|
context?: any;
|
|
11
12
|
stack?: any;
|
|
@@ -22,9 +23,7 @@ export class ApiClientError extends Error {
|
|
|
22
23
|
error.code,
|
|
23
24
|
error.issues
|
|
24
25
|
?.map((x) =>
|
|
25
|
-
[x.message,
|
|
26
|
-
.filter(hasValue)
|
|
27
|
-
.join(' on ')
|
|
26
|
+
[x.message, x.path?.join('->')].filter(hasValue).join(' on ')
|
|
28
27
|
)
|
|
29
28
|
.join(', '),
|
|
30
29
|
]
|