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

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 (52) hide show
  1. package/README.md +1 -0
  2. package/dist/application-config/index.js +30 -9
  3. package/dist/cli.js +174 -58
  4. package/dist/commons/api/router.d.ts +269 -11
  5. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  6. package/dist/commons/conditionals/validate.d.ts +9 -3
  7. package/dist/commons/events/ActionConfig.d.ts +0 -21
  8. package/dist/commons/events/AdvancedSearchConfig.d.ts +6 -0
  9. package/dist/commons/events/AuditLog.d.ts +147 -0
  10. package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
  11. package/dist/commons/events/EventConfig.d.ts +3 -0
  12. package/dist/commons/events/EventIndex.d.ts +2 -6
  13. package/dist/commons/events/EventMetadata.d.ts +0 -1
  14. package/dist/commons/events/FieldConfig.d.ts +65 -53
  15. package/dist/commons/events/FieldValue.d.ts +2 -2
  16. package/dist/commons/events/Flag.d.ts +0 -6
  17. package/dist/commons/events/PlainDate.d.ts +8 -0
  18. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  19. package/dist/commons/events/WorkqueueConfig.d.ts +5 -17
  20. package/dist/commons/events/event.d.ts +12 -0
  21. package/dist/commons/events/index.d.ts +1 -0
  22. package/dist/commons/events/locationPayloads.d.ts +95 -0
  23. package/dist/commons/events/locations.d.ts +106 -16
  24. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  25. package/dist/conditionals/index.js +2 -2
  26. package/dist/environment/index.d.ts +1 -0
  27. package/dist/environment/index.d.ts.map +1 -1
  28. package/dist/environment/index.js +10 -0
  29. package/dist/environment/logger.d.ts +12 -3
  30. package/dist/environment/logger.d.ts.map +1 -1
  31. package/dist/environment/paths.d.ts +7 -0
  32. package/dist/environment/paths.d.ts.map +1 -0
  33. package/dist/environment/paths.js +72 -0
  34. package/dist/environment/setup-environment.js +2 -1
  35. package/dist/environment/templates.d.ts.map +1 -1
  36. package/dist/environment/templates.js +2 -1
  37. package/dist/environment/update-workflows.d.ts.map +1 -1
  38. package/dist/environment/update-workflows.js +17 -5
  39. package/dist/environment/upgrade.d.ts +2 -0
  40. package/dist/environment/upgrade.d.ts.map +1 -0
  41. package/dist/environment/upgrade.js +82 -0
  42. package/dist/environment/users.js +11 -13
  43. package/dist/events/index.js +502 -211
  44. package/dist/notification/index.js +529 -262
  45. package/dist/scopes/index.d.ts +28 -53
  46. package/dist/scopes/index.js +2 -2
  47. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
  48. package/dist/templates/charts-values/opentelemetry/values.yaml +73 -0
  49. package/opencrvs-toolkit-2.1.0-rc.d876831.tgz +0 -0
  50. package/package.json +5 -4
  51. package/tsconfig.tsbuildinfo +1 -1
  52. package/opencrvs-toolkit-2.1.0-rc.d7bd264.tgz +0 -0
@@ -1,5 +1,6 @@
1
1
  import { UUID } from '../uuid';
2
2
  import * as z from 'zod/v4';
3
+ import { PlainDate } from './PlainDate';
3
4
  import { EventIndex } from './EventIndex';
4
5
  import { ActionCreationMetadata, RegistrationCreationMetadata } from './EventMetadata';
5
6
  import { RecordScopeV2, UserScopeV2 } from '../scopes';
@@ -75,6 +76,61 @@ export declare const Location: z.ZodObject<{
75
76
  }, z.core.$strip>>;
76
77
  }, z.core.$strip>;
77
78
  export type Location = z.infer<typeof Location>;
