zcatalyst-cli 1.18.0-beta.1 → 1.18.0-beta.11

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 (138) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/commands/ds/import.toml +5 -5
  3. package/docs/commands/zest/generate/index.toml +4 -0
  4. package/docs/serve/server/lib/appsail/index.toml +22 -1
  5. package/lib/authentication/login.js +8 -4
  6. package/lib/code-deck.js +7 -7
  7. package/lib/command_needs/rc.js +7 -7
  8. package/lib/commands/appsail/add.js +2 -2
  9. package/lib/commands/client/setup.js +1 -1
  10. package/lib/commands/codelib/install.js +6 -2
  11. package/lib/commands/ds/import.js +37 -21
  12. package/lib/commands/event/generate/index.js +14 -2
  13. package/lib/commands/functions/add.js +1 -1
  14. package/lib/commands/functions/setup.js +1 -1
  15. package/lib/commands/iac/export.js +5 -1
  16. package/lib/commands/iac/import.js +4 -1
  17. package/lib/commands/index.js +1 -0
  18. package/lib/commands/init.js +8 -1
  19. package/lib/commands/zest/generate/index.js +304 -0
  20. package/lib/deploy/features/appsail/index.js +25 -10
  21. package/lib/endpoints/index.js +17 -3
  22. package/lib/endpoints/lib/ds-bulk.js +1 -0
  23. package/lib/endpoints/lib/stratus.js +63 -0
  24. package/lib/endpoints/lib/tunnel.js +18 -0
  25. package/lib/endpoints/lib/zest.js +124 -0
  26. package/lib/event_generate/stratus.js +52 -0
  27. package/lib/fn-utils/lib/common.js +6 -1
  28. package/lib/iac/status/deploy.js +1 -5
  29. package/lib/init/features/appsail/index.js +34 -27
  30. package/lib/init/features/project.js +6 -15
  31. package/lib/internal/api.js +14 -6
  32. package/lib/internal/command.js +1 -1
  33. package/lib/prompt/index.js +5 -2
  34. package/lib/prompt/types/file-path.js +1 -1
  35. package/lib/prompt/types/search-box.js +281 -0
  36. package/lib/serve/features/appsail.js +1 -1
  37. package/lib/serve/server/index.js +44 -14
  38. package/lib/serve/server/lib/appsail/index.js +73 -13
  39. package/lib/serve/server/lib/appsail/start.js +9 -1
  40. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  41. package/lib/serve/server/lib/java/aio_server/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  42. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  43. package/lib/serve/server/lib/java/index.js +1 -1
  44. package/lib/serve/server/lib/master/appsail.js +3 -3
  45. package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
  46. package/lib/serve/server/lib/master/utils.js +27 -15
  47. package/lib/serve/server/lib/node/index.js +1 -1
  48. package/lib/serve/server/lib/node/server/package-lock.json +12 -0
  49. package/lib/serve/server/lib/python/index.js +1 -1
  50. package/lib/shell/dependencies/http-functions.js +1 -1
  51. package/lib/shell/dependencies/invoker/bio/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  52. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  53. package/lib/shell/dependencies/invoker/cron/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  54. package/lib/shell/dependencies/invoker/event/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  55. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +15 -0
  56. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  57. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  58. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +15 -1
  59. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  60. package/lib/shell/dependencies/local-function.js +24 -23
  61. package/lib/shell/dependencies/tunnel-server.js +52 -23
  62. package/lib/shell/index.js +22 -28
  63. package/lib/util_modules/config/lib/appsail.js +10 -8
  64. package/lib/util_modules/constants/lib/cliq-handlers.js +18 -10
  65. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  66. package/lib/util_modules/constants/lib/event-action.js +1 -0
  67. package/lib/util_modules/constants/lib/event-source.js +1 -0
  68. package/lib/util_modules/constants/lib/placeholders.js +2 -1
  69. package/lib/util_modules/constants/lib/scopes.js +14 -3
  70. package/lib/util_modules/constants/lib/urls.js +8 -0
  71. package/lib/util_modules/fs/lib/async.js +7 -2
  72. package/package.json +4 -2
  73. package/templates/event/integ/cliq/bot/action_handler.json +13 -4
  74. package/templates/event/integ/cliq/bot/call_handler.json +41 -0
  75. package/templates/event/integ/cliq/bot/context_handler.json +11 -3
  76. package/templates/event/integ/cliq/bot/incomingwebhook_handler.json +11 -3
  77. package/templates/event/integ/cliq/bot/mention_handler.json +12 -4
  78. package/templates/event/integ/cliq/bot/message_handler.json +13 -4
  79. package/templates/event/integ/cliq/bot/participation_handler.json +13 -3
  80. package/templates/event/integ/cliq/bot/welcome_handler.json +12 -8
  81. package/templates/event/integ/cliq/command/execution_handler.json +12 -3
  82. package/templates/event/integ/cliq/command/suggestion_handler.json +18 -4
  83. package/templates/event/integ/cliq/{installation → extension}/installation_handler.json +13 -4
  84. package/templates/event/integ/cliq/{installation → extension}/installation_validator.json +13 -5
  85. package/templates/event/integ/cliq/extension/uninstallation_handler.json +37 -0
  86. package/templates/event/integ/cliq/function/button_handler.json +13 -5
  87. package/templates/event/integ/cliq/function/form_change_handler.json +9 -3
  88. package/templates/event/integ/cliq/function/form_handler.json +11 -3
  89. package/templates/event/integ/cliq/function/form_values_handler.json +9 -3
  90. package/templates/event/integ/cliq/function/form_view_handler.json +26 -0
  91. package/templates/event/integ/cliq/function/widget_button_handler.json +14 -5
  92. package/templates/event/integ/cliq/link_preview/action_handler.json +54 -0
  93. package/templates/event/integ/cliq/link_preview/after_send_handler.json +47 -0
  94. package/templates/event/integ/cliq/link_preview/menu_handler.json +47 -0
  95. package/templates/event/integ/cliq/link_preview/preview_handler.json +47 -0
  96. package/templates/event/integ/cliq/messageaction/execution_handler.json +11 -3
  97. package/templates/event/integ/cliq/widget/view_handler.json +12 -4
  98. package/templates/init/client/react/react_js/template/src/index.js +3 -3
  99. package/templates/init/client/react/react_ts/template/src/index.tsx +3 -3
  100. package/templates/init/client/react/react_ts/template.json +3 -3
  101. package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +29 -23
  102. package/templates/init/functions/java/integ/cliq/com/handlers/CommandHandler.java +14 -17
  103. package/templates/init/functions/java/integ/cliq/com/handlers/ExtensionHandler.java +41 -0
  104. package/templates/init/functions/java/integ/cliq/com/handlers/FunctionHandler.java +74 -22
  105. package/templates/init/functions/java/integ/cliq/com/handlers/LinkPreviewHandler.java +108 -0
  106. package/templates/init/functions/java/integ/cliq/com/handlers/MessageActionHandler.java +6 -8
  107. package/templates/init/functions/java/integ/cliq/sample.java +10 -0
  108. package/templates/init/functions/java/job/sample.java +1 -1
  109. package/templates/init/functions/node/aio/sample.js +7 -0
  110. package/templates/init/functions/node/bio/sample.js +5 -0
  111. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  112. package/templates/init/functions/node/cron/sample.js +5 -0
  113. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  114. package/templates/init/functions/node/event/sample.js +11 -8
  115. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  116. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +4 -0
  117. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +3 -5
  118. package/templates/init/functions/node/integ/cliq/handlers/{installation-validator.js → extension-handler.js} +20 -3
  119. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +42 -0
  120. package/templates/init/functions/node/integ/cliq/handlers/link-preview-handler.js +73 -0
  121. package/templates/init/functions/node/job/sample.js +0 -1
  122. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  123. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +13 -3
  124. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +7 -7
  125. package/templates/init/functions/python/integ/cliq/handlers/extension_handler.py +25 -0
  126. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +54 -10
  127. package/templates/init/functions/python/integ/cliq/handlers/link_preview_handler.py +76 -0
  128. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +10 -9
  129. package/templates/init/functions/python/integ/cliq/sample.py +2 -2
  130. package/templates/init/functions/python/job/sample.py +0 -1
  131. package/templates/init.txt +2 -1
  132. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  133. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  134. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationHandler.java +0 -20
  135. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationValidator.java +0 -22
  136. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +0 -15
  137. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +0 -12
  138. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +0 -16
