zcatalyst-cli 1.18.1 → 1.20.0

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.
@@ -0,0 +1,19 @@
1
+ [IDX-1]
2
+ context = '''The options provided ${arg[0]}(publisher_service) ${arg[1]}(event_name) are not in a pair.'''
3
+ aid = '''Please provide the options as key values in this format: ${arg[2]}'''
4
+ link = ''
5
+
6
+ [IDX-2]
7
+ context = '''The provided input for publisher service is invalid.'''
8
+ aid = '''The publisher service must be one of the following: \n${arg[0]}'''
9
+ link = ''
10
+
11
+ [IDX-3]
12
+ context = '''The options are provided in an invalid format: ${arg[0]}'''
13
+ aid = '''Please provide the options only in this format: ${arg[1]}'''
14
+ link = ''
15
+
16
+ [IDX-4]
17
+ context = '''The provided event is not compatible with the publisher service: ${arg[0]} ${arg[1]} ${arg[2]} '''
18
+ aid = '''The compatible events with the publisher service ${arg[2]} are: \n${arg[3]}'''
19
+ link = ''
@@ -188,8 +188,14 @@ exports.default = new command_1.default('event:generate <source> <action>')
188
188
  break;
189
189
  }
190
190
  });
191
- const sourceModule = (yield (_a = '../../../event_generate/' + source, Promise.resolve().then(() => __importStar(require(_a))))).default;
192
- eventJsonContent = yield sourceModule(eventJsonContent, optionMap, action);
191
+ const isCustomSource = source === 'custom';
192
+ const sourceModule = yield (_a = `../../../event_generate/${source}`, Promise.resolve().then(() => __importStar(require(_a))));
193
+ eventJsonContent = eventJsonContent.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), isCustomSource ? yield sourceModule.getRuleId() : 'NULL');
194
+ const evenData = !isCustomSource
195
+ ? yield sourceModule.getData(optionMap)
196
+ : optionMap.payload;
197
+ eventJsonContent = eventJsonContent.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(evenData));
198
+ eventJsonContent = eventJsonContent.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), sourceModule.sourceId);
193
199
  const jsonContent = JSON.parse(eventJsonContent);