79
+ /**
80
+ * TEMPORARY — client-side view of {@link AdministrativeArea} with the
81
+ * server-flattened `name`, `status` and `externalId` removed, leaving exactly
82
+ * identity + versions. Every name/status read is thereby forced through the
83
+ * anchored resolution utilities ({@link resolveVersion}, {@link resolvePath})
84
+ * at compile time. Delete this type when the contract migration removes the
85
+ * flat fields from the server schema, at which point the wire type itself
86
+ * becomes identity + versions.
87
+ */
88
+ export declare const ClientAdministrativeArea: z.ZodObject<{
89
+ id: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
90
+ parentId: z.ZodNullable<z.core.$ZodBranded<z.ZodUUID, "UUID", "out">>;
91
+ versions: z.ZodArray<z.ZodObject<{
92
+ versionId: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
93
+ effectiveFrom: z.ZodISODate;
94
+ name: z.ZodString;
95
+ externalId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
96
+ status: z.ZodEnum<{
97
+ active: "active";
98
+ inactive: "inactive";
99
+ }>;
100
+ }, z.core.$strip>>;
101
+ }, z.core.$strip>;
102
+ export type ClientAdministrativeArea = z.infer<typeof ClientAdministrativeArea>;
103
+ /**
104
+ * TEMPORARY — client-side view of {@link Location} with the server-flattened
105
+ * `name`, `status` and `externalId` removed, leaving exactly identity +
106
+ * versions. See {@link ClientAdministrativeArea} for the full rationale and
107
+ * deletion condition.
108
+ */
109
+ export declare const ClientLocation: z.ZodObject<{
110
+ id: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
111
+ administrativeAreaId: z.ZodNullable<z.core.$ZodBranded<z.ZodUUID, "UUID", "out">>;
112
+ locationType: z.ZodNullable<z.ZodString>;
113
+ versions: z.ZodArray<z.ZodObject<{
114
+ versionId: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
115
+ effectiveFrom: z.ZodISODate;
116
+ name: z.ZodString;
117
+ externalId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
118
+ status: z.ZodEnum<{
119
+ active: "active";
120
+ inactive: "inactive";
121
+ }>;
122
+ }, z.core.$strip>>;
123
+ }, z.core.$strip>;
124
+ export type ClientLocation = z.infer<typeof ClientLocation>;
125
+ /**
126
+ * Strips the server-flattened fields from a location as it enters the
127
+ * client's cached maps. The wire format keeps the flat fields for
128
+ * compatibility; the cache must not, or devices would keep rendering names
129
+ * flattened before a future-dated version takes effect.
130
+ */
131
+ export declare function toClientLocation(location: Location): ClientLocation;
132
+ /** See {@link toClientLocation}. */
133
+ export declare function toClientAdministrativeArea(area: AdministrativeArea): ClientAdministrativeArea;
78
134
  /**
79
135
  * Input payload for the locations `set` mutation. Carries only the seedable
80
136
  * identity and hierarchy fields — version history is managed by the server.
@@ -111,6 +167,13 @@ export type SetAdministrativeAreaPayload = z.infer<typeof SetAdministrativeAreaP
111
167
  export declare function resolveVersion<T extends {
112
168
  effectiveFrom: string;
113
169
  }>(versions: T[], anchor: string): T;
170
+ /**
171
+ * Whether the entity holds the given externalId with active status at the
172
+ * anchor date or at any point after it. Used for point-in-time uniqueness of
173
+ * external codes: a new holder starting at `anchor` collides when an existing
174
+ * holder is (or is scheduled to be) active with the code from then on.
175
+ */
176
+ export declare function hasActiveExternalIdOnOrAfter(versions: LocationVersion[], externalId: string, anchor: string): boolean;
114
177
  type WrapArrayPreserveNullish<V> = V extends readonly any[] ? V : NonNullable<V>[] | Extract<V, null | undefined>;
115
178
  /**
116
179
  * For type T, convert fields K to arrays. If field is string, convert to string[].
@@ -157,20 +220,10 @@ export declare function canAccessOtherUserWithScopes({ scopes, userToAccess, use
157
220
  * One of the scopes must allow access for the event to be accessible.
158
221
  */
159
222
  export declare function userCanAccessEventWithScopes(event: Partial<EventIndexWithAdministrativeHierarchy>, scopes: RecordScopeV2[], user: UserContext | SystemContext, customActionType?: string): boolean;
