@opencrvs/toolkit 2.0.0-rc.b6a4023 → 2.0.0-rc.b99f685

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.
@@ -2132,10 +2132,6 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
2132
2132
  var import_ts_morph11 = require("ts-morph");
2133
2133
  var import_path11 = __toESM(require("path"));
2134
2134
 
2135
- // ../commons/src/scopes.deprecated.do-not-use.ts
2136
- var z4 = __toESM(require("zod/v4"));
2137
- var import_lodash = require("lodash");
2138
-
2139
2135
  // ../commons/src/scopes.ts
2140
2136
  var z3 = __toESM(require("zod/v4"));
2141
2137
  var qs = __toESM(require("qs"));
@@ -2409,6 +2405,7 @@ var DEFAULT_SCOPE_OPTIONS = {
2409
2405
  };
2410
2406
 
2411
2407
  // ../commons/src/scopes.deprecated.do-not-use.ts
2408
+ var z4 = __toESM(require("zod/v4"));
2412
2409
  var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
2413
2410
  var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
2414
2411
  var SearchScope = z4.object({
@@ -2642,74 +2639,6 @@ var legacyScopeToV2Scope = (v1Scope) => {
2642
2639
  }
2643
2640
  throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
2644
2641
  };
2645
- var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
2646
- function isMergeableUserScopeType(type) {
2647
- return MERGEABLE_USER_SCOPE_TYPES.includes(type);
2648
- }
2649
- function decodeLegacyScope(legacy) {
2650
- const encoded = legacyScopeToV2Scope(legacy);
2651
- const scope = decodeScope(encoded);
2652
- if (!scope) {
2653
- throw new Error(
2654
- `Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
2655
- );
2656
- }
2657
- return { legacy, scope };
2658
- }
2659
- function groupByType(entries) {
2660
- return entries.reduce(
2661
- (groups, entry) => ({
2662
- ...groups,
2663
- [entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
2664
- }),
2665
- {}
2666
- );
2667
- }
2668
- function deduplicateEntries(entries) {
2669
- return entries.filter(
2670
- (entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
2671
- );
2672
- }
2673
- function mergeEntries(type, entries) {
2674
- const optionsList = entries.map(
2675
- (e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
2676
- );
2677
- const allKeys = optionsList.flatMap(
2678
- (opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
2679
- );
2680
- const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
2681
- if (conflictKey) {
2682
- const conflicting = entries.filter(
2683
- (e) => conflictKey in ("options" in e.scope && e.scope.options || {})
2684
- ).map((e) => JSON.stringify(e.legacy));
2685
- throw new Error(
2686
- `Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
2687
- );
2688
- }
2689
- const mergedOptions = Object.assign({}, ...optionsList);
2690
- const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
2691
- const parsed = Scope2.safeParse(merged);
2692
- if (!parsed.success) {
2693
- throw new Error(
2694
- `Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
2695
- );
2696
- }
2697
- return parsed.data;
2698
- }
2699
- function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
2700
- const groups = groupByType(legacyScopes.map(decodeLegacyScope));
2701
- return Object.entries(groups).flatMap(([type, entries]) => {
2702
- const deduped = deduplicateEntries(entries);
2703
- if (deduped.length <= 1) return deduped.map((e) => e.scope);
2704
- if (!isMergeableUserScopeType(type)) {
2705
- console.warn(
2706
- `Multiple non-mergeable '${type}' scopes detected after dedup \u2014 kept all as-is. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}]. Review whether the duplication is intentional.`
2707
- );
2708
- return deduped.map((e) => e.scope);
2709
- }
2710
- return [mergeEntries(type, deduped)];
2711
- });
2712
- }
2713
2642
 
2714
2643
  // src/migrations/v2.0/migrate-scopes.ts
2715
2644
  var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
@@ -2747,65 +2676,57 @@ function resolveLegacyScopeFromElement(element) {
2747
2676
  }
2748
2677
  function migrateScopesArrays(rolesFilePath, project) {
2749
2678
  const sourceFile = project.getSourceFile(rolesFilePath);
2750
- if (!sourceFile) {
2751
- return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
2752
- }
2679
+ if (!sourceFile) return { migratedCount: 0, removedCount: 0 };
2753
2680
  let migratedCount = 0;
2754
2681
  let removedCount = 0;
2755
- let mergedCount = 0;
2756
2682
  const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
2757
- const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
2758
2683
  for (const scopesProp of scopesProperties) {
2759
2684
  const initializer = scopesProp.getInitializer();
2760
2685
  if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
2761
- const rawTexts = [];
2762
- const legacyStrings = [];
2763
- let anyChange = false;
2764
- for (const element of initializer.getElements()) {
2686
+ const elements = initializer.getElements();
2687
+ for (let index = elements.length - 1; index >= 0; index--) {
2688
+ const element = elements[index];
2689
+ if (!import_ts_morph11.Node.isExpression(element)) continue;
2765
2690
  const scopeKey = resolveScopeKeyFromElementAccess(element);
2766
2691
  if (scopeKey && !(scopeKey in SCOPES)) {
2767
2692
  console.warn(
2768
- ` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
2693
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2769
2694
  );
2695
+ initializer.removeElement(index);
2770
2696
  removedCount++;
2771
- anyChange = true;
2772
2697
  continue;
2773
2698
  }