194
200
  Object.keys(jsonContent).forEach((key) => {
195
201
  if (jsonContent[key] === 'NULL') {
@@ -81,6 +81,7 @@ exports.default = (client) => {
81
81
  loadCommand('codelib:install'),
82
82
  loadCommand('event:generate'),
83
83
  loadCommand('event:generate:integ'),
84
+ loadCommand('signals:generate'),
84
85
  loadCommand('event:generate:job'),
85
86
  loadCommand('serve'),
86
87
  loadCommand('deploy'),
@@ -0,0 +1,214 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const ansi_colors_1 = require("ansi-colors");
39
+ const error_1 = __importDefault(require("../../../error"));
40
+ const command_1 = __importDefault(require("../../../internal/command"));
41
+ const constants_1 = require("../../../util_modules/constants");
42
+ const fs_1 = require("../../../util_modules/fs");
43
+ const logger_1 = require("../../../util_modules/logger");
44
+ const project_1 = require("../../../util_modules/project");
45
+ const js_1 = require("../../../util_modules/js");
46
+ const option_1 = require("../../../util_modules/option");
47
+ exports.default = new command_1.default('signals:generate <publisher_service> <event_name>')
48
+ .description('Generate sample payloads from different components or custom event publishers to test Event functions')
49
+ .allowUnknownOpts()
50
+ .needs('rc')
51
+ .needs('auth')
52
+ .action(function generate(publisher, event) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ var _a;
55
+ const unknownArgs = (0, option_1.getUnknownOpts)([]);
56
+ if (unknownArgs.length % 2 !== 0) {
57
+ throw new error_1.default('Unknown options are not provided as key value pairs', {
58
+ exit: 1,
59
+ errorId: 'IDX-1',
60
+ arg: [(0, ansi_colors_1.bold)(publisher), (0, ansi_colors_1.bold)(event), (0, ansi_colors_1.bold)('--key value')]
61
+ });
62
+ }
63
+ const remotePublisherName = constants_1.SIGNALS_PUBLISHERS[publisher];
64
+ if (remotePublisherName === undefined) {
65
+ throw new error_1.default('Invalid publisher service', {
66
+ exit: 1,
67
+ errorId: 'IDX-2',
68
+ arg: [
69
+ (0, ansi_colors_1.bold)(Object.keys(constants_1.SIGNALS_PUBLISHERS)
70
+ .map((src) => '* ' + src)
71
+ .join('\n'))
72
+ ]
73
+ });
74
+ }
75
+ if (constants_1.SIGNALS_API_NAMES[remotePublisherName] === undefined) {
76
+ throw new error_1.default('Signal reference is not found for the publisher service provided', {
77
+ exit: 2
78
+ });
79
+ }
80
+ let eventJsonContent = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.signal_event_data);
81
+ if (eventJsonContent === undefined) {
82
+ throw new error_1.default('Signal template json is undefined', { exit: 2 });
83
+ }
84
+ const eventDataPlaceHolder = constants_1.PLACEHOLDER.signal_event_data;
85
+ const optionMap = unknownArgs.reduce((previousValue, currentValue, currentIndex, optionArr) => {
86
+ if (currentIndex % 2 === 0) {
87
+ if (!currentValue.startsWith('--') &&
88
+ currentValue !== '-e' &&
89
+ currentValue !== '-rid' &&
90
+ currentValue !== '--verbose') {
91
+ const fault = unknownArgs === null || unknownArgs === void 0 ? void 0 : unknownArgs.map((arg) => {
92
+ if (arg === currentValue) {
93
+ return (0, ansi_colors_1.red)(arg);
94
+ }
95
+ return arg;
96
+ }).join(' ');
97
+ throw new error_1.default('Invalid option format detected', {
98
+ exit: 1,
99
+ errorId: 'IDX-3',
100
+ arg: [(0, ansi_colors_1.italic)(fault), (0, ansi_colors_1.bold)('--<option> <value>')]
101
+ });
102
+ }
103
+ previousValue[currentValue.slice(2)] = optionArr[currentIndex + 1];
104
+ }
105
+ return previousValue;
106
+ }, {});
107
+ let data = {};
108
+ if (publisher !== 'custom') {
109
+ const publisherModule = yield (_a = '../../../event_generate/' + (publisher === 'authentication' ? 'user' : publisher), Promise.resolve().then(() => __importStar(require(_a))));
110
+ data = yield publisherModule.getData(optionMap);
111
+ if (publisher === 'datastore') {
112
+ data = Object.assign(Object.assign({}, data), { table_details: {
113
+ table_id: publisherModule.sourceId,
114
+ table_name: 'Default'
115
+ } });
116
+ }
117
+ if (publisher === 'authentication' && event !== 'user_signedup') {
118
+ data = data.user_details;
119
+ }
120
+ }
121
+ Object.keys(eventDataPlaceHolder).forEach((placeholderKey) => {
122
+ switch (placeholderKey) {
123
+ case 'version':
124
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), 1 + '');
125
+ break;
126
+ case 'org_id':
127
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), (0, project_1.getEnvId)() + '');
128
+ break;
129
+ case 'project_id':
130
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), (0, project_1.getProjectId)() + '');
131
+ break;
132
+ case 'project_name':
133
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), (0, project_1.getProjectName)() + '');
134
+ break;
135
+ case 'environment':
136
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), (0, project_1.getEnvName)() + '');
137
+ break;
138
+ case 'rule_id':
139
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), js_1.JS.randomNumber(18) + '');
140
+ break;
141
+ case 'uuid':
142
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), js_1.JS.randomString(8) +
143
+ '-' +
144
+ js_1.JS.randomString(4) +
145
+ '-' +
146
+ js_1.JS.randomString(4) +
147
+ '-' +
148
+ js_1.JS.randomString(4) +
149
+ '-' +
150
+ js_1.JS.randomString(11));
151
+ break;
152
+ case 'target_id':
153
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), js_1.JS.randomNumber(8) + '');
154
+ break;
155
+ case 'signal_id':
156
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), js_1.JS.randomNumber(17) + '');
157
+ break;
158
+ case 'signal_api_name':
159
+ if (publisher !== 'custom') {
160
+ const eventRefArr = constants_1.SIGNALS_API_NAMES[remotePublisherName];
161
+ const remoteRefevent = event;
162
+ (0, logger_1.debug)(`event name provided is : ${remoteRefevent}`);
163
+ const indexOfevent = eventRefArr.indexOf(remoteRefevent);
164
+ if (indexOfevent < 0) {
165
+ const availableEvents = eventRefArr
166
+ .map((act) => {
167
+ return '* ' + act;
168
+ })
169
+ .join('\n');
170
+ throw new error_1.default('Event name incompatible with the publisher service' + eventRefArr, {
171
+ exit: 1,
172
+ errorId: 'IDX-4',
173
+ arg: [
174
+ (0, ansi_colors_1.bold)(event),
175
+ ansi_colors_1.bold.red('X'),
176
+ (0, ansi_colors_1.bold)(publisher),
177
+ (0, ansi_colors_1.bold)(availableEvents)
178
+ ]
179
+ });
180
+ }
181
+ event = constants_1.SIGNALS_API_NAMES[remotePublisherName][indexOfevent];
182
+ }
183
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), event);
184
+ break;
185
+ case 'attempt':
186
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), 1 + '');
187
+ break;
188
+ case 'source':
189
+ const publisherDetails = `publisher_id:${js_1.JS.randomNumber(17)}` +
190
+ `/service:${getPublisherType(publisher)}${publisher === 'custom'
191
+ ? ''
192
+ : publisher + '/account:' + js_1.JS.randomNumber(8)}`;
193
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), publisherDetails);
194
+ break;
195
+ case 'time_in_ms':
196
+ eventJsonContent = eventJsonContent === null || eventJsonContent === void 0 ? void 0 : eventJsonContent.replace(new RegExp(eventDataPlaceHolder[placeholderKey], 'g'), Date.now().toString());
197
+ break;
198
+ default:
199
+ break;
200
+ }
201
+ });
202
+ eventJsonContent = eventJsonContent.replace(new RegExp(constants_1.PLACEHOLDER.signal_event_data.data, 'g'), JSON.stringify(data));
203
+ const jsonContent = JSON.parse(eventJsonContent);
204
+ process.stdout.write(JSON.stringify(jsonContent) + '\n');
205
+ });
206
+ });
207
+ function getPublisherType(publisher) {
208
+ for (const [category, services] of Object.entries(constants_1.SIGNALS_PUBLISHERS_TYPE)) {
209
+ if (services.includes(publisher)) {
210
+ return category;
211
+ }
212
+ }
213
+ return null;
214
+ }
@@ -12,42 +12,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getData = exports.sourceId = void 0;
15
16
  const ansi_colors_1 = require("ansi-colors");
