@opencrvs/toolkit 1.9.12-rc.c1b103f → 1.9.12-rc.c1f8f26

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.
Files changed (73) hide show
  1. package/build.sh +9 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/application-config/index.d.ts +2 -0
  4. package/dist/application-config/index.d.ts.map +1 -0
  5. package/dist/application-config/index.js +124 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +64 -0
  9. package/dist/commons/api/router.d.ts +3369 -2269
  10. package/dist/commons/application-config/index.d.ts +87 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -2
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +889 -1942
  15. package/dist/commons/events/ActionInput.d.ts +277 -1073
  16. package/dist/commons/events/ActionType.d.ts +91 -11
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +288 -1496
  18. package/dist/commons/events/AuditLog.d.ts +405 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
  20. package/dist/commons/events/Conditional.d.ts +26 -38
  21. package/dist/commons/events/Constants.d.ts +1 -1
  22. package/dist/commons/events/CountryConfigQueryInput.d.ts +1345 -4495
  23. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  24. package/dist/commons/events/Draft.d.ts +73 -108
  25. package/dist/commons/events/DynamicFieldValue.d.ts +7 -91
  26. package/dist/commons/events/EventConfig.d.ts +35 -2420
  27. package/dist/commons/events/EventConfigInput.d.ts +0 -3
  28. package/dist/commons/events/EventDocument.d.ts +354 -1366
  29. package/dist/commons/events/EventIndex.d.ts +208 -1014
  30. package/dist/commons/events/EventInput.d.ts +3 -8
  31. package/dist/commons/events/EventMetadata.d.ts +130 -357
  32. package/dist/commons/events/FieldConfig.d.ts +2779 -12470
  33. package/dist/commons/events/FieldType.d.ts +25 -4
  34. package/dist/commons/events/FieldTypeMapping.d.ts +289 -907
  35. package/dist/commons/events/FieldValue.d.ts +121 -527
  36. package/dist/commons/events/FileUtils.d.ts +2 -2
  37. package/dist/commons/events/Flag.d.ts +67 -0
  38. package/dist/commons/events/FormConfig.d.ts +54 -721
  39. package/dist/commons/events/PageConfig.d.ts +58 -320
  40. package/dist/commons/events/PlainDate.d.ts +1 -1
  41. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  42. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  43. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  44. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  45. package/dist/commons/events/WorkqueueConfig.d.ts +2008 -7597
  46. package/dist/commons/events/deduplication.d.ts +3 -3
  47. package/dist/commons/events/defineConfig.d.ts +2 -243
  48. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  49. package/dist/commons/events/index.d.ts +3 -0
  50. package/dist/commons/events/locations.d.ts +57 -20
  51. package/dist/commons/events/scopes.d.ts +35 -34
  52. package/dist/commons/events/state/availableActions.d.ts +7 -2
  53. package/dist/commons/events/state/flags.d.ts +21 -3
  54. package/dist/commons/events/state/index.d.ts +30 -27
  55. package/dist/commons/events/state/utils.d.ts +191 -173
  56. package/dist/commons/events/test.utils.d.ts +52 -11
  57. package/dist/commons/events/transactions.d.ts +1 -1
  58. package/dist/commons/events/utils.d.ts +413 -310
  59. package/dist/commons/notification/UserNotifications.d.ts +61 -637
  60. package/dist/conditionals/index.d.ts.map +1 -1
  61. package/dist/conditionals/index.js +294 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2736 -2099
  64. package/dist/notification/index.d.ts.map +1 -1
  65. package/dist/notification/index.js +2031 -1763
  66. package/dist/scopes/index.d.ts +623 -357
  67. package/dist/scopes/index.d.ts.map +1 -1
  68. package/dist/scopes/index.js +329 -301
  69. package/opencrvs-toolkit-1.9.12-rc.c1f8f26.tgz +0 -0
  70. package/package.json +14 -5
  71. package/tsconfig.json +9 -2
  72. package/tsconfig.tsbuildinfo +1 -1
  73. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -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
