@ecrvs/opencrvs-toolkit 1.8.1-rc.a7ee8fb
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 +70 -0
- package/build.sh +56 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +52 -0
- package/dist/commons/api/router.d.ts +14568 -0
- package/dist/commons/conditionals/conditionals.d.ts +194 -0
- package/dist/commons/conditionals/index.d.ts +2 -0
- package/dist/commons/conditionals/validate.d.ts +129 -0
- package/dist/commons/events/ActionConfig.d.ts +2034 -0
- package/dist/commons/events/ActionDocument.d.ts +14400 -0
- package/dist/commons/events/ActionInput.d.ts +11157 -0
- package/dist/commons/events/ActionType.d.ts +52 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +1175 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +181 -0
- package/dist/commons/events/Conditional.d.ts +55 -0
- package/dist/commons/events/Constants.d.ts +3 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +4494 -0
- package/dist/commons/events/CreatedAtLocation.d.ts +2 -0
- package/dist/commons/events/DeduplicationConfig.d.ts +209 -0
- package/dist/commons/events/Draft.d.ts +814 -0
- package/dist/commons/events/EventConfig.d.ts +2237 -0
- package/dist/commons/events/EventConfigInput.d.ts +10 -0
- package/dist/commons/events/EventDocument.d.ts +8505 -0
- package/dist/commons/events/EventIndex.d.ts +3858 -0
- package/dist/commons/events/EventInput.d.ts +13 -0
- package/dist/commons/events/EventMetadata.d.ts +408 -0
- package/dist/commons/events/FieldConfig.d.ts +7125 -0
- package/dist/commons/events/FieldType.d.ts +46 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +537 -0
- package/dist/commons/events/FieldValue.d.ts +250 -0
- package/dist/commons/events/FileUtils.d.ts +4 -0
- package/dist/commons/events/FormConfig.d.ts +725 -0
- package/dist/commons/events/PageConfig.d.ts +336 -0
- package/dist/commons/events/SummaryConfig.d.ts +170 -0
- package/dist/commons/events/TemplateConfig.d.ts +38 -0
- package/dist/commons/events/TranslationConfig.d.ts +15 -0
- package/dist/commons/events/User.d.ts +45 -0
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +53 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +8997 -0
- package/dist/commons/events/deduplication.d.ts +32 -0
- package/dist/commons/events/defineConfig.d.ts +309 -0
- package/dist/commons/events/event.d.ts +109 -0
- package/dist/commons/events/field.d.ts +151 -0
- package/dist/commons/events/index.d.ts +46 -0
- package/dist/commons/events/locations.d.ts +24 -0
- package/dist/commons/events/scopes.d.ts +55 -0
- package/dist/commons/events/serializer.d.ts +2 -0
- package/dist/commons/events/state/availableActions.d.ts +6 -0
- package/dist/commons/events/state/flags.d.ts +4 -0
- package/dist/commons/events/state/index.d.ts +146 -0
- package/dist/commons/events/state/utils.d.ts +1263 -0
- package/dist/commons/events/test.utils.d.ts +473 -0
- package/dist/commons/events/transactions.d.ts +2 -0
- package/dist/commons/events/utils.d.ts +501 -0
- package/dist/commons/events/workqueueDefaultColumns.d.ts +3 -0
- package/dist/commons/notification/UserNotifications.d.ts +632 -0
- package/dist/commons/notification/index.d.ts +2 -0
- package/dist/conditionals/index.d.ts +2 -0
- package/dist/conditionals/index.d.ts.map +1 -0
- package/dist/conditionals/index.js +491 -0
- package/dist/events/deduplication.d.ts +32 -0
- package/dist/events/deduplication.d.ts.map +1 -0
- package/dist/events/deduplication.js +67 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +8383 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/notification/index.d.ts.map +1 -0
- package/dist/notification/index.js +5928 -0
- package/dist/scopes/index.d.ts +335 -0
- package/dist/scopes/index.d.ts.map +1 -0
- package/dist/scopes/index.js +379 -0
- package/package.json +40 -0
- package/tsconfig.json +27 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/scopes/index.ts
|
|
21
|
+
var scopes_exports = {};
|
|
22
|
+
__export(scopes_exports, {
|
|
23
|
+
ActionScopes: () => ActionScopes,
|
|
24
|
+
RecordScope: () => RecordScope,
|
|
25
|
+
RecordScopeType: () => RecordScopeType,
|
|
26
|
+
SCOPES: () => SCOPES,
|
|
27
|
+
SearchScopes: () => SearchScopes,
|
|
28
|
+
findScope: () => findScope,
|
|
29
|
+
getAuthorizedEventsFromScopes: () => getAuthorizedEventsFromScopes,
|
|
30
|
+
parseConfigurableScope: () => parseConfigurableScope,
|
|
31
|
+
parseLiteralScope: () => parseLiteralScope,
|
|
32
|
+
scopes: () => scopes,
|
|
33
|
+
stringifyScope: () => stringifyScope
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(scopes_exports);
|
|
36
|
+
|
|
37
|
+
// ../commons/src/scopes.ts
|
|
38
|
+
var import_zod = require("zod");
|
|
39
|
+
var SCOPES = {
|
|
40
|
+
// TODO v1.8 legacy scopes
|
|
41
|
+
NATLSYSADMIN: "natlsysadmin",
|
|
42
|
+
BYPASSRATELIMIT: "bypassratelimit",
|
|
43
|
+
DECLARE: "declare",
|
|
44
|
+
REGISTER: "register",
|
|
45
|
+
VALIDATE: "validate",
|
|
46
|
+
DEMO: "demo",
|
|
47
|
+
CERTIFY: "certify",
|
|
48
|
+
PERFORMANCE: "performance",
|
|
49
|
+
SYSADMIN: "sysadmin",
|
|
50
|
+
TEAMS: "teams",
|
|
51
|
+
CONFIG: "config",
|
|
52
|
+
// systems / integrations
|
|
53
|
+
WEBHOOK: "webhook",
|
|
54
|
+
NATIONALID: "nationalId",
|
|
55
|
+
NOTIFICATION_API: "notification-api",
|
|
56
|
+
RECORDSEARCH: "recordsearch",
|
|
57
|
+
RECORD_IMPORT: "record.import",
|
|
58
|
+
RECORD_EXPORT: "record.export",
|
|
59
|
+
RECORD_REINDEX: "record.reindex",
|
|
60
|
+
// declare
|
|
61
|
+
RECORD_DECLARE_BIRTH: "record.declare-birth",
|
|
62
|
+
RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
|
|
63
|
+
RECORD_DECLARE_DEATH: "record.declare-death",
|
|
64
|
+
RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
|
|
65
|
+
RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
|
|
66
|
+
RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
|
|
67
|
+
RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
|
|
68
|
+
// @todo: should this record be removed from events v2?
|
|
69
|
+
RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
|
|
70
|
+
RECORD_UNASSIGN_OTHERS: "record.unassign-others",
|
|
71
|
+
// validate
|
|
72
|
+
RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
|
|
73
|
+
RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
|
|
74
|
+
RECORD_DECLARATION_EDIT: "record.declaration-edit",
|
|
75
|
+
RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
|
|
76
|
+
RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
|
|
77
|
+
RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
|
|
78
|
+
// register
|
|
79
|
+
RECORD_REGISTER: "record.register",
|
|
80
|
+
// certify
|
|
81
|
+
RECORD_EXPORT_RECORDS: "record.export-records",
|
|
82
|
+
RECORD_DECLARATION_PRINT: "record.declaration-print",
|
|
83
|
+
RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
|
|
84
|
+
RECORD_REGISTRATION_PRINT: "record.registration-print",
|
|
85
|
+
// v1.8
|
|
86
|
+
/**
|
|
87
|
+
* This scope is used to **print and **issue certified copies of a record
|
|
88
|
+
* after it has been registered. Previously Registrars had this permission.
|
|
89
|
+
*/
|
|
90
|
+
RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
|
|
91
|
+
RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
|
|
92
|
+
// v1.8
|
|
93
|
+
RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
|
|
94
|
+
// v1.8
|
|
95
|
+
// correct
|
|
96
|
+
RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
|
|
97
|
+
RECORD_REGISTRATION_CORRECT: "record.registration-correct",
|
|
98
|
+
RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
|
|
99
|
+
RECORD_REJECT_REGISTRATION: "record.reject-registration",
|
|
100
|
+
// search
|
|
101
|
+
SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
|
|
102
|
+
SEARCH_BIRTH: "search.birth",
|
|
103
|
+
SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
|
|
104
|
+
SEARCH_DEATH: "search.death",
|
|
105
|
+
SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
|
|
106
|
+
SEARCH_MARRIAGE: "search.marriage",
|
|
107
|
+
// audit v1.8
|
|
108
|
+
RECORD_READ: "record.read",
|
|
109
|
+
// profile
|
|
110
|
+
PROFILE_UPDATE: "profile.update",
|
|
111
|
+
//v1.8
|
|
112
|
+
PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
|
|
113
|
+
// performance
|
|
114
|
+
PERFORMANCE_READ: "performance.read",
|
|
115
|
+
PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
|
|
116
|
+
PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
|
|
117
|
+
// organisation
|
|
118
|
+
ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
|
|
119
|
+
ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
|
|
120
|
+
ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
|
|
121
|
+
// user
|
|
122
|
+
USER_READ: "user.read:all",
|
|
123
|
+
USER_READ_MY_OFFICE: "user.read:my-office",
|
|
124
|
+
USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
|
|
125
|
+
USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
|
|
126
|
+
//v1.8
|
|
127
|
+
USER_CREATE: "user.create:all",
|
|
128
|
+
USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
|
|
129
|
+
USER_UPDATE: "user.update:all",
|
|
130
|
+
USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
|
|
131
|
+
// config
|
|
132
|
+
CONFIG_UPDATE_ALL: "config.update:all",
|
|
133
|
+
// data seeding
|
|
134
|
+
USER_DATA_SEEDING: "user.data-seeding"
|
|
135
|
+
};
|
|
136
|
+
var LegacyScopes = import_zod.z.union([
|
|
137
|
+
import_zod.z.literal(SCOPES.NATLSYSADMIN),
|
|
138
|
+
import_zod.z.literal(SCOPES.BYPASSRATELIMIT),
|
|
139
|
+
import_zod.z.literal(SCOPES.DECLARE),
|
|
140
|
+
import_zod.z.literal(SCOPES.REGISTER),
|
|
141
|
+
import_zod.z.literal(SCOPES.VALIDATE),
|
|
142
|
+
import_zod.z.literal(SCOPES.DEMO),
|
|
143
|
+
import_zod.z.literal(SCOPES.CERTIFY),
|
|
144
|
+
import_zod.z.literal(SCOPES.PERFORMANCE),
|
|
145
|
+
import_zod.z.literal(SCOPES.SYSADMIN),
|
|
146
|
+
import_zod.z.literal(SCOPES.TEAMS),
|
|
147
|
+
import_zod.z.literal(SCOPES.CONFIG)
|
|
148
|
+
]);
|
|
149
|
+
var IntegrationScopes = import_zod.z.union([
|
|
150
|
+
import_zod.z.literal(SCOPES.WEBHOOK),
|
|
151
|
+
import_zod.z.literal(SCOPES.NATIONALID),
|
|
152
|
+
import_zod.z.literal(SCOPES.NOTIFICATION_API),
|
|
153
|
+
import_zod.z.literal(SCOPES.RECORDSEARCH)
|
|
154
|
+
]);
|
|
155
|
+
var InternalOperationsScopes = import_zod.z.union([
|
|
156
|
+
import_zod.z.literal(SCOPES.RECORD_REINDEX),
|
|
157
|
+
import_zod.z.literal(SCOPES.RECORD_IMPORT)
|
|
158
|
+
]);
|
|
159
|
+
var DeclareScopes = import_zod.z.union([
|
|
160
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
|
|
161
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
|
|
162
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH),
|
|
163
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
|
|
164
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
|
|
165
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
|
|
166
|
+
import_zod.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
|
|
167
|
+
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW)
|
|
168
|
+
]);
|
|
169
|
+
var UnassignScope = import_zod.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS);
|
|
170
|
+
var ValidateScopes = import_zod.z.union([
|
|
171
|
+
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
|
|
172
|
+
import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
|
|
173
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
|
|
174
|
+
import_zod.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
|
|
175
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
|
|
176
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE)
|
|
177
|
+
]);
|
|
178
|
+
var RegisterScope = import_zod.z.literal(SCOPES.RECORD_REGISTER);
|
|
179
|
+
var CertifyScopes = import_zod.z.union([
|
|
180
|
+
import_zod.z.literal(SCOPES.RECORD_EXPORT_RECORDS),
|
|
181
|
+
import_zod.z.literal(SCOPES.RECORD_DECLARATION_PRINT),
|
|
182
|
+
import_zod.z.literal(SCOPES.RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS),
|
|
183
|
+
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_PRINT),
|
|
184
|
+
import_zod.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
|
|
185
|
+
import_zod.z.literal(SCOPES.RECORD_PRINT_CERTIFIED_COPIES),
|
|
186
|
+
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES)
|
|
187
|
+
]);
|
|
188
|
+
var CorrectionScopes = import_zod.z.union([
|
|
189
|
+
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
|
|
190
|
+
import_zod.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
|
|
191
|
+
import_zod.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
|
|
192
|
+
import_zod.z.literal(SCOPES.RECORD_REJECT_REGISTRATION)
|
|
193
|
+
]);
|
|
194
|
+
var SearchScopes = import_zod.z.union([
|
|
195
|
+
import_zod.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
|
|
196
|
+
import_zod.z.literal(SCOPES.SEARCH_BIRTH),
|
|
197
|
+
import_zod.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
|
|
198
|
+
import_zod.z.literal(SCOPES.SEARCH_DEATH),
|
|
199
|
+
import_zod.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
|
|
200
|
+
import_zod.z.literal(SCOPES.SEARCH_MARRIAGE)
|
|
201
|
+
]);
|
|
202
|
+
var AuditScopes = import_zod.z.literal(SCOPES.RECORD_READ);
|
|
203
|
+
var ProfileScopes = import_zod.z.union([
|
|
204
|
+
import_zod.z.literal(SCOPES.PROFILE_UPDATE),
|
|
205
|
+
import_zod.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE)
|
|
206
|
+
]);
|
|
207
|
+
var PerformanceScopes = import_zod.z.union([
|
|
208
|
+
import_zod.z.literal(SCOPES.PERFORMANCE_READ),
|
|
209
|
+
import_zod.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
|
|
210
|
+
import_zod.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS)
|
|
211
|
+
]);
|
|
212
|
+
var OrganisationScopes = import_zod.z.union([
|
|
213
|
+
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
|
|
214
|
+
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
|
|
215
|
+
import_zod.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION)
|
|
216
|
+
]);
|
|
217
|
+
var UserScopes = import_zod.z.union([
|
|
218
|
+
import_zod.z.literal(SCOPES.USER_READ),
|
|
219
|
+
import_zod.z.literal(SCOPES.USER_READ_MY_OFFICE),
|
|
220
|
+
import_zod.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
|
|
221
|
+
import_zod.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
|
|
222
|
+
import_zod.z.literal(SCOPES.USER_CREATE),
|
|
223
|
+
import_zod.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
|
|
224
|
+
import_zod.z.literal(SCOPES.USER_UPDATE),
|
|
225
|
+
import_zod.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION)
|
|
226
|
+
]);
|
|
227
|
+
var ConfigScope = import_zod.z.literal(SCOPES.CONFIG_UPDATE_ALL);
|
|
228
|
+
var DataSeedingScope = import_zod.z.literal(SCOPES.USER_DATA_SEEDING);
|
|
229
|
+
var LiteralScopes = import_zod.z.union([
|
|
230
|
+
LegacyScopes,
|
|
231
|
+
IntegrationScopes,
|
|
232
|
+
UnassignScope,
|
|
233
|
+
DeclareScopes,
|
|
234
|
+
ValidateScopes,
|
|
235
|
+
RegisterScope,
|
|
236
|
+
CertifyScopes,
|
|
237
|
+
CorrectionScopes,
|
|
238
|
+
SearchScopes,
|
|
239
|
+
AuditScopes,
|
|
240
|
+
ProfileScopes,
|
|
241
|
+
PerformanceScopes,
|
|
242
|
+
OrganisationScopes,
|
|
243
|
+
UserScopes,
|
|
244
|
+
ConfigScope,
|
|
245
|
+
DataSeedingScope,
|
|
246
|
+
InternalOperationsScopes
|
|
247
|
+
]);
|
|
248
|
+
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
249
|
+
var rawConfigurableScope = import_zod.z.string().regex(rawConfigurableScopeRegex);
|
|
250
|
+
var CreateUserScope = import_zod.z.object({
|
|
251
|
+
type: import_zod.z.literal("user.create"),
|
|
252
|
+
options: import_zod.z.object({
|
|
253
|
+
role: import_zod.z.array(import_zod.z.string())
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
var EditUserScope = import_zod.z.object({
|
|
257
|
+
type: import_zod.z.literal("user.edit"),
|
|
258
|
+
options: import_zod.z.object({
|
|
259
|
+
role: import_zod.z.array(import_zod.z.string())
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
var WorkqueueScope = import_zod.z.object({
|
|
263
|
+
type: import_zod.z.literal("workqueue"),
|
|
264
|
+
options: import_zod.z.object({
|
|
265
|
+
id: import_zod.z.array(import_zod.z.string())
|
|
266
|
+
})
|
|
267
|
+
});
|
|
268
|
+
var SearchScope = import_zod.z.object({
|
|
269
|
+
type: import_zod.z.literal("search"),
|
|
270
|
+
options: import_zod.z.object({
|
|
271
|
+
event: import_zod.z.array(import_zod.z.string()).length(1),
|
|
272
|
+
access: import_zod.z.array(import_zod.z.enum(["my-jurisdiction", "all"])).length(1)
|
|
273
|
+
})
|
|
274
|
+
});
|
|
275
|
+
var RecordScopeType = import_zod.z.enum([
|
|
276
|
+
"record.create",
|
|
277
|
+
"record.read",
|
|
278
|
+
"record.declare",
|
|
279
|
+
"record.notify",
|
|
280
|
+
"record.declared.validate",
|
|
281
|
+
"record.declared.reject",
|
|
282
|
+
"record.declared.archive",
|
|
283
|
+
"record.declared.review-duplicates",
|
|
284
|
+
"record.register",
|
|
285
|
+
"record.registered.print-certified-copies",
|
|
286
|
+
"record.registered.request-correction",
|
|
287
|
+
"record.registered.correct",
|
|
288
|
+
"record.unassign-others"
|
|
289
|
+
]);
|
|
290
|
+
var RecordScope = import_zod.z.object({
|
|
291
|
+
type: RecordScopeType,
|
|
292
|
+
options: import_zod.z.object({
|
|
293
|
+
event: import_zod.z.array(import_zod.z.string()).describe("Event type, e.g. birth, death")
|
|
294
|
+
})
|
|
295
|
+
}).describe(
|
|
296
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
297
|
+
);
|
|
298
|
+
var ConfigurableRawScopes = import_zod.z.discriminatedUnion("type", [
|
|
299
|
+
SearchScope,
|
|
300
|
+
CreateUserScope,
|
|
301
|
+
EditUserScope,
|
|
302
|
+
WorkqueueScope,
|
|
303
|
+
RecordScope
|
|
304
|
+
]);
|
|
305
|
+
function flattenAndMergeScopes(scopes2) {
|
|
306
|
+
if (scopes2.length === 0) return null;
|
|
307
|
+
const type = scopes2[0].type;
|
|
308
|
+
const mergedOptions = {};
|
|
309
|
+
for (const scope of scopes2) {
|
|
310
|
+
const entries = Object.entries(scope.options);
|
|
311
|
+
if (entries.length < 2) continue;
|
|
312
|
+
const sourceValues = entries[0][1];
|
|
313
|
+
const targetValues = entries[1][1];
|
|
314
|
+
for (let i = 0; i < sourceValues.length; i++) {
|
|
315
|
+
mergedOptions[sourceValues[i]] = targetValues[i];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return { type, options: mergedOptions };
|
|
319
|
+
}
|
|
320
|
+
function findScope(scopes2, scopeType) {
|
|
321
|
+
const parsedScopes = scopes2.map(parseConfigurableScope);
|
|
322
|
+
const searchScopes = parsedScopes.filter((scope) => scope?.type === "search");
|
|
323
|
+
const otherScopes = parsedScopes.filter((scope) => scope?.type !== "search");
|
|
324
|
+
const mergedSearchScope = flattenAndMergeScopes(searchScopes);
|
|
325
|
+
return [...otherScopes, mergedSearchScope].find(
|
|
326
|
+
(scope) => scope?.type === scopeType
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
function getScopeOptions(rawOptions) {
|
|
330
|
+
return rawOptions.split(",").reduce((acc, option) => {
|
|
331
|
+
const [key, value] = option.split("=");
|
|
332
|
+
acc[key] = value.split("|");
|
|
333
|
+
return acc;
|
|
334
|
+
}, {});
|
|
335
|
+
}
|
|
336
|
+
function parseConfigurableScope(scope) {
|
|
337
|
+
const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
|
|
338
|
+
if (!maybeConfigurableScope.success) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const rawScope = maybeConfigurableScope.data;
|
|
342
|
+
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
|
343
|
+
const options = getScopeOptions(rawOptions);
|
|
344
|
+
const parsedScope = {
|
|
345
|
+
type,
|
|
346
|
+
options
|
|
347
|
+
};
|
|
348
|
+
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
|
349
|
+
return result.success ? result.data : void 0;
|
|
350
|
+
}
|
|
351
|
+
function parseLiteralScope(scope) {
|
|
352
|
+
const maybeLiteralScope = LiteralScopes.safeParse(scope);
|
|
353
|
+
if (maybeLiteralScope.success) {
|
|
354
|
+
return {
|
|
355
|
+
type: maybeLiteralScope.data
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
function stringifyScope(scope) {
|
|
361
|
+
const options = Object.entries(scope.options).map(([key, value]) => `${key}=${value.join("|")}`).join(",");
|
|
362
|
+
return `${scope.type}[${options}]`;
|
|
363
|
+
}
|
|
364
|
+
function getAuthorizedEventsFromScopes(scopes2) {
|
|
365
|
+
return scopes2.flatMap(({ options }) => {
|
|
366
|
+
if (options && "event" in options) {
|
|
367
|
+
return options.event;
|
|
368
|
+
}
|
|
369
|
+
return void 0;
|
|
370
|
+
}).filter((event) => event !== void 0).filter((event, index, self) => self.indexOf(event) === index);
|
|
371
|
+
}
|
|
372
|
+
var scopes = Object.values(SCOPES);
|
|
373
|
+
var ActionScopes = import_zod.z.union([
|
|
374
|
+
DeclareScopes,
|
|
375
|
+
ValidateScopes,
|
|
376
|
+
RegisterScope,
|
|
377
|
+
CertifyScopes,
|
|
378
|
+
CorrectionScopes
|
|
379
|
+
]);
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ecrvs/opencrvs-toolkit",
|
|
3
|
+
"version": "1.8.1-rc.a7ee8fb",
|
|
4
|
+
"description": "OpenCRVS toolkit for building country configurations",
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./lib": "./dist/lib.js",
|
|
8
|
+
"./api": "./dist/api/index.js",
|
|
9
|
+
"./events": "./dist/events/index.js",
|
|
10
|
+
"./scopes": "./dist/scopes/index.js",
|
|
11
|
+
"./events/deduplication": "./dist/events/deduplication.js",
|
|
12
|
+
"./conditionals": "./dist/conditionals/index.js",
|
|
13
|
+
"./notification": "./dist/notification/index.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "./build.sh",
|
|
17
|
+
"build:all": "lerna run build --include-dependencies --scope @ecrvs/opencrvs-toolkit && ./build.sh"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"uuid": "^9.0.0",
|
|
21
|
+
"ajv": "^8.17.1",
|
|
22
|
+
"ajv-formats": "^3.0.1",
|
|
23
|
+
"object-hash": "^3.0.0",
|
|
24
|
+
"superjson": "1.9.0-0",
|
|
25
|
+
"@trpc/client": "11.4.3",
|
|
26
|
+
"@trpc/server": "11.4.3",
|
|
27
|
+
"zod-openapi": "^4.2.4"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/uuid": "^9.0.3",
|
|
31
|
+
"esbuild": "^0.24.0",
|
|
32
|
+
"typescript": "^5.6.3",
|
|
33
|
+
"@opencrvs/events": "^1.7.0",
|
|
34
|
+
"@types/object-hash": "^3.0.6"
|
|
35
|
+
},
|
|
36
|
+
"moduleNameMapper": {
|
|
37
|
+
"@opencrvs/commons/events": "@opencrvs/commons/build/dist/common/events/index.js",
|
|
38
|
+
"@opencrvs/commons/scopes": "@opencrvs/commons/build/dist/common/scopes.js"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["esnext"],
|
|
4
|
+
"target": "es2016",
|
|
5
|
+
"module": "node16",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationMap": true,
|
|
12
|
+
"rootDir": "./src",
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"paths": {
|
|
15
|
+
"@opencrvs/commons/conditionals": [
|
|
16
|
+
"../commons/src/conditionals/conditionals.ts"
|
|
17
|
+
],
|
|
18
|
+
"@opencrvs/commons/scopes": ["../commons/src/scopes.ts"],
|
|
19
|
+
"@opencrvs/commons/events": ["../commons/src/events/index.ts"],
|
|
20
|
+
"@opencrvs/commons/events/deduplication": ["../commons/src/events/deduplication.ts"],
|
|
21
|
+
"@opencrvs/commons/notification": ["../commons/src/notification/index.ts"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"references": [{ "path": "../commons/tsconfig-commonjs.json" }],
|
|
25
|
+
"include": ["src/**/*.ts"],
|
|
26
|
+
"exclude": ["**/node_modules/**", "dist"]
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/api/index.ts","./src/conditionals/index.ts","./src/events/deduplication.ts","./src/events/index.ts","./src/notification/index.ts","./src/scopes/index.ts"],"version":"5.6.3"}
|