@opencrvs/toolkit 2.1.0-rc.d7bd264 → 2.1.0-rc.d987aec

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 (107) hide show
  1. package/README.md +3 -12
  2. package/build.sh +9 -1
  3. package/create-countryconfig/index.js +412 -59
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +4 -1
  6. package/dist/application-config/index.js +266 -212
  7. package/dist/authentication/index.d.ts +67 -0
  8. package/dist/authentication/index.d.ts.map +1 -0
  9. package/dist/authentication/index.js +750 -0
  10. package/dist/cli.js +1786 -120
  11. package/dist/commons/api/router.d.ts +691 -76
  12. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  13. package/dist/commons/conditionals/validate.d.ts +15 -5
  14. package/dist/commons/events/ActionConfig.d.ts +0 -21
  15. package/dist/commons/events/ActionDocument.d.ts +4 -4
  16. package/dist/commons/events/ActionInput.d.ts +4 -4
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +18 -0
  18. package/dist/commons/events/AuditLog.d.ts +147 -0
  19. package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
  20. package/dist/commons/events/EventConfig.d.ts +3 -0
  21. package/dist/commons/events/EventDocument.d.ts +470 -2
  22. package/dist/commons/events/EventIndex.d.ts +2 -6
  23. package/dist/commons/events/EventMetadata.d.ts +1 -12
  24. package/dist/commons/events/EventStatus.d.ts +19 -0
  25. package/dist/commons/events/FieldConfig.d.ts +84 -53
  26. package/dist/commons/events/FieldTypeMapping.d.ts +15 -15
  27. package/dist/commons/events/FieldValue.d.ts +2 -2
  28. package/dist/commons/events/Flag.d.ts +0 -6
  29. package/dist/commons/events/PlainDate.d.ts +8 -0
  30. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  31. package/dist/commons/events/WorkqueueConfig.d.ts +5 -17
  32. package/dist/commons/events/event.d.ts +12 -0
  33. package/dist/commons/events/index.d.ts +1 -0
  34. package/dist/commons/events/locationPayloads.d.ts +95 -0
  35. package/dist/commons/events/locations.d.ts +169 -26
  36. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  37. package/dist/commons/events/test.utils.d.ts +25 -4
  38. package/dist/commons/events/utils.d.ts +13 -2
  39. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  40. package/dist/commons/notification/dispatch.d.ts +10 -0
  41. package/dist/commons/notification/index.d.ts +1 -0
  42. package/dist/conditionals/index.js +81 -59
  43. package/dist/csv.d.ts +25 -0
  44. package/dist/csv.d.ts.map +1 -0
  45. package/dist/csv.js +120 -0
  46. package/dist/environment/index.d.ts +1 -0
  47. package/dist/environment/index.d.ts.map +1 -1
  48. package/dist/environment/index.js +10 -0
  49. package/dist/environment/logger.d.ts +15 -3
  50. package/dist/environment/logger.d.ts.map +1 -1
  51. package/dist/environment/manage-users.js +1 -1
  52. package/dist/environment/paths.d.ts +7 -0
  53. package/dist/environment/paths.d.ts.map +1 -0
  54. package/dist/environment/paths.js +72 -0
  55. package/dist/environment/questions.d.ts.map +1 -1
  56. package/dist/environment/questions.js +20 -14
  57. package/dist/environment/setup-environment.js +28 -7
  58. package/dist/environment/templates.d.ts +0 -1
  59. package/dist/environment/templates.d.ts.map +1 -1
  60. package/dist/environment/templates.js +5 -9
  61. package/dist/environment/update-workflows.d.ts.map +1 -1
  62. package/dist/environment/update-workflows.js +17 -5
  63. package/dist/environment/upgrade.d.ts +2 -0
  64. package/dist/environment/upgrade.d.ts.map +1 -0
  65. package/dist/environment/upgrade.js +82 -0
  66. package/dist/environment/users.js +11 -13
  67. package/dist/events/index.js +2905 -2463
  68. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  69. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  70. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  71. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  72. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  73. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  74. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  75. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  76. package/dist/migrations/v2.1/add-translations.js +213 -0
  77. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  78. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  79. package/dist/migrations/v2.1/enable-telemetry.js +438 -0
  80. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  81. package/dist/migrations/v2.1/index.js +1058 -0
  82. package/dist/notification/index.js +1317 -1475
  83. package/dist/scopes/index.d.ts +104 -59
  84. package/dist/scopes/index.js +81 -59
  85. package/dist/telemetry/index.d.ts +45 -0
  86. package/dist/telemetry/index.d.ts.map +1 -0
  87. package/dist/telemetry/index.js +39 -0
  88. package/dist/templates/charts-values/dependencies/values.yaml +2 -0
  89. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
  90. package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
  91. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  92. package/dist/templates/inventory/inventory.template.yml +1 -3
  93. package/dist/translations/check.d.ts +21 -0
  94. package/dist/translations/check.d.ts.map +1 -0
  95. package/dist/translations/check.js +132 -0
  96. package/dist/verify/endpoints.d.ts +2 -0
  97. package/dist/verify/endpoints.d.ts.map +1 -0
  98. package/dist/verify/endpoints.js +345 -0
  99. package/opencrvs-toolkit-2.1.0-rc.d987aec.tgz +0 -0
  100. package/package.json +12 -6
  101. package/tsconfig.build.json +11 -0
  102. package/tsconfig.build.tsbuildinfo +1 -0
  103. package/tsconfig.json +3 -0
  104. package/dist/templates/inventory/production.example.yml +0 -77
  105. package/dist/templates/inventory/qa.example.yml +0 -48
  106. package/opencrvs-toolkit-2.1.0-rc.d7bd264.tgz +0 -0
  107. package/tsconfig.tsbuildinfo +0 -1
