contensis-cli 1.1.2-beta.0 → 1.1.2-beta.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.
Files changed (47) hide show
  1. package/dist/factories/RequestHandlerFactory.js +203 -0
  2. package/dist/factories/RequestHandlerFactory.js.map +7 -0
  3. package/dist/localisation/en-GB.js +28 -5
  4. package/dist/localisation/en-GB.js.map +2 -2
  5. package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js +119 -0
  6. package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js.map +7 -0
  7. package/dist/providers/GitHubCliModuleProvider.js +107 -0
  8. package/dist/providers/GitHubCliModuleProvider.js.map +7 -0
  9. package/dist/providers/HttpProvider.js +72 -0
  10. package/dist/providers/HttpProvider.js.map +7 -0
  11. package/dist/providers/ManifestProvider.js +53 -0
  12. package/dist/providers/ManifestProvider.js.map +7 -0
  13. package/dist/providers/file-provider.js +11 -0
  14. package/dist/providers/file-provider.js.map +2 -2
  15. package/dist/services/ContensisAuthService.js +19 -11
  16. package/dist/services/ContensisAuthService.js.map +2 -2
  17. package/dist/services/ContensisCliService.js +27 -14
  18. package/dist/services/ContensisCliService.js.map +2 -2
  19. package/dist/services/ContensisDevService.js +10 -59
  20. package/dist/services/ContensisDevService.js.map +3 -3
  21. package/dist/util/debug.js +29 -0
  22. package/dist/util/debug.js.map +7 -0
  23. package/dist/util/fetch.js +65 -0
  24. package/dist/util/fetch.js.map +7 -0
  25. package/dist/util/index.js.map +1 -1
  26. package/dist/util/logger.js.map +2 -2
  27. package/dist/version.js +1 -1
  28. package/dist/version.js.map +1 -1
  29. package/package.json +4 -1
  30. package/src/factories/RequestHandlerFactory.ts +225 -0
  31. package/src/localisation/en-GB.ts +54 -12
  32. package/src/mappers/DevRequests-to-RequestHanderCliArgs.ts +145 -0
  33. package/src/providers/GitHubCliModuleProvider.ts +114 -0
  34. package/src/providers/HttpProvider.ts +50 -0
  35. package/src/providers/ManifestProvider.ts +43 -0
  36. package/src/providers/file-provider.ts +9 -0
  37. package/src/services/ContensisAuthService.ts +23 -14
  38. package/src/services/ContensisCliService.ts +30 -15
  39. package/src/services/ContensisDevService.ts +19 -85
  40. package/src/util/debug.ts +1 -0
  41. package/src/util/fetch.ts +74 -0
  42. package/src/util/index.ts +1 -1
  43. package/src/util/logger.ts +0 -1
  44. package/src/version.ts +1 -1
  45. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +0 -56
  46. package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +0 -7
  47. package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +0 -44
@@ -3,6 +3,17 @@ import { ClientGrants, ClientGrantType } from 'contensis-core-api';
3
3
 
