@snowplow/snowtype 0.1.1 → 0.1.2

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.
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchAction = void 0;
4
- const command_utils_1 = require("../../command-utils");
5
- const errors_1 = require("../../errors");
6
- const generate_1 = require("./generate");
7
- const utils_1 = require("./utils");
8
- const dispatch_1 = require("./dispatch");
9
- const defaultOptions = {
10
- trackingScenarioIds: [],
11
- dataStructures: [],
12
- igluCentralSchemas: [],
13
- yes: false
14
- };
15
- function checkPatchOptions(options, logger) {
16
- const patchOptions = { ...defaultOptions, ...options };
17
- if (Object.values(patchOptions).every((v) => typeof v === 'boolean' || v.length === 0)) {
18
- throw new errors_1.SnowtypeMissingOptionsError();
19
- }
20
- logger.debug("Checking for existing configuration..");
21
- (0, utils_1.guardConfigExistsValid)();
22
- logger.success("Valid configuration found");
23
- return patchOptions;
24
- }
25
- function execPatch(apiKey, logger, spinner, options) {
26
- const patchOptions = checkPatchOptions(options, logger);
27
- logger.debug("Starting patch process with options: ".concat(JSON.stringify(patchOptions)));
28
- const patchEntries = Object.entries(patchOptions);
29
- patchEntries.forEach(([key, value]) => {
30
- if (key !== "yes" && Array.isArray(value) && value.length !== 0) {
31
- value.forEach((element) => {
32
- (0, command_utils_1.addConfigAttribute)(key, element);
33
- });
34
- }
35
- });
36
- logger.success("Configuration patched");
37
- if (patchOptions.yes === true) {
38
- return (0, generate_1.execGenerate)(apiKey, logger, spinner);
39
- }
40
- else {
41
- logger.log("Code is not generated yet for the patched configuration");
42
- }
43
- return Promise.resolve(undefined);
44
- }
45
- exports.patchAction = (0, dispatch_1.act)(execPatch);
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSelectPrompt = exports.isConfirmPrompt = exports.isPasswordPrompt = exports.isInputPrompt = void 0;
4
- function isInputPrompt(p) {
5
- return p.type === 'input';
6
- }
7
- exports.isInputPrompt = isInputPrompt;
8
- function isPasswordPrompt(p) {
9
- return p.type === 'password';
10
- }
11
- exports.isPasswordPrompt = isPasswordPrompt;
12
- function isConfirmPrompt(p) {
13
- return p.type === 'confirm';
14
- }
15
- exports.isConfirmPrompt = isConfirmPrompt;
16
- function isSelectPrompt(p) {
17
- return p.type === 'select';
18
- }
19
- exports.isSelectPrompt = isSelectPrompt;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateAction = void 0;
4
- const process_1 = require("process");
5
- const path_1 = require("path");
6
- const api_1 = require("../../api");
7
- const command_utils_1 = require("../../command-utils");
8
- const errors_1 = require("../../errors");
9
- const utils_1 = require("./utils");
10
- const constants_1 = require("./constants");
11
- const generate_1 = require("./generate");
12
- const dispatch_1 = require("./dispatch");
13
- const defaultOptions = {
14
- yes: false
15
- };
16
- function checkUpdateOptions(options, logger) {
17
- // check**Updates
18
- // says if/diff available update
19
- // if not force (just show)
20
- // if force .. generate
21
- const updateOptions = { ...defaultOptions, ...options };
22
- logger.debug("Checking for existing configuration..");
23
- (0, utils_1.guardConfigExistsValid)();
24
- logger.success("Valid configuration found");
25
- return updateOptions;
26
- }
27
- async function execUpdate(apiKey, logger, spinner, options) {
28
- const updateOptions = checkUpdateOptions(options, logger);
29
- logger.debug("Starting update process with options: ".concat(JSON.stringify(updateOptions)));
30
- // guarded config exists and valid
31
- const config = (0, utils_1.getConfig)();
32
- const lockPath = (0, path_1.resolve)((0, process_1.cwd)(), config.outpath, constants_1.DEFAULT_STORAGE_FILENAME);
33
- const api = new api_1.ConsoleAPI({
34
- apiKey,
35
- organizationId: config.organizationId,
36
- });
37
- spinner.setSpinnerTitle("Checking for updates...");
38
- if (spinner.isSpinning() === false) {
39
- spinner.start();
40
- }
41
- let tsUpdates = {};
42
- if (!(0, utils_1.fileExists)(lockPath) && config.trackingScenarioIds.length) {
43
- throw new errors_1.SnowtypeMissingLockError();
44
- }
45
- else if ((0, utils_1.fileExists)(lockPath) && config.trackingScenarioIds.length) {
46
- const latestGenerationConfig = (0, utils_1.getSnowtypeLock)(lockPath);
47
- tsUpdates = (await (0, command_utils_1.checkScenarioUpdates)(api, config.trackingScenarioIds, latestGenerationConfig));
48
- }
49
- const dsUpdates = await (0, command_utils_1.checkDataStructureUpdates)(api, config.dataStructures);
50
- const dsToUpdate = dsUpdates.filter((upd) => upd.previous !== upd.next);
51
- const update = Object.entries(tsUpdates).length > 0 || dsToUpdate.length > 0;
52
- if (update === true) {
53
- logger.success("Available updates found!");
54
- (0, utils_1.presentAvailableUpdates)(tsUpdates, dsToUpdate, logger);
55
- if (updateOptions.yes === true) {
56
- if (dsToUpdate.length > 0) {
57
- dsToUpdate.forEach((upd) => {
58
- const idx = config.dataStructures.indexOf(upd.previous);
59
- config.dataStructures[idx] = upd.next;
60
- });
61
- (0, utils_1.writeConfigToFile)(config);
62
- }
63
- logger.debug("Applying the updates..");
64
- return (0, generate_1.execGenerate)(apiKey, logger, spinner);
65
- }
66
- else {
67
- logger.log("No updates applied");
68
- logger.log("To apply the available updates run update with --yes flag");
69
- }
70
- }
71
- else {
72
- logger.success("No updates found. Everything is up-to-date!");
73
- }
74
- return Promise.resolve(undefined);
75
- }
76
- exports.updateAction = (0, dispatch_1.act)(execUpdate);
@@ -1,213 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isEmpty = exports.getGlobalOptions = exports.presentAvailableUpdates = exports.mkDataStructures = exports.mkIgluSchemas = exports.writeLockFile = exports.mkDataProducts = exports.getExtension = exports.guardConfigNotExistsValid = exports.guardConfigExistsValid = exports.getSnowtypeLock = exports.getConfig = exports.readFile = exports.fileExists = exports.writeConfigToFile = exports.completeInitConfig = exports.isValidLanguage = exports.isValidTracker = exports.isNonEmpty = void 0;
18
- const process_1 = require("process");
19
- const path_1 = require("path");
20
- const fs_1 = require("fs");
21
- const api_1 = require("../../../api");
22
- const errors_1 = require("../../../errors");
23
- const constants_1 = require("../constants");
24
- const config_1 = require("../../../config");
25
- __exportStar(require("./ui"), exports);
26
- const validTrackers = { ...constants_1.TRACKER_LANGUAGES };
27
- const defaultConfigPath = `./${constants_1.DEFAULT_CONFIG_NAME}`;
28
- function isNonEmpty(str) {
29
- return str.length !== 0;
30
- }
31
- exports.isNonEmpty = isNonEmpty;
32
- function isValidTracker(tracker) {
33
- return Array.isArray(validTrackers[tracker]);
34
- }
35
- exports.isValidTracker = isValidTracker;
36
- function isValidLanguage(tracker, language) {
37
- const validLangChoices = validTrackers[tracker];
38
- if (!Array.isArray(validLangChoices)) {
39
- return false;
40
- }
41
- const validLangs = validLangChoices.map((l) => l.value);
42
- return !!validLangs.includes(language);
43
- }
44
- exports.isValidLanguage = isValidLanguage;
45
- function completeInitConfig(initOpts) {
46
- const initOptions = {
47
- organizationId: initOpts.organizationId,
48
- tracker: initOpts.tracker,
49
- language: initOpts.language,
50
- outpath: initOpts.outpath,
51
- };
52
- const initOmitted = {
53
- igluCentralSchemas: [],
54
- dataStructures: [],
55
- trackingScenarioIds: [],
56
- };
57
- return Object.assign(initOmitted, initOptions);
58
- }
59
- exports.completeInitConfig = completeInitConfig;
60
- function writeConfigToFile(config) {
61
- const resolvedPath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
62
- return (0, fs_1.writeFileSync)(resolvedPath, JSON.stringify(config, null, 2));
63
- }
64
- exports.writeConfigToFile = writeConfigToFile;
65
- function fileExists(path) {
66
- const stat = (0, fs_1.statSync)(path, { throwIfNoEntry: false });
67
- if (stat === undefined) {
68
- return false;
69
- }
70
- return stat.isFile();
71
- }
72
- exports.fileExists = fileExists;
73
- function readFile(path) {
74
- return (0, fs_1.readFileSync)(path, { encoding: "utf-8" });
75
- }
76
- exports.readFile = readFile;
77
- function getConfig() {
78
- const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
79
- return JSON.parse(readFile(truePath));
80
- }
81
- exports.getConfig = getConfig;
82
- function getSnowtypeLock(path) {
83
- return JSON.parse(readFile(path));
84
- }
85
- exports.getSnowtypeLock = getSnowtypeLock;
86
- function guardConfigExistsValid() {
87
- const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
88
- if (fileExists(truePath) === false) {
89
- throw new errors_1.SnowtypeConfigMissingError();
90
- }
91
- const cfg = JSON.parse(readFile(truePath));
92
- return (0, config_1.validateConfig)(cfg);
93
- }
94
- exports.guardConfigExistsValid = guardConfigExistsValid;
95
- function guardConfigNotExistsValid() {
96
- const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
97
- if (fileExists(truePath) === true) {
98
- const cfg = readFile(truePath);
99
- try {
100
- (0, config_1.validateConfig)(JSON.parse(cfg));
101
- // if we are here, means a valid config exists already, so guard fails
102
- throw new errors_1.SnowtypeConfigExistsError();
103
- }
104
- catch (err) {
105
- // if we caught what we just thrown
106
- if (err instanceof errors_1.SnowtypeConfigExistsError) {
107
- throw err;
108
- }
109
- // else means invalid config exists, so guard proceeds ok
110
- }
111
- }
112
- return;
113
- }
114
- exports.guardConfigNotExistsValid = guardConfigNotExistsValid;
115
- function getExtension(langId) {
116
- const langExtMap = {
117
- javascript: ".js",
118
- typescript: ".ts",
119
- kotlin: ".kt",
120
- swift: ".swift",
121
- go: ".go",
122
- };
123
- return langExtMap[langId] || "";
124
- }
125
- exports.getExtension = getExtension;
126
- async function mkDataProducts(api, scenarios) {
127
- const dataProducts = [];
128
- for (const scenarioId of scenarios) {
129
- const scenario = await api.fetchTrackingScenario({ scenarioId });
130
- const scenarioName = scenario.data[0]?.name;
131
- const scenarioVersion = scenario.data[0]?.version;
132
- const event = scenario.data[0]?.event;
133
- const eventSchema = await api.fetchSchemaVersion({
134
- schema: event?.source || "",
135
- });
136
- const entitiesSchemas = [];
137
- const entitySchemasToFetch = [];
138
- scenario.data[0]?.entities?.tracked?.forEach((entity) => entitySchemasToFetch.push(entity.source));
139
- await Promise.all(entitySchemasToFetch.map(async (schemaUrl) => {
140
- const entitySchema = await api.fetchSchemaVersion({
141
- schema: schemaUrl,
142
- });
143
- entitiesSchemas.push(entitySchema);
144
- }));
145
- dataProducts.push({
146
- scenario: { name: scenarioName || "", id: scenarioId },
147
- version: scenarioVersion || 0,
148
- eventSchema,
149
- entitiesSchemas,
150
- });
151
- }
152
- return dataProducts;
153
- }
154
- exports.mkDataProducts = mkDataProducts;
155
- function writeLockFile(dataProducts, outpath) {
156
- const storage = {
157
- trackingScenarios: {},
158
- };
159
- dataProducts.forEach((dp) => {
160
- storage.trackingScenarios[dp.scenario.id] = dp.version;
161
- });
162
- const truePath = (0, path_1.resolve)((0, process_1.cwd)(), outpath, constants_1.DEFAULT_STORAGE_FILENAME);
163
- try {
164
- (0, fs_1.writeFileSync)(truePath, JSON.stringify(storage, null, 2));
165
- }
166
- catch (error) {
167
- throw new errors_1.SnowtypeWriteLockError();
168
- }
169
- }
170
- exports.writeLockFile = writeLockFile;
171
- async function mkIgluSchemas(igluSchemas) {
172
- const igluCentralSchemas = await Promise.all(igluSchemas.map(async (schemaUrl) => JSON.parse(await (0, api_1.fetchIgluCentralSchema)({ schema: schemaUrl }))));
173
- return igluCentralSchemas;
174
- }
175
- exports.mkIgluSchemas = mkIgluSchemas;
176
- async function mkDataStructures(api, dsa) {
177
- const dataStructureSchemas = await Promise.all(dsa.map((dataStructureUrl) => api.fetchSchemaVersion({ schema: dataStructureUrl })));
178
- return dataStructureSchemas;
179
- }
180
- exports.mkDataStructures = mkDataStructures;
181
- function presentAvailableUpdates(tsUpdates, dsUpdates, logger) {
182
- const tsUpdatesEntries = Object.entries(tsUpdates);
183
- if (tsUpdatesEntries.length > 0) {
184
- logger.success("Available Tracking Scenario Updates");
185
- }
186
- tsUpdatesEntries.forEach(([key, value]) => {
187
- const current = `${key}: version ${value.previous}`;
188
- const next = `${key}: version ${value.next}`;
189
- logger.diff(current, next);
190
- });
191
- if (dsUpdates.length > 0) {
192
- logger.success("Available Data Structures Updates");
193
- }
194
- dsUpdates.forEach((schemaUpdate) => {
195
- const current = `${schemaUpdate.previous}`;
196
- const next = `${schemaUpdate.next}`;
197
- logger.diff(current, next);
198
- });
199
- return undefined;
200
- }
201
- exports.presentAvailableUpdates = presentAvailableUpdates;
202
- function getGlobalOptions(cmd) {
203
- const cmdGlobals = cmd.optsWithGlobals();
204
- return {
205
- ...cmdGlobals,
206
- apiKey: cmdGlobals.apiKey || process.env['SNOWPLOW_CONSOLE_API_KEY']
207
- };
208
- }
209
- exports.getGlobalOptions = getGlobalOptions;
210
- function isEmpty(arr) {
211
- return Boolean(Array.isArray(arr) && !arr.length);
212
- }
213
- exports.isEmpty = isEmpty;
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.renderDiff = exports.renderErrorMessage = exports.renderDebug = exports.renderLog = exports.renderWarn = exports.renderSuccess = exports.renderHelp = exports.createSpinner = void 0;
7
- const cli_spinner_1 = require("cli-spinner");
8
- const chalk_1 = __importDefault(require("chalk"));
9
- function createSpinner() {
10
- const spinner = new cli_spinner_1.Spinner();
11
- spinner.setSpinnerString(18);
12
- return spinner;
13
- }
14
- exports.createSpinner = createSpinner;
15
- const website = "https://snowplow.io";
16
- const docs = "https://docs.snowplow.io/docs/collecting-data/code-generation/";
17
- const icons = {
18
- SUCCESS: "✔",
19
- LOG: "ℹ",
20
- DEBUG: "➤",
21
- ERROR: "✗",
22
- WARN: "⚠",
23
- };
24
- const colors = {
25
- LINK: "#9911BB",
26
- OPTION: "#9911DD",
27
- };
28
- function renderLink(link) {
29
- return chalk_1.default.hex(colors.LINK).bold(link);
30
- }
31
- function renderOption(option) {
32
- return chalk_1.default.hex(colors.OPTION).italic(option);
33
- }
34
- function renderHeader(headerType, headerContent) {
35
- switch (headerType) {
36
- case "h1":
37
- return chalk_1.default.bold.underline(headerContent);
38
- default:
39
- return chalk_1.default.bold(headerContent);
40
- }
41
- }
42
- function renderHelp() {
43
- const helpText = `
44
- ${renderHeader("h1", "CLI Help")}
45
-
46
- For more information visit the Snowplow website ${renderLink(website)}
47
-
48
- For details see the CLI documentation ${renderLink(docs)}
49
-
50
- ${renderHeader("h2", "How to get started")}
51
- 1. Use ${chalk_1.default.cyanBright('snowtype init')} to initialize the setup.
52
- 2. Use ${chalk_1.default.cyanBright('snowtype patch')} to add a Data Structure or Tracking Scenario.
53
- 3. Use ${chalk_1.default.cyanBright('snowtype generate')} to generate tracking code.
54
-
55
- ${renderHeader("h2", "Available commands")}
56
- To learn more about each CLI command, use the ${renderOption("--help")} option, for example, ${renderOption("snowtype init --help")}.
57
-
58
- ${renderOption("snowtype init")}
59
- Initialize the setup of Snowtype code generation in a project. Creates the \`snowtype.config.json\` file.
60
-
61
- ${renderOption("snowtype patch")}
62
- Adds new Data Structures and Tracking Scenarios in the \`snowtype.config.json\` file.
63
-
64
- ${renderOption("snowtype generate")}
65
- Generates tracking code based on configuration on the \`snowtype.config.json\` file.
66
-
67
- ${renderOption("snowtype update")}
68
- Checks for latest version updates in Data Structures and Tracking Scenarios.
69
-
70
- ${renderHeader("h2", "Debug")}
71
- Use the ${renderOption("-v")} to output verbose logs
72
- `;
73
- return helpText;
74
- }
75
- exports.renderHelp = renderHelp;
76
- function renderSuccess(msg) {
77
- const successMsg = `${icons.SUCCESS}: `;
78
- return chalk_1.default.cyanBright(successMsg) + msg;
79
- }
80
- exports.renderSuccess = renderSuccess;
81
- function renderWarn(msg) {
82
- const successMsg = `${icons.WARN} Warning: `;
83
- return chalk_1.default.hex("#FFA500")(successMsg) + msg;
84
- }
85
- exports.renderWarn = renderWarn;
86
- function renderLog(msg) {
87
- const logMsg = `${icons.LOG} ${msg}`;
88
- return chalk_1.default.yellowBright(logMsg);
89
- }
90
- exports.renderLog = renderLog;
91
- function renderDebug(msg) {
92
- const debugMsg = `${icons.DEBUG} Debug: `;
93
- return chalk_1.default.magenta(debugMsg) + msg;
94
- }
95
- exports.renderDebug = renderDebug;
96
- function renderErrorMessage(msg) {
97
- const errorMsg = `${icons.ERROR} Error: `;
98
- return chalk_1.default.redBright(errorMsg) + msg;
99
- }
100
- exports.renderErrorMessage = renderErrorMessage;
101
- function renderDiff(current, next) {
102
- const minus = `- ${current}`;
103
- const plus = `+ ${next}`;
104
- const diff = `
105
- ${chalk_1.default.magenta(minus)}
106
- ${chalk_1.default.cyanBright(plus)}
107
- `;
108
- return diff;
109
- }
110
- exports.renderDiff = renderDiff;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.main = void 0;
27
- const process = __importStar(require("process"));
28
- const extra_typings_1 = require("@commander-js/extra-typings");
29
- const actions_1 = require("./actions");
30
- const utils_1 = require("./actions/utils");
31
- const version_1 = require("../version");
32
- async function main() {
33
- await import("dotenv/config");
34
- const program = new extra_typings_1.Command();
35
- program.exitOverride();
36
- program
37
- .version(version_1.PKG_VERSION, undefined, "Snowtype CLI version number")
38
- .name("snowtype")
39
- .description("The Snowtype CLI is a tool which aims to speed up tracking implementations, provide type safety and inline documentation for developers and ultimately reduce the number of erroneous events.")
40
- .showHelpAfterError()
41
- .configureHelp({ showGlobalOptions: true })
42
- .option("-k, --apiKey <string>", "Snowplow Console API key")
43
- .option("-v, --verbose", "Enable verbose logging");
44
- program
45
- .command("init")
46
- .description("Initialize the setup of Snowtype code generation in a project. Creates the `snowtype.config.json` file.")
47
- .option("-i, --organizationId <string>", "organization ID")
48
- .option("-t, --tracker <string>", "tracker to use")
49
- .option("-l, --language <string>", "language to use")
50
- .option("-o, --outpath <string>", "output path")
51
- .action(actions_1.initAction);
52
- program
53
- .command("update")
54
- .description("Checks for latest version updates in Data Structures and Tracking Scenarios.")
55
- .option("-y, --yes", "updates all to latest without asking", false)
56
- .action(actions_1.updateAction);
57
- // generate
58
- // - Does the codegen based on snowtype.config.json
59
- program
60
- .command("generate")
61
- .description("Generates tracking code based on configuration on the `snowtype.config.json` file.")
62
- .action(actions_1.generateAction);
63
- // patch
64
- // - options to specify TS ID, DS URI, IgluCentral URI
65
- // - This will add an entry to the corresponding array in snowtype.config.json
66
- program
67
- .command("patch")
68
- .description("Adds new Data Structures and Tracking Scenarios in the `snowtype.config.json` file.")
69
- .option("-t, --trackingScenarioIds [value...]", "tracking scenario ID")
70
- .option("-d, --dataStructures [value...]", "data structure URI")
71
- .option("-i, --igluCentralSchemas [value...]", "iglu central URI")
72
- .option("-y, --yes", "updates all to latest without asking", false)
73
- .action(actions_1.patchAction);
74
- program.addHelpText("before", (0, utils_1.renderHelp)()).addHelpText("after", `\n`);
75
- await program.parseAsync(process.argv).catch((err) => {
76
- handleCommanderError(err);
77
- });
78
- }
79
- exports.main = main;
80
- function handleCommanderError(err) {
81
- if (err instanceof extra_typings_1.CommanderError) {
82
- const ignoreCodes = [
83
- 'commander.help',
84
- 'commander.version',
85
- 'commander.helpDisplayed'
86
- ];
87
- if (ignoreCodes.indexOf(err.code) > -1) {
88
- return;
89
- }
90
- }
91
- throw err;
92
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLogger = void 0;
4
- const utils_1 = require("../actions/utils");
5
- function createLogger() {
6
- const logging = {
7
- withVerbosity: (verbose) => {
8
- const logger = {
9
- success: (msg) => {
10
- console.log((0, utils_1.renderSuccess)(msg));
11
- return undefined;
12
- },
13
- warn: (msg) => {
14
- console.log((0, utils_1.renderWarn)(msg));
15
- return undefined;
16
- },
17
- log: (msg) => {
18
- console.log((0, utils_1.renderLog)(msg));
19
- return undefined;
20
- },
21
- diff: (current, next) => {
22
- console.log((0, utils_1.renderDiff)(current, next));
23
- },
24
- debug: (msg) => {
25
- if (verbose === true) {
26
- console.log((0, utils_1.renderDebug)(JSON.stringify(msg)));
27
- }
28
- return undefined;
29
- },
30
- error: (err) => {
31
- console.log((0, utils_1.renderErrorMessage)(err.message));
32
- if (verbose === true) {
33
- console.log(err);
34
- }
35
- return undefined;
36
- }
37
- };
38
- return logger;
39
- }
40
- };
41
- return logging;
42
- }
43
- exports.createLogger = createLogger;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateConfig = void 0;
4
- var schema_1 = require("./schema");
5
- Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return schema_1.validateConfig; } });
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateConfig = void 0;
7
- const joi_1 = __importDefault(require("joi"));
8
- const errors_1 = require("../errors");
9
- const IGLU_URL_REGEX = new RegExp("^iglu:[a-zA-Z0-9-_.]+/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/[0-9]+-[0-9]+-[0-9]+$");
10
- /** Joi schema for performing validation on snowtype.config.json files. */
11
- const ConfigSchema = joi_1.default.object()
12
- .required()
13
- .keys({
14
- tracker: joi_1.default.string()
15
- .required()
16
- .valid("@snowplow/browser-tracker", "@snowplow/javascript-tracker", "@snowplow/node-tracker", "snowplow-android-tracker", "snowplow-ios-tracker", "snowplow-golang-tracker"),
17
- language: joi_1.default.string()
18
- .required()
19
- .valid("typescript", "kotlin", "swift", "javascript", "go"),
20
- outpath: joi_1.default.string().required(),
21
- organizationId: joi_1.default.string()
22
- .when("dataStructures", {
23
- is: joi_1.default.array().min(1),
24
- then: joi_1.default.required(),
25
- otherwise: joi_1.default.optional(),
26
- })
27
- .when("trackingScenarioIds", {
28
- is: joi_1.default.array().min(1),
29
- then: joi_1.default.required(),
30
- otherwise: joi_1.default.optional(),
31
- }),
32
- igluCentralSchemas: joi_1.default.array()
33
- .optional()
34
- .items(joi_1.default.string().regex(IGLU_URL_REGEX)),
35
- dataStructures: joi_1.default.array()
36
- .optional()
37
- .items(joi_1.default.string().regex(IGLU_URL_REGEX)),
38
- trackingScenarioIds: joi_1.default.array().optional().items(joi_1.default.string()),
39
- });
40
- const validateConfig = (rawConfig) => {
41
- // Validate the provided configuration file using our Joi schema.
42
- const result = ConfigSchema.validate(rawConfig, {
43
- abortEarly: false,
44
- convert: false,
45
- });
46
- if (result.error) {
47
- throw new errors_1.SnowtypeConfigInvalidError(result.error.annotate());
48
- }
49
- // We can safely type cast the config, now that is has been validated.
50
- return rawConfig;
51
- };
52
- exports.validateConfig = validateConfig;