@@ -0,0 +1,304 @@
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 command_1 = __importDefault(require("../../../internal/command"));
39
+ const constants_1 = require("../../../util_modules/constants");
40
+ const prompt_1 = __importDefault(require("../../../prompt"));
41
+ const js_1 = require("../../../util_modules/js");
42
+ const endpoints_1 = require("../../../endpoints");
43
+ const runtime_store_1 = __importDefault(require("../../../runtime-store"));
44
+ const archiver_1 = __importDefault(require("../../../archiver"));
45
+ const logger_1 = require("../../../util_modules/logger");
46
+ const inquirer_1 = __importStar(require("inquirer"));
47
+ const error_1 = __importDefault(require("../../../error"));
48
+ const project_1 = require("../../../util_modules/project");
49
+ const features_1 = require("../../../init/features");
50
+ const path_1 = require("path");
51
+ const throbber_1 = __importDefault(require("../../../throbber"));
52
+ const config_1 = require("../../../util_modules/config");
53
+ const common_1 = require("../../../init/util/common");
54
+ const ansi_colors_1 = require("ansi-colors");
55
+ const fs_1 = require("../../../util_modules/fs");
56
+ const console_1 = require("console");
57
+ function getSpecification(specs = []) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getSpecifications());
60
+ if (!res) {
61
+ return specs;
62
+ }
63
+ specs.push(...res.specifications);
64
+ if (res.info.more_records) {
65
+ yield getSpecification(specs);
66
+ }
67
+ return specs;
68
+ });
69
+ }
70
+ function searchSpecification(filter, specArray = []) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (filter) {
73
+ const response = [];
74
+ specArray.forEach((spec) => {
75
+ if (spec.name.includes(filter)) {
76
+ response.push(spec);
77
+ }
78
+ });
79
+ return response;
80
+ }
81
+ return specArray;
82
+ });
83
+ }
84
+ function pollScheduledJob(job_id) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const throbber = throbber_1.default.getInstance();
87
+ try {
88
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getScheduledJob(job_id));
89
+ const status = js_1.JS.capitalize(res.scheduled_jobs[0].status);
90
+ if (status === 'Completed') {
91
+ throbber.succeed('processing', { text: `Status >> ${status}` });
92
+ return res;
93
+ }
94
+ throbber.add('processing', { text: `Status >> ${status}` });
95
+ if (status === 'Failed') {
96
+ throbber.fail('processing', { text: `Status >> ${status}` });
97
+ throw new error_1.default('zest generation failed', {
98
+ exit: 2,
99
+ original: `${res.scheduled_jobs[0].action_info.failure_reason}`
100
+ });
101
+ }
102
+ yield js_1.JS.sleep(1000);
103
+ }
104
+ catch (err) {
105
+ throw new error_1.default('Error while processing scheduled job', {
106
+ exit: 2,
107
+ original: err
108
+ });
109
+ }
110
+ return yield pollScheduledJob(job_id);
111
+ });
112
+ }
113
+ function downloadSourceCode(fileId, outputDir, srcType, srcName) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const zestZip = (yield (yield (0, endpoints_1.zestAPI)()).getFile(fileId, srcType, srcName));
116
+ yield new archiver_1.default().load(zestZip).extract(outputDir).finalize();
117
+ });
118
+ }
119
+ exports.default = new command_1.default('zest:generate')
120
+ .description('Generate the functions or appsail source code for your ZEST Specifications')
121
+ .needs('auth', [
122
+ constants_1.SCOPE.zest_spec_all,
123
+ constants_1.SCOPE.zest_schedule_job_read,
124
+ constants_1.SCOPE.zest_spec_all,
125
+ constants_1.SCOPE.zest_spec_src_action
126
+ ])
127
+ .needs('config', { optional: true })
128
+ .needs('rc', { skipOrgCheck: false })
129
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
130
+ var _a;
131
+ const specArray = yield getSpecification();
132
+ if (specArray.length === 0) {
133
+ throw new error_1.default('No Specifications Found', {
134
+ exit: 1,
135
+ errorId: 'ZEST-GEN-1'
136
+ });
137
+ }
138
+ yield prompt_1.default.register('search-box');
139
+ const specName = yield inquirer_1.default.prompt([
140
+ {
141
+ type: 'search-box',
142
+ name: 'specs',
143
+ searchable: true,
144
+ pageSize: 10,
145
+ highlight: true,
146
+ notFoundMsg: 'No specifications found!',
147
+ searchMsg: 'Search specifications...',
148
+ message: 'Please search and select the specifications(Use space key to select)',
149
+ source(_answersSoFar, input) {
150
+ input || (input = '');
151
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
152
+ const fuzzyResult = yield searchSpecification(input, specArray);
153
+ const data = fuzzyResult.map((element) => {
154
+ return {
155
+ name: `${element.name}(${element.version})`,
156
+ value: element.id
157
+ };
158
+ });
159
+ resolve(data);
160
+ }));
161
+ },
162
+ validate: (ansArr) => {
163
+ if (js_1.JS.isEmpty(ansArr)) {
164
+ return 'Must select one specification.';
165
+ }
166
+ return true;
167
+ }
168
+ }
169
+ ]);
170
+ const srcTypeAns = yield prompt_1.default.ask(prompt_1.default.question('source', 'Please specify which source type you want to download', {
171
+ type: 'list',
172
+ choices: [
173
+ prompt_1.default.choice('Function', {
174
+ value: 'functions'
175
+ }),
176
+ prompt_1.default.choice('AppSail', {
177
+ value: 'appsail'
178
+ })
179
+ ]
180
+ }));
181
+ const srcType = srcTypeAns.source;
182
+ const sourceLabel = srcType.replace('functions', 'function');
183
+ const runtimeChoices = yield (0, common_1.getRuntimeChoices)({ fnType: 'aio' });
184
+ const ignoreRuntimes = ['node14', 'node12', 'node20'];
185
+ const stackChoices = runtimeChoices.filter((choice) => {
186
+ if (!(choice instanceof inquirer_1.Separator)) {
187
+ return !ignoreRuntimes.includes(choice.value.runtime);
188
+ }
189
+ return choice;
190
+ });
191
+ const srcStackAns = yield prompt_1.default.ask(prompt_1.default.question('stack', `Please select the language for your ${sourceLabel}`, {
192
+ type: 'list',
193
+ choices: stackChoices.map((choice) => {
194
+ if (!(choice instanceof inquirer_1.Separator)) {
195
+ return choice;
196
+ }
197
+ return choice;
198
+ }),
199
+ when: () => {
200
+ return runtimeChoices.length > 1;
201
+ }
202
+ }));
203
+ const srcStack = srcStackAns.stack.runtime;
204
+ const existingSails = config_1.appSailConfig.raw() || [];
205
+ const existingFuncs = ((_a = config_1.functionsConfig.raw()) === null || _a === void 0 ? void 0 : _a.targets) || [];
206
+ const source = yield prompt_1.default.ask(prompt_1.default.question('name', `Please provide a name for your ${(0, ansi_colors_1.bold)(sourceLabel)} `, {
207
+ type: 'input',
208
+ default: 'sample',
209
+ validate: (input) => __awaiter(void 0, void 0, void 0, function* () {
210
+ if (input === '') {
211
+ return 'Please provide a valid name.';
212
+ }
213
+ if (input === '' || !input.match(constants_1.REGEX.functions.package.name)) {
214
+ return `Special characters are not allowed. Includes only alphabets, numbers, hyphen and underscores.`;
215
+ }
216
+ if (srcType === 'functions' &&
217
+ existingFuncs.findIndex((func) => func === input) !== -1) {
218
+ return 'function name already exists';
219
+ }
220
+ if (srcType === 'appsail' &&
221
+ existingSails.findIndex((appSail) => appSail.name === input) !== -1) {
222
+ return 'appsail name already exists';
223
+ }
224
+ return true;
225
+ })
226
+ }));
227
+ const srcName = source.name;
228
+ let sourceCodeRes;
229
+ const resources = [];
230
+ specName.specs.forEach((element) => {
231
+ resources.push({ id: element });
232
+ });
233
+ const config = runtime_store_1.default.get('config');
234
+ let payload, outputDir;
235
+ if (srcType === 'appsail') {
236
+ const generateAppsailParams = {
237
+ resources: resources,
238
+ stack: srcStack,
239
+ name: srcName
240
+ };
241
+ outputDir = (0, project_1.resolveProjectPath)(`appsail-${srcName}`);
242
+ payload = {
243
+ source: outputDir,
244
+ name: srcName
245
+ };
246
+ if (srcStackAns.stack.lang.startsWith('java')) {
247
+ const basePackage = yield prompt_1.default.ask(prompt_1.default.question('basePkg', 'Please specify the base package name', {
248
+ type: 'input',
249
+ default: 'com.zoho'
250
+ }));
251
+ const install = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to install dependencies ? ', {
252
+ type: 'confirm',
253
+ default: true
254
+ }));
255
+ Object.assign(generateAppsailParams, {
256
+ with_dependency: install.consent,
257
+ config: {
258
+ base_package: basePackage.basePkg
259
+ }
260
+ });
261
+ }
262
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateAppsail(generateAppsailParams);
263
+ }
264
+ else {
265
+ const functionsDirPath = (0, project_1.resolveProjectPath)(config.get('functions.source') || constants_1.FOLDERNAME.functions);
266
+ outputDir = (0, path_1.join)(functionsDirPath, srcName);
267
+ payload = {
268
+ source: outputDir,
269
+ name: srcName,
270
+ stack: srcStack,
271
+ type: 'aio'
272
+ };
273
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateFunction(resources, srcStack, srcName);
274
+ }
275
+ const folderExists = yield fs_1.ASYNC.dirExists(outputDir);
276
+ const overwriteAns = folderExists
277
+ ? yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' + (0, ansi_colors_1.underline)(outputDir) + ' already exists. Overwrite ?', {
278
+ type: 'confirm',
279
+ defaultAns: false
280
+ }))
281
+ : { overwrite: true };
282
+ if (!overwriteAns.overwrite) {
283
+ (0, logger_1.labeled)('zest', `${sourceLabel} generation skipped.`).WARN();
284
+ return;
285
+ }
286
+ yield fs_1.ASYNC.deleteDir(outputDir);
287
+ runtime_store_1.default.set(`payload.${srcType}.targets`, [payload]);
288
+ const job_id = sourceCodeRes.job_id;
289
+ const throbber = throbber_1.default.getInstance();
290
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Generating ${js_1.JS.capitalize(sourceLabel)}`);
291
+ const fileId = yield pollScheduledJob(job_id).then((data) => {
292
+ throbber.remove('processing');
293
+ return data.scheduled_jobs[0].action_info.file_id;
294
+ });
295
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Downloading ${js_1.JS.capitalize(sourceLabel)}`);
296
+ yield downloadSourceCode(fileId, outputDir, sourceLabel, srcName);
297
+ (0, features_1.setCatalystConfig)(srcType, true);
298
+ yield config.save();
299
+ (0, console_1.info)();
300
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) +
301
+ ` file has been successfully updated with ${sourceLabel} details.`);
302
+ (0, console_1.info)();
303
+ (0, logger_1.success)(`Zest successfully generated in ${(0, ansi_colors_1.bold)((0, path_1.join)(outputDir))}.`);
304
+ }));
@@ -31,6 +31,7 @@ const option_1 = require("../../../util_modules/option");
31
31
  const project_1 = require("../../../util_modules/project");