@@ -47,7 +47,7 @@ __export(conditionals_exports, {
47
47
  user: () => user
48
48
  });
49
49
  module.exports = __toCommonJS(conditionals_exports);
50
- var z12 = __toESM(require("zod/v4"));
50
+ var z13 = __toESM(require("zod/v4"));
51
51
 
52
52
  // ../commons/src/conditionals/conditionals.ts
53
53
  var objectHash = __toESM(require("object-hash"));
@@ -124,7 +124,7 @@ function todayDateTimeValueSerializer() {
124
124
  }
125
125
 
126
126
  // ../commons/src/scopes.ts
127
- var z10 = __toESM(require("zod/v4"));
127
+ var z11 = __toESM(require("zod/v4"));
128
128
  var qs = __toESM(require("qs"));
129
129
 
130
130
  // ../commons/src/uuid.ts
@@ -333,8 +333,7 @@ var InherentFlags = {
333
333
  *
334
334
  * We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
335
335
  */
336
- EDIT_IN_PROGRESS: "edit-in-progress",
337
- SEALED: "sealed"
336
+ EDIT_IN_PROGRESS: "edit-in-progress"
338
337
  };
339
338
  var actionFlagPattern;
340
339
  function getActionFlagPattern() {
@@ -384,12 +383,22 @@ var ActionFlagConfig = z9.object({
384
383
  description: "Add or remove operation applied to a flag when the parent action is accepted. Optionally gated by a conditional."
385
384
  });
386
385
 
386
+ // ../commons/src/events/EventStatus.ts
387
+ var z10 = __toESM(require("zod/v4"));
388
+ var EventStatus = z10.enum([
389
+ "CREATED",
390
+ "NOTIFIED",
391
+ "DECLARED",
392
+ "REGISTERED",
393
+ "ARCHIVED"
394
+ ]);
395
+
387
396
  // ../commons/src/scopes.ts
388
- var JurisdictionFilter = z10.enum(["administrativeArea", "location", "all"]).describe(
397
+ var JurisdictionFilter = z11.enum(["administrativeArea", "location", "all"]).describe(
389
398
  "Filters based on user jurisdiction relative to their office location in hierarchy."
390
399
  );
391
- var UserFilter = z10.enum(["user"]).describe("Filters based on the user. Limits to self.");
392
- var RecordScopeTypeV2 = z10.enum([
400
+ var UserFilter = z11.enum(["user"]).describe("Filters based on the user. Limits to self.");
401
+ var RecordScopeTypeV2 = z11.enum([
393
402
  "record.search",
394
403
  "record.create",
395
404
  "record.read",
@@ -407,14 +416,20 @@ var RecordScopeTypeV2 = z10.enum([
407
416
  "record.unassign-others",
408
417
  "record.custom-action"
409
418
  ]);
410
- var PlainScopeType = z10.enum([
419
+ var PlainScopeType = z11.enum([
411
420
  // Misc. system scopes
412
421
  "bypassratelimit",
413
422
  "record.reindex",
414
423
  "user.data-seeding",
415
424
  "integration.create",
425
+ // Reading an integration's audit log. Deliberately separate from
426
+ // 'integration.create' so read-only oversight can be granted on its own, and
427
+ // deliberately option-less: system clients have no office and no
428
+ // administrative area, so jurisdiction options would have nothing to bind to.
429
+ "integration.audit.read",
416
430
  "record.import",
417
431
  "config.update-all",
432
+ "location.edit",
418
433
  "attachment.upload",
419
434
  "profile.electronic-signature",
420
435
  "user.read-only-my-audit",
@@ -426,15 +441,21 @@ var PlainScopeType = z10.enum([
426
441
  "record.confirm-registration",
427
442
  "record.reject-registration"
428
443
  ]);
429
- var scopeByEvent = z10.preprocess(
444
+ var scopeByEvent = z11.preprocess(
430
445
  (val) => val === void 0 ? void 0 : [val].flat(),
431
- z10.array(z10.string()).optional()
446
+ z11.array(z11.string()).optional()
432
447
  ).describe("Event type, e.g. birth, death");
433
- var userRole = z10.preprocess(
448
+ var scopeByStatus = z11.preprocess(
434
449
  (val) => val === void 0 ? void 0 : [val].flat(),
435
- z10.array(z10.string()).optional()
450
+ z11.array(EventStatus).optional()
451
+ ).describe(
452
+ "Restricts the scope to records currently in one of these statuses."
453
+ );
454
+ var userRole = z11.preprocess(
455
+ (val) => val === void 0 ? void 0 : [val].flat(),
456
+ z11.array(z11.string()).optional()
436
457
  ).describe("User role, e.g. admin, field agent");
437
- var scopeOptionsPlaceEvent = z10.object({
458
+ var scopeOptionsPlaceEvent = z11.object({
438
459
  event: scopeByEvent,
439
460
  placeOfEvent: JurisdictionFilter.optional()
440
461
  }).describe("Options applicable to all record scopes.");
@@ -442,7 +463,8 @@ var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
442
463
  notifiedIn: JurisdictionFilter.optional(),
443
464
  notifiedBy: UserFilter.optional(),
444
465
  declaredIn: JurisdictionFilter.optional(),
445
- declaredBy: UserFilter.optional()
466
+ declaredBy: UserFilter.optional(),
467
+ status: scopeByStatus
446
468
  }).describe("Options applicable to actions that may take place after DECLARE");
447
469
  var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
448
470
  registeredIn: JurisdictionFilter.optional(),
@@ -452,31 +474,31 @@ var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
452
474
  "Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
453
475
  );
454
476
  var CustomActionScopeOptions = AllRecordScopeOptions.extend({
455
- customActionTypes: z10.preprocess(
477
+ customActionTypes: z11.preprocess(
456
478
  (val) => val === void 0 ? void 0 : [val].flat(),
457
- z10.array(z10.string()).optional()
479
+ z11.array(z11.string()).optional()
458
480
  ).describe("Allowed custom action types")
459
481
  });
460
- var AccessLevelOptions = z10.object({
482
+ var AccessLevelOptions = z11.object({
461
483
  accessLevel: JurisdictionFilter.optional()
462
484
  });
463
485
  var AllUserScopeOptions = AccessLevelOptions.extend({
464
486
  role: userRole.optional()
465
487
  });
466
- var WorkqueueOrDashboardOptions = z10.object({
467
- ids: z10.preprocess(
488
+ var WorkqueueOrDashboardOptions = z11.object({
489
+ ids: z11.preprocess(
468
490
  (val) => val === void 0 ? void 0 : [val].flat(),
469
- z10.array(z10.string())
491
+ z11.array(z11.string())
470
492
  ).describe("Must contain a list of workqueue or dashboard ids.")
471
493
  });
472
- var AllScopeOptions = z10.object({
494
+ var AllScopeOptions = z11.object({
473
495
  ...AllRecordScopeOptions.shape,
474
496
  ...AccessLevelOptions.shape,
475
497
  ...AllUserScopeOptions.shape,
476
498
  ...WorkqueueOrDashboardOptions.shape
477
499
  });
478
500
  var ScopeOptionKey = AllScopeOptions.keyof();
479
- var ResolvedScopeOptionsPlaceEvent = z10.object({
501
+ var ResolvedScopeOptionsPlaceEvent = z11.object({
480
502
  event: scopeByEvent,
481
503
  placeOfEvent: UUID.nullish()
482
504
  }).describe(
@@ -484,15 +506,15 @@ var ResolvedScopeOptionsPlaceEvent = z10.object({
484
506
  );
485
507
  var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
486
508
  notifiedIn: UUID.nullish(),
487
- notifiedBy: z10.string().optional(),
509
+ notifiedBy: z11.string().optional(),
488
510
  declaredIn: UUID.nullish(),
489
- declaredBy: z10.string().optional()
511
+ declaredBy: z11.string().optional()
490
512
  }).describe(
491
513
  "Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
492
514
  );
493
515
  var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
494
516
  registeredIn: UUID.nullish(),
495
- registeredBy: z10.string().optional(),
517
+ registeredBy: z11.string().optional(),
496
518
  flags: ContainsFlags.optional()
497
519
  }).describe(
498
520
  "Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
@@ -507,7 +529,6 @@ var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
507
529
  "record.reject",
508
530
  "record.archive",
509
531
  "record.unarchive",
510
- "record.review-duplicates",
511
532
  "record.register"
512
533
  ]);
513
534
  var ScopesWithFullOptions = RecordScopeTypeV2.extract([
@@ -515,41 +536,42 @@ var ScopesWithFullOptions = RecordScopeTypeV2.extract([
515
536
  "record.read",
516
537
  "record.request-correction",
517
538
  "record.correct",
518
- "record.unassign-others"
539
+ "record.unassign-others",
540
+ "record.review-duplicates"
519
541
  ]);
520
542
  var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
521
- templates: z10.preprocess(
543
+ templates: z11.preprocess(
522
544
  (val) => val === void 0 ? void 0 : [val].flat(),
523
- z10.array(z10.string()).optional()
545
+ z11.array(z11.string()).optional()
524
546
  ).describe(
525
547
  "Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
526
548
  )
527
549
  });
528
- var RecordScopeV2 = z10.discriminatedUnion("type", [
529
- z10.object({
550
+ var RecordScopeV2 = z11.discriminatedUnion("type", [
551
+ z11.object({
530
552
  type: ScopesWithPlaceEventOptions,
531
553
  options: scopeOptionsPlaceEvent.optional()
532
554
  }),
533
- z10.object({
555
+ z11.object({
534
556
  type: ScopesWithDeclaredOptions,
535
557
  options: scopeOptionsDeclaredOrNotified.optional()
536
558
  }),
537
- z10.object({
559
+ z11.object({
538
560
  type: ScopesWithFullOptions,
539
561
  options: AllRecordScopeOptions.optional()
540
562
  }),
541
- z10.object({
542
- type: z10.literal("record.custom-action"),
563
+ z11.object({
564
+ type: z11.literal("record.custom-action"),
543
565
  options: CustomActionScopeOptions.optional()
544
566
  }),
545
- z10.object({
546
- type: z10.literal("record.print-certified-copies"),
567
+ z11.object({
568
+ type: z11.literal("record.print-certified-copies"),
547
569
  options: ScopeOptionsPrintCertifiedCopies.optional()
548
570
  })
549
571
  ]).describe(
550
572
  "Scopes used to check user's permission to perform actions on a record."
551
573
  );
552
- var SystemScopeType = z10.enum([
574
+ var SystemScopeType = z11.enum([
553
575
  "organisation.read-locations",
554
576
  "user.read",
555
577
  "user.create",
@@ -563,61 +585,61 @@ var UserScopeType = SystemScopeType.extract([
563
585
  "user.search"
564
586
  ]);
565
587
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
566
- var UserScopeV2 = z10.discriminatedUnion("type", [
567
- z10.object({
588
+ var UserScopeV2 = z11.discriminatedUnion("type", [
589
+ z11.object({
568
590
  type: ScopesWithRoleOption,
569
591
  options: AllUserScopeOptions.optional()
570
592
  }),
571
- z10.object({
593
+ z11.object({
572
594
  type: UserScopeType.extract(["user.read", "user.search"]),
573
595
  options: AccessLevelOptions.optional()
574
596
  })
575
597
  ]);
576
- var ResolvedRecordScopeV2 = z10.discriminatedUnion("type", [
577
- z10.object({
598
+ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
599
+ z11.object({
578
600
  type: ScopesWithPlaceEventOptions,
579
601
  options: ResolvedScopeOptionsPlaceEvent.optional()
580
602
  }),
581
- z10.object({
603
+ z11.object({
582
604
  type: ScopesWithDeclaredOptions,
583
605
  options: ResolvedScopeOptionsDeclared.optional()
584
606
  }),
585
- z10.object({
607
+ z11.object({
586
608
  type: ScopesWithFullOptions,
587
609
  options: ResolvedScopeOptionsFull.optional()
588
610
  }),
589
- z10.object({
590
- type: z10.literal("record.print-certified-copies"),
611
+ z11.object({
612
+ type: z11.literal("record.print-certified-copies"),
591
613
  options: ResolvedScopeOptionsFull.extend({
592
- templates: z10.array(z10.string()).optional()
614
+ templates: z11.array(z11.string()).optional()
593
615
  }).optional()
594
616
  })
595
617
  ]).describe("Resolved scope with location/user IDs instead of filters.");
596
- var Scope2 = z10.discriminatedUnion("type", [
597
- z10.object({ type: PlainScopeType }),
618
+ var Scope2 = z11.discriminatedUnion("type", [
619
+ z11.object({ type: PlainScopeType }),
598
620
  ...RecordScopeV2.options,
599
621
  ...UserScopeV2.options,
600
- z10.object({
601
- type: z10.literal("organisation.read-locations"),
622
+ z11.object({
623
+ type: z11.literal("organisation.read-locations"),
602
624
  options: AccessLevelOptions.optional()
603
625
  }),
604
- z10.object({
605
- type: z10.literal("workqueue"),
626
+ z11.object({
627
+ type: z11.literal("workqueue"),
606
628
  options: WorkqueueOrDashboardOptions
607
629
  }),
608
- z10.object({
609
- type: z10.literal("dashboard.view"),
630
+ z11.object({
631
+ type: z11.literal("dashboard.view"),
610
632
  options: WorkqueueOrDashboardOptions
611
633
  })
612
634
  ]);
613
- var ScopeType2 = z10.enum([
635
+ var ScopeType2 = z11.enum([
614
636
  ...SystemScopeType.options,
615
637
  ...RecordScopeTypeV2.options,
616
638
  ...PlainScopeType.options,
617
639
  "workqueue",
618
640
  "dashboard.view"
619
641
  ]);
620
- var EncodedScope2 = z10.string().brand("EncodedScope");
642
+ var EncodedScope2 = z11.string().brand("EncodedScope");
621
643
  var DEFAULT_SCOPE_OPTIONS = {
622
644
  placeOfEvent: JurisdictionFilter.enum.all,
623
645
  accessLevel: JurisdictionFilter.enum.all,
@@ -1312,4 +1334,4 @@ function createFieldConditionals(fieldId) {
1312
1334
  }
1313
1335
 
1314
1336
  // src/conditionals/index.ts
1315
- z12.globalRegistry.clear();
1337
+ z13.globalRegistry.clear();
package/dist/csv.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export type CsvFile = {
2
+ header: string;
3
+ body: string[];
4
+ /** Preserved so a file written on Windows stays written on Windows. */
5
+ newline: string;
6
+ trailingNewline: boolean;
7
+ };
8
+ export declare function parseCsvLine(line: string): string[];
9
+ export declare function toCsvLine(values: string[]): string;
10
+ /**
11
+ * The id of a row, which is its first column. Translation ids never contain a
12
+ * comma or a quote, so this does not need the parser.
13
+ */
14
+ export declare function idOf(line: string): string;
15
+ export declare function readCsvFile(path: string): CsvFile | undefined;
16
+ export declare function writeCsvFile(path: string, file: CsvFile): void;
17
+ /**
18
+ * Adds the rows the file does not already have an id for, in place. Rows go in
19
+ * sorted position when the file is sorted by id, and at the end when it is not,
20
+ * so a country config that keeps its own order keeps it.
21
+ *
22
+ * Returns the ids that were added.
23
+ */
24
+ export declare function addRows(file: CsvFile, rows: string[]): string[];
25
+ //# sourceMappingURL=csv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiCnD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAMlD;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKzC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAe7D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAM9D;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA4B/D"}
package/dist/csv.js ADDED
@@ -0,0 +1,120 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.parseCsvLine = parseCsvLine;
14
+ exports.toCsvLine = toCsvLine;
15
+ exports.idOf = idOf;
16
+ exports.readCsvFile = readCsvFile;
17
+ exports.writeCsvFile = writeCsvFile;
18
+ exports.addRows = addRows;
19
+ /**
20
+ * Just enough CSV for the translation files codemods edit. They are read and
21
+ * written a line at a time rather than through a parser, so that adding two
22
+ * rows to a file of sixteen hundred produces a diff of two lines instead of a
23
+ * re-quoted rewrite of the whole thing.
24
+ *
25
+ * Rows spanning multiple lines are not supported, and none of the translation
26
+ * files contain any.
27
+ */
28
+ const fs_1 = require("fs");
29
+ function parseCsvLine(line) {
30
+ const values = [];
31
+ let value = '';
32
+ let quoted = false;
33
+ for (let index = 0; index < line.length; index++) {
34
+ const character = line[index];
35
+ if (quoted) {
36
+ if (character !== '"') {
37
+ value += character;
38
+ }
39
+ else if (line[index + 1] === '"') {
40
+ value += '"';
41
+ index++;
42
+ }
43
+ else {
44
+ quoted = false;
45
+ }
46
+ continue;
47
+ }
48
+ if (character === '"') {
49
+ quoted = true;
50
+ }
51
+ else if (character === ',') {
52
+ values.push(value);
53
+ value = '';
54
+ }
55
+ else {
56
+ value += character;
57
+ }
58
+ }
59
+ values.push(value);
60
+ return values;
61
+ }
62
+ function toCsvLine(values) {
63
+ return values
64
+ .map((value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value)
65
+ .join(',');
66
+ }
67
+ /**
68
+ * The id of a row, which is its first column. Translation ids never contain a
69
+ * comma or a quote, so this does not need the parser.
70
+ */
71
+ function idOf(line) {
72
+ const comma = line.indexOf(',');
73
+ // No comma: `slice(0, -1)` would eat the last character.
74
+ return comma === -1 ? line : line.slice(0, comma);
75
+ }
76
+ function readCsvFile(path) {
77
+ if (!(0, fs_1.existsSync)(path)) {
78
+ return undefined;
79
+ }
80
+ const contents = (0, fs_1.readFileSync)(path, 'utf8');
81
+ const newline = contents.includes('\r\n') ? '\r\n' : '\n';
82
+ const trailingNewline = /\r?\n$/.test(contents);
83
+ const lines = contents.replace(/\r?\n$/, '').split(/\r?\n/);
84
+ // Trailing blank line leaves an empty entry. It sorts before every id, so
85
+ // the file reads as unsorted.
86
+ const body = lines.slice(1).filter((line) => line !== '');
87
+ return { header: lines[0], body, newline, trailingNewline };
88
+ }
89
+ function writeCsvFile(path, file) {
90
+ (0, fs_1.writeFileSync)(path, [file.header, ...file.body].join(file.newline) +
91
+ (file.trailingNewline ? file.newline : ''));
92
+ }
93
+ /**
94
+ * Adds the rows the file does not already have an id for, in place. Rows go in
95
+ * sorted position when the file is sorted by id, and at the end when it is not,
96
+ * so a country config that keeps its own order keeps it.
97
+ *
98
+ * Returns the ids that were added.
99
+ */
100
+ function addRows(file, rows) {
101
+ const isSorted = file.body.every((line, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line));
102
+ const added = [];
103
+ for (const row of rows) {
104
+ const id = idOf(row);
105
+ if (file.body.some((line) => idOf(line) === id)) {
106
+ continue;
107
+ }
108
+ const insertAt = isSorted
109
+ ? file.body.findIndex((line) => idOf(line) > id)
110
+ : -1;
111
+ if (insertAt === -1) {
112
+ file.body.push(row);
113
+ }
114
+ else {
115
+ file.body.splice(insertAt, 0, row);
116
+ }
117
+ added.push(id);
118
+ }
119
+ return added;
120
+ }
@@ -1,4 +1,5 @@
1
1
  export declare function runEnvironmentInit(): Promise<void>;
2
+ export declare function runEnvironmentUpgrade(): Promise<void>;
2
3
  export declare function runEnvironmentUpdateWorkflows(): Promise<void>;
3
4
  export declare function runEnvironmentUsers(): Promise<void>;
4
5
  export declare function runEnvironmentSwarmToK8s(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/environment/index.ts"],"names":[],"mappings":"AAwCA,wBAAsB,kBAAkB,kBAGvC;AAED,wBAAsB,6BAA6B,kBAIlD;AAED,wBAAsB,mBAAmB,kBAIxC;AAED,wBAAsB,wBAAwB,kBAG7C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/environment/index.ts"],"names":[],"mappings":"AAyCA,wBAAsB,kBAAkB,kBAIvC;AAED,wBAAsB,qBAAqB,kBAI1C;AAED,wBAAsB,6BAA6B,kBAIlD;AAED,wBAAsB,mBAAmB,kBAIxC;AAED,wBAAsB,wBAAwB,kBAG7C"}
@@ -20,11 +20,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.runEnvironmentInit = runEnvironmentInit;
23
+ exports.runEnvironmentUpgrade = runEnvironmentUpgrade;
23
24
  exports.runEnvironmentUpdateWorkflows = runEnvironmentUpdateWorkflows;
24
25
  exports.runEnvironmentUsers = runEnvironmentUsers;
25
26
  exports.runEnvironmentSwarmToK8s = runEnvironmentSwarmToK8s;
26
27
  const fs_1 = require("fs");
27
28
  const path_1 = require("path");
29
+ const paths_1 = require("./paths");
28
30
  const REQUIRED_REPOSITORY_DIRECTORIES = [
29
31
  '.github/workflows',
30
32
  'environments',
@@ -46,9 +48,17 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
46
48
  function runEnvironmentInit() {
47
49
  return __awaiter(this, void 0, void 0, function* () {
48
50
  validateRepositoryStructure();
51
+ (0, paths_1.assertNoOldInventoryLayout)();
49
52
  yield import('./setup-environment.js');
50
53
  });
51
54
  }
55
+ function runEnvironmentUpgrade() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ validateRepositoryStructure();
58
+ const { upgradeEnvironmentLayout } = yield import('./upgrade.js');
59
+ yield upgradeEnvironmentLayout();
60
+ });
61
+ }
52
62
  function runEnvironmentUpdateWorkflows() {
53
63
  return __awaiter(this, void 0, void 0, function* () {
54
64
  validateRepositoryStructure();
@@ -1,6 +1,18 @@
1
- export declare const log: (message?: any, ...optionalParams: any[]) => void;
2
- export declare const warn: (message?: any, ...optionalParams: any[]) => void;
1
+ export declare const log: {
2
+ (message?: any, ...optionalParams: any[]): void;
3
+ (message?: any, ...optionalParams: any[]): void;
4
+ (message?: any, ...optionalParams: any[]): void;
5
+ };
6
+ export declare const warn: {
7
+ (message?: any, ...optionalParams: any[]): void;
8
+ (message?: any, ...optionalParams: any[]): void;
9
+ (message?: any, ...optionalParams: any[]): void;
10
+ };
3
11
  export declare const success: (...args: any[]) => void;
4
- export declare const info: (message?: any, ...optionalParams: any[]) => void;
12
+ export declare const info: {
13
+ (message?: any, ...optionalParams: any[]): void;
14
+ (message?: any, ...optionalParams: any[]): void;
15
+ (message?: any, ...optionalParams: any[]): void;
16
+ };
5
17
  export declare const error: (...args: any[]) => void;
6
18
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/environment/logger.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,GAAG,mDAAc,CAAA;AAC9B,eAAO,MAAM,IAAI,mDAAe,CAAA;AAChC,eAAO,MAAM,OAAO,YAAa,GAAG,EAAE,SACI,CAAA;AAC1C,eAAO,MAAM,IAAI,mDAAe,CAAA;AAChC,eAAO,MAAM,KAAK,YAAa,GAAG,EAAE,SAA2C,CAAA"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/environment/logger.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,GAAG;;;;CAAc,CAAA;AAC9B,eAAO,MAAM,IAAI;;;;CAAe,CAAA;AAChC,eAAO,MAAM,OAAO,YAAa,GAAG,EAAE,SACI,CAAA;AAC1C,eAAO,MAAM,IAAI;;;;CAAe,CAAA;AAChC,eAAO,MAAM,KAAK,YAAa,GAAG,EAAE,SAA2C,CAAA"}
@@ -95,7 +95,7 @@ function updateInventoryFile(filePath, users) {
95
95
  function parseInventoryFile(filePath) {
96
96
  try {
97
97
  const data = (0, utils_1.readYamlFile)(filePath);
98
- return (0, templates_1.getUsers)(data);
98
+ return (0, templates_1.extractAndModifyUsers)(data);
99
99
  }
100
100
  catch (_a) {
101
101
  return [];
@@ -0,0 +1,7 @@
1
+ export declare const OLD_INVENTORY_DIR: string;
2
+ export declare const INVENTORY_FILE_NAME = "inventory.yml";
3
+ export declare function getEnvironmentInventoryPath(environment: string): string;
4
+ export declare function findOldInventoryFiles(): string[];
5
+ export declare function getEnvironmentNameFromOldInventoryPath(filePath: string): string;
6
+ export declare function assertNoOldInventoryLayout(): void;
7
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/environment/paths.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,iBAAiB,QAI7B,CAAA;AAED,eAAO,MAAM,mBAAmB,kBAAkB,CAAA;AAElD,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,UAE9D;AAED,wBAAgB,qBAAqB,aAEpC;AAED,wBAAgB,sCAAsC,CAAC,QAAQ,EAAE,MAAM,UAEtE;AAED,wBAAgB,0BAA0B,SAWzC"}
@@ -0,0 +1,72 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.INVENTORY_FILE_NAME = exports.OLD_INVENTORY_DIR = void 0;
47
+ exports.getEnvironmentInventoryPath = getEnvironmentInventoryPath;
48
+ exports.findOldInventoryFiles = findOldInventoryFiles;
49
+ exports.getEnvironmentNameFromOldInventoryPath = getEnvironmentNameFromOldInventoryPath;
50
+ exports.assertNoOldInventoryLayout = assertNoOldInventoryLayout;
51
+ const path_1 = require("path");
52
+ const glob = __importStar(require("glob"));
53
+ exports.OLD_INVENTORY_DIR = (0, path_1.join)('infrastructure', 'server-setup', 'inventory');
54
+ exports.INVENTORY_FILE_NAME = 'inventory.yml';
55
+ function getEnvironmentInventoryPath(environment) {
56
+ return (0, path_1.join)('environments', environment, exports.INVENTORY_FILE_NAME);
57
+ }
58
+ function findOldInventoryFiles() {
59
+ return glob.sync((0, path_1.join)(exports.OLD_INVENTORY_DIR, '*.yml')).sort();
60
+ }
61
+ function getEnvironmentNameFromOldInventoryPath(filePath) {
62
+ return (0, path_1.basename)(filePath, '.yml');
63
+ }
64
+ function assertNoOldInventoryLayout() {
65
+ if (findOldInventoryFiles().length === 0) {
66
+ return;
67
+ }
68
+ throw new Error([
69
+ `Old inventory layout detected at ${exports.OLD_INVENTORY_DIR}.`,
70
+ 'Please run `yarn environment:upgrade` before running `yarn environment:init`.'
71
+ ].join(' '));
72
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../../src/environment/questions.ts"],"names":[],"mappings":"AAeA,QAAA,MAAM,QAAQ,UAAW,MAAM,GAAG,MAAM,kCAC4B,CAAA;AAepE,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAgBnD;AAED,eAAO,MAAM,kBAAkB;;UAGrB,MAAM;;eAED,QAAQ;;;;WAIZ,YAAY;GAiCtB,CAAA;AAED,eAAO,MAAM,eAAe;;UAGlB,MAAM;;;;WAIL,YAAY;GAUtB,CAAA;AACD,eAAO,MAAM,oBAAoB;;UAGvB,MAAM;;;eAGD,UAAU;;WAEd,YAAY;;;;;UAIb,QAAQ;;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