- 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
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 import_zod = require("zod");
39
- var SCOPES = {
40
- // TODO v1.8 legacy scopes
41
- BYPASSRATELIMIT: "bypassratelimit",
42
- REGISTER: "register",
43
- DEMO: "demo",
44
- CONFIG: "config",
45
- // systems / integrations
46
- WEBHOOK: "webhook",
47
- NATIONALID: "nationalId",
48
- NOTIFICATION_API: "notification-api",
49
- RECORDSEARCH: "recordsearch",
50
- RECORD_IMPORT: "record.import",
51
- RECORD_EXPORT: "record.export",
52
- RECORD_REINDEX: "record.reindex",
53
- // declare
54
- RECORD_DECLARE_BIRTH: "record.declare-birth",
55
- RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
56
- RECORD_DECLARE_DEATH: "record.declare-death",
57
- RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
58
- RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
59
- RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
60
- RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
61
- // @todo: should this record be removed from events v2?
62
- RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
63
- RECORD_UNASSIGN_OTHERS: "record.unassign-others",
64
- // validate
65
- RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
66
- RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
67
- RECORD_DECLARATION_EDIT: "record.declaration-edit",
68
- RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
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 LegacyScopes = import_zod.z.union([
118
- import_zod.z.literal(SCOPES.BYPASSRATELIMIT),
119
- import_zod.z.literal(SCOPES.REGISTER),
120
- import_zod.z.literal(SCOPES.DEMO),
121
- import_zod.z.literal(SCOPES.CONFIG)
122
- ]);
123
- var IntegrationScopes = import_zod.z.union([
124
- import_zod.z.literal(SCOPES.WEBHOOK),
125
- import_zod.z.literal(SCOPES.NATIONALID),
126
- import_zod.z.literal(SCOPES.NOTIFICATION_API),
127
- import_zod.z.literal(SCOPES.RECORDSEARCH)
128
- ]);
129
- var InternalOperationsScopes = import_zod.z.union([
130
- import_zod.z.literal(SCOPES.RECORD_REINDEX),
131
- import_zod.z.literal(SCOPES.RECORD_IMPORT)
132
- ]);
133
- var DeclareScopes = import_zod.z.union([
134
- import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
135
- import_zod.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
136
- import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH),
137
- import_zod.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
138
- import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
139
- import_zod.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
140
- import_zod.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
141
- import_zod.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW)
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 ConfigScope = import_zod.z.literal(SCOPES.CONFIG_UPDATE_ALL);
189
- var DataSeedingScope = import_zod.z.literal(SCOPES.USER_DATA_SEEDING);
190
- var LiteralScopes = import_zod.z.union([
191
- LegacyScopes,
192
- IntegrationScopes,
193
- UnassignScope,
194
- DeclareScopes,
195
- ValidateScopes,
196
- RegisterScope,
197
- import_zod.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
198
- CorrectionScopes,
199
- SearchScopes,
200
- AuditScopes,
201
- import_zod.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
202
- PerformanceScopes,
203
- OrganisationScopes,
204
- UserScopes,
205
- ConfigScope,
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 rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
210
- var rawConfigurableScope = import_zod.z.string().regex(rawConfigurableScopeRegex);
211
- var CreateUserScope = import_zod.z.object({
212
- type: import_zod.z.literal("user.create"),
213
- options: import_zod.z.object({
214
- role: import_zod.z.array(import_zod.z.string())
215
- })
216
- });
217
- var EditUserScope = import_zod.z.object({
218
- type: import_zod.z.literal("user.edit"),
219
- options: import_zod.z.object({
220
- role: import_zod.z.array(import_zod.z.string())
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 WorkqueueScope = import_zod.z.object({
224
- type: import_zod.z.literal("workqueue"),
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 SearchScope = import_zod.z.object({
230
- type: import_zod.z.literal("search"),
231
- options: import_zod.z.object({
232
- event: import_zod.z.array(import_zod.z.string()).length(1),
233
- access: import_zod.z.array(import_zod.z.enum(["my-jurisdiction", "all"])).length(1)
234
- })
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 PrintCertifiedCopiesScope = import_zod.z.object({
237
- type: import_zod.z.literal("record.registered.print-certified-copies"),
238
- options: import_zod.z.object({
239
- event: import_zod.z.array(import_zod.z.string()).describe("Event type, e.g. birth, death"),
240
- templates: import_zod.z.array(import_zod.z.string()).optional().describe(
241
- "Template IDs for certified copies. If not provided, all templates will be used."
242
- )
243
- })
170
+ var AllScopeOptions = z3.object({
171
+ ...AllRecordScopeOptions.shape,
172
+ ...AccessLevelOptions.shape,
173
+ ...WorkqueueOptions.shape
244
174
  });
245
- var RecordScopeType = import_zod.z.enum([
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
- "record.declared.validate",
251
- "record.declared.reject",
252
- "record.declared.archive",
253
- "record.declared.review-duplicates",
254
- "record.register",
255
- "record.registered.request-correction",
256
- "record.registered.correct",
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 RecordScope = import_zod.z.object({
260
- type: RecordScopeType,
261
- options: import_zod.z.object({
262
- event: import_zod.z.array(import_zod.z.string()).describe("Event type, e.g. birth, death")
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
- }).describe(
242
+ ]).describe(
265
243
  "Scopes used to check user's permission to perform actions on a record."
266
244
  );
267
- var ConfigurableRawScopes = import_zod.z.discriminatedUnion("type", [
268
- SearchScope,
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 findScope(scopes2, scopeType) {
291
- const parsedScopes = scopes2.map(parseConfigurableScope);
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 getScopeOptions(rawOptions) {
300
- return rawOptions.split(",").reduce((acc, option) => {
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 parseConfigurableScope(scope) {
307
- const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
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
- function parseLiteralScope(scope) {
322
- const maybeLiteralScope = LiteralScopes.safeParse(scope);
323
- if (maybeLiteralScope.success) {
324
- return {
325
- type: maybeLiteralScope.data
326
- };
327
- }
328
- return;
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 stringifyScope(scope) {
331
- const options = Object.entries(scope.options).map(([key, value]) => `${key}=${value.join("|")}`).join(",");
332
- return `${scope.type}[${options}]`;
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 getAuthorizedEventsFromScopes(scopes2) {
335
- return scopes2.flatMap(({ options }) => {
336
- if (options && "event" in options) {
337
- return options.event;
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 void 0;
340
- }).filter((event) => event !== void 0).filter((event, index, self) => self.indexOf(event) === index);
369
+ return scope.options?.event?.includes(eventType);
370
+ });
341
371
  }
342
- var scopes = Object.values(SCOPES);
343
- var ActionScopes = import_zod.z.union([
344
- DeclareScopes,
345
- ValidateScopes,
346
- RegisterScope,
347
- import_zod.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
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();