@opencrvs/toolkit 1.9.12-rc.9db61b1 → 1.9.12-rc.a6c95e7
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 +9 -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/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +64 -0
- package/dist/commons/api/router.d.ts +3369 -2269
- 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 +889 -1942
- 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 +405 -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 +73 -108
- 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 +2776 -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 +35 -34
- 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 +191 -173
- 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 +61 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +294 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2721 -2099
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2016 -1763
- package/dist/scopes/index.d.ts +623 -357
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +329 -301
- package/opencrvs-toolkit-1.9.12-rc.a6c95e7.tgz +0 -0
- package/package.json +14 -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,335 +17,361 @@ 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
EncodedScope: () => EncodedScope2,
|
|
34
|
+
JurisdictionFilter: () => JurisdictionFilter,
|
|
35
|
+
RecordScopeTypeV2: () => RecordScopeTypeV2,
|
|
36
|
+
RecordScopeV2: () => RecordScopeV2,
|
|
37
|
+
ResolvedRecordScopeV2: () => ResolvedRecordScopeV2,
|
|
38
|
+
Scope: () => Scope2,
|
|
39
|
+
ScopeOptionKey: () => ScopeOptionKey,
|
|
40
|
+
ScopeType: () => ScopeType2,
|
|
41
|
+
ScopesWithDeclaredOptions: () => ScopesWithDeclaredOptions,
|
|
42
|
+
ScopesWithFullOptions: () => ScopesWithFullOptions,
|
|
43
|
+
ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
|
|
44
|
+
UserFilter: () => UserFilter,
|
|
45
|
+
canUserCreateEvent: () => canUserCreateEvent,
|
|
46
|
+
decodeScope: () => decodeScope,
|
|
47
|
+
defineScopes: () => defineScopes,
|
|
48
|
+
encodeScope: () => encodeScope,
|
|
49
|
+
getAcceptedScopesByType: () => getAcceptedScopesByType,
|
|
50
|
+
getScopeOptionValue: () => getScopeOptionValue,
|
|
51
|
+
hasAnyScope: () => hasAnyScope,
|
|
52
|
+
hasScope: () => hasScope,
|
|
53
|
+
isCustomActionScope: () => isCustomActionScope,
|
|
54
|
+
scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
|
|
55
|
+
scopeUsesFullOptions: () => scopeUsesFullOptions,
|
|
56
|
+
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
|
|
34
57
|
});
|
|
35
58
|
module.exports = __toCommonJS(scopes_exports);
|
|
59
|
+
var z4 = __toESM(require("zod/v4"));
|
|
36
60
|
|
|
37
61
|
// ../commons/src/scopes.ts
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
|
|
70
|
-
RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
|
|
71
|
-
// register
|
|
72
|
-
RECORD_REGISTER: "record.register",
|
|
73
|
-
/**
|
|
74
|
-
* This scope is used to **print and **issue certified copies of a record
|
|
75
|
-
* after it has been registered. Previously Registrars had this permission.
|
|
76
|
-
*/
|
|
77
|
-
RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
|
|
78
|
-
// correct
|
|
79
|
-
RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
|
|
80
|
-
RECORD_REGISTRATION_CORRECT: "record.registration-correct",
|
|
81
|
-
RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
|
|
82
|
-
RECORD_REJECT_REGISTRATION: "record.reject-registration",
|
|
83
|
-
// search
|
|
84
|
-
SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
|
|
85
|
-
SEARCH_BIRTH: "search.birth",
|
|
86
|
-
SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
|
|
87
|
-
SEARCH_DEATH: "search.death",
|
|
88
|
-
SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
|
|
89
|
-
SEARCH_MARRIAGE: "search.marriage",
|
|
90
|
-
// audit v1.8
|
|
91
|
-
RECORD_READ: "record.read",
|
|
92
|
-
// profile
|
|
93
|
-
PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
|
|
94
|
-
// performance
|
|
95
|
-
PERFORMANCE_READ: "performance.read",
|
|
96
|
-
PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
|
|
97
|
-
PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
|
|
98
|
-
// organisation
|
|
99
|
-
ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
|
|
100
|
-
ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
|
|
101
|
-
ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
|
|
102
|
-
// user
|
|
103
|
-
USER_READ: "user.read:all",
|
|
104
|
-
USER_READ_MY_OFFICE: "user.read:my-office",
|
|
105
|
-
USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
|
|
106
|
-
USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
|
|
107
|
-
//v1.8
|
|
108
|
-
USER_CREATE: "user.create:all",
|
|
109
|
-
USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
|
|
110
|
-
USER_UPDATE: "user.update:all",
|
|
111
|
-
USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
|
|
112
|
-
// config
|
|
113
|
-
CONFIG_UPDATE_ALL: "config.update:all",
|
|
114
|
-
// data seeding
|
|
115
|
-
USER_DATA_SEEDING: "user.data-seeding"
|
|
62
|
+
var z3 = __toESM(require("zod/v4"));
|
|
63
|
+
var qs = __toESM(require("qs"));
|
|
64
|
+
|
|
65
|
+
// ../commons/src/uuid.ts
|
|
66
|
+
var import_uuid = require("uuid");
|
|
67
|
+
var z = __toESM(require("zod/v4"));
|
|
68
|
+
var UUID = z.uuid().brand("UUID");
|
|
69
|
+
|
|
70
|
+
// ../commons/src/authentication.ts
|
|
71
|
+
var import_jwt_decode = __toESM(require("jwt-decode"));
|
|
72
|
+
var z2 = __toESM(require("zod/v4"));
|
|
73
|
+
var TokenUserType = z2.enum(["user", "system"]);
|
|
74
|
+
function setBearerForToken(token) {
|
|
75
|
+
const bearer = "Bearer";
|
|
76
|
+
return token.startsWith(bearer) ? token : `${bearer} ${token}`;
|
|
77
|
+
}
|
|
78
|
+
function getScopes(token) {
|
|
79
|
+
const authHeader = { Authorization: setBearerForToken(token) };
|
|
80
|
+
const tokenPayload = getTokenPayload(authHeader.Authorization.split(" ")[1]);
|
|
81
|
+
return tokenPayload.scope || [];
|
|
82
|
+
}
|
|
83
|
+
var getTokenPayload = (token) => {
|
|
84
|
+
let decoded;
|
|
85
|
+
try {
|
|
86
|
+
decoded = (0, import_jwt_decode.default)(token);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`getTokenPayload: Error occurred during token decode : ${err}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return decoded;
|
|
116
93
|
};
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
|
|
141
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW)
|
|
142
|
-
]);
|
|
143
|
-
var UnassignScope = import_zod.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS);
|
|
144
|
-
var ValidateScopes = import_zod.z.union([
|
|
145
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
|
|
146
|
-
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
|
|
147
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
|
|
148
|
-
import_zod.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
|
|
149
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
|
|
150
|
-
import_zod.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE)
|
|
151
|
-
]);
|
|
152
|
-
var RegisterScope = import_zod.z.literal(SCOPES.RECORD_REGISTER);
|
|
153
|
-
var CorrectionScopes = import_zod.z.union([
|
|
154
|
-
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
|
|
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)
|
|
158
|
-
]);
|
|
159
|
-
var SearchScopes = import_zod.z.union([
|
|
160
|
-
import_zod.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
|
|
161
|
-
import_zod.z.literal(SCOPES.SEARCH_BIRTH),
|
|
162
|
-
import_zod.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
|
|
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)
|
|
166
|
-
]);
|
|
167
|
-
var AuditScopes = import_zod.z.literal(SCOPES.RECORD_READ);
|
|
168
|
-
var PerformanceScopes = import_zod.z.union([
|
|
169
|
-
import_zod.z.literal(SCOPES.PERFORMANCE_READ),
|
|
170
|
-
import_zod.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
|
|
171
|
-
import_zod.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS)
|
|
172
|
-
]);
|
|
173
|
-
var OrganisationScopes = import_zod.z.union([
|
|
174
|
-
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
|
|
175
|
-
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
|
|
176
|
-
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION)
|
|
177
|
-
]);
|
|
178
|
-
var UserScopes = import_zod.z.union([
|
|
179
|
-
import_zod.z.literal(SCOPES.USER_READ),
|
|
180
|
-
import_zod.z.literal(SCOPES.USER_READ_MY_OFFICE),
|
|
181
|
-
import_zod.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
|
|
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)
|
|
94
|
+
var TokenWithBearer = z2.string().regex(/^Bearer\s/);
|
|
95
|
+
|
|
96
|
+
// ../commons/src/scopes.ts
|
|
97
|
+
var JurisdictionFilter = z3.enum(["administrativeArea", "location", "all"]).describe(
|
|
98
|
+
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
99
|
+
);
|
|
100
|
+
var UserFilter = z3.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
101
|
+
var RecordScopeTypeV2 = z3.enum([
|
|
102
|
+
"record.search",
|
|
103
|
+
"record.create",
|
|
104
|
+
"record.read",
|
|
105
|
+
"record.declare",
|
|
106
|
+
"record.notify",
|
|
107
|
+
"record.edit",
|
|
108
|
+
"record.reject",
|
|
109
|
+
"record.archive",
|
|
110
|
+
"record.review-duplicates",
|
|
111
|
+
"record.register",
|
|
112
|
+
"record.print-certified-copies",
|
|
113
|
+
"record.request-correction",
|
|
114
|
+
"record.correct",
|
|
115
|
+
"record.unassign-others",
|
|
116
|
+
"record.custom-action"
|
|
187
117
|
]);
|
|
188
|
-
var
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
DataSeedingScope,
|
|
207
|
-
InternalOperationsScopes
|
|
118
|
+
var PlainScopeType = z3.enum([
|
|
119
|
+
// Misc. system scopes
|
|
120
|
+
"bypassratelimit",
|
|
121
|
+
"record.reindex",
|
|
122
|
+
"user.data-seeding",
|
|
123
|
+
"integration.create",
|
|
124
|
+
"record.import",
|
|
125
|
+
"config.update-all",
|
|
126
|
+
"attachment.upload",
|
|
127
|
+
"profile.electronic-signature",
|
|
128
|
+
"user.read-only-my-audit",
|
|
129
|
+
// Performance dashboard
|
|
130
|
+
"performance.read",
|
|
131
|
+
"performance.read-dashboards",
|
|
132
|
+
"performance.vital-statistics-export",
|
|
133
|
+
// Scopes used exclusively by countryconfig integration token
|
|
134
|
+
"record.confirm-registration",
|
|
135
|
+
"record.reject-registration"
|
|
208
136
|
]);
|
|
209
|
-
var
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
137
|
+
var scopeByEvent = z3.preprocess(
|
|
138
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
139
|
+
z3.array(z3.string()).optional()
|
|
140
|
+
).describe("Event type, e.g. birth, death");
|
|
141
|
+
var scopeOptionsPlaceEvent = z3.object({
|
|
142
|
+
event: scopeByEvent,
|
|
143
|
+
placeOfEvent: JurisdictionFilter.optional()
|
|
144
|
+
}).describe("Options applicable to all record scopes.");
|
|
145
|
+
var scopeOptionsDeclared = scopeOptionsPlaceEvent.extend({
|
|
146
|
+
declaredIn: JurisdictionFilter.optional(),
|
|
147
|
+
declaredBy: UserFilter.optional()
|
|
148
|
+
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
149
|
+
var AllRecordScopeOptions = scopeOptionsDeclared.extend({
|
|
150
|
+
registeredIn: JurisdictionFilter.optional(),
|
|
151
|
+
registeredBy: UserFilter.optional()
|
|
152
|
+
}).describe(
|
|
153
|
+
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
154
|
+
);
|
|
155
|
+
var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
156
|
+
customActionTypes: z3.preprocess(
|
|
157
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
158
|
+
z3.array(z3.string()).optional()
|
|
159
|
+
).describe("Allowed custom action types")
|
|
222
160
|
});
|
|
223
|
-
var
|
|
224
|
-
|
|
225
|
-
options: import_zod.z.object({
|
|
226
|
-
id: import_zod.z.array(import_zod.z.string())
|
|
227
|
-
})
|
|
161
|
+
var AccessLevelOptions = z3.object({
|
|
162
|
+
accessLevel: JurisdictionFilter.optional()
|
|
228
163
|
});
|
|
229
|
-
var
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
})
|
|
164
|
+
var WorkqueueOptions = z3.object({
|
|
165
|
+
ids: z3.preprocess(
|
|
166
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
167
|
+
z3.array(z3.string())
|
|
168
|
+
).describe("Must contain a list of workqueue ids.")
|
|
235
169
|
});
|
|
236
|
-
var
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
})
|
|
170
|
+
var AllScopeOptions = z3.object({
|
|
171
|
+
...AllRecordScopeOptions.shape,
|
|
172
|
+
...AccessLevelOptions.shape,
|
|
173
|
+
...WorkqueueOptions.shape
|
|
244
174
|
});
|
|
245
|
-
var
|
|
175
|
+
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
176
|
+
var ResolvedScopeOptionsPlaceEvent = z3.object({
|
|
177
|
+
event: scopeByEvent,
|
|
178
|
+
placeOfEvent: UUID.nullish()
|
|
179
|
+
}).describe(
|
|
180
|
+
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
181
|
+
);
|
|
182
|
+
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
183
|
+
declaredIn: UUID.nullish(),
|
|
184
|
+
declaredBy: z3.string().optional()
|
|
185
|
+
}).describe(
|
|
186
|
+
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
187
|
+
);
|
|
188
|
+
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
189
|
+
registeredIn: UUID.nullish(),
|
|
190
|
+
registeredBy: z3.string().optional()
|
|
191
|
+
}).describe(
|
|
192
|
+
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
193
|
+
);
|
|
194
|
+
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
246
195
|
"record.create",
|
|
247
|
-
"record.read",
|
|
248
196
|
"record.declare",
|
|
249
|
-
"record.notify"
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
"record.
|
|
253
|
-
"record.
|
|
254
|
-
"record.
|
|
255
|
-
"record.
|
|
256
|
-
"record.
|
|
197
|
+
"record.notify"
|
|
198
|
+
]);
|
|
199
|
+
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
200
|
+
"record.edit",
|
|
201
|
+
"record.reject",
|
|
202
|
+
"record.archive",
|
|
203
|
+
"record.review-duplicates",
|
|
204
|
+
"record.register"
|
|
205
|
+
]);
|
|
206
|
+
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
207
|
+
"record.search",
|
|
208
|
+
"record.read",
|
|
209
|
+
"record.request-correction",
|
|
210
|
+
"record.correct",
|
|
257
211
|
"record.unassign-others"
|
|
258
212
|
]);
|
|
259
|
-
var
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
213
|
+
var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
|
|
214
|
+
templates: z3.preprocess(
|
|
215
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
216
|
+
z3.array(z3.string()).optional()
|
|
217
|
+
).describe(
|
|
218
|
+
"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."
|
|
219
|
+
)
|
|
220
|
+
});
|
|
221
|
+
var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
222
|
+
z3.object({
|
|
223
|
+
type: ScopesWithPlaceEventOptions,
|
|
224
|
+
options: scopeOptionsPlaceEvent.optional()
|
|
225
|
+
}),
|
|
226
|
+
z3.object({
|
|
227
|
+
type: ScopesWithDeclaredOptions,
|
|
228
|
+
options: scopeOptionsDeclared.optional()
|
|
229
|
+
}),
|
|
230
|
+
z3.object({
|
|
231
|
+
type: ScopesWithFullOptions,
|
|
232
|
+
options: AllRecordScopeOptions.optional()
|
|
233
|
+
}),
|
|
234
|
+
z3.object({
|
|
235
|
+
type: z3.literal("record.custom-action"),
|
|
236
|
+
options: CustomActionScopeOptions.optional()
|
|
237
|
+
}),
|
|
238
|
+
z3.object({
|
|
239
|
+
type: z3.literal("record.print-certified-copies"),
|
|
240
|
+
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
263
241
|
})
|
|
264
|
-
|
|
242
|
+
]).describe(
|
|
265
243
|
"Scopes used to check user's permission to perform actions on a record."
|
|
266
244
|
);
|
|
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 };
|
|
245
|
+
function scopeUsesDeclaredOptions(scope) {
|
|
246
|
+
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
289
247
|
}
|
|
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
|
-
);
|
|
248
|
+
function scopeUsesFullOptions(scope) {
|
|
249
|
+
return ScopesWithFullOptions.options.some((opt) => opt === scope.type);
|
|
298
250
|
}
|
|
299
|
-
function
|
|
300
|
-
return
|
|
301
|
-
const [key, value] = option.split("=");
|
|
302
|
-
acc[key] = value.split("|");
|
|
303
|
-
return acc;
|
|
304
|
-
}, {});
|
|
251
|
+
function scopeUsesPrintCertifiedCopiesOptions(scope) {
|
|
252
|
+
return scope.type === "record.print-certified-copies";
|
|
305
253
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
308
|
-
if (!maybeConfigurableScope.success) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const rawScope = maybeConfigurableScope.data;
|
|
312
|
-
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
|
313
|
-
const options = getScopeOptions(rawOptions);
|
|
314
|
-
const parsedScope = {
|
|
315
|
-
type,
|
|
316
|
-
options
|
|
317
|
-
};
|
|
318
|
-
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
|
319
|
-
return result.success ? result.data : void 0;
|
|
254
|
+
function isCustomActionScope(scope) {
|
|
255
|
+
return scope.type === "record.custom-action";
|
|
320
256
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
257
|
+
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
258
|
+
z3.object({
|
|
259
|
+
type: ScopesWithPlaceEventOptions,
|
|
260
|
+
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
261
|
+
}),
|
|
262
|
+
z3.object({
|
|
263
|
+
type: ScopesWithDeclaredOptions,
|
|
264
|
+
options: ResolvedScopeOptionsDeclared.optional()
|
|
265
|
+
}),
|
|
266
|
+
z3.object({
|
|
267
|
+
type: ScopesWithFullOptions,
|
|
268
|
+
options: ResolvedScopeOptionsFull.optional()
|
|
269
|
+
}),
|
|
270
|
+
z3.object({
|
|
271
|
+
type: z3.literal("record.print-certified-copies"),
|
|
272
|
+
options: ResolvedScopeOptionsFull.extend({
|
|
273
|
+
templates: z3.array(z3.string()).optional()
|
|
274
|
+
}).optional()
|
|
275
|
+
})
|
|
276
|
+
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
277
|
+
var SystemScopeType = z3.enum([
|
|
278
|
+
"organisation.read-locations",
|
|
279
|
+
"user.read",
|
|
280
|
+
"user.create",
|
|
281
|
+
"user.edit"
|
|
282
|
+
]);
|
|
283
|
+
var Scope2 = z3.discriminatedUnion("type", [
|
|
284
|
+
z3.object({ type: PlainScopeType }),
|
|
285
|
+
...RecordScopeV2.options,
|
|
286
|
+
z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
|
|
287
|
+
z3.object({ type: z3.literal("workqueue"), options: WorkqueueOptions })
|
|
288
|
+
]);
|
|
289
|
+
var ScopeType2 = z3.enum([
|
|
290
|
+
...SystemScopeType.options,
|
|
291
|
+
...RecordScopeTypeV2.options,
|
|
292
|
+
...PlainScopeType.options,
|
|
293
|
+
"workqueue"
|
|
294
|
+
]);
|
|
295
|
+
var flattenScope = (scope) => ({
|
|
296
|
+
type: scope.type,
|
|
297
|
+
..."options" in scope ? scope.options : {}
|
|
298
|
+
});
|
|
299
|
+
var unflattenScope = (input) => {
|
|
300
|
+
const { type, ...options } = input;
|
|
301
|
+
return { type, options };
|
|
302
|
+
};
|
|
303
|
+
var EncodedScope2 = z3.string().brand("EncodedScope");
|
|
304
|
+
var encodeScope = (scope) => {
|
|
305
|
+
const flattened = flattenScope(scope);
|
|
306
|
+
return qs.stringify(flattened, {
|
|
307
|
+
arrayFormat: "comma",
|
|
308
|
+
allowDots: true,
|
|
309
|
+
addQueryPrefix: false,
|
|
310
|
+
encode: false
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
var decodeScope = (query) => {
|
|
314
|
+
const scope = qs.parse(query, {
|
|
315
|
+
ignoreQueryPrefix: true,
|
|
316
|
+
comma: true,
|
|
317
|
+
allowDots: true
|
|
318
|
+
});
|
|
319
|
+
const unflattenedScope = unflattenScope(scope);
|
|
320
|
+
return Scope2.safeParse(unflattenedScope)?.data;
|
|
321
|
+
};
|
|
322
|
+
var DEFAULT_SCOPE_OPTIONS = {
|
|
323
|
+
placeOfEvent: JurisdictionFilter.enum.all,
|
|
324
|
+
accessLevel: JurisdictionFilter.enum.all
|
|
325
|
+
};
|
|
326
|
+
function getScopeOptionValue(scope, option) {
|
|
327
|
+
const options = "options" in scope ? scope.options : void 0;
|
|
328
|
+
const value = options?.[option];
|
|
329
|
+
const defaultValue = option in DEFAULT_SCOPE_OPTIONS ? DEFAULT_SCOPE_OPTIONS[option] : void 0;
|
|
330
|
+
return value ?? defaultValue;
|
|
331
|
+
}
|
|
332
|
+
function getAcceptedScopesByType({
|
|
333
|
+
acceptedScopes,
|
|
334
|
+
scopes
|
|
335
|
+
}) {
|
|
336
|
+
return scopes.map((scope) => {
|
|
337
|
+
const parsedScope = decodeScope(scope);
|
|
338
|
+
return parsedScope && acceptedScopes.some(
|
|
339
|
+
(acceptedScope) => acceptedScope === parsedScope.type
|
|
340
|
+
) ? parsedScope : null;
|
|
341
|
+
}).filter((scope) => scope !== null);
|
|
329
342
|
}
|
|
330
|
-
function
|
|
331
|
-
const
|
|
332
|
-
|
|
343
|
+
function hasAnyScope(tokenOrScopes, scopes) {
|
|
344
|
+
const userScopes = Array.isArray(tokenOrScopes) ? tokenOrScopes : getScopes(tokenOrScopes);
|
|
345
|
+
const foundScopes = getAcceptedScopesByType({
|
|
346
|
+
acceptedScopes: scopes,
|
|
347
|
+
scopes: userScopes
|
|
348
|
+
});
|
|
349
|
+
return foundScopes.length > 0;
|
|
350
|
+
}
|
|
351
|
+
function hasScope(tokenOrScopes, scope) {
|
|
352
|
+
if (Array.isArray(tokenOrScopes)) {
|
|
353
|
+
return getAcceptedScopesByType({
|
|
354
|
+
acceptedScopes: [scope],
|
|
355
|
+
scopes: tokenOrScopes
|
|
356
|
+
}).length > 0;
|
|
357
|
+
}
|
|
358
|
+
return hasAnyScope(tokenOrScopes, [scope]);
|
|
333
359
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
360
|
+
function canUserCreateEvent(userScopes, eventType) {
|
|
361
|
+
const scopes = getAcceptedScopesByType({
|
|
362
|
+
acceptedScopes: ["record.create"],
|
|
363
|
+
scopes: userScopes
|
|
364
|
+
});
|
|
365
|
+
return scopes.some((scope) => {
|
|
366
|
+
if (!("options" in scope) || !scope.options || !("event" in scope.options)) {
|
|
367
|
+
return true;
|
|
338
368
|
}
|
|
339
|
-
return
|
|
340
|
-
})
|
|
369
|
+
return scope.options?.event?.includes(eventType);
|
|
370
|
+
});
|
|
341
371
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
CorrectionScopes
|
|
349
|
-
]);
|
|
372
|
+
function defineScopes(scopes) {
|
|
373
|
+
return scopes.map((scope) => Scope2.parse(scope)).map(encodeScope);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/scopes/index.ts
|
|
377
|
+
z4.globalRegistry.clear();
|