@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.
- package/build.sh +13 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/application-config/index.d.ts +2 -0
- package/dist/application-config/index.d.ts.map +1 -0
- package/dist/application-config/index.js +2128 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3633 -0
- package/dist/commons/api/router.d.ts +3438 -2300
- package/dist/commons/application-config/index.d.ts +84 -0
- package/dist/commons/conditionals/conditionals.d.ts +27 -3
- package/dist/commons/conditionals/validate.d.ts +13 -3
- package/dist/commons/events/ActionConfig.d.ts +415 -1555
- package/dist/commons/events/ActionDocument.d.ts +888 -1941
- package/dist/commons/events/ActionInput.d.ts +277 -1073
- package/dist/commons/events/ActionType.d.ts +91 -11
- package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
- package/dist/commons/events/AuditLog.d.ts +405 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
- package/dist/commons/events/Conditional.d.ts +26 -38
- package/dist/commons/events/Constants.d.ts +1 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
- package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
- package/dist/commons/events/Draft.d.ts +72 -107
- package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
- package/dist/commons/events/EventConfig.d.ts +37 -2420
- package/dist/commons/events/EventConfigInput.d.ts +0 -3
- package/dist/commons/events/EventDocument.d.ts +354 -1366
- package/dist/commons/events/EventIndex.d.ts +212 -1010
- package/dist/commons/events/EventInput.d.ts +3 -8
- package/dist/commons/events/EventMetadata.d.ts +130 -357
- package/dist/commons/events/FieldConfig.d.ts +2892 -12892
- package/dist/commons/events/FieldType.d.ts +26 -4
- package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
- package/dist/commons/events/FieldValue.d.ts +149 -527
- package/dist/commons/events/FileUtils.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +67 -0
- package/dist/commons/events/FormConfig.d.ts +54 -721
- package/dist/commons/events/PageConfig.d.ts +58 -320
- package/dist/commons/events/PlainDate.d.ts +1 -1
- package/dist/commons/events/SummaryConfig.d.ts +14 -161
- package/dist/commons/events/TemplateConfig.d.ts +2 -3
- package/dist/commons/events/TranslationConfig.d.ts +2 -2
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
- package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
- package/dist/commons/events/deduplication.d.ts +3 -3
- package/dist/commons/events/defineConfig.d.ts +2 -247
- package/dist/commons/events/eventConfigValidation.d.ts +8 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +57 -20
- package/dist/commons/events/scopes.d.ts +36 -35
- package/dist/commons/events/state/availableActions.d.ts +7 -2
- package/dist/commons/events/state/flags.d.ts +21 -3
- package/dist/commons/events/state/index.d.ts +30 -27
- package/dist/commons/events/state/utils.d.ts +190 -172
- package/dist/commons/events/test.utils.d.ts +52 -11
- package/dist/commons/events/transactions.d.ts +1 -1
- package/dist/commons/events/utils.d.ts +373 -273
- package/dist/commons/notification/UserNotifications.d.ts +61 -637
- package/dist/conditionals/index.d.ts.map +1 -1
- package/dist/conditionals/index.js +302 -14
- package/dist/events/deduplication.d.ts +3 -3
- package/dist/events/index.js +2860 -2115
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +405 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +829 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +326 -0
- package/dist/migrations/v2.0/index.d.ts +7 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -0
- package/dist/migrations/v2.0/index.js +3572 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-scopes.js +282 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-api-paths.js +188 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
- package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
- package/dist/notification/index.d.ts.map +1 -1
- package/dist/notification/index.js +2076 -1767
- package/dist/scopes/index.d.ts +640 -353
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +340 -300
- package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
- package/package.json +18 -8
- package/tsconfig.json +12 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
package/dist/scopes/index.js
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
|
224
|
-
|
|
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
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
"record.
|
|
253
|
-
"record.
|
|
254
|
-
"record.
|
|
255
|
-
"record.
|
|
256
|
-
"record.
|
|
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
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
243
|
+
]).describe(
|
|
265
244
|
"Scopes used to check user's permission to perform actions on a record."
|
|
266
245
|
);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
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
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
|
331
|
-
|
|
332
|
-
return `${scope.type}[${options}]`;
|
|
381
|
+
function defineScopes(scopes) {
|
|
382
|
+
return scopes.map((scope) => Scope2.parse(scope)).map(encodeScope);
|
|
333
383
|
}
|
|
334
|
-
function
|
|
335
|
-
return
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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();
|