@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.
@@ -1144,6 +1144,9 @@ var EventMetadata = z15.object({
1144
1144
  "Timestamp of the most recent *accepted* status change. Possibly 3rd party update, if action is validation asynchronously."
1145
1145
  ),
1146
1146
  assignedTo: z15.string().nullish().describe("ID of the user currently assigned to the event."),
1147
+ assignedToSignature: DocumentPath.nullish().describe(
1148
+ "Signature of the user who is currently assigned to the event."
1149
+ ),
1147
1150
  updatedBy: z15.string().nullish().describe("ID of the user who last changed the status."),
1148
1151
  trackingId: z15.string().describe(
1149
1152
  "System-generated tracking ID used by informants or registrars to look up the event."
package/dist/cli.js CHANGED
@@ -2120,10 +2120,6 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
2120
2120
  var import_ts_morph11 = require("ts-morph");
2121
2121
  var import_path11 = __toESM(require("path"));
2122
2122
 
2123
- // ../commons/src/scopes.deprecated.do-not-use.ts
2124
- var z4 = __toESM(require("zod/v4"));
2125
- var import_lodash = require("lodash");
2126
-
2127
2123
  // ../commons/src/scopes.ts
2128
2124
  var z3 = __toESM(require("zod/v4"));
2129
2125
  var qs = __toESM(require("qs"));
@@ -2397,6 +2393,7 @@ var DEFAULT_SCOPE_OPTIONS = {
2397
2393
  };
2398
2394
 
2399
2395
  // ../commons/src/scopes.deprecated.do-not-use.ts
2396
+ var z4 = __toESM(require("zod/v4"));
2400
2397
  var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
2401
2398
  var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
2402
2399
  var SearchScope = z4.object({
@@ -2630,74 +2627,6 @@ var legacyScopeToV2Scope = (v1Scope) => {
2630
2627
  }
2631
2628
  throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
2632
2629
  };
2633
- var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
2634
- function isMergeableUserScopeType(type) {
2635
- return MERGEABLE_USER_SCOPE_TYPES.includes(type);
2636
- }
2637
- function decodeLegacyScope(legacy) {
2638
- const encoded = legacyScopeToV2Scope(legacy);
2639
- const scope = decodeScope(encoded);
2640
- if (!scope) {
2641
- throw new Error(
2642
- `Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
2643
- );
2644
- }
2645
- return { legacy, scope };
2646
- }
2647
- function groupByType(entries) {
2648
- return entries.reduce(
2649
- (groups, entry) => ({
2650
- ...groups,
2651
- [entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
2652
- }),
2653
- {}
2654
- );
2655
- }
2656
- function deduplicateEntries(entries) {
2657
- return entries.filter(
2658
- (entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
2659
- );
2660
- }
2661
- function mergeEntries(type, entries) {
2662
- const optionsList = entries.map(
2663
- (e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
2664
- );
2665
- const allKeys = optionsList.flatMap(
2666
- (opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
2667
- );
2668
- const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
2669
- if (conflictKey) {
2670
- const conflicting = entries.filter(
2671
- (e) => conflictKey in ("options" in e.scope && e.scope.options || {})
2672
- ).map((e) => JSON.stringify(e.legacy));
2673
- throw new Error(
2674
- `Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
2675
- );
2676
- }
2677
- const mergedOptions = Object.assign({}, ...optionsList);
2678
- const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
2679
- const parsed = Scope2.safeParse(merged);
2680
- if (!parsed.success) {
2681
- throw new Error(
2682
- `Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
2683
- );
2684
- }
2685
- return parsed.data;
2686
- }
2687
- function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
2688
- const groups = groupByType(legacyScopes.map(decodeLegacyScope));
2689
- return Object.entries(groups).flatMap(([type, entries]) => {
2690
- const deduped = deduplicateEntries(entries);
2691
- if (deduped.length <= 1) return deduped.map((e) => e.scope);
2692
- if (!isMergeableUserScopeType(type)) {
2693
- console.warn(
2694
- `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.`
2695
- );
2696
- return deduped.map((e) => e.scope);
2697
- }
2698
- return [mergeEntries(type, deduped)];
2699
- });
2700
- }
2701
2630
 
2702
2631
  // src/migrations/v2.0/migrate-scopes.ts
2703
2632
  var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
@@ -2735,65 +2664,57 @@ function resolveLegacyScopeFromElement(element) {
2735
2664
  }
2736
2665
  function migrateScopesArrays(rolesFilePath, project) {
2737
2666
  const sourceFile = project.getSourceFile(rolesFilePath);
2738
- if (!sourceFile) {
2739
- return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
2740
- }
2667
+ if (!sourceFile) return { migratedCount: 0, removedCount: 0 };
2741
2668
  let migratedCount = 0;
2742
2669
  let removedCount = 0;
2743
- let mergedCount = 0;
2744
2670
  const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
2745
- const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
2746
2671
  for (const scopesProp of scopesProperties) {
2747
2672
  const initializer = scopesProp.getInitializer();
2748
2673
  if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
2749
- const rawTexts = [];
2750
- const legacyStrings = [];
2751
- let anyChange = false;
2752
- for (const element of initializer.getElements()) {
2674
+ const elements = initializer.getElements();
2675
+ for (let index = elements.length - 1; index >= 0; index--) {
2676
+ const element = elements[index];
2677
+ if (!import_ts_morph11.Node.isExpression(element)) continue;
2753
2678
  const scopeKey = resolveScopeKeyFromElementAccess(element);
2754
2679
  if (scopeKey && !(scopeKey in SCOPES)) {
2755
2680
  console.warn(
2756
- ` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
2681
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2757
2682
  );
2683
+ initializer.removeElement(index);
2758
2684
  removedCount++;
2759
- anyChange = true;
2760
2685
  continue;
2761
2686
  }
2762
2687
  const legacyScope = resolveLegacyScopeFromElement(element);
2763
2688
  if (!legacyScope) {
2764
2689
  console.warn(
2765
- ` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
2690
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2766
2691
  );
2767
- rawTexts.push(element.getText());
2768
2692
  continue;
2769
2693
  }
2770
- legacyStrings.push(legacyScope);
2771
- anyChange = true;
2772
- }
2773
- if (!anyChange) continue;
2774
- let mergedScopes;
2775
- try {
2776
- mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
2777
- } catch (error) {
2778
- throw new Error(
2779
- `[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
2780
- { cause: error }
2781
- );
2694
+ try {
2695
+ const migratedScope = legacyScopeToV2Scope(legacyScope);
2696
+ const scope = decodeScope(migratedScope);
2697
+ if (!scope) {
2698
+ console.warn(
2699
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2700
+ );
2701
+ continue;
2702
+ }
2703
+ element.replaceWithText(JSON.stringify(scope));
2704
+ migratedCount++;
2705
+ } catch (error) {
2706
+ console.warn(
2707
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2708
+ );
2709
+ }
2782
2710
  }
2783
- migratedCount += legacyStrings.length;
2784
- mergedCount += legacyStrings.length - mergedScopes.length;
2785
- const outputElements = [
2786
- ...rawTexts,
2787
- ...mergedScopes.map((s) => JSON.stringify(s))
2788
- ];
2789
- scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
2790
2711
  }
2791
2712
  if (removedCount > 0) {
2792
2713
  console.log(
2793
- ` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
2714
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
2794
2715
  );
2795
2716
  }
2796
- return { migratedCount, removedCount, mergedCount };
2717
+ return { migratedCount, removedCount };
2797
2718
  }
2798
2719
  function ensureScopesHelpersImport(rolesFilePath, project) {
2799
2720
  const sourceFile = project.getSourceFile(rolesFilePath);
@@ -2928,7 +2849,7 @@ async function main11() {
2928
2849
  return;
2929
2850
  }
2930
2851
  const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
2931
- const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
2852
+ const { migratedCount, removedCount } = migrateScopesArrays(
2932
2853
  rolesFilePath,
2933
2854
  project
2934
2855
  );
@@ -2947,7 +2868,7 @@ async function main11() {
2947
2868
  }
2948
2869
  await sourceFile.save();
2949
2870
  console.log(
2950
- `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." : "."}`
2871
+ `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." : "."}`
2951
2872
  );
2952
2873
  }
2953
2874