160
- export declare function getAdministrativeAreaHierarchy(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, AdministrativeArea>): {
161
- id: string & z.$brand<"UUID">;
162
- name: string;
163
- externalId?: string | null | undefined;
164
- parentId: (string & z.$brand<"UUID">) | null;
165
- status: "active" | "inactive";
166
- versions: {
167
- versionId: string & z.$brand<"UUID">;
168
- effectiveFrom: string;
169
- name: string;
170
- externalId?: string | null | undefined;
171
- status: "active" | "inactive";
172
- }[];
173
- }[];
223
+ export declare function getAdministrativeAreaHierarchy<A extends {
224
+ id: UUID;
225
+ parentId: UUID | null;
226
+ }>(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, A>): A[];
174
227
  /**
175
228
  * Resolves a location or administrative area UUID into a root-first hierarchy of UUIDs.
176
229
  *
@@ -182,8 +235,45 @@ export declare function getAdministrativeAreaHierarchy(administrativeAreaId: str
182
235
  * so the result is reversed to match the root-first convention used by the server.
183
236
  */
184
237
  export declare function getLocationHierarchy(selectedId: UUID, context: {
185
- administrativeAreas: Map<UUID, AdministrativeArea>;
186
- locations: Map<UUID, Location>;
238
+ administrativeAreas: Map<UUID, {
239
+ id: UUID;
240
+ parentId: UUID | null;
241
+ }>;
242
+ locations: Map<UUID, {
243
+ id: UUID;
244
+ administrativeAreaId: UUID | null;
245
+ }>;
187
246
  }): UUID[];
247
+ /**
248
+ * A node of an anchored hierarchy path: the identity id plus the name and
249
+ * status in effect at the anchor date.
250
+ */
251
+ export type ResolvedPathNode = {
252
+ id: UUID;
253
+ name: string;
254
+ status: LocationStatus;
255
+ };
256
+ /**
257
+ * Resolves a location or administrative area id into its root-first
258
+ * hierarchy path — leaf included — with every node's name and status
259
+ * resolved at the anchor date.
260
+ *
261
+ * The parent chain is identity-level and fixed for life, so the chain is
262
+ * constant and only each node's name/status varies with the anchor. Status is
263
+ * returned for callers that filter on it; an inactive node still resolves to
264
+ * its name. Returns an empty array for an unknown id.
265
+ */
266
+ export declare function resolvePath(locationId: UUID, anchor: PlainDate, context: {
267
+ administrativeAreas: Map<UUID, {
268
+ id: UUID;
269
+ parentId: UUID | null;
270
+ versions: LocationVersion[];
271
+ }>;
272
+ locations: Map<UUID, {
273
+ id: UUID;
274
+ administrativeAreaId: UUID | null;
275
+ versions: LocationVersion[];
276
+ }>;
277
+ }): ResolvedPathNode[];
188
278
  export {};
189
279
  //# sourceMappingURL=locations.d.ts.map
@@ -30,4 +30,34 @@ export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: Map<string & impo
30
30
  status: "active" | "inactive";
31
31
  }[];
32
32
  }>;
33
+ /**
34
+ * Stripped view of {@link V2_DEFAULT_MOCK_LOCATIONS_MAP} matching what the
35
+ * client's cached location map actually holds at runtime (identity +
36
+ * versions only). Use this — not the wire-format map above — wherever a test
37
+ * stands in for `useLocations().getLocations.useSuspenseQuery()`.
38
+ */
39
+ export declare const V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP: Map<string & import("zod").$brand<"UUID">, {
40
+ id: string & import("zod").$brand<"UUID">;
41
+ administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
42
+ locationType: string | null;
43
+ versions: {
44
+ versionId: string & import("zod").$brand<"UUID">;
45
+ effectiveFrom: string;
46
+ name: string;
47
+ externalId?: string | null | undefined;
48
+ status: "active" | "inactive";
49
+ }[];
50
+ }>;
51
+ /** See {@link V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP}. */
52
+ export declare const V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP: Map<string & import("zod").$brand<"UUID">, {
53
+ id: string & import("zod").$brand<"UUID">;
54
+ parentId: (string & import("zod").$brand<"UUID">) | null;
55
+ versions: {
56
+ versionId: string & import("zod").$brand<"UUID">;
57
+ effectiveFrom: string;
58
+ name: string;
59
+ externalId?: string | null | undefined;
60
+ status: "active" | "inactive";
61
+ }[];
62
+ }>;
33
63
  //# sourceMappingURL=mocks.test.utils.d.ts.map
