@raytio/core 11.2.0 → 11.3.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/CHANGELOG.md +4 -0
- package/README.md +119 -30
- package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.js +28 -0
- package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.js +23 -0
- package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.js +27 -0
- package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.js +30 -0
- package/dist/accessApplication/api/fetchKeysForSubmission.d.ts +12 -0
- package/dist/accessApplication/api/fetchKeysForSubmission.js +16 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.js +25 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.js +10 -0
- package/dist/accessApplication/api/getMissingDataForInstance.d.ts +10 -0
- package/dist/accessApplication/api/getMissingDataForInstance.js +28 -0
- package/dist/accessApplication/api/index.d.ts +2 -0
- package/dist/accessApplication/api/index.js +18 -0
- package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.d.ts +1 -0
- package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.js +37 -0
- package/dist/accessApplication/api/legacy/convertRelationships.d.ts +16 -0
- package/dist/accessApplication/api/legacy/convertRelationships.js +21 -0
- package/dist/accessApplication/api/legacy/index.d.ts +1 -0
- package/dist/accessApplication/api/legacy/index.js +17 -0
- package/dist/accessApplication/createAA.js +6 -5
- package/dist/accessApplication/index.d.ts +1 -0
- package/dist/accessApplication/index.js +1 -0
- package/dist/crypto/cognitoAttributes.d.ts +1 -1
- package/dist/crypto/decryptSharedData.d.ts +2 -2
- package/dist/crypto/decryptSharedData.js +2 -5
- package/dist/crypto/getAADecryptor.d.ts +18 -3
- package/dist/crypto/getAADecryptor.js +10 -10
- package/dist/crypto/helpers.d.ts +2 -2
- package/dist/general/types.d.ts +9 -0
- package/dist/general/types.js +10 -1
- package/dist/rules/calculateScore.d.ts +1 -1
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +5 -2
- package/dist/rules/evaluateScoreCondition.d.ts +1 -1
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +1 -1
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +1 -1
- package/dist/rules/helpers/checkTypeofValue.d.ts +1 -1
- package/dist/rules/helpers/getValuesFromPath.d.ts +1 -1
- package/dist/rules/helpers/thresholds.d.ts +1 -1
- package/dist/rules/operators/bool.d.ts +1 -1
- package/dist/rules/operators/date.d.ts +1 -1
- package/dist/rules/operators/hfield.d.ts +1 -1
- package/dist/rules/operators/hschema.d.ts +1 -1
- package/dist/rules/operators/index.d.ts +1 -1
- package/dist/rules/operators/number.d.ts +1 -1
- package/dist/rules/operators/string.d.ts +1 -1
- package/dist/rules/types/config.d.ts +4 -3
- package/dist/rules/types/dataValueTypes.d.ts +2 -3
- package/dist/rules/types/internal.d.ts +4 -3
- package/dist/rules/validate.d.ts +2 -2
- package/dist/schema/expandSchema/__tests__/expandSchema.test.js +2 -2
- package/dist/schema/expandSchema/__tests__/i18n.test.js +1 -1
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +2 -2
- package/dist/schema/expandSchema/__tests__/processSchema.test.js +2 -2
- package/dist/schema/expandSchema/addLoadingTimes.d.ts +1 -1
- package/dist/schema/expandSchema/constants.d.ts +1 -1
- package/dist/schema/expandSchema/expandSchema.d.ts +1 -1
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +1 -1
- package/dist/schema/expandSchema/processSchema.d.ts +1 -1
- package/dist/schema/expandSchema/removePrivateFields.d.ts +5 -5
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +3 -3
- package/dist/schema/expandSchema/unwrapSchema.d.ts +2 -6
- package/dist/schema/labels.d.ts +2 -1
- package/dist/testHelpers.d.ts +2 -2
- package/dist/verifications/cleanInstance.d.ts +1 -1
- package/dist/verifications/getPOVerification.d.ts +1 -1
- package/dist/verifications/index.d.ts +0 -1
- package/dist/verifications/index.js +0 -1
- package/dist/verifications/safeHarbour.d.ts +2 -2
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +3 -3
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +2 -2
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +1 -1
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +1 -1
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +2 -2
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +2 -0
- package/package.json +6 -42
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
20
20
|
|
|
21
21
|
- [SafeHarbourObj](#safeharbourobj)
|
|
22
22
|
- [SafeHarbourResult](#safeharbourresult)
|
|
23
|
+
- [ServerRelationship](#serverrelationship)
|
|
23
24
|
- [VerDetails](#verdetails)
|
|
24
25
|
|
|
25
26
|
### Functions
|
|
@@ -27,9 +28,10 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
27
28
|
- [calcSafeHarbourScore](#calcsafeharbourscore)
|
|
28
29
|
- [calculateScore](#calculatescore)
|
|
29
30
|
- [checkJsonSignature](#checkjsonsignature)
|
|
30
|
-
- [cleanInstance](#cleaninstance)
|
|
31
31
|
- [convertInstanceToRuleInput](#convertinstancetoruleinput)
|
|
32
|
+
- [convertServerRelationship](#convertserverrelationship)
|
|
32
33
|
- [createAA](#createaa)
|
|
34
|
+
- [createHashedNId](#createhashednid)
|
|
33
35
|
- [decryptSharedData](#decryptshareddata)
|
|
34
36
|
- [evaluateRule](#evaluaterule)
|
|
35
37
|
- [expandSchema](#expandschema)
|
|
@@ -37,6 +39,8 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
37
39
|
- [findSuitableLocale](#findsuitablelocale)
|
|
38
40
|
- [fromCognitoAttributes](#fromcognitoattributes)
|
|
39
41
|
- [getAADecryptor](#getaadecryptor)
|
|
42
|
+
- [getAAPublicKey](#getaapublickey)
|
|
43
|
+
- [getMissingDataForInstance](#getmissingdataforinstance)
|
|
40
44
|
- [getNidFromUrn](#getnidfromurn)
|
|
41
45
|
- [getOwnRealVerifications](#getownrealverifications)
|
|
42
46
|
- [getPOVerification](#getpoverification)
|
|
@@ -77,6 +81,14 @@ the response from [calcSafeHarbourScore](#calcsafeharbourscore)
|
|
|
77
81
|
|
|
78
82
|
___
|
|
79
83
|
|
|
84
|
+
### ServerRelationship
|
|
85
|
+
|
|
86
|
+
Ƭ **ServerRelationship**: `Omit`<`Relationship`, ``"p_id"`` \| ``"start"`` \| ``"end"``\> & { `from_id`: `NId` ; `id`: `PId` } & { `to_id`: `NId` } \| { `to_i_id`: `IId` }
|
|
87
|
+
|
|
88
|
+
This type represents the relationship format returned by the Postgres API
|
|
89
|
+
|
|
90
|
+
___
|
|
91
|
+
|
|
80
92
|
### VerDetails
|
|
81
93
|
|
|
82
94
|
Ƭ **VerDetails**: `Object`
|
|
@@ -108,7 +120,7 @@ from different sources. For information, refer to the
|
|
|
108
120
|
| `data.person` | `ProfileObject` |
|
|
109
121
|
| `data.profileObjects` | `ProfileObject`[] |
|
|
110
122
|
| `data.realVers` | `RealVer`[] |
|
|
111
|
-
| `data.getSchema` | (`schemaName`: `
|
|
123
|
+
| `data.getSchema` | (`schemaName`: `SchemaName`) => `Promise`<`Schema`\> |
|
|
112
124
|
|
|
113
125
|
#### Returns
|
|
114
126
|
|
|
@@ -158,43 +170,41 @@ or `getSomeoneElsesRealVerifications` instead.
|
|
|
158
170
|
|
|
159
171
|
___
|
|
160
172
|
|
|
161
|
-
###
|
|
162
|
-
|
|
163
|
-
▸ **cleanInstance**(`instance`): `Instance`
|
|
164
|
-
|
|
165
|
-
The API response from share/v2/access_application/instance/:iId
|
|
166
|
-
returns a complicated hashed_n_id format, so you need to clean up
|
|
167
|
-
the API response using this function as soon as possible.
|
|
173
|
+
### convertInstanceToRuleInput
|
|
168
174
|
|
|
169
|
-
|
|
175
|
+
▸ **convertInstanceToRuleInput**(`POs`, `realVers`, `getSchema`): `Promise`<`RuleData`\>
|
|
170
176
|
|
|
171
177
|
#### Parameters
|
|
172
178
|
|
|
173
179
|
| Name | Type |
|
|
174
180
|
| :------ | :------ |
|
|
175
|
-
| `
|
|
181
|
+
| `POs` | `ProfileObject`[] |
|
|
182
|
+
| `realVers` | `RealVer`[] |
|
|
183
|
+
| `getSchema` | (`schemaName`: `SchemaName`) => `Promise`<`Schema`\> |
|
|
176
184
|
|
|
177
185
|
#### Returns
|
|
178
186
|
|
|
179
|
-
`
|
|
187
|
+
`Promise`<`RuleData`\>
|
|
180
188
|
|
|
181
189
|
___
|
|
182
190
|
|
|
183
|
-
###
|
|
191
|
+
### convertServerRelationship
|
|
184
192
|
|
|
185
|
-
▸ **
|
|
193
|
+
▸ **convertServerRelationship**(`serverRelationship`): `Relationship`
|
|
194
|
+
|
|
195
|
+
Converts relationship type used by the server into the (Urn format) type used by the client
|
|
186
196
|
|
|
187
197
|
#### Parameters
|
|
188
198
|
|
|
189
|
-
| Name | Type |
|
|
190
|
-
| :------ | :------ |
|
|
191
|
-
| `
|
|
192
|
-
| `realVers` | `RealVer`[] |
|
|
193
|
-
| `getSchema` | (`schemaName`: `string`) => `Promise`<`Schema`\> |
|
|
199
|
+
| Name | Type | Description |
|
|
200
|
+
| :------ | :------ | :------ |
|
|
201
|
+
| `serverRelationship` | [`ServerRelationship`](#serverrelationship) | relationship type used in the server |
|
|
194
202
|
|
|
195
203
|
#### Returns
|
|
196
204
|
|
|
197
|
-
`
|
|
205
|
+
`Relationship`
|
|
206
|
+
|
|
207
|
+
a Relationship (client-side type) that is equivalent to the inputted serverRelationship value
|
|
198
208
|
|
|
199
209
|
___
|
|
200
210
|
|
|
@@ -226,6 +236,29 @@ as well as the `userDoc` data which is stored in the user's cognito attributes.
|
|
|
226
236
|
|
|
227
237
|
___
|
|
228
238
|
|
|
239
|
+
### createHashedNId
|
|
240
|
+
|
|
241
|
+
▸ **createHashedNId**(`nId`, `aId`): `NId`
|
|
242
|
+
|
|
243
|
+
the API returns hashed NIds in a separate field,
|
|
244
|
+
which breaks the whole app. So, we move the hashed ID into
|
|
245
|
+
the normal `n_id` field, and use a different format.
|
|
246
|
+
|
|
247
|
+
This was first introduced in #1048
|
|
248
|
+
|
|
249
|
+
#### Parameters
|
|
250
|
+
|
|
251
|
+
| Name | Type |
|
|
252
|
+
| :------ | :------ |
|
|
253
|
+
| `nId` | `NId` |
|
|
254
|
+
| `aId` | `AId` |
|
|
255
|
+
|
|
256
|
+
#### Returns
|
|
257
|
+
|
|
258
|
+
`NId`
|
|
259
|
+
|
|
260
|
+
___
|
|
261
|
+
|
|
229
262
|
### decryptSharedData
|
|
230
263
|
|
|
231
264
|
▸ **decryptSharedData**(`«destructured»`): `Promise`<{ `applicationDecryptor`: `ApplicationDataEncryptorI` ; `instance`: `Instance` }\>
|
|
@@ -304,7 +337,7 @@ ___
|
|
|
304
337
|
|
|
305
338
|
### findSchemaLabel
|
|
306
339
|
|
|
307
|
-
▸ **findSchemaLabel**(`labels`): `undefined` \| `
|
|
340
|
+
▸ **findSchemaLabel**(`labels`): `undefined` \| `SchemaName`
|
|
308
341
|
|
|
309
342
|
Finds the label (on a profile object) which is the schema name
|
|
310
343
|
|
|
@@ -316,7 +349,7 @@ Finds the label (on a profile object) which is the schema name
|
|
|
316
349
|
|
|
317
350
|
#### Returns
|
|
318
351
|
|
|
319
|
-
`undefined` \| `
|
|
352
|
+
`undefined` \| `SchemaName`
|
|
320
353
|
|
|
321
354
|
___
|
|
322
355
|
|
|
@@ -361,7 +394,7 @@ ___
|
|
|
361
394
|
|
|
362
395
|
### getAADecryptor
|
|
363
396
|
|
|
364
|
-
▸ **getAADecryptor**(`«destructured»`): `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `
|
|
397
|
+
▸ **getAADecryptor**(`«destructured»`): `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyId`: `KId` }\>
|
|
365
398
|
|
|
366
399
|
Fetchs the public and private keys for an Access Application, then initializes
|
|
367
400
|
the [https://npm.im/@raytio/maxcryptor|Maxcryptor](https://npm.im/@raytio/maxcryptor|Maxcryptor)'s `ApplicationEncryptor`.
|
|
@@ -378,18 +411,69 @@ the [https://npm.im/@raytio/maxcryptor|Maxcryptor](https://npm.im/@raytio/maxcry
|
|
|
378
411
|
|
|
379
412
|
#### Returns
|
|
380
413
|
|
|
381
|
-
`Promise`<{ `decryptor`: `ApplicationEncryptor` ; `
|
|
414
|
+
`Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyId`: `KId` }\>
|
|
382
415
|
|
|
383
416
|
an `ApplicationEncryptor` and the public key of the Access Application
|
|
384
417
|
|
|
385
418
|
___
|
|
386
419
|
|
|
420
|
+
### getAAPublicKey
|
|
421
|
+
|
|
422
|
+
▸ **getAAPublicKey**(`«destructured»`): `Promise`<`PublicKeyNode`\>
|
|
423
|
+
|
|
424
|
+
Fetches the Public Key Information for an Access Application
|
|
425
|
+
|
|
426
|
+
#### Parameters
|
|
427
|
+
|
|
428
|
+
| Name | Type |
|
|
429
|
+
| :------ | :------ |
|
|
430
|
+
| `«destructured»` | `Object` |
|
|
431
|
+
| › `aId` | `AId` |
|
|
432
|
+
| › `apiToken` | `string` |
|
|
433
|
+
| › `apiUrl` | `string` |
|
|
434
|
+
|
|
435
|
+
#### Returns
|
|
436
|
+
|
|
437
|
+
`Promise`<`PublicKeyNode`\>
|
|
438
|
+
|
|
439
|
+
the id and Key information of the Applications Public Key
|
|
440
|
+
|
|
441
|
+
___
|
|
442
|
+
|
|
443
|
+
### getMissingDataForInstance
|
|
444
|
+
|
|
445
|
+
▸ **getMissingDataForInstance**(`«destructured»`): `Promise`<`Instance`\>
|
|
446
|
+
|
|
447
|
+
the new API doesn't return the whole instance at once,
|
|
448
|
+
so we have to make several additional API requests.
|
|
449
|
+
|
|
450
|
+
#### Parameters
|
|
451
|
+
|
|
452
|
+
| Name | Type |
|
|
453
|
+
| :------ | :------ |
|
|
454
|
+
| `«destructured»` | `Object` |
|
|
455
|
+
| › `apiToken` | `string` |
|
|
456
|
+
| › `apiUrl` | `string` |
|
|
457
|
+
| › `instanceWithoutData` | `InstanceWithoutData` |
|
|
458
|
+
|
|
459
|
+
#### Returns
|
|
460
|
+
|
|
461
|
+
`Promise`<`Instance`\>
|
|
462
|
+
|
|
463
|
+
___
|
|
464
|
+
|
|
387
465
|
### getNidFromUrn
|
|
388
466
|
|
|
389
|
-
▸ **getNidFromUrn
|
|
467
|
+
▸ **getNidFromUrn**<`IDType`\>(`urn`): `IDType`
|
|
390
468
|
|
|
391
469
|
two overloads - if you provide undefined, you might get undefined back
|
|
392
470
|
|
|
471
|
+
#### Type parameters
|
|
472
|
+
|
|
473
|
+
| Name | Type |
|
|
474
|
+
| :------ | :------ |
|
|
475
|
+
| `IDType` | `NId` |
|
|
476
|
+
|
|
393
477
|
#### Parameters
|
|
394
478
|
|
|
395
479
|
| Name | Type |
|
|
@@ -398,12 +482,18 @@ two overloads - if you provide undefined, you might get undefined back
|
|
|
398
482
|
|
|
399
483
|
#### Returns
|
|
400
484
|
|
|
401
|
-
`
|
|
485
|
+
`IDType`
|
|
402
486
|
|
|
403
|
-
▸ **getNidFromUrn
|
|
487
|
+
▸ **getNidFromUrn**<`IDType`\>(`urn`): `undefined` \| `IDType`
|
|
404
488
|
|
|
405
489
|
two overloads - if you provide undefined, you might get undefined back
|
|
406
490
|
|
|
491
|
+
#### Type parameters
|
|
492
|
+
|
|
493
|
+
| Name | Type |
|
|
494
|
+
| :------ | :------ |
|
|
495
|
+
| `IDType` | `NId` |
|
|
496
|
+
|
|
407
497
|
#### Parameters
|
|
408
498
|
|
|
409
499
|
| Name | Type |
|
|
@@ -412,7 +502,7 @@ two overloads - if you provide undefined, you might get undefined back
|
|
|
412
502
|
|
|
413
503
|
#### Returns
|
|
414
504
|
|
|
415
|
-
`undefined` \| `
|
|
505
|
+
`undefined` \| `IDType`
|
|
416
506
|
|
|
417
507
|
___
|
|
418
508
|
|
|
@@ -646,7 +736,7 @@ ___
|
|
|
646
736
|
|
|
647
737
|
### someEncrypted
|
|
648
738
|
|
|
649
|
-
▸ **someEncrypted**<`T
|
|
739
|
+
▸ **someEncrypted**<`T`\>(`...args`): `number`
|
|
650
740
|
|
|
651
741
|
Given a profile object's properties, returns the number
|
|
652
742
|
of properties that are encryted.
|
|
@@ -656,7 +746,6 @@ of properties that are encryted.
|
|
|
656
746
|
| Name | Type |
|
|
657
747
|
| :------ | :------ |
|
|
658
748
|
| `T` | extends `object` |
|
|
659
|
-
| `K` | extends `string` \| `number` \| `symbol` |
|
|
660
749
|
|
|
661
750
|
#### Parameters
|
|
662
751
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetchKeysForSubmission_1 = require("../fetchKeysForSubmission");
|
|
4
|
+
vi.spyOn(global, "fetch").mockResolvedValueOnce({
|
|
5
|
+
json: async () => [
|
|
6
|
+
{ aain_id: "n1", field_name: "f1", key_data: 1 },
|
|
7
|
+
{ aain_id: "n1", field_name: "f2", key_data: 1 },
|
|
8
|
+
{ aain_id: "n2", field_name: "f2", key_data: 3 },
|
|
9
|
+
{ aain_id: "n3", field_name: "f1", key_data: 4 },
|
|
10
|
+
{ aain_id: "n3", field_name: "f2", key_data: 5 },
|
|
11
|
+
{ aain_id: "n3", field_name: "f3", key_data: 6 },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
describe("fetchKeysForSubmission", () => {
|
|
15
|
+
it("converts the hashed_n_id format into n_id", async () => {
|
|
16
|
+
expect(await (0, fetchKeysForSubmission_1.fetchKeysForSubmission)({
|
|
17
|
+
iId: "i1",
|
|
18
|
+
apiToken: "apiToken",
|
|
19
|
+
apiUrl: "apiUrl",
|
|
20
|
+
})).toStrictEqual({
|
|
21
|
+
n1: { f1: 1, f2: 1 },
|
|
22
|
+
n2: { f2: 3 },
|
|
23
|
+
n3: { f1: 4, f2: 5, f3: 6 },
|
|
24
|
+
});
|
|
25
|
+
expect(fetch).toHaveBeenCalledTimes(1);
|
|
26
|
+
expect(fetch).toHaveBeenNthCalledWith(1, "apiUrl/db/v1/dsm_access_application_instance_node_keys?aai_id=eq.i1", { headers: { Authorization: "Bearer apiToken" } });
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetchPOsOrAOsForSubmission_1 = require("../fetchPOsOrAOsForSubmission");
|
|
4
|
+
vi.spyOn(global, "fetch").mockResolvedValueOnce({
|
|
5
|
+
json: async () => [
|
|
6
|
+
{ n_id: "n1", properties: { a: 1 }, aa_id: "a1", aai_id: "i1" },
|
|
7
|
+
{ hashed_n_id: "n2", properties: { b: 2 }, aa_id: "a2", aai_id: "i2" },
|
|
8
|
+
],
|
|
9
|
+
});
|
|
10
|
+
describe("fetchPOsOrAOsForSubmission", () => {
|
|
11
|
+
it("converts the hashed_n_id format into n_id", async () => {
|
|
12
|
+
expect(await (0, fetchPOsOrAOsForSubmission_1.fetchPOsOrAOsForSubmission)({ iId: "i1", apiToken: "apiToken", apiUrl: "apiUrl" }, "AOs")).toStrictEqual([
|
|
13
|
+
{ n_id: "n1", properties: { a: 1 }, isFromSubmission: ["a1", "i1"] },
|
|
14
|
+
{
|
|
15
|
+
n_id: "HASHED::n2::a2",
|
|
16
|
+
properties: { b: 2 },
|
|
17
|
+
isFromSubmission: ["a2", "i2"],
|
|
18
|
+
},
|
|
19
|
+
]);
|
|
20
|
+
expect(fetch).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(fetch).toHaveBeenNthCalledWith(1, "apiUrl/db/v1/dsm_access_application_instance_application_objects?aai_id=eq.i1", { headers: { Authorization: "Bearer apiToken" } });
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetchRelationshipsForSubmission_1 = require("../fetchRelationshipsForSubmission");
|
|
4
|
+
vi.spyOn(global, "fetch").mockResolvedValueOnce({
|
|
5
|
+
json: async () => [
|
|
6
|
+
{ id: "p1", from_id: "n1", to_id: "n2" },
|
|
7
|
+
{ id: "p1", from_id: "n1", to_i_id: "n2" },
|
|
8
|
+
],
|
|
9
|
+
});
|
|
10
|
+
describe("fetchRelationshipsForSubmission", () => {
|
|
11
|
+
it("converts the hashed_n_id format into n_id", async () => {
|
|
12
|
+
expect(await (0, fetchRelationshipsForSubmission_1.fetchRelationshipsForSubmission)({
|
|
13
|
+
iId: "i1",
|
|
14
|
+
apiToken: "apiToken",
|
|
15
|
+
apiUrl: "apiUrl",
|
|
16
|
+
})).toStrictEqual([
|
|
17
|
+
{
|
|
18
|
+
p_id: "p1",
|
|
19
|
+
start: "urn:profile_object:n1",
|
|
20
|
+
end: "urn:profile_object:n2",
|
|
21
|
+
},
|
|
22
|
+
{ p_id: "p1", start: "urn:profile_object:n1", end: "urn:instance:n2" },
|
|
23
|
+
]);
|
|
24
|
+
expect(fetch).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(fetch).toHaveBeenNthCalledWith(1, "apiUrl/db/v1/dsm_access_application_instance_node_relationships?aai_id=eq.i1", { headers: { Authorization: "Bearer apiToken" } });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getMissingDataForInstance_1 = require("../getMissingDataForInstance");
|
|
4
|
+
vi.mock("../fetchKeysForSubmission", () => ({
|
|
5
|
+
fetchKeysForSubmission: async () => [3, 4],
|
|
6
|
+
}));
|
|
7
|
+
vi.mock("../fetchPOsOrAOsForSubmission", () => ({
|
|
8
|
+
fetchPOsOrAOsForSubmission: async () => [1, 2],
|
|
9
|
+
}));
|
|
10
|
+
vi.mock("../fetchRelationshipsForSubmission", () => ({
|
|
11
|
+
fetchRelationshipsForSubmission: async () => [5, 6],
|
|
12
|
+
}));
|
|
13
|
+
describe("getMissingDataForInstance", () => {
|
|
14
|
+
it("converts the hashed_n_id format into n_id", async () => {
|
|
15
|
+
expect(await (0, getMissingDataForInstance_1.getMissingDataForInstance)({
|
|
16
|
+
instanceWithoutData: {
|
|
17
|
+
id: "i1",
|
|
18
|
+
confirmation_code: "ABC123",
|
|
19
|
+
},
|
|
20
|
+
apiToken: "apiToken",
|
|
21
|
+
apiUrl: "apiUrl",
|
|
22
|
+
})).toStrictEqual({
|
|
23
|
+
confirmation_code: "ABC123",
|
|
24
|
+
id: "i1",
|
|
25
|
+
keys: [3, 4],
|
|
26
|
+
profile_objects: [1, 2, 1, 2],
|
|
27
|
+
relationships: [5, 6],
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IId, NId2 } from "@raytio/types";
|
|
2
|
+
export declare function fetchKeysForSubmission({ apiToken, apiUrl, iId, }: {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
apiToken: string;
|
|
5
|
+
iId: IId;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
[nId2: NId2]: {
|
|
8
|
+
[fieldName: string]: {
|
|
9
|
+
data: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchKeysForSubmission = void 0;
|
|
4
|
+
const util_1 = require("../../util");
|
|
5
|
+
async function fetchKeysForSubmission({ apiToken, apiUrl, iId, }) {
|
|
6
|
+
var _a;
|
|
7
|
+
const keys = await fetch(`${apiUrl}/db/v1/dsm_access_application_instance_node_keys?aai_id=eq.${iId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
|
|
8
|
+
const keysObject = {};
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
/* eslint-disable fp/no-mutation -- much more logical written like this */
|
|
11
|
+
keysObject[_a = key.aain_id] || (keysObject[_a] = {});
|
|
12
|
+
keysObject[key.aain_id][key.field_name] = key.key_data;
|
|
13
|
+
}
|
|
14
|
+
return keysObject;
|
|
15
|
+
}
|
|
16
|
+
exports.fetchKeysForSubmission = fetchKeysForSubmission;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchPOsOrAOsForSubmission = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const util_1 = require("../../util");
|
|
6
|
+
const general_1 = require("../../general");
|
|
7
|
+
const API_URLS = {
|
|
8
|
+
POs: "dsm_access_application_instance_nodes",
|
|
9
|
+
AOs: "dsm_access_application_instance_application_objects",
|
|
10
|
+
};
|
|
11
|
+
async function fetchPOsOrAOsForSubmission({ iId, apiUrl, apiToken }, type) {
|
|
12
|
+
const POsforAA = await fetch(`${apiUrl}/db/v1/${API_URLS[type]}?aai_id=eq.${iId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
|
|
13
|
+
/**
|
|
14
|
+
* the backend finally includes the aId and iId properties,
|
|
15
|
+
* but we already have our own system for accessing this data
|
|
16
|
+
* since we've needed it for the past few years.
|
|
17
|
+
*
|
|
18
|
+
* additionally, we relace the weird `hashed_n_id` format with
|
|
19
|
+
* the result from {@link createHashedNId}, because that's what we've
|
|
20
|
+
* always done.
|
|
21
|
+
*/
|
|
22
|
+
const cleanedPOs = POsforAA.map((PO) => (Object.assign(Object.assign({}, (0, ramda_1.omit)(["aa_id", "aai_id", "hashed_n_id"], PO)), { n_id: PO.n_id || (0, general_1.createHashedNId)(PO.hashed_n_id, PO.aa_id), isFromSubmission: [PO.aa_id, PO.aai_id] }))).filter(PO => PO.properties !== null && PO.properties !== undefined);
|
|
23
|
+
return cleanedPOs;
|
|
24
|
+
}
|
|
25
|
+
exports.fetchPOsOrAOsForSubmission = fetchPOsOrAOsForSubmission;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchRelationshipsForSubmission = void 0;
|
|
4
|
+
const util_1 = require("../../util");
|
|
5
|
+
const legacy_1 = require("./legacy");
|
|
6
|
+
async function fetchRelationshipsForSubmission({ iId, apiUrl, apiToken, }) {
|
|
7
|
+
const relationships = await fetch(`${apiUrl}/db/v1/dsm_access_application_instance_node_relationships?aai_id=eq.${iId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
|
|
8
|
+
return relationships.map(legacy_1.convertServerRelationship);
|
|
9
|
+
}
|
|
10
|
+
exports.fetchRelationshipsForSubmission = fetchRelationshipsForSubmission;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Instance, InstanceWithoutData } from "@raytio/types";
|
|
2
|
+
/**
|
|
3
|
+
* the new API doesn't return the whole instance at once,
|
|
4
|
+
* so we have to make several additional API requests.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getMissingDataForInstance: ({ apiToken, apiUrl, instanceWithoutData, }: {
|
|
7
|
+
apiToken: string;
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
instanceWithoutData: InstanceWithoutData;
|
|
10
|
+
}) => Promise<Instance>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMissingDataForInstance = void 0;
|
|
4
|
+
const fetchKeysForSubmission_1 = require("./fetchKeysForSubmission");
|
|
5
|
+
const fetchPOsOrAOsForSubmission_1 = require("./fetchPOsOrAOsForSubmission");
|
|
6
|
+
const fetchRelationshipsForSubmission_1 = require("./fetchRelationshipsForSubmission");
|
|
7
|
+
/**
|
|
8
|
+
* the new API doesn't return the whole instance at once,
|
|
9
|
+
* so we have to make several additional API requests.
|
|
10
|
+
*/
|
|
11
|
+
const getMissingDataForInstance = async ({ apiToken, apiUrl, instanceWithoutData, }) => {
|
|
12
|
+
const options = {
|
|
13
|
+
apiToken,
|
|
14
|
+
apiUrl,
|
|
15
|
+
iId: instanceWithoutData.id,
|
|
16
|
+
};
|
|
17
|
+
// these 4 can be requested in parallel. Ideally the backend
|
|
18
|
+
// would do this work for us like the old API used to.
|
|
19
|
+
const [POs, AOs, relationships, keys] = await Promise.all([
|
|
20
|
+
(0, fetchPOsOrAOsForSubmission_1.fetchPOsOrAOsForSubmission)(options, "POs"),
|
|
21
|
+
(0, fetchPOsOrAOsForSubmission_1.fetchPOsOrAOsForSubmission)(options, "AOs"),
|
|
22
|
+
(0, fetchRelationshipsForSubmission_1.fetchRelationshipsForSubmission)(options),
|
|
23
|
+
(0, fetchKeysForSubmission_1.fetchKeysForSubmission)(options),
|
|
24
|
+
]);
|
|
25
|
+
return Object.assign(Object.assign({}, instanceWithoutData), { profile_objects: [...POs, ...AOs], relationships,
|
|
26
|
+
keys });
|
|
27
|
+
};
|
|
28
|
+
exports.getMissingDataForInstance = getMissingDataForInstance;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./legacy"), exports);
|
|
18
|
+
__exportStar(require("./getMissingDataForInstance"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ramda_1 = require("ramda");
|
|
4
|
+
const convertRelationships_1 = require("../convertRelationships");
|
|
5
|
+
const relationship = {
|
|
6
|
+
p_id: "PId",
|
|
7
|
+
start_date: "",
|
|
8
|
+
end_date: "",
|
|
9
|
+
start: "urn:profile_object:1",
|
|
10
|
+
end: "urn:profile_object:2",
|
|
11
|
+
type: "IS_RELATED_TO",
|
|
12
|
+
active: true,
|
|
13
|
+
properties: undefined,
|
|
14
|
+
};
|
|
15
|
+
const serverRelationship = {
|
|
16
|
+
id: "PId",
|
|
17
|
+
start_date: "",
|
|
18
|
+
end_date: "",
|
|
19
|
+
active: true,
|
|
20
|
+
from_id: `1`,
|
|
21
|
+
to_id: `2`,
|
|
22
|
+
to_i_id: null,
|
|
23
|
+
type: "IS_RELATED_TO",
|
|
24
|
+
properties: undefined,
|
|
25
|
+
};
|
|
26
|
+
describe("convertServerRelationship", () => {
|
|
27
|
+
it("Converts fields in PO relationship", () => {
|
|
28
|
+
expect((0, convertRelationships_1.convertServerRelationship)(serverRelationship)).toStrictEqual(relationship);
|
|
29
|
+
});
|
|
30
|
+
it("Converts fields in instance/crust relationship", () => {
|
|
31
|
+
// Same Ids with Instance and PO to_ids swapped
|
|
32
|
+
const instanceServerRelationship = Object.assign(Object.assign({}, (0, ramda_1.omit)(["to_id", "to_i_id"], serverRelationship)), { to_i_id: "2" });
|
|
33
|
+
// Replacing Urn prepend text
|
|
34
|
+
const instanceRelationship = Object.assign(Object.assign({}, (0, ramda_1.omit)(["end"], relationship)), { end: "urn:instance:2" });
|
|
35
|
+
expect((0, convertRelationships_1.convertServerRelationship)(instanceServerRelationship)).toStrictEqual(instanceRelationship);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IId, NId, PId, Relationship } from "@raytio/types";
|
|
2
|
+
/** This type represents the relationship format returned by the Postgres API */
|
|
3
|
+
export type ServerRelationship = Omit<Relationship, "p_id" | "start" | "end"> & {
|
|
4
|
+
id: PId;
|
|
5
|
+
from_id: NId;
|
|
6
|
+
} & ({
|
|
7
|
+
to_id: NId;
|
|
8
|
+
} | {
|
|
9
|
+
to_i_id: IId;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Converts relationship type used by the server into the (Urn format) type used by the client
|
|
13
|
+
* @param serverRelationship relationship type used in the server
|
|
14
|
+
* @returns a Relationship (client-side type) that is equivalent to the inputted serverRelationship value
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertServerRelationship(serverRelationship: ServerRelationship): Relationship;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertServerRelationship = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
/**
|
|
6
|
+
* Converts relationship type used by the server into the (Urn format) type used by the client
|
|
7
|
+
* @param serverRelationship relationship type used in the server
|
|
8
|
+
* @returns a Relationship (client-side type) that is equivalent to the inputted serverRelationship value
|
|
9
|
+
*/
|
|
10
|
+
function convertServerRelationship(serverRelationship) {
|
|
11
|
+
const { id, from_id } = serverRelationship;
|
|
12
|
+
/**
|
|
13
|
+
* This functionality is similar to LinkToCrust, but in this case the API has already worked out
|
|
14
|
+
* which instance the PO links to (if any) so we simply convert it into a {@link Urn}
|
|
15
|
+
*/
|
|
16
|
+
const end = "to_id" in serverRelationship
|
|
17
|
+
? `urn:profile_object:${serverRelationship.to_id}`
|
|
18
|
+
: `urn:instance:${serverRelationship.to_i_id}`;
|
|
19
|
+
return Object.assign({ p_id: id, start: `urn:profile_object:${from_id}`, end }, (0, ramda_1.omit)(["id", "from_id", "to_id", "to_i_id"], serverRelationship));
|
|
20
|
+
}
|
|
21
|
+
exports.convertServerRelationship = convertServerRelationship;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./convertRelationships";
|