@syncmatters/script-api 1.0.0
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/LICENSE +21 -0
- package/README.md +37 -0
- package/api.d.ts +24 -0
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/lib/coded-error.d.ts +7 -0
- package/lib/connection.d.ts +597 -0
- package/lib/context.d.ts +58 -0
- package/lib/environment.d.ts +4 -0
- package/lib/logger.d.ts +20 -0
- package/lib/script-error.d.ts +38 -0
- package/lib/sync-group.d.ts +85 -0
- package/lib/sync.d.ts +392 -0
- package/lib/utilities/csv-reader/csv-reader-csv-parse.d.ts +16 -0
- package/lib/utilities/csv-reader/csv-reader-fast-csv.d.ts +15 -0
- package/lib/utilities/csv-reader/csv-reader.d.ts +2 -0
- package/lib/utilities/csv-reader/index.d.ts +2 -0
- package/lib/utilities/csv-reader/types.d.ts +48 -0
- package/lib/utilities/csv-writer/csv-writer.d.ts +21 -0
- package/lib/utilities/date-utils/date-utils.d.ts +37 -0
- package/lib/utilities/file-provider/file-provider-buffer.d.ts +11 -0
- package/lib/utilities/file-provider/file-provider-disk.d.ts +12 -0
- package/lib/utilities/file-provider/file-provider-string.d.ts +11 -0
- package/lib/utilities/file-provider/file-provider.d.ts +21 -0
- package/lib/utilities/file-utils/file-utils.d.ts +8 -0
- package/lib/utilities/html-utils/html-utils.d.ts +1 -0
- package/lib/utilities/http-client/fetch-http-client.d.ts +7 -0
- package/lib/utilities/http-client/fetch-http-error.d.ts +14 -0
- package/lib/utilities/http-client/types.d.ts +62 -0
- package/lib/utilities/json-utils/index.d.ts +6 -0
- package/lib/utilities/json-utils/json-changed-checker.d.ts +15 -0
- package/lib/utilities/json-utils/json-hash.d.ts +4 -0
- package/lib/utilities/json-utils/json-values-reader.d.ts +13 -0
- package/lib/utilities/json-utils/json-values-types.d.ts +41 -0
- package/lib/utilities/json-utils/json-values-writer.d.ts +28 -0
- package/lib/utilities/json-utils/lossless-numbers.d.ts +6 -0
- package/lib/utilities/json-utils/paths.d.ts +8 -0
- package/lib/utilities/kv-store/better-sqlite3/kv-collection-better-sqlite3.d.ts +18 -0
- package/lib/utilities/kv-store/better-sqlite3/kv-iterator-better-sqlite3.d.ts +26 -0
- package/lib/utilities/kv-store/better-sqlite3/kv-store-better-sqlite3.d.ts +11 -0
- package/lib/utilities/kv-store/index.d.ts +4 -0
- package/lib/utilities/kv-store/kv-store-benchmark-helpers.d.ts +14 -0
- package/lib/utilities/kv-store/shadow/kv-store-shadow.d.ts +29 -0
- package/lib/utilities/kv-store/sqlite3/database-sqlite3.d.ts +16 -0
- package/lib/utilities/kv-store/sqlite3/kv-collection-sqlite3.d.ts +18 -0
- package/lib/utilities/kv-store/sqlite3/kv-iterator-sqlite3.d.ts +21 -0
- package/lib/utilities/kv-store/sqlite3/kv-store-sqlite3.d.ts +11 -0
- package/lib/utilities/kv-store/sqlite3/statement-sqlite3.d.ts +13 -0
- package/lib/utilities/kv-store/types.d.ts +20 -0
- package/lib/utilities/name-parser/name-parser.d.ts +6 -0
- package/lib/utilities/rate-limiter/rate-limiter-concurrent.d.ts +24 -0
- package/lib/utilities/rate-limiter/rate-limiter-rolling.d.ts +18 -0
- package/lib/utilities/rate-limiter/rate-limiter.d.ts +15 -0
- package/lib/utilities/type-utils/type-utils.d.ts +11 -0
- package/lib/utilities/upsert-flags/upsert-flags.d.ts +10 -0
- package/lib/utilities/utilities.d.ts +105 -0
- package/lib/utilities/www-utils/www-utils.d.ts +14 -0
- package/lib/utilities/xlsx-reader/xlsx-reader.d.ts +32 -0
- package/lib/utilities/xlsx-writer/xlsx-writer.d.ts +23 -0
- package/lib/utilities/xml-utils/xml-utils.d.ts +1 -0
- package/lib/utilities/zip-utils/zip-utils.d.ts +29 -0
- package/package.json +23 -0
- package/sdk-test/sdk-test.d.ts +451 -0
- package/sdk-test.d.ts +3 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import API from "../index.js";
|
|
2
|
+
import { CodedError } from "./coded-error.js";
|
|
3
|
+
import { FileProvider } from "./utilities/file-provider/file-provider.js";
|
|
4
|
+
import { SyncEndpoint, SyncSession } from "./sync.js";
|
|
5
|
+
export interface Connection {
|
|
6
|
+
/** org unique connection id */
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly cache: Cache;
|
|
9
|
+
readonly base?: any;
|
|
10
|
+
readonly identity?: string;
|
|
11
|
+
readonly version?: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
meta: {
|
|
14
|
+
objects: {
|
|
15
|
+
[id: string]: () => Promise<ObjectMeta>;
|
|
16
|
+
};
|
|
17
|
+
events: {
|
|
18
|
+
[id: string]: () => Promise<EventTypeMeta>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
query: {
|
|
22
|
+
[id: string]: (options?: QueryOptions) => QueryIterator<Row>;
|
|
23
|
+
};
|
|
24
|
+
queryOne: {
|
|
25
|
+
[id: string]: (options?: QueryOneOptions) => Promise<Row | undefined>;
|
|
26
|
+
};
|
|
27
|
+
upsert?: {
|
|
28
|
+
[id: string]: (rows: any[]) => Promise<Row[]>;
|
|
29
|
+
};
|
|
30
|
+
upsertClean?: {
|
|
31
|
+
[id: string]: (options: UpsertCleanOptions) => Promise<UpsertCleanResponse>;
|
|
32
|
+
};
|
|
33
|
+
delete?: {
|
|
34
|
+
[id: string]: (rows: any[]) => Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
/** Id's of all objects found on this connection. */
|
|
37
|
+
objectIds: string[];
|
|
38
|
+
/** Connect to the source, validating credentials etc ... */
|
|
39
|
+
test(): Promise<TestResult>;
|
|
40
|
+
/** Retrieves the latest meta data (identity, object, field definitions, event types) from the connector. */
|
|
41
|
+
metaRefresh?(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates/updates the meta data model of a connection. This method is only applicable to connectors with
|
|
44
|
+
* data models that are managed by platform or user logic rather than through interrogation of the source application.
|
|
45
|
+
* @param options hold the updated item specification
|
|
46
|
+
* @param options.objects holds the updated object specifications
|
|
47
|
+
* @param options.objectSettingsValues [optional] holds the updated object settings
|
|
48
|
+
*/
|
|
49
|
+
metaUpsert?(options: {
|
|
50
|
+
objects?: ObjectMetaUpsert[];
|
|
51
|
+
objectSettingsValues?: ObjectSettingsValuesUpsert[];
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Requests that cached meta data (and data) for the object/event types be deleted.
|
|
55
|
+
* <p>
|
|
56
|
+
* Note: This function does not delete data/object definitions from from the underlying connector.
|
|
57
|
+
* If the meta data is acquired from a remote system then this meta data will be re-created on next
|
|
58
|
+
* metaRefresh() call. This function may be used when shaping connections that have hand (or script)
|
|
59
|
+
* managed data models.
|
|
60
|
+
* </p>
|
|
61
|
+
* @param options holds the unique identifiers of the items to be deleted from the cache (blank means clear all).
|
|
62
|
+
*/
|
|
63
|
+
metaDelete?(options?: {
|
|
64
|
+
objectIds?: string[];
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Requests the connection prepares for a session that will interact with sync(s)
|
|
68
|
+
* @param options session specification.
|
|
69
|
+
*/
|
|
70
|
+
syncSession?(options: SyncSession): Promise<SyncEndpoint>;
|
|
71
|
+
}
|
|
72
|
+
export interface Cache {
|
|
73
|
+
count: {
|
|
74
|
+
[id: string]: () => Promise<number>;
|
|
75
|
+
};
|
|
76
|
+
query: {
|
|
77
|
+
[id: string]: (options?: CacheQueryOptions) => AsyncIterableIterator<CacheRow>;
|
|
78
|
+
};
|
|
79
|
+
queryOne: {
|
|
80
|
+
[id: string]: (options?: CacheQueryOneOptions) => Promise<CacheRow | undefined>;
|
|
81
|
+
};
|
|
82
|
+
upsert: {
|
|
83
|
+
[id: string]: (page: CacheUpsertPage) => Promise<void>;
|
|
84
|
+
};
|
|
85
|
+
delete: {
|
|
86
|
+
[id: string]: (options?: {
|
|
87
|
+
keys?: string[];
|
|
88
|
+
}) => Promise<void>;
|
|
89
|
+
};
|
|
90
|
+
refresh: {
|
|
91
|
+
[id: string]: (options?: {
|
|
92
|
+
forceFull?: boolean;
|
|
93
|
+
}) => Promise<void>;
|
|
94
|
+
};
|
|
95
|
+
lastRefresh: {
|
|
96
|
+
[id: string]: () => Promise<Date | undefined>;
|
|
97
|
+
};
|
|
98
|
+
bulkRefresh(options: CacheRefreshOptions): Promise<void>;
|
|
99
|
+
bulkCount(options: {
|
|
100
|
+
ids: string[];
|
|
101
|
+
}): Promise<{
|
|
102
|
+
[id: string]: number;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
export interface CacheQueryOptions {
|
|
106
|
+
limit?: number;
|
|
107
|
+
rowFilter?: {
|
|
108
|
+
modifiedSince?: number;
|
|
109
|
+
index?: {
|
|
110
|
+
name: string;
|
|
111
|
+
values: string[];
|
|
112
|
+
};
|
|
113
|
+
keys?: string[];
|
|
114
|
+
};
|
|
115
|
+
propertyFilter?: {
|
|
116
|
+
metaOnly?: boolean;
|
|
117
|
+
noFile?: boolean;
|
|
118
|
+
properties?: {
|
|
119
|
+
name: string;
|
|
120
|
+
path: string[];
|
|
121
|
+
}[];
|
|
122
|
+
relationships?: string[];
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export interface CacheQueryOneOptions {
|
|
126
|
+
rowFilter?: {
|
|
127
|
+
modifiedSince?: number;
|
|
128
|
+
index?: {
|
|
129
|
+
name: string;
|
|
130
|
+
values: string[];
|
|
131
|
+
};
|
|
132
|
+
key?: string;
|
|
133
|
+
};
|
|
134
|
+
propertyFilter?: {
|
|
135
|
+
metaOnly?: boolean;
|
|
136
|
+
noFile?: boolean;
|
|
137
|
+
properties?: {
|
|
138
|
+
name: string;
|
|
139
|
+
path: string[];
|
|
140
|
+
}[];
|
|
141
|
+
relationships?: string[];
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export interface CacheUpsertPage {
|
|
145
|
+
rows?: CacheUpsertRow[];
|
|
146
|
+
state?: any;
|
|
147
|
+
lastRefresh?: Date;
|
|
148
|
+
}
|
|
149
|
+
export interface CacheRow {
|
|
150
|
+
meta: {
|
|
151
|
+
key: string;
|
|
152
|
+
hasFile?: boolean;
|
|
153
|
+
sequence?: number;
|
|
154
|
+
created: number;
|
|
155
|
+
modified: number;
|
|
156
|
+
};
|
|
157
|
+
data: object;
|
|
158
|
+
file?: FileProvider | null | undefined;
|
|
159
|
+
}
|
|
160
|
+
export interface CacheUpsertRow {
|
|
161
|
+
meta: {
|
|
162
|
+
key: string;
|
|
163
|
+
};
|
|
164
|
+
data?: any;
|
|
165
|
+
file?: FileProvider | null | undefined;
|
|
166
|
+
}
|
|
167
|
+
export interface CacheRefreshOptions {
|
|
168
|
+
objects: [
|
|
169
|
+
{
|
|
170
|
+
id: string;
|
|
171
|
+
forceFull?: boolean;
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
/** TestResult is the reponse to a test() call */
|
|
176
|
+
export interface TestResult {
|
|
177
|
+
success: boolean;
|
|
178
|
+
message?: string;
|
|
179
|
+
error?: CodedError;
|
|
180
|
+
}
|
|
181
|
+
/** QueryOptions holds filter options passed to a connection when querying data. */
|
|
182
|
+
export interface QueryOptions {
|
|
183
|
+
/** limit the number of rows returned */
|
|
184
|
+
limit?: number;
|
|
185
|
+
/** include any file associated with each row? */
|
|
186
|
+
file?: boolean;
|
|
187
|
+
/** fields expected in the response */
|
|
188
|
+
fields?: Array<Array<API.JsonValuePathPart>>;
|
|
189
|
+
/** include fields needed to collect rows from selected relationships */
|
|
190
|
+
relationshipFields?: Array<string>;
|
|
191
|
+
/** retrieve a random sample of up to 'limit' records */
|
|
192
|
+
randomFilter?: boolean;
|
|
193
|
+
/** filter for rows by row id (key) */
|
|
194
|
+
idsFilter?: Array<string>;
|
|
195
|
+
/** filter for rows that relate to another object on this connection */
|
|
196
|
+
relatedFilter?: QueryRelatedFilter;
|
|
197
|
+
/** filter for rows that meet a specific matching rule */
|
|
198
|
+
matchFilter?: QueryMatchFilter;
|
|
199
|
+
/** collect records changed since a particular checkpoint */
|
|
200
|
+
checkpointFilter?: QueryCheckpointFilter;
|
|
201
|
+
/** row filter & property filter are system-specific and may support non-standard filters */
|
|
202
|
+
rowFilter?: any;
|
|
203
|
+
propertyFilter?: any;
|
|
204
|
+
}
|
|
205
|
+
export type RowMatchRuleType = "id" /** match by source row id (key) */ | "name[ci]" /** match by destination row name (case senstive) */ | "email[ci]" /** match by destination row email (case insenstive) */ | "domain[ci]" /** match by destination domain (case insenstive) */ | "first_and_last_name[ci]" /** match by destination first and last name (case insenstive) */ | "field_value_equals[ci]"; /** match by value in user selected field (case insenstive) */
|
|
206
|
+
export type RowMatchRuleOrder = "oldest" | "newest" | "alphabetical";
|
|
207
|
+
/** source row data used by the destination connector when matching a source row to a destination row */
|
|
208
|
+
export interface RowMatchData {
|
|
209
|
+
/** id of the source row we are trying to match to a destination row (used to correlate matches) */
|
|
210
|
+
srcRowId: string;
|
|
211
|
+
/** rule-specific values to test for when matching a source to to a related row */
|
|
212
|
+
match: {
|
|
213
|
+
/** destination system record id (key) to match */
|
|
214
|
+
id?: string;
|
|
215
|
+
/** name value to match */
|
|
216
|
+
name?: string;
|
|
217
|
+
/** email value to match */
|
|
218
|
+
email?: string;
|
|
219
|
+
/** domain value to match */
|
|
220
|
+
domain?: string;
|
|
221
|
+
/** first name value to match */
|
|
222
|
+
firstname?: string;
|
|
223
|
+
/** last name value to match */
|
|
224
|
+
lastname?: string;
|
|
225
|
+
/** custom value to match */
|
|
226
|
+
custom?: string | number;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** unique ids (property names) used in the row match data passed to the destination when a match is saught */
|
|
230
|
+
export type RowMatchValueUid = "id" /** value relates to source row id (key) */ | "name" /** value relates to destination row name */ | "email" /** value relates to destination row email */ | "domain" /** value relates to destination domain */ | "firstname" /** value relates to destination first name */ | "lastname" /** value relates to destination last name */ | "custom"; /** value relates to user selected destination field */
|
|
231
|
+
/** QueryOneOptions holds connector specific options passed to a query. */
|
|
232
|
+
export interface QueryOneOptions {
|
|
233
|
+
/** include any file associated with each row? */
|
|
234
|
+
file?: boolean;
|
|
235
|
+
/** fields expected in the response */
|
|
236
|
+
fields?: Array<Array<API.JsonValuePathPart>>;
|
|
237
|
+
/** include fields needed to collect rows from selected relationships */
|
|
238
|
+
relationshipFields?: Array<string>;
|
|
239
|
+
/** filter for rows by row id (key) */
|
|
240
|
+
idsFilter?: Array<string>;
|
|
241
|
+
/** filter for rows that relate to another object on this connection */
|
|
242
|
+
relatedFilter?: QueryRelatedFilter;
|
|
243
|
+
/** filter for rows that meet a specific matching rule */
|
|
244
|
+
matchFilter?: QueryMatchFilter;
|
|
245
|
+
/** row filter & property filter are system-specific and may support non-standard filters */
|
|
246
|
+
rowFilter?: any;
|
|
247
|
+
propertyFilter?: any;
|
|
248
|
+
}
|
|
249
|
+
/** Row is a record returned in response to a query. */
|
|
250
|
+
export interface Row {
|
|
251
|
+
/** meta holds row metadata */
|
|
252
|
+
meta: {
|
|
253
|
+
/** unique identifier for the row on the object */
|
|
254
|
+
key: string;
|
|
255
|
+
/** indication that the row has been deleted from the object */
|
|
256
|
+
deleted?: boolean;
|
|
257
|
+
/** keys that have previously been assigned to this row (e.g. merged) */
|
|
258
|
+
previousKeys?: Array<string>;
|
|
259
|
+
/** URL users can click to view the row in the business system UI (if available) */
|
|
260
|
+
url?: string;
|
|
261
|
+
};
|
|
262
|
+
/** data is the row contents */
|
|
263
|
+
data?: any;
|
|
264
|
+
/** if filters requested files be included in the response, and the if row includes a file, the file will be here */
|
|
265
|
+
file?: FileProvider | null | undefined;
|
|
266
|
+
/** if filters requested rows filter by 'related', or 'matched' to source rows the relationship details will be here */
|
|
267
|
+
relationship?: {
|
|
268
|
+
relationshipId?: string;
|
|
269
|
+
srcObjectId?: string;
|
|
270
|
+
srcRowId: string;
|
|
271
|
+
};
|
|
272
|
+
/** if filters requested rows be returned from a 'checkpoint', the final row in the stream will return the next checkpoint here */
|
|
273
|
+
checkpoint?: string | undefined;
|
|
274
|
+
}
|
|
275
|
+
/** Iterator is returned in response to Query() operations */
|
|
276
|
+
export interface QueryIterator<T> extends AsyncIterableIterator<T> {
|
|
277
|
+
/** Checkpoint filters allow retrieval of the next checkpoint once all rows are collected */
|
|
278
|
+
nextCheckpoint?(): Promise<string | undefined>;
|
|
279
|
+
}
|
|
280
|
+
/** QueryRelatedFilter holds filters to apply when querying rows from this object that relate to rows from another object. */
|
|
281
|
+
export interface QueryRelatedFilter {
|
|
282
|
+
/** id of the other object for which related rows from this object are saught */
|
|
283
|
+
otherObjectId: string;
|
|
284
|
+
/** unique id of the relationship defined on the other object that describes how other object rows relate to rows on this object */
|
|
285
|
+
otherRelationshipId: string;
|
|
286
|
+
/** rows from the other object for which related rows from this object are saught */
|
|
287
|
+
otherRows: Array<Row>;
|
|
288
|
+
}
|
|
289
|
+
/** QueryMatchFilter holds filters to apply when searching for matching rows. */
|
|
290
|
+
export interface QueryMatchFilter {
|
|
291
|
+
/** rule to use to match */
|
|
292
|
+
rule: RowMatchRuleType;
|
|
293
|
+
/** in the case of multiple matches, how should the "best" match be selected */
|
|
294
|
+
selectOrder?: RowMatchRuleOrder;
|
|
295
|
+
/** if the rule references a field in the destination row the path to the destination field will be specified here (e.g. match value in a specific field) */
|
|
296
|
+
destFieldPath?: Array<API.JsonValuePathPart>;
|
|
297
|
+
/** data to match */
|
|
298
|
+
srcData: Array<RowMatchData>;
|
|
299
|
+
/**
|
|
300
|
+
* once the connector has identified candidates for the src rows, call this with possible candidates to select an un-mapped candidate.
|
|
301
|
+
* it will return the selected candidates, populating 'row.relationship' with details of the src row the match relates to.
|
|
302
|
+
*/
|
|
303
|
+
canUse: (options: Array<{
|
|
304
|
+
srcRowId: string;
|
|
305
|
+
candidates: Array<Row>;
|
|
306
|
+
}>) => Promise<Array<Row>>;
|
|
307
|
+
}
|
|
308
|
+
/** QueryCheckpointFilter holds filters to apply when collecring rows changed since a prior checkpoint. */
|
|
309
|
+
export interface QueryCheckpointFilter {
|
|
310
|
+
/** checkpoint last returned by this connector when this query was run */
|
|
311
|
+
value?: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* EventTypeMeta is the definition of an event emitted by a connection.
|
|
315
|
+
*/
|
|
316
|
+
export interface EventTypeMeta {
|
|
317
|
+
id: string;
|
|
318
|
+
name?: string;
|
|
319
|
+
dataFields?: ObjectField[];
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* ObjectMeta defines the the features, user defined settings values & behavior of an object on a connection.
|
|
323
|
+
*
|
|
324
|
+
* Fields that must not be sent in `Connection.metaUpsert` payloads belong in {@link ObjectMetaUpsertExcludedKeys}
|
|
325
|
+
* so {@link ObjectMetaUpsert} stays aligned.
|
|
326
|
+
*/
|
|
327
|
+
export interface ObjectMeta {
|
|
328
|
+
id: string;
|
|
329
|
+
name?: string;
|
|
330
|
+
settingsMeta?: Record<string, ObjectSettingMeta>;
|
|
331
|
+
settingsValues?: Record<string, unknown>;
|
|
332
|
+
order?: string;
|
|
333
|
+
data?: any;
|
|
334
|
+
isCustom?: boolean;
|
|
335
|
+
queryFields?: ObjectField[];
|
|
336
|
+
queryFilter?: {
|
|
337
|
+
rowFilter?: ObjectRowFilter[];
|
|
338
|
+
propertyFilter?: ObjectField[];
|
|
339
|
+
};
|
|
340
|
+
queryFile?: boolean;
|
|
341
|
+
upsertFields?: ObjectField[];
|
|
342
|
+
deleteFields?: ObjectField[];
|
|
343
|
+
canQueryList?: boolean;
|
|
344
|
+
canQueryByCheckpoint?: boolean;
|
|
345
|
+
canQueryByIds?: boolean;
|
|
346
|
+
canQueryRandoms?: boolean;
|
|
347
|
+
canUpsertClean?: boolean;
|
|
348
|
+
canUpsertFieldOptions?: boolean;
|
|
349
|
+
canAddCustomRelationships?: boolean;
|
|
350
|
+
matchRules?: RowMatchRuleType[];
|
|
351
|
+
customIndexes?: ObjectIndex[];
|
|
352
|
+
systemIndexes?: ObjectIndex[];
|
|
353
|
+
/** relationships that may be used to find rows of this object that relate to other objects */
|
|
354
|
+
relationships?: ObjectRelationship[];
|
|
355
|
+
}
|
|
356
|
+
/** ObjectSettingMeta holds metadata describing a setting */
|
|
357
|
+
export interface ObjectSettingMeta {
|
|
358
|
+
i18nKey?: string;
|
|
359
|
+
order?: string;
|
|
360
|
+
name?: string;
|
|
361
|
+
groupId?: string;
|
|
362
|
+
description?: string;
|
|
363
|
+
placeholder?: string;
|
|
364
|
+
secret?: boolean;
|
|
365
|
+
hidden?: boolean;
|
|
366
|
+
advanced?: boolean;
|
|
367
|
+
readonly?: boolean;
|
|
368
|
+
mandatory?: boolean;
|
|
369
|
+
displayIf?: string;
|
|
370
|
+
displayIfSetting?: string;
|
|
371
|
+
displayIfValues?: string[];
|
|
372
|
+
type?: string;
|
|
373
|
+
control?: string;
|
|
374
|
+
options?: ObjectSettingMetaOption[];
|
|
375
|
+
default?: unknown;
|
|
376
|
+
constraints?: ObjectFieldConstraints;
|
|
377
|
+
}
|
|
378
|
+
/** ObjectSettingMetaOption holds a metadata option value */
|
|
379
|
+
export interface ObjectSettingMetaOption {
|
|
380
|
+
id: string;
|
|
381
|
+
name?: string;
|
|
382
|
+
order?: string;
|
|
383
|
+
}
|
|
384
|
+
export interface ObjectRowFilter {
|
|
385
|
+
/** unique identifier for the filter */
|
|
386
|
+
id: string;
|
|
387
|
+
/** data type of the json property value */
|
|
388
|
+
type: "string" | "number" | "boolean" | "object" | "array";
|
|
389
|
+
/** display label for the field */
|
|
390
|
+
name?: string;
|
|
391
|
+
/** for picklist fields, this holds the allowed options */
|
|
392
|
+
optionValues?: ObjectFieldOption[];
|
|
393
|
+
/** for object filters, these are the properties of the object */
|
|
394
|
+
objectFields?: ObjectRowFilter[];
|
|
395
|
+
/** for array filters, this is the type of each array element */
|
|
396
|
+
arrayType?: "string" | "number" | "boolean" | "object";
|
|
397
|
+
/** for array filters of type object, these are the properties of each array element */
|
|
398
|
+
arrayObjectFields?: ObjectRowFilter[];
|
|
399
|
+
/** 'data' may hold a small amount of info for connector-internal logic to reference */
|
|
400
|
+
data?: any;
|
|
401
|
+
/** identify where this filter can extend standard filters */
|
|
402
|
+
extends?: Array<{
|
|
403
|
+
type: "checkpoint" | "list" | "match";
|
|
404
|
+
mandatory?: boolean;
|
|
405
|
+
}>;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* {@link ObjectMeta} property names removed when building {@link ObjectMetaUpsert} / `Connection.metaUpsert`
|
|
409
|
+
* payloads. Append when adding read-only or client-only fields on {@link ObjectMeta}.
|
|
410
|
+
*/
|
|
411
|
+
export declare const OBJECT_META_UPSERT_EXCLUDED_KEYS: readonly ["customIndexes", "settingsValues"];
|
|
412
|
+
export type ObjectMetaUpsertExcludedKeys = (typeof OBJECT_META_UPSERT_EXCLUDED_KEYS)[number];
|
|
413
|
+
/**
|
|
414
|
+
* Structure used when a script modifies object definition via `Connection.metaUpsert` — {@link ObjectMeta}
|
|
415
|
+
* minus {@link ObjectMetaUpsertExcludedKeys}.
|
|
416
|
+
*/
|
|
417
|
+
export type ObjectMetaUpsert = Omit<ObjectMeta, ObjectMetaUpsertExcludedKeys>;
|
|
418
|
+
/** Structure used when a script modifies object settings values via `Connection.metaUpsert` */
|
|
419
|
+
export interface ObjectSettingsValuesUpsert {
|
|
420
|
+
/** id of the object whose settings values are to be updated */
|
|
421
|
+
id: string;
|
|
422
|
+
/** new settings values to replace ALL current settings, full replacement so all values must be provided */
|
|
423
|
+
values: Record<string, unknown>;
|
|
424
|
+
}
|
|
425
|
+
/** ObjectField holds a field definition. */
|
|
426
|
+
export interface ObjectField {
|
|
427
|
+
/** id of the property in the json response */
|
|
428
|
+
id: string;
|
|
429
|
+
/** data type of the json property value */
|
|
430
|
+
type: "any" | "string" | "number" | "boolean" | "object" | "file" | "array";
|
|
431
|
+
/** display label for the field */
|
|
432
|
+
name?: string;
|
|
433
|
+
/** field holds the row unique identifier, required for update operations */
|
|
434
|
+
isKey?: boolean;
|
|
435
|
+
/** field holds an object containing the user defined row unique identifier required for add an update operations, and an indication of the operation type */
|
|
436
|
+
isUserKey?: boolean;
|
|
437
|
+
/** field, and any fields below, are custom (account specific) */
|
|
438
|
+
isCustom?: boolean;
|
|
439
|
+
/** can this field be referenced in match rules? */
|
|
440
|
+
canMatch?: boolean;
|
|
441
|
+
/** for picklist fields, this holds the allowed options */
|
|
442
|
+
optionValues?: ObjectFieldOption[];
|
|
443
|
+
/** for picklist fields, can options be added/updated? */
|
|
444
|
+
canUpdateOptions?: boolean;
|
|
445
|
+
/** field constraints */
|
|
446
|
+
constraints?: ObjectFieldConstraints;
|
|
447
|
+
/** for object fields, these are the properties of the object */
|
|
448
|
+
objectFields?: ObjectField[];
|
|
449
|
+
/** for array fields, this is the type of each array element */
|
|
450
|
+
arrayType?: "any" | "string" | "number" | "boolean" | "object" | "file" | "array";
|
|
451
|
+
/** for array fields of type object, these are the properties of each array element */
|
|
452
|
+
arrayObjectFields?: ObjectField[];
|
|
453
|
+
/** for flat file objects this holds extra details applicable to the generic flat-file connector */
|
|
454
|
+
flatFile?: {
|
|
455
|
+
/** how are arrays serialized/deserialized? (default: delimited) */
|
|
456
|
+
arrayFormat?: "delimited" | "json";
|
|
457
|
+
/** delimiter used to separate array elements (default: comma) */
|
|
458
|
+
arrayDelimiter?: string;
|
|
459
|
+
/** indicates the field contains the last modified date/time used for checkpointing (expects ISO8601 format, override using a constraint) */
|
|
460
|
+
isLastModified?: boolean;
|
|
461
|
+
};
|
|
462
|
+
/** 'data' may hold a small amount of info for connector-internal logic to reference */
|
|
463
|
+
data?: any;
|
|
464
|
+
format?: string;
|
|
465
|
+
export?: boolean;
|
|
466
|
+
}
|
|
467
|
+
/** FieldType expresses the allowed types of fields. Not used in ObjectField as this improves intellisense */
|
|
468
|
+
export type FieldType = "any" | "string" | "number" | "boolean" | "object" | "file" | "array";
|
|
469
|
+
/** RowFilterType expresses the allowed types of filters. Not used in ObjectField as this improves intellisense */
|
|
470
|
+
export type RowFilterType = "string" | "number" | "boolean" | "object";
|
|
471
|
+
/**
|
|
472
|
+
* ObjectFieldOption holds details of a valid option value for a field (e.g. useful for validating user input)
|
|
473
|
+
* on a object
|
|
474
|
+
*/
|
|
475
|
+
export interface ObjectFieldOption {
|
|
476
|
+
id: string;
|
|
477
|
+
name?: string;
|
|
478
|
+
group?: string;
|
|
479
|
+
}
|
|
480
|
+
/** ObjectFieldConstraints holds details of expected/allowed values for a field. */
|
|
481
|
+
export interface ObjectFieldConstraints {
|
|
482
|
+
mandatory?: "always" | "add" | "update";
|
|
483
|
+
mandatoryAccepts?: Array<"null" | "blank_string">;
|
|
484
|
+
max?: number;
|
|
485
|
+
min?: number;
|
|
486
|
+
maxLen?: number;
|
|
487
|
+
minLen?: number;
|
|
488
|
+
trim?: boolean;
|
|
489
|
+
dt?: {
|
|
490
|
+
format?: "unix" | "unix_ms" | "iso8601" | "yyyy-MM-dd" | "M/d/yyyy" | "dd/MM/yyyy" | "yyyy-MM-dd HH:mm:ss" | "custom";
|
|
491
|
+
pattern?: string;
|
|
492
|
+
rangeYears?: number;
|
|
493
|
+
future?: boolean;
|
|
494
|
+
past?: boolean;
|
|
495
|
+
weekday?: boolean;
|
|
496
|
+
from?: string;
|
|
497
|
+
to?: string;
|
|
498
|
+
};
|
|
499
|
+
integer?: boolean;
|
|
500
|
+
decimals?: number;
|
|
501
|
+
regex?: string;
|
|
502
|
+
email?: boolean;
|
|
503
|
+
}
|
|
504
|
+
/** UpsertFieldOptionMeta is metadata describing a field 'option' value. */
|
|
505
|
+
export interface UpsertFieldOptionMeta {
|
|
506
|
+
name?: string;
|
|
507
|
+
order?: string;
|
|
508
|
+
pipeline?: string;
|
|
509
|
+
probability?: string;
|
|
510
|
+
}
|
|
511
|
+
/** UpsertCleanOptions holds the upsert record and options to control the process. */
|
|
512
|
+
export interface UpsertCleanOptions {
|
|
513
|
+
/** upsert row to be be cleaned & upserted (blank means send all pending rows) */
|
|
514
|
+
upsert?: any;
|
|
515
|
+
/** current row in query response format (used to detect whether the row contains any changes) */
|
|
516
|
+
current?: API.Row;
|
|
517
|
+
/** the number of rows to collect into a batch before performing the upsert (default is 1)*/
|
|
518
|
+
batchSize?: number;
|
|
519
|
+
optionFields?: {
|
|
520
|
+
/** selected option fields will have their metadata (available options) adjusted when new/changed values are found in the upsert row */
|
|
521
|
+
fixSelected: Array<string[]>;
|
|
522
|
+
/** this optional function can provide other metadata that may be required when creating/updating the given option id in the field (e.g. the name/display label for the id) */
|
|
523
|
+
meta?: (fieldPath: string[], id: string) => UpsertFieldOptionMeta;
|
|
524
|
+
};
|
|
525
|
+
issues?: {
|
|
526
|
+
/** upsert field to populate with details of issues found during the clean process */
|
|
527
|
+
field?: {
|
|
528
|
+
path?: string[];
|
|
529
|
+
jsonPath?: string;
|
|
530
|
+
};
|
|
531
|
+
/** details of issues that were cleansed (resolved) by external logic prior to calling upsertClean */
|
|
532
|
+
external?: UpsertIssue[];
|
|
533
|
+
/** seperator to place between each issue (default: "; ") */
|
|
534
|
+
seperator?: string;
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/** UpsertCleanResponse is returned from the upsertClean function. */
|
|
538
|
+
export interface UpsertCleanResponse {
|
|
539
|
+
/** indicates that changes were detected (ie. the row needed to be upserted) */
|
|
540
|
+
hasChanges: boolean;
|
|
541
|
+
/** indicates that the row cannot be upserted due to a fatal issue */
|
|
542
|
+
hasFatalIssues: boolean;
|
|
543
|
+
/** summary of the first change identified */
|
|
544
|
+
change?: {
|
|
545
|
+
field: string;
|
|
546
|
+
oldValue?: string;
|
|
547
|
+
newValue?: string;
|
|
548
|
+
};
|
|
549
|
+
/** details of issues (includes any issues that were 'cleansed' to resolve) */
|
|
550
|
+
issues: UpsertIssue[];
|
|
551
|
+
/** row(s) returned from the batched upsert requests */
|
|
552
|
+
rows?: API.Row[];
|
|
553
|
+
}
|
|
554
|
+
/** UpsertIssue has details of an issue found within an upsert request. */
|
|
555
|
+
export interface UpsertIssue {
|
|
556
|
+
/** type of issue */
|
|
557
|
+
type: UpsertIssueType;
|
|
558
|
+
/** fatal issues block the row from being written to the destination */
|
|
559
|
+
fatal?: boolean;
|
|
560
|
+
/** path to the field that caused the issue */
|
|
561
|
+
fieldPath?: string[];
|
|
562
|
+
/** value that caused the issue */
|
|
563
|
+
value?: any;
|
|
564
|
+
/** option that caused the issue */
|
|
565
|
+
option?: {
|
|
566
|
+
id: string;
|
|
567
|
+
meta?: UpsertFieldOptionMeta;
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
/** UpsertIssueType is the type of issue found in an upsert request. */
|
|
571
|
+
export type UpsertIssueType = "External" | "RowCleanFailed" | "OptionNotFound" | "OptionNameUpdateRequired" | "OptionNameUpdateConflict" | "ValueRequired" | "AboveMax" | "BelowMin" | "DateTimeFormat" | "WeekdayExpected" | "Trimmed" | "IntegerExpected" | "DecimalRounded" | "NotNumber" | "Regex" | "EmailInvalid" | "EmailConflict" | "ValueInvalid" | "MaxLength" | "MinLength";
|
|
572
|
+
/** Specification of the relationship from one object to another. */
|
|
573
|
+
export interface ObjectRelationship {
|
|
574
|
+
/** id for the relationship to the other object (must be unique on this object) */
|
|
575
|
+
id: string;
|
|
576
|
+
/** display label for the relationship (defaults to the id) */
|
|
577
|
+
name?: string;
|
|
578
|
+
/** object id of the other object that has a relationship to this object */
|
|
579
|
+
relObjectId: string;
|
|
580
|
+
/** maximum number of related rows on that may be returned when this relation is queried for a given row on this object */
|
|
581
|
+
cardinality: "OneToOne" | "OneToMany";
|
|
582
|
+
/** if the relationship is a foreign key, path to the field that holds the key (see fkPathOn for which object) */
|
|
583
|
+
fkPath?: Array<API.JsonValuePathPart>;
|
|
584
|
+
/** where fkPath is evaluated: this (default) = source object; related = relObjectId object */
|
|
585
|
+
fkPathOn?: "this" | "related";
|
|
586
|
+
/** connector may store extra info here */
|
|
587
|
+
data?: any;
|
|
588
|
+
}
|
|
589
|
+
/** IndexType holds a data index definition */
|
|
590
|
+
export type IndexType = "unknown" | "jsonpath expression";
|
|
591
|
+
/** ObjectIndex specifies an index to be added to cached connector data. */
|
|
592
|
+
export interface ObjectIndex {
|
|
593
|
+
name: string;
|
|
594
|
+
type: IndexType;
|
|
595
|
+
path?: string[];
|
|
596
|
+
pattern?: string;
|
|
597
|
+
}
|
package/lib/context.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Connection } from "./connection.js";
|
|
2
|
+
import { SyncGroup } from "./sync-group.js";
|
|
3
|
+
import { Logger } from "./logger.js";
|
|
4
|
+
import { FileProvider } from "./utilities/file-provider/file-provider.js";
|
|
5
|
+
/** Context is passed to the script to provide access to system services such as logging, connections, state and environment information */
|
|
6
|
+
export interface Context {
|
|
7
|
+
log: Logger;
|
|
8
|
+
parameters: {
|
|
9
|
+
[name: string]: any;
|
|
10
|
+
};
|
|
11
|
+
connections: {
|
|
12
|
+
[name: string]: () => Promise<Connection>;
|
|
13
|
+
};
|
|
14
|
+
syncGroups: {
|
|
15
|
+
[name: string]: () => Promise<SyncGroup>;
|
|
16
|
+
};
|
|
17
|
+
state: {
|
|
18
|
+
get(): Promise<any>;
|
|
19
|
+
set(state: any): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
feedback(options: {
|
|
22
|
+
percent: number;
|
|
23
|
+
code: string;
|
|
24
|
+
args?: string[];
|
|
25
|
+
}): void;
|
|
26
|
+
sendEmail(options: {
|
|
27
|
+
to: string[];
|
|
28
|
+
subject: string;
|
|
29
|
+
bodyHtml: string;
|
|
30
|
+
attachments?: Array<{
|
|
31
|
+
name: string;
|
|
32
|
+
file: FileProvider;
|
|
33
|
+
}>;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
account: {
|
|
36
|
+
executions: {
|
|
37
|
+
list: (options: {
|
|
38
|
+
startTimeFrom?: Date;
|
|
39
|
+
startTimeTo?: Date;
|
|
40
|
+
minimumDurationSec?: number;
|
|
41
|
+
}) => AsyncIterableIterator<Execution>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
environment: {
|
|
45
|
+
engineUid: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface Execution {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
complete: boolean;
|
|
52
|
+
startTime?: string;
|
|
53
|
+
durationSec?: number;
|
|
54
|
+
success?: boolean;
|
|
55
|
+
result?: any;
|
|
56
|
+
errorMessage?: string;
|
|
57
|
+
exitCode?: string;
|
|
58
|
+
}
|
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
info(message: string, props?: unknown): void;
|
|
3
|
+
error(message: string | Error, props?: unknown): void;
|
|
4
|
+
context(): EventContext;
|
|
5
|
+
}
|
|
6
|
+
export interface EventContext {
|
|
7
|
+
scriptId?: string;
|
|
8
|
+
groupId?: string;
|
|
9
|
+
syncId?: string;
|
|
10
|
+
connectionId?: string;
|
|
11
|
+
objectId?: string;
|
|
12
|
+
rowKey?: string;
|
|
13
|
+
groupUID?: string;
|
|
14
|
+
syncUID?: string;
|
|
15
|
+
childSyncUID?: string;
|
|
16
|
+
syncProgressUID?: string;
|
|
17
|
+
queryUID?: string;
|
|
18
|
+
upsertUID?: string;
|
|
19
|
+
deleteUID?: string;
|
|
20
|
+
}
|