@opencrvs/toolkit 1.9.13-rc.72233cd → 1.9.13-rc.76fce04

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 (121) hide show
  1. package/build.sh +0 -13
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/commons/api/router.d.ts +4561 -3370
  4. package/dist/commons/conditionals/conditionals.d.ts +3 -27
  5. package/dist/commons/conditionals/validate.d.ts +3 -13
  6. package/dist/commons/events/ActionConfig.d.ts +1555 -415
  7. package/dist/commons/events/ActionDocument.d.ts +1941 -888
  8. package/dist/commons/events/ActionInput.d.ts +1277 -277
  9. package/dist/commons/events/ActionType.d.ts +11 -91
  10. package/dist/commons/events/AdvancedSearchConfig.d.ts +1496 -294
  11. package/dist/commons/events/CompositeFieldValue.d.ts +190 -30
  12. package/dist/commons/events/Conditional.d.ts +38 -26
  13. package/dist/commons/events/Constants.d.ts +1 -1
  14. package/dist/commons/events/CountryConfigQueryInput.d.ts +4471 -1592
  15. package/dist/commons/events/CreatedAtLocation.d.ts +2 -0
  16. package/dist/commons/events/DeduplicationConfig.d.ts +171 -15
  17. package/dist/commons/events/Draft.d.ts +113 -72
  18. package/dist/commons/events/DynamicFieldValue.d.ts +78 -12
  19. package/dist/commons/events/EventConfig.d.ts +2420 -35
  20. package/dist/commons/events/EventConfigInput.d.ts +3 -0
  21. package/dist/commons/events/EventDocument.d.ts +1366 -354
  22. package/dist/commons/events/EventIndex.d.ts +1010 -212
  23. package/dist/commons/events/EventInput.d.ts +8 -3
  24. package/dist/commons/events/EventMetadata.d.ts +357 -130
  25. package/dist/commons/events/FieldConfig.d.ts +12890 -2890
  26. package/dist/commons/events/FieldType.d.ts +4 -26
  27. package/dist/commons/events/FieldTypeMapping.d.ts +906 -314
  28. package/dist/commons/events/FieldValue.d.ts +527 -149
  29. package/dist/commons/events/FileUtils.d.ts +2 -2
  30. package/dist/commons/events/FormConfig.d.ts +721 -54
  31. package/dist/commons/events/PageConfig.d.ts +320 -58
  32. package/dist/commons/events/PlainDate.d.ts +1 -1
  33. package/dist/commons/events/SummaryConfig.d.ts +161 -14
  34. package/dist/commons/events/TemplateConfig.d.ts +3 -2
  35. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  36. package/dist/commons/events/WorkqueueColumnConfig.d.ts +37 -74
  37. package/dist/commons/events/WorkqueueConfig.d.ts +7480 -2135
  38. package/dist/commons/events/deduplication.d.ts +3 -3
  39. package/dist/commons/events/defineConfig.d.ts +247 -2
  40. package/dist/commons/events/index.d.ts +0 -3
  41. package/dist/commons/events/locations.d.ts +20 -57
  42. package/dist/commons/events/scopes.d.ts +34 -35
  43. package/dist/commons/events/state/availableActions.d.ts +2 -7
  44. package/dist/commons/events/state/flags.d.ts +3 -21
  45. package/dist/commons/events/state/index.d.ts +27 -30
  46. package/dist/commons/events/state/utils.d.ts +172 -190
  47. package/dist/commons/events/test.utils.d.ts +11 -52
  48. package/dist/commons/events/transactions.d.ts +1 -1
  49. package/dist/commons/events/utils.d.ts +274 -374
  50. package/dist/commons/notification/UserNotifications.d.ts +637 -61
  51. package/dist/conditionals/index.d.ts.map +1 -1
  52. package/dist/conditionals/index.js +14 -302
  53. package/dist/events/deduplication.d.ts +3 -3
  54. package/dist/events/index.js +2113 -2847
  55. package/dist/notification/index.d.ts.map +1 -1
  56. package/dist/notification/index.js +1769 -2073
  57. package/dist/scopes/index.d.ts +353 -640
  58. package/dist/scopes/index.d.ts.map +1 -1
  59. package/dist/scopes/index.js +300 -340
  60. package/package.json +3 -13
  61. package/tsconfig.json +2 -12
  62. package/tsconfig.tsbuildinfo +1 -1
  63. package/dist/application-config/index.d.ts +0 -2
  64. package/dist/application-config/index.d.ts.map +0 -1
  65. package/dist/application-config/index.js +0 -2128
  66. package/dist/cli.d.ts +0 -2
  67. package/dist/cli.d.ts.map +0 -1
  68. package/dist/cli.js +0 -3237
  69. package/dist/commons/application-config/index.d.ts +0 -84
  70. package/dist/commons/events/AuditLog.d.ts +0 -405
  71. package/dist/commons/events/Flag.d.ts +0 -67
  72. package/dist/commons/events/eventConfigValidation.d.ts +0 -8
  73. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  74. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  75. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -405
  76. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  77. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  78. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -829
  79. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  80. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  81. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -159
  82. package/dist/migrations/v2.0/index.d.ts +0 -7
  83. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  84. package/dist/migrations/v2.0/index.js +0 -3176
  85. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  86. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  87. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -344
  88. package/dist/migrations/v2.0/migrate-scopes.d.ts +0 -3
  89. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  90. package/dist/migrations/v2.0/migrate-scopes.js +0 -282
  91. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  92. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  93. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -268
  94. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  95. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  96. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -237
  97. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  98. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  99. package/dist/migrations/v2.0/remove-delete-actions.js +0 -157
  100. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  101. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  102. package/dist/migrations/v2.0/remove-demo-scope.js +0 -75
  103. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  104. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  105. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -97
  106. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  107. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  108. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -78
  109. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  110. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  111. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -110
  112. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  113. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  114. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -164
  115. package/dist/migrations/v2.0/rename-api-paths.d.ts +0 -3
  116. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  117. package/dist/migrations/v2.0/rename-api-paths.js +0 -188
  118. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  119. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  120. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -181
  121. package/opencrvs-toolkit-1.9.13-rc.72233cd.tgz +0 -0
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,373 +15,335 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/scopes/index.ts
31
21
  var scopes_exports = {};