16
17
  const moment_1 = __importDefault(require("moment"));
17
18
  const endpoints_1 = require("../endpoints");
18
19
  const error_1 = __importDefault(require("../error"));
19
- const constants_1 = require("../util_modules/constants");
20
20
  const js_1 = require("../util_modules/js");
21
- const project_1 = require("../util_modules/project");
22
- exports.default = (eventJson, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
23
- const segmentId = options.segment;
24
- const allSegments = (yield (yield (0, endpoints_1.cacheAPI)()).getAllSegments());
25
- const selectedSegment = segmentId !== undefined
26
- ? allSegments.find((segment) => segment.segment_name === segmentId || segment.id + '' === segmentId)
27
- : allSegments.find((segment) => segment.segment_name === 'Default');
28
- if (selectedSegment === undefined) {
29
- if (!allSegments.find((segment) => segment.segment_name === 'Default')) {
30
- throw new error_1.default('Default segment is missing !!!', { exit: 2 });
21
+ exports.sourceId = 'NULL';
22
+ function getData(options = {}) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const segmentId = options.segment;
25
+ const allSegments = (yield (yield (0, endpoints_1.cacheAPI)()).getAllSegments());
26
+ const selectedSegment = segmentId !== undefined
27
+ ? allSegments.find((segment) => segment.segment_name === segmentId || segment.id + '' === segmentId)
28
+ : allSegments.find((segment) => segment.segment_name === 'Default');
29
+ if (selectedSegment === undefined) {
30
+ if (!allSegments.find((segment) => segment.segment_name === 'Default')) {
31
+ throw new error_1.default('Default segment is missing !!!', { exit: 2 });
32
+ }
33
+ throw new error_1.default('Unknown segment identifier', {
34
+ exit: 1,
35
+ errorId: 'CACHE-1',
36
+ arg: [(0, ansi_colors_1.bold)(segmentId || ''), (0, ansi_colors_1.bold)('--segment')]
37
+ });
31
38
  }
32
- throw new error_1.default('Unknown segment identifier', {
33
- exit: 1,
34
- errorId: 'CACHE-1',
35
- arg: [(0, ansi_colors_1.bold)(segmentId || ''), (0, ansi_colors_1.bold)('--segment')]
36
- });
37
- }
38
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), selectedSegment.id);
39
- const expiryInHours = js_1.JS.random(1, 48);
40
- const data = {
41
- cache_name: js_1.JS.randomString(js_1.JS.random(5, 10)),
42
- cache_value: js_1.JS.randomString(10),
43
- project_details: {
44
- id: (0, project_1.getProjectId)(),
45
- project_name: (0, project_1.getProjectName)()
46
- },
47
- segment_details: selectedSegment,
48
- expiry_in_hours: expiryInHours,
49
- expires_in: (0, moment_1.default)(moment_1.default.now() + expiryInHours * 60 * 60 * 1000).format('MMM DD, YYYY hh:mm A')
50
- };
51
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), 'NULL');
52
- return eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(data));
53
- });
39
+ exports.sourceId = selectedSegment.id;
40
+ const expiryInHours = js_1.JS.random(1, 48);
41
+ return {
42
+ cache_name: js_1.JS.randomString(js_1.JS.random(5, 10)),
43
+ cache_value: js_1.JS.randomString(10),
44
+ project_details: selectedSegment.project_details,
45
+ segment_details: {
46
+ segment_name: selectedSegment.segment_name,
47
+ id: selectedSegment.id
48
+ },
49
+ expiry_in_hours: expiryInHours,
50
+ expires_in: (0, moment_1.default)(moment_1.default.now() + expiryInHours * 60 * 60 * 1000).format('MMM DD, YYYY hh:mm A'),
51
+ ttl_in_milliseconds: expiryInHours * 60 * 60 * 1000 + ''
52
+ };
53
+ });
54
+ }
55
+ exports.getData = getData;
@@ -12,25 +12,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getRuleId = void 0;
15
16
  const ansi_colors_1 = require("ansi-colors");
