@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.
Files changed (99) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +126 -30
  3. package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.d.ts +1 -0
  4. package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.js +28 -0
  5. package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.d.ts +1 -0
  6. package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.js +23 -0
  7. package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.d.ts +1 -0
  8. package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.js +27 -0
  9. package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.d.ts +1 -0
  10. package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.js +30 -0
  11. package/dist/accessApplication/api/fetchKeysForSubmission.d.ts +12 -0
  12. package/dist/accessApplication/api/fetchKeysForSubmission.js +15 -0
  13. package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.d.ts +6 -0
  14. package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.js +24 -0
  15. package/dist/accessApplication/api/fetchRelationshipsForSubmission.d.ts +6 -0
  16. package/dist/accessApplication/api/fetchRelationshipsForSubmission.js +9 -0
  17. package/dist/accessApplication/api/getMissingDataForInstance.d.ts +10 -0
  18. package/dist/accessApplication/api/getMissingDataForInstance.js +28 -0
  19. package/dist/accessApplication/api/index.d.ts +2 -0
  20. package/dist/accessApplication/api/index.js +18 -0
  21. package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.d.ts +1 -0
  22. package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.js +37 -0
  23. package/dist/accessApplication/api/legacy/convertRelationships.d.ts +16 -0
  24. package/dist/accessApplication/api/legacy/convertRelationships.js +20 -0
  25. package/dist/accessApplication/api/legacy/index.d.ts +1 -0
  26. package/dist/accessApplication/api/legacy/index.js +17 -0
  27. package/dist/accessApplication/createAA.d.ts +4 -1
  28. package/dist/accessApplication/createAA.js +70 -19
  29. package/dist/accessApplication/index.d.ts +1 -0
  30. package/dist/accessApplication/index.js +1 -0
  31. package/dist/crypto/cognitoAttributes.d.ts +1 -1
  32. package/dist/crypto/decryptSharedData.d.ts +3 -3
  33. package/dist/crypto/decryptSharedData.js +2 -5
  34. package/dist/crypto/getAADecryptor.d.ts +18 -3
  35. package/dist/crypto/getAADecryptor.js +10 -11
  36. package/dist/crypto/helpers.d.ts +2 -2
  37. package/dist/general/date.js +1 -2
  38. package/dist/general/password.js +1 -2
  39. package/dist/general/types.d.ts +9 -0
  40. package/dist/general/types.js +11 -2
  41. package/dist/rules/calculateScore.d.ts +1 -1
  42. package/dist/rules/calculateScore.js +2 -3
  43. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  44. package/dist/rules/convertInstanceToRuleInput.js +5 -2
  45. package/dist/rules/evaluateScoreCondition.d.ts +1 -1
  46. package/dist/rules/evaluateScoreCondition.js +1 -2
  47. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +1 -1
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +1 -1
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +1 -1
  50. package/dist/rules/helpers/checkTypeofValue.js +2 -3
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +1 -1
  52. package/dist/rules/helpers/getValuesFromPath.js +1 -2
  53. package/dist/rules/helpers/thresholds.d.ts +1 -1
  54. package/dist/rules/helpers/thresholds.js +2 -3
  55. package/dist/rules/operators/bool.d.ts +1 -1
  56. package/dist/rules/operators/date.d.ts +1 -1
  57. package/dist/rules/operators/hfield.d.ts +1 -1
  58. package/dist/rules/operators/hschema.d.ts +1 -1
  59. package/dist/rules/operators/index.d.ts +1 -1
  60. package/dist/rules/operators/number.d.ts +1 -1
  61. package/dist/rules/operators/string.d.ts +1 -1
  62. package/dist/rules/types/config.d.ts +4 -3
  63. package/dist/rules/types/dataValueTypes.d.ts +2 -3
  64. package/dist/rules/types/internal.d.ts +4 -3
  65. package/dist/rules/validate.d.ts +2 -2
  66. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +2 -2
  67. package/dist/schema/expandSchema/__tests__/i18n.test.js +1 -1
  68. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +2 -2
  69. package/dist/schema/expandSchema/__tests__/processSchema.test.js +2 -2
  70. package/dist/schema/expandSchema/addLoadingTimes.d.ts +1 -1
  71. package/dist/schema/expandSchema/constants.d.ts +1 -1
  72. package/dist/schema/expandSchema/expandSchema.d.ts +1 -1
  73. package/dist/schema/expandSchema/expandSchema.js +1 -2
  74. package/dist/schema/expandSchema/maybeUseI18n.d.ts +1 -1
  75. package/dist/schema/expandSchema/processSchema.d.ts +1 -1
  76. package/dist/schema/expandSchema/processSchema.js +12 -10
  77. package/dist/schema/expandSchema/removePrivateFields.d.ts +57 -49
  78. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +3 -3
  79. package/dist/schema/expandSchema/sortSchemaProperties.js +2 -2
  80. package/dist/schema/expandSchema/unwrapSchema.d.ts +2 -6
  81. package/dist/schema/expandSchema/unwrapSchema.js +1 -2
  82. package/dist/schema/labels.d.ts +2 -1
  83. package/dist/testHelpers.d.ts +2 -2
  84. package/dist/verifications/getPOVerification.d.ts +1 -1
  85. package/dist/verifications/getPOVerification.js +1 -2
  86. package/dist/verifications/index.d.ts +0 -1
  87. package/dist/verifications/index.js +0 -1
  88. package/dist/verifications/safeHarbour.d.ts +2 -2
  89. package/dist/verifications/safeHarbour.js +4 -4
  90. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +3 -3
  91. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +2 -2
  92. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +1 -1
  93. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
  94. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +1 -1
  95. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +1 -1
  96. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +2 -2
  97. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +1 -1
  98. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +4 -2
  99. package/package.json +6 -42
