@remkoj/optimizely-graph-cli 1.0.3 → 1.0.5
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.
- package/bin/index.js +156 -6
- package/package.json +6 -6
package/bin/index.js
CHANGED
|
@@ -83,7 +83,7 @@ function getFrontendURL(config) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
const publishToVercelModule$2 = {
|
|
86
|
-
command: ['register [path] [verb]'],
|
|
86
|
+
command: ['webhook:create [path] [verb]', 'wc [path] [verb]', 'register [path] [verb]'],
|
|
87
87
|
handler: async (args) => {
|
|
88
88
|
const cgConfig = getArgsConfig(args);
|
|
89
89
|
const frontendUrl = getFrontendURL(cgConfig);
|
|
@@ -164,7 +164,7 @@ const publishToVercelModule$2 = {
|
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
const publishToVercelModule$1 = {
|
|
167
|
-
command: ['unregister [path]'],
|
|
167
|
+
command: ['webhook:delete [path]', 'wd [path]', 'unregister [path]'],
|
|
168
168
|
handler: async (args) => {
|
|
169
169
|
const cgConfig = getArgsConfig(args);
|
|
170
170
|
const hookPath = args.path ?? '/';
|
|
@@ -245,7 +245,7 @@ const publishToVercelModule$1 = {
|
|
|
245
245
|
};
|
|
246
246
|
|
|
247
247
|
const publishToVercelModule = {
|
|
248
|
-
command: ['list'],
|
|
248
|
+
command: ['webhook:list', 'wl', 'list'],
|
|
249
249
|
handler: async (args) => {
|
|
250
250
|
const cgConfig = getArgsConfig(args);
|
|
251
251
|
if (!cgConfig.app_key || !cgConfig.secret)
|
|
@@ -284,7 +284,7 @@ const publishToVercelModule = {
|
|
|
284
284
|
|
|
285
285
|
const DEFAULT_CONFIG_FILE = "src/site-config.ts";
|
|
286
286
|
const createSiteConfigModule = {
|
|
287
|
-
command: ['site-config [file_path]'],
|
|
287
|
+
command: ['config:create [file_path]', 'cc [file_path]', 'site-config [file_path]'],
|
|
288
288
|
handler: async (args) => {
|
|
289
289
|
const cgConfig = getArgsConfig(args);
|
|
290
290
|
if (!cgConfig.app_key || !cgConfig.secret)
|
|
@@ -404,7 +404,157 @@ function siteQuery(site_url) {
|
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
const GraphSourceListCommand = {
|
|
408
|
+
command: ['source:list', 'sl'],
|
|
409
|
+
handler: async (args) => {
|
|
410
|
+
const cgConfig = getArgsConfig(args);
|
|
411
|
+
if (!cgConfig.app_key || !cgConfig.secret)
|
|
412
|
+
throw new Error("Make sure both the Optimizely Graph App Key & Secret have been defined");
|
|
413
|
+
const adminApi = createAdminApi(cgConfig);
|
|
414
|
+
try {
|
|
415
|
+
const currentSources = (await adminApi.definitionV3.getContentV3SourceHandler());
|
|
416
|
+
const sources = new Table({
|
|
417
|
+
head: [chalk.yellow(chalk.bold("ID")), chalk.yellow(chalk.bold("Label")), chalk.yellow(chalk.bold("Languages"))],
|
|
418
|
+
colWidths: [10, 50, 50]
|
|
419
|
+
});
|
|
420
|
+
for (const sourceDetails of currentSources) {
|
|
421
|
+
sources.push([sourceDetails.id, sourceDetails.label, sourceDetails.languages.join(', ')]);
|
|
422
|
+
}
|
|
423
|
+
process.stdout.write(sources.toString() + "\n");
|
|
424
|
+
process.stdout.write(chalk.green(chalk.bold(figures.tick + " Done")) + "\n");
|
|
425
|
+
}
|
|
426
|
+
catch (e) {
|
|
427
|
+
if (isApiError(e)) {
|
|
428
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an error: HTTP ${e.status}: ${e.statusText}`) + "\n");
|
|
429
|
+
if (args.verbose)
|
|
430
|
+
console.error(chalk.redBright(JSON.stringify(e.body, undefined, 4)));
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an unknown error`) + "\n");
|
|
434
|
+
if (args.verbose)
|
|
435
|
+
console.error(chalk.redBright(e));
|
|
436
|
+
}
|
|
437
|
+
process.exitCode = 1;
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
aliases: [],
|
|
442
|
+
describe: "List all content sources in Optimizely Graph",
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const GraphSourceClearCommand = {
|
|
446
|
+
command: ['source:clear [sourceId]', 'sc [sourceId]'],
|
|
447
|
+
handler: async (args) => {
|
|
448
|
+
const cgConfig = getArgsConfig(args);
|
|
449
|
+
if (!cgConfig.app_key || !cgConfig.secret)
|
|
450
|
+
throw new Error("Make sure both the Optimizely Graph App Key & Secret have been defined");
|
|
451
|
+
const sourceId = args.sourceId;
|
|
452
|
+
if (!sourceId) {
|
|
453
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Missing source ID, invoke with --help for more details`) + "\n");
|
|
454
|
+
return process.exit(1);
|
|
455
|
+
}
|
|
456
|
+
const adminApi = createAdminApi(cgConfig);
|
|
457
|
+
try {
|
|
458
|
+
process.stdout.write(`${chalk.yellow(chalk.bold(figures.arrowRight))} Loading content source: ${chalk.yellow(sourceId)}\n`);
|
|
459
|
+
const contentSource = (await adminApi.definitionV3.getContentV3SourceHandler(sourceId))[0];
|
|
460
|
+
if (!(contentSource && contentSource.id == sourceId)) {
|
|
461
|
+
throw new Error("An incorrect content source was returned by Optimizely Graph");
|
|
462
|
+
}
|
|
463
|
+
process.stdout.write(`${chalk.yellow(chalk.bold(figures.arrowRight))} Removing all content from ${chalk.yellow(contentSource.label)} (Languages: ${chalk.yellow(contentSource.languages.join(', '))})\n`);
|
|
464
|
+
await adminApi.definitionV2.deleteContentV2DataHandler(sourceId, contentSource.languages);
|
|
465
|
+
process.stdout.write(chalk.green(chalk.bold(figures.tick + " Done")) + "\n");
|
|
466
|
+
}
|
|
467
|
+
catch (e) {
|
|
468
|
+
if (isApiError(e)) {
|
|
469
|
+
if (e.status == 404) {
|
|
470
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph Source with ID ${sourceId} does not exist`) + "\n");
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an error: HTTP ${e.status}: ${e.statusText}`) + "\n");
|
|
474
|
+
}
|
|
475
|
+
if (args.verbose)
|
|
476
|
+
console.error(chalk.redBright(JSON.stringify(e.body, undefined, 4)));
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an unknown error`) + "\n");
|
|
480
|
+
if (args.verbose)
|
|
481
|
+
console.error(chalk.redBright(e));
|
|
482
|
+
}
|
|
483
|
+
process.exitCode = 1;
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
aliases: [],
|
|
488
|
+
builder: (args) => {
|
|
489
|
+
args.positional('sourceId', { type: "string", describe: "The source to clear", demandOption: true });
|
|
490
|
+
return args;
|
|
491
|
+
},
|
|
492
|
+
describe: "Remove all data for the specified source",
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const GraphSourceRemoveCommand = {
|
|
496
|
+
command: ['source:delete [sourceId]', 'sd [sourceId]'],
|
|
497
|
+
handler: async (args) => {
|
|
498
|
+
const cgConfig = getArgsConfig(args);
|
|
499
|
+
if (!cgConfig.app_key || !cgConfig.secret)
|
|
500
|
+
throw new Error("Make sure both the Optimizely Graph App Key & Secret have been defined");
|
|
501
|
+
const sourceId = args.sourceId;
|
|
502
|
+
if (!sourceId) {
|
|
503
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Missing source ID, invoke with --help for more details`) + "\n");
|
|
504
|
+
return process.exit(1);
|
|
505
|
+
}
|
|
506
|
+
const adminApi = createAdminApi(cgConfig);
|
|
507
|
+
try {
|
|
508
|
+
process.stdout.write(`${chalk.yellow(chalk.bold(figures.arrowRight))} Loading content source: ${chalk.yellow(sourceId)}\n`);
|
|
509
|
+
const contentSource = (await adminApi.definitionV3.getContentV3SourceHandler(sourceId))[0];
|
|
510
|
+
if (!(contentSource && contentSource.id == sourceId)) {
|
|
511
|
+
throw new Error("An incorrect content source was returned by Optimizely Graph");
|
|
512
|
+
}
|
|
513
|
+
process.stdout.write(`${chalk.yellow(chalk.bold(figures.arrowRight))} Removing all content from ${chalk.yellow(contentSource.label)} (Languages: ${chalk.yellow(contentSource.languages.join(', '))})\n`);
|
|
514
|
+
await adminApi.definitionV2.deleteContentV2DataHandler(sourceId, contentSource.languages);
|
|
515
|
+
process.stdout.write(`${chalk.yellow(chalk.bold(figures.arrowRight))} Removing source ${chalk.yellow(contentSource.label)}\n`);
|
|
516
|
+
await adminApi.definitionV3.deleteContentV3SourceHandler(sourceId);
|
|
517
|
+
process.stdout.write(chalk.green(chalk.bold(figures.tick + " Done")) + "\n");
|
|
518
|
+
}
|
|
519
|
+
catch (e) {
|
|
520
|
+
if (isApiError(e)) {
|
|
521
|
+
if (e.status == 404) {
|
|
522
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph Source with ID ${sourceId} does not exist`) + "\n");
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an error: HTTP ${e.status}: ${e.statusText}`) + "\n");
|
|
526
|
+
}
|
|
527
|
+
if (args.verbose)
|
|
528
|
+
console.error(chalk.redBright(JSON.stringify(e.body, undefined, 4)));
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
process.stderr.write(chalk.redBright(`${chalk.bold(figures.cross)} Optimizely Graph returned an unknown error`) + "\n");
|
|
532
|
+
if (args.verbose)
|
|
533
|
+
console.error(chalk.redBright(e));
|
|
534
|
+
}
|
|
535
|
+
process.exitCode = 1;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
aliases: [],
|
|
540
|
+
builder: (args) => {
|
|
541
|
+
args.positional('sourceId', { type: "string", describe: "The source to clear", demandOption: true });
|
|
542
|
+
return args;
|
|
543
|
+
},
|
|
544
|
+
describe: "Remove all data for the specified source",
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
var SourceModules = /*#__PURE__*/Object.freeze({
|
|
548
|
+
__proto__: null,
|
|
549
|
+
GraphSourceClearCommand: GraphSourceClearCommand,
|
|
550
|
+
GraphSourceListCommand: GraphSourceListCommand,
|
|
551
|
+
GraphSourceRemoveCommand: GraphSourceRemoveCommand
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
const modules = [publishToVercelModule$2, publishToVercelModule$1, publishToVercelModule, createSiteConfigModule];
|
|
555
|
+
for (const moduleName of Object.getOwnPropertyNames(SourceModules)) {
|
|
556
|
+
modules.push(SourceModules[moduleName]);
|
|
557
|
+
}
|
|
408
558
|
|
|
409
559
|
var APP;
|
|
410
560
|
(function (APP) {
|
|
@@ -412,5 +562,5 @@ var APP;
|
|
|
412
562
|
APP["Version"] = "1.0.3";
|
|
413
563
|
})(APP || (APP = {}));
|
|
414
564
|
const app = createCliApp(APP.Script, APP.Version);
|
|
415
|
-
app.command(
|
|
565
|
+
app.command(modules);
|
|
416
566
|
app.parse(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
4
4
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
5
5
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.5",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"packageManager": "yarn@4.1.1",
|
|
9
9
|
"type": "module",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"bundle": "yarn rollup --config rollup.config.js"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@remkoj/optimizely-graph-client": "1.0.
|
|
30
|
+
"@remkoj/optimizely-graph-client": "1.0.5",
|
|
31
31
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
32
32
|
"@rollup/plugin-json": "^6.1.0",
|
|
33
33
|
"@rollup/pluginutils": "^5.1.0",
|
|
34
34
|
"@types/crypto-js": "^4.2.2",
|
|
35
35
|
"@types/glob": "^8.1.0",
|
|
36
|
-
"@types/node": "^20.12.
|
|
36
|
+
"@types/node": "^20.12.6",
|
|
37
37
|
"@types/source-map-support": "^0.5.10",
|
|
38
38
|
"@types/yargs": "^17.0.32",
|
|
39
|
-
"rollup": "^4.14.
|
|
39
|
+
"rollup": "^4.14.1",
|
|
40
40
|
"source-map-support": "^0.5.21",
|
|
41
41
|
"tslib": "^2.6.2",
|
|
42
|
-
"typescript": "^5.4.
|
|
42
|
+
"typescript": "^5.4.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"chalk": "^5.3.0",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"yargs": "^17.7.2"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@remkoj/optimizely-graph-client": "1.0.
|
|
53
|
+
"@remkoj/optimizely-graph-client": "1.0.5"
|
|
54
54
|
}
|
|
55
55
|
}
|