@opencrvs/toolkit 1.9.12-rc.f5ca5e6 → 1.9.12-rc.f687751

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 (128) hide show
  1. package/build.sh +8 -0
  2. package/dist/application-config/index.js +2045 -41
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +4841 -0
  6. package/dist/commons/api/router.d.ts +475 -244
  7. package/dist/commons/application-config/index.d.ts +13 -16
  8. package/dist/commons/conditionals/conditionals.d.ts +8 -8
  9. package/dist/commons/events/ActionDocument.d.ts +196 -196
  10. package/dist/commons/events/ActionInput.d.ts +113 -113
  11. package/dist/commons/events/ActionType.d.ts +3 -3
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +6 -0
  13. package/dist/commons/events/AuditLog.d.ts +347 -163
  14. package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
  15. package/dist/commons/events/CountryConfigQueryInput.d.ts +461 -190
  16. package/dist/commons/events/Draft.d.ts +9 -9
  17. package/dist/commons/events/DynamicFieldValue.d.ts +37 -19
  18. package/dist/commons/events/EventConfig.d.ts +3 -1
  19. package/dist/commons/events/EventDocument.d.ts +80 -80
  20. package/dist/commons/events/EventIndex.d.ts +35 -27
  21. package/dist/commons/events/EventInput.d.ts +1 -1
  22. package/dist/commons/events/EventMetadata.d.ts +19 -19
  23. package/dist/commons/events/FieldConfig.d.ts +287 -71
  24. package/dist/commons/events/FieldType.d.ts +2 -1
  25. package/dist/commons/events/FieldTypeMapping.d.ts +98 -72
  26. package/dist/commons/events/FieldValue.d.ts +54 -26
  27. package/dist/commons/events/PlainDate.d.ts +1 -1
  28. package/dist/commons/events/WorkqueueColumnConfig.d.ts +7 -7
  29. package/dist/commons/events/WorkqueueConfig.d.ts +443 -199
  30. package/dist/commons/events/defineConfig.d.ts +0 -4
  31. package/dist/commons/events/locations.d.ts +4 -4
  32. package/dist/commons/events/scopes.d.ts +4 -3
  33. package/dist/commons/events/state/index.d.ts +2 -2
  34. package/dist/commons/events/state/utils.d.ts +1 -1
  35. package/dist/commons/events/test.utils.d.ts +2 -2
  36. package/dist/commons/events/utils.d.ts +3 -175
  37. package/dist/commons/notification/UserNotifications.d.ts +21 -1
  38. package/dist/conditionals/index.js +74 -359
  39. package/dist/events/index.js +1207 -1260
  40. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  41. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  42. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +404 -0
  43. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  44. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  45. package/dist/migrations/v2.0/add-resend-invite-notification.js +345 -0
  46. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  47. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  48. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  49. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  50. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  51. package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
  52. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  53. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  54. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
  55. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  56. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  57. package/dist/migrations/v2.0/create-events-index.js +325 -0
  58. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  59. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  60. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  61. package/dist/migrations/v2.0/index.d.ts +11 -0
  62. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  63. package/dist/migrations/v2.0/index.js +4751 -0
  64. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  65. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +343 -0
  67. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  68. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  70. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  71. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  73. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  74. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  76. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  77. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
  79. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  80. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/migrate-workqueue-configs.js +236 -0
  82. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  83. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
  85. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  86. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
  88. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  89. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
  91. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  92. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  94. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  95. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
  97. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  98. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  100. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  101. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
  103. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  104. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
  106. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  109. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  110. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/rename-api-paths.js +187 -0
  112. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  113. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
  115. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  116. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  118. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  119. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/update-package-json.js +105 -0
  121. package/dist/notification/index.js +1013 -1135
  122. package/dist/scopes/index.d.ts +389 -152
  123. package/dist/scopes/index.js +128 -322
  124. package/opencrvs-toolkit-1.9.12-rc.f687751.tgz +0 -0
  125. package/package.json +11 -7
  126. package/tsconfig.json +3 -0
  127. package/tsconfig.tsbuildinfo +1 -1
  128. package/opencrvs-toolkit-1.9.12-rc.f5ca5e6.tgz +0 -0
