@opencrvs/toolkit 1.9.12-rc.af3c5dc → 1.9.12-rc.b2b5081

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.
Files changed (34) hide show
  1. package/dist/cli.js +1246 -35
  2. package/dist/commons/events/EventConfig.d.ts +3 -1
  3. package/dist/commons/events/scopes.d.ts +1 -1
  4. package/dist/events/index.js +4 -1
  5. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
  6. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  7. package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
  8. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  9. package/dist/migrations/v2.0/convert-config-files-to-ts.js +97 -21
  10. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  11. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  12. package/dist/migrations/v2.0/create-events-index.js +326 -0
  13. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  14. package/dist/migrations/v2.0/index.js +1244 -33
  15. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  16. package/dist/migrations/v2.0/migrate-scopes.js +6 -5
  17. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  18. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  19. package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
  20. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  21. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  22. package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
  23. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  24. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  25. package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
  26. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  27. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  28. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
  29. package/dist/notification/index.js +4 -1
  30. package/opencrvs-toolkit-1.9.12-rc.b2b5081.tgz +0 -0
  31. package/package.json +1 -1
  32. package/tsconfig.json +3 -0
  33. package/tsconfig.tsbuildinfo +1 -1
  34. package/opencrvs-toolkit-1.9.12-rc.af3c5dc.tgz +0 -0
@@ -29,14 +29,16 @@ export type EventConfig = {
29
29
  declaration: DeclarationFormConfig;
30
30
  advancedSearch: AdvancedSearchConfig[];
31
31
  flags: FlagConfig[];
32
+ analytics: boolean;
32
33
  };
33
- export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent'> & {
34
+ export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent' | 'analytics'> & {
34
35
  dateOfEvent?: z.input<typeof FieldReference> | z.infer<typeof EventFieldReference>;
35
36
  placeOfEvent?: z.input<typeof FieldReference>;
36
37
  advancedSearch?: AdvancedSearchConfig[];
37
38
  flags?: FlagConfig[];
38
39
  declaration: DeclarationFormConfigInput;
39
40
  actions: z.input<typeof ActionConfig>[];
41
+ analytics?: boolean;
40
42
  };
41
43
  export declare const EventConfig: z.ZodType<EventConfig, EventConfigInput>;
42
44
  //# sourceMappingURL=EventConfig.d.ts.map
@@ -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")[];
@@ -5342,6 +5342,9 @@ var _EventConfigBase = z33.object({
5342
5342
  ),
5343
5343
  flags: z33.array(FlagConfig).optional().default([]).describe(
5344
5344
  "Configuration of flags associated with the actions of this event type."
5345
+ ),
5346
+ analytics: z33.boolean().optional().default(true).describe(
5347
+ "Indicates whether the records of this event type are included in analytics"
5345
5348
  )
5346
5349
  });
5347
5350
  var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
