@opencrvs/toolkit 2.1.0-rc.982e0ae → 2.1.0-rc.9a83eed

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 (64) hide show
  1. package/README.md +2 -12
  2. package/create-countryconfig/index.js +133 -2
  3. package/dist/application-config/index.js +17 -18
  4. package/dist/authentication/index.js +7 -6
  5. package/dist/cli.js +458 -204
  6. package/dist/commons/api/router.d.ts +6 -42
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/conditionals/validate.d.ts +1 -1
  9. package/dist/commons/events/ActionConfig.d.ts +4 -0
  10. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -12
  11. package/dist/commons/events/FieldConfig.d.ts +16 -15
  12. package/dist/commons/events/FormConfig.d.ts +6 -0
  13. package/dist/commons/events/PageConfig.d.ts +4 -0
  14. package/dist/commons/events/locations.d.ts +4 -0
  15. package/dist/commons/events/test.utils.d.ts +18 -1
  16. package/dist/commons/events/utils.d.ts +15 -0
  17. package/dist/conditionals/index.js +7 -6
  18. package/dist/environment/manage-users.js +1 -1
  19. package/dist/environment/setup-environment.js +44 -26
  20. package/dist/environment/templates.d.ts +0 -1
  21. package/dist/environment/templates.d.ts.map +1 -1
  22. package/dist/environment/templates.js +3 -8
  23. package/dist/environment/update-workflows.d.ts.map +1 -1
  24. package/dist/environment/update-workflows.js +4 -0
  25. package/dist/environment/utils.d.ts +0 -12
  26. package/dist/environment/utils.d.ts.map +1 -1
  27. package/dist/environment/utils.js +1 -28
  28. package/dist/events/index.js +1901 -1792
  29. package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
  30. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +1 -1
  31. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +1 -1
  32. package/dist/migrations/v2.1/add-explicit-correction-flags.js +34 -6
  33. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +1 -1
  34. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -1
  35. package/dist/migrations/v2.1/add-recovery-link-notifications.js +2 -7
  36. package/dist/migrations/v2.1/add-translations.d.ts +1 -1
  37. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
  38. package/dist/migrations/v2.1/add-translations.js +1 -6
  39. package/dist/migrations/v2.1/enable-telemetry.d.ts +1 -1
  40. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
  41. package/dist/migrations/v2.1/enable-telemetry.js +1 -6
  42. package/dist/migrations/v2.1/index.d.ts +14 -1
  43. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  44. package/dist/migrations/v2.1/index.js +96 -84
  45. package/dist/notification/index.js +155 -152
  46. package/dist/scopes/index.d.ts +109 -5
  47. package/dist/scopes/index.js +7 -6
  48. package/dist/templates/charts-values/dependencies/values.yaml +2 -0
  49. package/dist/translations/check.d.ts +2 -0
  50. package/dist/translations/check.d.ts.map +1 -1
  51. package/dist/translations/check.js +9 -4
  52. package/dist/verify/endpoints.d.ts +18 -1
  53. package/dist/verify/endpoints.d.ts.map +1 -1
  54. package/dist/verify/endpoints.js +12 -4
  55. package/dist/verify/scopes.d.ts +13 -0
  56. package/dist/verify/scopes.d.ts.map +1 -0
  57. package/dist/verify/scopes.js +131 -0
  58. package/dist/verify/upgrade.d.ts +14 -0
  59. package/dist/verify/upgrade.d.ts.map +1 -0
  60. package/dist/verify/upgrade.js +111 -0
  61. package/opencrvs-toolkit-2.1.0-rc.9a83eed.tgz +0 -0
  62. package/package.json +2 -2
  63. package/tsconfig.build.tsbuildinfo +1 -1
  64. package/opencrvs-toolkit-2.1.0-rc.982e0ae.tgz +0 -0
package/README.md CHANGED
@@ -55,19 +55,9 @@ Toolkit "re-exports" TRPC router to allow for easy client interaction.
55
55
 
