@opencrvs/toolkit 1.8.0-rc.f89fbcb → 1.8.0-rc.f8aa0c5
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/dist/commons/api/router.d.ts +589 -589
- package/dist/commons/events/ActionConfig.d.ts +256 -0
- package/dist/commons/events/ActionDocument.d.ts +700 -700
- package/dist/commons/events/ActionInput.d.ts +600 -600
- package/dist/commons/events/AdvancedSearchConfig.d.ts +18 -40
- package/dist/commons/events/CompositeFieldValue.d.ts +6 -6
- package/dist/commons/events/Draft.d.ts +54 -54
- package/dist/commons/events/EventConfig.d.ts +106 -18
- package/dist/commons/events/EventDocument.d.ts +436 -436
- package/dist/commons/events/EventIndex.d.ts +15 -10
- package/dist/commons/events/FieldConfig.d.ts +20 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +16 -16
- package/dist/commons/events/FieldValue.d.ts +12 -12
- package/dist/commons/events/FormConfig.d.ts +108 -0
- package/dist/commons/events/PageConfig.d.ts +28 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +14 -14
- package/dist/commons/events/defineConfig.d.ts +22 -2
- package/dist/commons/events/field.d.ts +1 -13
- package/dist/commons/events/test.utils.d.ts +12 -12
- package/dist/commons/events/utils.d.ts +41 -11
- package/dist/events/index.js +48 -57
- package/dist/scopes/index.d.ts +92 -6
- package/dist/scopes/index.js +38 -9
- package/package.json +1 -1
package/dist/events/index.js
CHANGED
@@ -155,6 +155,7 @@ __export(events_exports, {
|
|
155
155
|
RuralAddressValue: () => RuralAddressValue,
|
156
156
|
SearchField: () => SearchField,
|
157
157
|
SearchQueryParams: () => SearchQueryParams,
|
158
|
+
SearchScopeAccessLevels: () => SearchScopeAccessLevels,
|
158
159
|
SelectOption: () => SelectOption,
|
159
160
|
ShowConditional: () => ShowConditional,
|
160
161
|
SignatureFieldValue: () => SignatureFieldValue,
|
@@ -187,6 +188,7 @@ __export(events_exports, {
|
|
187
188
|
alwaysTrue: () => alwaysTrue,
|
188
189
|
and: () => and,
|
189
190
|
annotationActions: () => annotationActions,
|
191
|
+
applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
|
190
192
|
applyDraftsToEventIndex: () => applyDraftsToEventIndex,
|
191
193
|
areConditionsMet: () => areConditionsMet,
|
192
194
|
compositeFieldTypes: () => compositeFieldTypes,
|
@@ -306,6 +308,7 @@ __export(events_exports, {
|
|
306
308
|
omitHiddenFields: () => omitHiddenFields,
|
307
309
|
omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
|
308
310
|
or: () => or,
|
311
|
+
resolveDateOfEvent: () => resolveDateOfEvent,
|
309
312
|
runFieldValidations: () => runFieldValidations,
|
310
313
|
user: () => user,
|
311
314
|
validate: () => validate,
|
@@ -481,8 +484,8 @@ var NameFieldValue = import_zod3.z.object({
|
|
481
484
|
middlename: import_zod3.z.string().optional()
|
482
485
|
});
|
483
486
|
var NameFieldUpdateValue = import_zod3.z.object({
|
484
|
-
firstname: import_zod3.z.string(),
|
485
|
-
surname: import_zod3.z.string(),
|
487
|
+
firstname: import_zod3.z.string().nullish(),
|
488
|
+
surname: import_zod3.z.string().nullish(),
|
486
489
|
middlename: import_zod3.z.string().nullish()
|
487
490
|
}).or(import_zod3.z.null()).or(import_zod3.z.undefined());
|
488
491
|
var RuralAddressUpdateValue = AdminStructure.extend({
|
@@ -748,7 +751,9 @@ var NameField = BaseField.extend({
|
|
748
751
|
configuration: import_zod5.z.object({
|
749
752
|
maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
|
750
753
|
prefix: TranslationConfig.optional(),
|
751
|
-
postfix: TranslationConfig.optional()
|
754
|
+
postfix: TranslationConfig.optional(),
|
755
|
+
includeMiddlename: import_zod5.z.boolean().default(false).optional().describe("To make middle name visible in Name form field"),
|
756
|
+
searchMode: import_zod5.z.boolean().optional()
|
752
757
|
}).optional()
|
753
758
|
}).describe("Name input field");
|
754
759
|
var PhoneField = BaseField.extend({
|
@@ -1305,17 +1310,7 @@ var SearchQueryParams = import_zod14.z.object({
|
|
1305
1310
|
}).catchall(FieldValue);
|
1306
1311
|
var FieldConfigSchema = BaseField3.extend({
|
1307
1312
|
fieldId: import_zod14.z.string(),
|
1308
|
-
fieldType: import_zod14.z.literal("field")
|
1309
|
-
alternateFieldIds: import_zod14.z.array(import_zod14.z.string()).optional().describe(
|
1310
|
-
`Sometimes there might be need to search a value against multiple field of same FormField type. For example
|
1311
|
-
search Country, Province, District against child.address.private and child.address.other. In such case, we
|
1312
|
-
add a one field as fieldId, and accomodate others in alternateFieldIds`
|
1313
|
-
),
|
1314
|
-
excludeInSearchQuery: import_zod14.z.boolean().default(false).optional().describe(`Sometimes there will be search fields which are used to
|
1315
|
-
conditionally display another search field, but its not needed in search query. For example, child.placeOfBirth
|
1316
|
-
is select field, which has 3 options, FACILITY, PRIVATE_HOME, OTHER. Upon selecting any of the option, pops up another field
|
1317
|
-
related to the selected option, whose value is required in the search query. But child.placeOfBirth itself is not needed in the query.
|
1318
|
-
In such case, populate this field (excludeInSearchQuery) with boolean true`)
|
1313
|
+
fieldType: import_zod14.z.literal("field")
|
1319
1314
|
});
|
1320
1315
|
var EventFieldId = import_zod14.z.enum([
|
1321
1316
|
"trackingId",
|
@@ -1618,7 +1613,15 @@ var NotifyRecordScope = import_zod16.z.object({
|
|
1618
1613
|
event: import_zod16.z.array(import_zod16.z.string())
|
1619
1614
|
})
|
1620
1615
|
});
|
1621
|
-
var
|
1616
|
+
var SearchScope = import_zod16.z.object({
|
1617
|
+
type: import_zod16.z.literal("search"),
|
1618
|
+
options: import_zod16.z.object({
|
1619
|
+
event: import_zod16.z.array(import_zod16.z.string()).length(1),
|
1620
|
+
access: import_zod16.z.array(import_zod16.z.enum(["my-jurisdiction", "all"])).length(1)
|
1621
|
+
})
|
1622
|
+
});
|
1623
|
+
var ConfigurableRawScopes = import_zod16.z.discriminatedUnion("type", [
|
1624
|
+
SearchScope,
|
1622
1625
|
CreateUserScope,
|
1623
1626
|
EditUserScope,
|
1624
1627
|
WorkqueueScope,
|
@@ -2638,28 +2641,6 @@ var EventConfig = import_zod20.z.object({
|
|
2638
2641
|
path: ["advancedSearch"]
|
2639
2642
|
});
|
2640
2643
|
}
|
2641
|
-
event2.advancedSearch.forEach((section, sectionIndex) => {
|
2642
|
-
section.fields.forEach((field2, fieldIndex) => {
|
2643
|
-
if ("alternateFieldIds" in field2 && Array.isArray(field2.alternateFieldIds)) {
|
2644
|
-
const invalidAltIds = field2.alternateFieldIds.filter(
|
2645
|
-
(id) => !fieldIds.includes(id)
|
2646
|
-
);
|
2647
|
-
if (invalidAltIds.length > 0) {
|
2648
|
-
ctx.addIssue({
|
2649
|
-
code: "custom",
|
2650
|
-
message: `Invalid alternateFieldIds: ${invalidAltIds.join(", ")}`,
|
2651
|
-
path: [
|
2652
|
-
"advancedSearch",
|
2653
|
-
sectionIndex,
|
2654
|
-
"fields",
|
2655
|
-
fieldIndex,
|
2656
|
-
"alternateFieldIds"
|
2657
|
-
]
|
2658
|
-
});
|
2659
|
-
}
|
2660
|
-
}
|
2661
|
-
});
|
2662
|
-
});
|
2663
2644
|
if (event2.dateOfEvent) {
|
2664
2645
|
const eventDateFieldId = getDeclarationFields(event2).find(
|
2665
2646
|
({ id }) => id === event2.dateOfEvent?.$$field
|
@@ -3436,6 +3417,10 @@ var QueryType = import_zod24.z.object({
|
|
3436
3417
|
}).openapi({
|
3437
3418
|
ref: "QueryType"
|
3438
3419
|
});
|
3420
|
+
var SearchScopeAccessLevels = {
|
3421
|
+
MY_JURISDICTION: "my-jurisdiction",
|
3422
|
+
ALL: "all"
|
3423
|
+
};
|
3439
3424
|
|
3440
3425
|
// ../commons/src/events/CountryConfigQueryInput.ts
|
3441
3426
|
var SerializableExact = import_zod25.z.object({
|
@@ -4101,6 +4086,13 @@ function getAcceptedActions(event2) {
|
|
4101
4086
|
);
|
4102
4087
|
}
|
4103
4088
|
var DEFAULT_DATE_OF_EVENT_PROPERTY = "createdAt";
|
4089
|
+
function resolveDateOfEvent(eventMetadata, declaration, config) {
|
4090
|
+
if (!config.dateOfEvent) {
|
4091
|
+
return eventMetadata[DEFAULT_DATE_OF_EVENT_PROPERTY].split("T")[0];
|
4092
|
+
}
|
4093
|
+
const parsedDate = ZodDate.safeParse(declaration[config.dateOfEvent.$$field]);
|
4094
|
+
return parsedDate.success ? parsedDate.data : void 0;
|
4095
|
+
}
|
4104
4096
|
function getCurrentEventState(event2, config) {
|
4105
4097
|
const creationAction = event2.actions.find(
|
4106
4098
|
(action) => action.type === ActionType.CREATE
|
@@ -4114,17 +4106,6 @@ function getCurrentEventState(event2, config) {
|
|
4114
4106
|
const requestActionMetadata = getActionUpdateMetadata(event2.actions);
|
4115
4107
|
const acceptedActionMetadata = getActionUpdateMetadata(acceptedActions);
|
4116
4108
|
const declaration = aggregateActionDeclarations(acceptedActions);
|
4117
|
-
let dateOfEvent;
|
4118
|
-
if (config.dateOfEvent) {
|
4119
|
-
const parsedDate = ZodDate.safeParse(
|
4120
|
-
declaration[config.dateOfEvent.$$field]
|
4121
|
-
);
|
4122
|
-
if (parsedDate.success) {
|
4123
|
-
dateOfEvent = parsedDate.data;
|
4124
|
-
}
|
4125
|
-
} else {
|
4126
|
-
dateOfEvent = event2[DEFAULT_DATE_OF_EVENT_PROPERTY].split("T")[0];
|
4127
|
-
}
|
4128
4109
|
return deepDropNulls({
|
4129
4110
|
id: event2.id,
|
4130
4111
|
type: event2.type,
|
@@ -4143,7 +4124,7 @@ function getCurrentEventState(event2, config) {
|
|
4143
4124
|
declaration,
|
4144
4125
|
trackingId: event2.trackingId,
|
4145
4126
|
updatedByUserRole: requestActionMetadata.createdByRole,
|
4146
|
-
dateOfEvent,
|
4127
|
+
dateOfEvent: resolveDateOfEvent(event2, declaration, config),
|
4147
4128
|
flags: getFlagsFromActions(event2.actions)
|
4148
4129
|
});
|
4149
4130
|
}
|
@@ -4172,19 +4153,29 @@ function getCurrentEventStateWithDrafts({
|
|
4172
4153
|
};
|
4173
4154
|
return getCurrentEventState(withDrafts, configuration);
|
4174
4155
|
}
|
4175
|
-
function
|
4156
|
+
function applyDeclarationToEventIndex(eventIndex, declaration, eventConfiguration) {
|
4157
|
+
const updatedDeclaration = deepMerge(eventIndex.declaration, declaration);
|
4158
|
+
return {
|
4159
|
+
...eventIndex,
|
4160
|
+
dateOfEvent: resolveDateOfEvent(
|
4161
|
+
eventIndex,
|
4162
|
+
updatedDeclaration,
|
4163
|
+
eventConfiguration
|
4164
|
+
),
|
4165
|
+
declaration: updatedDeclaration
|
4166
|
+
};
|
4167
|
+
}
|
4168
|
+
function applyDraftsToEventIndex(eventIndex, drafts, eventConfiguration) {
|
4176
4169
|
const indexedAt = eventIndex.updatedAt;
|
4177
4170
|
const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
|
4178
4171
|
if (activeDrafts.length === 0) {
|
4179
4172
|
return eventIndex;
|
4180
4173
|
}
|
4181
|
-
return
|
4182
|
-
|
4183
|
-
declaration
|
4184
|
-
|
4185
|
-
|
4186
|
-
}
|
4187
|
-
};
|
4174
|
+
return applyDeclarationToEventIndex(
|
4175
|
+
eventIndex,
|
4176
|
+
activeDrafts[activeDrafts.length - 1].declaration,
|
4177
|
+
eventConfiguration
|
4178
|
+
);
|
4188
4179
|
}
|
4189
4180
|
function getAnnotationFromDrafts(drafts) {
|
4190
4181
|
const actions = drafts.map((draft) => draft.action);
|
package/dist/scopes/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { z } from 'zod';
|
2
|
+
import { SearchScopeAccessLevels } from './events';
|
2
3
|
export declare const SCOPES: {
|
3
4
|
readonly NATLSYSADMIN: "natlsysadmin";
|
4
5
|
readonly BYPASSRATELIMIT: "bypassratelimit";
|
@@ -87,7 +88,77 @@ export declare const SCOPES: {
|
|
87
88
|
};
|
88
89
|
export declare const SearchScopes: z.ZodUnion<[z.ZodLiteral<"search.birth:my-jurisdiction">, z.ZodLiteral<"search.birth">, z.ZodLiteral<"search.death:my-jurisdiction">, z.ZodLiteral<"search.death">, z.ZodLiteral<"search.marriage:my-jurisdiction">, z.ZodLiteral<"search.marriage">]>;
|
89
90
|
declare const LiteralScopes: z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"natlsysadmin">, z.ZodLiteral<"bypassratelimit">, z.ZodLiteral<"declare">, z.ZodLiteral<"register">, z.ZodLiteral<"validate">, z.ZodLiteral<"demo">, z.ZodLiteral<"certify">, z.ZodLiteral<"performance">, z.ZodLiteral<"sysadmin">, z.ZodLiteral<"teams">, z.ZodLiteral<"config">]>, z.ZodUnion<[z.ZodLiteral<"webhook">, z.ZodLiteral<"nationalId">, z.ZodLiteral<"notification-api">, z.ZodLiteral<"recordsearch">]>, z.ZodLiteral<"record.unassign-others">, z.ZodUnion<[z.ZodLiteral<"record.declare-birth">, z.ZodLiteral<"record.import">, z.ZodLiteral<"record.declare-birth">, z.ZodLiteral<"record.declare-birth:my-jurisdiction">, z.ZodLiteral<"record.declare-death">, z.ZodLiteral<"record.declare-death:my-jurisdiction">, z.ZodLiteral<"record.declare-marriage">, z.ZodLiteral<"record.declare-marriage:my-jurisdiction">, z.ZodLiteral<"record.declaration-submit-incomplete">, z.ZodLiteral<"record.declaration-submit-for-review">]>, z.ZodUnion<[z.ZodLiteral<"record.declaration-submit-for-approval">, z.ZodLiteral<"record.declaration-submit-for-updates">, z.ZodLiteral<"record.declaration-edit">, z.ZodLiteral<"record.review-duplicates">, z.ZodLiteral<"record.declaration-archive">, z.ZodLiteral<"record.declaration-reinstate">]>, z.ZodLiteral<"record.register">, z.ZodUnion<[z.ZodLiteral<"record.export-records">, z.ZodLiteral<"record.declaration-print">, z.ZodLiteral<"record.declaration-print-supporting-documents">, z.ZodLiteral<"record.registration-print">, z.ZodLiteral<"record.registration-print&issue-certified-copies">, z.ZodLiteral<"record.registration-print-certified-copies">, z.ZodLiteral<"record.registration-bulk-print-certified-copies">, z.ZodLiteral<"record.registration-verify-certified-copies">]>, z.ZodUnion<[z.ZodLiteral<"record.registration-request-correction">, z.ZodLiteral<"record.registration-correct">, z.ZodLiteral<"record.registration-request-revocation">, z.ZodLiteral<"record.registration-revoke">, z.ZodLiteral<"record.registration-request-reinstatement">, z.ZodLiteral<"record.registration-reinstate">, z.ZodLiteral<"record.confirm-registration">, z.ZodLiteral<"record.reject-registration">]>, z.ZodUnion<[z.ZodLiteral<"search.birth:my-jurisdiction">, z.ZodLiteral<"search.birth">, z.ZodLiteral<"search.death:my-jurisdiction">, z.ZodLiteral<"search.death">, z.ZodLiteral<"search.marriage:my-jurisdiction">, z.ZodLiteral<"search.marriage">]>, z.ZodUnion<[z.ZodLiteral<"record.read">, z.ZodLiteral<"record.read-audit">, z.ZodLiteral<"record.read-comments">, z.ZodLiteral<"record.create-comments">]>, z.ZodUnion<[z.ZodLiteral<"profile.update">, z.ZodLiteral<"profile.electronic-signature">]>, z.ZodUnion<[z.ZodLiteral<"performance.read">, z.ZodLiteral<"performance.read-dashboards">, z.ZodLiteral<"performance.vital-statistics-export">]>, z.ZodUnion<[z.ZodLiteral<"organisation.read-locations:all">, z.ZodLiteral<"organisation.read-locations:my-office">, z.ZodLiteral<"organisation.read-locations:my-jurisdiction">]>, z.ZodUnion<[z.ZodLiteral<"user.read:all">, z.ZodLiteral<"user.read:my-office">, z.ZodLiteral<"user.read:my-jurisdiction">, z.ZodLiteral<"user.read:only-my-audit">, z.ZodLiteral<"user.create:all">, z.ZodLiteral<"user.create:my-jurisdiction">, z.ZodLiteral<"user.update:all">, z.ZodLiteral<"user.update:my-jurisdiction">]>, z.ZodLiteral<"config.update:all">, z.ZodLiteral<"user.data-seeding">]>;
|
90
|
-
declare const
|
91
|
+
declare const NotifyRecordScope: z.ZodObject<{
|
92
|
+
type: z.ZodLiteral<"record.notify">;
|
93
|
+
options: z.ZodObject<{
|
94
|
+
event: z.ZodArray<z.ZodString, "many">;
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
96
|
+
event: string[];
|
97
|
+
}, {
|
98
|
+
event: string[];
|
99
|
+
}>;
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
101
|
+
type: "record.notify";
|
102
|
+
options: {
|
103
|
+
event: string[];
|
104
|
+
};
|
105
|
+
}, {
|
106
|
+
type: "record.notify";
|
107
|
+
options: {
|
108
|
+
event: string[];
|
109
|
+
};
|
110
|
+
}>;
|
111
|
+
declare const SearchScope: z.ZodObject<{
|
112
|
+
type: z.ZodLiteral<"search">;
|
113
|
+
options: z.ZodObject<{
|
114
|
+
event: z.ZodArray<z.ZodString, "many">;
|
115
|
+
access: z.ZodArray<z.ZodEnum<["my-jurisdiction", "all"]>, "many">;
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
117
|
+
event: string[];
|
118
|
+
access: ("my-jurisdiction" | "all")[];
|
119
|
+
}, {
|
120
|
+
event: string[];
|
121
|
+
access: ("my-jurisdiction" | "all")[];
|
122
|
+
}>;
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
124
|
+
type: "search";
|
125
|
+
options: {
|
126
|
+
event: string[];
|
127
|
+
access: ("my-jurisdiction" | "all")[];
|
128
|
+
};
|
129
|
+
}, {
|
130
|
+
type: "search";
|
131
|
+
options: {
|
132
|
+
event: string[];
|
133
|
+
access: ("my-jurisdiction" | "all")[];
|
134
|
+
};
|
135
|
+
}>;
|
136
|
+
export type SearchScope = z.infer<typeof SearchScope>;
|
137
|
+
declare const ConfigurableRawScopes: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
138
|
+
type: z.ZodLiteral<"search">;
|
139
|
+
options: z.ZodObject<{
|
140
|
+
event: z.ZodArray<z.ZodString, "many">;
|
141
|
+
access: z.ZodArray<z.ZodEnum<["my-jurisdiction", "all"]>, "many">;
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
143
|
+
event: string[];
|
144
|
+
access: ("my-jurisdiction" | "all")[];
|
145
|
+
}, {
|
146
|
+
event: string[];
|
147
|
+
access: ("my-jurisdiction" | "all")[];
|
148
|
+
}>;
|
149
|
+
}, "strip", z.ZodTypeAny, {
|
150
|
+
type: "search";
|
151
|
+
options: {
|
152
|
+
event: string[];
|
153
|
+
access: ("my-jurisdiction" | "all")[];
|
154
|
+
};
|
155
|
+
}, {
|
156
|
+
type: "search";
|
157
|
+
options: {
|
158
|
+
event: string[];
|
159
|
+
access: ("my-jurisdiction" | "all")[];
|
160
|
+
};
|
161
|
+
}>, z.ZodObject<{
|
91
162
|
type: z.ZodLiteral<"user.create">;
|
92
163
|
options: z.ZodObject<{
|
93
164
|
role: z.ZodArray<z.ZodString, "many">;
|
@@ -164,8 +235,15 @@ declare const ConfigurableScopes: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
164
235
|
event: string[];
|
165
236
|
};
|
166
237
|
}>]>;
|
167
|
-
|
168
|
-
export type
|
238
|
+
type ConfigurableRawScopes = z.infer<typeof ConfigurableRawScopes>;
|
239
|
+
export type ConfigurableScopeType = ConfigurableRawScopes['type'];
|
240
|
+
type FlattenedSearchScope = {
|
241
|
+
type: 'search';
|
242
|
+
options: Record<string, SearchScopeAccessLevels>;
|
243
|
+
};
|
244
|
+
export type ConfigurableScopes = Exclude<ConfigurableRawScopes, {
|
245
|
+
type: 'search';
|
246
|
+
}> | FlattenedSearchScope;
|
169
247
|
export declare function findScope<T extends ConfigurableScopeType>(scopes: string[], scopeType: T): Extract<{
|
170
248
|
type: "user.create";
|
171
249
|
options: {
|
@@ -194,16 +272,24 @@ export declare function findScope<T extends ConfigurableScopeType>(scopes: strin
|
|
194
272
|
};
|
195
273
|
}, {
|
196
274
|
type: T;
|
275
|
+
}> | Extract<FlattenedSearchScope, {
|
276
|
+
type: T;
|
197
277
|
}> | undefined;
|
198
278
|
/**
|
199
|
-
* Parses a configurable scope string into a
|
279
|
+
* Parses a configurable scope string into a ConfigurableRawScopes object.
|
200
280
|
* @param {string} scope - The scope string to parse
|
201
|
-
* @returns {
|
281
|
+
* @returns {ConfigurableRawScopes | undefined} The parsed scope object if valid, undefined otherwise
|
202
282
|
* @example
|
203
283
|
* parseScope("user.create[role=field-agent|registration-agent]")
|
204
284
|
* // Returns: { type: "user.create", options: { role: ["field-agent", "registration-agent"] } }
|
205
285
|
*/
|
206
286
|
export declare function parseScope(scope: string): {
|
287
|
+
type: "search";
|
288
|
+
options: {
|
289
|
+
event: string[];
|
290
|
+
access: ("my-jurisdiction" | "all")[];
|
291
|
+
};
|
292
|
+
} | {
|
207
293
|
type: "user.create";
|
208
294
|
options: {
|
209
295
|
role: string[];
|
@@ -237,7 +323,7 @@ export declare function parseScope(scope: string): {
|
|
237
323
|
* })
|
238
324
|
* // Returns: "record.notify[event=v2.birth|tennis-club-membership]"
|
239
325
|
*/
|
240
|
-
export declare function stringifyScope(scope:
|
326
|
+
export declare function stringifyScope(scope: z.infer<typeof NotifyRecordScope>): string;
|
241
327
|
export declare const scopes: Scope[];
|
242
328
|
export type ParsedScopes = NonNullable<ReturnType<typeof parseScope>>;
|
243
329
|
export type RawScopes = z.infer<typeof LiteralScopes> | (string & {});
|
package/dist/scopes/index.js
CHANGED
@@ -289,18 +289,51 @@ var NotifyRecordScope = import_zod.z.object({
|
|
289
289
|
event: import_zod.z.array(import_zod.z.string())
|
290
290
|
})
|
291
291
|
});
|
292
|
-
var
|
292
|
+
var SearchScope = import_zod.z.object({
|
293
|
+
type: import_zod.z.literal("search"),
|
294
|
+
options: import_zod.z.object({
|
295
|
+
event: import_zod.z.array(import_zod.z.string()).length(1),
|
296
|
+
access: import_zod.z.array(import_zod.z.enum(["my-jurisdiction", "all"])).length(1)
|
297
|
+
})
|
298
|
+
});
|
299
|
+
var ConfigurableRawScopes = import_zod.z.discriminatedUnion("type", [
|
300
|
+
SearchScope,
|
293
301
|
CreateUserScope,
|
294
302
|
EditUserScope,
|
295
303
|
WorkqueueScope,
|
296
304
|
NotifyRecordScope
|
297
305
|
]);
|
306
|
+
function flattenAndMergeScopes(scopes2) {
|
307
|
+
if (scopes2.length === 0) return null;
|
308
|
+
const type = scopes2[0].type;
|
309
|
+
const mergedOptions = {};
|
310
|
+
for (const scope of scopes2) {
|
311
|
+
const entries = Object.entries(scope.options);
|
312
|
+
if (entries.length < 2) continue;
|
313
|
+
const sourceValues = entries[0][1];
|
314
|
+
const targetValues = entries[1][1];
|
315
|
+
for (let i = 0; i < sourceValues.length; i++) {
|
316
|
+
mergedOptions[sourceValues[i]] = targetValues[i];
|
317
|
+
}
|
318
|
+
}
|
319
|
+
return { type, options: mergedOptions };
|
320
|
+
}
|
298
321
|
function findScope(scopes2, scopeType) {
|
299
322
|
const parsedScopes = scopes2.map((rawScope) => parseScope(rawScope));
|
300
|
-
|
301
|
-
|
323
|
+
const searchScopes = parsedScopes.filter((scope) => scope?.type === "search");
|
324
|
+
const otherScopes = parsedScopes.filter((scope) => scope?.type !== "search");
|
325
|
+
const mergedSearchScope = flattenAndMergeScopes(searchScopes);
|
326
|
+
return [...otherScopes, mergedSearchScope].find(
|
327
|
+
(scope) => scope?.type === scopeType
|
302
328
|
);
|
303
329
|
}
|
330
|
+
function getScopeOptions(rawOptions) {
|
331
|
+
return rawOptions.split(",").reduce((acc, option) => {
|
332
|
+
const [key, value] = option.split("=");
|
333
|
+
acc[key] = value.split("|");
|
334
|
+
return acc;
|
335
|
+
}, {});
|
336
|
+
}
|
304
337
|
function parseScope(scope) {
|
305
338
|
const maybeLiteralScope = LiteralScopes.safeParse(scope);
|
306
339
|
if (maybeLiteralScope.success) {
|
@@ -314,16 +347,12 @@ function parseScope(scope) {
|
|
314
347
|
}
|
315
348
|
const rawScope = maybeConfigurableScope.data;
|
316
349
|
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
317
|
-
const options = rawOptions
|
318
|
-
const [key, value] = option.split("=");
|
319
|
-
acc[key] = value.split("|");
|
320
|
-
return acc;
|
321
|
-
}, {});
|
350
|
+
const options = getScopeOptions(rawOptions);
|
322
351
|
const parsedScope = {
|
323
352
|
type,
|
324
353
|
options
|
325
354
|
};
|
326
|
-
const result =
|
355
|
+
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
327
356
|
return result.success ? result.data : void 0;
|
328
357
|
}
|
329
358
|
function stringifyScope(scope) {
|