@raytio/core 11.2.0 → 11.4.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 +126 -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 +15 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.js +24 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.js +9 -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 +20 -0
- package/dist/accessApplication/api/legacy/index.d.ts +1 -0
- package/dist/accessApplication/api/legacy/index.js +17 -0
- package/dist/accessApplication/createAA.d.ts +4 -1
- package/dist/accessApplication/createAA.js +70 -19
- 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 +3 -3
- package/dist/crypto/decryptSharedData.js +2 -5
- package/dist/crypto/getAADecryptor.d.ts +18 -3
- package/dist/crypto/getAADecryptor.js +10 -11
- package/dist/crypto/helpers.d.ts +2 -2
- package/dist/general/date.js +1 -2
- package/dist/general/password.js +1 -2
- package/dist/general/types.d.ts +9 -0
- package/dist/general/types.js +11 -2
- package/dist/rules/calculateScore.d.ts +1 -1
- package/dist/rules/calculateScore.js +2 -3
- 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/evaluateScoreCondition.js +1 -2
- 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/checkTypeofValue.js +2 -3
- package/dist/rules/helpers/getValuesFromPath.d.ts +1 -1
- package/dist/rules/helpers/getValuesFromPath.js +1 -2
- package/dist/rules/helpers/thresholds.d.ts +1 -1
- package/dist/rules/helpers/thresholds.js +2 -3
- 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/expandSchema.js +1 -2
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +1 -1
- package/dist/schema/expandSchema/processSchema.d.ts +1 -1
- package/dist/schema/expandSchema/processSchema.js +12 -10
- package/dist/schema/expandSchema/removePrivateFields.d.ts +57 -49
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +3 -3
- package/dist/schema/expandSchema/sortSchemaProperties.js +2 -2
- package/dist/schema/expandSchema/unwrapSchema.d.ts +2 -6
- package/dist/schema/expandSchema/unwrapSchema.js +1 -2
- package/dist/schema/labels.d.ts +2 -1
- package/dist/testHelpers.d.ts +2 -2
- package/dist/verifications/getPOVerification.d.ts +1 -1
- package/dist/verifications/getPOVerification.js +1 -2
- 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/safeHarbour.js +4 -4
- 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 +4 -2
- package/package.json +6 -42
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
20
20
|
|
|
21
21
|
- [SafeHarbourObj](#safeharbourobj)
|
|
22
22
|
- [SafeHarbourResult](#safeharbourresult)
|
|
23
|
+
- [ServerAA](#serveraa)
|
|
24
|
+
- [ServerRelationship](#serverrelationship)
|
|
23
25
|
- [VerDetails](#verdetails)
|
|
24
26
|
|
|
25
27
|
### Functions
|
|
@@ -27,9 +29,10 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
27
29
|
- [calcSafeHarbourScore](#calcsafeharbourscore)
|
|
28
30
|
- [calculateScore](#calculatescore)
|
|
29
31
|
- [checkJsonSignature](#checkjsonsignature)
|
|
30
|
-
- [cleanInstance](#cleaninstance)
|
|
31
32
|
- [convertInstanceToRuleInput](#convertinstancetoruleinput)
|
|
33
|
+
- [convertServerRelationship](#convertserverrelationship)
|
|
32
34
|
- [createAA](#createaa)
|
|
35
|
+
- [createHashedNId](#createhashednid)
|
|
33
36
|
- [decryptSharedData](#decryptshareddata)
|
|
34
37
|
- [evaluateRule](#evaluaterule)
|
|
35
38
|
- [expandSchema](#expandschema)
|
|
@@ -37,6 +40,8 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
37
40
|
- [findSuitableLocale](#findsuitablelocale)
|
|
38
41
|
- [fromCognitoAttributes](#fromcognitoattributes)
|
|
39
42
|
- [getAADecryptor](#getaadecryptor)
|
|
43
|
+
- [getAAPublicKey](#getaapublickey)
|
|
44
|
+
- [getMissingDataForInstance](#getmissingdataforinstance)
|
|
40
45
|
- [getNidFromUrn](#getnidfromurn)
|
|
41
46
|
- [getOwnRealVerifications](#getownrealverifications)
|
|
42
47
|
- [getPOVerification](#getpoverification)
|
|
@@ -77,6 +82,20 @@ the response from [calcSafeHarbourScore](#calcsafeharbourscore)
|
|
|
77
82
|
|
|
78
83
|
___
|
|
79
84
|
|
|
85
|
+
### ServerAA
|
|
86
|
+
|
|
87
|
+
Ƭ **ServerAA**: `Omit`<`AA`, ``"a_id"``\> & { `id`: `AId` }
|
|
88
|
+
|
|
89
|
+
___
|
|
90
|
+
|
|
91
|
+
### ServerRelationship
|
|
92
|
+
|
|
93
|
+
Ƭ **ServerRelationship**: `Omit`<`Relationship`, ``"p_id"`` \| ``"start"`` \| ``"end"``\> & { `from_id`: `NId` ; `id`: `PId` } & { `to_id`: `NId` } \| { `to_i_id`: `IId` }
|
|
94
|
+
|
|
95
|
+
This type represents the relationship format returned by the Postgres API
|
|
96
|
+
|
|
97
|
+
___
|
|
98
|
+
|
|
80
99
|
### VerDetails
|
|
81
100
|
|
|
82
101
|
Ƭ **VerDetails**: `Object`
|
|
@@ -108,7 +127,7 @@ from different sources. For information, refer to the
|
|
|
108
127
|
| `data.person` | `ProfileObject` |
|
|
109
128
|
| `data.profileObjects` | `ProfileObject`[] |
|
|
110
129
|
| `data.realVers` | `RealVer`[] |
|
|
111
|
-
| `data.getSchema` | (`schemaName`: `
|
|
130
|
+
| `data.getSchema` | (`schemaName`: `SchemaName`) => `Promise`<`Schema`\> |
|
|
112
131
|
|
|
113
132
|
#### Returns
|
|
114
133
|
|
|
@@ -158,43 +177,41 @@ or `getSomeoneElsesRealVerifications` instead.
|
|
|
158
177
|
|
|
159
178
|
___
|
|
160
179
|
|
|
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.
|
|
180
|
+
### convertInstanceToRuleInput
|
|
168
181
|
|
|
169
|
-
|
|
182
|
+
▸ **convertInstanceToRuleInput**(`POs`, `realVers`, `getSchema`): `Promise`<`RuleData`\>
|
|
170
183
|
|
|
171
184
|
#### Parameters
|
|
172
185
|
|
|
173
186
|
| Name | Type |
|
|
174
187
|
| :------ | :------ |
|
|
175
|
-
| `
|
|
188
|
+
| `POs` | `ProfileObject`[] |
|
|
189
|
+
| `realVers` | `RealVer`[] |
|
|
190
|
+
| `getSchema` | (`schemaName`: `SchemaName`) => `Promise`<`Schema`\> |
|
|
176
191
|
|
|
177
192
|
#### Returns
|
|
178
193
|
|
|
179
|
-
`
|
|
194
|
+
`Promise`<`RuleData`\>
|
|
180
195
|
|
|
181
196
|
___
|
|
182
197
|
|
|
183
|
-
###
|
|
198
|
+
### convertServerRelationship
|
|
184
199
|
|
|
185
|
-
▸ **
|
|
200
|
+
▸ **convertServerRelationship**(`serverRelationship`): `Relationship`
|
|
201
|
+
|
|
202
|
+
Converts relationship type used by the server into the (Urn format) type used by the client
|
|
186
203
|
|
|
187
204
|
#### Parameters
|
|
188
205
|
|
|
189
|
-
| Name | Type |
|
|
190
|
-
| :------ | :------ |
|
|
191
|
-
| `
|
|
192
|
-
| `realVers` | `RealVer`[] |
|
|
193
|
-
| `getSchema` | (`schemaName`: `string`) => `Promise`<`Schema`\> |
|
|
206
|
+
| Name | Type | Description |
|
|
207
|
+
| :------ | :------ | :------ |
|
|
208
|
+
| `serverRelationship` | [`ServerRelationship`](#serverrelationship) | relationship type used in the server |
|
|
194
209
|
|
|
195
210
|
#### Returns
|
|
196
211
|
|
|
197
|
-
`
|
|
212
|
+
`Relationship`
|
|
213
|
+
|
|
214
|
+
a Relationship (client-side type) that is equivalent to the inputted serverRelationship value
|
|
198
215
|
|
|
199
216
|
___
|
|
200
217
|
|
|
@@ -226,6 +243,29 @@ as well as the `userDoc` data which is stored in the user's cognito attributes.
|
|
|
226
243
|
|
|
227
244
|
___
|
|
228
245
|
|
|
246
|
+
### createHashedNId
|
|
247
|
+
|
|
248
|
+
▸ **createHashedNId**(`nId`, `aId`): `NId`
|
|
249
|
+
|
|
250
|
+
the API returns hashed NIds in a separate field,
|
|
251
|
+
which breaks the whole app. So, we move the hashed ID into
|
|
252
|
+
the normal `n_id` field, and use a different format.
|
|
253
|
+
|
|
254
|
+
This was first introduced in #1048
|
|
255
|
+
|
|
256
|
+
#### Parameters
|
|
257
|
+
|
|
258
|
+
| Name | Type |
|
|
259
|
+
| :------ | :------ |
|
|
260
|
+
| `nId` | `NId` |
|
|
261
|
+
| `aId` | `AId` |
|
|
262
|
+
|
|
263
|
+
#### Returns
|
|
264
|
+
|
|
265
|
+
`NId`
|
|
266
|
+
|
|
267
|
+
___
|
|
268
|
+
|
|
229
269
|
### decryptSharedData
|
|
230
270
|
|
|
231
271
|
▸ **decryptSharedData**(`«destructured»`): `Promise`<{ `applicationDecryptor`: `ApplicationDataEncryptorI` ; `instance`: `Instance` }\>
|
|
@@ -304,7 +344,7 @@ ___
|
|
|
304
344
|
|
|
305
345
|
### findSchemaLabel
|
|
306
346
|
|
|
307
|
-
▸ **findSchemaLabel**(`labels`): `undefined` \| `
|
|
347
|
+
▸ **findSchemaLabel**(`labels`): `undefined` \| `SchemaName`
|
|
308
348
|
|
|
309
349
|
Finds the label (on a profile object) which is the schema name
|
|
310
350
|
|
|
@@ -316,7 +356,7 @@ Finds the label (on a profile object) which is the schema name
|
|
|
316
356
|
|
|
317
357
|
#### Returns
|
|
318
358
|
|
|
319
|
-
`undefined` \| `
|
|
359
|
+
`undefined` \| `SchemaName`
|
|
320
360
|
|
|
321
361
|
___
|
|
322
362
|
|
|
@@ -361,7 +401,7 @@ ___
|
|
|
361
401
|
|
|
362
402
|
### getAADecryptor
|
|
363
403
|
|
|
364
|
-
▸ **getAADecryptor**(`«destructured»`): `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `
|
|
404
|
+
▸ **getAADecryptor**(`«destructured»`): `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyId`: `KId` }\>
|
|
365
405
|
|
|
366
406
|
Fetchs the public and private keys for an Access Application, then initializes
|
|
367
407
|
the [https://npm.im/@raytio/maxcryptor|Maxcryptor](https://npm.im/@raytio/maxcryptor|Maxcryptor)'s `ApplicationEncryptor`.
|
|
@@ -378,18 +418,69 @@ the [https://npm.im/@raytio/maxcryptor|Maxcryptor](https://npm.im/@raytio/maxcry
|
|
|
378
418
|
|
|
379
419
|
#### Returns
|
|
380
420
|
|
|
381
|
-
`Promise`<{ `decryptor`: `ApplicationEncryptor` ; `
|
|
421
|
+
`Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyId`: `KId` }\>
|
|
382
422
|
|
|
383
423
|
an `ApplicationEncryptor` and the public key of the Access Application
|
|
384
424
|
|
|
385
425
|
___
|
|
386
426
|
|
|
427
|
+
### getAAPublicKey
|
|
428
|
+
|
|
429
|
+
▸ **getAAPublicKey**(`«destructured»`): `Promise`<`PublicKeyNode`\>
|
|
430
|
+
|
|
431
|
+
Fetches the Public Key Information for an Access Application
|
|
432
|
+
|
|
433
|
+
#### Parameters
|
|
434
|
+
|
|
435
|
+
| Name | Type |
|
|
436
|
+
| :------ | :------ |
|
|
437
|
+
| `«destructured»` | `Object` |
|
|
438
|
+
| › `aId` | `AId` |
|
|
439
|
+
| › `apiToken` | `string` |
|
|
440
|
+
| › `apiUrl` | `string` |
|
|
441
|
+
|
|
442
|
+
#### Returns
|
|
443
|
+
|
|
444
|
+
`Promise`<`PublicKeyNode`\>
|
|
445
|
+
|
|
446
|
+
the id and Key information of the Applications Public Key
|
|
447
|
+
|
|
448
|
+
___
|
|
449
|
+
|
|
450
|
+
### getMissingDataForInstance
|
|
451
|
+
|
|
452
|
+
▸ **getMissingDataForInstance**(`«destructured»`): `Promise`<`Instance`\>
|
|
453
|
+
|
|
454
|
+
the new API doesn't return the whole instance at once,
|
|
455
|
+
so we have to make several additional API requests.
|
|
456
|
+
|
|
457
|
+
#### Parameters
|
|
458
|
+
|
|
459
|
+
| Name | Type |
|
|
460
|
+
| :------ | :------ |
|
|
461
|
+
| `«destructured»` | `Object` |
|
|
462
|
+
| › `apiToken` | `string` |
|
|
463
|
+
| › `apiUrl` | `string` |
|
|
464
|
+
| › `instanceWithoutData` | `InstanceWithoutData` |
|
|
465
|
+
|
|
466
|
+
#### Returns
|
|
467
|
+
|
|
468
|
+
`Promise`<`Instance`\>
|
|
469
|
+
|
|
470
|
+
___
|
|
471
|
+
|
|
387
472
|
### getNidFromUrn
|
|
388
473
|
|
|
389
|
-
▸ **getNidFromUrn
|
|
474
|
+
▸ **getNidFromUrn**<`IDType`\>(`urn`): `IDType`
|
|
390
475
|
|
|
391
476
|
two overloads - if you provide undefined, you might get undefined back
|
|
392
477
|
|
|
478
|
+
#### Type parameters
|
|
479
|
+
|
|
480
|
+
| Name | Type |
|
|
481
|
+
| :------ | :------ |
|
|
482
|
+
| `IDType` | `NId` |
|
|
483
|
+
|
|
393
484
|
#### Parameters
|
|
394
485
|
|
|
395
486
|
| Name | Type |
|
|
@@ -398,12 +489,18 @@ two overloads - if you provide undefined, you might get undefined back
|
|
|
398
489
|
|
|
399
490
|
#### Returns
|
|
400
491
|
|
|
401
|
-
`
|
|
492
|
+
`IDType`
|
|
402
493
|
|
|
403
|
-
▸ **getNidFromUrn
|
|
494
|
+
▸ **getNidFromUrn**<`IDType`\>(`urn`): `undefined` \| `IDType`
|
|
404
495
|
|
|
405
496
|
two overloads - if you provide undefined, you might get undefined back
|
|
406
497
|
|
|
498
|
+
#### Type parameters
|
|
499
|
+
|
|
500
|
+
| Name | Type |
|
|
501
|
+
| :------ | :------ |
|
|
502
|
+
| `IDType` | `NId` |
|
|
503
|
+
|
|
407
504
|
#### Parameters
|
|
408
505
|
|
|
409
506
|
| Name | Type |
|
|
@@ -412,7 +509,7 @@ two overloads - if you provide undefined, you might get undefined back
|
|
|
412
509
|
|
|
413
510
|
#### Returns
|
|
414
511
|
|
|
415
|
-
`undefined` \| `
|
|
512
|
+
`undefined` \| `IDType`
|
|
416
513
|
|
|
417
514
|
___
|
|
418
515
|
|
|
@@ -646,7 +743,7 @@ ___
|
|
|
646
743
|
|
|
647
744
|
### someEncrypted
|
|
648
745
|
|
|
649
|
-
▸ **someEncrypted**<`T
|
|
746
|
+
▸ **someEncrypted**<`T`\>(`...args`): `number`
|
|
650
747
|
|
|
651
748
|
Given a profile object's properties, returns the number
|
|
652
749
|
of properties that are encryted.
|
|
@@ -656,7 +753,6 @@ of properties that are encryted.
|
|
|
656
753
|
| Name | Type |
|
|
657
754
|
| :------ | :------ |
|
|
658
755
|
| `T` | extends `object` |
|
|
659
|
-
| `K` | extends `string` \| `number` \| `symbol` |
|
|
660
756
|
|
|
661
757
|
#### Parameters
|
|
662
758
|
|
|
@@ -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,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchKeysForSubmission = fetchKeysForSubmission;
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchPOsOrAOsForSubmission = fetchPOsOrAOsForSubmission;
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchRelationshipsForSubmission = fetchRelationshipsForSubmission;
|
|
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
|
+
}
|
|
@@ -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,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertServerRelationship = convertServerRelationship;
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./convertRelationships";
|