32
32
  const utils_1 = require("./utils");
33
33
  const throbber_1 = __importDefault(require("../../../throbber"));
34
+ const minimatch_1 = __importDefault(require("minimatch"));
34
35
  function executeHook(script, name, moduleSource) {
35
36
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
36
37
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -183,29 +184,42 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
183
184
  var _a, _b;
184
185
  const targ = _targ.config;
185
186
  const prevRes = yield result;
187
+ const throbberName = `prepare_appsail_${_targ.name}`;
186
188
  try {
187
189
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
188
190
  executeHook(targ.scripts.predeploy, 'predeploy', _targ.source);
189
191
  }
190
- const throbberName = `prepare_appsail_${_targ.name}`;
191
192
  throbber.add(throbberName, {
192
193
  text: `Preparing AppSail[${_targ.name}]`
193
194
  });
194
- const zip = new archiver_1.default();
195
- const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
196
195
  const folderPath = targ.build_path;
196
+ const isBuildPath = yield fs_1.ASYNC.isPathExists(folderPath);
197
+ if (!isBuildPath) {
198
+ throw new error_1.default(`the build path doesn't exists: ${folderPath}`, {
199
+ exit: 1,
200
+ skipHelp: true
201
+ });
202
+ }
203
+ const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
204
+ const excludePatterns = [
205
+ '**/.DS_Store',
206
+ '**/.vscode/**/*',
207
+ `**/${constants_1.FILENAME.log}`,
208
+ `**/${constants_1.FILENAME.config}`,
209
+ `**/${constants_1.FILENAME.rc}`,
210
+ `**/${constants_1.FILENAME.app_config}`,
211
+ `**/${constants_1.FILENAME.catalyst_ignore}`,
212
+ ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
213
+ ];
197
214
  const folderContents = yield fs_1.ASYNC.walk(folderPath, {
198
215
  filter: {
199
- exclude: [
200
- '**/.DS_Store',
201
- '**/.vscode/**/*',
202
- `**/${constants_1.FILENAME.app_config}`,
203
- `**/${constants_1.FILENAME.catalyst_ignore}`,
204
- ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
205
- ],
216
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
217
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(folderPath + path_1.sep, ''), glob, { dot: true }));
218
+ }),
206
219
  excludeDir: true