@@ -0,0 +1,17 @@
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("./convertRelationships"), exports);
@@ -1,5 +1,8 @@
1
1
  import type { Maxcryptor, UserDoc } from "@raytio/maxcryptor";
2
- import type { AA } from "@raytio/types";
2
+ import type { AA, AId } from "@raytio/types";
3
+ export type ServerAA = Omit<AA, "a_id"> & {
4
+ id: AId;
5
+ };
3
6
  /**
4
7
  * Creates an Access Application and associated public+private keys.
5
8
  *
@@ -1,27 +1,70 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAA = void 0;
14
+ exports.createAA = createAA;
4
15
  const util_1 = require("../util");
5
16
  /** @internal */
6
- const createApplication = ({ apiUrl, apiToken, application, }) => fetch(`${apiUrl}/share/v2/access_application`, {
17
+ const createApplication = ({ apiUrl, apiToken, application, }) => fetch(`${apiUrl}/db/v1/dsm_access_applications`, {
7
18
  method: "POST",
8
19
  body: JSON.stringify(application),
9
- headers: { Authorization: `Bearer ${apiToken}` },
20
+ headers: {
21
+ Authorization: `Bearer ${apiToken}`,
22
+ "Content-Type": "application/json",
23
+ Prefer: "return=representation",
24
+ },
25
+ }).then(util_1.handleResponse);
26
+ /** @internal */
27
+ const createAATransitions = async ({ apiUrl, apiToken, transitions, }) => fetch(`${apiUrl}/db/v1/dsm_access_application_transitions`, {
28
+ method: "POST",
29
+ body: JSON.stringify(transitions),
30
+ headers: {
31
+ Authorization: `Bearer ${apiToken}`,
32
+ "Content-Type": "application/json",
33
+ },
10
34
  }).then(util_1.handleResponse);
11
35
  /** @internal */
12
36
  const createApplicationPublicKey = async ({ apiUrl, apiToken, aId, publicKey, }) => {
13
- const PO = await fetch(`${apiUrl}/share/v2/access_application/${aId}/public_key`, {
37
+ const PO = await fetch(`${apiUrl}/db/v1/dsm_access_application_public_keys`, {
14
38
  method: "POST",
15
- body: JSON.stringify({ a_id: aId, key: publicKey }),
16
- headers: { Authorization: `Bearer ${apiToken}` },
39
+ headers: {
40
+ Authorization: `Bearer ${apiToken}`,
41
+ Accept: "application/json",
42
+ "Content-Type": "application/json",
43
+ Prefer: "return=representation",
44
+ },
45
+ body: JSON.stringify({
46
+ aa_id: aId,
47
+ public_key: publicKey,
48
+ metadata: null,
49
+ }),
17
50
  }).then(util_1.handleResponse);
18
- return { publicKeyNId: PO.n_id };
51
+ // temporary typecast until this API is updated
52
+ return { publicKeyId: PO[0].id };
19
53
  };
20
54
  /** @internal */
21
- const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken, publicKeyNId, encryptedPrivateKey, }) => fetch(`${apiUrl}/share/v2/access_application/public_key/${publicKeyNId}/private_key`, {
55
+ const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken, aId, publicKeyId, encryptedPrivateKey, }) => fetch(`${apiUrl}/db/v1/dsm_access_application_private_keys`, {
22
56
  method: "POST",
23
- body: JSON.stringify({ n_id: publicKeyNId, key: encryptedPrivateKey }),
24
- headers: { Authorization: `Bearer ${apiToken}` },
57
+ headers: {
58
+ Authorization: `Bearer ${apiToken}`,
59
+ Accept: "application/json",
60
+ "Content-Type": "application/json",
61
+ Prefer: "return=representation",
62
+ },
63
+ body: JSON.stringify({
64
+ aa_id: aId,
65
+ aack_id: publicKeyId,
66
+ encrypted_private_key: encryptedPrivateKey,
67
+ }),
25
68
  }).then(util_1.handleResponse);
26
69
  /** @internal */
27
70
  async function createApplicationEncryptor(userDoc, maxcryptor) {
@@ -45,27 +88,35 @@ async function createApplicationEncryptor(userDoc, maxcryptor) {
45
88
  * as well as the `userDoc` data which is stored in the user's cognito attributes.
46
89
  */
47
90
  async function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, }) {
48
- if (!application.org_id) {
49
- throw new Error("Cannot create an AA without an org_id");
91
+ if (!application.customer_id) {
92
+ throw new Error("Cannot create an AA without a customer_id");
50
93
  }
51
- const newApp = await createApplication({
94
+ const { transitions } = application, applicationWithoutTransitions = __rest(application, ["transitions"]);
95
+ const createAAResponse = await createApplication({
52
96
  apiUrl,
53
97
  apiToken,
54
- application,
98
+ application: applicationWithoutTransitions,
99
+ });
100
+ const _a = createAAResponse[0], { id: newAppID } = _a, restOfNewApp = __rest(_a, ["id"]);
101
+ const transitionsWithAid = (transitions || []).map(item => (Object.assign(Object.assign({}, item), { aa_id: newAppID })));
102
+ await createAATransitions({
103
+ apiUrl,
104
+ apiToken,
105
+ transitions: transitionsWithAid,
55
106
  });
56
107
  const { publicKey, encryptedPrivateKey } = await createApplicationEncryptor(userDoc, maxcryptor);
57
- const { publicKeyNId } = await createApplicationPublicKey({
108
+ const { publicKeyId } = await createApplicationPublicKey({
58
109
  apiUrl,
59
110
  apiToken,
60
- aId: newApp.a_id,
111
+ aId: newAppID,
61
112
  publicKey,
62
113
  });
63
114
  await createApplicationEncryptedPrivateKey({
64
115
  apiUrl,
65
116
  apiToken,
66
- publicKeyNId,
117
+ aId: newAppID,
118
+ publicKeyId,
67
119
  encryptedPrivateKey,
68
120
  });
69
- return newApp;
121
+ return Object.assign({ a_id: newAppID }, restOfNewApp);
70
122
  }
71
- exports.createAA = createAA;
@@ -1 +1,2 @@
1
+ export * from "./api";
1
2
  export * from "./createAA";
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
17
18
  __exportStar(require("./createAA"), exports);
@@ -1,4 +1,4 @@
1
- import { UserDoc } from "@raytio/maxcryptor";
1
+ import type { UserDoc } from "@raytio/maxcryptor";
2
2
  import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
3
3
  /**
4
4
  * Given a `UserDoc` from the maxcryptor, this returns an object
@@ -1,5 +1,5 @@
1
- import { Maxcryptor, ApplicationEncryptor } from "@raytio/maxcryptor";
2
- import { Encrypted, Instance } from "@raytio/types";
1
+ import type { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
2
+ import type { Encrypted, Instance } from "@raytio/types";
3
3
  /**
4
4
  * Decrypts any encrypted properties included in the supplied `instanceData`.
5
5
  * If nothing is encrypted the supplied `instanceData` is returned.
@@ -19,7 +19,7 @@ export declare const decryptSharedData: ({ instanceData, maxcryptor, apiUrl, api
19
19
  * If you supply a function, it will be called instead of throwing an error,
20
20
  * and the value you return will be used instead of the corrupted field value.
21
21
  */
22
- onCorruptedData?: ((fieldName: string, fieldValue: Encrypted, error: Error) => any) | undefined;
22
+ onCorruptedData?: (fieldName: string, fieldValue: Encrypted, error: Error) => any;
23
23
  }) => Promise<{
24
24
  instance: Instance;
25
25
  applicationDecryptor: ApplicationEncryptor;
@@ -15,16 +15,13 @@ const decryptKeys_1 = require("./decryptKeys");
15
15
  */
16
16
  const decryptSharedData = async ({ instanceData, maxcryptor, apiUrl, apiToken, onCorruptedData, }) => {
17
17
  const { decryptor: applicationDecryptor } = await (0, getAADecryptor_1.getAADecryptor)({
18
- aId: instanceData.a_id,
18
+ aId: instanceData.aa_id,
19
19
  maxcryptor,
20
20
  apiUrl,
21
21
  apiToken,
22
22
  });
23
23
  const instance = Object.assign(Object.assign({}, instanceData), { profile_objects: await Promise.all(instanceData.profile_objects.map(async (PO) => {
24
- const realNId = PO.n_id.startsWith("HASHED::")
25
- ? PO.n_id.split("::")[1]
26
- : PO.n_id;
27
- const keys = instanceData.keys[realNId];
24
+ const keys = instanceData.keys[PO.id];
28
25
  const decryptedProperties = await (0, decryptKeys_1.decryptKeys)({
29
26
  applicationDecryptor,
30
27
  keys,
@@ -1,5 +1,19 @@
1
- import { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
2
- import { NId, AId } from "@raytio/types";
1
+ import type { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
2
+ import type { AId, CommonFields as CommonNodeFields, KId } from "@raytio/types";
3
+ type PublicKeyNode = CommonNodeFields<KId> & {
4
+ public_key_name: string;
5
+ public_key_description: string;
6
+ public_key: JsonWebKey;
7
+ };
8
+ /**
9
+ * Fetches the Public Key Information for an Access Application
10
+ * @returns the id and Key information of the Applications Public Key
11
+ */
12
+ export declare function getAAPublicKey({ apiUrl, apiToken, aId, }: {
13
+ apiUrl: string;
14
+ apiToken: string;
15
+ aId: AId;
16
+ }): Promise<PublicKeyNode>;
3
17
  /**
4
18
  * Fetchs the public and private keys for an Access Application, then initializes
5
19
  * the {@link https://npm.im/@raytio/maxcryptor|Maxcryptor}'s `ApplicationEncryptor`.
@@ -12,5 +26,6 @@ export declare function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }: {
12
26
  apiToken: string;
13
27
  }): Promise<{
14
28
  decryptor: ApplicationEncryptor;
15
- publicKeyNId: NId;
29
+ publicKeyId: KId;
16
30
  }>;
31
+ export {};
@@ -1,27 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAADecryptor = void 0;
3
+ exports.getAAPublicKey = getAAPublicKey;
4
+ exports.getAADecryptor = getAADecryptor;
4
5
  const util_1 = require("../util");
5
6
  /**
6
7
  * Fetches the Public Key Information for an Access Application
7
8
  * @returns the id and Key information of the Applications Public Key
8
9
  */
9
- async function fetchPublicKey({ apiUrl, apiToken, aId, }) {
10
+ async function getAAPublicKey({ apiUrl, apiToken, aId, }) {
10
11
  const [publicKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_public_keys?aa_id=eq.${aId}`, {
11
12
  headers: { Authorization: `Bearer ${apiToken}` },
12
13
  }).then(util_1.handleResponse);
13
14
  if (!publicKey) {
14
15
  throw new Error("Could not Find Encryption Key");
15
16
  }
16
- const { id, public_key } = publicKey;
17
- return { n_id: id, properties: public_key };
17
+ return publicKey;
18
18
  }
19
19
  /**
20
20
  * Fetches the Private Key Information from a Public Key
21
21
  * @returns An encrypted Private Key
22
22
  */
23
- async function fetchPrivateKey({ apiUrl, apiToken, publicKeyNId, }) {
24
- const [privateKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_private_keys?aack_id=eq.${publicKeyNId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
23
+ async function fetchPrivateKey({ apiUrl, apiToken, publicKeyId, }) {
24
+ const [privateKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_private_keys?aack_id=eq.${publicKeyId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
25
25
  return privateKey.encrypted_private_key;
26
26
  }
27
27
  /**
@@ -30,19 +30,18 @@ async function fetchPrivateKey({ apiUrl, apiToken, publicKeyNId, }) {
30
30
  * @returns an `ApplicationEncryptor` and the public key of the Access Application
31
31
  */
32
32
  async function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }) {
33
- const { n_id: publicKeyNId, properties: publicKey } = (await fetchPublicKey({
33
+ const { id: publicKeyId, public_key: publicKey } = await getAAPublicKey({
34
34
  apiUrl,
35
35
  apiToken,
36
36
  aId,
37
- }));
37
+ });
38
38
  const privateKey = await fetchPrivateKey({
39
39
  apiUrl,
40
40
  apiToken,
41
- publicKeyNId,
41
+ publicKeyId,
42
42
  });
43
43
  return {
44
44
  decryptor: await maxcryptor.loadApplicationEncryptorForDecryption(publicKey, privateKey),
45
- publicKeyNId,
45
+ publicKeyId,
46
46
  };
47
47
  }
48
- exports.getAADecryptor = getAADecryptor;
@@ -1,4 +1,4 @@
1
- import { Encrypted } from "@raytio/types";
1
+ import type { Encrypted } from "@raytio/types";
2
2
  /**
3
3
  * Determines where the input is an encrypted Raytio object
4
4
  * @param value anything
@@ -15,4 +15,4 @@ export declare const isEncryptedFile: (value: unknown) => value is Encrypted;
15
15
  * Given a profile object's properties, returns the number
16
16
  * of properties that are encryted.
17
17
  */
18
- export declare const someEncrypted: <T extends object, K extends keyof T>(obj: T) => number;
18
+ export declare const someEncrypted: <T extends object>(obj: T) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.repairDate = void 0;
3
+ exports.repairDate = repairDate;
4
4
  /** repairs broken ISO dates into valid JS date objects */
5
5
  function repairDate(date) {
6
6
  if (date instanceof Date)
@@ -15,4 +15,3 @@ function repairDate(date) {
15
15
  }
16
16
  return new Date(date);
17
17
  }
18
- exports.repairDate = repairDate;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hashPassword = void 0;
3
+ exports.hashPassword = hashPassword;
4
4
  // ⚠ updating this value will lock all existing users out of their accounts
5
5
  /** @internal */
6
6
  const SALT = "247 213 94 9 15 236 156 48 194 177 107 216 198 215 169 239";
@@ -28,4 +28,3 @@ async function hashPassword(password) {
28
28
  .join("");
29
29
  return btoa(compositeStr);
30
30
  }
31
- exports.hashPassword = hashPassword;
@@ -1,6 +1,15 @@
1
+ import type { AId, NId } from "@raytio/types";
1
2
  /**
2
3
  * to prevent a key from the JS object prototype (e.g. `__proto__`) from
3
4
  * returning an unexpected value (see #1162)
4
5
  * @ignore
5
6
  */
6
7
  export declare function assertSafeProperty(key: string): asserts key is string;
8
+ /**
9
+ * the API returns hashed {@link NId}s in a separate field,
10
+ * which breaks the whole app. So, we move the hashed ID into
11
+ * the normal `n_id` field, and use a different format.
12
+ *
13
+ * This was first introduced in #1048
14
+ */
15
+ export declare const createHashedNId: (nId: NId, aId: AId) => NId;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertSafeProperty = void 0;
3
+ exports.createHashedNId = void 0;
4
+ exports.assertSafeProperty = assertSafeProperty;
4
5
  /**
5
6
  * to prevent a key from the JS object prototype (e.g. `__proto__`) from
6
7
  * returning an unexpected value (see #1162)
@@ -10,4 +11,12 @@ function assertSafeProperty(key) {
10
11
  if (key in {})
11
12
  throw new Error("Unacceptable object property");
12
13
  }
13
- exports.assertSafeProperty = assertSafeProperty;
14
+ /**
15
+ * the API returns hashed {@link NId}s in a separate field,
16
+ * which breaks the whole app. So, we move the hashed ID into
17
+ * the normal `n_id` field, and use a different format.
18
+ *
19
+ * This was first introduced in #1048
20
+ */
21
+ const createHashedNId = (nId, aId) => `HASHED::${nId}::${aId}`;
22
+ exports.createHashedNId = createHashedNId;
@@ -1,4 +1,4 @@
1
- import { RuleData, ScoreConfig, ScoreRule } from "./types";
1
+ import type { RuleData, ScoreConfig, ScoreRule } from "./types";
2
2
  /** evaluates an individual rule, normally you should use {@link calculateScore} */
3
3
  export declare function evaluateRule(rule: ScoreRule, data: RuleData): {
4
4
  passed: boolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateScore = exports.evaluateRule = void 0;
3
+ exports.evaluateRule = evaluateRule;
4
+ exports.calculateScore = calculateScore;
4
5
  const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
5
6
  const helpers_1 = require("./helpers");
6
7
  const general_1 = require("../general");
@@ -35,7 +36,6 @@ function evaluateRule(rule, data) {
35
36
  score: rulePassed ? rule.trueWeight : rule.falseWeight,
36
37
  };
37
38
  }
38
- exports.evaluateRule = evaluateRule;
39
39
  /**
40
40
  * We guarantee that the same configId or ruleId will always produce the same output.
41
41
  * This is the closest thing we have to versioning.
@@ -79,4 +79,3 @@ async function calculateScore(ruleConfig, ruleInput) {
79
79
  },
80
80
  };
81
81
  }
82
- exports.calculateScore = calculateScore;
@@ -1,3 +1,3 @@
1
- import { ProfileObject, RealVer, Schema } from "@raytio/types";
2
- import { RuleData } from "./types";
3
- export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName: string) => Promise<Schema>) => Promise<RuleData>;
1
+ import type { ProfileObject, RealVer, Schema, SchemaName } from "@raytio/types";
2
+ import type { RuleData } from "./types";
3
+ export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName: SchemaName) => Promise<Schema>) => Promise<RuleData>;
@@ -60,8 +60,11 @@ const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
60
60
  });
61
61
  const dateFieldByCategorys = (0, ramda_1.groupBy)(([fieldName]) => schema.properties[fieldName].tags.find(tag => tag.startsWith("group:date_picker")), validFields.filter(isDateField(schema)));
62
62
  // the three date fields become one pseudo field for the score system
63
- const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, members]) => {
63
+ const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, _members]) => {
64
64
  var _a;
65
+ // obviously this won't be undefined since we're
66
+ // looping through the object.
67
+ const members = _members;
65
68
  const groupName = groupTag.split(":")[2] || "NO_NAME";
66
69
  const memberFieldNames = members.map(x => x[0]);
67
70
  const worstVer = (0, ramda_1.sort)((a, b) => b - a, // find the highest enum value (that's the worst)
@@ -108,7 +111,7 @@ const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
108
111
  return subFields.map(subFieldName => {
109
112
  const value = fieldValue[subFieldName];
110
113
  const hsubfield = {
111
- hField: null,
114
+ hField: null, // you can't access metadata on a subfield
112
115
  type: getTypeofFieldValue(value),
113
116
  value,
114
117
  };
@@ -1,2 +1,2 @@
1
- import { ASTScoreConditionNode, RuleData } from "./types";
1
+ import type { ASTScoreConditionNode, RuleData } from "./types";
2
2
  export declare function evaluateScoreCondition(node: ASTScoreConditionNode, data: RuleData): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.evaluateScoreCondition = void 0;
3
+ exports.evaluateScoreCondition = evaluateScoreCondition;
4
4
  const ramda_1 = require("ramda");
5
5
  const general_1 = require("../general");
6
6
  const operators_1 = require("./operators");
@@ -41,4 +41,3 @@ function evaluateScoreCondition(node, data) {
41
41
  // data value. Return true if ANY of the values return true.
42
42
  return options.some(args => op.implementation(...args));
43
43
  }
44
- exports.evaluateScoreCondition = evaluateScoreCondition;
@@ -15,7 +15,7 @@ const hField = {
15
15
  verifiedBy: ["Waka Kotahi"],
16
16
  };
17
17
  const data = {
18
- ss_NZ_DL: [
18
+ ["ss_NZ_DL"]: [
19
19
  {
20
20
  hSchema,
21
21
  properties: {
@@ -1,4 +1,4 @@
1
- import { ScoreThreshold } from "../types";
1
+ import type { ScoreThreshold } from "../types";
2
2
  /**
3
3
  * @ignore the first and last threshold boundaries are -Infinity and +Infinity.
4
4
  * We override whatever is specified to ensure these boundaries are infinite.
@@ -1,4 +1,4 @@
1
- import { GetTSType, ValueType } from "../types";
1
+ import { type GetTSType, type ValueType } from "../types";
2
2
  /** asserts that the provided `value` meets the constaints of `type` */
3
3
  export declare function checkTypeofValue<T extends ValueType>(type: T, value: unknown): value is GetTSType<T>;
4
4
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.simplifyValueType = exports.checkTypeofValue = void 0;
3
+ exports.checkTypeofValue = checkTypeofValue;
4
+ exports.simplifyValueType = simplifyValueType;
4
5
  const types_1 = require("@raytio/types");
5
6
  const symbols_1 = require("./symbols");
6
7
  const types_2 = require("../types");
@@ -46,7 +47,6 @@ function checkTypeofValue(type, value) {
46
47
  return false;
47
48
  }
48
49
  }
49
- exports.checkTypeofValue = checkTypeofValue;
50
50
  /**
51
51
  * Some types are effectively equivilant (e.g. n_id and string).
52
52
  * Any exceptions defined here should use the same validator in
@@ -57,4 +57,3 @@ function simplifyValueType(type) {
57
57
  return "String";
58
58
  return type;
59
59
  }
60
- exports.simplifyValueType = simplifyValueType;
@@ -1,3 +1,3 @@
1
- import { RuleData, ValuePath } from "../types";
1
+ import type { RuleData, ValuePath } from "../types";
2
2
  /** this returns an array because there might be multiple of the same schema shared */
3
3
  export declare function getValuesFromPath(path: ValuePath, data: RuleData): unknown[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValuesFromPath = void 0;
3
+ exports.getValuesFromPath = getValuesFromPath;
4
4
  const general_1 = require("../../general");
5
5
  /** this returns an array because there might be multiple of the same schema shared */
6
6
  function getValuesFromPath(path, data) {
@@ -47,4 +47,3 @@ function getValuesFromPath(path, data) {
47
47
  throw new Error(`Invalid ValuePath[0] (${type})`);
48
48
  }
49
49
  }
50
- exports.getValuesFromPath = getValuesFromPath;
@@ -1,4 +1,4 @@
1
- import { Combinator, ScoreRule } from "../types";
1
+ import type { Combinator, ScoreRule } from "../types";
2
2
  /** @ignore */
3
3
  export declare function getCombinator(combinator: Combinator): [func: (a: number, b: number) => number, initialValue: number];
4
4
  /** @ignore */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getThresholdBoundary = exports.getCombinator = void 0;
3
+ exports.getCombinator = getCombinator;
4
+ exports.getThresholdBoundary = getThresholdBoundary;
4
5
  /** @ignore */
5
6
  function getCombinator(combinator) {
6
7
  switch (combinator) {
@@ -12,7 +13,6 @@ function getCombinator(combinator) {
12
13
  throw new Error("Invalid combinator");
13
14
  }
14
15
  }
15
- exports.getCombinator = getCombinator;
16
16
  /** @ignore */
17
17
  function getThresholdBoundary(combinator, rules) {
18
18
  switch (combinator) {
@@ -43,4 +43,3 @@ function getThresholdBoundary(combinator, rules) {
43
43
  throw new Error("Invalid combinator");
44
44
  }
45
45
  }
46
- exports.getThresholdBoundary = getThresholdBoundary;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const boolOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const dateOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const fieldOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const schemaOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,3 +1,3 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  /** @ignore */
3
3
  export declare const operators: Record<OperatorID, OperatorDef>;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const numberOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,2 +1,2 @@
1
- import { OperatorID, OperatorDef } from "../types";
1
+ import type { OperatorDef, OperatorID } from "../types";
2
2
  export declare const stringOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,4 +1,5 @@
1
- import { GetTSType } from "./dataValueTypes";
1
+ import type { SchemaName } from "@raytio/types";
2
+ import type { GetTSType } from "./dataValueTypes";
2
3
  /**
3
4
  * @ignore
4
5
  * these are just IDs, the string is never parsed by anything.
@@ -11,9 +12,9 @@ export type OperatorID = "bool_eq" | "bool_neq" | "num_eq" | "num_neq" | "num_lt
11
12
  /** @ignore */
12
13
  export type ValuePathFieldProp = "meta" | "value" | "valueLength" | `subField|${string}`;
13
14
  /** @ignore */
14
- export type ValuePath = [type: "schema", schemaName: string, prop: "meta"] | [
15
+ export type ValuePath = [type: "schema", schemaName: SchemaName, prop: "meta"] | [
15
16
  type: "field",
16
- schemaName: string,
17
+ schemaName: SchemaName,
17
18
  fieldName: string,
18
19
  prop: ValuePathFieldProp
19
20
  ];
@@ -1,12 +1,11 @@
1
- import { FieldVerification, NId, POVerification } from "@raytio/types";
1
+ import type { FieldVerification, NId, POVerification, SchemaName } from "@raytio/types";
2
2
  import type { HFieldSymbol, HSchemaSymbol } from "../helpers";
3
3
  /** undefined if not shared */
4
4
  export type HField = {
5
5
  __typeof__: typeof HFieldSymbol;
6
6
  verification: FieldVerification;
7
7
  verifiedBy: readonly NId[];
8
- /** schemaName */
9
- cameFromSchema: string;
8
+ cameFromSchema: SchemaName;
10
9
  };
11
10
  /** undefined if not shared */
12
11
  export type HSchema = {