@vrplatform/api 1.3.0-stage.1301 → 1.3.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/generated/v1.d.ts +3020 -2905
- package/build/main/generated/v1.js.map +1 -1
- package/build/main/index.d.ts +3 -0
- package/build/main/index.js +1 -0
- package/build/main/index.js.map +1 -1
- package/build/main/ingest/index.d.ts +21 -0
- package/build/main/ingest/index.js +189 -0
- package/build/main/ingest/index.js.map +1 -0
- package/build/main/ingest/types.d.ts +48 -0
- package/build/main/ingest/types.js +3 -0
- package/build/main/ingest/types.js.map +1 -0
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/module/generated/v1.d.ts +3020 -2905
- package/build/module/generated/v1.js.map +1 -1
- package/build/module/index.d.ts +3 -0
- package/build/module/index.js +1 -0
- package/build/module/index.js.map +1 -1
- package/build/module/ingest/index.d.ts +21 -0
- package/build/module/ingest/index.js +171 -0
- package/build/module/ingest/index.js.map +1 -0
- package/build/module/ingest/types.d.ts +48 -0
- package/build/module/ingest/types.js +2 -0
- package/build/module/ingest/types.js.map +1 -0
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +18 -22
- package/src/generated/v1.ts +3020 -2905
- package/src/index.ts +3 -0
- package/src/ingest/index.ts +227 -0
- package/src/ingest/types.ts +91 -0
package/build/module/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { useIngest } from './ingest';
|
|
1
2
|
import type { ApiClient } from './types';
|
|
2
3
|
export * from './client';
|
|
3
4
|
export * from './error';
|
|
4
5
|
export * from './generated/v1';
|
|
6
|
+
export * from './ingest';
|
|
5
7
|
export * from './types';
|
|
8
|
+
export type ApiIngest = ReturnType<typeof useIngest>;
|
|
6
9
|
export type VRPlatformApi = ApiClient;
|
package/build/module/index.js
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,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC","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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ApiClient, RequestBody } from '../types';
|
|
2
|
+
import type * as t from './types';
|
|
3
|
+
export * from './types';
|
|
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>[]>;
|
|
5
|
+
export declare function useIngest(api: ApiClient, config: t.IngestArg): {
|
|
6
|
+
api: ApiClient;
|
|
7
|
+
readonly sessionId: string;
|
|
8
|
+
sources(changes: t.IngestSourceInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<undefined>[] | undefined>;
|
|
9
|
+
updateSources(data: RequestBody<"put:/sources/batch">["data"], configOverwrites?: t.IngestFnArg): Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
}[]>;
|
|
12
|
+
reservations(changes: t.IngestReservationInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.ReservationParam>[]>;
|
|
13
|
+
payments(changes: t.IngestPaymentInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.PaymentParam>[] | undefined>;
|
|
14
|
+
listings(changes: t.IngestListingInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.ListingParam>[] | undefined>;
|
|
15
|
+
cleanup(type: string | "listing", configOverwrites?: t.IngestFnArg & {
|
|
16
|
+
whereRange?: RequestBody<"put:/sources/cleanup">["whereRange"];
|
|
17
|
+
}): Promise<any>;
|
|
18
|
+
bankRecords(changes: t.IngestBankRecordInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.BankRecordParam>[] | undefined>;
|
|
19
|
+
transactions(changes: t.IngestTransactionInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.TransactionParam>[] | undefined>;
|
|
20
|
+
contacts(changes: t.IngestContactInput[], configOverwrites?: t.IngestFnArg): Promise<t.TypedResponseData<t.ContactParam>[] | undefined>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { throwIfError } from '../error';
|
|
2
|
+
export * from './types';
|
|
3
|
+
function mergeConfig(body, config, configOverwrites) {
|
|
4
|
+
const headers = {};
|
|
5
|
+
if (configOverwrites) {
|
|
6
|
+
const { correlationId, ...restOverwrites } = configOverwrites;
|
|
7
|
+
for (const [key, value] of Object.entries(restOverwrites))
|
|
8
|
+
if (value)
|
|
9
|
+
body[key] = value;
|
|
10
|
+
if (correlationId)
|
|
11
|
+
headers['X-Correlation-Id'] = correlationId;
|
|
12
|
+
}
|
|
13
|
+
if (config.sessionId)
|
|
14
|
+
headers['X-Session-Id'] = config.sessionId;
|
|
15
|
+
return headers;
|
|
16
|
+
}
|
|
17
|
+
export function usePostSources(api, config) {
|
|
18
|
+
const { sessionId: _, ...restConfig } = config;
|
|
19
|
+
async function post(data, configOverwrites) {
|
|
20
|
+
const body = {
|
|
21
|
+
...restConfig,
|
|
22
|
+
data,
|
|
23
|
+
};
|
|
24
|
+
const headers = mergeConfig(body, config, configOverwrites);
|
|
25
|
+
const response = throwIfError(await api.POST('/sources/batch', { body, headers }));
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
return post;
|
|
29
|
+
}
|
|
30
|
+
export function useIngest(api, config) {
|
|
31
|
+
const post = usePostSources(api, config);
|
|
32
|
+
return {
|
|
33
|
+
api,
|
|
34
|
+
get sessionId() {
|
|
35
|
+
return api.sessionId;
|
|
36
|
+
},
|
|
37
|
+
async sources(changes, configOverwrites) {
|
|
38
|
+
if (!changes.length)
|
|
39
|
+
return undefined;
|
|
40
|
+
return await post(changes, configOverwrites);
|
|
41
|
+
},
|
|
42
|
+
async updateSources(data, configOverwrites) {
|
|
43
|
+
const { sessionId: _, ...restConfig } = config;
|
|
44
|
+
const body = {
|
|
45
|
+
...restConfig,
|
|
46
|
+
data,
|
|
47
|
+
};
|
|
48
|
+
const headers = mergeConfig(body, config, configOverwrites);
|
|
49
|
+
const response = throwIfError(await api.PUT('/sources/batch', { body, headers }));
|
|
50
|
+
return response.data;
|
|
51
|
+
},
|
|
52
|
+
async reservations(changes, configOverwrites) {
|
|
53
|
+
if (!changes.length)
|
|
54
|
+
return [];
|
|
55
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
56
|
+
return {
|
|
57
|
+
...source,
|
|
58
|
+
type: source.type || 'reservation',
|
|
59
|
+
description: source.description || transform.confirmationCode,
|
|
60
|
+
uniqueRef: source.uniqueRef || transform.uniqueRef,
|
|
61
|
+
date: source.date || transform.bookedAt,
|
|
62
|
+
status: source.status || 'active',
|
|
63
|
+
transform: {
|
|
64
|
+
data: transform,
|
|
65
|
+
type: 'reservation',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}), configOverwrites);
|
|
69
|
+
},
|
|
70
|
+
async payments(changes, configOverwrites) {
|
|
71
|
+
if (!changes.length)
|
|
72
|
+
return undefined;
|
|
73
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
74
|
+
return {
|
|
75
|
+
...source,
|
|
76
|
+
type: source.type || 'payment',
|
|
77
|
+
description: source.description || transform.description,
|
|
78
|
+
uniqueRef: source.uniqueRef || transform.uniqueRef,
|
|
79
|
+
date: source.date || transform.paidAt,
|
|
80
|
+
status: source.status || 'active',
|
|
81
|
+
transform: {
|
|
82
|
+
data: transform,
|
|
83
|
+
type: 'payment',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}), configOverwrites);
|
|
87
|
+
},
|
|
88
|
+
async listings(changes, configOverwrites) {
|
|
89
|
+
if (!changes.length)
|
|
90
|
+
return undefined;
|
|
91
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
92
|
+
return {
|
|
93
|
+
...source,
|
|
94
|
+
type: source.type || 'listing',
|
|
95
|
+
description: source.description || transform.name,
|
|
96
|
+
uniqueRef: source.uniqueRef || transform.uniqueRef,
|
|
97
|
+
status: source.status || 'active',
|
|
98
|
+
transform: {
|
|
99
|
+
data: transform,
|
|
100
|
+
type: 'listing',
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}), configOverwrites);
|
|
104
|
+
},
|
|
105
|
+
async cleanup(type, configOverwrites) {
|
|
106
|
+
const body = {
|
|
107
|
+
syncId: configOverwrites?.syncId || config.syncId,
|
|
108
|
+
connectionId: configOverwrites?.connectionId || config.connectionId,
|
|
109
|
+
type,
|
|
110
|
+
};
|
|
111
|
+
if (configOverwrites?.whereRange) {
|
|
112
|
+
body.whereRange = configOverwrites.whereRange;
|
|
113
|
+
}
|
|
114
|
+
const headers = mergeConfig(body, config, configOverwrites);
|
|
115
|
+
const response = throwIfError(await api.PUT('/sources/cleanup', { body, headers }));
|
|
116
|
+
return response.ok;
|
|
117
|
+
},
|
|
118
|
+
async bankRecords(changes, configOverwrites) {
|
|
119
|
+
if (!changes.length)
|
|
120
|
+
return undefined;
|
|
121
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
122
|
+
return {
|
|
123
|
+
...source,
|
|
124
|
+
type: source.type || 'bankRecord',
|
|
125
|
+
description: source.description || transform.description,
|
|
126
|
+
uniqueRef: source.uniqueRef || transform.uniqueRef,
|
|
127
|
+
status: source.status || 'active',
|
|
128
|
+
transform: {
|
|
129
|
+
data: transform,
|
|
130
|
+
type: 'bankRecord',
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}), configOverwrites);
|
|
134
|
+
},
|
|
135
|
+
async transactions(changes, configOverwrites) {
|
|
136
|
+
if (!changes.length)
|
|
137
|
+
return undefined;
|
|
138
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
139
|
+
return {
|
|
140
|
+
...source,
|
|
141
|
+
type: source.type || 'transaction',
|
|
142
|
+
description: source.description || transform.description,
|
|
143
|
+
uniqueRef: source.uniqueRef || transform.uniqueRef,
|
|
144
|
+
status: source.status || 'active',
|
|
145
|
+
transform: {
|
|
146
|
+
data: transform,
|
|
147
|
+
type: 'transaction',
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}), configOverwrites);
|
|
151
|
+
},
|
|
152
|
+
async contacts(changes, configOverwrites) {
|
|
153
|
+
if (!changes.length)
|
|
154
|
+
return undefined;
|
|
155
|
+
return await post(changes.map(({ source, ...transform }) => {
|
|
156
|
+
return {
|
|
157
|
+
...source,
|
|
158
|
+
type: source.type || 'contact',
|
|
159
|
+
description: source.description || transform.name,
|
|
160
|
+
uniqueRef: source.uniqueRef || transform.email,
|
|
161
|
+
status: source.status || 'active',
|
|
162
|
+
transform: {
|
|
163
|
+
data: transform,
|
|
164
|
+
type: 'contact',
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}), configOverwrites);
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["ingest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,cAAc,SAAS,CAAC;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,KAA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AC;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"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PartialBy } from '@vrplatform/utils';
|
|
2
|
+
import type { RequestBody, ResponseData } from '../types';
|
|
3
|
+
export type ReservationParam = Omit<RequestBody<'post:/reservations/batch'>['data'][0], 'sourceId'>;
|
|
4
|
+
export type PaymentParam = Omit<RequestBody<'post:/payments/batch'>['data'][0], 'sourceId'>;
|
|
5
|
+
export type ListingParam = Omit<RequestBody<'post:/listings/batch'>['data'][0], 'sourceId'>;
|
|
6
|
+
export type BankRecordParam = Omit<RequestBody<'post:/bank-records/batch'>['data'][0], 'sourceId'>;
|
|
7
|
+
export type TransactionParam = Omit<RequestBody<'post:/transactions/batch'>['data'][0], 'sourceId'>;
|
|
8
|
+
export type ContactParam = Omit<RequestBody<'post:/contacts/batch'>['data'][0], 'sourceId'>;
|
|
9
|
+
type _SourceWithoutTransform = Omit<RequestBody<'post:/sources/batch'>['data'][number], 'transform'> & {
|
|
10
|
+
fileStorageId?: string;
|
|
11
|
+
};
|
|
12
|
+
type _SourceWithTransform<T> = _SourceWithoutTransform & {
|
|
13
|
+
transform: {
|
|
14
|
+
type: string;
|
|
15
|
+
data: T;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type Source<T = undefined> = T extends undefined ? _SourceWithoutTransform : _SourceWithTransform<T>;
|
|
19
|
+
export type IngestArg = Omit<RequestBody<'post:/sources/batch'>, 'data'> & {
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
tenantId: string;
|
|
22
|
+
};
|
|
23
|
+
export type IngestFnArg = Omit<Partial<IngestArg>, 'sessionId'> & {
|
|
24
|
+
correlationId?: string;
|
|
25
|
+
};
|
|
26
|
+
export type BatchResponseData = ResponseData<'post:/sources/batch'>['data'][0];
|
|
27
|
+
export type TypedResponseData<T = undefined> = Omit<BatchResponseData, 'transform'> & (T extends undefined ? {
|
|
28
|
+
transform?: never;
|
|
29
|
+
} : {
|
|
30
|
+
transform: Omit<BatchResponseData['transform'], 'data'> & {
|
|
31
|
+
data: T;
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
export type Impossible<K extends keyof any> = {
|
|
35
|
+
[P in K]: never;
|
|
36
|
+
};
|
|
37
|
+
export type NoExtraProperties<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
|
|
38
|
+
export type ObjectWithSource<T = undefined> = T & {
|
|
39
|
+
source: PartialBy<_SourceWithoutTransform, 'type'>;
|
|
40
|
+
};
|
|
41
|
+
export type IngestReservationInput = NoExtraProperties<ObjectWithSource<ReservationParam>>;
|
|
42
|
+
export type IngestPaymentInput = NoExtraProperties<ObjectWithSource<PaymentParam>>;
|
|
43
|
+
export type IngestListingInput = NoExtraProperties<ObjectWithSource<ListingParam>>;
|
|
44
|
+
export type IngestBankRecordInput = NoExtraProperties<ObjectWithSource<BankRecordParam>>;
|
|
45
|
+
export type IngestTransactionInput = NoExtraProperties<ObjectWithSource<TransactionParam>>;
|
|
46
|
+
export type IngestContactInput = NoExtraProperties<ObjectWithSource<ContactParam>>;
|
|
47
|
+
export type IngestSourceInput = NoExtraProperties<Source>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
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"],"version":"5.9.3"}
|
|
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/package.json
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrplatform/api",
|
|
3
3
|
"publishConfig": {
|
|
4
|
-
"access": "public"
|
|
5
|
-
"main": "build/main/index.js",
|
|
6
|
-
"typings": "build/main/index.d.ts",
|
|
7
|
-
"module": "build/module/index.js"
|
|
4
|
+
"access": "public"
|
|
8
5
|
},
|
|
9
|
-
"version": "1.3.
|
|
6
|
+
"version": "1.3.1",
|
|
10
7
|
"description": "",
|
|
11
8
|
"main": "build/main/index.js",
|
|
12
9
|
"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:release": "vrp-publish",
|
|
18
|
-
"build": "bun run generate && bun build:main && bun build:module",
|
|
19
|
-
"build:main": "tsc -b tsconfig.main.json",
|
|
20
|
-
"build:module": "tsc -b tsconfig.esm.json",
|
|
21
|
-
"dev": "NODE_ENV=generator bun --watch ./generate.ts",
|
|
22
|
-
"generate": "bun generate:schema && bun generate:client",
|
|
23
|
-
"generate:schema": "bun run --cwd ../../api generate",
|
|
24
|
-
"generate:client": "bunx --bun openapi-typescript ../../api/openapi.json -o ./src/generated/v1.ts",
|
|
25
|
-
"typecheck": "tsc --noEmit",
|
|
26
|
-
"tsgo": "tsgo --noEmit"
|
|
27
|
-
},
|
|
28
10
|
"author": "",
|
|
29
11
|
"license": "ISC",
|
|
30
12
|
"dependencies": {
|
|
@@ -39,8 +21,7 @@
|
|
|
39
21
|
"devDependencies": {
|
|
40
22
|
"@vrplatform/kysely": "*",
|
|
41
23
|
"@vrplatform/repository": "*",
|
|
42
|
-
"@vrplatform/common": "*"
|
|
43
|
-
"@vrplatform/bin": "*"
|
|
24
|
+
"@vrplatform/common": "*"
|
|
44
25
|
},
|
|
45
26
|
"files": [
|
|
46
27
|
"build/main",
|
|
@@ -49,5 +30,20 @@
|
|
|
49
30
|
"!**/*.spec.*",
|
|
50
31
|
"LICENSE"
|
|
51
32
|
],
|
|
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
|
+
},
|
|
52
48
|
"typings": "build/main/index.d.ts"
|
|
53
49
|
}
|