207
220
  }
208
221
  });
222
+ const zip = new archiver_1.default();
209
223
  folderContents.forEach((content) => {
210
224
  zip.add(content.path === folderPath
211
225
  ? (0, path_1.basename)(content.path)
@@ -234,6 +248,7 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
234
248
  }
235
249
  }
236
250
  catch (err) {
251
+ throbber.remove(throbberName);
237
252
  (0, logger_1.debug)(err);
238
253
  _targ.validity = {
239
254
  valid: false,
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.tunnelAPI = exports.commonAPI = exports.jobScheduling = exports.codeDeck = exports.gitHubAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
35
+ exports.tunnelAPI = exports.commonAPI = exports.jobScheduling = exports.codeDeck = exports.gitHubAPI = exports.stratusAPI = exports.zestAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
36
36
  const project_1 = require("../util_modules/project");
37
37
  function orgAPI({ auth = true } = {}) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -41,10 +41,10 @@ function orgAPI({ auth = true } = {}) {
41
41
  });
42
42
  }
43
43
  exports.orgAPI = orgAPI;
44
- function projectAPI({ auth = true, org = (0, project_1.getEnvId)() } = {}) {
44
+ function projectAPI({ auth = true, org = (0, project_1.getEnvId)(), printError = true } = {}) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  const project = (yield Promise.resolve().then(() => __importStar(require('./lib/project')))).default;
47
- return new project({ authNeeded: auth }, org);
47
+ return new project({ authNeeded: auth, printError }, org);
48
48
  });