@@ -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() {
@@ -415,6 +414,7 @@ var PlainScopeType = z10.enum([
415
414
  "integration.create",
416
415
  "record.import",
417
416
  "config.update-all",
417
+ "location.edit",
418
418
  "attachment.upload",
419
419
  "profile.electronic-signature",
420
420
  "user.read-only-my-audit",
@@ -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,15 @@
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
+ };
5
+ export declare const warn: {
6
+ (message?: any, ...optionalParams: any[]): void;
7
+ (message?: any, ...optionalParams: any[]): void;
8
+ };
3
9
  export declare const success: (...args: any[]) => void;
4
- export declare const info: (message?: any, ...optionalParams: any[]) => void;
10
+ export declare const info: {
11
+ (message?: any, ...optionalParams: any[]): void;
12
+ (message?: any, ...optionalParams: any[]): void;
13
+ };
5
14
  export declare const error: (...args: any[]) => void;
6
15
  //# 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"}
@@ -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
+ }
@@ -59,6 +59,7 @@ const questions_1 = require("./questions");
59
59
  const editor_questions_1 = require("./editor-questions");
60
60
  const questions_helper_1 = require("./questions-helper");
61
61
  const manage_users_1 = require("./manage-users");
62
+ const paths_1 = require("./paths");
62
63
  function questionToPrompt(_a) {
63
64
  var { valueType, valueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
64
65
  return promptOptions;
@@ -271,7 +272,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
271
272
  ? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim())
272
273
  : [];
273
274
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('SSH Users'), '\n');
274
- const users = yield (0, manage_users_1.manageUsers)(`infrastructure/server-setup/inventory/${environment}.yml`);
275
+ const users = yield (0, manage_users_1.manageUsers)((0, paths_1.getEnvironmentInventoryPath)(environment));
275
276
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Traefik SSL Certificate'), '\n');
276
277
  const sslCertExists = (0, utils_1.findExistingValue)('SSL_CRT', 'SECRET', 'ENVIRONMENT', existingValues);
277
278
  let ssl_answers = [];
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AAsBA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAKvC;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAWpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QA0CzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QA4BzE"}
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AAuBA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAKvC;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAWpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QA0CzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAsBzE"}
@@ -34,6 +34,7 @@ exports.generateInventory = generateInventory;
34
34
  const fs_1 = __importDefault(require("fs"));
35
35
  const path_1 = __importDefault(require("path"));
36
36
  const logger_1 = require("./logger");
37
+ const paths_1 = require("./paths");
37
38
  const handlebars_1 = __importDefault(require("handlebars"));
38
39
  // Register a helper to increment numbers
39
40
  handlebars_1.default.registerHelper('data_label_idx', function (value) {
@@ -149,7 +150,7 @@ function copyChartsValues(env, values) {
149
150
  function generateInventory(env, values) {
150
151
  // Template and output paths
151
152
  const templatePath = path_1.default.join(__dirname, 'templates', 'inventory', 'inventory.template.yml');
152
- const outputPath = path_1.default.join(process.cwd(), 'infrastructure', 'server-setup', 'inventory', `${env}.yml`);
153
+ const outputPath = path_1.default.resolve(process.cwd(), (0, paths_1.getEnvironmentInventoryPath)(env));
153
154
  const templateFile = fs_1.default.readFileSync(templatePath, 'utf-8');
154
155
  const template = handlebars_1.default.compile(templateFile);
155
156
  values['single_node'] =
@@ -1 +1 @@
1
- {"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AAgHA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhE"}
1
+ {"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AA+HA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhE"}
@@ -60,12 +60,21 @@ const path_1 = require("path");
60
60
  const glob = __importStar(require("glob"));
61
61
  const yaml = __importStar(require("js-yaml"));
62
62
  const logger_1 = require("./logger");
63
+ const paths_1 = require("./paths");
64
+ function isDirectory(path) {
65
+ try {
66
+ return (0, fs_1.statSync)(path).isDirectory();
67
+ }
68
+ catch (_a) {
69
+ return false;
70
+ }
71
+ }
63
72
  function extractInfrastructureNames() {
64
73
  return __awaiter(this, void 0, void 0, function* () {
65
- const files = glob.sync('infrastructure/server-setup/inventory/*.yml');
66
- const infraEnvironments = files.map((file) => (0, path_1.basename)(file, '.yml'));
74
+ const files = glob.sync((0, path_1.join)('environments', '*', paths_1.INVENTORY_FILE_NAME));
75
+ const infraEnvironments = files.map((file) => (0, path_1.basename)((0, path_1.dirname)(file)));
67
76
  if (infraEnvironments.length === 0) {
68
- console.log('⚠️ Warning: No environment directories found in infrastructure/server-setup/inventory/');
77
+ console.log(`⚠️ Warning: No environment inventory files found at environments/*/${paths_1.INVENTORY_FILE_NAME}`);
69
78
  return [];
70
79
  }
71
80
  (0, logger_1.log)('🔍 Found infrastructure configurations:', infraEnvironments.join(', '));
@@ -77,8 +86,11 @@ function extractEnvironmentNames() {
77
86
  const entries = yield (0, promises_1.readdir)('environments');
78
87
  // Filter only directories
79
88
  const environments = entries.filter((entry) => {
80
- const fullPath = (0, path_1.join)('environments', entry);
81
- return (0, fs_1.statSync)(fullPath).isDirectory();
89
+ const environmentPath = (0, path_1.join)('environments', entry);
90
+ const opencrvsServicesPath = (0, path_1.join)(environmentPath, 'opencrvs-services');
91
+ return (isDirectory(environmentPath) &&
92
+ (0, fs_1.existsSync)(opencrvsServicesPath) &&
93
+ isDirectory(opencrvsServicesPath));
82
94
  });
83
95
  if (environments.length === 0) {
84
96
  console.log('⚠️ Warning: No environment directories found in environments/');
@@ -0,0 +1,2 @@
1
+ export declare function upgradeEnvironmentLayout(): Promise<void>;
2
+ //# sourceMappingURL=upgrade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/environment/upgrade.ts"],"names":[],"mappings":"AAkFA,wBAAsB,wBAAwB,kBAY7C"}
@@ -0,0 +1,82 @@
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.upgradeEnvironmentLayout = upgradeEnvironmentLayout;
26
+ const fs_1 = require("fs");
27
+ const path_1 = require("path");
28
+ const kleur_1 = __importDefault(require("kleur"));
29
+ const logger_1 = require("./logger");
30
+ const paths_1 = require("./paths");
31
+ const update_workflows_1 = require("./update-workflows");
32
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
33
+ if (!(0, fs_1.existsSync)(sourcePath)) {
34
+ return false;
35
+ }
36
+ if ((0, fs_1.existsSync)(destinationPath)) {
37
+ (0, logger_1.warn)(`⚠️ Skipped ${sourcePath}; destination already exists at ${destinationPath}`);
38
+ return false;
39
+ }
40
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(destinationPath), { recursive: true });
41
+ (0, fs_1.renameSync)(sourcePath, destinationPath);
42
+ (0, logger_1.log)(` ✓ Moved ${sourcePath} -> ${destinationPath}`);
43
+ return true;
44
+ }
45
+ function migrateInventoryFiles() {
46
+ const oldInventoryFiles = (0, paths_1.findOldInventoryFiles)();
47
+ if (oldInventoryFiles.length === 0) {
48
+ (0, logger_1.log)(`ℹ️ No old inventory files found at ${paths_1.OLD_INVENTORY_DIR}`);
49
+ return false;
50
+ }
51
+ (0, logger_1.log)(kleur_1.default.bold('\nMigrating Ansible inventory files'));
52
+ let didMoveInventory = false;
53
+ for (const oldInventoryFile of oldInventoryFiles) {
54
+ const environment = (0, paths_1.getEnvironmentNameFromOldInventoryPath)(oldInventoryFile);
55
+ didMoveInventory =
56
+ moveFileIfDestinationMissing(oldInventoryFile, (0, paths_1.getEnvironmentInventoryPath)(environment)) || didMoveInventory;
57
+ }
58
+ try {
59
+ if ((0, fs_1.existsSync)(paths_1.OLD_INVENTORY_DIR) &&
60
+ (0, fs_1.readdirSync)(paths_1.OLD_INVENTORY_DIR).length === 0) {
61
+ (0, fs_1.rmdirSync)(paths_1.OLD_INVENTORY_DIR);
62
+ (0, logger_1.log)(` ✓ Removed empty ${paths_1.OLD_INVENTORY_DIR}`);
63
+ }
64
+ }
65
+ catch (_a) {
66
+ (0, logger_1.warn)(`⚠️ Could not remove ${paths_1.OLD_INVENTORY_DIR}; please review it manually`);
67
+ }
68
+ return didMoveInventory;
69
+ }
70
+ function upgradeEnvironmentLayout() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const didMoveInventory = migrateInventoryFiles();
73
+ yield (0, update_workflows_1.updateWorkflowEnvironments)();
74
+ if (didMoveInventory) {
75
+ (0, logger_1.success)('\n✅ Environment layout upgrade completed successfully.');
76
+ }
77
+ else {
78
+ (0, logger_1.success)('\n✅ Environment layout already uses the current structure.');
79
+ }
80
+ (0, logger_1.log)('\nCommit changes into git after upgrade');
81
+ });
82
+ }
@@ -62,6 +62,7 @@ const path = __importStar(require("path"));
62
62
  const kleur_1 = __importDefault(require("kleur"));
63
63
  const manage_users_1 = require("./manage-users");
64
64
  const logger_1 = require("./logger");
65
+ const paths_1 = require("./paths");
65
66
  function select(options) {
66
67
  return __awaiter(this, void 0, void 0, function* () {
67
68
  const inquirer = yield import('@inquirer/prompts');
@@ -76,32 +77,29 @@ function select(options) {
76
77
  * * @returns {string} Inventory file
77
78
  */
78
79
  function selectInventoryFile() {
79
- return __awaiter(this, arguments, void 0, function* (dirPath = './infrastructure/server-setup/inventory/') {
80
+ return __awaiter(this, arguments, void 0, function* (dirPath = './environments') {
80
81
  // Check if directory exists
81
82
  if (!fs.existsSync(dirPath)) {
82
83
  (0, logger_1.warn)(`⚠️ No environment configuration directory found at ${dirPath}`);
83
84
  (0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
84
85
  return null;
85
86
  }
86
- // Read and filter files
87
- const files = fs
87
+ const environments = fs
88
88
  .readdirSync(dirPath)
89
- .filter((file) => {
90
- const filePath = path.join(dirPath, file);
91
- const isFile = fs.statSync(filePath).isFile();
92
- const ext = path.extname(file).slice(1).toLowerCase();
93
- return isFile && (ext === 'yml' || ext === 'yaml');
89
+ .filter((entry) => {
90
+ const filePath = path.join(dirPath, entry);
91
+ return (fs.statSync(filePath).isDirectory() &&
92
+ fs.existsSync((0, paths_1.getEnvironmentInventoryPath)(entry)));
94
93
  })
95
94
  .sort();
96
- if (files.length === 0) {
95
+ if (environments.length === 0) {
97
96
  (0, logger_1.warn)(`⚠️ No environment configuration files found at ${dirPath}`);
98
97
  (0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
99
98
  return null;
100
99
  }
101
- // Create choices - remove extension from display
102
- const choices = files.map((file) => ({
103
- name: path.basename(file, path.extname(file)),
104
- value: path.join(dirPath, file)
100
+ const choices = environments.map((environment) => ({
101
+ name: environment,
102
+ value: (0, paths_1.getEnvironmentInventoryPath)(environment)
105
103
  }));
106
104
  const selectedFile = yield select({
107
105
  message: 'Select environment (inventory file) to load users:',