32
22
  __export(scopes_exports, {
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
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
58
34
  });
59
35
  module.exports = __toCommonJS(scopes_exports);
60
- var z4 = __toESM(require("zod/v4"));
61
36
 
62
37
  // ../commons/src/scopes.ts
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;
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"
94
116
  };
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"
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)
118
122
  ]);
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"
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)
137
128
  ]);
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")
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)
187
+ ]);
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
208
+ ]);
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
+ })
161
216
  });
162
- var AccessLevelOptions = z3.object({
163
- accessLevel: JurisdictionFilter.optional()
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
+ })
164
222
  });
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.")
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
+ })
170
228
  });
171
- var AllScopeOptions = z3.object({
172
- ...AllRecordScopeOptions.shape,
173
- ...AccessLevelOptions.shape,
174
- ...WorkqueueOrDashboardOptions.shape
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
+ })
175
235
  });
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([
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
+ })
244
+ });
245
+ var RecordScopeType = import_zod.z.enum([
196
246
  "record.create",
197
- "record.declare",
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
247
  "record.read",
210
- "record.request-correction",
211
- "record.correct",
248
+ "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",
212
257
  "record.unassign-others"
213
258
  ]);
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()
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")
242
263
  })
243
- ]).describe(
264
+ }).describe(
244
265
  "Scopes used to check user's permission to perform actions on a record."
245
266
  );
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"
267
+ var ConfigurableRawScopes = import_zod.z.discriminatedUnion("type", [
268
+ SearchScope,
269
+ PrintCertifiedCopiesScope,
270
+ CreateUserScope,
271
+ EditUserScope,
272
+ WorkqueueScope,
273
+ RecordScope
283
274
  ]);
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;
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 };
340
289
  }
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);
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
+ );
351
298
  }
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;
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
+ }, {});
359
305
  }
360
- function hasScope(tokenOrScopes, scope) {
361
- if (Array.isArray(tokenOrScopes)) {
362
- return getAcceptedScopesByType({
363
- acceptedScopes: [scope],
364
- scopes: tokenOrScopes
365
- }).length > 0;
306
+ function parseConfigurableScope(scope) {
307
+ const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
308
+ if (!maybeConfigurableScope.success) {
309
+ return;
366
310
  }
367
- return hasAnyScope(tokenOrScopes, [scope]);
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;
368
320
  }
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
- });
321
+ function parseLiteralScope(scope) {
322
+ const maybeLiteralScope = LiteralScopes.safeParse(scope);
323
+ if (maybeLiteralScope.success) {
324
+ return {
325
+ type: maybeLiteralScope.data
326
+ };
327
+ }
328
+ return;
380
329
  }
381
- function defineScopes(scopes) {
382
- return scopes.map((scope) => Scope2.parse(scope)).map(encodeScope);
330
+ function stringifyScope(scope) {
331
+ const options = Object.entries(scope.options).map(([key, value]) => `${key}=${value.join("|")}`).join(",");
332
+ return `${scope.type}[${options}]`;
383
333
  }
384
- function defineRoles(roles) {
385
- return roles;
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);
386
341
  }
387
-
388
- // src/scopes/index.ts
389
- z4.globalRegistry.clear();
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
+ ]);