@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.e0918cb

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 (130) hide show
  1. package/build.sh +13 -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 +2128 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +3633 -0
  9. package/dist/commons/api/router.d.ts +3438 -2300
  10. package/dist/commons/application-config/index.d.ts +84 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -3
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +888 -1941
  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 +294 -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 +1592 -4471
  23. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  24. package/dist/commons/events/Draft.d.ts +72 -107
  25. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  26. package/dist/commons/events/EventConfig.d.ts +37 -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 +212 -1010
  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 +2892 -12892
  33. package/dist/commons/events/FieldType.d.ts +26 -4
  34. package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
  35. package/dist/commons/events/FieldValue.d.ts +149 -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 +2208 -7553
  46. package/dist/commons/events/deduplication.d.ts +3 -3
  47. package/dist/commons/events/defineConfig.d.ts +2 -247
  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 +36 -35
  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 +190 -172
  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 +373 -273
  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 +302 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2860 -2115
  64. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  65. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +405 -0
  67. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
  68. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
  70. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  71. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/convert-config-files-to-ts.js +829 -0
  73. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  74. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
  76. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  77. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/create-events-index.js +326 -0
  79. package/dist/migrations/v2.0/index.d.ts +7 -0
  80. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/index.js +3572 -0
  82. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  83. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
  85. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  86. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/migrate-scopes.js +282 -0
  88. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  89. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
  91. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  92. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
  94. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  95. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
  97. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  98. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
  100. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  101. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
  103. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  104. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
  106. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
  109. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
  112. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  113. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/rename-api-paths.js +188 -0
  115. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  116. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
  118. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  119. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
  121. package/dist/notification/index.d.ts.map +1 -1
  122. package/dist/notification/index.js +2076 -1767
  123. package/dist/scopes/index.d.ts +640 -353
  124. package/dist/scopes/index.d.ts.map +1 -1
  125. package/dist/scopes/index.js +340 -300
  126. package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
  127. package/package.json +18 -8
  128. package/tsconfig.json +12 -2
  129. package/tsconfig.tsbuildinfo +1 -1
  130. 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,373 @@ 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
+ defineRoles: () => defineRoles,
48
+ defineScopes: () => defineScopes,
49
+ encodeScope: () => encodeScope,
50
+ getAcceptedScopesByType: () => getAcceptedScopesByType,
51
+ getScopeOptionValue: () => getScopeOptionValue,
52
+ hasAnyScope: () => hasAnyScope,
53
+ hasScope: () => hasScope,
54
+ isCustomActionScope: () => isCustomActionScope,
55
+ scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
56
+ scopeUsesFullOptions: () => scopeUsesFullOptions,
57
+ scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
34
58
  });
35
59
  module.exports = __toCommonJS(scopes_exports);
60
+ var z4 = __toESM(require("zod/v4"));
36
61
 
37
62
  // ../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"