56
56
  Toolkit "re-exports" common definitions (e.g. events, conditionals) and make them available through npm.
57
57
 
58
- ### Releasing and buiding
58
+ ### Publishing
59
59
 
60
- #### While developing
61
-
62
- 1. Update version number in `package.json`
63
- 2. `yarn build:all`
64
- 3. `npm publish`
65
-
66
- #### Through version control
67
-
68
- 1. Update version number in `package.json`
69
- 2. Create a pull request
70
- 3. Once merged, github action will get triggered.
60
+ Publish via [Publish toolkit to NPM registry](https://github.com/opencrvs/opencrvs-core/actions/workflows/publish-toolkit-to-npm.yml).
71
61
 
72
62
  #### Gotchas, good to know
73
63
 
@@ -13,6 +13,7 @@
13
13
 
14
14
  const path = require('path')
15
15
  const fs = require('fs')
16
+ const { execSync } = require('child_process')
16
17
  const readline = require('readline/promises')
17
18
  const degit = require('degit').default
18
19
 
@@ -21,6 +22,14 @@ const CORE_REPOSITORY = 'opencrvs/opencrvs-core'
21
22
  const COUNTRYCONFIG_TEMPLATE_REPOSITORY_SUBPATH =
22
23
  'packages/countryconfig-template'
23
24
 
25
+ const CORE_REPO_URL = 'https://github.com/' + CORE_REPOSITORY + '.git'
26
+ const INFRASTRUCTURE_REPO_URL =
27
+ 'https://github.com/' + INFRASTRUCTURE_REPOSITORY + '.git'
28
+
29
+ const { version } = JSON.parse(
30
+ fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8')
31
+ )
32
+
24
33
  function joinValues(values, separator) {
25
34
  return values
26
35
  .filter((value) => !!value)
@@ -28,6 +37,125 @@ function joinValues(values, separator) {
28
37
  .trim()
29
38
  }
30
39
 
40
+ function tagExists(repoUrl, tag) {
41
+ try {
42
+ execSync(
43
+ 'git ls-remote --exit-code --tags ' + repoUrl + ' refs/tags/' + tag,
44
+ { stdio: 'pipe' }
45
+ )
46
+ return true
47
+ } catch (err) {
48
+ return false
49
+ }
50
+ }
51
+
52
+ function branchExists(repoUrl, branch) {
53
+ try {
54
+ execSync(
55
+ 'git ls-remote --exit-code --heads ' + repoUrl + ' refs/heads/' + branch,
56
+ { stdio: 'pipe' }
57
+ )
58
+ return true
59
+ } catch (err) {
60
+ return false
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Release tags (e.g. "v2.1.0"), highest first. Delegates the version-aware
66
+ * ordering to git itself rather than hand-parsing semver, then filters down
67
+ * to strict "vX.Y.Z" tags - `--sort=-version:refname` alone still leaves in
68
+ * non-release refs (e.g. "vtesting", "v2.0.0-beta") and peeled annotated-tag
69
+ * lines ("refs/tags/v2.0.0^{}").
70
+ */
71
+ function listReleaseTags(repoUrl) {
72
+ const output = execSync(
73
+ 'git ls-remote --tags --sort=-version:refname ' + repoUrl,
74
+ { encoding: 'utf-8' }
75
+ )
76
+
77
+ return output
78
+ .split('\n')
79
+ .map((line) => line.split('\t')[1])
80
+ .filter(Boolean)
81
+ .map((ref) => ref.replace('refs/tags/', ''))
82
+ .filter((tag) => /^v\d+\.\d+\.\d+$/.test(tag))
83
+ }
84
+
85
+ /**
86
+ * The highest release tag present in *both* repositories - used as the
87
+ * fallback when the version-specific tag can't be found in one or both, so
88
+ * scaffolding still lands on a real, matched release rather than develop.
89
+ */
90
+ function getLatestCommonReleaseTag() {
91
+ const infrastructureTags = new Set(listReleaseTags(INFRASTRUCTURE_REPO_URL))
92
+ return (
93
+ listReleaseTags(CORE_REPO_URL).find((tag) => infrastructureTags.has(tag)) ||
94
+ null
95
+ )
96
+ }
97
+
98
+ /**
99
+ * A prerelease-shaped own version (e.g. "2.1.0-rc.f5ea803", what npm resolves
100
+ * `@next` to - a build published from every push to a branch) never has a
101
+ * matching release tag, so it's resolved as a branch instead. Its base
102
+ * version (stripped of the "-rc.<sha>" suffix) tells apart two different
103
+ * situations: an RC for a version already being stabilized on its own
104
+ * "release/X.Y.Z" branch (e.g. "2.0.1-rc.*" while a patch release is in
105
+ * progress) versus an RC for a version that hasn't been branched off yet and
106
+ * only exists on develop (e.g. "2.1.0-rc.*" while that release branch hasn't
107
+ * been cut). Scaffold from the release branch when it exists in both
108
+ * repositories, otherwise fall back to develop.
109
+ *
110
+ * Otherwise, the own "X.Y.Z" version - whether resolved via npm's `latest`
111
+ * dist-tag (bare invocation) or an explicit `@X.Y.Z` pin - scaffolds from the
112
+ * matching "vX.Y.Z" tag when it exists in both repositories. If it doesn't
113
+ * (e.g. `latest` lagging behind the repos, or a pin that predates one repo's
114
+ * tagging), fall back to the highest release tag common to both, rather than
115
+ * a mismatched pairing of one tagged repo at that version and another repo
116
+ * at a different release. Exits with an error if no matching release tag
117
+ * exists in both repositories.
118
+ */
119
+ function resolveRef() {
120
+ if (version.includes('-')) {
121
+ const releaseBranch = 'release/' + version.split('-')[0]
122
+ if (
123
+ branchExists(CORE_REPO_URL, releaseBranch) &&
124
+ branchExists(INFRASTRUCTURE_REPO_URL, releaseBranch)
125
+ ) {
126
+ return releaseBranch
127
+ }
128
+ return 'develop'
129
+ }
130
+
131
+ const tag = 'v' + version
132
+ if (
133
+ tagExists(CORE_REPO_URL, tag) &&
134
+ tagExists(INFRASTRUCTURE_REPO_URL, tag)
135
+ ) {
136
+ return tag
137
+ }
138
+
139
+ const latestCommonTag = getLatestCommonReleaseTag()
140
+ if (latestCommonTag) {
141
+ console.warn(
142
+ '\nWarning: tag "' +
143
+ tag +
144
+ '" was not found in both repositories; falling back to the latest ' +
145
+ 'available release, ' +
146
+ latestCommonTag +
147
+ '.'
148
+ )
149
+ return latestCommonTag
150
+ }
151
+
152
+ console.error(
153
+ '\nError: no matching release tag was found in both the core and ' +
154
+ 'infrastructure repositories.'
155
+ )
156
+ process.exit(1)
157
+ }
158
+
31
159
  /**
32
160
  * Clones a repository from GitHub to a target directory.
33
161
  *
@@ -271,6 +399,8 @@ async function main() {
271
399
  ensureTargetDirectoryDoesNotExist(countryconfigDirName)
272
400
  ensureTargetDirectoryDoesNotExist(infrastructureDirName)
273
401
 
402
+ const ref = resolveRef()
403
+
274
404
  // Gather all answers up front so the operator isn't interrupted mid-clone.
275
405
  const organisation = await promptOrganisation()
276
406
  const countryCode = await promptCountryCode()
@@ -280,7 +410,8 @@ async function main() {
280
410
  await cloneRepository(
281
411
  {
282
412
  repository: CORE_REPOSITORY,
283
- repositorySubPath: COUNTRYCONFIG_TEMPLATE_REPOSITORY_SUBPATH
413
+ repositorySubPath: COUNTRYCONFIG_TEMPLATE_REPOSITORY_SUBPATH,
414
+ branch: ref
284
415
  },
285
416
  countryconfigTargetPath
286
417
  )
@@ -293,7 +424,7 @@ async function main() {
293
424
 
294
425
  try {
295
426
  await cloneRepository(
296
- { repository: INFRASTRUCTURE_REPOSITORY },
427
+ { repository: INFRASTRUCTURE_REPOSITORY, branch: ref },
297
428
  infrastructureTargetPath
298
429
  )
299
430
  } catch (err) {
@@ -741,10 +741,7 @@ var PlainScopeType = z13.enum([
741
741
  // Performance dashboard
742
742
  "performance.read",
743
743
  "performance.read-dashboards",
744
- "performance.vital-statistics-export",
745
- // Scopes used exclusively by countryconfig integration token
746
- "record.confirm-registration",
747
- "record.reject-registration"
744
+ "performance.vital-statistics-export"
748
745
  ]);
749
746
  var scopeByEvent = z13.preprocess(
750
747
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -762,7 +759,9 @@ var userRole = z13.preprocess(
762
759
  ).describe("User role, e.g. admin, field agent");
763
760
  var scopeOptionsPlaceEvent = z13.object({
764
761
  event: scopeByEvent,
765
- placeOfEvent: JurisdictionFilter.optional()
762
+ placeOfEvent: JurisdictionFilter.optional(),
763
+ createdBy: UserFilter.optional(),
764
+ createdIn: JurisdictionFilter.optional()
766
765
  }).describe("Options applicable to all record scopes.");
767
766
  var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
768
767
  notifiedIn: JurisdictionFilter.optional(),
@@ -805,7 +804,9 @@ var AllScopeOptions = z13.object({
805
804
  var ScopeOptionKey = AllScopeOptions.keyof();
806
805
  var ResolvedScopeOptionsPlaceEvent = z13.object({
807
806
  event: scopeByEvent,
808
- placeOfEvent: UUID.nullish()
807
+ placeOfEvent: UUID.nullish(),
808
+ createdBy: z13.string().optional(),
809
+ createdIn: UUID.nullish()
809
810
  }).describe(
810
811
  "Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
811
812
  );
@@ -1912,9 +1913,6 @@ var AdministrativeAreaField = BaseField.extend({
1912
1913
  partOf: FieldReference.optional().describe("Parent location"),
1913
1914
  type: AdministrativeAreas,
1914
1915
  allowedLocations: AllowedLocations,
1915
- listHistoricalNames: import_v43.default.boolean().optional().describe(
1916
- "List every historical name a location has had as a separate, selectable option."
1917
- ),
1918
1916
  activeOnly: import_v43.default.boolean().optional().describe(
1919
1917
  "Offer only locations that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded."
1920
1918
  ),
@@ -1932,9 +1930,6 @@ var LocationInput = BaseField.extend({
1932
1930
  configuration: import_v43.default.object({
1933
1931
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
1934
1932
  allowedLocations: AllowedLocations,
1935
- listHistoricalNames: import_v43.default.boolean().optional().describe(
1936
- "List every historical name a location has had as a separate, selectable option."
1937
- ),
1938
1933
  activeOnly: import_v43.default.boolean().optional().describe(
1939
1934
  "Offer only locations that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded."
1940
1935
  ),
@@ -1968,7 +1963,6 @@ var Facility = BaseField.extend({
1968
1963
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1969
1964
  configuration: import_v43.default.object({
1970
1965
  allowedLocations: AllowedLocations,
1971
- listHistoricalNames: import_v43.default.boolean().optional(),
1972
1966
  activeOnly: import_v43.default.boolean().optional(),
1973
1967
  anchorToDateOfEvent: import_v43.default.boolean().optional()
1974
1968
  }).optional()
@@ -1978,7 +1972,6 @@ var Office = BaseField.extend({
1978
1972
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1979
1973
  configuration: import_v43.default.object({
1980
1974
  allowedLocations: AllowedLocations,
1981
- listHistoricalNames: import_v43.default.boolean().optional(),
1982
1975
  activeOnly: import_v43.default.boolean().optional(),
1983
1976
  anchorToDateOfEvent: import_v43.default.boolean().optional()
1984
1977
  }).optional()
@@ -2015,9 +2008,6 @@ var Address = BaseField.extend({
2015
2008
  })
2016
2009
  ).optional(),
2017
2010
  allowedLocations: AllowedLocations,
2018
- listHistoricalNames: import_v43.default.boolean().optional().describe(
2019
- "List every historical name a location has had as a separate, selectable option. Propagated to the embedded admin-area selectors."
2020
- ),
2021
2011
  activeOnly: import_v43.default.boolean().optional().describe(
2022
2012
  "Offer only admin areas that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded. Propagated to the embedded admin-area selectors."
2023
2013
  ),
@@ -2078,10 +2068,19 @@ var ButtonField = BaseField.extend({
2078
2068
  description: "A generic button that can be used to trigger an action",
2079
2069
  id: "ButtonField"
2080
2070
  });
2071
+ var FieldGroupConfiguration = import_v43.default.object({
2072
+ separator: import_v43.default.string().optional().describe(
2073
+ 'Joins the subfield values when the group is rendered as output, e.g. ", ". Defaults to one subfield per line.'
2074
+ ),
2075
+ hideEmptyFields: import_v43.default.boolean().default(false).optional().describe(
2076
+ "Leaves subfields without a value out of the output. Pair it with a separator so the separator does not double up around the gaps."
2077
+ )
2078
+ });
2081
2079
  var FieldGroup = BaseField.extend({
2082
2080
  type: import_v43.default.literal(FieldType.FIELD_GROUP),
2083
2081
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
2084
- fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig))
2082
+ fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig)),
2083
+ configuration: FieldGroupConfiguration.optional()
2085
2084
  }).meta({
2086
2085
  description: "A group of fields that are displayed together",
2087
2086
  id: "FieldGroup"
@@ -383,10 +383,7 @@ var PlainScopeType = z7.enum([
383
383
  // Performance dashboard
384
384
  "performance.read",
385
385
  "performance.read-dashboards",
386
- "performance.vital-statistics-export",
387
- // Scopes used exclusively by countryconfig integration token
388
- "record.confirm-registration",
389
- "record.reject-registration"
386
+ "performance.vital-statistics-export"
390
387
  ]);
391
388
  var scopeByEvent = z7.preprocess(
392
389
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -404,7 +401,9 @@ var userRole = z7.preprocess(
404
401
  ).describe("User role, e.g. admin, field agent");
405
402
  var scopeOptionsPlaceEvent = z7.object({
406
403
  event: scopeByEvent,
407
- placeOfEvent: JurisdictionFilter.optional()
404
+ placeOfEvent: JurisdictionFilter.optional(),
405
+ createdBy: UserFilter.optional(),
406
+ createdIn: JurisdictionFilter.optional()
408
407
  }).describe("Options applicable to all record scopes.");
409
408
  var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
410
409
  notifiedIn: JurisdictionFilter.optional(),
@@ -447,7 +446,9 @@ var AllScopeOptions = z7.object({
447
446
  var ScopeOptionKey = AllScopeOptions.keyof();
448
447
  var ResolvedScopeOptionsPlaceEvent = z7.object({
449
448
  event: scopeByEvent,
450
- placeOfEvent: UUID.nullish()
449
+ placeOfEvent: UUID.nullish(),
450
+ createdBy: z7.string().optional(),
451
+ createdIn: UUID.nullish()
451
452
  }).describe(
452
453
  "Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
453
454
  );