@opencrvs/toolkit 2.1.0-rc.75e32d8 → 2.1.0-rc.7737766
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 +1 -0
- package/build.sh +9 -1
- package/create-countryconfig/index.js +412 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +349 -277
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +754 -0
- package/dist/cli.js +1782 -113
- package/dist/commons/api/router.d.ts +3976 -3374
- package/dist/commons/application-config/index.d.ts +6 -6
- package/dist/commons/conditionals/conditionals.d.ts +32 -323
- package/dist/commons/conditionals/validate.d.ts +16 -5
- package/dist/commons/events/ActionConfig.d.ts +109 -105
- package/dist/commons/events/ActionDocument.d.ts +121 -127
- package/dist/commons/events/ActionInput.d.ts +4 -10
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/ActionType.d.ts +62 -62
- package/dist/commons/events/AdvancedSearchConfig.d.ts +543 -507
- package/dist/commons/events/AuditLog.d.ts +189 -42
- package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
- package/dist/commons/events/Conditional.d.ts +3 -3
- package/dist/commons/events/CountryConfigQueryInput.d.ts +590 -590
- package/dist/commons/events/Draft.d.ts +37 -37
- package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
- package/dist/commons/events/EventConfig.d.ts +8 -5
- package/dist/commons/events/EventDocument.d.ts +518 -50
- package/dist/commons/events/EventIndex.d.ts +49 -72
- package/dist/commons/events/EventMetadata.d.ts +39 -49
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +434 -389
- package/dist/commons/events/FieldType.d.ts +51 -51
- package/dist/commons/events/FieldTypeMapping.d.ts +86 -86
- package/dist/commons/events/FieldValue.d.ts +14 -14
- package/dist/commons/events/Flag.d.ts +57 -15
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/TemplateConfig.d.ts +1 -1
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
- package/dist/commons/events/WorkqueueConfig.d.ts +817 -814
- package/dist/commons/events/deduplication.d.ts +1 -1
- package/dist/commons/events/event.d.ts +14 -2
- package/dist/commons/events/field.d.ts +69 -198
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +247 -14
- package/dist/commons/events/mocks.test.utils.d.ts +48 -4
- package/dist/commons/events/scopes.d.ts +4 -4
- package/dist/commons/events/state/index.d.ts +17 -17
- package/dist/commons/events/state/utils.d.ts +7 -7
- package/dist/commons/events/test.utils.d.ts +64 -46
- package/dist/commons/events/utils.d.ts +129 -114
- package/dist/commons/notification/UserNotifications.d.ts +38 -23
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +334 -60
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/derived-variables.d.ts +119 -119
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +10 -0
- package/dist/environment/logger.d.ts +6 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +17 -7
- package/dist/environment/paths.d.ts +7 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +72 -0
- package/dist/environment/questions.d.ts +75 -74
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.js +36 -21
- package/dist/environment/swarm-to-k8s.js +17 -7
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +2 -1
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +34 -12
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +82 -0
- package/dist/environment/users.js +28 -20
- package/dist/environment/utils.d.ts +1 -1
- package/dist/environment/utils.js +17 -7
- package/dist/events/deduplication.d.ts +1 -1
- package/dist/events/index.js +7641 -7128
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +17 -7
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
- package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.js +17 -7
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +213 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +438 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1058 -0
- package/dist/notification/index.js +1870 -1464
- package/dist/scopes/index.d.ts +560 -157
- package/dist/scopes/index.js +335 -60
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +39 -0
- package/dist/templates/charts-values/dependencies/values.yaml +2 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/check.d.ts +21 -0
- package/dist/translations/check.d.ts.map +1 -0
- package/dist/translations/check.js +132 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +345 -0
- package/opencrvs-toolkit-2.1.0-rc.7737766.tgz +0 -0
- package/package.json +12 -7
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.75e32d8.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/authentication/index.ts
|
|
31
|
+
var authentication_exports = {};
|
|
32
|
+
__export(authentication_exports, {
|
|
33
|
+
EncodedScope: () => EncodedScope,
|
|
34
|
+
JurisdictionFilter: () => JurisdictionFilter,
|
|
35
|
+
RecordScopeTypeV2: () => RecordScopeTypeV2,
|
|
36
|
+
RecordScopeV2: () => RecordScopeV2,
|
|
37
|
+
ResolvedRecordScopeV2: () => ResolvedRecordScopeV2,
|
|
38
|
+
SERVICE_USER_ID: () => SERVICE_USER_ID,
|
|
39
|
+
Scope: () => Scope,
|
|
40
|
+
ScopeOptionKey: () => ScopeOptionKey,
|
|
41
|
+
ScopeType: () => ScopeType,
|
|
42
|
+
ScopesWithDeclaredOptions: () => ScopesWithDeclaredOptions,
|
|
43
|
+
ScopesWithFullOptions: () => ScopesWithFullOptions,
|
|
44
|
+
ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
|
|
45
|
+
TokenUserType: () => TokenUserType,
|
|
46
|
+
TokenWithBearer: () => TokenWithBearer,
|
|
47
|
+
UserFilter: () => UserFilter,
|
|
48
|
+
UserScopeV2: () => UserScopeV2,
|
|
49
|
+
canUserCreateEvent: () => canUserCreateEvent,
|
|
50
|
+
decodeScope: () => decodeScope,
|
|
51
|
+
defineRoles: () => defineRoles,
|
|
52
|
+
defineScopes: () => defineScopes,
|
|
53
|
+
encodeScope: () => encodeScope,
|
|
54
|
+
getAcceptedScopesByType: () => getAcceptedScopesByType,
|
|
55
|
+
getAcceptedScopesFromToken: () => getAcceptedScopesFromToken,
|
|
56
|
+
getScopeOptionValue: () => getScopeOptionValue,
|
|
57
|
+
getScopes: () => getScopes,
|
|
58
|
+
getTokenPayload: () => getTokenPayload,
|
|
59
|
+
getUserId: () => getUserId,
|
|
60
|
+
getUserIdFromToken: () => getUserIdFromToken,
|
|
61
|
+
getUserTypeFromToken: () => getUserTypeFromToken,
|
|
62
|
+
hasAnyScope: () => hasAnyScope,
|
|
63
|
+
hasScope: () => hasScope,
|
|
64
|
+
isCustomActionScope: () => isCustomActionScope,
|
|
65
|
+
isServiceToken: () => isServiceToken,
|
|
66
|
+
scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
|
|
67
|
+
scopeUsesFullOptions: () => scopeUsesFullOptions,
|
|
68
|
+
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
|
|
69
|
+
scopeUsesRoleOptions: () => scopeUsesRoleOptions,
|
|
70
|
+
setBearerForToken: () => setBearerForToken
|
|
71
|
+
});
|
|
72
|
+
module.exports = __toCommonJS(authentication_exports);
|
|
73
|
+
var z9 = __toESM(require("zod/v4"));
|
|
74
|
+
|
|
75
|
+
// ../commons/src/authentication.ts
|
|
76
|
+
var import_jwt_decode = __toESM(require("jwt-decode"));
|
|
77
|
+
var z8 = __toESM(require("zod/v4"));
|
|
78
|
+
|
|
79
|
+
// ../commons/src/scopes.ts
|
|
80
|
+
var z7 = __toESM(require("zod/v4"));
|
|
81
|
+
var qs = __toESM(require("qs"));
|
|
82
|
+
|
|
83
|
+
// ../commons/src/uuid.ts
|
|
84
|
+
var import_uuid = require("uuid");
|
|
85
|
+
var z = __toESM(require("zod/v4"));
|
|
86
|
+
var UUID = z.uuid().brand("UUID");
|
|
87
|
+
|
|
88
|
+
// ../commons/src/events/ActionType.ts
|
|
89
|
+
var z2 = __toESM(require("zod/v4"));
|
|
90
|
+
var ActionType = {
|
|
91
|
+
// Pre-declaration actions
|
|
92
|
+
DELETE: "DELETE",
|
|
93
|
+
CREATE: "CREATE",
|
|
94
|
+
NOTIFY: "NOTIFY",
|
|
95
|
+
// Declaration actions
|
|
96
|
+
DECLARE: "DECLARE",
|
|
97
|
+
REGISTER: "REGISTER",
|
|
98
|
+
EDIT: "EDIT",
|
|
99
|
+
// Declaration system actions. Non-configurable.
|
|
100
|
+
DUPLICATE_DETECTED: "DUPLICATE_DETECTED",
|
|
101
|
+
REJECT: "REJECT",
|
|
102
|
+
// REJECT_DECLARATION
|
|
103
|
+
MARK_AS_DUPLICATE: "MARK_AS_DUPLICATE",
|
|
104
|
+
MARK_AS_NOT_DUPLICATE: "MARK_AS_NOT_DUPLICATE",
|
|
105
|
+
ARCHIVE: "ARCHIVE",
|
|
106
|
+
UNARCHIVE: "UNARCHIVE",
|
|
107
|
+
// Record actions
|
|
108
|
+
PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
|
|
109
|
+
REQUEST_CORRECTION: "REQUEST_CORRECTION",
|
|
110
|
+
REJECT_CORRECTION: "REJECT_CORRECTION",
|
|
111
|
+
APPROVE_CORRECTION: "APPROVE_CORRECTION",
|
|
112
|
+
// General actions
|
|
113
|
+
READ: "READ",
|
|
114
|
+
ASSIGN: "ASSIGN",
|
|
115
|
+
UNASSIGN: "UNASSIGN",
|
|
116
|
+
// Custom action
|
|
117
|
+
CUSTOM: "CUSTOM"
|
|
118
|
+
};
|
|
119
|
+
var ConfirmableActions = [
|
|
120
|
+
ActionType.NOTIFY,
|
|
121
|
+
ActionType.DECLARE,
|
|
122
|
+
ActionType.EDIT,
|
|
123
|
+
ActionType.REGISTER,
|
|
124
|
+
ActionType.REJECT,
|
|
125
|
+
ActionType.ARCHIVE,
|
|
126
|
+
ActionType.UNARCHIVE,
|
|
127
|
+
ActionType.PRINT_CERTIFICATE,
|
|
128
|
+
ActionType.REQUEST_CORRECTION,
|
|
129
|
+
ActionType.APPROVE_CORRECTION,
|
|
130
|
+
ActionType.REJECT_CORRECTION,
|
|
131
|
+
ActionType.CUSTOM
|
|
132
|
+
];
|
|
133
|
+
var ActionTypes = z2.enum([
|
|
134
|
+
"DELETE",
|
|
135
|
+
"CREATE",
|
|
136
|
+
"NOTIFY",
|
|
137
|
+
"DECLARE",
|
|
138
|
+
"EDIT",
|
|
139
|
+
"REGISTER",
|
|
140
|
+
"DUPLICATE_DETECTED",
|
|
141
|
+
"REJECT",
|
|
142
|
+
"MARK_AS_DUPLICATE",
|
|
143
|
+
"MARK_AS_NOT_DUPLICATE",
|
|
144
|
+
"ARCHIVE",
|
|
145
|
+
"UNARCHIVE",
|
|
146
|
+
"PRINT_CERTIFICATE",
|
|
147
|
+
"REQUEST_CORRECTION",
|
|
148
|
+
"REJECT_CORRECTION",
|
|
149
|
+
"APPROVE_CORRECTION",
|
|
150
|
+
"READ",
|
|
151
|
+
"ASSIGN",
|
|
152
|
+
"UNASSIGN",
|
|
153
|
+
"CUSTOM"
|
|
154
|
+
]);
|
|
155
|
+
var declarationActionValues = [
|
|
156
|
+
ActionTypes.enum.DECLARE,
|
|
157
|
+
ActionTypes.enum.EDIT,
|
|
158
|
+
ActionTypes.enum.REGISTER,
|
|
159
|
+
ActionTypes.enum.NOTIFY,
|
|
160
|
+
ActionTypes.enum.DUPLICATE_DETECTED
|
|
161
|
+
];
|
|
162
|
+
var DeclarationActions = ActionTypes.extract(declarationActionValues);
|
|
163
|
+
var declarationUpdateActionValues = [
|
|
164
|
+
...declarationActionValues,
|
|
165
|
+
ActionTypes.enum.REQUEST_CORRECTION
|
|
166
|
+
];
|
|
167
|
+
var DeclarationUpdateActions = ActionTypes.extract(
|
|
168
|
+
declarationUpdateActionValues
|
|
169
|
+
);
|
|
170
|
+
var annotationActions = ActionTypes.exclude(declarationActionValues);
|
|
171
|
+
var writeActions = ActionTypes.exclude([
|
|
172
|
+
ActionType.CREATE,
|
|
173
|
+
ActionType.READ,
|
|
174
|
+
ActionType.ASSIGN,
|
|
175
|
+
ActionType.UNASSIGN
|
|
176
|
+
]);
|
|
177
|
+
var WorkqueueActionType = ActionTypes.extract([
|
|
178
|
+
ActionType.READ,
|
|
179
|
+
ActionType.DELETE,
|
|
180
|
+
ActionType.DECLARE,
|
|
181
|
+
ActionType.REGISTER,
|
|
182
|
+
ActionType.EDIT,
|
|
183
|
+
ActionType.REJECT,
|
|
184
|
+
ActionType.MARK_AS_DUPLICATE,
|
|
185
|
+
ActionType.ARCHIVE,
|
|
186
|
+
ActionType.UNARCHIVE,
|
|
187
|
+
ActionType.PRINT_CERTIFICATE,
|
|
188
|
+
ActionType.REQUEST_CORRECTION
|
|
189
|
+
]);
|
|
190
|
+
var META_ACTIONS = [
|
|
191
|
+
ActionType.ASSIGN,
|
|
192
|
+
ActionType.UNASSIGN,
|
|
193
|
+
ActionType.READ
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
// ../commons/src/events/ActionStatus.ts
|
|
197
|
+
var ActionStatus = {
|
|
198
|
+
Requested: "Requested",
|
|
199
|
+
Accepted: "Accepted",
|
|
200
|
+
Rejected: "Rejected"
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// ../commons/src/events/Flag.ts
|
|
204
|
+
var z5 = __toESM(require("zod/v4"));
|
|
205
|
+
|
|
206
|
+
// ../commons/src/events/TranslationConfig.ts
|
|
207
|
+
var z3 = __toESM(require("zod/v4"));
|
|
208
|
+
var TranslationConfig = z3.object({
|
|
209
|
+
id: z3.string().describe(
|
|
210
|
+
"The identifier of the translation referred in translation CSV files"
|
|
211
|
+
),
|
|
212
|
+
defaultMessage: z3.string().describe("Default translation message"),
|
|
213
|
+
description: z3.string().describe(
|
|
214
|
+
"Describe the translation for a translator to be able to identify it."
|
|
215
|
+
)
|
|
216
|
+
}).meta({
|
|
217
|
+
description: "Translation configuration",
|
|
218
|
+
id: "TranslationConfig"
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// ../commons/src/events/Conditional.ts
|
|
222
|
+
var z4 = __toESM(require("zod/v4"));
|
|
223
|
+
var Conditional = z4.any().describe("JSONSchema").meta({
|
|
224
|
+
description: "JSON schema conditional configuration",
|
|
225
|
+
id: "Conditional"
|
|
226
|
+
});
|
|
227
|
+
var ConditionalType = {
|
|
228
|
+
SHOW: "SHOW",
|
|
229
|
+
ENABLE: "ENABLE",
|
|
230
|
+
DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
|
|
231
|
+
};
|
|
232
|
+
var ShowConditional = z4.object({
|
|
233
|
+
type: z4.literal(ConditionalType.SHOW),
|
|
234
|
+
conditional: Conditional
|
|
235
|
+
}).describe(
|
|
236
|
+
"If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
|
|
237
|
+
);
|
|
238
|
+
var EnableConditional = z4.object({
|
|
239
|
+
type: z4.literal(ConditionalType.ENABLE),
|
|
240
|
+
conditional: Conditional
|
|
241
|
+
}).describe(
|
|
242
|
+
"If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
|
|
243
|
+
);
|
|
244
|
+
var ActionConditional = z4.discriminatedUnion("type", [
|
|
245
|
+
// Action can be shown / hidden
|
|
246
|
+
ShowConditional,
|
|
247
|
+
// Action can be shown to the user in the list but as disabled
|
|
248
|
+
EnableConditional
|
|
249
|
+
]).meta({
|
|
250
|
+
id: "ActionConditional",
|
|
251
|
+
description: "Conditional gating whether an action is shown (SHOW) or enabled (ENABLE). When omitted from an action, the action is shown and enabled for everyone."
|
|
252
|
+
});
|
|
253
|
+
var DisplayOnReviewConditional = z4.object({
|
|
254
|
+
type: z4.literal(ConditionalType.DISPLAY_ON_REVIEW),
|
|
255
|
+
conditional: Conditional
|
|
256
|
+
}).describe(
|
|
257
|
+
"If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
|
|
258
|
+
);
|
|
259
|
+
var FieldConditional = z4.discriminatedUnion("type", [
|
|
260
|
+
// Field input can be shown / hidden
|
|
261
|
+
ShowConditional,
|
|
262
|
+
// Field input can be shown to the user but as disabled
|
|
263
|
+
EnableConditional,
|
|
264
|
+
// Field output can be shown / hidden on the review page
|
|
265
|
+
DisplayOnReviewConditional
|
|
266
|
+
]).meta({
|
|
267
|
+
id: "FieldConditional",
|
|
268
|
+
description: "Conditional gating whether a form field is shown (SHOW), enabled (ENABLE), or displayed on the review page (DISPLAY_ON_REVIEW). When omitted, the field is shown and enabled for everyone, and is displayed on review whenever it has a value."
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// ../commons/src/events/Flag.ts
|
|
272
|
+
var InherentFlags = {
|
|
273
|
+
INCOMPLETE: "incomplete",
|
|
274
|
+
REJECTED: "rejected",
|
|
275
|
+
CORRECTION_REQUESTED: "correction-requested",
|
|
276
|
+
POTENTIAL_DUPLICATE: "potential-duplicate",
|
|
277
|
+
/**
|
|
278
|
+
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
279
|
+
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
280
|
+
*
|
|
281
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
282
|
+
*/
|
|
283
|
+
EDIT_IN_PROGRESS: "edit-in-progress"
|
|
284
|
+
};
|
|
285
|
+
var actionFlagPattern;
|
|
286
|
+
function getActionFlagPattern() {
|
|
287
|
+
actionFlagPattern ??= new RegExp(
|
|
288
|
+
`^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(
|
|
289
|
+
ActionStatus
|
|
290
|
+
).join("|").toLowerCase()})$`
|
|
291
|
+
);
|
|
292
|
+
return actionFlagPattern;
|
|
293
|
+
}
|
|
294
|
+
var ActionFlag = z5.string().refine((value) => getActionFlagPattern().test(value), {
|
|
295
|
+
message: "Flag must be in the format ActionType:ActionStatus (lowerCase)"
|
|
296
|
+
});
|
|
297
|
+
var CustomFlag = z5.string().refine((val) => !Object.values(InherentFlags).includes(val), {
|
|
298
|
+
message: `Custom flag cannot be one of the inherent flags: ${Object.values(
|
|
299
|
+
InherentFlags
|
|
300
|
+
).join(", ")}`
|
|
301
|
+
}).refine((val) => !ActionFlag.safeParse(val).success, {
|
|
302
|
+
message: "Custom flag cannot match the ActionFlag pattern (ActionType:ActionStatus)."
|
|
303
|
+
}).describe("Custom flag identifier defined by the country config.");
|
|
304
|
+
var Flag = ActionFlag.or(z5.enum(InherentFlags)).or(CustomFlag);
|
|
305
|
+
var ContainsFlags = z5.object({
|
|
306
|
+
anyOf: z5.array(Flag).optional(),
|
|
307
|
+
noneOf: z5.array(Flag).optional(),
|
|
308
|
+
allOf: z5.array(Flag).optional()
|
|
309
|
+
}).meta({
|
|
310
|
+
id: "ContainsFlags"
|
|
311
|
+
});
|
|
312
|
+
var FlagConfig = z5.object({
|
|
313
|
+
id: CustomFlag,
|
|
314
|
+
requiresAction: z5.boolean().describe(
|
|
315
|
+
"Indicates if this flag expects an action to be performed to be cleared."
|
|
316
|
+
),
|
|
317
|
+
label: TranslationConfig.describe("Human readable label of the flag.")
|
|
318
|
+
}).meta({
|
|
319
|
+
id: "FlagConfig",
|
|
320
|
+
description: "Configuration for a custom flag that can be added to or removed from records by event actions."
|
|
321
|
+
});
|
|
322
|
+
var ActionFlagConfig = z5.object({
|
|
323
|
+
id: Flag,
|
|
324
|
+
operation: z5.enum(["add", "remove"]).describe("Operation to perform on the flag."),
|
|
325
|
+
conditional: Conditional.optional().describe(
|
|
326
|
+
"When conditional is met, the operation is performed on the flag. If not provided, the operation is performed unconditionally."
|
|
327
|
+
)
|
|
328
|
+
}).meta({
|
|
329
|
+
id: "ActionFlagConfig",
|
|
330
|
+
description: "Add or remove operation applied to a flag when the parent action is accepted. Optionally gated by a conditional."
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ../commons/src/events/EventStatus.ts
|
|
334
|
+
var z6 = __toESM(require("zod/v4"));
|
|
335
|
+
var EventStatus = z6.enum([
|
|
336
|
+
"CREATED",
|
|
337
|
+
"NOTIFIED",
|
|
338
|
+
"DECLARED",
|
|
339
|
+
"REGISTERED",
|
|
340
|
+
"ARCHIVED"
|
|
341
|
+
]);
|
|
342
|
+
|
|
343
|
+
// ../commons/src/scopes.ts
|
|
344
|
+
var JurisdictionFilter = z7.enum(["administrativeArea", "location", "all"]).describe(
|
|
345
|
+
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
346
|
+
);
|
|
347
|
+
var UserFilter = z7.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
348
|
+
var RecordScopeTypeV2 = z7.enum([
|
|
349
|
+
"record.search",
|
|
350
|
+
"record.create",
|
|
351
|
+
"record.read",
|
|
352
|
+
"record.declare",
|
|
353
|
+
"record.notify",
|
|
354
|
+
"record.edit",
|
|
355
|
+
"record.reject",
|
|
356
|
+
"record.archive",
|
|
357
|
+
"record.unarchive",
|
|
358
|
+
"record.review-duplicates",
|
|
359
|
+
"record.register",
|
|
360
|
+
"record.print-certified-copies",
|
|
361
|
+
"record.request-correction",
|
|
362
|
+
"record.correct",
|
|
363
|
+
"record.unassign-others",
|
|
364
|
+
"record.custom-action"
|
|
365
|
+
]);
|
|
366
|
+
var PlainScopeType = z7.enum([
|
|
367
|
+
// Misc. system scopes
|
|
368
|
+
"bypassratelimit",
|
|
369
|
+
"record.reindex",
|
|
370
|
+
"user.data-seeding",
|
|
371
|
+
"integration.create",
|
|
372
|
+
// Reading an integration's audit log. Deliberately separate from
|
|
373
|
+
// 'integration.create' so read-only oversight can be granted on its own, and
|
|
374
|
+
// deliberately option-less: system clients have no office and no
|
|
375
|
+
// administrative area, so jurisdiction options would have nothing to bind to.
|
|
376
|
+
"integration.audit.read",
|
|
377
|
+
"record.import",
|
|
378
|
+
"config.update-all",
|
|
379
|
+
"location.edit",
|
|
380
|
+
"attachment.upload",
|
|
381
|
+
"profile.electronic-signature",
|
|
382
|
+
"user.read-only-my-audit",
|
|
383
|
+
// Performance dashboard
|
|
384
|
+
"performance.read",
|
|
385
|
+
"performance.read-dashboards",
|
|
386
|
+
"performance.vital-statistics-export",
|
|
387
|
+
// Scopes used exclusively by countryconfig integration token
|
|
388
|
+
"record.confirm-registration",
|
|
389
|
+
"record.reject-registration"
|
|
390
|
+
]);
|
|
391
|
+
var scopeByEvent = z7.preprocess(
|
|
392
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
393
|
+
z7.array(z7.string()).optional()
|
|
394
|
+
).describe("Event type, e.g. birth, death");
|
|
395
|
+
var scopeByStatus = z7.preprocess(
|
|
396
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
397
|
+
z7.array(EventStatus).optional()
|
|
398
|
+
).describe(
|
|
399
|
+
"Restricts the scope to records currently in one of these statuses."
|
|
400
|
+
);
|
|
401
|
+
var userRole = z7.preprocess(
|
|
402
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
403
|
+
z7.array(z7.string()).optional()
|
|
404
|
+
).describe("User role, e.g. admin, field agent");
|
|
405
|
+
var scopeOptionsPlaceEvent = z7.object({
|
|
406
|
+
event: scopeByEvent,
|
|
407
|
+
placeOfEvent: JurisdictionFilter.optional(),
|
|
408
|
+
createdBy: UserFilter.optional(),
|
|
409
|
+
createdIn: JurisdictionFilter.optional()
|
|
410
|
+
}).describe("Options applicable to all record scopes.");
|
|
411
|
+
var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
|
|
412
|
+
notifiedIn: JurisdictionFilter.optional(),
|
|
413
|
+
notifiedBy: UserFilter.optional(),
|
|
414
|
+
declaredIn: JurisdictionFilter.optional(),
|
|
415
|
+
declaredBy: UserFilter.optional(),
|
|
416
|
+
status: scopeByStatus
|
|
417
|
+
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
418
|
+
var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
|
|
419
|
+
registeredIn: JurisdictionFilter.optional(),
|
|
420
|
+
registeredBy: UserFilter.optional(),
|
|
421
|
+
flags: ContainsFlags.optional()
|
|
422
|
+
}).describe(
|
|
423
|
+
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
424
|
+
);
|
|
425
|
+
var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
426
|
+
customActionTypes: z7.preprocess(
|
|
427
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
428
|
+
z7.array(z7.string()).optional()
|
|
429
|
+
).describe("Allowed custom action types")
|
|
430
|
+
});
|
|
431
|
+
var AccessLevelOptions = z7.object({
|
|
432
|
+
accessLevel: JurisdictionFilter.optional()
|
|
433
|
+
});
|
|
434
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
435
|
+
role: userRole.optional()
|
|
436
|
+
});
|
|
437
|
+
var WorkqueueOrDashboardOptions = z7.object({
|
|
438
|
+
ids: z7.preprocess(
|
|
439
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
440
|
+
z7.array(z7.string())
|
|
441
|
+
).describe("Must contain a list of workqueue or dashboard ids.")
|
|
442
|
+
});
|
|
443
|
+
var AllScopeOptions = z7.object({
|
|
444
|
+
...AllRecordScopeOptions.shape,
|
|
445
|
+
...AccessLevelOptions.shape,
|
|
446
|
+
...AllUserScopeOptions.shape,
|
|
447
|
+
...WorkqueueOrDashboardOptions.shape
|
|
448
|
+
});
|
|
449
|
+
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
450
|
+
var ResolvedScopeOptionsPlaceEvent = z7.object({
|
|
451
|
+
event: scopeByEvent,
|
|
452
|
+
placeOfEvent: UUID.nullish(),
|
|
453
|
+
createdBy: z7.string().optional(),
|
|
454
|
+
createdIn: UUID.nullish()
|
|
455
|
+
}).describe(
|
|
456
|
+
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
457
|
+
);
|
|
458
|
+
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
459
|
+
notifiedIn: UUID.nullish(),
|
|
460
|
+
notifiedBy: z7.string().optional(),
|
|
461
|
+
declaredIn: UUID.nullish(),
|
|
462
|
+
declaredBy: z7.string().optional()
|
|
463
|
+
}).describe(
|
|
464
|
+
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
465
|
+
);
|
|
466
|
+
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
467
|
+
registeredIn: UUID.nullish(),
|
|
468
|
+
registeredBy: z7.string().optional(),
|
|
469
|
+
flags: ContainsFlags.optional()
|
|
470
|
+
}).describe(
|
|
471
|
+
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
472
|
+
);
|
|
473
|
+
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
474
|
+
"record.create",
|
|
475
|
+
"record.declare",
|
|
476
|
+
"record.notify"
|
|
477
|
+
]);
|
|
478
|
+
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
479
|
+
"record.edit",
|
|
480
|
+
"record.reject",
|
|
481
|
+
"record.archive",
|
|
482
|
+
"record.unarchive",
|
|
483
|
+
"record.register"
|
|
484
|
+
]);
|
|
485
|
+
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
486
|
+
"record.search",
|
|
487
|
+
"record.read",
|
|
488
|
+
"record.request-correction",
|
|
489
|
+
"record.correct",
|
|
490
|
+
"record.unassign-others",
|
|
491
|
+
"record.review-duplicates"
|
|
492
|
+
]);
|
|
493
|
+
var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
|
|
494
|
+
templates: z7.preprocess(
|
|
495
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
496
|
+
z7.array(z7.string()).optional()
|
|
497
|
+
).describe(
|
|
498
|
+
"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."
|
|
499
|
+
)
|
|
500
|
+
});
|
|
501
|
+
var RecordScopeV2 = z7.discriminatedUnion("type", [
|
|
502
|
+
z7.object({
|
|
503
|
+
type: ScopesWithPlaceEventOptions,
|
|
504
|
+
options: scopeOptionsPlaceEvent.optional()
|
|
505
|
+
}),
|
|
506
|
+
z7.object({
|
|
507
|
+
type: ScopesWithDeclaredOptions,
|
|
508
|
+
options: scopeOptionsDeclaredOrNotified.optional()
|
|
509
|
+
}),
|
|
510
|
+
z7.object({
|
|
511
|
+
type: ScopesWithFullOptions,
|
|
512
|
+
options: AllRecordScopeOptions.optional()
|
|
513
|
+
}),
|
|
514
|
+
z7.object({
|
|
515
|
+
type: z7.literal("record.custom-action"),
|
|
516
|
+
options: CustomActionScopeOptions.optional()
|
|
517
|
+
}),
|
|
518
|
+
z7.object({
|
|
519
|
+
type: z7.literal("record.print-certified-copies"),
|
|
520
|
+
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
521
|
+
})
|
|
522
|
+
]).describe(
|
|
523
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
524
|
+
);
|
|
525
|
+
var SystemScopeType = z7.enum([
|
|
526
|
+
"organisation.read-locations",
|
|
527
|
+
"user.read",
|
|
528
|
+
"user.create",
|
|
529
|
+
"user.edit",
|
|
530
|
+
"user.search"
|
|
531
|
+
]);
|
|
532
|
+
var UserScopeType = SystemScopeType.extract([
|
|
533
|
+
"user.read",
|
|
534
|
+
"user.create",
|
|
535
|
+
"user.edit",
|
|
536
|
+
"user.search"
|
|
537
|
+
]);
|
|
538
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
539
|
+
var UserScopeV2 = z7.discriminatedUnion("type", [
|
|
540
|
+
z7.object({
|
|
541
|
+
type: ScopesWithRoleOption,
|
|
542
|
+
options: AllUserScopeOptions.optional()
|
|
543
|
+
}),
|
|
544
|
+
z7.object({
|
|
545
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
546
|
+
options: AccessLevelOptions.optional()
|
|
547
|
+
})
|
|
548
|
+
]);
|
|
549
|
+
function scopeUsesRoleOptions(scope) {
|
|
550
|
+
return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
|
|
551
|
+
}
|
|
552
|
+
function scopeUsesDeclaredOptions(scope) {
|
|
553
|
+
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
554
|
+
}
|
|
555
|
+
function scopeUsesFullOptions(scope) {
|
|
556
|
+
return ScopesWithFullOptions.options.some((opt) => opt === scope.type);
|
|
557
|
+
}
|
|
558
|
+
function scopeUsesPrintCertifiedCopiesOptions(scope) {
|
|
559
|
+
return scope.type === "record.print-certified-copies";
|
|
560
|
+
}
|
|
561
|
+
function isCustomActionScope(scope) {
|
|
562
|
+
return scope.type === "record.custom-action";
|
|
563
|
+
}
|
|
564
|
+
var ResolvedRecordScopeV2 = z7.discriminatedUnion("type", [
|
|
565
|
+
z7.object({
|
|
566
|
+
type: ScopesWithPlaceEventOptions,
|
|
567
|
+
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
568
|
+
}),
|
|
569
|
+
z7.object({
|
|
570
|
+
type: ScopesWithDeclaredOptions,
|
|
571
|
+
options: ResolvedScopeOptionsDeclared.optional()
|
|
572
|
+
}),
|
|
573
|
+
z7.object({
|
|
574
|
+
type: ScopesWithFullOptions,
|
|
575
|
+
options: ResolvedScopeOptionsFull.optional()
|
|
576
|
+
}),
|
|
577
|
+
z7.object({
|
|
578
|
+
type: z7.literal("record.print-certified-copies"),
|
|
579
|
+
options: ResolvedScopeOptionsFull.extend({
|
|
580
|
+
templates: z7.array(z7.string()).optional()
|
|
581
|
+
}).optional()
|
|
582
|
+
})
|
|
583
|
+
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
584
|
+
var Scope = z7.discriminatedUnion("type", [
|
|
585
|
+
z7.object({ type: PlainScopeType }),
|
|
586
|
+
...RecordScopeV2.options,
|
|
587
|
+
...UserScopeV2.options,
|
|
588
|
+
z7.object({
|
|
589
|
+
type: z7.literal("organisation.read-locations"),
|
|
590
|
+
options: AccessLevelOptions.optional()
|
|
591
|
+
}),
|
|
592
|
+
z7.object({
|
|
593
|
+
type: z7.literal("workqueue"),
|
|
594
|
+
options: WorkqueueOrDashboardOptions
|
|
595
|
+
}),
|
|
596
|
+
z7.object({
|
|
597
|
+
type: z7.literal("dashboard.view"),
|
|
598
|
+
options: WorkqueueOrDashboardOptions
|
|
599
|
+
})
|
|
600
|
+
]);
|
|
601
|
+
var ScopeType = z7.enum([
|
|
602
|
+
...SystemScopeType.options,
|
|
603
|
+
...RecordScopeTypeV2.options,
|
|
604
|
+
...PlainScopeType.options,
|
|
605
|
+
"workqueue",
|
|
606
|
+
"dashboard.view"
|
|
607
|
+
]);
|
|
608
|
+
var flattenScope = (scope) => ({
|
|
609
|
+
type: scope.type,
|
|
610
|
+
..."options" in scope ? scope.options : {}
|
|
611
|
+
});
|
|
612
|
+
var unflattenScope = (input) => {
|
|
613
|
+
const { type, ...options } = input;
|
|
614
|
+
return { type, options };
|
|
615
|
+
};
|
|
616
|
+
var EncodedScope = z7.string().brand("EncodedScope");
|
|
617
|
+
var encodeScope = (scope) => {
|
|
618
|
+
const flattened = flattenScope(scope);
|
|
619
|
+
return qs.stringify(flattened, {
|
|
620
|
+
arrayFormat: "comma",
|
|
621
|
+
commaRoundTrip: true,
|
|
622
|
+
allowDots: true,
|
|
623
|
+
addQueryPrefix: false,
|
|
624
|
+
encode: false
|
|
625
|
+
});
|
|
626
|
+
};
|
|
627
|
+
var decodedScopeCache = /* @__PURE__ */ new Map();
|
|
628
|
+
var decodeScope = (encodedScope) => {
|
|
629
|
+
if (decodedScopeCache.has(encodedScope)) {
|
|
630
|
+
return decodedScopeCache.get(encodedScope);
|
|
631
|
+
}
|
|
632
|
+
const scope = qs.parse(encodedScope, {
|
|
633
|
+
ignoreQueryPrefix: true,
|
|
634
|
+
comma: true,
|
|
635
|
+
allowDots: true
|
|
636
|
+
});
|
|
637
|
+
const unflattenedScope = unflattenScope(scope);
|
|
638
|
+
const result = Scope.safeParse(unflattenedScope)?.data;
|
|
639
|
+
decodedScopeCache.set(encodedScope, result);
|
|
640
|
+
return result;
|
|
641
|
+
};
|
|
642
|
+
var DEFAULT_SCOPE_OPTIONS = {
|
|
643
|
+
placeOfEvent: JurisdictionFilter.enum.all,
|
|
644
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
645
|
+
notifiedIn: JurisdictionFilter.enum.all,
|
|
646
|
+
declaredIn: JurisdictionFilter.enum.all,
|
|
647
|
+
registeredIn: JurisdictionFilter.enum.all
|
|
648
|
+
};
|
|
649
|
+
function getScopeOptionValue(scope, option) {
|
|
650
|
+
const options = "options" in scope ? scope.options : void 0;
|
|
651
|
+
const value = options?.[option];
|
|
652
|
+
const defaultValue = option in DEFAULT_SCOPE_OPTIONS ? DEFAULT_SCOPE_OPTIONS[option] : void 0;
|
|
653
|
+
return value ?? defaultValue;
|
|
654
|
+
}
|
|
655
|
+
function getAcceptedScopesByType({
|
|
656
|
+
acceptedScopes,
|
|
657
|
+
scopes
|
|
658
|
+
}) {
|
|
659
|
+
return scopes.map((scope) => {
|
|
660
|
+
const parsedScope = decodeScope(scope);
|
|
661
|
+
return parsedScope && acceptedScopes.some(
|
|
662
|
+
(acceptedScope) => acceptedScope === parsedScope.type
|
|
663
|
+
) ? parsedScope : null;
|
|
664
|
+
}).filter((scope) => scope !== null);
|
|
665
|
+
}
|
|
666
|
+
function hasAnyScope(tokenOrScopes, scopes) {
|
|
667
|
+
const userScopes = Array.isArray(tokenOrScopes) ? tokenOrScopes : getScopes(tokenOrScopes);
|
|
668
|
+
const foundScopes = getAcceptedScopesByType({
|
|
669
|
+
acceptedScopes: scopes,
|
|
670
|
+
scopes: userScopes
|
|
671
|
+
});
|
|
672
|
+
return foundScopes.length > 0;
|
|
673
|
+
}
|
|
674
|
+
function hasScope(tokenOrScopes, scope) {
|
|
675
|
+
if (Array.isArray(tokenOrScopes)) {
|
|
676
|
+
return getAcceptedScopesByType({
|
|
677
|
+
acceptedScopes: [scope],
|
|
678
|
+
scopes: tokenOrScopes
|
|
679
|
+
}).length > 0;
|
|
680
|
+
}
|
|
681
|
+
return hasAnyScope(tokenOrScopes, [scope]);
|
|
682
|
+
}
|
|
683
|
+
function canUserCreateEvent(userScopes, eventType) {
|
|
684
|
+
const scopes = getAcceptedScopesByType({
|
|
685
|
+
acceptedScopes: ["record.create"],
|
|
686
|
+
scopes: userScopes
|
|
687
|
+
});
|
|
688
|
+
return scopes.some((scope) => {
|
|
689
|
+
if (!("options" in scope) || !scope.options || !("event" in scope.options)) {
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
return scope.options?.event?.includes(eventType);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
function defineScopes(scopes) {
|
|
696
|
+
return scopes.map((scope) => Scope.parse(scope)).map(encodeScope);
|
|
697
|
+
}
|
|
698
|
+
function defineRoles(roles) {
|
|
699
|
+
return roles;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// ../commons/src/authentication.ts
|
|
703
|
+
function getAcceptedScopesFromToken(token, acceptedScopes) {
|
|
704
|
+
const tokenScopes = getScopes(token);
|
|
705
|
+
return tokenScopes.map((scope) => {
|
|
706
|
+
const parsedScope = decodeScope(scope);
|
|
707
|
+
return parsedScope && acceptedScopes.some((s) => s === parsedScope.type) ? parsedScope : null;
|
|
708
|
+
}).filter((scope) => scope !== null);
|
|
709
|
+
}
|
|
710
|
+
var TokenUserType = z8.enum(["user", "system"]);
|
|
711
|
+
function setBearerForToken(token) {
|
|
712
|
+
const bearer = "Bearer";
|
|
713
|
+
return token.startsWith(bearer) ? token : `${bearer} ${token}`;
|
|
714
|
+
}
|
|
715
|
+
function getScopes(token) {
|
|
716
|
+
const authHeader = { Authorization: setBearerForToken(token) };
|
|
717
|
+
const tokenPayload = getTokenPayload(authHeader.Authorization.split(" ")[1]);
|
|
718
|
+
return tokenPayload.scope || [];
|
|
719
|
+
}
|
|
720
|
+
var getTokenPayload = (token) => {
|
|
721
|
+
let decoded;
|
|
722
|
+
try {
|
|
723
|
+
decoded = (0, import_jwt_decode.default)(token);
|
|
724
|
+
} catch (err) {
|
|
725
|
+
throw new Error(
|
|
726
|
+
`getTokenPayload: Error occurred during token decode : ${err}`
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
return decoded;
|
|
730
|
+
};
|
|
731
|
+
var getUserId = (token) => {
|
|
732
|
+
const tokenPayload = getTokenPayload(token.split(" ")[1]);
|
|
733
|
+
return z8.string().parse(tokenPayload.sub);
|
|
734
|
+
};
|
|
735
|
+
var getUserIdFromToken = (token) => {
|
|
736
|
+
try {
|
|
737
|
+
const payload = (0, import_jwt_decode.default)(token);
|
|
738
|
+
return payload.sub ?? null;
|
|
739
|
+
} catch {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
var SERVICE_USER_ID = "__SERVICE_USER__";
|
|
744
|
+
function isServiceToken(credentials) {
|
|
745
|
+
return typeof credentials === "object" && credentials !== null && credentials.sub === SERVICE_USER_ID;
|
|
746
|
+
}
|
|
747
|
+
var getUserTypeFromToken = (token) => {
|
|
748
|
+
const tokenPayload = getTokenPayload(token.split(" ")[1]);
|
|
749
|
+
return TokenUserType.parse(tokenPayload.userType);
|
|
750
|
+
};
|
|
751
|
+
var TokenWithBearer = z8.string().regex(/^Bearer\s/);
|
|
752
|
+
|
|
753
|
+
// src/authentication/index.ts
|
|
754
|
+
z9.globalRegistry.clear();
|