16
17
  const error_1 = __importDefault(require("../error"));
17
- const constants_1 = require("../util_modules/constants");
18
- const js_1 = require("../util_modules/js");
19
18
  const option_1 = require("../util_modules/option");
20
- exports.default = (eventJson, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
21
- let data = options.payload;
22
- if (data === undefined) {
23
- data = js_1.JS.randomString(15);
24
- }
25
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(data));
26
- const ruleId = (0, option_1.getOptionValue)('ruleId', false);
27
- if (!ruleId) {
28
- throw new error_1.default('no rule-id provided', {
29
- exit: 1,
30
- errorId: 'CUSTOM-1',
31
- arg: [(0, ansi_colors_1.bold)('-rid'), (0, ansi_colors_1.bold)('--rule-id')]
32
- });
33
- }
34
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), 'NULL');
35
- return eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), ruleId);
36
- });
19
+ function getRuleId() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const ruleId = (0, option_1.getOptionValue)('ruleId', false);
22
+ if (!ruleId) {
23
+ throw new error_1.default('no rule-id provided', {
24
+ exit: 1,
25
+ errorId: 'CUSTOM-1',
26
+ arg: [(0, ansi_colors_1.bold)('-rid'), (0, ansi_colors_1.bold)('--rule-id')]
27
+ });
28
+ }
29
+ return ruleId;
30
+ });
31
+ }
32
+ exports.getRuleId = getRuleId;
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getData = exports.sourceId = void 0;
15
16
  const ansi_colors_1 = require("ansi-colors");