63
+ var z3 = __toESM(require("zod/v4"));
64
+ var qs = __toESM(require("qs"));
65
+
66
+ // ../commons/src/uuid.ts
67
+ var import_uuid = require("uuid");
68
+ var z = __toESM(require("zod/v4"));
69
+ var UUID = z.uuid().brand("UUID");
70
+
71
+ // ../commons/src/authentication.ts
72
+ var import_jwt_decode = __toESM(require("jwt-decode"));
73
+ var z2 = __toESM(require("zod/v4"));
74
+ var TokenUserType = z2.enum(["user", "system"]);
75
+ function setBearerForToken(token) {
76
+ const bearer = "Bearer";
77
+ return token.startsWith(bearer) ? token : `${bearer} ${token}`;
78
+ }
79
+ function getScopes(token) {
80
+ const authHeader = { Authorization: setBearerForToken(token) };
81
+ const tokenPayload = getTokenPayload(authHeader.Authorization.split(" ")[1]);
82
+ return tokenPayload.scope || [];
83
+ }
84
+ var getTokenPayload = (token) => {
85
+ let decoded;
86
+ try {
87
+ decoded = (0, import_jwt_decode.default)(token);
88
+ } catch (err) {
89
+ throw new Error(
90
+ `getTokenPayload: Error occurred during token decode : ${err}`
91
+ );
92
+ }
93
+ return decoded;
116
94
  };
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)
95
+ var TokenWithBearer = z2.string().regex(/^Bearer\s/);
96
+
97
+ // ../commons/src/scopes.ts
98
+ var JurisdictionFilter = z3.enum(["administrativeArea", "location", "all"]).describe(
99
+ "Filters based on user jurisdiction relative to their office location in hierarchy."
100
+ );
101
+ var UserFilter = z3.enum(["user"]).describe("Filters based on the user. Limits to self.");
102
+ var RecordScopeTypeV2 = z3.enum([
103
+ "record.search",
104
+ "record.create",
105
+ "record.read",
106
+ "record.declare",
107
+ "record.notify",
108
+ "record.edit",
109
+ "record.reject",
110
+ "record.archive",
111
+ "record.review-duplicates",
112
+ "record.register",
113
+ "record.print-certified-copies",
114
+ "record.request-correction",
115
+ "record.correct",
116
+ "record.unassign-others",
117
+ "record.custom-action"
187
118
  ]);
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
119
+ var PlainScopeType = z3.enum([
120
+ // Misc. system scopes
121
+ "bypassratelimit",
122
+ "record.reindex",
123
+ "user.data-seeding",
124
+ "integration.create",
125
+ "record.import",
126
+ "config.update-all",
127
+ "attachment.upload",
128
+ "profile.electronic-signature",
129
+ "user.read-only-my-audit",
130
+ // Performance dashboard
131
+ "performance.read",
132
+ "performance.read-dashboards",
133
+ "performance.vital-statistics-export",
134
+ // Scopes used exclusively by countryconfig integration token
135
+ "record.confirm-registration",
136
+ "record.reject-registration"
208
137
  ]);
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
- })
138
+ var scopeByEvent = z3.preprocess(
139
+ (val) => val === void 0 ? void 0 : [val].flat(),
140
+ z3.array(z3.string()).optional()
141
+ ).describe("Event type, e.g. birth, death");
142
+ var scopeOptionsPlaceEvent = z3.object({
143
+ event: scopeByEvent,
144
+ placeOfEvent: JurisdictionFilter.optional()
145
+ }).describe("Options applicable to all record scopes.");
146
+ var scopeOptionsDeclared = scopeOptionsPlaceEvent.extend({
147
+ declaredIn: JurisdictionFilter.optional(),
148
+ declaredBy: UserFilter.optional()
149
+ }).describe("Options applicable to actions that may take place after DECLARE");
150
+ var AllRecordScopeOptions = scopeOptionsDeclared.extend({
151
+ registeredIn: JurisdictionFilter.optional(),
152
+ registeredBy: UserFilter.optional()
153
+ }).describe(
154
+ "Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
155
+ );
156
+ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
157
+ customActionTypes: z3.preprocess(
158
+ (val) => val === void 0 ? void 0 : [val].flat(),
159
+ z3.array(z3.string()).optional()
160
+ ).describe("Allowed custom action types")
222
161
  });
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
- })
162
+ var AccessLevelOptions = z3.object({
163
+ accessLevel: JurisdictionFilter.optional()
228
164
  });
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
- })
165
+ var WorkqueueOrDashboardOptions = z3.object({
166
+ ids: z3.preprocess(
167
+ (val) => val === void 0 ? void 0 : [val].flat(),
168
+ z3.array(z3.string())
169
+ ).describe("Must contain a list of workqueue or dashboard ids.")
235
170
  });
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
- })
171
+ var AllScopeOptions = z3.object({
172
+ ...AllRecordScopeOptions.shape,
173
+ ...AccessLevelOptions.shape,
174
+ ...WorkqueueOrDashboardOptions.shape
244
175
  });
245
- var RecordScopeType = import_zod.z.enum([
176
+ var ScopeOptionKey = AllScopeOptions.keyof();
177
+ var ResolvedScopeOptionsPlaceEvent = z3.object({
178
+ event: scopeByEvent,
179
+ placeOfEvent: UUID.nullish()
180
+ }).describe(
181
+ "Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
182
+ );
183
+ var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
184
+ declaredIn: UUID.nullish(),
185
+ declaredBy: z3.string().optional()
186
+ }).describe(
187
+ "Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
188
+ );
189
+ var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
190
+ registeredIn: UUID.nullish(),
191
+ registeredBy: z3.string().optional()
192
+ }).describe(
193
+ "Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
194
+ );
195
+ var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
246
196
  "record.create",
247
- "record.read",
248
197
  "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",