49
49
  }
50
50
  exports.projectAPI = projectAPI;
@@ -156,6 +156,20 @@ function appSailAPI({ auth = true, projectId = (0, project_1.getProjectId)(), en
156
156
  });
157
157
  }
158
158
  exports.appSailAPI = appSailAPI;
159
+ function zestAPI({ auth = true, projectId = (0, project_1.getProjectId)(), env = (0, project_1.getEnvName)() } = {}) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const zest = (yield Promise.resolve().then(() => __importStar(require('./lib/zest.js')))).default;
162
+ return new zest(projectId, { authNeeded: auth, env, isExternal: true });
163
+ });
164
+ }
165
+ exports.zestAPI = zestAPI;
166
+ function stratusAPI({ auth = true, projectId = (0, project_1.getProjectId)(), env = (0, project_1.getEnvName)() } = {}) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const stratus = (yield Promise.resolve().then(() => __importStar(require('./lib/stratus')))).default;
169
+ return new stratus(projectId, { authNeeded: auth, env });
170
+ });
171
+ }
172
+ exports.stratusAPI = stratusAPI;
159
173
  function gitHubAPI() {
160
174
  return __awaiter(this, void 0, void 0, function* () {
161
175
  const gitHub = (yield Promise.resolve().then(() => __importStar(require('./lib/git-hub')))).default;
@@ -50,6 +50,7 @@ class BulkDS {
50
50
  body: {
51
51
  table_identifier: table,
52
52
  operation: config === null || config === void 0 ? void 0 : config.operation,
53
+ object_details: config === null || config === void 0 ? void 0 : config.object_details,
53
54
  file_id: config === null || config === void 0 ? void 0 : config.file_id,
54
55
  callback: config === null || config === void 0 ? void 0 : config.callback,
55
56
  find_by: config === null || config === void 0 ? void 0 : config.find_by,
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const error_1 = __importDefault(require("../../error"));
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ const logger_1 = require("../../util_modules/logger");
18
+ const mime_types_1 = __importDefault(require("mime-types"));
19
+ const constants_1 = require("../../util_modules/constants");
20
+ class Stratus {
21
+ constructor(projectId, opts) {
22
+ this.opts = opts;
23
+ this.projectId = projectId;
24
+ }
25
+ getAllBuckets() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/bucket`);
28
+ if (res.body && res.body.data) {
29
+ return res.body.data;
30
+ }
31
+ (0, logger_1.debug)('get all buckets response from server : ' + res.body);
32
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
33
+ exit: 2
34
+ });
35
+ });
36
+ }
37
+ uploadObject(bucketName, objectName, fileStream) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const extension = objectName.substring(objectName.lastIndexOf('.') + 1).toLowerCase();
40
+ const contentType = mime_types_1.default.lookup(extension + '');
41
+ const res = yield new api_1.default(Object.assign({ origin: `https://${bucketName}` +
42
+ (this.opts.env === 'Development'
43
+ ? '-' + this.opts.env.toLowerCase()
44
+ : '') +
45
+ constants_1.ORIGIN.stratusSuffix, isExternal: true }, this.opts)).put(`/${objectName}`, {
46
+ body: fileStream,
47
+ headers: {
48
+ compress: 'false',
49
+ 'Content-Type': contentType || 'application/octet-stream'
50
+ },
51
+ json: false
52
+ });
53
+ if (res.status === 200) {
54
+ return res.status;
55
+ }
56
+ (0, logger_1.debug)('upload object response from server : ' + res);
57
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
58
+ exit: 2
59
+ });
60
+ });
61
+ }
62
+ }
63
+ exports.default = Stratus;
@@ -62,5 +62,23 @@ class TunnelAPI {
62
62
  });