16
17
  const moment_1 = __importDefault(require("moment"));
17
18
  const endpoints_1 = require("../endpoints");
@@ -19,63 +20,66 @@ const error_1 = __importDefault(require("../error"));
19
20
  const constants_1 = require("../util_modules/constants");
20
21
  const js_1 = require("../util_modules/js");
21
22
  const logger_1 = require("../util_modules/logger");
22
- exports.default = (eventJson, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
23
- const tableId = options.table;
24
- let columnDetails = constants_1.DEFAULT.datastore.column_details;
25
- if (tableId !== undefined) {
26
- columnDetails = (yield (yield (0, endpoints_1.datastoreAPI)()).getColumnDetails(tableId).catch((err) => {
27
- if (err.status && err.status === 404) {
28
- throw new error_1.default('Invalid table identifier', {
29
- exit: 1,
30
- errorId: 'DSTORE-1',
31
- arg: [(0, ansi_colors_1.bold)(tableId), (0, ansi_colors_1.bold)('--table')]
23
+ exports.sourceId = 'NULL';
24
+ function getData(options = {}) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const tableId = options.table;
27
+ let columnDetails = constants_1.DEFAULT.datastore.column_details;
28
+ if (tableId !== undefined) {
29
+ columnDetails = (yield (yield (0, endpoints_1.datastoreAPI)()).getColumnDetails(tableId).catch((err) => {
30
+ if (err.status && err.status === 404) {
31
+ throw new error_1.default('Invalid table identifier', {
32
+ exit: 1,
33
+ errorId: 'DSTORE-1',
34
+ arg: [(0, ansi_colors_1.bold)(tableId), (0, ansi_colors_1.bold)('--table')]
35
+ });
36
+ }
37
+ throw err;
38
+ }));
39
+ if (!Array.isArray(columnDetails)) {
40
+ throw new error_1.default('Invalid column details', { exit: 2 });
41
+ }
42
+ const rowColumn = columnDetails.find((col) => col.column_name === 'ROWID');
43
+ if (rowColumn === undefined) {
44
+ throw new error_1.default('There is no ROWID column present in the column details', {
45
+ exit: 2
32
46
  });
33
47
  }
34
- throw err;
35
- }));
36
- if (!Array.isArray(columnDetails)) {
37
- throw new error_1.default('Invalid column details', { exit: 2 });
38
- }
39
- const rowColumn = columnDetails.find((col) => col.column_name === 'ROWID');
40
- if (rowColumn === undefined) {
41
- throw new error_1.default('There is no ROWID column present in the column details', {
42
- exit: 2
43
- });
48
+ exports.sourceId = rowColumn.table_id;
44
49
  }
45
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), rowColumn.table_id);
46
- }
47
- else {
48
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), js_1.JS.randomNumber(15).toString());
49
- }
50
- const data = columnDetails.reduce((accumulator, current) => {
51
- switch (current.data_type) {
52
- case 'bigint':
53
- case 'foreignkey':
54
- accumulator[0][current.column_name] = js_1.JS.randomNumber(15);
55
- break;
56
- case 'datetime':
57
- accumulator[0][current.column_name] = (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss');
58
- break;
59
- case 'text':
60
- case 'varchar':
61
- accumulator[0][current.column_name] = js_1.JS.randomString(10);
62
- break;
63
- case 'date':
64
- accumulator[0][current.column_name] = (0, moment_1.default)().format('YYYY-MM-DD');
65
- break;
66
- case 'boolean':
67
- accumulator[0][current.column_name] = js_1.JS.random(0, 1) === 1 ? true : false;
68
- break;
69
- case 'int':
70
- case 'double':
71
- accumulator[0][current.column_name] = js_1.JS.randomNumber(5);
72
- break;
73
- default:
74
- (0, logger_1.debug)('Unknown data_type received: ' + current.data_type);
75
- break;
50
+ else {
51
+ exports.sourceId = js_1.JS.randomNumber(15).toString();
76
52
  }
77
- return accumulator;
78
- }, [{}]);
79
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), 'NULL');
80
- return eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(data));
81
- });
53
+ return columnDetails.reduce((accumulator, current) => {
54
+ switch (current.data_type) {
55
+ case 'bigint':
56
+ case 'foreignkey':
57
+ accumulator[0][current.column_name] = js_1.JS.randomNumber(15);
58
+ break;
59
+ case 'datetime':
60
+ accumulator[0][current.column_name] =
61
+ (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss:SSS');
62
+ break;
63
+ case 'text':
64
+ case 'varchar':
65
+ accumulator[0][current.column_name] = js_1.JS.randomString(10);
66
+ break;
67
+ case 'date':
68
+ accumulator[0][current.column_name] = (0, moment_1.default)().format('YYYY-MM-DD');
69
+ break;
70
+ case 'boolean':
71
+ accumulator[0][current.column_name] = js_1.JS.random(0, 1) === 1 ? true : false;
72
+ break;
73
+ case 'int':
74
+ case 'double':
75
+ accumulator[0][current.column_name] = js_1.JS.randomNumber(5);
76
+ break;
77
+ default:
78
+ (0, logger_1.debug)('Unknown data_type received: ' + current.data_type);
79
+ break;
80
+ }
81
+ return accumulator;
82
+ }, [{}])[0];
83
+ });
84
+ }
85
+ exports.getData = getData;
@@ -12,58 +12,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getData = exports.sourceId = void 0;
15
16
  const ansi_colors_1 = require("ansi-colors");
