@opencrvs/toolkit 1.9.12-rc.ea32f28 → 1.9.12-rc.f5ca5e6
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/build.sh +5 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/application-config/index.d.ts +2 -0
- package/dist/application-config/index.d.ts.map +1 -0
- package/dist/application-config/index.js +124 -0
- package/dist/commons/api/router.d.ts +3163 -2251
- package/dist/commons/application-config/index.d.ts +87 -0
- package/dist/commons/conditionals/conditionals.d.ts +27 -3
- package/dist/commons/conditionals/validate.d.ts +13 -2
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +888 -1941
- package/dist/commons/events/ActionInput.d.ts +277 -1073
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +288 -1496
- package/dist/commons/events/AuditLog.d.ts +223 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1345 -4495
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +72 -107
- package/dist/commons/events/DynamicFieldValue.d.ts +7 -91
- package/dist/commons/events/EventConfig.d.ts +35 -2420
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +354 -1366
- package/dist/commons/events/EventIndex.d.ts +208 -1014
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +130 -357
- package/dist/commons/events/FieldConfig.d.ts +2671 -12896
- package/dist/commons/events/FieldType.d.ts +25 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +289 -907
- package/dist/commons/events/FieldValue.d.ts +121 -527
- package/dist/commons/events/FileUtils.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +54 -721
- package/dist/commons/events/PageConfig.d.ts +58 -320
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +2008 -7597
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -243
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +57 -20
- package/dist/commons/events/scopes.d.ts +33 -33
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +21 -3
- package/dist/commons/events/state/index.d.ts +30 -27
- package/dist/commons/events/state/utils.d.ts +190 -172
- package/dist/commons/events/test.utils.d.ts +52 -11
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +413 -310
- package/dist/commons/notification/UserNotifications.d.ts +55 -636
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +587 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2689 -1891
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +1987 -1553
- package/dist/scopes/index.d.ts +352 -302
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +444 -210
- package/opencrvs-toolkit-1.9.12-rc.f5ca5e6.tgz +0 -0
- package/package.json +11 -5
- package/tsconfig.json +9 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
package/dist/scopes/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,27 +17,147 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/scopes/index.ts
|
|
21
31
|
var scopes_exports = {};
|
|
22
32
|
__export(scopes_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
JurisdictionFilter: () => JurisdictionFilter,
|
|
34
|
+
RecordScopeTypeV2: () => RecordScopeTypeV2,
|
|
35
|
+
RecordScopeV2: () => RecordScopeV2,
|
|
36
|
+
ResolvedRecordScopeV2: () => ResolvedRecordScopeV2,
|
|
26
37
|
SCOPES: () => SCOPES,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
ScopeOptionKey: () => ScopeOptionKey,
|
|
39
|
+
ScopesWithDeclaredOptions: () => ScopesWithDeclaredOptions,
|
|
40
|
+
ScopesWithFullOptions: () => ScopesWithFullOptions,
|
|
41
|
+
ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
|
|
42
|
+
UserFilter: () => UserFilter,
|
|
43
|
+
canUserCreateEvent: () => canUserCreateEvent,
|
|
44
|
+
decodeScope: () => decodeScope,
|
|
45
|
+
defineScopes: () => defineScopes,
|
|
46
|
+
encodeScope: () => encodeScope,
|
|
47
|
+
getAcceptedScopesByType: () => getAcceptedScopesByType,
|
|
48
|
+
getScopeOptionValue: () => getScopeOptionValue,
|
|
49
|
+
isCustomActionScope: () => isCustomActionScope,
|
|
50
|
+
migrateV1ScopesToV2: () => migrateV1ScopesToV2,
|
|
31
51
|
parseLiteralScope: () => parseLiteralScope,
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
|
|
53
|
+
scopeUsesFullOptions: () => scopeUsesFullOptions,
|
|
54
|
+
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
|
|
55
|
+
v1ScopeToV2Scope: () => v1ScopeToV2Scope
|
|
34
56
|
});
|
|
35
57
|
module.exports = __toCommonJS(scopes_exports);
|
|
58
|
+
var z4 = __toESM(require("zod/v4"));
|
|
59
|
+
|
|
60
|
+
// ../commons/src/scopes.ts
|
|
61
|
+
var z3 = __toESM(require("zod/v4"));
|
|
62
|
+
var qs = __toESM(require("qs"));
|
|
63
|
+
|
|
64
|
+
// ../commons/src/uuid.ts
|
|
65
|
+
var import_uuid = require("uuid");
|
|
66
|
+
var z = __toESM(require("zod/v4"));
|
|
67
|
+
var UUID = z.uuid().brand("UUID");
|
|
68
|
+
|
|
69
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
70
|
+
var z2 = __toESM(require("zod/v4"));
|
|
71
|
+
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
72
|
+
var rawConfigurableScope = z2.string().regex(rawConfigurableScopeRegex);
|
|
73
|
+
var SearchScope = z2.object({
|
|
74
|
+
type: z2.literal("search"),
|
|
75
|
+
options: z2.object({
|
|
76
|
+
event: z2.array(z2.string()).length(1),
|
|
77
|
+
access: z2.array(z2.enum(["my-jurisdiction", "all"])).length(1)
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
var CreateUserScope = z2.object({
|
|
81
|
+
type: z2.literal("user.create"),
|
|
82
|
+
options: z2.object({
|
|
83
|
+
role: z2.array(z2.string())
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
var EditUserScope = z2.object({
|
|
87
|
+
type: z2.literal("user.edit"),
|
|
88
|
+
options: z2.object({
|
|
89
|
+
role: z2.array(z2.string())
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
var WorkqueueScope = z2.object({
|
|
93
|
+
type: z2.literal("workqueue"),
|
|
94
|
+
options: z2.object({
|
|
95
|
+
id: z2.array(z2.string())
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
var PrintCertifiedCopiesScope = z2.object({
|
|
99
|
+
type: z2.literal("record.registered.print-certified-copies"),
|
|
100
|
+
options: z2.object({
|
|
101
|
+
event: z2.array(z2.string()).describe("Event type, e.g. birth, death"),
|
|
102
|
+
templates: z2.array(z2.string()).optional().describe(
|
|
103
|
+
"Template IDs for certified copies. If not provided, all templates will be used."
|
|
104
|
+
)
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
var LegacyRecordScope = z2.object({
|
|
108
|
+
type: z2.enum([
|
|
109
|
+
"record.create",
|
|
110
|
+
"record.read",
|
|
111
|
+
"record.declare",
|
|
112
|
+
"record.notify",
|
|
113
|
+
"record.declared.edit",
|
|
114
|
+
"record.declared.validate",
|
|
115
|
+
"record.declared.reject",
|
|
116
|
+
"record.declared.archive",
|
|
117
|
+
"record.declared.review-duplicates",
|
|
118
|
+
"record.register",
|
|
119
|
+
"record.registered.request-correction",
|
|
120
|
+
"record.registered.correct",
|
|
121
|
+
"record.unassign-others"
|
|
122
|
+
]),
|
|
123
|
+
options: z2.object({
|
|
124
|
+
event: z2.array(z2.string()).describe("Event type, e.g. birth, death")
|
|
125
|
+
})
|
|
126
|
+
}).describe(
|
|
127
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
128
|
+
);
|
|
129
|
+
var ConfigurableRawScopes = z2.discriminatedUnion("type", [
|
|
130
|
+
SearchScope,
|
|
131
|
+
LegacyRecordScope,
|
|
132
|
+
PrintCertifiedCopiesScope,
|
|
133
|
+
CreateUserScope,
|
|
134
|
+
EditUserScope,
|
|
135
|
+
WorkqueueScope
|
|
136
|
+
]);
|
|
137
|
+
function getScopeOptions(rawOptions) {
|
|
138
|
+
return rawOptions.split(",").reduce((acc, option) => {
|
|
139
|
+
const [key, value] = option.split("=");
|
|
140
|
+
acc[key] = value.split("|");
|
|
141
|
+
return acc;
|
|
142
|
+
}, {});
|
|
143
|
+
}
|
|
144
|
+
function parseConfigurableScope(scope) {
|
|
145
|
+
const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
|
|
146
|
+
if (!maybeConfigurableScope.success) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const rawScope = maybeConfigurableScope.data;
|
|
150
|
+
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
|
151
|
+
const options = getScopeOptions(rawOptions);
|
|
152
|
+
const parsedScope = {
|
|
153
|
+
type,
|
|
154
|
+
options
|
|
155
|
+
};
|
|
156
|
+
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
|
157
|
+
return result.success ? result.data : void 0;
|
|
158
|
+
}
|
|
36
159
|
|
|
37
160
|
// ../commons/src/scopes.ts
|
|
38
|
-
var import_zod = require("zod");
|
|
39
161
|
var SCOPES = {
|
|
40
162
|
// TODO v1.8 legacy scopes
|
|
41
163
|
BYPASSRATELIMIT: "bypassratelimit",
|
|
@@ -50,6 +172,7 @@ var SCOPES = {
|
|
|
50
172
|
RECORD_IMPORT: "record.import",
|
|
51
173
|
RECORD_EXPORT: "record.export",
|
|
52
174
|
RECORD_REINDEX: "record.reindex",
|
|
175
|
+
INTEGRATION_CREATE: "integration.create",
|
|
53
176
|
// declare
|
|
54
177
|
RECORD_DECLARE_BIRTH: "record.declare-birth",
|
|
55
178
|
RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
|
|
@@ -112,238 +235,349 @@ var SCOPES = {
|
|
|
112
235
|
// config
|
|
113
236
|
CONFIG_UPDATE_ALL: "config.update:all",
|
|
114
237
|
// data seeding
|
|
115
|
-
USER_DATA_SEEDING: "user.data-seeding"
|
|
238
|
+
USER_DATA_SEEDING: "user.data-seeding",
|
|
239
|
+
// attachment
|
|
240
|
+
ATTACHMENT_UPLOAD: "attachment.upload"
|
|
116
241
|
};
|
|
117
|
-
var LegacyScopes =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]);
|
|
123
|
-
var IntegrationScopes = import_zod.z.union([
|
|
124
|
-
import_zod.z.literal(SCOPES.WEBHOOK),
|
|
125
|
-
import_zod.z.literal(SCOPES.NATIONALID),
|
|
126
|
-
import_zod.z.literal(SCOPES.NOTIFICATION_API),
|
|
127
|
-
import_zod.z.literal(SCOPES.RECORDSEARCH)
|
|
128
|
-
]);
|
|
129
|
-
var InternalOperationsScopes = import_zod.z.union([
|
|
130
|
-
import_zod.z.literal(SCOPES.RECORD_REINDEX),
|
|
131
|
-
import_zod.z.literal(SCOPES.RECORD_IMPORT)
|
|
132
|
-
]);
|
|
133
|
-
var DeclareScopes = import_zod.z.union([
|
|
134
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
|
|
135
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
|
|
136
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH),
|
|
137
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
|
|
138
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
|
|
139
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
|
|
140
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
|
|
141
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW)
|
|
242
|
+
var LegacyScopes = z3.union([
|
|
243
|
+
z3.literal(SCOPES.BYPASSRATELIMIT),
|
|
244
|
+
z3.literal(SCOPES.REGISTER),
|
|
245
|
+
z3.literal(SCOPES.DEMO),
|
|
246
|
+
z3.literal(SCOPES.CONFIG)
|
|
142
247
|
]);
|
|
143
|
-
var
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
|
|
150
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE)
|
|
248
|
+
var IntegrationScopes = z3.union([
|
|
249
|
+
z3.literal(SCOPES.WEBHOOK),
|
|
250
|
+
z3.literal(SCOPES.NATIONALID),
|
|
251
|
+
z3.literal(SCOPES.NOTIFICATION_API),
|
|
252
|
+
z3.literal(SCOPES.RECORDSEARCH),
|
|
253
|
+
z3.literal(SCOPES.INTEGRATION_CREATE)
|
|
151
254
|
]);
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
|
|
156
|
-
import_zod.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
|
|
157
|
-
import_zod.z.literal(SCOPES.RECORD_REJECT_REGISTRATION)
|
|
255
|
+
var InternalOperationsScopes = z3.union([
|
|
256
|
+
z3.literal(SCOPES.RECORD_REINDEX),
|
|
257
|
+
z3.literal(SCOPES.RECORD_IMPORT)
|
|
158
258
|
]);
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
import_zod.z.literal(SCOPES.SEARCH_DEATH),
|
|
164
|
-
import_zod.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
|
|
165
|
-
import_zod.z.literal(SCOPES.SEARCH_MARRIAGE)
|
|
259
|
+
var PerformanceScopes = z3.union([
|
|
260
|
+
z3.literal(SCOPES.PERFORMANCE_READ),
|
|
261
|
+
z3.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
|
|
262
|
+
z3.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS)
|
|
166
263
|
]);
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
import_zod.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS)
|
|
264
|
+
var OrganisationScopes = z3.union([
|
|
265
|
+
z3.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
|
|
266
|
+
z3.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
|
|
267
|
+
z3.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION)
|
|
172
268
|
]);
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
269
|
+
var UserScopes = z3.union([
|
|
270
|
+
z3.literal(SCOPES.USER_READ),
|
|
271
|
+
z3.literal(SCOPES.USER_READ_MY_OFFICE),
|
|
272
|
+
z3.literal(SCOPES.USER_READ_MY_JURISDICTION),
|
|
273
|
+
z3.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
|
|
274
|
+
z3.literal(SCOPES.USER_CREATE),
|
|
275
|
+
z3.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
|
|
276
|
+
z3.literal(SCOPES.USER_UPDATE),
|
|
277
|
+
z3.literal(SCOPES.USER_UPDATE_MY_JURISDICTION)
|
|
177
278
|
]);
|
|
178
|
-
var
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
import_zod.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
|
|
183
|
-
import_zod.z.literal(SCOPES.USER_CREATE),
|
|
184
|
-
import_zod.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
|
|
185
|
-
import_zod.z.literal(SCOPES.USER_UPDATE),
|
|
186
|
-
import_zod.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION)
|
|
187
|
-
]);
|
|
188
|
-
var ConfigScope = import_zod.z.literal(SCOPES.CONFIG_UPDATE_ALL);
|
|
189
|
-
var DataSeedingScope = import_zod.z.literal(SCOPES.USER_DATA_SEEDING);
|
|
190
|
-
var LiteralScopes = import_zod.z.union([
|
|
279
|
+
var ConfigScope = z3.literal(SCOPES.CONFIG_UPDATE_ALL);
|
|
280
|
+
var DataSeedingScope = z3.literal(SCOPES.USER_DATA_SEEDING);
|
|
281
|
+
var AttachmentScope = z3.literal(SCOPES.ATTACHMENT_UPLOAD);
|
|
282
|
+
var LiteralScopes = z3.union([
|
|
191
283
|
LegacyScopes,
|
|
192
284
|
IntegrationScopes,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
ValidateScopes,
|
|
196
|
-
RegisterScope,
|
|
197
|
-
import_zod.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
|
|
198
|
-
CorrectionScopes,
|
|
199
|
-
SearchScopes,
|
|
200
|
-
AuditScopes,
|
|
201
|
-
import_zod.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
|
|
285
|
+
z3.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
|
|
286
|
+
z3.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
|
|
202
287
|
PerformanceScopes,
|
|
203
288
|
OrganisationScopes,
|
|
204
289
|
UserScopes,
|
|
205
290
|
ConfigScope,
|
|
206
291
|
DataSeedingScope,
|
|
207
|
-
InternalOperationsScopes
|
|
292
|
+
InternalOperationsScopes,
|
|
293
|
+
AttachmentScope
|
|
208
294
|
]);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
type: import_zod.z.literal("workqueue"),
|
|
225
|
-
options: import_zod.z.object({
|
|
226
|
-
id: import_zod.z.array(import_zod.z.string())
|
|
227
|
-
})
|
|
228
|
-
});
|
|
229
|
-
var SearchScope = import_zod.z.object({
|
|
230
|
-
type: import_zod.z.literal("search"),
|
|
231
|
-
options: import_zod.z.object({
|
|
232
|
-
event: import_zod.z.array(import_zod.z.string()).length(1),
|
|
233
|
-
access: import_zod.z.array(import_zod.z.enum(["my-jurisdiction", "all"])).length(1)
|
|
234
|
-
})
|
|
235
|
-
});
|
|
236
|
-
var PrintCertifiedCopiesScope = import_zod.z.object({
|
|
237
|
-
type: import_zod.z.literal("record.registered.print-certified-copies"),
|
|
238
|
-
options: import_zod.z.object({
|
|
239
|
-
event: import_zod.z.array(import_zod.z.string()).describe("Event type, e.g. birth, death"),
|
|
240
|
-
templates: import_zod.z.array(import_zod.z.string()).optional().describe(
|
|
241
|
-
"Template IDs for certified copies. If not provided, all templates will be used."
|
|
242
|
-
)
|
|
243
|
-
})
|
|
244
|
-
});
|
|
245
|
-
var RecordScopeType = import_zod.z.enum([
|
|
295
|
+
function parseLiteralScope(scope) {
|
|
296
|
+
const maybeLiteralScope = LiteralScopes.safeParse(scope);
|
|
297
|
+
if (maybeLiteralScope.success) {
|
|
298
|
+
return {
|
|
299
|
+
type: maybeLiteralScope.data
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
var JurisdictionFilter = z3.enum(["administrativeArea", "location", "all"]).describe(
|
|
305
|
+
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
306
|
+
);
|
|
307
|
+
var UserFilter = z3.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
308
|
+
var RecordScopeTypeV2 = z3.enum([
|
|
309
|
+
"record.search",
|
|
246
310
|
"record.create",
|
|
247
311
|
"record.read",
|
|
248
312
|
"record.declare",
|
|
249
313
|
"record.notify",
|
|
250
|
-
"record.
|
|
251
|
-
"record.
|
|
252
|
-
"record.
|
|
253
|
-
"record.
|
|
314
|
+
"record.edit",
|
|
315
|
+
"record.reject",
|
|
316
|
+
"record.archive",
|
|
317
|
+
"record.review-duplicates",
|
|
254
318
|
"record.register",
|
|
255
|
-
"record.
|
|
256
|
-
"record.
|
|
319
|
+
"record.print-certified-copies",
|
|
320
|
+
"record.request-correction",
|
|
321
|
+
"record.correct",
|
|
322
|
+
"record.unassign-others",
|
|
323
|
+
"record.custom-action"
|
|
324
|
+
]);
|
|
325
|
+
var scopeByEvent = z3.preprocess(
|
|
326
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
327
|
+
z3.array(z3.string()).optional()
|
|
328
|
+
).describe("Event type, e.g. birth, death");
|
|
329
|
+
var scopeOptionsPlaceEvent = z3.object({
|
|
330
|
+
event: scopeByEvent,
|
|
331
|
+
placeOfEvent: JurisdictionFilter.optional()
|
|
332
|
+
}).describe("Options applicable to all record scopes.");
|
|
333
|
+
var scopeOptionsDeclared = scopeOptionsPlaceEvent.extend({
|
|
334
|
+
declaredIn: JurisdictionFilter.optional(),
|
|
335
|
+
declaredBy: UserFilter.optional()
|
|
336
|
+
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
337
|
+
var ScopeOptionsFull = scopeOptionsDeclared.extend({
|
|
338
|
+
registeredIn: JurisdictionFilter.optional(),
|
|
339
|
+
registeredBy: UserFilter.optional()
|
|
340
|
+
}).describe(
|
|
341
|
+
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
342
|
+
);
|
|
343
|
+
var CustomActionScopeOptions = ScopeOptionsFull.extend({
|
|
344
|
+
customActionTypes: z3.preprocess(
|
|
345
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
346
|
+
z3.array(z3.string()).optional()
|
|
347
|
+
).describe("Allowed custom action types")
|
|
348
|
+
});
|
|
349
|
+
var ScopeOptionKey = ScopeOptionsFull.keyof();
|
|
350
|
+
var ResolvedScopeOptionsPlaceEvent = z3.object({
|
|
351
|
+
event: scopeByEvent,
|
|
352
|
+
placeOfEvent: UUID.nullish()
|
|
353
|
+
}).describe(
|
|
354
|
+
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
355
|
+
);
|
|
356
|
+
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
357
|
+
declaredIn: UUID.nullish(),
|
|
358
|
+
declaredBy: z3.string().optional()
|
|
359
|
+
}).describe(
|
|
360
|
+
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
361
|
+
);
|
|
362
|
+
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
363
|
+
registeredIn: UUID.nullish(),
|
|
364
|
+
registeredBy: z3.string().optional()
|
|
365
|
+
}).describe(
|
|
366
|
+
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
367
|
+
);
|
|
368
|
+
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
369
|
+
"record.create",
|
|
370
|
+
"record.declare",
|
|
371
|
+
"record.notify"
|
|
372
|
+
]);
|
|
373
|
+
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
374
|
+
"record.edit",
|
|
375
|
+
"record.reject",
|
|
376
|
+
"record.archive",
|
|
377
|
+
"record.review-duplicates",
|
|
378
|
+
"record.register"
|
|
379
|
+
]);
|
|
380
|
+
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
381
|
+
"record.search",
|
|
382
|
+
"record.read",
|
|
383
|
+
"record.request-correction",
|
|
384
|
+
"record.correct",
|
|
257
385
|
"record.unassign-others"
|
|
258
386
|
]);
|
|
259
|
-
var
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
387
|
+
var ScopeOptionsPrintCertifiedCopies = ScopeOptionsFull.extend({
|
|
388
|
+
templates: z3.preprocess(
|
|
389
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
390
|
+
z3.array(z3.string()).optional()
|
|
391
|
+
).describe(
|
|
392
|
+
"Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
|
|
393
|
+
)
|
|
394
|
+
});
|
|
395
|
+
var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
396
|
+
z3.object({
|
|
397
|
+
type: ScopesWithPlaceEventOptions,
|
|
398
|
+
options: scopeOptionsPlaceEvent.optional()
|
|
399
|
+
}),
|
|
400
|
+
z3.object({
|
|
401
|
+
type: ScopesWithDeclaredOptions,
|
|
402
|
+
options: scopeOptionsDeclared.optional()
|
|
403
|
+
}),
|
|
404
|
+
z3.object({
|
|
405
|
+
type: ScopesWithFullOptions,
|
|
406
|
+
options: ScopeOptionsFull.optional()
|
|
407
|
+
}),
|
|
408
|
+
z3.object({
|
|
409
|
+
type: z3.literal("record.custom-action"),
|
|
410
|
+
options: CustomActionScopeOptions.optional()
|
|
411
|
+
}),
|
|
412
|
+
z3.object({
|
|
413
|
+
type: z3.literal("record.print-certified-copies"),
|
|
414
|
+
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
263
415
|
})
|
|
264
|
-
|
|
416
|
+
]).describe(
|
|
265
417
|
"Scopes used to check user's permission to perform actions on a record."
|
|
266
418
|
);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
PrintCertifiedCopiesScope,
|
|
270
|
-
CreateUserScope,
|
|
271
|
-
EditUserScope,
|
|
272
|
-
WorkqueueScope,
|
|
273
|
-
RecordScope
|
|
274
|
-
]);
|
|
275
|
-
function flattenAndMergeScopes(scopes2) {
|
|
276
|
-
if (scopes2.length === 0) return null;
|
|
277
|
-
const type = scopes2[0].type;
|
|
278
|
-
const mergedOptions = {};
|
|
279
|
-
for (const scope of scopes2) {
|
|
280
|
-
const entries = Object.entries(scope.options);
|
|
281
|
-
if (entries.length < 2) continue;
|
|
282
|
-
const sourceValues = entries[0][1];
|
|
283
|
-
const targetValues = entries[1][1];
|
|
284
|
-
for (let i = 0; i < sourceValues.length; i++) {
|
|
285
|
-
mergedOptions[sourceValues[i]] = targetValues[i];
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return { type, options: mergedOptions };
|
|
419
|
+
function scopeUsesDeclaredOptions(scope) {
|
|
420
|
+
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
289
421
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
const searchScopes = parsedScopes.filter((scope) => scope?.type === "search");
|
|
293
|
-
const otherScopes = parsedScopes.filter((scope) => scope?.type !== "search");
|
|
294
|
-
const mergedSearchScope = flattenAndMergeScopes(searchScopes);
|
|
295
|
-
return [...otherScopes, mergedSearchScope].find(
|
|
296
|
-
(scope) => scope?.type === scopeType
|
|
297
|
-
);
|
|
422
|
+
function scopeUsesFullOptions(scope) {
|
|
423
|
+
return ScopesWithFullOptions.options.some((opt) => opt === scope.type);
|
|
298
424
|
}
|
|
299
|
-
function
|
|
300
|
-
return
|
|
301
|
-
const [key, value] = option.split("=");
|
|
302
|
-
acc[key] = value.split("|");
|
|
303
|
-
return acc;
|
|
304
|
-
}, {});
|
|
425
|
+
function scopeUsesPrintCertifiedCopiesOptions(scope) {
|
|
426
|
+
return scope.type === "record.print-certified-copies";
|
|
305
427
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
428
|
+
function isCustomActionScope(scope) {
|
|
429
|
+
return scope.type === "record.custom-action";
|
|
430
|
+
}
|
|
431
|
+
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
432
|
+
z3.object({
|
|
433
|
+
type: ScopesWithPlaceEventOptions,
|
|
434
|
+
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
435
|
+
}),
|
|
436
|
+
z3.object({
|
|
437
|
+
type: ScopesWithDeclaredOptions,
|
|
438
|
+
options: ResolvedScopeOptionsDeclared.optional()
|
|
439
|
+
}),
|
|
440
|
+
z3.object({
|
|
441
|
+
type: ScopesWithFullOptions,
|
|
442
|
+
options: ResolvedScopeOptionsFull.optional()
|
|
443
|
+
}),
|
|
444
|
+
z3.object({
|
|
445
|
+
type: z3.literal("record.print-certified-copies"),
|
|
446
|
+
options: ResolvedScopeOptionsFull.extend({
|
|
447
|
+
templates: z3.array(z3.string()).optional()
|
|
448
|
+
}).optional()
|
|
449
|
+
})
|
|
450
|
+
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
451
|
+
var flattenScope = (scope) => ({
|
|
452
|
+
type: scope.type,
|
|
453
|
+
...scope.options
|
|
454
|
+
});
|
|
455
|
+
var unflattenScope = (input) => {
|
|
456
|
+
const { type, ...options } = input;
|
|
457
|
+
return { type, options };
|
|
458
|
+
};
|
|
459
|
+
var encodeScope = (scope) => {
|
|
460
|
+
const flattened = flattenScope(scope);
|
|
461
|
+
return qs.stringify(flattened, {
|
|
462
|
+
arrayFormat: "comma",
|
|
463
|
+
allowDots: true,
|
|
464
|
+
addQueryPrefix: false,
|
|
465
|
+
encode: false
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
var decodeScope = (query) => {
|
|
469
|
+
const scope = qs.parse(query, {
|
|
470
|
+
ignoreQueryPrefix: true,
|
|
471
|
+
comma: true,
|
|
472
|
+
allowDots: true
|
|
473
|
+
});
|
|
474
|
+
const unflattenedScope = unflattenScope(scope);
|
|
475
|
+
return RecordScopeV2.safeParse(unflattenedScope)?.data;
|
|
476
|
+
};
|
|
477
|
+
var DEFAULT_SCOPE_OPTIONS = {
|
|
478
|
+
placeOfEvent: JurisdictionFilter.enum.all
|
|
479
|
+
};
|
|
480
|
+
function getScopeOptionValue(scope, option) {
|
|
481
|
+
const options = scope.options;
|
|
482
|
+
const value = options?.[option];
|
|
483
|
+
const defaultValue = option in DEFAULT_SCOPE_OPTIONS ? DEFAULT_SCOPE_OPTIONS[option] : void 0;
|
|
484
|
+
return value ?? defaultValue;
|
|
485
|
+
}
|
|
486
|
+
var v1ToV2ConfigScopeTypeMap = {
|
|
487
|
+
search: "record.search",
|
|
488
|
+
workqueue: "workqueue",
|
|
489
|
+
"user.create": "user.create",
|
|
490
|
+
"user.edit": "user.edit",
|
|
491
|
+
"record.create": "record.create",
|
|
492
|
+
"record.read": "record.read",
|
|
493
|
+
"record.declare": "record.declare",
|
|
494
|
+
"record.notify": "record.notify",
|
|
495
|
+
"record.register": "record.register",
|
|
496
|
+
"record.unassign-others": "record.unassign-others",
|
|
497
|
+
"record.declared.reject": "record.reject",
|
|
498
|
+
"record.declared.archive": "record.archive",
|
|
499
|
+
"record.declared.review-duplicates": "record.review-duplicates",
|
|
500
|
+
"record.registered.print-certified-copies": "record.print-certified-copies",
|
|
501
|
+
"record.registered.request-correction": "record.request-correction",
|
|
502
|
+
"record.registered.correct": "record.correct",
|
|
503
|
+
"record.declared.edit": "record.edit",
|
|
504
|
+
"record.declared.validate": "record.custom-action"
|
|
505
|
+
};
|
|
506
|
+
var v1ScopeToV2Scope = (v1Scope) => {
|
|
507
|
+
const configurableV1Scope = parseConfigurableScope(v1Scope);
|
|
508
|
+
const literalV1Scope = parseLiteralScope(v1Scope);
|
|
509
|
+
if (!configurableV1Scope && !literalV1Scope) {
|
|
510
|
+
throw new Error(`Invalid V1 scope: ${v1Scope}`);
|
|
310
511
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
type
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
512
|
+
if (literalV1Scope) {
|
|
513
|
+
return literalV1Scope.type;
|
|
514
|
+
}
|
|
515
|
+
if (configurableV1Scope) {
|
|
516
|
+
const type = v1ToV2ConfigScopeTypeMap[configurableV1Scope.type];
|
|
517
|
+
if (type === void 0) {
|
|
518
|
+
throw new Error(`Unsupported V1 scope type: ${configurableV1Scope.type}`);
|
|
519
|
+
}
|
|
520
|
+
if (configurableV1Scope.type === "search") {
|
|
521
|
+
return encodeScope({
|
|
522
|
+
type,
|
|
523
|
+
options: {
|
|
524
|
+
event: configurableV1Scope.options.event || [],
|
|
525
|
+
placeOfEvent: configurableV1Scope.options.access[0] === "my-jurisdiction" ? "administrativeArea" : "all"
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
if (configurableV1Scope.type === "record.declared.validate") {
|
|
530
|
+
return encodeScope({
|
|
531
|
+
type: "record.custom-action",
|
|
532
|
+
options: {
|
|
533
|
+
event: configurableV1Scope.options.event,
|
|
534
|
+
customActionTypes: ["VALIDATE_DECLARATION"]
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
if (!configurableV1Scope.type.startsWith("record.")) {
|
|
539
|
+
return v1Scope;
|
|
540
|
+
}
|
|
541
|
+
return encodeScope({
|
|
542
|
+
type,
|
|
543
|
+
options: configurableV1Scope.options
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
547
|
+
};
|
|
548
|
+
function getAcceptedScopesByType({
|
|
549
|
+
acceptedScopes,
|
|
550
|
+
scopes
|
|
551
|
+
}) {
|
|
552
|
+
return scopes.map((scope) => {
|
|
553
|
+
const parsedScope = decodeScope(scope);
|
|
554
|
+
return parsedScope && acceptedScopes.some(
|
|
555
|
+
(acceptedScope) => acceptedScope === parsedScope.type
|
|
556
|
+
) ? parsedScope : null;
|
|
557
|
+
}).filter((scope) => scope !== null);
|
|
320
558
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return {
|
|
325
|
-
type: maybeLiteralScope.data
|
|
326
|
-
};
|
|
559
|
+
function isEventTypeAllowed(scope, eventType) {
|
|
560
|
+
if (scope.options?.event === void 0) {
|
|
561
|
+
return true;
|
|
327
562
|
}
|
|
328
|
-
return;
|
|
563
|
+
return scope.options?.event?.includes(eventType);
|
|
329
564
|
}
|
|
330
|
-
function
|
|
331
|
-
|
|
332
|
-
return `${scope.type}[${options}]`;
|
|
565
|
+
function canUserCreateEvent(acceptedScopes, eventType) {
|
|
566
|
+
return acceptedScopes.some((scope) => isEventTypeAllowed(scope, eventType));
|
|
333
567
|
}
|
|
334
|
-
function
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
|
|
568
|
+
function defineScopes(scopes) {
|
|
569
|
+
return scopes.map((scope) => RecordScopeV2.parse(scope)).map(encodeScope);
|
|
570
|
+
}
|
|
571
|
+
function migrateV1ScopesToV2(scopes) {
|
|
572
|
+
return scopes.map((scope) => {
|
|
573
|
+
try {
|
|
574
|
+
return v1ScopeToV2Scope(scope);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
console.warn(`Could not migrate scope: ${scope}. Error: ${error}`);
|
|
577
|
+
return null;
|
|
338
578
|
}
|
|
339
|
-
|
|
340
|
-
}).filter((event) => event !== void 0).filter((event, index, self) => self.indexOf(event) === index);
|
|
579
|
+
}).filter((scope) => !!scope);
|
|
341
580
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
ValidateScopes,
|
|
346
|
-
RegisterScope,
|
|
347
|
-
import_zod.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
|
|
348
|
-
CorrectionScopes
|
|
349
|
-
]);
|
|
581
|
+
|
|
582
|
+
// src/scopes/index.ts
|
|
583
|
+
z4.globalRegistry.clear();
|