@@ -0,0 +1,345 @@
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 `TriggerEvent.RESEND_INVITE` wiring to the country config
28
+ * (email schemas, templates, `/triggers/user/resend-invite` route,
29
+ * SMS keys, CSV copy, HTML template).
30
+ *
31
+ * Idempotent: safe to run multiple times; skips edits when markers are
32
+ * already present.
33
+ */
34
+ const fs_1 = require("fs");
35
+ const path_1 = __importDefault(require("path"));
36
+ const EMAIL_TEMPLATES_INDEX = 'src/api/notification/email-templates/index.ts';
37
+ const NOTIFICATION_HANDLER = 'src/api/notification/handler.ts';
38
+ const USER_NOTIFICATION_ROUTES = 'src/config/routes/userNotificationRoutes.ts';
39
+ const SMS_SERVICE = 'src/api/notification/sms-service.ts';
40
+ const NOTIFICATION_CSV = 'src/translations/notification.csv';
41
+ const RESEND_INVITE_HTML = 'src/api/notification/email-templates/other/resend-invite.html';
42
+ const TRIGGER_VARIABLE_ANCHOR_BEFORE = ` [TriggerEvent.CHANGE_PHONE_NUMBER]: z.object({
43
+ firstname: z.string(),
44
+ code: z.string()
45
+ })
46
+ } as const`;
47
+ const TRIGGER_VARIABLE_ANCHOR_AFTER = ` [TriggerEvent.CHANGE_PHONE_NUMBER]: z.object({
48
+ firstname: z.string(),
49
+ code: z.string()
50
+ }),
51
+ [TriggerEvent.RESEND_INVITE]: z.object({
52
+ firstname: z.string(),
53
+ username: z.string(),
54
+ temporaryPassword: z.string(),
55
+ completeSetupUrl: z.string(),
56
+ loginURL: z.string()
57
+ })
58
+ } as const`;
59
+ const TEMPLATES_ANCHOR_BEFORE = ` [TriggerEvent.USER_CREATED]: {
60
+ type: 'onboarding-invite',
61
+ subject: 'Welcome to OpenCRVS!',
62
+ template:
63
+ readOtherTemplate<TriggerVariable['user-created']>('onboarding-invite')
64
+ },
65
+ [TriggerEvent.TWO_FA]: {`;
66
+ const TEMPLATES_ANCHOR_AFTER = ` [TriggerEvent.USER_CREATED]: {
67
+ type: 'onboarding-invite',
68
+ subject: 'Welcome to OpenCRVS!',
69
+ template:
70
+ readOtherTemplate<TriggerVariable['user-created']>('onboarding-invite')
71
+ },
72
+ [TriggerEvent.RESEND_INVITE]: {
73
+ type: 'resend-invite',
74
+ subject: 'Your OpenCRVS account invitation',
75
+ template:
76
+ readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
77
+ },
78
+ [TriggerEvent.TWO_FA]: {`;
79
+ const HANDLER_ANCHOR_BEFORE = ` case TriggerEvent.USER_CREATED:
80
+ return {
81
+ firstname,
82
+ username: payload.username,
83
+ temporaryPassword: payload.temporaryPassword,
84
+ completeSetupUrl: LOGIN_URL,
85
+ loginURL: LOGIN_URL
86
+ }
87
+
88
+ case TriggerEvent.USER_UPDATED:`;
89
+ const HANDLER_ANCHOR_AFTER = ` case TriggerEvent.USER_CREATED:
90
+ return {
91
+ firstname,
92
+ username: payload.username,
93
+ temporaryPassword: payload.temporaryPassword,
94
+ completeSetupUrl: LOGIN_URL,
95
+ loginURL: LOGIN_URL
96
+ }
97
+
98
+ case TriggerEvent.RESEND_INVITE:
99
+ return {
100
+ firstname,
101
+ username: payload.username,
102
+ temporaryPassword: payload.temporaryPassword,
103
+ completeSetupUrl: LOGIN_URL,
104
+ loginURL: LOGIN_URL
105
+ }
106
+
107
+ case TriggerEvent.USER_UPDATED:`;
108
+ const ROUTES_ANCHOR_BEFORE = ` {
109
+ method: 'POST',
110
+ path: '/triggers/user/user-created',
111
+ handler: makeNotificationHandler('user-created'),
112
+ options: {
113
+ auth: false,
114
+ tags: ['api'],
115
+ description: 'Handles notification for user creation'
116
+ }
117
+ },
118
+ {
119
+ method: 'POST',
120
+ path: '/triggers/user/user-updated',`;
121
+ const ROUTES_ANCHOR_AFTER = ` {
122
+ method: 'POST',
123
+ path: '/triggers/user/user-created',
124
+ handler: makeNotificationHandler('user-created'),
125
+ options: {
126
+ auth: false,
127
+ tags: ['api'],
128
+ description: 'Handles notification for user creation'
129
+ }
130
+ },
131
+ {
132
+ method: 'POST',
133
+ path: '/triggers/user/resend-invite',
134
+ handler: makeNotificationHandler('resend-invite'),
135
+ options: {
136
+ auth: false,
137
+ tags: ['api'],
138
+ description: 'Handles notification for resent user invite'
139
+ }
140
+ },
141
+ {
142
+ method: 'POST',
143
+ path: '/triggers/user/user-updated',`;
144
+ const SMS_OTHER_BEFORE = ` userCredentialsNotification: 'userCredentialsNotification',
145
+ retieveUserNameNotification:`;
146
+ const SMS_OTHER_AFTER = ` userCredentialsNotification: 'userCredentialsNotification',
147
+ resendInviteNotification: 'resendInviteNotification',
148
+ retieveUserNameNotification:`;
149
+ const SMS_TRIGGER_BEFORE = ` ['user-created']: 'userCredentialsNotification',
150
+ ['user-updated']: 'updateUserNameNotification',`;
151
+ const SMS_TRIGGER_AFTER = ` ['user-created']: 'userCredentialsNotification',
152
+ ['resend-invite']: 'resendInviteNotification',
153
+ ['user-updated']: 'updateUserNameNotification',`;
154
+ const RESEND_INVITE_HTML_CONTENT = `<!doctype html>
155
+ <html>
156
+ <head>
157
+ <link
158
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
159
+ rel="stylesheet"
160
+ />
161
+ <style type="text/css">
162
+ body {
163
+ font-family: 'Noto Sans', sans-serif;
164
+ color: #222;
165
+ padding: 16px 24px;
166
+ }
167
+
168
+ h1 {
169
+ font-size: 21px;
170
+ margin-top: 32px;
171
+ margin-bottom: 36px;
172
+ font-weight: 700;
173
+ }
174
+
175
+ p {
176
+ font-weight: 400;
177
+ font-size: 16px;
178
+ line-height: 1.8;
179
+ margin-bottom: 24px;
180
+ }
181
+
182
+ i {
183
+ color: #666;
184
+ font-weight: 400;
185
+ font-size: 16px;
186
+ }
187
+ </style>
188
+ </head>
189
+
190
+ <body>
191
+ <img
192
+ src="{{countryLogo}}"
193
+ alt="country_logo"
194
+ style="max-height: 88px; max-width: 100%"
195
+ />
196
+ <h1>Your {{applicationName}} account invitation</h1>
197
+ <p>Hello {{firstname}},</p>
198
+ <p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
199
+ <p>
200
+ Username: <strong>{{username}}</strong><br />
201
+ Password: <strong>{{temporaryPassword}}</strong>
202
+ </p>
203
+ <p>
204
+ Please click the link below to complete your account setup and start using
205
+ {{applicationName}}.
206
+ </p>
207
+
208
+ <div style="margin-top: 32px; margin-bottom: 32px">
209
+ <a href="{{loginURL}}">Complete setup</a>
210
+ </div>
211
+ <br />
212
+ <p>
213
+ Best regards, <br />
214
+ {{applicationName}} Team
215
+ </p>
216
+ </body>
217
+ </html>
218
+ `;
219
+ const CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a été renvoyée. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
220
+ function replaceExactlyOnceOrSkip(fileLabel, contents, before, after, anchorName) {
221
+ const n = contents.split(before).length - 1;
222
+ if (n === 0) {
223
+ // eslint-disable-next-line no-console
224
+ console.log(` [${fileLabel}] ${anchorName}: anchor not found — skipping (unexpected file shape).`);
225
+ return { contents, changed: false };
226
+ }
227
+ if (n > 1) {
228
+ // eslint-disable-next-line no-console
229
+ console.warn(` [${fileLabel}] ${anchorName}: ambiguous anchor (${n} matches) — skipping.`);
230
+ return { contents, changed: false };
231
+ }
232
+ const next = contents.replace(before, after);
233
+ return { contents: next, changed: true };
234
+ }
235
+ function patchEmailTemplatesIndex() {
236
+ const full = path_1.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
237
+ if (!(0, fs_1.existsSync)(full)) {
238
+ // eslint-disable-next-line no-console
239
+ console.log(` '${EMAIL_TEMPLATES_INDEX}' missing — skipping.`);
240
+ return false;
241
+ }
242
+ let text = (0, fs_1.readFileSync)(full, 'utf8');
243
+ let changed = false;
244
+ if (!text.includes('[TriggerEvent.RESEND_INVITE]: z.object')) {
245
+ const r = replaceExactlyOnceOrSkip(EMAIL_TEMPLATES_INDEX, text, TRIGGER_VARIABLE_ANCHOR_BEFORE, TRIGGER_VARIABLE_ANCHOR_AFTER, 'TriggerVariable');
246
+ text = r.contents;
247
+ if (r.changed)
248
+ changed = true;
249
+ }
250
+ if (!text.includes("readOtherTemplate<TriggerVariable['resend-invite']>")) {
251
+ const r = replaceExactlyOnceOrSkip(EMAIL_TEMPLATES_INDEX, text, TEMPLATES_ANCHOR_BEFORE, TEMPLATES_ANCHOR_AFTER, '`templates`');
252
+ text = r.contents;
253
+ if (r.changed)
254
+ changed = true;
255
+ }
256
+ if (changed) {
257
+ (0, fs_1.writeFileSync)(full, text);
258
+ }
259
+ return changed;
260
+ }
261
+ function main() {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ // eslint-disable-next-line no-console
264
+ console.log('Adding RESEND_INVITE notification wiring…');
265
+ const touched = [];
266
+ if (patchEmailTemplatesIndex())
267
+ touched.push(EMAIL_TEMPLATES_INDEX);
268
+ /* handler */
269
+ const handlerPath = path_1.default.join(process.cwd(), NOTIFICATION_HANDLER);
270
+ if ((0, fs_1.existsSync)(handlerPath)) {
271
+ let t = (0, fs_1.readFileSync)(handlerPath, 'utf8');
272
+ if (!t.includes('TriggerEvent.RESEND_INVITE') &&
273
+ t.includes(HANDLER_ANCHOR_BEFORE)) {
274
+ const count = t.split(HANDLER_ANCHOR_BEFORE).length - 1;
275
+ if (count === 1) {
276
+ t = t.replace(HANDLER_ANCHOR_BEFORE, HANDLER_ANCHOR_AFTER);
277
+ (0, fs_1.writeFileSync)(handlerPath, t);
278
+ touched.push(NOTIFICATION_HANDLER);
279
+ }
280
+ }
281
+ }
282
+ /* routes */
283
+ const routesPath = path_1.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
284
+ if ((0, fs_1.existsSync)(routesPath)) {
285
+ let t = (0, fs_1.readFileSync)(routesPath, 'utf8');
286
+ if (!t.includes(`/triggers/user/resend-invite`) && t.includes(ROUTES_ANCHOR_BEFORE)) {
287
+ const count = t.split(ROUTES_ANCHOR_BEFORE).length - 1;
288
+ if (count === 1) {
289
+ t = t.replace(ROUTES_ANCHOR_BEFORE, ROUTES_ANCHOR_AFTER);
290
+ (0, fs_1.writeFileSync)(routesPath, t);
291
+ touched.push(USER_NOTIFICATION_ROUTES);
292
+ }
293
+ }
294
+ }
295
+ /* sms-service */
296
+ const smsPath = path_1.default.join(process.cwd(), SMS_SERVICE);
297
+ if ((0, fs_1.existsSync)(smsPath)) {
298
+ let t = (0, fs_1.readFileSync)(smsPath, 'utf8');
299
+ let smsChanged = false;
300
+ if (!t.includes(`resendInviteNotification`)) {
301
+ const n = t.split(SMS_OTHER_BEFORE).length - 1;
302
+ if (n === 1) {
303
+ t = t.replace(SMS_OTHER_BEFORE, SMS_OTHER_AFTER);
304
+ smsChanged = true;
305
+ }
306
+ }
307
+ if (!t.includes(`['resend-invite']`)) {
308
+ const n = t.split(SMS_TRIGGER_BEFORE).length - 1;
309
+ if (n === 1) {
310
+ t = t.replace(SMS_TRIGGER_BEFORE, SMS_TRIGGER_AFTER);
311
+ smsChanged = true;
312
+ }
313
+ }
314
+ if (smsChanged) {
315
+ (0, fs_1.writeFileSync)(smsPath, t);
316
+ touched.push(SMS_SERVICE);
317
+ }
318
+ }
319
+ /* csv */
320
+ const csvPath = path_1.default.join(process.cwd(), NOTIFICATION_CSV);
321
+ if ((0, fs_1.existsSync)(csvPath)) {
322
+ let t = (0, fs_1.readFileSync)(csvPath, 'utf8');
323
+ if (!/^resendInviteNotification,/m.test(t)) {
324
+ if (!t.endsWith('\n'))
325
+ t += '\n';
326
+ (0, fs_1.writeFileSync)(csvPath, t + CSV_ROW);
327
+ touched.push(NOTIFICATION_CSV);
328
+ }
329
+ }
330
+ /* html */
331
+ const htmlPath = path_1.default.join(process.cwd(), RESEND_INVITE_HTML);
332
+ (0, fs_1.mkdirSync)(path_1.default.dirname(htmlPath), { recursive: true });
333
+ if (!(0, fs_1.existsSync)(htmlPath)) {
334
+ (0, fs_1.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
335
+ touched.push(RESEND_INVITE_HTML);
336
+ }
337
+ if (touched.length === 0) {
338
+ // eslint-disable-next-line no-console
339
+ console.log(' Nothing to update (already present or anchors not found).');
340
+ return;
341
+ }
342
+ // eslint-disable-next-line no-console
343
+ console.log(` Updated:\n${touched.map((f) => ` - ${f}`).join('\n')}`);
344
+ });
345
+ }
@@ -0,0 +1,22 @@
1
+ export declare const UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
2
+ export declare const UPSTREAM_BRANCH = "develop";
3
+ /**
4
+ * Runs a git command in the country config working directory.
5
+ *
6
+ * By default stderr is inherited so the user sees progress output from
7
+ * long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
8
+ * both stdout and stderr when you only care about the exit code.
9
+ */
10
+ export declare function runGit(args: string[], { silent }?: {
11
+ silent?: boolean;
12
+ }): string;
13
+ /**
14
+ * Runs a git command and returns true on success, false on failure.
15
+ * Stderr/stdout are suppressed — use only when the exit code is the only
16
+ * signal you care about.
17
+ */
18
+ export declare function tryGit(args: string[]): boolean;
19
+ export declare function assertIsGitRepo(): void;
20
+ declare function main(): Promise<void>;
21
+ export { main };
22
+ //# 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":"AA8CA,eAAO,MAAM,YAAY,2DACiC,CAAA;AAG1D,eAAO,MAAM,eAAe,YAAY,CAAA;AAcxC;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAO9C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAID,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,147 @@
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.UPSTREAM_BRANCH = exports.UPSTREAM_URL = void 0;
23
+ exports.runGit = runGit;
24
+ exports.tryGit = tryGit;
25
+ exports.assertIsGitRepo = assertIsGitRepo;
26
+ exports.main = main;
27
+ /**
28
+ * Codemod: Replace selected files with their upstream v2.0 versions from
29
+ * opencrvs/opencrvs-countryconfig.
30
+ *
31
+ * Usage:
32
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/checkout-upstream-files.ts
33
+ *
34
+ * What it does:
35
+ * 1. Registers a temporary git remote that points at the canonical
36
+ * opencrvs-countryconfig repository.
37
+ * 2. Fetches the chosen upstream branch at --depth=1 to keep it fast.
38
+ * 3. Path-scoped checkouts each listed file from that branch. The upstream
39
+ * version is written to the working tree AND staged in the index, so
40
+ * the dev can review the diff afterwards with:
41
+ * git diff --cached -- <file>
42
+ * 4. Removes the temporary remote in all cases (success, failure, or
43
+ * unexpected error) via a `finally` block.
44
+ *
45
+ * Why a git-based approach (as opposed to a raw HTTPS download):
46
+ * - Git handles text, binary, and line endings correctly.
47
+ * - The checked-out files end up staged, giving an obvious review UX.
48
+ * - `git checkout <ref> -- <paths>` is a blob-level copy, so it works
49
+ * whether or not the target repo shares history with
50
+ * opencrvs-countryconfig (e.g. country implementations started from
51
+ * scratch rather than forked).
52
+ *
53
+ * Caveats:
54
+ * - Overwrites any local modifications to the listed files. Run the
55
+ * upgrade on a clean working tree, or accept that the upstream version
56
+ * replaces yours.
57
+ * - Requires git to be installed and network access to github.com.
58
+ * - Requires the country config working directory to be a git repo.
59
+ */
60
+ const child_process_1 = require("child_process");
61
+ exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
62
+ // @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
63
+ exports.UPSTREAM_BRANCH = 'develop';
64
+ // Remote name used only for the duration of this codemod. Prefixed to avoid
65
+ // clashing with remotes the user may have (origin, upstream, etc.).
66
+ const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
67
+ const FILES_TO_CHECKOUT = [
68
+ 'src/analytics/analytics.ts',
69
+ 'Dockerfile',
70
+ 'Dockerfile.assets'
71
+ ];
72
+ // ─── Git helpers ─────────────────────────────────────────────────────────────
73
+ /**
74
+ * Runs a git command in the country config working directory.
75
+ *
76
+ * By default stderr is inherited so the user sees progress output from
77
+ * long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
78
+ * both stdout and stderr when you only care about the exit code.
79
+ */
80
+ function runGit(args, { silent = false } = {}) {
81
+ return (0, child_process_1.execFileSync)('git', args, {
82
+ cwd: process.cwd(),
83
+ encoding: 'utf8',
84
+ stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
85
+ });
86
+ }
87
+ /**
88
+ * Runs a git command and returns true on success, false on failure.
89
+ * Stderr/stdout are suppressed — use only when the exit code is the only
90
+ * signal you care about.
91
+ */
92
+ function tryGit(args) {
93
+ try {
94
+ runGit(args, { silent: true });
95
+ return true;
96
+ }
97
+ catch (_a) {
98
+ return false;
99
+ }
100
+ }
101
+ function assertIsGitRepo() {
102
+ if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
103
+ throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
104
+ }
105
+ }
106
+ // ─── Entry point ─────────────────────────────────────────────────────────────
107
+ function main() {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${exports.UPSTREAM_URL}@${exports.UPSTREAM_BRANCH}...\n`);
110
+ assertIsGitRepo();
111
+ // Best-effort cleanup of a stale temp remote from a previous aborted run.
112
+ tryGit(['remote', 'remove', TEMP_REMOTE]);
113
+ try {
114
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${exports.UPSTREAM_URL}`);
115
+ runGit(['remote', 'add', TEMP_REMOTE, exports.UPSTREAM_URL], { silent: true });
116
+ console.log(` Fetching ${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH} (depth 1)...`);
117
+ runGit(['fetch', '--depth=1', TEMP_REMOTE, exports.UPSTREAM_BRANCH]);
118
+ const ref = `${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH}`;
119
+ const missing = [];
120
+ let checkedOut = 0;
121
+ for (const file of FILES_TO_CHECKOUT) {
122
+ // `--` separates paths from refs and avoids ambiguity when a path
123
+ // happens to match a branch/tag name.
124
+ if (tryGit(['checkout', ref, '--', file])) {
125
+ console.log(` Checked out ${file} from ${ref}`);
126
+ checkedOut++;
127
+ }
128
+ else {
129
+ console.warn(` [warn] ${file} not found on ${ref} — skipping. Verify the path exists on that branch.`);
130
+ missing.push(file);
131
+ }
132
+ }
133
+ console.log(`\n Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`);
134
+ if (missing.length > 0) {
135
+ console.warn(` Missing on upstream branch: ${missing.join(', ')}`);
136
+ }
137
+ if (checkedOut > 0) {
138
+ console.log(` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map((f) => `'${f}'`).join(' ')}\n`);
139
+ }
140
+ }
141
+ finally {
142
+ if (tryGit(['remote', 'remove', TEMP_REMOTE])) {
143
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
144
+ }
145
+ }
146
+ });
147
+ }
@@ -0,0 +1,2 @@
1
+ export declare function main(): Promise<void>;
2
+ //# sourceMappingURL=convert-config-files-to-ts.d.ts.map
@@ -0,0 +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":"AAuuBA,wBAAsB,IAAI,kBAyPzB"}