198
+ "record.notify"
199
+ ]);
200
+ var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
201
+ "record.edit",
202
+ "record.reject",
203
+ "record.archive",
204
+ "record.review-duplicates",
205
+ "record.register"
206
+ ]);
207
+ var ScopesWithFullOptions = RecordScopeTypeV2.extract([
208
+ "record.search",
209
+ "record.read",
210
+ "record.request-correction",
211
+ "record.correct",
257
212
  "record.unassign-others"
258
213
  ]);
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")
214
+ var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
215
+ templates: z3.preprocess(
216
+ (val) => val === void 0 ? void 0 : [val].flat(),
217
+ z3.array(z3.string()).optional()
218
+ ).describe(
219
+ "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."
220
+ )
221
+ });
222
+ var RecordScopeV2 = z3.discriminatedUnion("type", [
223
+ z3.object({
224
+ type: ScopesWithPlaceEventOptions,
225
+ options: scopeOptionsPlaceEvent.optional()
226
+ }),
227
+ z3.object({
228
+ type: ScopesWithDeclaredOptions,
229
+ options: scopeOptionsDeclared.optional()
230
+ }),
231
+ z3.object({
232
+ type: ScopesWithFullOptions,
233
+ options: AllRecordScopeOptions.optional()
234
+ }),
235
+ z3.object({
236
+ type: z3.literal("record.custom-action"),
237
+ options: CustomActionScopeOptions.optional()
238
+ }),
239
+ z3.object({
240
+ type: z3.literal("record.print-certified-copies"),
241
+ options: ScopeOptionsPrintCertifiedCopies.optional()
263
242
  })
264
- }).describe(
243
+ ]).describe(
265
244
  "Scopes used to check user's permission to perform actions on a record."
266
245
  );
267
- var ConfigurableRawScopes = import_zod.z.discriminatedUnion("type", [
268
- SearchScope,
269
- PrintCertifiedCopiesScope,
270
- CreateUserScope,
271
- EditUserScope,
272
- WorkqueueScope,
273
- RecordScope
246
+ function scopeUsesDeclaredOptions(scope) {
247
+ return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
248
+ }
249
+ function scopeUsesFullOptions(scope) {
250
+ return ScopesWithFullOptions.options.some((opt) => opt === scope.type);
251
+ }
252
+ function scopeUsesPrintCertifiedCopiesOptions(scope) {
253
+ return scope.type === "record.print-certified-copies";
254
+ }
255
+ function isCustomActionScope(scope) {
256
+ return scope.type === "record.custom-action";
257
+ }
258
+ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
259
+ z3.object({
260
+ type: ScopesWithPlaceEventOptions,
261
+ options: ResolvedScopeOptionsPlaceEvent.optional()
262
+ }),
263
+ z3.object({
264
+ type: ScopesWithDeclaredOptions,
265
+ options: ResolvedScopeOptionsDeclared.optional()
266
+ }),
267
+ z3.object({
268
+ type: ScopesWithFullOptions,
269
+ options: ResolvedScopeOptionsFull.optional()
270
+ }),
271
+ z3.object({
272
+ type: z3.literal("record.print-certified-copies"),
273
+ options: ResolvedScopeOptionsFull.extend({
274
+ templates: z3.array(z3.string()).optional()
275
+ }).optional()
276
+ })
277
+ ]).describe("Resolved scope with location/user IDs instead of filters.");
278
+ var SystemScopeType = z3.enum([
279
+ "organisation.read-locations",
280
+ "user.read",
281
+ "user.create",
282
+ "user.edit"
274
283
  ]);
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 };
284
+ var Scope2 = z3.discriminatedUnion("type", [
285
+ z3.object({ type: PlainScopeType }),
286
+ ...RecordScopeV2.options,
287
+ z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
288
+ z3.object({
289
+ type: z3.literal("workqueue"),
290
+ options: WorkqueueOrDashboardOptions
291
+ }),
292
+ z3.object({
293
+ type: z3.literal("dashboard.view"),
294
+ options: WorkqueueOrDashboardOptions
295
+ })
296
+ ]);
297
+ var ScopeType2 = z3.enum([
298
+ ...SystemScopeType.options,
299
+ ...RecordScopeTypeV2.options,
300
+ ...PlainScopeType.options,
301
+ "workqueue",
302
+ "dashboard.view"
303
+ ]);
304
+ var flattenScope = (scope) => ({
305
+ type: scope.type,
306
+ ..."options" in scope ? scope.options : {}
307
+ });
308
+ var unflattenScope = (input) => {
309
+ const { type, ...options } = input;
310
+ return { type, options };
311
+ };
312
+ var EncodedScope2 = z3.string().brand("EncodedScope");
313
+ var encodeScope = (scope) => {
314
+ const flattened = flattenScope(scope);
315
+ return qs.stringify(flattened, {
316
+ arrayFormat: "comma",
317
+ allowDots: true,
318
+ addQueryPrefix: false,
319
+ encode: false
320
+ });
321
+ };
322
+ var decodeScope = (query) => {
323
+ const scope = qs.parse(query, {
324
+ ignoreQueryPrefix: true,
325
+ comma: true,
326
+ allowDots: true
327
+ });
328
+ const unflattenedScope = unflattenScope(scope);
329
+ return Scope2.safeParse(unflattenedScope)?.data;
330
+ };
331
+ var DEFAULT_SCOPE_OPTIONS = {
332
+ placeOfEvent: JurisdictionFilter.enum.all,
333
+ accessLevel: JurisdictionFilter.enum.all
334
+ };
335
+ function getScopeOptionValue(scope, option) {
336
+ const options = "options" in scope ? scope.options : void 0;
337
+ const value = options?.[option];
338
+ const defaultValue = option in DEFAULT_SCOPE_OPTIONS ? DEFAULT_SCOPE_OPTIONS[option] : void 0;
339
+ return value ?? defaultValue;
289
340
  }
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
- );
341
+ function getAcceptedScopesByType({
342
+ acceptedScopes,
343
+ scopes
344
+ }) {
345
+ return scopes.map((scope) => {
346
+ const parsedScope = decodeScope(scope);
347
+ return parsedScope && acceptedScopes.some(
348
+ (acceptedScope) => acceptedScope === parsedScope.type
349
+ ) ? parsedScope : null;
350
+ }).filter((scope) => scope !== null);
298
351
  }
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
- }, {});
352
+ function hasAnyScope(tokenOrScopes, scopes) {
353
+ const userScopes = Array.isArray(tokenOrScopes) ? tokenOrScopes : getScopes(tokenOrScopes);
354
+ const foundScopes = getAcceptedScopesByType({
355
+ acceptedScopes: scopes,
356
+ scopes: userScopes
357
+ });
358
+ return foundScopes.length > 0;
305
359
  }