16
17
  const moment_1 = __importDefault(require("moment"));
17
18
  const endpoints_1 = require("../endpoints");
18
19
  const error_1 = __importDefault(require("../error"));
19
20
  const runtime_store_1 = __importDefault(require("../runtime-store"));
20
- const constants_1 = require("../util_modules/constants");
21
21
  const js_1 = require("../util_modules/js");
22
22
  const project_1 = require("../util_modules/project");
23
- exports.default = (eventJson, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
24
- const folderId = options.folder;
25
- const allFolders = (yield (yield (0, endpoints_1.filestoreAPI)()).getAllFolders());
26
- const selectedFolder = folderId !== undefined
27
- ? allFolders.find((folder) => folder.folder_name === folderId || folder.id + '' === folderId)
28
- : {
29
- folder_name: js_1.JS.randomString(js_1.JS.random(5, 10)),
30
- id: js_1.JS.randomNumber(15) + ''
23
+ exports.sourceId = 'NULL';
24
+ function getData(options = {}) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const folderId = options.folder;
27
+ const allFolders = (yield (yield (0, endpoints_1.filestoreAPI)()).getAllFolders());
28
+ const selectedFolder = folderId !== undefined
29
+ ? allFolders.find((folder) => folder.folder_name === folderId || folder.id + '' === folderId)
30
+ : {
31
+ folder_name: js_1.JS.randomString(js_1.JS.random(5, 10)),
32
+ id: js_1.JS.randomNumber(15) + ''
33
+ };
34
+ if (selectedFolder === undefined) {
35
+ const allFoldersFormatted = allFolders.length > 0
36
+ ? allFolders.map((folder) => '* ' + folder.folder_name).join('\n')
37
+ : 'None';
38
+ throw new error_1.default('Invalid folder identifier', {
39
+ exit: 1,
40
+ errorId: 'FSTORE-1',
41
+ arg: [(0, ansi_colors_1.bold)('--folder'), (0, ansi_colors_1.bold)(allFoldersFormatted)]
42
+ });
43
+ }
44
+ exports.sourceId = selectedFolder.id;
45
+ const userDetails = {
46
+ email_id: runtime_store_1.default.get('user.Email'),
47
+ user_type: 'Admin',
48
+ user_id: js_1.JS.randomNumber(15),
49
+ is_confirmed: js_1.JS.random(0, 1) === 1 ? true : false,
50
+ last_name: js_1.JS.randomString(5),
51
+ first_name: js_1.JS.randomString(10),
52
+ zuid: js_1.JS.randomNumber(10)
31
53
  };
32
- if (selectedFolder === undefined) {
33
- const allFoldersFormatted = allFolders.length > 0
34
- ? allFolders.map((folder) => '* ' + folder.folder_name).join('\n')
35
- : 'None';
36
- throw new error_1.default('Invalid folder identifier', {
37
- exit: 1,
38
- errorId: 'FSTORE-1',
39
- arg: [(0, ansi_colors_1.bold)('--folder'), (0, ansi_colors_1.bold)(allFoldersFormatted)]
40
- });
41
- }
42
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), selectedFolder.id);
43
- const userDetails = {
44
- email_id: runtime_store_1.default.get('user.Email'),
45
- user_id: js_1.JS.randomNumber(15),
46
- is_confirmed: js_1.JS.random(0, 1) === 1 ? true : false,
47
- last_name: js_1.JS.randomString(5),
48
- first_name: js_1.JS.randomString(10),
49
- zuid: js_1.JS.randomNumber(10)
50
- };
51
- const time = (0, moment_1.default)().format('MMM DD, YYYY hh:mm A');
52
- const data = {
53
- project_details: {
54
- id: (0, project_1.getProjectId)(),
55
- project_name: (0, project_1.getProjectName)()
56
- },
57
- folder_details: selectedFolder.id,
58
- created_time: time,
59
- file_location: null,
60
- modified_time: time,
61
- file_name: js_1.JS.randomString(10) + (js_1.JS.random(0, 1) === 1) ? '.js' : '.txt',
62
- modified_by: userDetails,
63
- id: selectedFolder.id,
64
- created_by: userDetails,
65
- file_size: parseInt(js_1.JS.randomNumber(6), 10)
66
- };
67
- eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), 'NULL');
68
- return eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(data));
69
- });
54
+ const time = (0, moment_1.default)().format('MMM DD, YYYY hh:mm A');
55
+ return {
56
+ project_details: {
57
+ project_type: 'Live',
58
+ id: (0, project_1.getProjectId)(),
59
+ project_name: (0, project_1.getProjectName)()
60
+ },
61
+ folder_details: selectedFolder === null || selectedFolder === void 0 ? void 0 : selectedFolder.id,
62
+ created_time: time,
63
+ file_location: null,
64
+ modified_time: time,
65
+ file_name: js_1.JS.randomString(10) + (js_1.JS.random(0, 1) === 1) ? '.js' : '.txt',
66
+ modified_by: userDetails,
67
+ id: selectedFolder === null || selectedFolder === void 0 ? void 0 : selectedFolder.id,
68
+ created_by: userDetails,
69
+ file_size: parseInt(js_1.JS.randomNumber(6), 10) + ''
70
+ };
71
+ });
72
+ }
73
+ exports.getData = getData;