@raisenow/tamaro-cli 1.6.0-dev.3 → 1.6.1

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.
@@ -74,7 +74,6 @@ import { basename, dirname, join, relative, resolve } from "path";
74
74
  import chalk2 from "chalk";
75
75
  import stripIndent2 from "strip-indent";
76
76
  import { getIfUtils } from "webpack-config-utils";
77
- import { z } from "zod";
78
77
  var require2 = createRequire(import.meta.url);
79
78
  var moduleFileExtensions = ["ts", "tsx", "js", "jsx"];
80
79
  var extensions = moduleFileExtensions.map((v) => `.${v}`);
@@ -140,7 +139,6 @@ var getPaths = (ifCore) => {
140
139
  appTsConfig: resolveApp("tsconfig.json"),
141
140
  appHtml: resolveApp("*.html"),
142
141
  appEnv: resolveApp(".env*"),
143
- configYml: resolveApp("config.yml"),
144
142
  appTailwindConfig: void 0
145
143
  }
146
144
  );
@@ -187,55 +185,17 @@ var getIfCoreFns = ({
187
185
  );
188
186
  process.exit(1);
189
187
  };
190
- var resolveAccountUuidFromConfig = (rawConfig, field) => {
191
- const epmsConfig = z.object({
192
- [field]: z.object()
193
- }).safeParse(rawConfig);
194
- if (!epmsConfig.success) {
195
- return void 0;
196
- }
197
- const simple = z.object({
198
- [field]: z.object({
199
- account_uuid: z.uuid()
200
- })
201
- }).safeParse(rawConfig);
202
- if (simple.success) {
203
- return simple.data[field].account_uuid;
204
- }
205
- const accountMapping = z.object({
206
- [field]: z.object({
207
- account_mapping: z.uuid()
208
- })
209
- }).safeParse(rawConfig);
210
- if (accountMapping.success) {
211
- return accountMapping.data[field].account_mapping;
212
- }
213
- halt(
214
- stripIndent2(
215
- `Could not extract EPMS account UUID(s) from config.yml. Please ensure that the "${field}" field is correctly formatted. Expected formats:
216
- 1. ${field}:
217
- account_uuid: <UUID>
218
-
219
- 2. ${field}:
220
- account_mapping: <UUID>
221
- `
222
- )
223
- );
224
- };
225
188
 
226
189
  // src/lib/constants.ts
227
- import envPaths from "env-paths";
228
190
  var DEFAULT_TAG = "latest";
229
191
  var DEFAULT_PORT = 1234;
230
192
  var AWS_S3_BUCKET_TAMARO = "tamaro.raisenow.com";
231
193
  var AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE = "rnw-stage-email-service";
232
194
  var AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD = "rnw-email-service";
233
- var EPMS_API_BASE_URL_STAGE = "https://api.stage.mesos.raisenow.net";
234
195
  var CORE_CONFIG_NAME = "tamaro-core";
235
196
  var AWS_CLOUDFRONT_DISTRIBUTION_ID = "EHJ1OM458YQ0I";
236
197
  var HTTPS_CRT_FILE = "localhost.crt";
237
198
  var HTTPS_KEY_FILE = "localhost.key";
238
- var CACHE_DIR = envPaths("tamaro-cli", { suffix: "" }).cache;
239
199
 
240
200
  // src/lib/env.ts
241
201
  import { createRequire as createRequire2 } from "module";