2774
2699
  const legacyScope = resolveLegacyScopeFromElement(element);
2775
2700
  if (!legacyScope) {
2776
2701
  console.warn(
2777
- ` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
2702
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2778
2703
  );
2779
- rawTexts.push(element.getText());
2780
2704
  continue;
2781
2705
  }
2782
- legacyStrings.push(legacyScope);
2783
- anyChange = true;
2784
- }
2785
- if (!anyChange) continue;
2786
- let mergedScopes;
2787
- try {
2788
- mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
2789
- } catch (error) {
2790
- throw new Error(
2791
- `[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
2792
- { cause: error }
2793
- );
2706
+ try {
2707
+ const migratedScope = legacyScopeToV2Scope(legacyScope);
2708
+ const scope = decodeScope(migratedScope);
2709
+ if (!scope) {
2710
+ console.warn(
2711
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2712
+ );
2713
+ continue;
2714
+ }
2715
+ element.replaceWithText(JSON.stringify(scope));
2716
+ migratedCount++;
2717
+ } catch (error) {
2718
+ console.warn(
2719
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2720
+ );
2721
+ }
2794
2722
  }
2795
- migratedCount += legacyStrings.length;
2796
- mergedCount += legacyStrings.length - mergedScopes.length;
2797
- const outputElements = [
2798
- ...rawTexts,
2799
- ...mergedScopes.map((s) => JSON.stringify(s))
2800
- ];
2801
- scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
2802
2723
  }
2803
2724
  if (removedCount > 0) {
2804
2725
  console.log(
2805
- ` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
2726
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
2806
2727
  );
2807
2728
  }
2808
- return { migratedCount, removedCount, mergedCount };
2729
+ return { migratedCount, removedCount };
2809
2730
  }
2810
2731
  function ensureScopesHelpersImport(rolesFilePath, project) {
2811
2732
  const sourceFile = project.getSourceFile(rolesFilePath);
@@ -2940,7 +2861,7 @@ async function main11() {
2940
2861
  return;
2941
2862
  }
2942
2863
  const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
2943
- const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
2864
+ const { migratedCount, removedCount } = migrateScopesArrays(
2944
2865
  rolesFilePath,
2945
2866
  project
2946
2867
  );
@@ -2959,7 +2880,7 @@ async function main11() {
2959
2880
  }
2960
2881
  await sourceFile.save();
2961
2882
  console.log(
2962
- `Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
2883
+ `Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
2963
2884
  );
2964
2885
  }
2965
2886
 
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAoXA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAyVA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.main = main;
26
26
  const ts_morph_1 = require("ts-morph");
27
27
  const path_1 = __importDefault(require("path"));
28
+ const scopes_1 = require("../commons/scopes");
28
29
  const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
29
30
  const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
30
31
  const SCOPES_PROPERTY_NAME = 'scopes';
@@ -64,85 +65,60 @@ function resolveLegacyScopeFromElement(element) {
64
65
  }
65
66
  return null;
66
67
  }
67
- /**
68
- * Walks each `scopes: [...]` array in the roles file, classifies elements,
69
- * and rewrites the whole array using `migrateLegacyScopesArrayToV2Scopes`
70
- * (which preserves v1.9 AND semantics by merging pairs of legacy scopes
71
- * that targeted the same v2 type). See issue #12489.
72
- *
73
- * Elements are partitioned into three kinds:
74
- * - drop: `SCOPES.X` references where X is not in the SCOPES map (warned
75
- * and removed, matching pre-refactor behavior).
76
- * - raw: non-literal expressions we cannot statically resolve (e.g.
77
- * `...sharedScopes` spreads). Preserved verbatim in output so authoring
78
- * intent isn't lost.
79
- * - legacy: literal strings or resolvable `SCOPES.X` references.
80
- * Collected and passed as a batch to the merge function.
81
- *
82
- * The output array text is `[...rawTexts, ...mergedScopesAsJson]`. Order of
83
- * legacy entries relative to raw expressions is not preserved — scopes in a
84
- * v2 array compose with OR, so position is semantically irrelevant.
85
- */
86
68
  function migrateScopesArrays(rolesFilePath, project) {
87
69
  const sourceFile = project.getSourceFile(rolesFilePath);
88
- if (!sourceFile) {
89
- return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
90
- }
70
+ if (!sourceFile)
71
+ return { migratedCount: 0, removedCount: 0 };
91
72
  let migratedCount = 0;
92
73
  let removedCount = 0;
93
- let mergedCount = 0;
94
74
  const scopesProperties = sourceFile
95
75
  .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
96
76
  .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
97
- const relPath = path_1.default.relative(process.cwd(), rolesFilePath);
98
77
  for (const scopesProp of scopesProperties) {
99
78
  const initializer = scopesProp.getInitializer();
100
79
  if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
101
80
  continue;
102
- const rawTexts = [];
103
- const legacyStrings = [];
104
- let anyChange = false;
105
- for (const element of initializer.getElements()) {
81
+ const elements = initializer.getElements();
82
+ for (let index = elements.length - 1; index >= 0; index--) {
83
+ const element = elements[index];
84
+ if (!ts_morph_1.Node.isExpression(element))
85
+ continue;
106
86
  const scopeKey = resolveScopeKeyFromElementAccess(element);
107
87
  if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
108
88
  // eslint-disable-next-line no-console
109
- console.warn(` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`);
89
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`);
90
+ initializer.removeElement(index);
110
91
  removedCount++;
111
- anyChange = true;
112
92
  continue;
113
93
  }
