@raytio/core 10.0.1 → 11.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +129 -55
  3. package/dist/__tests__/docs.test.d.ts +1 -0
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/crypto/getAADecryptor.d.ts +8 -3
  6. package/dist/crypto/helpers.d.ts +2 -2
  7. package/dist/general/conditional.d.ts +12 -2
  8. package/dist/general/conditional.js +11 -1
  9. package/dist/general/date.d.ts +2 -0
  10. package/dist/general/date.js +18 -0
  11. package/dist/general/index.d.ts +1 -0
  12. package/dist/general/index.js +1 -0
  13. package/dist/rules/calculateScore.d.ts +7 -2
  14. package/dist/rules/calculateScore.js +8 -2
  15. package/dist/rules/convertInstanceToRuleInput.d.ts +2 -2
  16. package/dist/rules/convertInstanceToRuleInput.js +2 -3
  17. package/dist/rules/evaluateScoreCondition.js +0 -1
  18. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts +1 -0
  19. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  20. package/dist/rules/helpers/__tests__/checkTypeofValue.test.d.ts +1 -0
  21. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  22. package/dist/rules/helpers/__tests__/getValuesFromPath.test.d.ts +1 -0
  23. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  24. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  25. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  26. package/dist/rules/helpers/checkTypeofValue.js +11 -6
  27. package/dist/rules/helpers/thresholds.js +1 -2
  28. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  29. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  30. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  31. package/dist/rules/operators/__tests__/date.test.js +81 -0
  32. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  33. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  34. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  35. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  36. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  37. package/dist/rules/operators/__tests__/number.test.js +53 -0
  38. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  39. package/dist/rules/operators/__tests__/string.test.js +74 -0
  40. package/dist/rules/types/config.d.ts +21 -17
  41. package/dist/rules/types/dataValueTypes.d.ts +4 -4
  42. package/dist/rules/types/internal.d.ts +3 -3
  43. package/dist/rules/version.d.ts +1 -1
  44. package/dist/rules/version.js +1 -1
  45. package/dist/schema/labels.js +1 -1
  46. package/dist/util/canonicalJsonify.js +1 -1
  47. package/dist/util/handleResponse.js +1 -1
  48. package/dist/verifications/getPOVerification.d.ts +7 -4
  49. package/dist/verifications/getPOVerification.js +15 -4
  50. package/dist/verifications/safeHarbour.d.ts +2 -2
  51. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  52. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  53. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  54. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  55. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +5 -2
  56. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
  57. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +3 -2
  58. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  59. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  60. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  61. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  62. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  63. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +1 -1
  64. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +1 -1
  65. package/package.json +13 -10
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 11.0.0 (2022-04-20)
11
+
12
+ - 💥 BREAKING CHANGE: Changed the input arguments of `convertInstanceToRuleInput` to only require a list of `ProfileObject`s, instead of the whole `Instance` object.
13
+ - Any profile object with an expired field is now considered `Expired`, even if other fields are verified.
14
+ - Fix the `valid_until` attribute being ignored on verifications
15
+
16
+ ## 10.1.0 (2022-07-06)
17
+
18
+ - move `repairDate` into core, and use it when processing verifications
19
+
10
20
  ## 10.0.1 (2022-07-06)
11
21
 
12
22
  - added 2 methods (`isScoreResultValid` and `isScoreConfigValid`) to verify if stored score-data is valid
package/README.md CHANGED
@@ -16,10 +16,11 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
16
16
 
17
17
  ## Table of contents
18
18
 
19
- ### Type aliases
19
+ ### Type Aliases
20
20
 