@@ -9930,7 +9933,7 @@ var ACTION_SCOPE_MAP = {
9930
9933
  [ActionType.NOTIFY]: ["record.notify"],
9931
9934
  [ActionType.DECLARE]: ["record.declare", "record.register"],
9932
9935
  [ActionType.EDIT]: ["record.edit"],
9933
- [ActionType.DELETE]: ["record.declare"],
9936
+ [ActionType.DELETE]: ["record.declare", "record.notify"],
9934
9937
  [ActionType.REGISTER]: ["record.register"],
9935
9938
  [ActionType.PRINT_CERTIFICATE]: ["record.print-certified-copies"],
9936
9939
  [ActionType.REQUEST_CORRECTION]: [
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=checkout-upstream-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA0GA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.main = main;
23
+ /**
24
+ * Codemod: Replace selected files with their upstream v2.0 versions from
25
+ * opencrvs/opencrvs-countryconfig.
26
+ *
27
+ * Usage:
28
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/checkout-upstream-files.ts
29
+ *
30
+ * What it does:
31
+ * 1. Registers a temporary git remote that points at the canonical
32
+ * opencrvs-countryconfig repository.
33
+ * 2. Fetches the chosen upstream branch at --depth=1 to keep it fast.
34
+ * 3. Path-scoped checkouts each listed file from that branch. The upstream
35
+ * version is written to the working tree AND staged in the index, so
36
+ * the dev can review the diff afterwards with:
37
+ * git diff --cached -- <file>
38
+ * 4. Removes the temporary remote in all cases (success, failure, or
39
+ * unexpected error) via a `finally` block.
40
+ *
41
+ * Why a git-based approach (as opposed to a raw HTTPS download):
42
+ * - Git handles text, binary, and line endings correctly.
43
+ * - The checked-out files end up staged, giving an obvious review UX.
44
+ * - `git checkout <ref> -- <paths>` is a blob-level copy, so it works
45
+ * whether or not the target repo shares history with
46
+ * opencrvs-countryconfig (e.g. country implementations started from
47
+ * scratch rather than forked).
48
+ *
49
+ * Caveats:
50
+ * - Overwrites any local modifications to the listed files. Run the
51
+ * upgrade on a clean working tree, or accept that the upstream version
52
+ * replaces yours.
53
+ * - Requires git to be installed and network access to github.com.
54
+ * - Requires the country config working directory to be a git repo.
55
+ */
56
+ const child_process_1 = require("child_process");
57
+ const _1 = require(".");
58
+ const UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
59
+ // @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
60
+ const UPSTREAM_BRANCH = 'develop';
61
+ // Remote name used only for the duration of this codemod. Prefixed to avoid
62
+ // clashing with remotes the user may have (origin, upstream, etc.).
63
+ const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
64
+ const FILES_TO_CHECKOUT = [
65
+ 'infrastructure/postgres/setup-analytics.sh',
66
+ 'src/analytics/analytics.ts'
67
+ ];
68
+ // ─── Git helpers ─────────────────────────────────────────────────────────────
69
+ /**
70
+ * Runs a git command in the country config working directory.
71
+ *
72
+ * By default stderr is inherited so the user sees progress output from
73
+ * long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
74
+ * both stdout and stderr when you only care about the exit code.
75
+ */
76
+ function runGit(args, { silent = false } = {}) {
77
+ return (0, child_process_1.execFileSync)('git', args, {
78
+ cwd: (0, _1.getCwd)(),
79
+ encoding: 'utf8',
80
+ stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
81
+ });
82
+ }
83
+ /**
84
+ * Runs a git command and returns true on success, false on failure.
85
+ * Stderr/stdout are suppressed — use only when the exit code is the only
86
+ * signal you care about.
87
+ */
88
+ function tryGit(args) {
89
+ try {
90
+ runGit(args, { silent: true });
91
+ return true;
92
+ }
93
+ catch (_a) {
94
+ return false;
95
+ }
96
+ }
97
+ function assertIsGitRepo() {
98
+ if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
99
+ throw new Error(`checkout-upstream-files: ${(0, _1.getCwd)()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
100
+ }
101
+ }
102
+ // ─── Entry point ─────────────────────────────────────────────────────────────
103
+ function main() {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...\n`);
106
+ assertIsGitRepo();
107
+ // Best-effort cleanup of a stale temp remote from a previous aborted run.
108
+ tryGit(['remote', 'remove', TEMP_REMOTE]);
109
+ try {
110
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${UPSTREAM_URL}`);
111
+ runGit(['remote', 'add', TEMP_REMOTE, UPSTREAM_URL], { silent: true });
112
+ console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
113
+ runGit(['fetch', '--depth=1', TEMP_REMOTE, UPSTREAM_BRANCH]);
114
+ const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
115
+ const missing = [];
116
+ let checkedOut = 0;
117
+ for (const file of FILES_TO_CHECKOUT) {
118
+ // `--` separates paths from refs and avoids ambiguity when a path
119
+ // happens to match a branch/tag name.
120
+ if (tryGit(['checkout', ref, '--', file])) {
121
+ console.log(` Checked out ${file} from ${ref}`);
122
+ checkedOut++;
123
+ }
124
+ else {
125
+ console.warn(` [warn] ${file} not found on ${ref} — skipping. Verify the path exists on that branch.`);
126
+ missing.push(file);
127
+ }
128
+ }
129
+ console.log(`\n Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`);
130
+ if (missing.length > 0) {
131
+ console.warn(` Missing on upstream branch: ${missing.join(', ')}`);
132
+ }
133
+ if (checkedOut > 0) {
134
+ console.log(` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map((f) => `'${f}'`).join(' ')}\n`);
135
+ }
136
+ }
137
+ finally {
138
+ if (tryGit(['remote', 'remove', TEMP_REMOTE])) {
139
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
140
+ }
141
+ }
142
+ });
143
+ }
@@ -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
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=create-events-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAqTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}