306
- function parseConfigurableScope(scope) {
307
- const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
308
- if (!maybeConfigurableScope.success) {
309
- return;
360
+ function hasScope(tokenOrScopes, scope) {
361
+ if (Array.isArray(tokenOrScopes)) {
362
+ return getAcceptedScopesByType({
363
+ acceptedScopes: [scope],
364
+ scopes: tokenOrScopes
365
+ }).length > 0;
310
366
  }
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;
367
+ return hasAnyScope(tokenOrScopes, [scope]);
320
368
  }
321
- function parseLiteralScope(scope) {
322
- const maybeLiteralScope = LiteralScopes.safeParse(scope);
323
- if (maybeLiteralScope.success) {
324
- return {
325
- type: maybeLiteralScope.data
326
- };
327
- }
328
- return;
369
+ function canUserCreateEvent(userScopes, eventType) {
370
+ const scopes = getAcceptedScopesByType({
371
+ acceptedScopes: ["record.create"],
372
+ scopes: userScopes
373
+ });
374
+ return scopes.some((scope) => {
375
+ if (!("options" in scope) || !scope.options || !("event" in scope.options)) {
376
+ return true;
377
+ }
378
+ return scope.options?.event?.includes(eventType);
379
+ });
329
380
  }
330
- function stringifyScope(scope) {
331
- const options = Object.entries(scope.options).map(([key, value]) => `${key}=${value.join("|")}`).join(",");
332
- return `${scope.type}[${options}]`;
381
+ function defineScopes(scopes) {
382
+ return scopes.map((scope) => Scope2.parse(scope)).map(encodeScope);
333
383
  }
334
- function getAuthorizedEventsFromScopes(scopes2) {
335
- return scopes2.flatMap(({ options }) => {
336
- if (options && "event" in options) {
337
- return options.event;
338
- }
339
- return void 0;
340
- }).filter((event) => event !== void 0).filter((event, index, self) => self.indexOf(event) === index);
384
+ function defineRoles(roles) {
385
+ return roles;
341
386
  }
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
- ]);
387
+
388
+ // src/scopes/index.ts
389
+ z4.globalRegistry.clear();