21
21
  - [SafeHarbourObj](#safeharbourobj)
22
22
  - [SafeHarbourResult](#safeharbourresult)
23
+ - [VerDetails](#verdetails)
23
24
 
24
25
  ### Functions
25
26
 
@@ -30,6 +31,7 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
30
31
  - [convertInstanceToRuleInput](#convertinstancetoruleinput)
31
32
  - [createAA](#createaa)
32
33
  - [decryptSharedData](#decryptshareddata)
34
+ - [evaluateRule](#evaluaterule)
33
35
  - [findSchemaLabel](#findschemalabel)
34
36
  - [fromCognitoAttributes](#fromcognitoattributes)
35
37
  - [getAADecryptor](#getaadecryptor)
@@ -42,10 +44,11 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
42
44
  - [isEncryptedFile](#isencryptedfile)
43
45
  - [isScoreConfigValid](#isscoreconfigvalid)
44
46
  - [isScoreResultValid](#isscoreresultvalid)
47
+ - [repairDate](#repairdate)
45
48
  - [someEncrypted](#someencrypted)
46
49
  - [toCognitoAttributes](#tocognitoattributes)
47
50
 
48
- ## Type aliases
51
+ ## Type Aliases
49
52
 
50
53
  ### SafeHarbourObj
51
54
 
@@ -68,11 +71,25 @@ the response from [calcSafeHarbourScore](#calcsafeharbourscore)
68
71
  | `flags` | [`SafeHarbourObj`](#safeharbourobj) |
69
72
  | `isSafe` | `boolean` |
70
73
 
74
+ ___
75
+
76
+ ### VerDetails
77
+
78
+ Ƭ **VerDetails**: `Object`
79
+
80
+ #### Type declaration
81
+
82
+ | Name | Type | Description |
83
+ | :------ | :------ | :------ |
84
+ | `expiryDate?` | `Date` | field only present for expired verifications |
85
+ | `sourceNId?` | `NId` | - |
86
+ | `verifiers` | `VerificationProvider`[] | - |
87
+
71
88
  ## Functions
72
89
 
73
90
  ### calcSafeHarbourScore
74
91
 
75
- `Const` **calcSafeHarbourScore**(`data`): `Promise`<[`SafeHarbourResult`](#safeharbourresult)\>
92
+ ▸ **calcSafeHarbourScore**(`data`): `Promise`<[`SafeHarbourResult`](#safeharbourresult)\>
76
93
 
77
94
  The Safe Harbour Score indidicates whether a person's identity has been verified
78
95
  to the extent requried for Safe Harbour Compliance. This requires multiple verifications
@@ -84,8 +101,8 @@ from different sources. For information, refer to the
84
101
  | Name | Type |
85
102
  | :------ | :------ |
86
103
  | `data` | `Object` |
87
- | `data.person` | `ProfileObject`<`Json`\> |
88
- | `data.profileObjects` | `ProfileObject`<`Json`\>[] |
104
+ | `data.person` | `ProfileObject` |
105
+ | `data.profileObjects` | `ProfileObject`[] |
89
106
  | `data.realVers` | `RealVer`[] |
90
107
  | `data.getSchema` | (`schemaName`: `string`) => `Promise`<`Schema`\> |
91
108
 
@@ -117,7 +134,7 @@ ___
117
134
 
118
135
  ### checkJsonSignature
119
136
 
120
- `Const` **checkJsonSignature**(`data`, `signature`): `Promise`<`boolean`\>
137
+ ▸ **checkJsonSignature**(`data`, `signature`): `Promise`<`boolean`\>
121
138
 
122
139
  checks that a json object was signed by the provided signature. Unless you're
123
140
  dealing with bundled verifications, you should use `getOwnRealVerifications`
@@ -160,13 +177,13 @@ ___
160
177
 
161
178
  ### convertInstanceToRuleInput
162
179
 
163
- `Const` **convertInstanceToRuleInput**(`instance`, `realVers`, `getSchema`): `Promise`<`RuleData`\>
180
+ ▸ **convertInstanceToRuleInput**(`POs`, `realVers`, `getSchema`): `Promise`<`RuleData`\>
164
181
 
165
182
  #### Parameters
166
183
 
167
184
  | Name | Type |
168
185
  | :------ | :------ |
169
- | `instance` | `Instance` |
186
+ | `POs` | `ProfileObject`[] |
170
187
  | `realVers` | `RealVer`[] |
171
188
  | `getSchema` | (`schemaName`: `string`) => `Promise`<`Schema`\> |
172
189
 
@@ -178,7 +195,7 @@ ___
178
195
 
179
196
  ### createAA
180
197
 
181
- ▸ **createAA**(`__namedParameters`): `Promise`<`AA`\>
198
+ ▸ **createAA**(`«destructured»`): `Promise`<`AA`\>
182
199
 
183
200
  Creates an Access Application and associated public+private keys.
184
201
 
@@ -191,12 +208,12 @@ as well as the `userDoc` data which is stored in the user's cognito attributes.
191
208
 
192
209
  | Name | Type |
193
210
  | :------ | :------ |
194
- | `__namedParameters` | `Object` |
195
- | `__namedParameters.apiToken` | `string` |
196
- | `__namedParameters.apiUrl` | `string` |
197
- | `__namedParameters.application` | `Omit`<`AA`, ``"a_id"``\> |
198
- | `__namedParameters.maxcryptor` | `DataEncryptorI` |
199
- | `__namedParameters.userDoc` | `UserDoc` |
211
+ | `«destructured»` | `Object` |
212
+ | › `apiToken` | `string` |
213
+ | › `apiUrl` | `string` |
214
+ | › `application` | `Omit`<`AA`, ``"a_id"``\> |
215
+ | › `maxcryptor` | `DataEncryptorI` |
216
+ | › `userDoc` | `UserDoc` |
200
217
 
201
218
  #### Returns
202
219
 
@@ -206,7 +223,7 @@ ___
206
223
 
207
224
  ### decryptSharedData
208
225
 
209
- `Const` **decryptSharedData**(`__namedParameters`): `Promise`<`Object`\>
226
+ ▸ **decryptSharedData**(`«destructured»`): `Promise`<{ `applicationDecryptor`: `ApplicationDataEncryptorI` ; `instance`: `Instance` }\>
210
227
 
211
228
  Decrypts any encrypted properties included in the supplied `instanceData`.
212
229
  If nothing is encrypted the supplied `instanceData` is returned.
@@ -219,24 +236,48 @@ supply a `onCorruptedData` function which returns a value to use instead.
219
236
 
220
237
  | Name | Type |
221
238
  | :------ | :------ |
222
- | `__namedParameters` | `Object` |
223
- | `__namedParameters.apiToken` | `string` |
224
- | `__namedParameters.apiUrl` | `string` |
225
- | `__namedParameters.instanceData` | `Instance` |
226
- | `__namedParameters.maxcryptor` | `DataEncryptorI` |
227
- | `__namedParameters.onCorruptedData?` | (`fieldName`: `string`, `fieldValue`: `Encrypted`<`string`\>, `error`: `Error`) => `any` |
239
+ | `«destructured»` | `Object` |
240
+ | › `apiToken` | `string` |
241
+ | › `apiUrl` | `string` |
242
+ | › `instanceData` | `Instance` |
243
+ | › `maxcryptor` | `DataEncryptorI` |
244
+ | › `onCorruptedData?` | (`fieldName`: `string`, `fieldValue`: `Encrypted`, `error`: `Error`) => `any` |
228
245
 
229
246
  #### Returns
230
247
 
231
- `Promise`<`Object`\>
248
+ `Promise`<{ `applicationDecryptor`: `ApplicationDataEncryptorI` ; `instance`: `Instance` }\>
232
249
 
233
250
  a copy of `instanceData` with all properties decrypted.
234
251
 
235
252
  ___
236
253
 
254
+ ### evaluateRule
255
+
256
+ ▸ **evaluateRule**(`rule`, `data`): `Object`
257
+
258
+ evaluates an individual rule, normally you should use [calculateScore](#calculatescore)
259
+
260
+ #### Parameters
261
+
262
+ | Name | Type |
263
+ | :------ | :------ |
264
+ | `rule` | `ScoreRule` |
265
+ | `data` | `RuleData` |
266
+
267
+ #### Returns
268
+
269
+ `Object`
270
+
271
+ | Name | Type |
272
+ | :------ | :------ |
273
+ | `passed` | `boolean` |
274
+ | `score` | `number` |
275
+
276
+ ___
277
+
237
278
  ### findSchemaLabel
238
279
 
239
- `Const` **findSchemaLabel**(`labels`): `undefined` \| `string`
280
+ ▸ **findSchemaLabel**(`labels`): `undefined` \| `string`
240
281
 
241
282
  Finds the label (on a profile object) which is the schema name
242
283
 
@@ -254,7 +295,7 @@ ___
254
295
 
255
296
  ### fromCognitoAttributes
256
297
 
257
- `Const` **fromCognitoAttributes**(`attributes`): `UserDoc`
298
+ ▸ **fromCognitoAttributes**(`attributes`): `UserDoc`
258
299
 
259
300
  This function converts Cognito's userAttributes into a maxcryptor UserDoc.
260
301
  The userAttributes come from `const attributes = await Auth.userAttributes(user)`
@@ -273,20 +314,24 @@ ___
273
314
 
274
315
  ### getAADecryptor
275
316
 
276
- ▸ **getAADecryptor**(`__namedParameters`): `Promise`<`Object`\>
317
+ ▸ **getAADecryptor**(`«destructured»`): `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyNId`: `NId` }\>
277
318
 
278
319
  Fetchs the public and private keys for an Access Application, then initializes
279
- the [Maxcryptor](https://npm.im/@raytio/maxcryptor)'s `ApplicationEncryptor`.
320
+ the [https://npm.im/@raytio/maxcryptor|Maxcryptor](https://npm.im/@raytio/maxcryptor|Maxcryptor)'s `ApplicationEncryptor`.
280
321
 
281
322
  #### Parameters
282
323
 
283
324
  | Name | Type |
284
325
  | :------ | :------ |
285
- | `__namedParameters` | `Arg` |
326
+ | `«destructured»` | `Object` |
327
+ | › `aId` | `AId` |
328
+ | › `apiToken` | `string` |
329
+ | › `apiUrl` | `string` |
330
+ | › `maxcryptor` | `DataEncryptorI` |
286
331
 
287
332
  #### Returns
288
333
 
289
- `Promise`<`Object`\>
334
+ `Promise`<{ `decryptor`: `ApplicationEncryptor` ; `publicKeyNId`: `NId` }\>
290
335
 
291
336
  an `ApplicationEncryptor` and the public key of the Access Application
292
337
 
@@ -294,7 +339,7 @@ ___
294
339
 
295
340
  ### getOwnRealVerifications
296
341
 
297
- `Const` **getOwnRealVerifications**(`__namedParameters`): `Promise`<`RealVer`[]\>
342
+ ▸ **getOwnRealVerifications**(`«destructured»`): `Promise`<`RealVer`[]\>
298
343
 
299
344
  Given a list of verifications and decrypted profile objects, this function
300
345
  locally verifies the credibility of the signatures in the verifications.
@@ -305,10 +350,10 @@ This function does NOT call the API, except to fetch the public key.
305
350
 
306
351
  | Name | Type |
307
352
  | :------ | :------ |
308
- | `__namedParameters` | `Object` |
309
- | `__namedParameters.profileObjects` | `ProfileObject`<`Json`\>[] |
310
- | `__namedParameters.userId` | `UId` |
311
- | `__namedParameters.verifications` | `Verification`<``false``\>[] |
353
+ | `«destructured»` | `Object` |
354
+ | › `profileObjects` | `ProfileObject`[] |
355
+ | › `userId` | `UId` |
356
+ | › `verifications` | `Verification`[] |
312
357
 
313
358
  #### Returns
314
359
 
@@ -320,7 +365,7 @@ ___
320
365
 
321
366
  ### getPOVerification
322
367
 
323
- ▸ **getPOVerification**(`__namedParameters`): `Object`
368
+ ▸ **getPOVerification**(`«destructured»`): `Object`
324
369
 
325
370
  Determines the verification status of a profile object, and its individual fields.
326
371
 
@@ -328,10 +373,10 @@ Determines the verification status of a profile object, and its individual field
328
373
 
329
374
  | Name | Type |
330
375
  | :------ | :------ |
331
- | `__namedParameters` | `Object` |
332
- | `__namedParameters.PO` | `ProfileObject`<`Json`\> \| `ProfileObjectForUpload`<`Json`\> |
333
- | `__namedParameters.realVers` | `RealVer`[] |
334
- | `__namedParameters.schema` | `Schema` |
376
+ | `«destructured»` | `Object` |
377
+ | › `PO` | `ProfileObject` \| `ProfileObjectForUpload` |
378
+ | › `realVers` | `RealVer`[] |
379
+ | › `schema` | `Schema` |
335
380
 
336
381
  #### Returns
337
382
 
@@ -339,9 +384,7 @@ Determines the verification status of a profile object, and its individual field
339
384
 
340
385
  | Name | Type |
341
386
  | :------ | :------ |
342
- | `details` | `Object` |
343
- | `details.sourceNId?` | `NId` |
344
- | `details.verifiers` | `VerificationProvider`[] |
387
+ | `details` | [`VerDetails`](#verdetails) |
345
388
  | `fieldVerifications` | `Record`<`string`, `FieldVerification`\> |
346
389
  | `status` | `POVerification` |
347
390
 
@@ -349,7 +392,7 @@ ___
349
392
 
350
393
  ### getSomeoneElsesRealVerifications
351
394
 
352
- `Const` **getSomeoneElsesRealVerifications**(`__namedParameters`): `Promise`<`RealVer`[]\>
395
+ ▸ **getSomeoneElsesRealVerifications**(`«destructured»`): `Promise`<`RealVer`[]\>
353
396
 
354
397
  Given a list of verifications and decrypted profile objects, this function calls
355
398
  the Raytio API to verify the credibility of these verifications, returning only valid
@@ -361,7 +404,7 @@ verifications.
361
404
 
362
405
  | Name | Type |
363
406
  | :------ | :------ |
364
- | `__namedParameters` | `Props` |
407
+ | `«destructured»` | `Props` |
365
408
 
366
409
  #### Returns
367
410
 
@@ -375,7 +418,9 @@ ___
375
418
 
376
419
  ▸ **hashPassword**(`password`): `Promise`<`string`\>
377
420
 
378
- **`deprecated`** legacy feature, see #1252
421
+ **`Deprecated`**
422
+
423
+ legacy feature, see #1252
379
424
 
380
425
  AWS Cognito never gets the raw password. We send them
381
426
  a hashed verison using PBKDF2 with SHA-256 and 10,000
@@ -397,10 +442,21 @@ ___
397
442
 
398
443
  ### isConditionMet
399
444
 
400
- `Const` **isConditionMet**(`condition`, `formValues`): `boolean`
445
+ ▸ **isConditionMet**(`condition`, `formValues`): `boolean`
401
446
 
402
447
  Checks all other form values in case any have a
403
- trigger value that makes this field requirted.
448
+ trigger value that makes this field required.
449
+
450
+ **`Example`**
451
+
452
+ ```json
453
+ [
454
+ { "if": { "age": [17, 18], "city": ["Taupō"] } },
455
+ { "if": { "age": [19, 20] } }
456
+ ]
457
+ ```
458
+
459
+ This means `[(age=17 OR age=18) AND (city=Taupō)] OR [(age=19 OR age=20)]`
404
460
 
405
461
  #### Parameters
406
462
 
@@ -417,7 +473,7 @@ ___
417
473
 
418
474
  ### isEncrypted
419
475
 
420
- `Const` **isEncrypted**(`value`): value is Encrypted<string\>
476
+ ▸ **isEncrypted**(`value`): value is Encrypted
421
477
 
422
478
  Determines where the input is an encrypted Raytio object
423
479
 
@@ -429,7 +485,7 @@ Determines where the input is an encrypted Raytio object
429
485
 
430
486
  #### Returns
431
487
 
432
- value is Encrypted<string\>
488
+ value is Encrypted
433
489
 
434
490
  true or false depending on whether the input is an encrypted Raytio object
435
491
 
@@ -437,7 +493,7 @@ ___
437
493
 
438
494
  ### isEncryptedFile
439
495
 
440
- `Const` **isEncryptedFile**(`value`): value is Encrypted<string\>
496
+ ▸ **isEncryptedFile**(`value`): value is Encrypted
441
497
 
442
498
  Determines where the input is an encrypted Raytio file
443
499
 
@@ -449,7 +505,7 @@ Determines where the input is an encrypted Raytio file
449
505
 
450
506
  #### Returns
451
507
 
452
- value is Encrypted<string\>
508
+ value is Encrypted
453
509
 
454
510
  true or false depending on whether the input is an encrypted Raytio file
455
511
 
@@ -457,7 +513,7 @@ ___
457
513
 
458
514
  ### isScoreConfigValid
459
515
 
460
- `Const` **isScoreConfigValid**(`x`): x is ScoreConfig
516
+ ▸ **isScoreConfigValid**(`x`): x is ScoreConfig
461
517
 
462
518
  determines whether a `ScoreConfig` object is valid
463
519
 
@@ -475,7 +531,7 @@ ___
475
531
 
476
532
  ### isScoreResultValid
477
533
 
478
- `Const` **isScoreResultValid**(`x`): x is ScoreResult
534
+ ▸ **isScoreResultValid**(`x`): x is ScoreResult
479
535
 
480
536
  determines whether a `ScoreResult` object is valid
481
537
 
@@ -491,9 +547,27 @@ x is ScoreResult
491
547
 
492
548
  ___
493
549
 
550
+ ### repairDate
551
+
552
+ ▸ **repairDate**(`date`): `Date`
553
+
554
+ repairs broken ISO dates into valid JS date objects
555
+
556
+ #### Parameters
557
+
558
+ | Name | Type |
559
+ | :------ | :------ |
560
+ | `date` | `string` \| `Date` |
561
+
562
+ #### Returns
563
+
564
+ `Date`
565
+
566
+ ___
567
+
494
568
  ### someEncrypted
495
569
 
496
- `Const` **someEncrypted**<`T`, `K`\>(...`args`): `number`
570
+ ▸ **someEncrypted**<`T`, `K`\>(`...args`): `number`
497
571
 
498
572
  Given a profile object's properties, returns the number
499
573
  of properties that are encryted.
@@ -519,7 +593,7 @@ ___
519
593
 
520
594
  ### toCognitoAttributes
521
595
 
522
- `Const` **toCognitoAttributes**(`userDoc`): `Object`
596
+ ▸ **toCognitoAttributes**(`userDoc`): `Object`
523
597
 
524
598
  Given a `UserDoc` from the maxcryptor, this returns an object
525
599
  which you can provide to `Auth.updateUserAttributes()`. It is
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable no-console */
4
+ const child_process_1 = require("child_process");
5
+ const fs_1 = require("fs");
6
+ const util_1 = require("util");
7
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
8
+ describe("docs", () => {
9
+ it("generates a nice README for @raytio/core & @raytio/types", async () => {
10
+ console.log("(1/4) Running `yarn docs` for core...");
11
+ console.log(Object.values(await execAsync("yarn docs")).join("\n"));
12
+ console.log("(2/4) Reading README.md for core...");
13
+ const readmeCore = await fs_1.promises.readFile("README.md", { encoding: "utf-8" });
14
+ expect(readmeCore).toMatchSnapshot();
15
+ // types & core are in the same test to avoid jest parallelizing them
16
+ console.log("(3/4) Running `yarn docs` for types...");
17
+ console.log(Object.values(await execAsync("cd ../types && yarn docs")).join("\n"));
18
+ console.log("(4/4) Reading README.md for types...");
19
+ const readmeTypes = await fs_1.promises.readFile("../types/README.md", {
20
+ encoding: "utf-8",
21
+ });
22
+ expect(readmeTypes).toMatchSnapshot();
23
+ }, 30000);
24
+ });
@@ -1,11 +1,16 @@
1
- import { ApplicationEncryptor } from "@raytio/maxcryptor";
2
- import { NId } from "@raytio/types";
1
+ import { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
2
+ import { NId, AId } from "@raytio/types";
3
3
  /**
4
4
  * Fetchs the public and private keys for an Access Application, then initializes
5
5
  * the {@link https://npm.im/@raytio/maxcryptor|Maxcryptor}'s `ApplicationEncryptor`.
6
6
  * @returns an `ApplicationEncryptor` and the public key of the Access Application
7
7
  */
8
- export declare function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }: Arg): Promise<{
8
+ export declare function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }: {
9
+ aId: AId;
10
+ apiUrl: string;
11
+ maxcryptor: Maxcryptor;
12
+ apiToken: string;
13
+ }): Promise<{
9
14
  decryptor: ApplicationEncryptor;
10
15
  publicKeyNId: NId;
11
16
  }>;
@@ -4,13 +4,13 @@ import { Encrypted } from "@raytio/types";
4
4
  * @param value anything
5
5
  * @returns true or false depending on whether the input is an encrypted Raytio object
6
6
  */
7
- export declare const isEncrypted: (value: unknown) => value is Encrypted<string>;
7
+ export declare const isEncrypted: (value: unknown) => value is Encrypted;
8
8
  /**
9
9
  * Determines where the input is an encrypted Raytio file
10
10
  * @param value anything
11
11
  * @returns true or false depending on whether the input is an encrypted Raytio file
12
12
  */
13
- export declare const isEncryptedFile: (value: unknown) => value is Encrypted<string>;
13
+ export declare const isEncryptedFile: (value: unknown) => value is Encrypted;
14
14
  /**
15
15
  * Given a profile object's properties, returns the number
16
16
  * of properties that are encryted.
@@ -1,7 +1,17 @@
1
- declare type ConditionValue = string | number | boolean;
1
+ type ConditionValue = string | number | boolean;
2
2
  /**
3
3
  * Checks all other form values in case any have a
4
- * trigger value that makes this field requirted.
4
+ * trigger value that makes this field required.
5
+ *
6
+ * @example
7
+ * ```json
8
+ * [
9
+ * { "if": { "age": [17, 18], "city": ["Taupō"] } },
10
+ * { "if": { "age": [19, 20] } }
11
+ * ]
12
+ * ```
13
+ *
14
+ * This means `[(age=17 OR age=18) AND (city=Taupō)] OR [(age=19 OR age=20)]`
5
15
  */
6
16
  export declare const isConditionMet: (condition: Record<string, ConditionValue[]>, formValues: Record<string, unknown>) => boolean;
7
17
  export {};
@@ -3,7 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isConditionMet = void 0;
4
4
  /**
5
5
  * Checks all other form values in case any have a
6
- * trigger value that makes this field requirted.
6
+ * trigger value that makes this field required.
7
+ *
8
+ * @example
9
+ * ```json
10
+ * [
11
+ * { "if": { "age": [17, 18], "city": ["Taupō"] } },
12
+ * { "if": { "age": [19, 20] } }
13
+ * ]
14
+ * ```
15
+ *
16
+ * This means `[(age=17 OR age=18) AND (city=Taupō)] OR [(age=19 OR age=20)]`
7
17
  */
8
18
  const isConditionMet = (condition, formValues) => {
9
19
  // .every() illogically returns true for arrays with zero length
@@ -0,0 +1,2 @@
1
+ /** repairs broken ISO dates into valid JS date objects */
2
+ export declare function repairDate(date: Date | string): Date;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.repairDate = void 0;
4
+ /** repairs broken ISO dates into valid JS date objects */
5
+ function repairDate(date) {
6
+ if (date instanceof Date)
7
+ return date;
8
+ if (typeof date !== "string")
9
+ return new Date(date); // will return an invalid date obj
10
+ if (date.includes("T") && !date.includes("Z") && !date.includes("+")) {
11
+ // it's a weird ISO date from the backend
12
+ // as of #1280, most APIs should return valid dates, but POs or verifications
13
+ // created before July 2022 will still have the invalid dates emebedded in them.
14
+ return new Date(`${date}Z`);
15
+ }
16
+ return new Date(date);
17
+ }
18
+ exports.repairDate = repairDate;
@@ -1,3 +1,4 @@
1
1
  export * from "./conditional";
2
+ export * from "./date";
2
3
  export * from "./password";
3
4
  export * from "./types";
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./conditional"), exports);
18
+ __exportStar(require("./date"), exports);
18
19
  __exportStar(require("./password"), exports);
19
20
  __exportStar(require("./types"), exports);
@@ -1,6 +1,11 @@
1
- import { RuleData, ScoreConfig } from "./types";
1
+ import { RuleData, ScoreConfig, ScoreRule } from "./types";
2
+ /** evaluates an individual rule, normally you should use {@link calculateScore} */
3
+ export declare function evaluateRule(rule: ScoreRule, data: RuleData): {
4
+ passed: boolean;
5
+ score: number;
6
+ };
2
7
  /** @ignore */
3
- export declare type ScoreResult = {
8
+ export type ScoreResult = {
4
9
  score: number;
5
10
  category: string;
6
11
  categoryColour: string | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateScore = void 0;
3
+ exports.calculateScore = exports.evaluateRule = void 0;
4
4
  const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
5
5
  const helpers_1 = require("./helpers");
6
6
  const general_1 = require("../general");
@@ -24,6 +24,7 @@ function evaluateASTNode(node, data) {
24
24
  }
25
25
  throw new Error("ASTNode has invalid type");
26
26
  }
27
+ /** evaluates an individual rule, normally you should use {@link calculateScore} */
27
28
  function evaluateRule(rule, data) {
28
29
  if (rule.tree.length !== 1) {
29
30
  throw new Error("A rule may only have 1 root node");
@@ -34,6 +35,7 @@ function evaluateRule(rule, data) {
34
35
  score: rulePassed ? rule.trueWeight : rule.falseWeight,
35
36
  };
36
37
  }
38
+ exports.evaluateRule = evaluateRule;
37
39
  /**
38
40
  * We guarantee that the same configId or ruleId will always produce the same output.
39
41
  * This is the closest thing we have to versioning.
@@ -44,7 +46,11 @@ const jsonId = (json) => (0, general_1.hashPassword)(JSON.stringify(json)).then(
44
46
  * Might throw an error.
45
47
  */
46
48
  async function calculateScore(ruleConfig, ruleInput) {
47
- const result = ruleConfig.rules.map(rule => evaluateRule(rule, ruleInput));
49
+ const activeRules = ruleConfig.rules.filter(rule => rule.enabled !== false);
50
+ if (!activeRules.length) {
51
+ throw new Error("There are no enabled rules");
52
+ }
53
+ const result = activeRules.map(rule => evaluateRule(rule, ruleInput));
48
54
  const [addOrMultiply, initialValue] = (0, helpers_1.getCombinator)(ruleConfig.combinator);
49
55
  const finalScore = result
50
56
  .map(x => x.score)
@@ -1,3 +1,3 @@
1
- import { Instance, RealVer, Schema } from "@raytio/types";
1
+ import { ProfileObject, RealVer, Schema } from "@raytio/types";
2
2
  import { RuleData } from "./types";
3
- export declare const convertInstanceToRuleInput: (instance: Instance, realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
3
+ export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
@@ -26,10 +26,9 @@ const isDateField = (schema) => ([fieldName]) => {
26
26
  var _a;
27
27
  return (_a = schema.properties[fieldName].tags) === null || _a === void 0 ? void 0 : _a.some(tag => tag.startsWith("group:date_picker"));
28
28
  };
29
- const convertInstanceToRuleInput = async (instance, realVers, getSchema) => {
29
+ const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
30
30
  const out = {};
31
- // eslint-disable-next-line fp/no-loops
32
- for (const PO of instance.profile_objects) {
31
+ for (const PO of POs) {
33
32
  const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
34
33
  // eslint-disable-next-line no-continue
35
34
  if (schemaName === VERIFICATION_SCHEMA)
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluateScoreCondition = void 0;
4
- /* eslint-disable fp/no-loops */
5
4
  const ramda_1 = require("ramda");
6
5
  const general_1 = require("../general");
7
6
  const operators_1 = require("./operators");