114
94
  const legacyScope = resolveLegacyScopeFromElement(element);
115
95
  if (!legacyScope) {
116
96
  // eslint-disable-next-line no-console
117
- console.warn(` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`);
118
- rawTexts.push(element.getText());
97
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`);
119
98
  continue;
120
99
  }
121
- legacyStrings.push(legacyScope);
122
- anyChange = true;
123
- }
124
- if (!anyChange)
125
- continue;
126
- let mergedScopes;
127
- try {
128
- mergedScopes = (0, scopes_deprecated_do_not_use_1.migrateLegacyScopesArrayToV2Scopes)(legacyStrings);
129
- }
130
- catch (error) {
131
- throw new Error(`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
100
+ try {
101
+ const migratedScope = (0, scopes_deprecated_do_not_use_1.legacyScopeToV2Scope)(legacyScope);
102
+ const scope = (0, scopes_1.decodeScope)(migratedScope);
103
+ if (!scope) {
104
+ // eslint-disable-next-line no-console
105
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`);
106
+ continue;
107
+ }
108
+ element.replaceWithText(JSON.stringify(scope));
109
+ migratedCount++;
110
+ }
111
+ catch (error) {
112
+ // eslint-disable-next-line no-console
113
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
114
+ }
132
115
  }
133
- migratedCount += legacyStrings.length;
134
- mergedCount += legacyStrings.length - mergedScopes.length;
135
- const outputElements = [
136
- ...rawTexts,
137
- ...mergedScopes.map((s) => JSON.stringify(s))
138
- ];
139
- scopesProp.setInitializer(`[${outputElements.join(', ')}]`);
140
116
  }
141
117
  if (removedCount > 0) {
142
118
  // eslint-disable-next-line no-console
143
- console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`);
119
+ console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${path_1.default.relative(process.cwd(), rolesFilePath)}'.`);
144
120
  }
145
- return { migratedCount, removedCount, mergedCount };
121
+ return { migratedCount, removedCount };
146
122
  }
147
123
  function ensureScopesHelpersImport(rolesFilePath, project) {
148
124
  const sourceFile = project.getSourceFile(rolesFilePath);
@@ -286,7 +262,7 @@ function main() {
286
262
  return;
287
263
  }
288
264
  const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
289
- const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(rolesFilePath, project);
265
+ const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
290
266
  const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
291
267
  const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
292
268
  const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
@@ -300,6 +276,6 @@ function main() {
300
276
  return;
301
277
  }
302
278
  yield sourceFile.save();
303
- console.log(`Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
279
+ console.log(`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
304
280
  });
305
281
  }
@@ -1370,6 +1370,9 @@ var EventMetadata = z16.object({
1370
1370
  "Timestamp of the most recent *accepted* status change. Possibly 3rd party update, if action is validation asynchronously."
1371
1371
  ),
1372
1372
  assignedTo: z16.string().nullish().describe("ID of the user currently assigned to the event."),
1373
+ assignedToSignature: DocumentPath.nullish().describe(
1374
+ "Signature of the user who is currently assigned to the event."
1375
+ ),
1373
1376
  updatedBy: z16.string().nullish().describe("ID of the user who last changed the status."),
1374
1377
  trackingId: z16.string().describe(
1375
1378
  "System-generated tracking ID used by informants or registrars to look up the event."
@@ -4172,8 +4175,6 @@ var BaseActionInput = z38.object({
4172
4175
  originalActionId: UUID.optional(),
4173
4176
  // should not be part of base action.
4174
4177
  keepAssignment: z38.boolean().optional(),
4175
- keepAssignmentIfAccepted: z38.boolean().optional(),
4176
- keepAssignmentIfRejected: z38.boolean().optional(),
4177
4178
  waitFor: z38.boolean().optional(),
4178
4179
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
4179
4180
  // @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.b6a4023",
3
+ "version": "2.0.0-rc.b99f685",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {