@opencrvs/toolkit 1.9.12-rc.f8905a4 → 1.9.12-rc.f8f1dc7

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/cli.js CHANGED
@@ -1813,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1813
1813
  }
1814
1814
  return replacedCount;
1815
1815
  }
1816
- function resolveConfigChain(configObj, path15) {
1816
+ function resolveConfigChain(configObj, path16) {
1817
1817
  let current = configObj;
1818
- for (const key of path15) {
1818
+ for (const key of path16) {
1819
1819
  if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1820
1820
  const prop = current.getProperty(key);
1821
1821
  if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
@@ -3126,6 +3126,177 @@ async function main15() {
3126
3126
  }
3127
3127
  }
3128
3128
 
3129
+ // src/migrations/v2.0/add-analytics-option-to-event-configs.ts
3130
+ var import_ts_morph15 = require("ts-morph");
3131
+ var import_path16 = __toESM(require("path"));
3132
+ var DEFINE_CONFIG_NAME5 = "defineConfig";
3133
+ var ID_PROPERTY_NAME = "id";
3134
+ var ANALYTICS_PROPERTY_NAME = "analytics";
3135
+ function getEventLabel(configArg) {
3136
+ const idProp = configArg.getProperty(ID_PROPERTY_NAME);
3137
+ if (!idProp || !import_ts_morph15.Node.isPropertyAssignment(idProp)) return "<unknown event>";
3138
+ const initializer = idProp.getInitializer();
3139
+ if (!initializer) return "<unknown event>";
3140
+ if (import_ts_morph15.Node.isStringLiteral(initializer)) {
3141
+ return initializer.getLiteralValue();
3142
+ }
3143
+ return initializer.getText();
3144
+ }
3145
+ function hasAnalyticsProperty(configArg) {
3146
+ return configArg.getProperty(ANALYTICS_PROPERTY_NAME) !== void 0;
3147
+ }
3148
+ function processFile12(filePath, project) {
3149
+ const sourceFile = project.getSourceFile(filePath);
3150
+ if (!sourceFile) return 0;
3151
+ const relPath = import_path16.default.relative(getCwd(), filePath);
3152
+ let changes = 0;
3153
+ const callExpressions = sourceFile.getDescendantsOfKind(
3154
+ import_ts_morph15.SyntaxKind.CallExpression
3155
+ );
3156
+ for (const call of callExpressions) {
3157
+ const expression = call.getExpression();
3158
+ if (!import_ts_morph15.Node.isIdentifier(expression)) continue;
3159
+ if (expression.getText() !== DEFINE_CONFIG_NAME5) continue;
3160
+ const args2 = call.getArguments();
3161
+ if (args2.length === 0) continue;
3162
+ const configArg = args2[0];
3163
+ if (!import_ts_morph15.Node.isObjectLiteralExpression(configArg)) continue;
3164
+ const eventLabel = getEventLabel(configArg);
3165
+ if (hasAnalyticsProperty(configArg)) {
3166
+ console.log(
3167
+ ` [${relPath}] Skipped '${eventLabel}' \u2014 'analytics' already declared.`
3168
+ );
3169
+ continue;
3170
+ }
3171
+ configArg.addPropertyAssignment({
3172
+ name: ANALYTICS_PROPERTY_NAME,
3173
+ initializer: "true"
3174
+ });
3175
+ console.log(` [${relPath}] Added 'analytics: true' to '${eventLabel}'.`);
3176
+ changes++;
3177
+ }
3178
+ return changes;
3179
+ }
3180
+ async function main16() {
3181
+ const srcDir = import_path16.default.join(getCwd(), "src");
3182
+ console.log(`Scanning for defineConfig calls in: ${srcDir}
3183
+ `);
3184
+ const project = new import_ts_morph15.Project({
3185
+ tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
3186
+ skipAddingFilesFromTsConfig: false
3187
+ });
3188
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3189
+ const fp = sf.getFilePath();
3190
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3191
+ });
3192
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
3193
+ `);
3194
+ let totalChanges = 0;
3195
+ const modifiedFiles = [];
3196
+ for (const sourceFile of sourceFiles) {
3197
+ const filePath = sourceFile.getFilePath();
3198
+ const changes = processFile12(filePath, project);
3199
+ if (changes > 0) {
3200
+ totalChanges += changes;
3201
+ modifiedFiles.push(filePath);
3202
+ }
3203
+ }
3204
+ if (modifiedFiles.length === 0) {
3205
+ console.log("No event configs needed updating. Nothing to do.");
3206
+ return;
3207
+ }
3208
+ console.log(`
3209
+ Saving ${modifiedFiles.length} modified file(s)...`);
3210
+ for (const filePath of modifiedFiles) {
3211
+ const sourceFile = project.getSourceFileOrThrow(filePath);
3212
+ await sourceFile.save();
3213
+ console.log(` Saved: ${import_path16.default.relative(getCwd(), filePath)}`);
3214
+ }
3215
+ console.log(
3216
+ `
3217
+ Done. Added 'analytics: true' to ${totalChanges} event config(s) across ${modifiedFiles.length} file(s).`
3218
+ );
3219
+ }
3220
+
3221
+ // src/migrations/v2.0/checkout-upstream-files.ts
3222
+ var import_child_process = require("child_process");
3223
+ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
3224
+ var UPSTREAM_BRANCH = "codemod-analytics";
3225
+ var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
3226
+ var FILES_TO_CHECKOUT = [
3227
+ "infrastructure/postgres/setup-analytics.sh",
3228
+ "src/analytics/analytics.ts"
3229
+ ];
3230
+ function runGit(args2, { silent = false } = {}) {
3231
+ return (0, import_child_process.execFileSync)("git", args2, {
3232
+ cwd: getCwd(),
3233
+ encoding: "utf8",
3234
+ stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
3235
+ });
3236
+ }
3237
+ function tryGit(args2) {
3238
+ try {
3239
+ runGit(args2, { silent: true });
3240
+ return true;
3241
+ } catch {
3242
+ return false;
3243
+ }
3244
+ }
3245
+ function assertIsGitRepo() {
3246
+ if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
3247
+ throw new Error(
3248
+ `checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3249
+ );
3250
+ }
3251
+ }
3252
+ async function main17() {
3253
+ console.log(
3254
+ `Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
3255
+ `
3256
+ );
3257
+ assertIsGitRepo();
3258
+ tryGit(["remote", "remove", TEMP_REMOTE]);
3259
+ try {
3260
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
3261
+ runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
3262
+ console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
3263
+ runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
3264
+ const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
3265
+ const missing = [];
3266
+ let checkedOut = 0;
3267
+ for (const file of FILES_TO_CHECKOUT) {
3268
+ if (tryGit(["checkout", ref, "--", file])) {
3269
+ console.log(` Checked out ${file} from ${ref}`);
3270
+ checkedOut++;
3271
+ } else {
3272
+ console.warn(
3273
+ ` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
3274
+ );
3275
+ missing.push(file);
3276
+ }
3277
+ }
3278
+ console.log(
3279
+ `
3280
+ Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
3281
+ );
3282
+ if (missing.length > 0) {
3283
+ console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
3284
+ }
3285
+ if (checkedOut > 0) {
3286
+ console.log(
3287
+ ` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
3288
+ (f) => `'${f}'`
3289
+ ).join(" ")}
3290
+ `
3291
+ );
3292
+ }
3293
+ } finally {
3294
+ if (tryGit(["remote", "remove", TEMP_REMOTE])) {
3295
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
3296
+ }
3297
+ }
3298
+ }
3299
+
3129
3300
  // src/migrations/v2.0/index.ts
3130
3301
  var cwd;
3131
3302
  function getCwd() {
@@ -3160,6 +3331,8 @@ async function runUpgrade(ccwd) {
3160
3331
  await main12();
3161
3332
  await main14();
3162
3333
  await main15();
3334
+ await main16();
3335
+ await main17();
3163
3336
  }
3164
3337
 
3165
3338
  // src/cli.ts
@@ -3174,7 +3347,7 @@ Commands:
3174
3347
 
3175
3348
  Run 'opencrvs <command> --help' for more information on a command.
3176
3349
  `.trim();
3177
- function main16() {
3350
+ function main18() {
3178
3351
  const command = args[0];
3179
3352
  if (!command || command === "--help" || command === "-h") {
3180
3353
  console.log(USAGE);
@@ -3234,4 +3407,4 @@ function handleCheckTranslations() {
3234
3407
  console.warn("This command is not implemented yet!");
3235
3408
  process.exit(1);
3236
3409
  }
3237
- main16();
3410
+ main18();
@@ -29,6 +29,7 @@ export type EventConfig = {
29
29
  declaration: DeclarationFormConfig;
30
30
  advancedSearch: AdvancedSearchConfig[];
31
31
  flags: FlagConfig[];
32
+ analytics?: boolean;
32
33
  };
33
34
  export type EventConfigInput = Omit<EventConfig, 'advancedSearch' | 'flags' | 'declaration' | 'actions' | 'dateOfEvent' | 'placeOfEvent'> & {
34
35
  dateOfEvent?: z.input<typeof FieldReference> | z.infer<typeof EventFieldReference>;
@@ -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(false).describe(
5347
+ "Indicates whether the recors of this event type are included in analytics"
5345
5348
  )
5346
5349
  });
5347
5350
  var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=add-analytics-option-to-event-configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-analytics-option-to-event-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-analytics-option-to-event-configs.ts"],"names":[],"mappings":"AA4GA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA6CnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,139 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ /**
27
+ * Codemod: Add `analytics: true` option to event configs.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/add-analytics-option-to-event-configs.ts
31
+ *
32
+ * What it does:
33
+ * 1. Scans the country config `src/` directory for `defineConfig({...})` calls.
34
+ * 2. For every event config that does not yet declare an `analytics` property,
35
+ * inserts `analytics: true` into the config object literal.
36
+ * 3. Saves the modified files in-place.
37
+ *
38
+ * Event configs that already declare `analytics` are left untouched so this
39
+ * codemod is safe to re-run.
40
+ */
41
+ const ts_morph_1 = require("ts-morph");
42
+ const path_1 = __importDefault(require("path"));
43
+ const _1 = require(".");
44
+ const DEFINE_CONFIG_NAME = 'defineConfig';
45
+ const ID_PROPERTY_NAME = 'id';
46
+ const ANALYTICS_PROPERTY_NAME = 'analytics';
47
+ // ─── AST helpers ─────────────────────────────────────────────────────────────
48
+ /**
49
+ * Returns a human-readable label for an event config, derived from its `id`
50
+ * property. Used only for log output. Falls back to `<unknown event>` when the
51
+ * id can't be statically resolved.
52
+ */
53
+ function getEventLabel(configArg) {
54
+ const idProp = configArg.getProperty(ID_PROPERTY_NAME);
55
+ if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
56
+ return '<unknown event>';
57
+ const initializer = idProp.getInitializer();
58
+ if (!initializer)
59
+ return '<unknown event>';
60
+ if (ts_morph_1.Node.isStringLiteral(initializer)) {
61
+ return initializer.getLiteralValue();
62
+ }
63
+ // Handles `Event.Birth`, `EventType.BIRTH`, etc.
64
+ return initializer.getText();
65
+ }
66
+ function hasAnalyticsProperty(configArg) {
67
+ return configArg.getProperty(ANALYTICS_PROPERTY_NAME) !== undefined;
68
+ }
69
+ // ─── File processor ──────────────────────────────────────────────────────────
70
+ function processFile(filePath, project) {
71
+ const sourceFile = project.getSourceFile(filePath);
72
+ if (!sourceFile)
73
+ return 0;
74
+ const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
75
+ let changes = 0;
76
+ const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
77
+ for (const call of callExpressions) {
78
+ const expression = call.getExpression();
79
+ if (!ts_morph_1.Node.isIdentifier(expression))
80
+ continue;
81
+ if (expression.getText() !== DEFINE_CONFIG_NAME)
82
+ continue;
83
+ const args = call.getArguments();
84
+ if (args.length === 0)
85
+ continue;
86
+ const configArg = args[0];
87
+ if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
88
+ continue;
89
+ const eventLabel = getEventLabel(configArg);
90
+ if (hasAnalyticsProperty(configArg)) {
91
+ console.log(` [${relPath}] Skipped '${eventLabel}' — 'analytics' already declared.`);
92
+ continue;
93
+ }
94
+ configArg.addPropertyAssignment({
95
+ name: ANALYTICS_PROPERTY_NAME,
96
+ initializer: 'true'
97
+ });
98
+ console.log(` [${relPath}] Added 'analytics: true' to '${eventLabel}'.`);
99
+ changes++;
100
+ }
101
+ return changes;
102
+ }
103
+ // ─── Entry point ─────────────────────────────────────────────────────────────
104
+ function main() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
107
+ console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
108
+ const project = new ts_morph_1.Project({
109
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
110
+ skipAddingFilesFromTsConfig: false
111
+ });
112
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
113
+ const fp = sf.getFilePath();
114
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
115
+ });
116
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
117
+ let totalChanges = 0;
118
+ const modifiedFiles = [];
119
+ for (const sourceFile of sourceFiles) {
120
+ const filePath = sourceFile.getFilePath();
121
+ const changes = processFile(filePath, project);
122
+ if (changes > 0) {
123
+ totalChanges += changes;
124
+ modifiedFiles.push(filePath);
125
+ }
126
+ }
127
+ if (modifiedFiles.length === 0) {
128
+ console.log('No event configs needed updating. Nothing to do.');
129
+ return;
130
+ }
131
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
132
+ for (const filePath of modifiedFiles) {
133
+ const sourceFile = project.getSourceFileOrThrow(filePath);
134
+ yield sourceFile.save();
135
+ console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
136
+ }
137
+ console.log(`\nDone. Added 'analytics: true' to ${totalChanges} event config(s) across ${modifiedFiles.length} file(s).`);
138
+ });
139
+ }
@@ -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 = 'codemod-analytics';
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":"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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA8BA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBA6BxD"}
@@ -1826,9 +1826,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1826
1826
  }
1827
1827
  return replacedCount;
1828
1828
  }
1829
- function resolveConfigChain(configObj, path15) {
1829
+ function resolveConfigChain(configObj, path16) {
1830
1830
  let current = configObj;
1831
- for (const key of path15) {
1831
+ for (const key of path16) {
1832
1832
  if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1833
1833
  const prop = current.getProperty(key);
1834
1834
  if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
@@ -3139,6 +3139,177 @@ async function main15() {
3139
3139
  }
3140
3140
  }
3141
3141
 
3142
+ // src/migrations/v2.0/add-analytics-option-to-event-configs.ts
3143
+ var import_ts_morph15 = require("ts-morph");
3144
+ var import_path16 = __toESM(require("path"));
3145
+ var DEFINE_CONFIG_NAME5 = "defineConfig";
3146
+ var ID_PROPERTY_NAME = "id";
3147
+ var ANALYTICS_PROPERTY_NAME = "analytics";
3148
+ function getEventLabel(configArg) {
3149
+ const idProp = configArg.getProperty(ID_PROPERTY_NAME);
3150
+ if (!idProp || !import_ts_morph15.Node.isPropertyAssignment(idProp)) return "<unknown event>";
3151
+ const initializer = idProp.getInitializer();
3152
+ if (!initializer) return "<unknown event>";
3153
+ if (import_ts_morph15.Node.isStringLiteral(initializer)) {
3154
+ return initializer.getLiteralValue();
3155
+ }
3156
+ return initializer.getText();
3157
+ }
3158
+ function hasAnalyticsProperty(configArg) {
3159
+ return configArg.getProperty(ANALYTICS_PROPERTY_NAME) !== void 0;
3160
+ }
3161
+ function processFile12(filePath, project) {
3162
+ const sourceFile = project.getSourceFile(filePath);
3163
+ if (!sourceFile) return 0;
3164
+ const relPath = import_path16.default.relative(getCwd(), filePath);
3165
+ let changes = 0;
3166
+ const callExpressions = sourceFile.getDescendantsOfKind(
3167
+ import_ts_morph15.SyntaxKind.CallExpression
3168
+ );
3169
+ for (const call of callExpressions) {
3170
+ const expression = call.getExpression();
3171
+ if (!import_ts_morph15.Node.isIdentifier(expression)) continue;
3172
+ if (expression.getText() !== DEFINE_CONFIG_NAME5) continue;
3173
+ const args = call.getArguments();
3174
+ if (args.length === 0) continue;
3175
+ const configArg = args[0];
3176
+ if (!import_ts_morph15.Node.isObjectLiteralExpression(configArg)) continue;
3177
+ const eventLabel = getEventLabel(configArg);
3178
+ if (hasAnalyticsProperty(configArg)) {
3179
+ console.log(
3180
+ ` [${relPath}] Skipped '${eventLabel}' \u2014 'analytics' already declared.`
3181
+ );
3182
+ continue;
3183
+ }
3184
+ configArg.addPropertyAssignment({
3185
+ name: ANALYTICS_PROPERTY_NAME,
3186
+ initializer: "true"
3187
+ });
3188
+ console.log(` [${relPath}] Added 'analytics: true' to '${eventLabel}'.`);
3189
+ changes++;
3190
+ }
3191
+ return changes;
3192
+ }
3193
+ async function main16() {
3194
+ const srcDir = import_path16.default.join(getCwd(), "src");
3195
+ console.log(`Scanning for defineConfig calls in: ${srcDir}
3196
+ `);
3197
+ const project = new import_ts_morph15.Project({
3198
+ tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
3199
+ skipAddingFilesFromTsConfig: false
3200
+ });
3201
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3202
+ const fp = sf.getFilePath();
3203
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3204
+ });
3205
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
3206
+ `);
3207
+ let totalChanges = 0;
3208
+ const modifiedFiles = [];
3209
+ for (const sourceFile of sourceFiles) {
3210
+ const filePath = sourceFile.getFilePath();
3211
+ const changes = processFile12(filePath, project);
3212
+ if (changes > 0) {
3213
+ totalChanges += changes;
3214
+ modifiedFiles.push(filePath);
3215
+ }
3216
+ }
3217
+ if (modifiedFiles.length === 0) {
3218
+ console.log("No event configs needed updating. Nothing to do.");
3219
+ return;
3220
+ }
3221
+ console.log(`
3222
+ Saving ${modifiedFiles.length} modified file(s)...`);
3223
+ for (const filePath of modifiedFiles) {
3224
+ const sourceFile = project.getSourceFileOrThrow(filePath);
3225
+ await sourceFile.save();
3226
+ console.log(` Saved: ${import_path16.default.relative(getCwd(), filePath)}`);
3227
+ }
3228
+ console.log(
3229
+ `
3230
+ Done. Added 'analytics: true' to ${totalChanges} event config(s) across ${modifiedFiles.length} file(s).`
3231
+ );
3232
+ }
3233
+
3234
+ // src/migrations/v2.0/checkout-upstream-files.ts
3235
+ var import_child_process = require("child_process");
3236
+ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
3237
+ var UPSTREAM_BRANCH = "codemod-analytics";
3238
+ var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
3239
+ var FILES_TO_CHECKOUT = [
3240
+ "infrastructure/postgres/setup-analytics.sh",
3241
+ "src/analytics/analytics.ts"
3242
+ ];
3243
+ function runGit(args, { silent = false } = {}) {
3244
+ return (0, import_child_process.execFileSync)("git", args, {
3245
+ cwd: getCwd(),
3246
+ encoding: "utf8",
3247
+ stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
3248
+ });
3249
+ }
3250
+ function tryGit(args) {
3251
+ try {
3252
+ runGit(args, { silent: true });
3253
+ return true;
3254
+ } catch {
3255
+ return false;
3256
+ }
3257
+ }
3258
+ function assertIsGitRepo() {
3259
+ if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
3260
+ throw new Error(
3261
+ `checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3262
+ );
3263
+ }
3264
+ }
3265
+ async function main17() {
3266
+ console.log(
3267
+ `Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
3268
+ `
3269
+ );
3270
+ assertIsGitRepo();
3271
+ tryGit(["remote", "remove", TEMP_REMOTE]);
3272
+ try {
3273
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
3274
+ runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
3275
+ console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
3276
+ runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
3277
+ const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
3278
+ const missing = [];
3279
+ let checkedOut = 0;
3280
+ for (const file of FILES_TO_CHECKOUT) {
3281
+ if (tryGit(["checkout", ref, "--", file])) {
3282
+ console.log(` Checked out ${file} from ${ref}`);
3283
+ checkedOut++;
3284
+ } else {
3285
+ console.warn(
3286
+ ` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
3287
+ );
3288
+ missing.push(file);
3289
+ }
3290
+ }
3291
+ console.log(
3292
+ `
3293
+ Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
3294
+ );
3295
+ if (missing.length > 0) {
3296
+ console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
3297
+ }
3298
+ if (checkedOut > 0) {
3299
+ console.log(
3300
+ ` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
3301
+ (f) => `'${f}'`
3302
+ ).join(" ")}
3303
+ `
3304
+ );
3305
+ }
3306
+ } finally {
3307
+ if (tryGit(["remote", "remove", TEMP_REMOTE])) {
3308
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
3309
+ }
3310
+ }
3311
+ }
3312
+
3142
3313
  // src/migrations/v2.0/index.ts
3143
3314
  var cwd;
3144
3315
  function getCwd() {
@@ -3173,4 +3344,6 @@ async function runUpgrade(ccwd) {
3173
3344
  await main12();
3174
3345
  await main14();
3175
3346
  await main15();
3347
+ await main16();
3348
+ await main17();
3176
3349
  }
@@ -3661,6 +3661,9 @@ var _EventConfigBase = z33.object({
3661
3661
  ),
3662
3662
  flags: z33.array(FlagConfig).optional().default([]).describe(
3663
3663
  "Configuration of flags associated with the actions of this event type."
3664
+ ),
3665
+ analytics: z33.boolean().optional().default(false).describe(
3666
+ "Indicates whether the recors of this event type are included in analytics"
3664
3667
  )
3665
3668
  });
3666
3669
  var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.12-rc.f8905a4",
3
+ "version": "1.9.12-rc.f8f1dc7",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"root":["./src/cli.ts","./src/api/index.ts","./src/application-config/index.ts","./src/conditionals/index.ts","./src/events/deduplication.ts","./src/events/index.ts","./src/migrations/v2.0/add-birth-certificate-issuance-flag.ts","./src/migrations/v2.0/convert-config-files-to-ts.ts","./src/migrations/v2.0/convert-paragraph-to-heading.ts","./src/migrations/v2.0/index.ts","./src/migrations/v2.0/make-built-in-validate-actions-custom.ts","./src/migrations/v2.0/migrate-scopes.ts","./src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts","./src/migrations/v2.0/migrate-workqueue-configs.ts","./src/migrations/v2.0/remove-delete-actions.ts","./src/migrations/v2.0/remove-demo-scope.ts","./src/migrations/v2.0/remove-deprecated-imports.ts","./src/migrations/v2.0/remove-hearth-migrations.ts","./src/migrations/v2.0/remove-pending-certification-flag.ts","./src/migrations/v2.0/remove-review-from-register-action.ts","./src/migrations/v2.0/rename-api-paths.ts","./src/migrations/v2.0/rename-location-parent-id.ts","./src/notification/index.ts","./src/scopes/index.ts"],"version":"5.6.3"}
1
+ {"root":["./src/cli.ts","./src/api/index.ts","./src/application-config/index.ts","./src/conditionals/index.ts","./src/events/deduplication.ts","./src/events/index.ts","./src/migrations/v2.0/add-analytics-option-to-event-configs.ts","./src/migrations/v2.0/add-birth-certificate-issuance-flag.ts","./src/migrations/v2.0/checkout-upstream-files.ts","./src/migrations/v2.0/convert-config-files-to-ts.ts","./src/migrations/v2.0/convert-paragraph-to-heading.ts","./src/migrations/v2.0/index.ts","./src/migrations/v2.0/make-built-in-validate-actions-custom.ts","./src/migrations/v2.0/migrate-scopes.ts","./src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts","./src/migrations/v2.0/migrate-workqueue-configs.ts","./src/migrations/v2.0/remove-delete-actions.ts","./src/migrations/v2.0/remove-demo-scope.ts","./src/migrations/v2.0/remove-deprecated-imports.ts","./src/migrations/v2.0/remove-hearth-migrations.ts","./src/migrations/v2.0/remove-pending-certification-flag.ts","./src/migrations/v2.0/remove-review-from-register-action.ts","./src/migrations/v2.0/rename-api-paths.ts","./src/migrations/v2.0/rename-location-parent-id.ts","./src/notification/index.ts","./src/scopes/index.ts"],"version":"5.6.3"}