4
4
  class ContensisAuthService {
5
5
  private client: NodejsClient;
6
+ private credentials: {
7
+ clientType: ClientGrantType;
8
+ clientDetails: ClientGrants;
9
+ };
10
+
11
+ get clientType() {
12
+ return this.credentials.clientType;
13
+ }
14
+ get clientDetails() {
15
+ return this.credentials.clientDetails;
16
+ }
6
17
 
7
18
  constructor({
8
19
  clientId = '',
@@ -21,39 +32,37 @@ class ContensisAuthService {
21
32
  projectId: string;
22
33
  rootUrl: string;
23
34
  }) {
24
- let credentials: {
25
- clientType: ClientGrantType;
26
- clientDetails: ClientGrants;
27
- };
28
- if (clientId && clientSecret) {
29
- credentials = {
35
+ if (clientId && clientSecret)
36
+ this.credentials = {
30
37
  clientType: 'client_credentials',
31
38
  clientDetails: {
32
39
  clientId,
33
40
  clientSecret,
34
41
  },
35
42
  };
36
- } else if (username && password) {
37
- credentials = {
43
+ else if (username && password)
44
+ this.credentials = {
38
45
  clientType: 'contensis_classic',
39
46
  clientDetails: {
40
47
  username,
41
48
  password,
42
49
  },
43
50
  };
44
- } else if (refreshToken) {
45
- credentials = {
51
+ else if (refreshToken)
52
+ this.credentials = {
46
53
  clientType: 'contensis_classic_refresh_token',
47
54
  clientDetails: {
48
55
  refreshToken,
49
56
  },
50
57
  };
51
- } else {
52
- credentials = { clientType: 'none', clientDetails: { refreshToken: '' } };
53
- }
58
+ else
59
+ this.credentials = {
60
+ clientType: 'none',
61
+ clientDetails: { refreshToken: '' },
62
+ };
54
63
 
55
64
  this.client = NodejsClient.create({
56
- ...credentials,
65
+ ...this.credentials,
57
66
  projectId,
58
67
  rootUrl,
59
68
  });
@@ -45,12 +45,13 @@ import {
45
45
  printNodesMigrateResult,
46
46
  } from '~/util/console.printer';
47
47
  import { csvFormatter } from '~/util/csv.formatter';
48
- import { xmlFormatter } from '~/util/xml.formatter';
49
48
  import { jsonFormatter, limitFields } from '~/util/json.formatter';
49
+ import { xmlFormatter } from '~/util/xml.formatter';
50
+ import { isDebug } from '~/util/debug';
50
51
  import { diffLogStrings } from '~/util/diff';
52
+ import { findByIdOrName } from '~/util/find';
51
53
  import { logError, Logger } from '~/util/logger';
52
54
  import { promiseDelay } from '~/util/timers';
53
- import { findByIdOrName } from '~/util/find';
54
55
 
55
56
  let insecurePasswordWarningShown = false;
56
57
 
@@ -72,6 +73,7 @@ class ContensisCli {
72
73
  contensis?: ContensisMigrationService;
73
74
  contensisOpts: Partial<MigrateRequest>;
74
75
  currentProject: string;
76
+ debug = isDebug();
75
77
 
76
78
  sourceAlias?: string;
77
79
  targetEnv?: string;
@@ -2048,7 +2050,7 @@ class ContensisCli {
2048
2050
  // Retrieve blocks list for env
2049
2051
  const [err, blocks] = await contensis.blocks.GetBlocks();
2050
2052
 
2051
- if (Array.isArray(blocks)) {
2053
+ if (Array.isArray(blocks) && blocks.length) {
2052
2054
  await this.HandleFormattingAndOutput(blocks, () => {
2053
2055
  // print the blocks to console
2054
2056
  log.success(messages.blocks.list(currentEnv, env.currentProject));
@@ -2082,8 +2084,8 @@ class ContensisCli {
2082
2084
  }
2083
2085
 
2084
2086
  if (err) {
2085
- log.error(messages.blocks.noList(currentEnv));
2086
- log.error(jsonFormatter(err));
2087
+ log.error(messages.blocks.noList(currentEnv, env.currentProject));
2088
+ // log.error(jsonFormatter(err));
2087
2089
  }
2088
2090
  }
2089
2091
  };
@@ -2103,11 +2105,29 @@ class ContensisCli {
2103
2105
  version
2104
2106
  );
2105
2107
 
2106
- if (blocks) {
2108
+ if (err || blocks?.length === 0) {
2109
+ log.warning(
2110
+ messages.blocks.noGet(
2111
+ blockId,
2112
+ branch,
2113
+ version,
2114
+ currentEnv,
2115
+ env.currentProject
2116
+ )
2117
+ );
2118
+ log.help(messages.blocks.noGetTip());
2119
+ // if (err) log.error(jsonFormatter(err));
2120
+ } else if (blocks) {
2107
2121
  await this.HandleFormattingAndOutput(blocks, () => {
2108
2122
  // print the version detail to console
2109
2123
  log.success(
2110
- messages.blocks.get(blockId, currentEnv, env.currentProject)
2124
+ messages.blocks.get(
2125
+ blockId,
2126
+ branch,
2127
+ version,
2128
+ currentEnv,
2129
+ env.currentProject
2130
+ )
2111
2131
  );
2112
2132
  for (const block of blocks)
2113
2133
  printBlockVersion(
@@ -2126,11 +2146,6 @@ class ContensisCli {
2126
2146
 
2127
2147
  return blocks;
2128
2148
  }
2129
-
2130
- if (err) {
2131
- log.error(messages.blocks.noList(currentEnv, env.currentProject));
2132
- log.error(jsonFormatter(err));
2133
- }
2134
2149
  }
2135
2150
  };
2136
2151
 
@@ -2454,9 +2469,7 @@ class ContensisCli {
2454
2469
  const contensis = await this.ConnectContensis();
2455
2470
  if (contensis) {
2456
2471
  // Retrieve renderers list for env
2457
- const [err, renderers] = await (contensis.renderers.GetRenderers as any)(
2458
- rendererId
2459
- ); // TODO: resolve any cast
2472
+ const [err, renderers] = await contensis.renderers.GetRenderers();
2460
2473
 
2461
2474
  if (Array.isArray(renderers)) {
2462
2475
  await this.HandleFormattingAndOutput(renderers, () => {
@@ -2487,6 +2500,7 @@ class ContensisCli {
2487
2500
  );
2488
2501
  }
2489
2502
  });
2503
+ return renderers;
2490
2504
  }
2491
2505
 
2492
2506
  if (err) {
@@ -2495,6 +2509,7 @@ class ContensisCli {
2495
2509
  }
2496
2510
  }
2497
2511
  };
2512
+
2498
2513
  HandleFormattingAndOutput = async <T>(obj: T, logFn: (obj: T) => void) => {
2499
2514
  const { format, log, messages, output } = this;
2500
2515
  const fields = this.contensis?.payload.query?.fields;
@@ -1,27 +1,25 @@
1
1
  import ansiEscapes from 'ansi-escapes';
2
2
  import to from 'await-to-js';
3
- import { spawn } from 'child_process';
4
3
  import inquirer from 'inquirer';
5
4
  import { createSpinner } from 'nanospinner';
6
- import path from 'path';
7
5
 
8
6
  import { Role } from 'contensis-management-api/lib/models';
9
7
  import { MigrateRequest } from 'migratortron';
10
8
 
11
9
  import ContensisRole from './ContensisRoleService';
10
+ import { createRequestHandler } from '~/factories/RequestHandlerFactory';
12
11
  import { OutputOptionsConstructorArg } from '~/models/CliService';
13
12
  import { EnvContentsToAdd } from '~/models/DevService';
14
- import { mapSiteConfigYaml } from '~/mappers/DevRequests-to-RequestHanderSiteConfigYaml';
15
13
  import { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';
14
+ import { requestHandlerCliArgs } from '~/mappers/DevRequests-to-RequestHanderCliArgs';
16
15
  import { deployKeyRole } from '~/mappers/DevInit-to-RolePermissions';
17
- import { appRootDir, readFile, writeFile } from '~/providers/file-provider';
16
+ import { readFile, writeFile } from '~/providers/file-provider';
18
17
  import { diffFileContent } from '~/util/diff';
19
18
  import { mergeDotEnvFileContents } from '~/util/dotenv';
20
19
  import { findByIdOrName } from '~/util/find';
21
20
  import { GitHelper } from '~/util/git';
22
21
  import { jsonFormatter } from '~/util/json.formatter';
23
22
  import { winSlash } from '~/util/os';
24
- import { stringifyYaml } from '~/util/yaml';
25
23
  import { mergeContentsToAddWithGitignore } from '~/util/gitignore';
26
24
 
27
25
  class ContensisDev extends ContensisRole {
@@ -413,90 +411,26 @@ class ContensisDev extends ContensisRole {
413
411
  }
414
412
  };
415
413
 
416
- ExecRequestHandler = async (blockIds: string[], overrideArgs?: string[]) => {
417
- // if no request handler exe
418
- // download it.
419
-
420
- // if update arg, redownload it
421
-
422
- const { log } = this;
423
- // const getPrefixOld = log.getPrefix;
424
- const exeHome = path.join(appRootDir, 'reqhan');
425
- const exe = 'Zengenti.Contensis.RequestHandler.LocalDevelopment';
426
- const exePath = path.join(exeHome, exe);
427
- const siteConfigPath = path.join(appRootDir, 'site_config.yaml');
428
-
429
- const siteConfig = await mapSiteConfigYaml(this);
430
- writeFile('site_config.yaml', stringifyYaml(siteConfig));
431
-
432
- const args = overrideArgs
433
- ? typeof overrideArgs?.[0] === 'string' &&
434
- overrideArgs[0].includes(' ', 2)
435
- ? overrideArgs[0].split(' ')
436
- : overrideArgs
437
- : []; // args could be [ '-c .\\site_config.yaml' ] or [ '-c', '.\\site_config.yaml' ]
438
-
439
- // Add required args
440
- if (!args.find(a => a === '-c')) args.push('-c', siteConfigPath);
441
-
442
- // const child = execFile(exePath, args);
443
-
444
- const child = spawn(exePath, args, { stdio: 'inherit' });
445
-
446
- // log.raw('');
447
- log.info(`Launching request handler...`);
448
- if (overrideArgs?.length)
449
- this.log.warning(
450
- `Spawning process with supplied args: ${JSON.stringify(
451
- child.spawnargs,
452
- null,
453
- 2
454
- )}`
455
- );
456
-
457
- let isRunning = false;
458
-
459
- // Log child output through event listeners
460
- child?.stdout?.on('data', data => {
461
- isRunning = true;
462
- log.raw(data);
463
- });
414
+ ExecRequestHandler = async (
415
+ blockIds: string[],
416
+ overrideArgs: string[] = []
417
+ ) => {
418
+ const { debug, log, messages } = this;
464
419
 
465
- child?.stderr?.on('data', data => {
466
- log.error(data);
467
- });
420
+ const spinner = !debug
421
+ ? createSpinner(messages.devrequests.launch())
422
+ : log.info(messages.devrequests.launch());
468
423
 
469
- child.on('spawn', () => {
470
- isRunning = true;
471
- log.help(
472
- `You may see a firewall popup requesting network access, it is safe to approve`
473
- );
474
- // log.getPrefix = () => Logger.infoText(`[rqh]`);
475
- });
476
-
477
- child.on('exit', code => {
478
- isRunning = false;
424
+ // Ensure request handler is available to use
425
+ const requestHandler = await createRequestHandler();
479
426
 
480
- log[code === 0 ? 'success' : 'warning'](
481
- `Request handler exited with code ${code}\n`
482
- );
483
- });
427
+ // Generate args for request handler using CLI methods
428
+ spinner?.start();
429
+ const args = await requestHandlerCliArgs(this, overrideArgs);
430
+ spinner?.success();
484
431
 
485
- child.on('error', error => {
486
- isRunning = false;
487
- log.error(`Could not launch request handler due to error \n${error}`);
488
- });
489
-
490
- await new Promise(resolve => setTimeout(resolve, 2000));
491
-
492
- // keep the method running until we can return
493
- while (true === true) {
494
- if (!isRunning) {
495
- // log.getPrefix = getPrefixOld; // restore logger state
496
- return;
497
- }
498
- await new Promise(resolve => setTimeout(resolve, 1000));
499
- }
432
+ // Launch request handler
433
+ await requestHandler(args);
500
434
  };
501
435
  }
502
436
  export const devCommand = (
@@ -0,0 +1 @@
1
+ export const isDebug = () => ['true', '1'].includes(process.env.debug || '');
@@ -0,0 +1,74 @@
1
+ import { DoRetry, FetchInit, fetchWithDefaults } from 'enterprise-fetch';
2
+ import { Logger } from './logger';
3
+
4
+ const retryPolicy = {
5
+ retries: 2,
6
+ minTimeout: 400,
7
+ factor: 2,
8
+ };
9
+
10
+ const applyTimeout = (s: number) =>
11
+ process.env.NODE_ENV === 'test' ? 2 * 1000 : s * 1000;
12
+
13
+ export const doRetry = ({ silent = false } = {}) => {
14
+ const fn: DoRetry = async (
15
+ attempt: number,
16
+ res: Response | AppError,
17
+ { url, options } = { url: '', options: {} }
18
+ ) => {
19
+ // Get the retry policy from options or fetchDefaults
20
+ const { retry = retryPolicy } = options || ({} as any);
21
+ let shouldRetry = false;
22
+
23
+ // Retry request on any network error, or 4xx or 5xx status codes
24
+ if (
25
+ !res.status ||
26
+ (res.status >= 400 && ![400, 404, 409, 422, 500].includes(res.status))
27
+ )
28
+ if (
29
+ !('message' in res) ||
30
+ ('message' in res &&
31
+ !(res.message as string).includes('Nock: No match'))
32
+ )
33
+ shouldRetry = true;
34
+
35
+ if (attempt <= retry.retries) {
36
+ // If a res has a status it is a HTTP error
37
+ // With no status it could be a fetch error or app error
38
+ const errorMessage = !res.status
39
+ ? `${('name' in res && res.name) || ('type' in res && res.type)}: ${
40
+ 'message' in res && res.message
41
+ }`
42
+ : `${res.status}: ${res.statusText}`;
43
+
44
+ if (!silent)
45
+ Logger.warning(
46
+ `[fetch] ${
47
+ shouldRetry
48
+ ? `attempt ${attempt}/${retry.retries}`
49
+ : 'non-retriable'
50
+ } ${errorMessage} ${url || ''}`
51
+ );
52
+ } else {
53
+ shouldRetry = false;
54
+ }
55
+ return await Promise.resolve(shouldRetry);
56
+ };
57
+ return fn;
58
+ };
59
+
60
+ const fetchDefaults = {
61
+ // The timeout to apply to requests that do not supply a timeout option
62
+ timeout: applyTimeout(60),
63
+ // Retry policy for all fetch requests
64
+ retry: retryPolicy,
65
+ // Do retry function to examine failures and apply custom retry logic
66
+ // return true to retry the fetch call
67
+ doRetry: doRetry(),
68
+ } as FetchInit;
69
+
70
+ export const enhancedFetch = fetchWithDefaults(fetchDefaults);
71
+ // export const assetFetch = fetchWithDefaults({
72
+ // ...fetchDefaults,
73
+ // timeout: applyTimeout(1200),
74
+ // });
package/src/util/index.ts CHANGED
@@ -16,7 +16,7 @@ export const tryParse = (str: any) => {
16
16
  }
17
17
  };
18
18
 
19
- export const isJson = (str: string) =>
19
+ export const isJson = (str?: string) =>
20
20
  typeof str === 'object' || !!tryParse(str);
21
21
 
22
22
  export const tryStringify = (obj: any) => {
@@ -57,7 +57,6 @@ export class Logger {
57
57
  else console.log(message);
58
58
  };
59
59
  static warning: LogMethod = content => {
60
- // if (process.env.DEBUG === 'true') {
61
60
  const message = `${Logger.getPrefix()} ${Logger.warningText(
62
61
  `${Logger.isUserTerminal ? '⚠️ ' : '[WARN]'} ${content}`
63
62
  )}\n`;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.1.2-beta.0";
1
+ export const LIB_VERSION = "1.1.2-beta.1";
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var DevRequests_to_RequestHanderSiteConfigYaml_exports = {};
20
- __export(DevRequests_to_RequestHanderSiteConfigYaml_exports, {
21
- mapSiteConfigYaml: () => mapSiteConfigYaml
22
- });
23
- module.exports = __toCommonJS(DevRequests_to_RequestHanderSiteConfigYaml_exports);
24
- const mapSiteConfigYaml = async (cli) => {
25
- var _a, _b;
26
- const credentials = await cli.GetCredentials(cli.env.lastUserId);
27
- const blocks = [];
28
- const blocksRaw = await cli.PrintBlocks();
29
- for (const block of blocksRaw || []) {
30
- const versions = await cli.PrintBlockVersions(
31
- block.id,
32
- "default",
33
- "latest"
34
- );
35
- if (versions == null ? void 0 : versions[0]) {
36
- blocks.push({
37
- id: versions[0].id,
38
- baseUri: versions[0].previewUrl
39
- });
40
- }
41
- }
42
- const siteConfig = {
43
- alias: cli.currentEnv,
44
- projectId: cli.currentProject,
45
- accessToken: "",
46
- clientId: ((_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.account) || "",
47
- sharedSecret: ((_b = credentials == null ? void 0 : credentials.current) == null ? void 0 : _b.password) || "",
48
- blocks
49
- };
50
- return siteConfig;
51
- };
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- mapSiteConfigYaml
55
- });
56
- //# sourceMappingURL=DevRequests-to-RequestHanderSiteConfigYaml.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts"],
4
- "sourcesContent": ["import ContensisCli from '~/services/ContensisCliService';\n\ninterface ISiteConfigYaml {\n alias: string;\n projectId: string;\n accessToken: string;\n clientId: string;\n sharedSecret: string;\n blocks: {\n id: string;\n baseUri: string;\n }[];\n}\n\nexport const mapSiteConfigYaml = async (cli: ContensisCli) => {\n const credentials = await cli.GetCredentials(cli.env.lastUserId);\n\n const blocks = [];\n const blocksRaw = await cli.PrintBlocks();\n\n for (const block of blocksRaw || []) {\n const versions = await cli.PrintBlockVersions(\n block.id,\n 'default',\n 'latest'\n );\n if (versions?.[0]) {\n blocks.push({\n id: versions[0].id,\n baseUri: versions[0].previewUrl,\n });\n }\n }\n\n const siteConfig: ISiteConfigYaml = {\n alias: cli.currentEnv,\n projectId: cli.currentProject,\n accessToken: '',\n clientId: credentials?.current?.account || '',\n sharedSecret: credentials?.current?.password || '',\n blocks,\n };\n return siteConfig;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,MAAM,oBAAoB,OAAO,QAAsB;AAd9D;AAeE,QAAM,cAAc,MAAM,IAAI,eAAe,IAAI,IAAI,UAAU;AAE/D,QAAM,SAAS,CAAC;AAChB,QAAM,YAAY,MAAM,IAAI,YAAY;AAExC,aAAW,SAAS,aAAa,CAAC,GAAG;AACnC,UAAM,WAAW,MAAM,IAAI;AAAA,MACzB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,IACF;AACA,QAAI,qCAAW,IAAI;AACjB,aAAO,KAAK;AAAA,QACV,IAAI,SAAS,GAAG;AAAA,QAChB,SAAS,SAAS,GAAG;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,aAA8B;AAAA,IAClC,OAAO,IAAI;AAAA,IACX,WAAW,IAAI;AAAA,IACf,aAAa;AAAA,IACb,YAAU,gDAAa,YAAb,mBAAsB,YAAW;AAAA,IAC3C,gBAAc,gDAAa,YAAb,mBAAsB,aAAY;AAAA,IAChD;AAAA,EACF;AACA,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,44 +0,0 @@
1
- import ContensisCli from '~/services/ContensisCliService';
2
-
3
- interface ISiteConfigYaml {
4
- alias: string;
5
- projectId: string;
6
- accessToken: string;
7
- clientId: string;
8
- sharedSecret: string;
9
- blocks: {
10
- id: string;
11
- baseUri: string;
12
- }[];
13
- }
14
-
15
- export const mapSiteConfigYaml = async (cli: ContensisCli) => {
16
- const credentials = await cli.GetCredentials(cli.env.lastUserId);
17
-
18
- const blocks = [];
19
- const blocksRaw = await cli.PrintBlocks();
20
-
21
- for (const block of blocksRaw || []) {
22
- const versions = await cli.PrintBlockVersions(
23
- block.id,
24
- 'default',
25
- 'latest'
26
- );
27
- if (versions?.[0]) {
28
- blocks.push({
29
- id: versions[0].id,
30
- baseUri: versions[0].previewUrl,
31
- });
32
- }
33
- }
34
-
35
- const siteConfig: ISiteConfigYaml = {
36
- alias: cli.currentEnv,
37
- projectId: cli.currentProject,
38
- accessToken: '',
39
- clientId: credentials?.current?.account || '',
40
- sharedSecret: credentials?.current?.password || '',
41
- blocks,
42
- };
43
- return siteConfig;
44
- };