@dynamatix/gb-schemas 2.19.1 → 2.20.2
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/README.md +308 -308
- package/dist/applicants/applicant-additional-income.model.d.ts +1 -1
- package/dist/applicants/applicant-additional-income.type.d.ts +1 -1
- package/dist/applicants/applicant-commitment-creditCard.model.d.ts +1 -1
- package/dist/applicants/applicant-commitment-loan.model.d.ts +1 -1
- package/dist/applicants/applicant-commitment-mortgage.model.d.ts +1 -1
- package/dist/applicants/applicant-commitment-residence.model.d.ts +1 -1
- package/dist/applicants/applicant-commitment-secureLoan.model.d.ts +1 -1
- package/dist/applicants/applicant-commitment-unsecuredLoan.model.d.ts +1 -1
- package/dist/applicants/applicant-credit-data.model.d.ts +1 -1
- package/dist/applicants/applicant-credit-profile.model.d.ts +1 -1
- package/dist/applicants/applicant-credit-report.model.d.ts +19 -19
- package/dist/applicants/applicant-credit-report.type.d.ts +1 -1
- package/dist/applicants/applicant-direct-debit.model.d.ts +86 -0
- package/dist/applicants/applicant-direct-debit.model.d.ts.map +1 -0
- package/dist/applicants/applicant-direct-debit.model.js +16 -0
- package/dist/applicants/applicant-employment-income.model.d.ts +1 -1
- package/dist/applicants/applicant-employment-income.type.d.ts +1 -1
- package/dist/applicants/applicant-employment.model.d.ts +1 -1
- package/dist/applicants/applicant-expenditure.model.d.ts +1 -1
- package/dist/applicants/applicant-expenditure.type.d.ts +1 -1
- package/dist/applicants/applicant-income-settings.model.d.ts +1 -1
- package/dist/applicants/applicant-income-settings.type.d.ts +1 -1
- package/dist/applicants/applicant-income-source.model.d.ts +26 -0
- package/dist/applicants/applicant-income-source.model.d.ts.map +1 -0
- package/dist/applicants/applicant-income-summary.model.d.ts +1 -1
- package/dist/applicants/applicant-income-summary.type.d.ts +1 -1
- package/dist/applicants/applicant-income.model.d.ts +160 -0
- package/dist/applicants/applicant-income.model.d.ts.map +1 -0
- package/dist/applicants/applicant-large-exposure.model.d.ts +1 -1
- package/dist/applicants/applicant-large-exposure.type.d.ts +1 -1
- package/dist/applicants/applicant-other-income.model.d.ts +85 -0
- package/dist/applicants/applicant-other-income.model.d.ts.map +1 -0
- package/dist/applicants/applicant-pension-income.model.d.ts +1 -1
- package/dist/applicants/applicant-pension-income.type.d.ts +1 -1
- package/dist/applicants/applicant-property-income.model.d.ts +1 -1
- package/dist/applicants/applicant-property-income.type.d.ts +1 -1
- package/dist/applicants/applicant-risk-narrative.model.d.ts +1 -1
- package/dist/applicants/applicant-self-employed-income.model.d.ts +1 -1
- package/dist/applicants/applicant-self-employed-income.type.d.ts +1 -1
- package/dist/applicants/applicant-self-employment.model.d.ts +1 -1
- package/dist/applicants/applicant-sole-trader-income.model.d.ts +1 -1
- package/dist/applicants/applicant-sole-trader-income.type.d.ts +1 -1
- package/dist/applicants/applicant-uk-tax-credits.model.d.ts +1 -1
- package/dist/applicants/applicant-uk-tax-credits.type.d.ts +1 -1
- package/dist/applicants/applicant-welcome-call.model.d.ts +1 -1
- package/dist/applicants/applicant-welcome-call.model.js +9 -9
- package/dist/applicants/applicant-welcome-call.type.d.ts +1 -1
- package/dist/applicants/applicant.model.d.ts +1 -1
- package/dist/applicants/applicant.model.d.ts.map +1 -1
- package/dist/applicants/applicant.model.js +2 -0
- package/dist/applicants/applicant.type.d.ts +1 -1
- package/dist/applications/application-audit.model.d.ts +1 -1
- package/dist/applications/application-checklist-Item.model.d.ts +1 -1
- package/dist/applications/application-company-model.d.ts +1 -1
- package/dist/applications/application-credit-profile.model.d.ts +1 -1
- package/dist/applications/application-direct-debit.model.d.ts +4 -4
- package/dist/applications/application-direct-debit.model.d.ts.map +1 -1
- package/dist/applications/application-direct-debit.model.js +2 -0
- package/dist/applications/application-direct-debit.type.d.ts +1 -1
- package/dist/applications/application-document.model.d.ts +158 -0
- package/dist/applications/application-document.model.d.ts.map +1 -0
- package/dist/applications/application-euc.model.d.ts +1 -1
- package/dist/applications/application-euc.type.d.ts +1 -1
- package/dist/applications/application-fieldconfig.model.d.ts +1 -1
- package/dist/applications/application-illustration-model.d.ts +1 -1
- package/dist/applications/application-legal.model.d.ts +1 -1
- package/dist/applications/application-mortgage.model.d.ts +1 -1
- package/dist/applications/application-mortgage.type.d.ts +1 -1
- package/dist/applications/application-note.model.d.ts +1 -1
- package/dist/applications/application-note.type.d.ts +1 -1
- package/dist/applications/application-offer.model.d.ts +1 -1
- package/dist/applications/application-offer.type.d.ts +1 -1
- package/dist/applications/application-onboarding.model.d.ts +1 -1
- package/dist/applications/application-product.model.d.ts +1 -1
- package/dist/applications/application-product.type.d.ts +1 -1
- package/dist/applications/application-productfeatures.model.d.ts +1 -1
- package/dist/applications/application-productfeatures.type.d.ts +1 -1
- package/dist/applications/application-rationale.model.d.ts +1 -1
- package/dist/applications/application-rationale.type.d.ts +1 -1
- package/dist/applications/application-risk-narrative.model.d.ts +1 -1
- package/dist/applications/application-valuation-report.model.d.ts +1 -1
- package/dist/applications/application-valuation-report.type.d.ts +1 -1
- package/dist/applications/application-valuation.model.d.ts +1 -1
- package/dist/applications/application-valuation.type.d.ts +1 -1
- package/dist/applications/application.model.d.ts +1 -1
- package/dist/applications/applications-task.model.d.ts +1 -1
- package/dist/applications/applications-task.type.d.ts +1 -1
- package/dist/applications/broker.model.d.ts +1 -1
- package/dist/applications/broker.type.d.ts +1 -1
- package/dist/applications/document.model.d.ts +158 -0
- package/dist/applications/document.model.d.ts.map +1 -0
- package/dist/applications/euc-country-tier.model.d.ts +65 -0
- package/dist/applications/euc-country-tier.model.d.ts.map +1 -0
- package/dist/applications/euc-country-tier.model.js +24 -0
- package/dist/applications/euc-country-tier.type.d.ts +7 -0
- package/dist/applications/euc-country-tier.type.d.ts.map +1 -0
- package/dist/applications/euc-country-tier.type.js +1 -0
- package/dist/applications/index.d.ts +2 -0
- package/dist/applications/index.d.ts.map +1 -1
- package/dist/applications/index.js +1 -0
- package/dist/applications/productfeatures.model.d.ts +368 -0
- package/dist/applications/productfeatures.model.d.ts.map +1 -0
- package/dist/applications/solicitor.model.d.ts +1 -1
- package/dist/applications/solicitor.type.d.ts +1 -1
- package/dist/product-catalogues/product-catalogue.model.d.ts +1 -1
- package/dist/product-catalogues/product-definitions.model.d.ts +1 -1
- package/dist/product-catalogues/product-definitions.type.d.ts +1 -1
- package/dist/product-catalogues/product-variant.model.d.ts +1 -1
- package/dist/product-catalogues/product-variant.type.d.ts +1 -1
- package/dist/properties/property.model.d.ts +1 -1
- package/dist/properties/security.model.d.ts +1 -1
- package/dist/shared/alert.model.d.ts +1 -1
- package/dist/shared/api-log.model.d.ts +1 -1
- package/dist/shared/api-performance.model.d.ts +1 -1
- package/dist/shared/api-performance.type.d.ts +1 -1
- package/dist/shared/apprivo-sync-journey.model.d.ts +1 -1
- package/dist/shared/checklist.model.d.ts +1 -1
- package/dist/shared/document-type-model.d.ts +48 -0
- package/dist/shared/document-type-model.d.ts.map +1 -0
- package/dist/shared/encryption/encrypted-field-map.d.ts +5 -0
- package/dist/shared/encryption/encrypted-field-map.d.ts.map +1 -1
- package/dist/shared/encryption/encrypted-field-map.js +5 -1
- package/dist/shared/encryption/encryption-filter.guard.d.ts +69 -0
- package/dist/shared/encryption/encryption-filter.guard.d.ts.map +1 -0
- package/dist/shared/encryption/encryption-filter.guard.js +103 -0
- package/dist/shared/encryption/encryption.plugin.d.ts +225 -0
- package/dist/shared/encryption/encryption.plugin.d.ts.map +1 -0
- package/dist/shared/encryption/encryption.plugin.js +372 -0
- package/dist/shared/encryption/index.d.ts +2 -0
- package/dist/shared/encryption/index.d.ts.map +1 -1
- package/dist/shared/encryption/index.js +2 -0
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/job-run.model.d.ts +1 -1
- package/dist/shared/job-setting.model.d.ts +1 -1
- package/dist/shared/lookup-group.model.d.ts +1 -1
- package/dist/shared/lookup.model.d.ts +1 -1
- package/dist/shared/schema-doc.model.d.ts +1 -1
- package/dist/shared/system-parameter.model.d.ts +1 -1
- package/dist/shared/task-document.model.d.ts +1 -1
- package/dist/shared/task.model.d.ts +1 -1
- package/dist/shared/webhook-event.model.d.ts +1 -1
- package/dist/shared/workflow-trigger.model.d.ts +1 -1
- package/dist/shared/workflow-trigger.type.d.ts +1 -1
- package/dist/shared/workflow.middleware.d.ts +1 -1
- package/dist/shared/workflow.plugin.d.ts +1 -1
- package/dist/types/base.types.d.ts +1 -1
- package/dist/underwriter/underwriter.model.d.ts +1 -1
- package/dist/users/auth-log.model.d.ts +1 -1
- package/dist/users/permission.model.d.ts +1 -1
- package/dist/users/role-group.model.d.ts +1 -1
- package/dist/users/role.model.d.ts +1 -1
- package/dist/users/tasks.model.d.ts +1 -1
- package/dist/users/user.model.d.ts +1 -1
- package/dist/users/user.type.d.ts +1 -1
- package/dist/value-objects/account-number.d.ts +1 -1
- package/dist/value-objects/pound.d.ts +1 -1
- package/package.json +90 -90
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail-loud guard for queries that touch RANDOM-encrypted fields.
|
|
3
|
+
*
|
|
4
|
+
* RANDOM ciphertext is unqueryable: any filter, equality, range, regex or
|
|
5
|
+
* sort on an encrypted path would silently match nothing (or garbage).
|
|
6
|
+
* The guard converts that class of production data bug into an immediate,
|
|
7
|
+
* descriptive error at the call site — in CI, not in front of a customer.
|
|
8
|
+
*/
|
|
9
|
+
export declare class EncryptionFilterGuard {
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that neither the filter nor the sort of a query references an
|
|
13
|
+
* encrypted path. Recurses through `$and` / `$or` / `$nor` branches and
|
|
14
|
+
* flags parent-object matches (e.g. filtering on a whole subdocument
|
|
15
|
+
* that contains encrypted leaves).
|
|
16
|
+
*
|
|
17
|
+
* @param filter - The query filter as returned by `Query.getFilter()`.
|
|
18
|
+
* @param sort - The sort spec (object or string form) from query options.
|
|
19
|
+
* @param encryptedPaths - Dot paths of all encrypted fields of the model.
|
|
20
|
+
* @throws Error naming the offending path when the query is unsafe.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* EncryptionFilterGuard.assertQuerySafe(
|
|
24
|
+
* { $or: [{ firstName: 'Ann' }] }, undefined, ['firstName']
|
|
25
|
+
* ); // → throws: firstName is RANDOM-encrypted and cannot be filtered
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
static assertQuerySafe(filter: Record<string, unknown> | null | undefined, sort: Record<string, unknown> | string | null | undefined, encryptedPaths: string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Recursively walks one filter node, throwing on any encrypted-path key.
|
|
31
|
+
*
|
|
32
|
+
* @param node - Filter object or logical-operator branch.
|
|
33
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
34
|
+
* @throws Error when a key covers an encrypted path.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // internal use only — called by assertQuerySafe()
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
private static walkFilter;
|
|
41
|
+
/**
|
|
42
|
+
* Asserts that no sort key covers an encrypted path (random ciphertext
|
|
43
|
+
* has no meaningful order).
|
|
44
|
+
*
|
|
45
|
+
* @param sort - Sort spec in object (`{ field: 1 }`) or string (`'-field'`) form.
|
|
46
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
47
|
+
* @throws Error when a sort key covers an encrypted path.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // internal use only — called by assertQuerySafe()
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
private static assertSortSafe;
|
|
54
|
+
/**
|
|
55
|
+
* Matches a filter/sort key against the encrypted paths, including
|
|
56
|
+
* parent-object keys (`bankWizardCheck` covers its encrypted leaves)
|
|
57
|
+
* and child keys under an encrypted leaf.
|
|
58
|
+
*
|
|
59
|
+
* @param key - The filter or sort key to test.
|
|
60
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
61
|
+
* @returns The covered encrypted path, or `undefined` when safe.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* // internal use only
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
private static matchEncryptedPath;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=encryption-filter.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption-filter.guard.d.ts","sourceRoot":"","sources":["../../../shared/encryption/encryption-filter.guard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,qBAAqB;IAC9B,OAAO;IAEP;;;;;;;;;;;;;;;;OAgBG;WACW,eAAe,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EAClD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzD,cAAc,EAAE,MAAM,EAAE,GACzB,IAAI;IAOP;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAkBzB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAqB7B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAKpC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail-loud guard for queries that touch RANDOM-encrypted fields.
|
|
3
|
+
*
|
|
4
|
+
* RANDOM ciphertext is unqueryable: any filter, equality, range, regex or
|
|
5
|
+
* sort on an encrypted path would silently match nothing (or garbage).
|
|
6
|
+
* The guard converts that class of production data bug into an immediate,
|
|
7
|
+
* descriptive error at the call site — in CI, not in front of a customer.
|
|
8
|
+
*/
|
|
9
|
+
export class EncryptionFilterGuard {
|
|
10
|
+
constructor() { }
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that neither the filter nor the sort of a query references an
|
|
13
|
+
* encrypted path. Recurses through `$and` / `$or` / `$nor` branches and
|
|
14
|
+
* flags parent-object matches (e.g. filtering on a whole subdocument
|
|
15
|
+
* that contains encrypted leaves).
|
|
16
|
+
*
|
|
17
|
+
* @param filter - The query filter as returned by `Query.getFilter()`.
|
|
18
|
+
* @param sort - The sort spec (object or string form) from query options.
|
|
19
|
+
* @param encryptedPaths - Dot paths of all encrypted fields of the model.
|
|
20
|
+
* @throws Error naming the offending path when the query is unsafe.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* EncryptionFilterGuard.assertQuerySafe(
|
|
24
|
+
* { $or: [{ firstName: 'Ann' }] }, undefined, ['firstName']
|
|
25
|
+
* ); // → throws: firstName is RANDOM-encrypted and cannot be filtered
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
static assertQuerySafe(filter, sort, encryptedPaths) {
|
|
29
|
+
EncryptionFilterGuard.assertSortSafe(sort, encryptedPaths);
|
|
30
|
+
if (filter) {
|
|
31
|
+
EncryptionFilterGuard.walkFilter(filter, encryptedPaths);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Recursively walks one filter node, throwing on any encrypted-path key.
|
|
36
|
+
*
|
|
37
|
+
* @param node - Filter object or logical-operator branch.
|
|
38
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
39
|
+
* @throws Error when a key covers an encrypted path.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // internal use only — called by assertQuerySafe()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
static walkFilter(node, encryptedPaths) {
|
|
46
|
+
for (const [key, value] of Object.entries(node)) {
|
|
47
|
+
if (key === '$and' || key === '$or' || key === '$nor') {
|
|
48
|
+
for (const branch of value ?? []) {
|
|
49
|
+
EncryptionFilterGuard.walkFilter(branch, encryptedPaths);
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const hit = EncryptionFilterGuard.matchEncryptedPath(key, encryptedPaths);
|
|
54
|
+
if (hit) {
|
|
55
|
+
throw new Error(`Query filter references '${key}': '${hit}' is RANDOM-encrypted and can never be ` +
|
|
56
|
+
'filtered, matched or compared. Query a plaintext predicate field instead.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Asserts that no sort key covers an encrypted path (random ciphertext
|
|
62
|
+
* has no meaningful order).
|
|
63
|
+
*
|
|
64
|
+
* @param sort - Sort spec in object (`{ field: 1 }`) or string (`'-field'`) form.
|
|
65
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
66
|
+
* @throws Error when a sort key covers an encrypted path.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* // internal use only — called by assertQuerySafe()
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
static assertSortSafe(sort, encryptedPaths) {
|
|
73
|
+
if (!sort) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const keys = typeof sort === 'string'
|
|
77
|
+
? sort.split(/\s+/).filter(Boolean).map((key) => key.replace(/^-/, ''))
|
|
78
|
+
: Object.keys(sort);
|
|
79
|
+
for (const key of keys) {
|
|
80
|
+
const hit = EncryptionFilterGuard.matchEncryptedPath(key, encryptedPaths);
|
|
81
|
+
if (hit) {
|
|
82
|
+
throw new Error(`Sort key '${key}': '${hit}' is RANDOM-encrypted — ciphertext has no meaningful ` +
|
|
83
|
+
'order. Sort on a plaintext field instead.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Matches a filter/sort key against the encrypted paths, including
|
|
89
|
+
* parent-object keys (`bankWizardCheck` covers its encrypted leaves)
|
|
90
|
+
* and child keys under an encrypted leaf.
|
|
91
|
+
*
|
|
92
|
+
* @param key - The filter or sort key to test.
|
|
93
|
+
* @param encryptedPaths - Dot paths of all encrypted fields.
|
|
94
|
+
* @returns The covered encrypted path, or `undefined` when safe.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // internal use only
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
static matchEncryptedPath(key, encryptedPaths) {
|
|
101
|
+
return encryptedPaths.find((path) => key === path || path.startsWith(`${key}.`) || key.startsWith(`${path}.`));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/// <reference path="../../value-objects/pound.d.ts" />
|
|
2
|
+
/// <reference path="../../value-objects/account-number.d.ts" />
|
|
3
|
+
/// <reference path="encrypted-field-map.d.ts" />
|
|
4
|
+
/// <reference path="../../value-objects/sort-code.d.ts" />
|
|
5
|
+
/// <reference types="mongoose/types/aggregate.js" />
|
|
6
|
+
/// <reference types="mongoose/types/callback.js" />
|
|
7
|
+
/// <reference types="mongoose/types/collection.js" />
|
|
8
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
9
|
+
/// <reference types="mongoose/types/cursor.js" />
|
|
10
|
+
/// <reference types="mongoose/types/document.js" />
|
|
11
|
+
/// <reference types="mongoose/types/error.js" />
|
|
12
|
+
/// <reference types="mongoose/types/expressions.js" />
|
|
13
|
+
/// <reference types="mongoose/types/helpers.js" />
|
|
14
|
+
/// <reference types="mongoose/types/middlewares.js" />
|
|
15
|
+
/// <reference types="mongoose/types/indexes.js" />
|
|
16
|
+
/// <reference types="mongoose/types/models.js" />
|
|
17
|
+
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
18
|
+
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
19
|
+
/// <reference types="mongoose/types/populate.js" />
|
|
20
|
+
/// <reference types="mongoose/types/query.js" />
|
|
21
|
+
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
22
|
+
/// <reference types="mongoose/types/session.js" />
|
|
23
|
+
/// <reference types="mongoose/types/types.js" />
|
|
24
|
+
/// <reference types="mongoose/types/utility.js" />
|
|
25
|
+
/// <reference types="mongoose/types/validation.js" />
|
|
26
|
+
/// <reference types="mongoose/types/virtuals.js" />
|
|
27
|
+
/// <reference types="mongoose/types/schematypes.js" />
|
|
28
|
+
/// <reference types="mongoose/types/inferschematype.js" />
|
|
29
|
+
/// <reference types="mongoose/types/inferrawdoctype.js" />
|
|
30
|
+
import { Schema } from 'mongoose';
|
|
31
|
+
/**
|
|
32
|
+
* Global Mongoose plugin routing `ghEncrypt: true` fields through the
|
|
33
|
+
* {@link EncryptionService} — plumbing only, no crypto in hooks.
|
|
34
|
+
*
|
|
35
|
+
* Write hooks (`save`, `insertMany`, update/replace queries) encrypt
|
|
36
|
+
* annotated values to BSON Binary subtype 6; read hooks (`find`, `findOne`,
|
|
37
|
+
* `findOneAnd*`, `distinct`) decrypt hydrated docs and `.lean()` results.
|
|
38
|
+
* Filters and sorts on encrypted paths fail loud via
|
|
39
|
+
* {@link EncryptionFilterGuard}. When {@link EncryptionBootstrap} is not
|
|
40
|
+
* initialized, every hook is a transparent pass-through so consumers that
|
|
41
|
+
* have not opted in keep working on plaintext.
|
|
42
|
+
*
|
|
43
|
+
* Annotated paths are re-typed to `Mixed` (original type stashed in
|
|
44
|
+
* `ghOriginalType`) so ciphertext survives Mongoose casting. Aggregation is
|
|
45
|
+
* not interceptable and is handled per call site (Enc-5).
|
|
46
|
+
*/
|
|
47
|
+
export declare class EncryptionPlugin {
|
|
48
|
+
private constructor();
|
|
49
|
+
/**
|
|
50
|
+
* Applies the plugin to a schema: validates and collects annotated
|
|
51
|
+
* paths, re-types them to `Mixed`, and registers guard/write/read hooks.
|
|
52
|
+
* No-op for schemas without annotations; safe to call more than once
|
|
53
|
+
* (encrypt/decrypt transforms are idempotent).
|
|
54
|
+
*
|
|
55
|
+
* @param schema - The Mongoose schema to instrument.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const applicantSchema = new mongoose.Schema({
|
|
59
|
+
* firstName: { type: String, ghEncrypt: true }
|
|
60
|
+
* });
|
|
61
|
+
* EncryptionPlugin.apply(applicantSchema);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
static apply(schema: Schema): void;
|
|
65
|
+
/**
|
|
66
|
+
* Re-types one annotated path to `Mixed` so Binary ciphertext is not
|
|
67
|
+
* mangled by the original String/Number cast, stashing the original
|
|
68
|
+
* BSON type in `ghOriginalType` for the field-map/tooling.
|
|
69
|
+
*
|
|
70
|
+
* @param schema - The owning schema.
|
|
71
|
+
* @param entry - The annotated path being re-typed.
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // internal use only — called by apply()
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
private static retypeToMixed;
|
|
78
|
+
/**
|
|
79
|
+
* Registers fail-loud filter/sort guards on every query hook.
|
|
80
|
+
*
|
|
81
|
+
* @param schema - The owning schema.
|
|
82
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // internal use only — called by apply()
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
private static registerGuardHooks;
|
|
89
|
+
/**
|
|
90
|
+
* Registers encrypt-on-write hooks: `save`, `insertMany` and the
|
|
91
|
+
* update/replace query family (`$set`, `$setOnInsert`, dot paths,
|
|
92
|
+
* parent-object values and full replacement docs).
|
|
93
|
+
*
|
|
94
|
+
* @param schema - The owning schema.
|
|
95
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* // internal use only — called by apply()
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
private static registerWriteHooks;
|
|
102
|
+
/**
|
|
103
|
+
* Registers decrypt-on-read hooks: `find`, the `findOne*` family,
|
|
104
|
+
* `distinct`, plus post-`save`/`insertMany` restores so callers keep
|
|
105
|
+
* seeing plaintext on the documents they just persisted.
|
|
106
|
+
*
|
|
107
|
+
* @param schema - The owning schema.
|
|
108
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // internal use only — called by apply()
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
private static registerReadHooks;
|
|
115
|
+
/**
|
|
116
|
+
* Encrypts annotated values inside an update object: exact dot-path
|
|
117
|
+
* keys, parent-object values containing encrypted leaves, and full
|
|
118
|
+
* replacement documents (updates without atomic operators).
|
|
119
|
+
*
|
|
120
|
+
* @param update - The mutable update object from `Query.getUpdate()`.
|
|
121
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* // internal use only — called by the update-query pre hook
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
private static encryptUpdate;
|
|
128
|
+
/**
|
|
129
|
+
* Applies a value transform to every encrypted path of one target,
|
|
130
|
+
* dispatching between hydrated documents (getter-free `get`/`set`) and
|
|
131
|
+
* plain objects (`.lean()` results, insert payloads).
|
|
132
|
+
*
|
|
133
|
+
* @param target - Hydrated document or plain object; non-objects no-op.
|
|
134
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
135
|
+
* @param transform - Value transform (encrypt or decrypt).
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* // internal use only
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
private static transformTarget;
|
|
142
|
+
/**
|
|
143
|
+
* Applies a transform to every encrypted path of one hydrated document.
|
|
144
|
+
*
|
|
145
|
+
* @param doc - The hydrated Mongoose document.
|
|
146
|
+
* @param paths - Encrypted dot paths of the schema.
|
|
147
|
+
* @param transform - Value transform (encrypt or decrypt).
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* // internal use only
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
private static transformDocument;
|
|
154
|
+
/**
|
|
155
|
+
* Transforms one dot path on a hydrated document, reading with getters
|
|
156
|
+
* disabled so value-object formatters never leak into ciphertext.
|
|
157
|
+
*
|
|
158
|
+
* @param doc - The hydrated Mongoose document.
|
|
159
|
+
* @param path - Encrypted dot path.
|
|
160
|
+
* @param transform - Value transform (encrypt or decrypt).
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* // internal use only
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
private static transformDocPath;
|
|
167
|
+
/**
|
|
168
|
+
* Transforms one segmented path on a plain object, descending nested
|
|
169
|
+
* objects and fanning out over arrays.
|
|
170
|
+
*
|
|
171
|
+
* @param target - Plain object (or array element) being walked.
|
|
172
|
+
* @param segments - Remaining path segments.
|
|
173
|
+
* @param transform - Value transform (encrypt or decrypt).
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* // internal use only
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
private static transformPlain;
|
|
180
|
+
/**
|
|
181
|
+
* Builds the encrypt transform: plaintext → Binary; ciphertext and the
|
|
182
|
+
* uninitialized-bootstrap case pass through untouched.
|
|
183
|
+
*
|
|
184
|
+
* @returns Async value transform used by all write hooks.
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* // internal use only
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
private static encryptTransform;
|
|
191
|
+
/**
|
|
192
|
+
* Builds the decrypt transform: Binary → plaintext; non-ciphertext and
|
|
193
|
+
* the uninitialized-bootstrap case pass through untouched.
|
|
194
|
+
*
|
|
195
|
+
* @returns Async value transform used by all read hooks.
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* // internal use only
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
private static decryptTransform;
|
|
202
|
+
/**
|
|
203
|
+
* Returns the bootstrapped service, or `null` when encryption is not
|
|
204
|
+
* initialized (pass-through mode for non-opted-in consumers).
|
|
205
|
+
*
|
|
206
|
+
* @returns The active {@link EncryptionService} or `null`.
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* // internal use only
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
private static activeService;
|
|
213
|
+
/**
|
|
214
|
+
* Duck-type check for BSON Binary subtype 6 (encrypted) values.
|
|
215
|
+
*
|
|
216
|
+
* @param value - Candidate value.
|
|
217
|
+
* @returns `true` when the value is ciphertext.
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* // internal use only
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
private static isCiphertext;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=encryption.plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.plugin.d.ts","sourceRoot":"","sources":["../../../shared/encryption/encryption.plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,UAAU,CAAC;AAuBnD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IACzB,OAAO;IAEP;;;;;;;;;;;;;;OAcG;WACW,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAczC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAUjC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAiBjC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAgChC;;;;;;;;;;;OAWG;mBACkB,aAAa;IA0BlC;;;;;;;;;;;;OAYG;mBACkB,eAAe;IAiBpC;;;;;;;;;;OAUG;mBACkB,iBAAiB;IAQtC;;;;;;;;;;;OAWG;mBACkB,gBAAgB;IAarC;;;;;;;;;;;OAWG;mBACkB,cAAc;IAuBnC;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAU/B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAU/B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAI5B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;CAO9B"}
|