@opencrvs/toolkit 1.9.12-rc.9a1685f → 1.9.12-rc.9c9cef9

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.
@@ -9,7 +9,7 @@ export declare const ACTION_SCOPE_MAP: {
9
9
  NOTIFY: "record.notify"[];
10
10
  DECLARE: ("record.declare" | "record.register")[];
11
11
  EDIT: "record.edit"[];
12
- DELETE: "record.declare"[];
12
+ DELETE: ("record.declare" | "record.notify")[];
13
13
  REGISTER: "record.register"[];
14
14
  PRINT_CERTIFICATE: "record.print-certified-copies"[];
15
15
  REQUEST_CORRECTION: ("record.request-correction" | "record.correct")[];
@@ -9930,7 +9930,7 @@ var ACTION_SCOPE_MAP = {
9930
9930
  [ActionType.NOTIFY]: ["record.notify"],
9931
9931
  [ActionType.DECLARE]: ["record.declare", "record.register"],
9932
9932
  [ActionType.EDIT]: ["record.edit"],
9933
- [ActionType.DELETE]: ["record.declare"],
9933
+ [ActionType.DELETE]: ["record.declare", "record.notify"],
9934
9934
  [ActionType.REGISTER]: ["record.register"],
9935
9935
  [ActionType.PRINT_CERTIFICATE]: ["record.print-certified-copies"],
9936
9936
  [ActionType.REQUEST_CORRECTION]: [
@@ -1 +1 @@
1
- {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AA+pBA,wBAAsB,IAAI,kBAiOzB"}
1
+ {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAyuBA,wBAAsB,IAAI,kBAyPzB"}
@@ -318,25 +318,6 @@ function transformDashboardsValue(init, isProd) {
318
318
  */
319
319
  function generateTsContent(configObj, exportName, group, isProd) {
320
320
  var _a;
321
- // ── File header ─────────────────────────────────────────────────────────────
322
- const headerLines = [];
323
- if (isProd) {
324
- headerLines.push(`import { env } from './environment'`);
325
- }
326
- headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
327
- if (group.applicationConfigImportPath) {
328
- headerLines.push(`import { applicationConfig } from '${group.applicationConfigImportPath}'`);
329
- }
330
- headerLines.push('');
331
- if (isProd) {
332
- headerLines.push(`const scheme = 'https'`);
333
- headerLines.push(`const hostname = env.DOMAIN`);
334
- headerLines.push(`const sentry = env.SENTRY_DSN`);
335
- }
336
- else {
337
- headerLines.push(`const scheme = 'http'`);
338
- headerLines.push(`const hostname = 'localhost'`);
339
- }
340
321
  // ── Config properties ────────────────────────────────────────────────────────
341
322
  const propertyLines = [];
342
323
  const seenKeys = new Set();
@@ -379,6 +360,26 @@ function generateTsContent(configObj, exportName, group, isProd) {
379
360
  propertyLines.push(` ${key}: applicationConfig.${key}`);
380
361
  }
381
362
  const body = propertyLines.join(',\n');
363
+ const headerLines = [];
364
+ headerLines.push(`import * as fs from 'fs'`);
365
+ headerLines.push(`import { join } from 'path'`);
366
+ if (isProd) {
367
+ headerLines.push(`import { env } from './environment'`);
368
+ }
369
+ headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
370
+ if (group.applicationConfigImportPath) {
371
+ headerLines.push(`import { applicationConfig } from '${group.applicationConfigImportPath}'`);
372
+ }
373
+ headerLines.push('');
374
+ if (isProd) {
375
+ headerLines.push(`const scheme = 'https'`);
376
+ headerLines.push(`const hostname = env.DOMAIN`);
377
+ headerLines.push(`const sentry = env.SENTRY_DSN`);
378
+ }
379
+ else {
380
+ headerLines.push(`const scheme = 'http'`);
381
+ headerLines.push(`const hostname = 'localhost'`);
382
+ }
382
383
  return [
383
384
  ...headerLines,
384
385
  '',
@@ -571,6 +572,64 @@ function resolveConfigChain(configObj, path) {
571
572
  }
572
573
  return current.getText();
573
574
  }
575
+ /**
576
+ * When inlining a value from `application-config.ts` into a file in a
577
+ * different directory, `__dirname`-based paths (e.g. for reading image
578
+ * assets) must be adjusted so they continue to resolve to the original
579
+ * location — the referenced files themselves are NOT moved.
580
+ *
581
+ * Rewrites `join(__dirname, ...)` / `path.join(__dirname, ...)` /
582
+ * `resolve(__dirname, ...)` / `path.resolve(__dirname, ...)` by inserting
583
+ * the relative path from the target directory back to the source directory
584
+ * as an extra leading argument.
585
+ *
586
+ * Example: inlining from `src/api/application/` into `src/login-config.ts`
587
+ * join(__dirname, 'login-bg.jpg')
588
+ * → join(__dirname, 'api/application', 'login-bg.jpg')
589
+ */
590
+ function rewriteDirnameRefs(text, relDir) {
591
+ if (!relDir || relDir === '.')
592
+ return text;
593
+ const relForward = relDir.replace(/\\/g, '/');
594
+ return text.replace(/\b((?:path\.)?(?:join|resolve))\s*\(\s*__dirname\s*,/g, `$1(__dirname, '${relForward}',`);
595
+ }
596
+ /**
597
+ * Ensures the source file has a namespace `fs` import (`import * as fs from 'fs'`).
598
+ * No-op if a namespace or default `fs` import is already present.
599
+ */
600
+ function ensureFsImport(sf) {
601
+ const hasFs = sf
602
+ .getImportDeclarations()
603
+ .some((d) => d.getModuleSpecifierValue() === 'fs' &&
604
+ (d.getNamespaceImport() || d.getDefaultImport()));
605
+ if (hasFs)
606
+ return;
607
+ sf.addImportDeclaration({
608
+ moduleSpecifier: 'fs',
609
+ namespaceImport: 'fs'
610
+ });
611
+ }
612
+ /**
613
+ * Ensures the source file has a named `join` import from 'path'.
614
+ * Merges into an existing 'path' import if present, otherwise adds a new
615
+ * `import { join } from 'path'` declaration.
616
+ */
617
+ function ensureJoinImport(sf) {
618
+ const pathImports = sf
619
+ .getImportDeclarations()
620
+ .filter((d) => d.getModuleSpecifierValue() === 'path');
621
+ if (pathImports.some((d) => d.getNamedImports().some((ni) => ni.getName() === 'join'))) {
622
+ return;
623
+ }
624
+ if (pathImports.length > 0) {
625
+ pathImports[0].addNamedImport('join');
626
+ return;
627
+ }
628
+ sf.addImportDeclaration({
629
+ moduleSpecifier: 'path',
630
+ namedImports: ['join']
631
+ });
632
+ }
574
633
  // ─── Entry point ─────────────────────────────────────────────────────────────
575
634
  function main() {
576
635
  return __awaiter(this, void 0, void 0, function* () {
@@ -627,6 +686,7 @@ function main() {
627
686
  // Before removing, inline every cross-file reference to each unknown key.
628
687
  // Example: applicationConfig.BIRTH.LATE_REGISTRATION_TARGET → 45
629
688
  const filesToSaveAfterInlining = new Set();
689
+ const appConfigDir = path_1.default.dirname(appConfigAbsPath);
630
690
  for (const removedProp of propsToRemove) {
631
691
  const key = removedProp.getName();
632
692
  for (const sf of appConfigProject.getSourceFiles()) {
@@ -637,6 +697,12 @@ function main() {
637
697
  continue;
638
698
  if (sf.getFilePath().includes('/node_modules/'))
639
699
  continue;
700
+ // Relative path from the target file's directory back to the
701
+ // applicationConfig's directory. Used to adjust `__dirname`-based
702
+ // paths in the inlined value (e.g. image asset references) since
703
+ // those assets are not moved.
704
+ const targetDir = path_1.default.dirname(sf.getFilePath());
705
+ const relDirFromTarget = path_1.default.relative(targetDir, appConfigDir);
640
706
  // Break-and-restart after each replacement because replaceWithText()
641
707
  // invalidates existing node references in the ts-morph tree
642
708
  let madeReplacement = true;
@@ -664,8 +730,18 @@ function main() {
664
730
  console.log(` Cannot resolve applicationConfig.${accessPath.join('.')} — skipping inline replacement`);
665
731
  continue;
666
732
  }
667
- node.replaceWithText(resolvedValue);
668
- console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${resolvedValue} in ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
733
+ const adjustedValue = rewriteDirnameRefs(resolvedValue, relDirFromTarget);
734
+ node.replaceWithText(adjustedValue);
735
+ // If the inlined value references `fs` or `join`, ensure the
736
+ // target file has the corresponding imports — these are
737
+ // commonly used to read image assets from disk.
738
+ if (/\bfs\s*\./.test(adjustedValue)) {
739
+ ensureFsImport(sf);
740
+ }
741
+ if (/\bjoin\s*\(/.test(adjustedValue)) {
742
+ ensureJoinImport(sf);
743
+ }
744
+ console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${adjustedValue} in ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
669
745
  filesToSaveAfterInlining.add(sf);
670
746
  madeReplacement = true;
671
747
  break; // restart — tree has changed
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AAyBA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBAwBxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA4BA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBA2BxD"}