@@ -380,18 +340,15 @@ export {
380
340
  getPaths,
381
341
  getRelativePaths,
382
342
  getIfCoreFns,
383
- resolveAccountUuidFromConfig,
384
343
  DEFAULT_TAG,
385
344
  DEFAULT_PORT,
386
345
  AWS_S3_BUCKET_TAMARO,
387
346
  AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE,
388
347
  AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD,
389
- EPMS_API_BASE_URL_STAGE,
390
348
  CORE_CONFIG_NAME,
391
349
  AWS_CLOUDFRONT_DISTRIBUTION_ID,
392
350
  HTTPS_CRT_FILE,
393
351
  HTTPS_KEY_FILE,
394
- CACHE_DIR,
395
352
  getEnvVars,
396
353
  assertEnvValid,
397
354
  applyEnv
package/dist/cli.js CHANGED
@@ -4,11 +4,9 @@ import {
4
4
  AWS_S3_BUCKET_TAMARO,
5
5
  AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD,
6
6
  AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE,
7
- CACHE_DIR,
8
7
  CORE_CONFIG_NAME,
9
8
  DEFAULT_PORT,
10
9
  DEFAULT_TAG,
11
- EPMS_API_BASE_URL_STAGE,
12
10
  HTTPS_CRT_FILE,
13
11
  HTTPS_KEY_FILE,
14
12
  applyEnv,
@@ -23,11 +21,10 @@ import {
23
21
  logSuccess,
24
22
  logTitle,
25
23
  promptConfirmation,
26
- resolveAccountUuidFromConfig,
27
24
  resolveBin,
28
25
  resolveOwn,
29
26
  runCommandSync
30
- } from "./chunk-FI7KZAG6.js";
27
+ } from "./chunk-5D6F3T2J.js";
31
28
 
32
29
  // src/cli.ts
33
30
  import { createCommand } from "commander";
@@ -850,7 +847,7 @@ var undeploy = async (options) => {
850
847
  assertOptionsValid9(options);
851
848
  awsAuthenticate(options);
852
849
  const flags = prepareFlags(options);
853
- const { tag, all, dryrun } = options;
850
+ const { tag = DEFAULT_TAG, all, dryrun } = options;
854
851
  const dryRunFlag = dryrun ? `--dryrun` : "";
855
852
  const deployUrl = all ? `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/` : `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/`;
856
853
  const description = all ? `all tags of "${configName}"` : `tag "${tag}" of "${configName}"`;
@@ -859,7 +856,7 @@ var undeploy = async (options) => {
859
856
  }
860
857
  await promptConfirmation(
861
858
  `Are you sure you want to undeploy ${description}?`,
862
- options.ci
859
+ options.yes
863
860
  );
864
861
  const cmd = `
865
862
  aws s3 rm ${deployUrl}
@@ -929,8 +926,19 @@ var undeployEmailConfig = async (options) => {
929
926
  assertProfilesPresent();
930
927
  options.profile = await promptProfile();
931
928
  }
929
+ if (options.ci) {
930
+ options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
931
+ }
932
932
  if (!options.bucket) {
933
- options.bucket = options.ci ? AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD : await promptBucketTamaroEmailConfig2();
933
+ if (options.ci) {
934
+ options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
935
+ } else if (options.prod) {
936
+ options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD;
937
+ } else if (options.stage) {
938
+ options.bucket = AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE;
939
+ } else {
940
+ options.bucket = await promptBucketTamaroEmailConfig2();
941
+ }
934
942
  }
935
943
  assertOptionsValid10(options);
936
944
  awsAuthenticate(options);
@@ -1013,247 +1021,10 @@ var promptBucketTamaroEmailConfig2 = async () => {
1013
1021
  return bucket;
1014
1022
  };
1015
1023
 
1016
- // src/commands/update-epms.ts
1017
- import { readFileSync as readFileSync3 } from "fs";
1018
- import { basename as basename3 } from "path";
1019
- import { config as dotenvConfig } from "dotenv";
1020
- import { globSync as globSync2 } from "glob";
1021
- import yaml2 from "js-yaml";
1022
-
1023
- // src/lib/epms/assert.ts
1024
- import { existsSync as existsSync6, readFileSync } from "fs";
1025
- import yaml from "js-yaml";
1026
- import stripIndent5 from "strip-indent";
1027
- var assertEpmsCredentials = (configPath) => {
1028
- if (!existsSync6(configPath)) {
1029
- throw new Error(`Config file not found at path: ${configPath}`);
1030
- }
1031
- try {
1032
- const configContent = yaml.load(readFileSync(configPath, "utf8"));
1033
- assertEpmsCredentialsPresentStage(configContent);
1034
- assertEpmsCredentialsPresentProd(configContent);
1035
- } catch (e) {
1036
- throw new Error(
1037
- `Error parsing config file at path: ${configPath}. Details: ${e}`
1038
- );
1039
- }
1040
- };
1041
- var assertEpmsCredentialsPresentStage = (rawConfig) => {
1042
- const accountsUuidsStage = resolveAccountUuidFromConfig(
1043
- rawConfig,
1044
- "epms_stage"
1045
- );
1046
- if (!accountsUuidsStage) {
1047
- return;
1048
- }
1049
- if (!process.env.EPMS_CLIENT_ID_STAGE || !process.env.EPMS_CLIENT_SECRET_STAGE) {
1050
- halt(
1051
- stripIndent5(
1052
- `EPMS credentials for stage environment are missing.
1053
- - Please set EPMS_CLIENT_ID_STAGE and EPMS_CLIENT_SECRET_STAGE in your environment variables.
1054
- - Alternatively, remove the "epms_stage" fields from your config.yml
1055
- `
1056
- )
1057
- );
1058
- }
1059
- };
1060
- var assertEpmsCredentialsPresentProd = (rawConfig) => {
1061
- const accountsUuidsProd = resolveAccountUuidFromConfig(rawConfig, "epms");
1062
- if (!accountsUuidsProd) {
1063
- return;
1064
- }
1065
- if (!process.env.EPMS_CLIENT_ID || !process.env.EPMS_CLIENT_SECRET) {
1066
- halt(
1067
- stripIndent5(
1068
- `EPMS credentials for prod environment are missing.
1069
- - Please set EPMS_CLIENT_ID and EPMS_CLIENT_SECRET in your environment variables.
1070
- - Alternatively, remove the "epms" fields from your config.yml
1071
- `
1072
- )
1073
- );
1074
- }
1075
- };
1076
-
1077
- // src/lib/epms/auth.ts
1078
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
1079
- import { dirname as dirname3, join } from "path";
1080
- import ky from "ky";
1081
- var DEFAULT_TIMEOUT = 1e4;
1082
- function getCacheFilePath() {
1083
- return join(CACHE_DIR, "token.json");
1084
- }
1085
- function readCachedToken() {
1086
- try {
1087
- const filePath = getCacheFilePath();
1088
- if (!existsSync7(filePath)) {
1089
- return void 0;
1090
- }
1091
- const data = JSON.parse(readFileSync2(filePath, "utf-8"));
1092
- if (typeof data.token === "string" && typeof data.expirationTime === "number") {
1093
- return data;
1094
- }
1095
- } catch {
1096
- }
1097
- return void 0;
1098
- }
1099
- function writeCachedToken(cached) {
1100
- try {
1101
- const filePath = getCacheFilePath();
1102
- mkdirSync2(dirname3(filePath), { recursive: true });
1103
- writeFileSync(filePath, JSON.stringify(cached), { mode: 384 });
1104
- } catch {
1105
- }
1106
- }
1107
- var createAuthorizer = (baseUrl, clientId, clientSecret) => {
1108
- const apiUnauthorized = ky.extend({
1109
- headers: {
1110
- "Access-Control-Allow-Origin": "*"
1111
- },
1112
- prefixUrl: baseUrl,
1113
- timeout: DEFAULT_TIMEOUT
1114
- });
1115
- let expirationTime = void 0;
1116
- let token = void 0;
1117
- const cached = readCachedToken();
1118
- if (cached) {
1119
- token = cached.token;
1120
- expirationTime = cached.expirationTime;
1121
- }
1122
- const authorize = async () => {
1123
- const isExpired = (expirationTime ?? 0) - Date.now() < 5 * 60 * 1e3;
1124
- if (token && !isExpired) {
1125
- return token;
1126
- }
1127
- const data = await apiUnauthorized.post("oauth2/token", {
1128
- json: {
1129
- client_id: clientId,
1130
- client_secret: clientSecret,
1131
- grant_type: "client_credentials"
1132
- }
1133
- }).json();
1134
- token = `${data.token_type} ${data.access_token}`;
1135
- expirationTime = Date.now() + data.expires_in * 1e3;
1136
- writeCachedToken({ token, expirationTime });
1137
- return token;
1138
- };
1139
- return apiUnauthorized.extend({
1140
- hooks: {
1141
- beforeRequest: [
1142
- async (request) => {
1143
- request.headers.set("Authorization", await authorize());
1144
- }
1145
- ]
1146
- }
1147
- });
1148
- };
1149
-
1150
- // src/lib/epms/client.ts
1151
- var EpmsClient = class {
1152
- #epmsClient;
1153
- constructor(baseUrl, clientId, clientSecret) {
1154
- this.#epmsClient = createAuthorizer(baseUrl, clientId, clientSecret);
1155
- }
1156
- async getOrganisationIdByAccountUuid(accountUuid) {
1157
- const query = {
1158
- query: {
1159
- $and: [
1160
- { $term: { object_uuid: accountUuid } },
1161
- { $term: { object: "account" } }
1162
- ]
1163
- },
1164
- size: 1,
1165
- from: 0
1166
- };
1167
- const response = await this.#epmsClient.post("search/events", {
1168
- json: query
1169
- }).json();
1170
- if (response.hits.length === 0) {
1171
- throw new Error(`No events found for account UUID: ${accountUuid}`);
1172
- }
1173
- const organisationId = response.hits[0].organisation_uuid;
1174
- if (!organisationId) {
1175
- throw new Error(
1176
- `Organisation UUID not found for account UUID: ${accountUuid}`
1177
- );
1178
- }
1179
- return organisationId;
1180
- }
1181
- async updateTamaro(configName, tag, json) {
1182
- return this.#epmsClient.put(`products/tamaro/${configName}/tags/${tag}`, {
1183
- json
1184
- }).json();
1185
- }
1186
- };
1187
-
1188
- // src/commands/update-epms.ts
1189
- var updateEpms = async (options) => {
1190
- const { ifCore } = getIfCoreFns();
1191
- assertIsNotCore5(ifCore);
1192
- const paths = getPaths(ifCore);
1193
- const { tag, dryrun } = options;
1194
- const dryRunFlag = dryrun ? `--dryrun` : "";
1195
- const configName = getWidgetUuid();
1196
- const appEnvFiles = globSync2(paths.appEnv);
1197
- const filePath = appEnvFiles.find((file) => basename3(file) === ".env");
1198
- if (!filePath) {
1199
- halt(
1200
- 'No ".env" file found. Please make sure to have a ".env" file with EPMS credentials in the root of your widget project.'
1201
- );
1202
- }
1203
- dotenvConfig({ path: filePath, quiet: true });
1204
- if (!("configYml" in paths)) {
1205
- halt("Fatal error, this should never happen");
1206
- throw new Error();
1207
- }
1208
- if (dryRunFlag) {
1209
- logTitle("\u{1F9EA} DRY RUN MODE - No actual changes will be made \u{1F9EA}");
1210
- }
1211
- assertTagValid(tag);
1212
- assertEpmsCredentials(paths.configYml);
1213
- const configContent = yaml2.load(readFileSync3(paths.configYml, "utf8"));
1214
- const accountUuidStage = resolveAccountUuidFromConfig(
1215
- configContent,
1216
- "epms_stage"
1217
- );
1218
- if (dryrun) {
1219
- logTitle(
1220
- `[DRY RUN] Would update EPMS for "${configName}" with tag "${tag}"`
1221
- );
1222
- } else {
1223
- if (accountUuidStage) {
1224
- const epmsClient = new EpmsClient(
1225
- EPMS_API_BASE_URL_STAGE,
1226
- process.env.EPMS_CLIENT_ID_STAGE,
1227
- process.env.EPMS_CLIENT_SECRET_STAGE
1228
- );
1229
- const organisationUuid = await epmsClient.getOrganisationIdByAccountUuid(accountUuidStage);
1230
- logTitle("Updating EPMS with the following details:");
1231
- const body = {
1232
- account_uuid: accountUuidStage,
1233
- organisation_uuid: organisationUuid,
1234
- configured_version: process.env.CORE_VERSION ?? "unknown",
1235
- read_only: false
1236
- };
1237
- logDataTable({
1238
- name: configName,
1239
- tag,
1240
- ...body
1241
- });
1242
- await epmsClient.updateTamaro(configName, tag, body);
1243
- logSuccess("\u2705 EPMS Stage is updated.");
1244
- }
1245
- }
1246
- };
1247
- var assertIsNotCore5 = (ifCore) => {
1248
- if (ifCore()) {
1249
- halt("You cannot update EPMS in the context of Tamaro Core.");
1250
- }
1251
- };
1252
-
1253
1024
  // package.json
1254
1025
  var package_default = {
1255
1026
  name: "@raisenow/tamaro-cli",
1256
- version: "1.6.0-dev.3",
1027
+ version: "1.6.1",
1257
1028
  author: {
1258
1029
  name: "RaiseNow",
1259
1030
  email: "development@raisenow.com"
@@ -1316,7 +1087,6 @@ var package_default = {
1316
1087
  "css-loader": "^7.1.3",
1317
1088
  "css-minimizer-webpack-plugin": "^7.0.4",
1318
1089
  dotenv: "^17.2.3",
1319
- "env-paths": "^4.0.0",
1320
1090
  "escape-string-regexp": "^5.0.0",
1321
1091
  eslint: "^8.57.1",
1322
1092
  "eslint-config-prettier": "^10.1.8",
@@ -1336,9 +1106,7 @@ var package_default = {
1336
1106
  "handlebars-helpers": "^0.10.0",
1337
1107
  "html-loader": "^5.1.0",
1338
1108
  "html-webpack-plugin": "^5.6.6",
1339
- "js-yaml": "^4.1.1",
1340
1109
  "json-loader": "^0.5.7",
1341
- ky: "^1.14.3",
1342
1110
  lodash: "^4.17.23",
1343
1111
  "mini-css-extract-plugin": "^2.10.0",
1344
1112
  "node-notifier": "^10.0.1",
@@ -1366,11 +1134,7 @@ var package_default = {
1366
1134
  "webpack-cli": "^6.0.1",
1367
1135
  "webpack-config-utils": "^2.3.1",
1368
1136
  "webpack-dev-server": "^5.2.3",
1369
- "yaml-loader": "^0.9.0",
1370
- zod: "^4.3.6"
1371
- },
1372
- devDependencies: {
1373
- "@types/js-yaml": "^4.0.9"
1137
+ "yaml-loader": "^0.9.0"
1374
1138
  }
1375
1139
  };
1376
1140
 
@@ -1459,7 +1223,7 @@ cli.command("deploy-email-config").description("Deploy a widget's email configur
1459
1223
  });
1460
1224
  cli.command("undeploy").description(
1461
1225
  "Undeploy a Tamaro Core or customer configuration bundle from AWS S3"
1462
- ).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--tag <tag>", "Tag which should be undeployed", DEFAULT_TAG).option("--all", "Undeploy all tags", false).option(
1226
+ ).option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--tag <tag>", "Tag which should be undeployed").option("--all", "Undeploy all tags", false).option(
1463
1227
  "--dryrun",
1464
1228
  "Displays the operations that would be performed without actually running them",
1465
1229
  false
@@ -1467,6 +1231,9 @@ cli.command("undeploy").description(
1467
1231
  await undeploy(options);
1468
1232
  });
1469
1233
  cli.command("undeploy-email-config").description("Undeploy a widget's email configuration from AWS S3").option("--profile <profile>", "AWS profile").option("--ci", "CI environment", false).option("--bucket <bucket>", "AWS bucket for email configs").option(
1234
+ "--stage",
1235
+ "Undeploy from stage environment (alternative to --bucket)"
1236
+ ).option("--prod", "Undeploy from prod environment (alternative to --bucket)").option(
1470
1237
  "--dryrun",
1471
1238
  "Displays the operations that would be performed without actually running them",
1472
1239
  false
@@ -1491,13 +1258,6 @@ cli.command("unarchive").description(
1491
1258
  ).action((options) => {
1492
1259
  unarchive(options);
1493
1260
  });
1494
- cli.command("update-epms").description("Update EPMS with the currently configured widget version.").option("--tag <tag>", "Tag which should be used for the update", DEFAULT_TAG).option(
1495
- "--dryrun",
1496
- "Displays the operations that would be performed without actually running them",
1497
- false
1498
- ).action(async (options) => {
1499
- await updateEpms(options);
1500
- });
1501
1261
  cli.command("validate").description(
1502
1262
  "Validate the current Tamaro configuration to avoid common errors"
1503
1263
  ).action(async () => {
@@ -10,7 +10,7 @@ import {
10
10
  logTitle,
11
11
  resolveApp,
12
12
  resolveEslintPluginConfig
13
- } from "./chunk-FI7KZAG6.js";
13
+ } from "./chunk-5D6F3T2J.js";
14
14
 
15
15
  // src/webpack.config.ts
16
16
  import { existsSync } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raisenow/tamaro-cli",
3
- "version": "1.6.0-dev.3",
3
+ "version": "1.6.1",
4
4
  "author": {
5
5
  "name": "RaiseNow",
6
6
  "email": "development@raisenow.com"
@@ -48,7 +48,6 @@
48
48
  "css-loader": "^7.1.3",
49
49
  "css-minimizer-webpack-plugin": "^7.0.4",
50
50
  "dotenv": "^17.2.3",
51
- "env-paths": "^4.0.0",
52
51
  "escape-string-regexp": "^5.0.0",
53
52
  "eslint": "^8.57.1",
54
53
  "eslint-config-prettier": "^10.1.8",
@@ -68,9 +67,7 @@
68
67
  "handlebars-helpers": "^0.10.0",
69
68
  "html-loader": "^5.1.0",
70
69
  "html-webpack-plugin": "^5.6.6",
71
- "js-yaml": "^4.1.1",
72
70
  "json-loader": "^0.5.7",
73
- "ky": "^1.14.3",
74
71
  "lodash": "^4.17.23",
75
72
  "mini-css-extract-plugin": "^2.10.0",
76
73
  "node-notifier": "^10.0.1",
@@ -98,11 +95,7 @@
98
95
  "webpack-cli": "^6.0.1",
99
96
  "webpack-config-utils": "^2.3.1",
100
97
  "webpack-dev-server": "^5.2.3",
101
- "yaml-loader": "^0.9.0",
102
- "zod": "^4.3.6"
103
- },
104
- "devDependencies": {
105
- "@types/js-yaml": "^4.0.9"
98
+ "yaml-loader": "^0.9.0"
106
99
  },
107
100
  "scripts": {
108
101
  "typecheck": "tsc --noEmit",