63
63
  });
64
64
  }
65
+ tunnelCallback(status, details, data) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/tunneling/callback`, {
68
+ body: {
69
+ status,
70
+ content: Object.assign({}, details),
71
+ data
72
+ }
73
+ });
74
+ if (res.status >= 200 && res.status <= 299) {
75
+ return;
76
+ }
77
+ (0, logger_1.debug)(`tunnel callback response from server ::: status=${res.status} ::: body=${res.body}`);
78
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
79
+ exit: 2
80
+ });
81
+ });
82
+ }
65
83
  }
66
84
  exports.default = TunnelAPI;
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const error_1 = __importDefault(require("../../error"));
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ const js_1 = require("../../util_modules/js");
18
+ const logger_1 = require("../../util_modules/logger");
19
+ const project_1 = require("../../util_modules/project");
20
+ class Zest {
21
+ constructor(projectId, opts) {
22
+ this.opts = Object.assign(Object.assign({}, opts), { headers: {
23
+ 'CATALYST-ORG': (0, project_1.getEnvId)()
24
+ } });
25
+ this.projectId = projectId;
26
+ }
27
+ getSpecifications(query) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ try {
30
+ const res = yield new api_1.default(this.opts).get(`/zest/v1/project/${this.projectId}/specifications`, {
31
+ qs: query,
32
+ log: {
33
+ awaitingSpinner: 'Getting Zest Specifications'
34
+ }
35
+ });
36
+ if (res.body || res.status === 204) {
37
+ return res.body;
38
+ }
39
+ (0, logger_1.debug)('get specifications response from server : ' + res.body);
40
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
41
+ exit: 2
42
+ });
43
+ }
44
+ catch (err) {
45
+ if (err.status === 429) {
46
+ const responseData = err.context;
47
+ const retryAfter = responseData.response.headers['Retry-After'];
48
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () { return yield this.getSpecifications(query); }), (retryAfter ? parseInt(retryAfter, 10) : 1) * 1000);
49
+ }
50
+ throw err;
51
+ }
52
+ });
53
+ }
54
+ generateFunction(resources, specEnv, name) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const res = yield new api_1.default(this.opts).post(`/zest/v1/project/${this.projectId}/specifications/actions/generate_function`, {
57
+ body: {
58
+ name,
59
+ stack: specEnv,
60
+ resources: resources
61
+ },
62
+ log: {
63
+ awaitingSpinner: `Scheduling Function Generation ${name}`
64
+ }
65
+ });
66
+ if (res.body && res.body.details && res.body.code === 'SCHEDULED') {
67
+ return res.body.details;
68
+ }
69
+ (0, logger_1.debug)('generate function response from server : ' + res.body);
70
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
71
+ exit: 2
72
+ });
73
+ });
74
+ }
75
+ generateAppsail(requestJson) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const res = yield new api_1.default(this.opts).post(`/zest/v1/project/${this.projectId}/specifications/actions/generate_appsail`, {
78
+ body: requestJson,
79
+ log: {
80
+ awaitingSpinner: `Scheduling Appsail Generation${requestJson.name}`
81
+ }
82
+ });
83
+ if (res.body && res.body.details && res.body.code === 'SCHEDULED') {
84
+ return res.body.details;
85
+ }
86
+ (0, logger_1.debug)('generate appsail response from server : ' + res.body);
87
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
88
+ exit: 2
89
+ });
90
+ });
91
+ }
92
+ getScheduledJob(job_id) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const res = yield new api_1.default(this.opts).get(`/zest/v1/scheduled_jobs/${job_id}`);
95
+ if (res.body) {
96
+ return res.body;
97
+ }
98
+ (0, logger_1.debug)('get scheduled job response from server : ' + res.body);
99
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
100
+ exit: 2
101
+ });
102
+ });
103
+ }
104
+ getFile(file_id, source, name) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const res = yield new api_1.default(Object.assign(Object.assign({}, this.opts), { json: false })).get(`/zest/v1/files/${file_id}`, {
107
+ encoding: null,
108
+ log: {
109
+ progress: {
110
+ title: `${js_1.JS.capitalize(source)} (${name})`
111
+ }
112
+ }
113
+ });
114
+ if (res.body) {
115
+ return res.body;
116
+ }
117
+ (0, logger_1.debug)('get file response from server : ' + res);
118
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
119
+ exit: 2
120
+ });
121
+ });
122
+ }
123
+ }
124
+ exports.default = Zest;