@botonic/cli 0.40.1 → 0.41.0-alpha.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.
Files changed (95) hide show
  1. package/README.md +0 -175
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +5 -0
  4. package/bin/run.js +5 -0
  5. package/lib/{botonic-api-service.d.ts → src/botonic-api-service.d.ts} +3 -3
  6. package/lib/src/botonic-api-service.js +245 -0
  7. package/lib/src/botonic-api-service.js.map +1 -0
  8. package/lib/src/botonic-examples.d.ts +2 -0
  9. package/lib/src/botonic-examples.js +28 -0
  10. package/lib/src/botonic-examples.js.map +1 -0
  11. package/lib/{commands → src/commands}/deploy.d.ts +13 -22
  12. package/lib/src/commands/deploy.js +346 -0
  13. package/lib/src/commands/deploy.js.map +1 -0
  14. package/lib/src/commands/login.d.ts +11 -0
  15. package/lib/src/commands/login.js +33 -0
  16. package/lib/src/commands/login.js.map +1 -0
  17. package/lib/src/commands/logout.d.ts +11 -0
  18. package/lib/src/commands/logout.js +22 -0
  19. package/lib/src/commands/logout.js.map +1 -0
  20. package/lib/{commands → src/commands}/new.d.ts +8 -11
  21. package/lib/src/commands/new.js +134 -0
  22. package/lib/src/commands/new.js.map +1 -0
  23. package/lib/{commands → src/commands}/serve.d.ts +3 -3
  24. package/lib/src/commands/serve.js +22 -0
  25. package/lib/src/commands/serve.js.map +1 -0
  26. package/lib/src/constants.js +7 -0
  27. package/lib/src/constants.js.map +1 -0
  28. package/lib/src/index.d.ts +1 -0
  29. package/lib/src/index.js +2 -0
  30. package/lib/src/index.js.map +1 -0
  31. package/lib/{interfaces.d.ts → src/interfaces.d.ts} +9 -0
  32. package/lib/src/interfaces.js +2 -0
  33. package/lib/{interfaces.js.map → src/interfaces.js.map} +1 -1
  34. package/lib/src/util/bot-config.js +98 -0
  35. package/lib/src/util/bot-config.js.map +1 -0
  36. package/lib/{analytics → src/util}/credentials-handler.d.ts +1 -1
  37. package/lib/src/util/credentials-handler.js +73 -0
  38. package/lib/src/util/credentials-handler.js.map +1 -0
  39. package/lib/src/util/download-gzip.js +71 -0
  40. package/lib/src/util/download-gzip.js.map +1 -0
  41. package/lib/{util → src/util}/environment-info.d.ts +1 -1
  42. package/lib/src/util/environment-info.js +46 -0
  43. package/lib/src/util/environment-info.js.map +1 -0
  44. package/lib/{util → src/util}/file-system.d.ts +2 -2
  45. package/lib/src/util/file-system.js +45 -0
  46. package/lib/src/util/file-system.js.map +1 -0
  47. package/lib/src/util/system.js +32 -0
  48. package/lib/src/util/system.js.map +1 -0
  49. package/lib/tsconfig.tsbuildinfo +1 -0
  50. package/oclif.manifest.json +191 -1
  51. package/package.json +43 -36
  52. package/bin/run +0 -5
  53. package/lib/analytics/credentials-handler.js +0 -77
  54. package/lib/analytics/credentials-handler.js.map +0 -1
  55. package/lib/botonic-api-service.js +0 -274
  56. package/lib/botonic-api-service.js.map +0 -1
  57. package/lib/botonic-examples.d.ts +0 -2
  58. package/lib/botonic-examples.js +0 -76
  59. package/lib/botonic-examples.js.map +0 -1
  60. package/lib/commands/deploy.js +0 -422
  61. package/lib/commands/deploy.js.map +0 -1
  62. package/lib/commands/login.d.ts +0 -16
  63. package/lib/commands/login.js +0 -47
  64. package/lib/commands/login.js.map +0 -1
  65. package/lib/commands/logout.d.ts +0 -11
  66. package/lib/commands/logout.js +0 -29
  67. package/lib/commands/logout.js.map +0 -1
  68. package/lib/commands/new.js +0 -159
  69. package/lib/commands/new.js.map +0 -1
  70. package/lib/commands/serve.js +0 -28
  71. package/lib/commands/serve.js.map +0 -1
  72. package/lib/commands/test.d.ts +0 -8
  73. package/lib/commands/test.js +0 -43
  74. package/lib/commands/test.js.map +0 -1
  75. package/lib/constants.js +0 -10
  76. package/lib/constants.js.map +0 -1
  77. package/lib/index.d.ts +0 -1
  78. package/lib/index.js +0 -6
  79. package/lib/index.js.map +0 -1
  80. package/lib/interfaces.js +0 -3
  81. package/lib/util/bot-config.js +0 -114
  82. package/lib/util/bot-config.js.map +0 -1
  83. package/lib/util/download-gzip.js +0 -87
  84. package/lib/util/download-gzip.js.map +0 -1
  85. package/lib/util/environment-info.js +0 -53
  86. package/lib/util/environment-info.js.map +0 -1
  87. package/lib/util/file-system.js +0 -59
  88. package/lib/util/file-system.js.map +0 -1
  89. package/lib/util/system.js +0 -43
  90. package/lib/util/system.js.map +0 -1
  91. package/scripts/postinstall.js +0 -13
  92. /package/lib/{constants.d.ts → src/constants.d.ts} +0 -0
  93. /package/lib/{util → src/util}/bot-config.d.ts +0 -0
  94. /package/lib/{util → src/util}/download-gzip.d.ts +0 -0
  95. /package/lib/{util → src/util}/system.d.ts +0 -0
@@ -1 +1,191 @@
1
- {"version":"0.40.1","commands":{"deploy":{"id":"deploy","description":"Deploy Botonic project to cloud provider","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":["$ botonic deploy\nBuilding...\nCreating bundle...\nUploading...\n🚀 Bot deployed!\n","$ botonic deploy aws\nDeploying to AWS...\n"],"flags":{"command":{"name":"command","type":"option","char":"c","description":"Command to execute from the package \"scripts\" object"},"email":{"name":"email","type":"option","char":"e","description":"Email from Hubtype Organization"},"password":{"name":"password","type":"option","char":"p","description":"Password from Hubtype Organization"},"botName":{"name":"botName","type":"option","char":"b","description":"Name of the bot from Hubtype where you want to deploy"}},"args":[{"name":"provider","options":["hubtype"]}]},"login":{"id":"login","description":"Log in to Botonic","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":[],"flags":{"path":{"name":"path","type":"option","char":"p","description":"Path to botonic project. Defaults to current dir."}},"args":[]},"logout":{"id":"logout","description":"Log out of Botonic","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":[],"flags":{"path":{"name":"path","type":"option","char":"p","description":"Path to botonic project. Defaults to current dir."}},"args":[]},"new":{"id":"new","description":"Create a new Botonic project","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":["$ botonic new test_bot\nCreating...\n✨ test_bot was successfully created!\n"],"flags":{},"args":[{"name":"name","description":"name of the bot folder","required":true},{"name":"projectName","description":"OPTIONAL name of the bot project","required":false}]},"serve":{"id":"serve","description":"Serve your bot in your localhost","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":["$ botonic serve\n> Project is running at http://localhost:8080/"],"flags":{},"args":[]},"test":{"id":"test","description":"Test your Botonic components","pluginName":"@botonic/cli","pluginType":"core","aliases":[],"examples":["PASS tests/app.test.js\n ✓ TEST: hi.js (10ms)\n ✓ TEST: pizza.js (1ms)\n ✓ TEST: sausage.js (1ms)\n ✓ TEST: bacon.js\n ✓ TEST: pasta.js (1ms)\n ✓ TEST: cheese.js (1ms)\n ✓ TEST: tomato.js\n\nTest Suites: 1 passed, 1 total\nTests: 7 passed, 7 total\nSnapshots: 0 total\nTime: 1.223s\nRan all test suites."],"flags":{},"args":[]}}}
1
+ {
2
+ "commands": {
3
+ "deploy": {
4
+ "aliases": [],
5
+ "args": {
6
+ "provider": {
7
+ "description": "Provider to deploy to",
8
+ "name": "provider",
9
+ "options": [
10
+ "hubtype"
11
+ ]
12
+ }
13
+ },
14
+ "description": "Deploy Botonic project to cloud provider",
15
+ "examples": [
16
+ "$ botonic deploy\nBuilding...\nCreating bundle...\nUploading...\n🚀 Bot deployed!"
17
+ ],
18
+ "flags": {
19
+ "command": {
20
+ "char": "c",
21
+ "description": "Command to execute from the package \"scripts\" object",
22
+ "name": "command",
23
+ "hasDynamicHelp": false,
24
+ "multiple": false,
25
+ "type": "option"
26
+ },
27
+ "email": {
28
+ "char": "e",
29
+ "description": "Email from Hubtype Organization",
30
+ "name": "email",
31
+ "hasDynamicHelp": false,
32
+ "multiple": false,
33
+ "type": "option"
34
+ },
35
+ "password": {
36
+ "char": "p",
37
+ "description": "Password from Hubtype Organization",
38
+ "name": "password",
39
+ "hasDynamicHelp": false,
40
+ "multiple": false,
41
+ "type": "option"
42
+ },
43
+ "botName": {
44
+ "char": "b",
45
+ "description": "Name of the bot from Hubtype where you want to deploy",
46
+ "name": "botName",
47
+ "hasDynamicHelp": false,
48
+ "multiple": false,
49
+ "type": "option"
50
+ }
51
+ },
52
+ "hasDynamicHelp": false,
53
+ "hiddenAliases": [],
54
+ "id": "deploy",
55
+ "pluginAlias": "@botonic/cli",
56
+ "pluginName": "@botonic/cli",
57
+ "pluginType": "core",
58
+ "strict": true,
59
+ "enableJsonFlag": false,
60
+ "isESM": true,
61
+ "relativePath": [
62
+ "lib",
63
+ "src",
64
+ "commands",
65
+ "deploy.js"
66
+ ]
67
+ },
68
+ "login": {
69
+ "aliases": [],
70
+ "args": {},
71
+ "description": "Log in to Botonic",
72
+ "examples": [],
73
+ "flags": {
74
+ "path": {
75
+ "char": "p",
76
+ "description": "Path to botonic project. Defaults to current dir.",
77
+ "name": "path",
78
+ "hasDynamicHelp": false,
79
+ "multiple": false,
80
+ "type": "option"
81
+ }
82
+ },
83
+ "hasDynamicHelp": false,
84
+ "hiddenAliases": [],
85
+ "id": "login",
86
+ "pluginAlias": "@botonic/cli",
87
+ "pluginName": "@botonic/cli",
88
+ "pluginType": "core",
89
+ "strict": true,
90
+ "enableJsonFlag": false,
91
+ "isESM": true,
92
+ "relativePath": [
93
+ "lib",
94
+ "src",
95
+ "commands",
96
+ "login.js"
97
+ ]
98
+ },
99
+ "logout": {
100
+ "aliases": [],
101
+ "args": {},
102
+ "description": "Log out of Botonic",
103
+ "examples": [],
104
+ "flags": {
105
+ "path": {
106
+ "char": "p",
107
+ "description": "Path to botonic project. Defaults to current dir.",
108
+ "name": "path",
109
+ "hasDynamicHelp": false,
110
+ "multiple": false,
111
+ "type": "option"
112
+ }
113
+ },
114
+ "hasDynamicHelp": false,
115
+ "hiddenAliases": [],
116
+ "id": "logout",
117
+ "pluginAlias": "@botonic/cli",
118
+ "pluginName": "@botonic/cli",
119
+ "pluginType": "core",
120
+ "strict": true,
121
+ "enableJsonFlag": false,
122
+ "isESM": true,
123
+ "relativePath": [
124
+ "lib",
125
+ "src",
126
+ "commands",
127
+ "logout.js"
128
+ ]
129
+ },
130
+ "new": {
131
+ "aliases": [],
132
+ "args": {
133
+ "name": {
134
+ "description": "name of the bot folder",
135
+ "name": "name",
136
+ "required": true
137
+ },
138
+ "projectName": {
139
+ "description": "OPTIONAL name of the bot project",
140
+ "name": "projectName",
141
+ "required": false
142
+ }
143
+ },
144
+ "description": "Create a new Botonic project",
145
+ "examples": [
146
+ "$ botonic new test_bot\nCreating...\n✨ test_bot was successfully created!"
147
+ ],
148
+ "flags": {},
149
+ "hasDynamicHelp": false,
150
+ "hiddenAliases": [],
151
+ "id": "new",
152
+ "pluginAlias": "@botonic/cli",
153
+ "pluginName": "@botonic/cli",
154
+ "pluginType": "core",
155
+ "strict": true,
156
+ "enableJsonFlag": false,
157
+ "isESM": true,
158
+ "relativePath": [
159
+ "lib",
160
+ "src",
161
+ "commands",
162
+ "new.js"
163
+ ]
164
+ },
165
+ "serve": {
166
+ "aliases": [],
167
+ "args": {},
168
+ "description": "Serve your bot in your localhost",
169
+ "examples": [
170
+ "$ botonic serve\n> Project is running at http://localhost:8080/"
171
+ ],
172
+ "flags": {},
173
+ "hasDynamicHelp": false,
174
+ "hiddenAliases": [],
175
+ "id": "serve",
176
+ "pluginAlias": "@botonic/cli",
177
+ "pluginName": "@botonic/cli",
178
+ "pluginType": "core",
179
+ "strict": true,
180
+ "enableJsonFlag": false,
181
+ "isESM": true,
182
+ "relativePath": [
183
+ "lib",
184
+ "src",
185
+ "commands",
186
+ "serve.js"
187
+ ]
188
+ }
189
+ },
190
+ "version": "0.41.0-alpha.0"
191
+ }
package/package.json CHANGED
@@ -1,45 +1,50 @@
1
1
  {
2
2
  "name": "@botonic/cli",
3
3
  "description": "Build Chatbots Using React",
4
- "version": "0.40.1",
4
+ "version": "0.41.0-alpha.0",
5
5
  "license": "MIT",
6
6
  "bin": {
7
- "botonic": "./bin/run"
7
+ "botonic": "./bin/run.js"
8
8
  },
9
9
  "scripts": {
10
10
  "prepublishOnly": "npm i && npm run build",
11
- "build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json",
12
- "build:watch": "rm -rf lib && ../../node_modules/.bin/tsc -w",
13
- "postpack": "rm -f oclif.manifest.json",
14
- "prepack": "oclif-dev manifest && oclif-dev readme",
15
- "version": "oclif-dev readme && git add README.md",
16
- "postinstall": "node scripts/postinstall.js",
11
+ "build": "shx rm -rf lib && tsc -b",
12
+ "postpack": "shx rm -f oclif.manifest.json",
13
+ "posttest": "npm run lint",
14
+ "prepack": "oclif manifest && oclif readme",
17
15
  "lint": "npm run lint_core -- --fix",
18
- "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'",
19
- "test": "../../node_modules/.bin/jest --coverage",
20
- "test_ci": "../../node_modules/.bin/jest --coverage --ci --reporters=default --reporters=jest-junit"
16
+ "lint_core": "../../node_modules/.bin/eslint --quiet",
17
+ "test": "node --experimental-vm-modules --no-warnings=ExperimentalWarning ../../node_modules/.bin/jest --coverage",
18
+ "test_ci": "node --experimental-vm-modules --no-warnings=ExperimentalWarning ../../node_modules/.bin/jest --coverage --ci --reporters=default --reporters=jest-junit",
19
+ "version": "oclif readme && git add README.md"
21
20
  },
22
21
  "dependencies": {
23
- "@oclif/command": "^1.8.36",
24
- "@oclif/config": "^1.18.17",
25
- "@oclif/plugin-help": "^3.3.1",
22
+ "@inquirer/prompts": "^7.8.6",
23
+ "@oclif/core": "^4.5.4",
24
+ "@oclif/plugin-help": "^6.2.33",
26
25
  "axios": "^1.12.2",
27
- "colors": "^1.4.0",
28
- "form-data": "^3.0.2",
29
- "fs-extra": "^10.1.0",
30
- "inquirer": "^7.3.3",
31
- "ora": "^5.4.1",
32
- "qs": "^6.14.0",
33
- "tar": "^6.2.1",
26
+ "fs-extra": "^11.3.2",
27
+ "ora": "^9.0.0",
28
+ "picocolors": "^1.1.1",
34
29
  "tslib": "^2.8.1",
35
- "zip-a-folder": "3.1.8"
30
+ "zip-a-folder": "^3.1.9"
36
31
  },
37
32
  "devDependencies": {
38
- "@oclif/dev-cli": "^1.26.10",
39
- "@types/fs-extra": "^9.0.13",
40
- "@types/inquirer": "^7.3.3",
41
- "@types/tar": "^6.1.13",
42
- "globby": "^11.1.0"
33
+ "@eslint/compat": "^1.0.0",
34
+ "@oclif/prettier-config": "^0.2.1",
35
+ "@oclif/test": "^4.1.14",
36
+ "@swc/jest": "^0.2.39",
37
+ "@types/fs-extra": "^11.0.4",
38
+ "@types/jest": "^29.5.14",
39
+ "@types/node": "^22.0.0",
40
+ "eslint": "^9.0.0",
41
+ "eslint-config-oclif": "^6.0.0",
42
+ "eslint-config-prettier": "^10.1.8",
43
+ "oclif": "^4.22.27",
44
+ "shx": "^0.3.3",
45
+ "ts-jest": "^29.2.5",
46
+ "ts-node": "^10.9.2",
47
+ "typescript": "^5.9.3"
43
48
  },
44
49
  "engines": {
45
50
  "node": ">=22.19.0",
@@ -47,23 +52,25 @@
47
52
  },
48
53
  "bugs": "https://github.com/hubtype/botonic/issues",
49
54
  "files": [
50
- "/bin",
51
- "/lib",
52
- "/npm-shrinkwrap.json",
53
- "/oclif.manifest.json",
54
- "/scripts"
55
+ "./bin",
56
+ "./lib",
57
+ "./lib",
58
+ "./oclif.manifest.json"
55
59
  ],
56
60
  "homepage": "https://github.com/hubtype/botonic",
57
- "main": "lib/index.js",
61
+ "main": "lib/src/index.js",
62
+ "type": "module",
58
63
  "oclif": {
59
- "commands": "./lib/commands",
60
64
  "bin": "botonic",
65
+ "dirname": "botonic",
66
+ "commands": "./lib/src/commands",
61
67
  "plugins": [
62
- "@oclif/plugin-help"
68
+ "@oclif/plugin-help",
69
+ "@oclif/plugin-plugins"
63
70
  ]
64
71
  },
65
72
  "repository": "hubtype/botonic",
66
- "types": "lib/index.d.ts",
73
+ "types": "lib/src/index.d.ts",
67
74
  "keywords": [
68
75
  "bot-framework",
69
76
  "chatbot",
package/bin/run DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('@oclif/command').run()
4
- .then(require('@oclif/command/flush'))
5
- .catch(require('@oclif/errors/handle'))
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BotCredentialsHandler = exports.GlobalCredentialsHandler = exports.CredentialsHandler = void 0;
4
- const path_1 = require("path");
5
- const constants_1 = require("../constants");
6
- const file_system_1 = require("../util/file-system");
7
- class CredentialsHandler {
8
- constructor(args) {
9
- this.homeDir = (0, path_1.resolve)(args.homeDir);
10
- this.pathToCredentials = (0, path_1.join)(this.homeDir, args.filename);
11
- this.initialize();
12
- }
13
- initialize() {
14
- this.createDirIfNotExists();
15
- }
16
- createDirIfNotExists() {
17
- if (!(0, file_system_1.pathExists)(this.homeDir))
18
- (0, file_system_1.createDir)(this.homeDir);
19
- }
20
- loadJSON() {
21
- try {
22
- if (!(0, file_system_1.pathExists)(this.pathToCredentials))
23
- return undefined;
24
- return (0, file_system_1.readJSON)(this.pathToCredentials);
25
- }
26
- catch (e) {
27
- console.warn('Credentials could not be loaded');
28
- return undefined;
29
- }
30
- }
31
- dumpJSON(obj) {
32
- try {
33
- (0, file_system_1.writeJSON)(this.pathToCredentials, obj);
34
- }
35
- catch (e) {
36
- console.warn('Credentials could not be overwritten');
37
- }
38
- }
39
- }
40
- exports.CredentialsHandler = CredentialsHandler;
41
- class GlobalCredentialsHandler extends CredentialsHandler {
42
- constructor() {
43
- super({
44
- homeDir: (0, path_1.join)((0, file_system_1.getHomeDirectory)(), constants_1.BOTONIC_HOME_DIRNAME),
45
- filename: constants_1.GLOBAL_CREDENTIALS_FILENAME,
46
- });
47
- }
48
- initialize() {
49
- this.createDirIfNotExists();
50
- }
51
- load() {
52
- const json = this.loadJSON();
53
- if (!json)
54
- return undefined;
55
- return json;
56
- }
57
- dump(obj) {
58
- return this.dumpJSON(obj);
59
- }
60
- }
61
- exports.GlobalCredentialsHandler = GlobalCredentialsHandler;
62
- class BotCredentialsHandler extends CredentialsHandler {
63
- constructor() {
64
- super({ homeDir: constants_1.BOTONIC_PROJECT_PATH, filename: constants_1.BOT_CREDENTIALS_FILENAME });
65
- }
66
- load() {
67
- const json = this.loadJSON();
68
- if (!json)
69
- return undefined;
70
- return json;
71
- }
72
- dump(obj) {
73
- return this.dumpJSON(obj);
74
- }
75
- }
76
- exports.BotCredentialsHandler = BotCredentialsHandler;
77
- //# sourceMappingURL=credentials-handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credentials-handler.js","sourceRoot":"","sources":["../../src/analytics/credentials-handler.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAEpC,4CAKqB;AAOrB,qDAM4B;AAE5B,MAAa,kBAAkB;IAI7B,YAAY,IAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACpC,IAAI,CAAC,iBAAiB,GAAG,IAAA,WAAI,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAA;IACnB,CAAC;IAED,UAAU;QACR,IAAI,CAAC,oBAAoB,EAAE,CAAA;IAC7B,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YAAE,IAAA,uBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACxD,CAAC;IAED,QAAQ;QACN,IAAI;YACF,IAAI,CAAC,IAAA,wBAAU,EAAC,IAAI,CAAC,iBAAiB,CAAC;gBAAE,OAAO,SAAS,CAAA;YACzD,OAAO,IAAA,sBAAQ,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;SACxC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAA;YAC/C,OAAO,SAAS,CAAA;SACjB;IACH,CAAC;IAED,QAAQ,CAAC,GAAe;QACtB,IAAI;YACF,IAAA,uBAAS,EAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;SACvC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;SACrD;IACH,CAAC;CACF;AAnCD,gDAmCC;AAED,MAAa,wBAAyB,SAAQ,kBAAkB;IAC9D;QACE,KAAK,CAAC;YACJ,OAAO,EAAE,IAAA,WAAI,EAAC,IAAA,8BAAgB,GAAE,EAAE,gCAAoB,CAAC;YACvD,QAAQ,EAAE,uCAA2B;SACtC,CAAC,CAAA;IACJ,CAAC;IAED,UAAU;QACR,IAAI,CAAC,oBAAoB,EAAE,CAAA;IAC7B,CAAC;IAED,IAAI;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAC5B,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAA;QAC3B,OAAO,IAAoC,CAAA;IAC7C,CAAC;IAED,IAAI,CAAC,GAAsB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAA4B,CAAC,CAAA;IACpD,CAAC;CACF;AArBD,4DAqBC;AAED,MAAa,qBAAsB,SAAQ,kBAAkB;IAC3D;QACE,KAAK,CAAC,EAAE,OAAO,EAAE,gCAAoB,EAAE,QAAQ,EAAE,oCAAwB,EAAE,CAAC,CAAA;IAC9E,CAAC;IAED,IAAI;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAC5B,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAA;QAC3B,OAAO,IAAiC,CAAA;IAC1C,CAAC;IAED,IAAI,CAAC,GAAmB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAA4B,CAAC,CAAA;IACpD,CAAC;CACF;AAdD,sDAcC"}
@@ -1,274 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BotonicAPIService = void 0;
4
- const tslib_1 = require("tslib");
5
- /* eslint-disable @typescript-eslint/naming-convention */
6
- const axios_1 = tslib_1.__importStar(require("axios"));
7
- const child_process_1 = tslib_1.__importDefault(require("child_process"));
8
- const colors_1 = tslib_1.__importDefault(require("colors"));
9
- const form_data_1 = tslib_1.__importDefault(require("form-data"));
10
- const fs_1 = require("fs");
11
- const ora_1 = tslib_1.__importDefault(require("ora"));
12
- const qs_1 = require("qs");
13
- const util = tslib_1.__importStar(require("util"));
14
- const credentials_handler_1 = require("./analytics/credentials-handler");
15
- const file_system_1 = require("./util/file-system");
16
- const exec = util.promisify(child_process_1.default.exec);
17
- const BOTONIC_CLIENT_ID = process.env.BOTONIC_CLIENT_ID || 'jOIYDdvcfwqwSs7ZJ1CpmTKcE7UDapZDOSobFmEp';
18
- const BOTONIC_URL = process.env.BOTONIC_URL || 'https://api.hubtype.com';
19
- class BotonicAPIService {
20
- constructor() {
21
- var _a;
22
- this.clientId = BOTONIC_CLIENT_ID;
23
- this.baseUrl = BOTONIC_URL;
24
- this.loginUrl = this.baseUrl + '/o/token/';
25
- this.botCredentialsHandler = new credentials_handler_1.BotCredentialsHandler();
26
- this.globalCredentialsHandler = new credentials_handler_1.GlobalCredentialsHandler();
27
- this.loadGlobalCredentials();
28
- this.loadBotCredentials();
29
- this.setHeaders((_a = this.oauth) === null || _a === void 0 ? void 0 : _a.access_token);
30
- this.apiClient = axios_1.default.create({
31
- baseURL: BOTONIC_URL,
32
- headers: this.headers,
33
- });
34
- const onFulfilled = (response) => {
35
- return response;
36
- };
37
- const onRejected = (error) => tslib_1.__awaiter(this, void 0, void 0, function* () {
38
- var _b;
39
- const originalRequest = error.config;
40
- const retry = originalRequest === null || originalRequest === void 0 ? void 0 : originalRequest._retry;
41
- if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 401 && !retry) {
42
- originalRequest._retry = true;
43
- yield this.refreshToken();
44
- const nextRequest = Object.assign(Object.assign({}, originalRequest), { headers: this.headers });
45
- return this.apiClient.request(nextRequest);
46
- }
47
- return Promise.reject(error);
48
- });
49
- this.apiClient.interceptors.response.use(onFulfilled, onRejected);
50
- }
51
- beforeExit() {
52
- this.saveGlobalCredentials();
53
- this.saveBotCredentials();
54
- }
55
- botInfo() {
56
- if (!this.bot) {
57
- throw new Error('Not bot info available');
58
- }
59
- return this.bot;
60
- }
61
- getOauth() {
62
- if (!this.oauth) {
63
- throw new Error('Not OAuth available');
64
- }
65
- return this.oauth;
66
- }
67
- loadGlobalCredentials() {
68
- const credentials = this.globalCredentialsHandler.load();
69
- if (credentials) {
70
- this.oauth = credentials.oauth;
71
- this.me = credentials.me;
72
- }
73
- }
74
- loadBotCredentials() {
75
- const credentials = this.botCredentialsHandler.load();
76
- if (credentials === null || credentials === void 0 ? void 0 : credentials.bot) {
77
- this.bot = credentials.bot;
78
- }
79
- }
80
- setHeaders(accessToken) {
81
- if (accessToken) {
82
- this.headers = new axios_1.AxiosHeaders({
83
- Authorization: `Bearer ${accessToken}`,
84
- 'content-type': 'application/json',
85
- });
86
- }
87
- }
88
- saveGlobalCredentials() {
89
- this.globalCredentialsHandler.createDirIfNotExists();
90
- this.globalCredentialsHandler.dump({ oauth: this.oauth, me: this.me });
91
- }
92
- saveBotCredentials() {
93
- this.botCredentialsHandler.dump({ bot: this.bot });
94
- }
95
- build(npmCommand = 'build') {
96
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
97
- const spinner = (0, ora_1.default)({ text: 'Building...', spinner: 'bouncingBar' }).start();
98
- try {
99
- yield exec(`npm run ${npmCommand}`);
100
- }
101
- catch (error) {
102
- spinner.fail();
103
- console.log(`${String(error.stdout)}` +
104
- colors_1.default.red(`\n\nBuild error:\n${String(error)}`));
105
- return false;
106
- }
107
- spinner.succeed();
108
- return true;
109
- });
110
- }
111
- setCurrentBot(bot) {
112
- this.bot = bot;
113
- }
114
- logout() {
115
- const pathToCredentials = this.globalCredentialsHandler.pathToCredentials;
116
- if ((0, file_system_1.pathExists)(pathToCredentials))
117
- (0, fs_1.unlinkSync)(pathToCredentials);
118
- }
119
- apiPost({ apiVersion = 'v1', path, body, headers, params, }) {
120
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
121
- return this.apiClient.post(`${this.baseUrl}/${apiVersion}/${path}`, body, { headers: headers || this.headers, params });
122
- });
123
- }
124
- apiGet({ apiVersion = 'v1', path, headers, params, }) {
125
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
126
- return this.apiClient.get(`${this.baseUrl}/${apiVersion}/${path}`, {
127
- headers: headers || this.headers,
128
- params,
129
- });
130
- });
131
- }
132
- refreshToken() {
133
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
134
- const data = (0, qs_1.stringify)({
135
- callback: 'none',
136
- grant_type: 'refresh_token',
137
- refresh_token: this.getOauth().refresh_token,
138
- client_id: this.clientId,
139
- });
140
- const oauthResponse = yield axios_1.default.post(this.loginUrl, data, {
141
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
142
- });
143
- if (oauthResponse.status !== 200) {
144
- throw new Error('Error refreshing token');
145
- }
146
- this.oauth = oauthResponse.data;
147
- const accessToken = this.getOauth().access_token;
148
- this.setHeaders(accessToken);
149
- this.saveGlobalCredentials();
150
- });
151
- }
152
- login(email, password) {
153
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
154
- const data = (0, qs_1.stringify)({
155
- username: email,
156
- password: password,
157
- grant_type: 'password',
158
- client_id: this.clientId,
159
- });
160
- const loginResponse = yield axios_1.default.post(this.loginUrl, data, {
161
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
162
- });
163
- this.oauth = loginResponse.data;
164
- const accessToken = this.getOauth().access_token;
165
- this.setHeaders(accessToken);
166
- const meResponse = yield this.getMe();
167
- if (meResponse) {
168
- this.me = meResponse.data;
169
- }
170
- });
171
- }
172
- signup(email, password, orgName, campaign) {
173
- const signupData = { email, password, org_name: orgName, campaign };
174
- return this.apiPost({ path: 'sign-up/', body: signupData });
175
- }
176
- createBot(botName) {
177
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
178
- const resp = yield this.apiPost({
179
- apiVersion: 'v2',
180
- path: 'bots/',
181
- body: { name: botName },
182
- });
183
- if (resp.data) {
184
- this.setCurrentBot(resp.data);
185
- }
186
- return resp;
187
- });
188
- }
189
- getMe() {
190
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
191
- return this.apiGet({ path: 'users/me/', apiVersion: 'v3' });
192
- });
193
- }
194
- getBots() {
195
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
196
- const botsResponse = yield this.apiGet({
197
- apiVersion: 'v2',
198
- path: 'bots/?page_size=100',
199
- });
200
- if (botsResponse.data.next) {
201
- yield this.getMoreBots(botsResponse.data.results, botsResponse.data.next);
202
- }
203
- return botsResponse;
204
- });
205
- }
206
- getMoreBots(bots, nextUrl) {
207
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
208
- if (!nextUrl) {
209
- return bots;
210
- }
211
- const resp = yield this.apiGet({
212
- apiVersion: 'v2',
213
- path: nextUrl.split(`${this.baseUrl}/v2/`)[1],
214
- });
215
- resp.data.results.forEach(bot => bots.push(bot));
216
- nextUrl = resp.data.next;
217
- return this.getMoreBots(bots, nextUrl);
218
- });
219
- }
220
- getProviders() {
221
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
222
- return this.apiGet({
223
- path: 'provider_accounts/',
224
- params: { bot_id: this.botInfo().id },
225
- });
226
- });
227
- }
228
- deployBot(bundlePath, botConfigJson) {
229
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
230
- try {
231
- yield this.getMe();
232
- }
233
- catch (e) {
234
- console.log(`Error authenticating: ${String(e)}`);
235
- }
236
- const form = new form_data_1.default();
237
- const data = (0, fs_1.createReadStream)(bundlePath);
238
- form.append('bundle', data, 'botonic_bundle.zip');
239
- form.append('bot_config', JSON.stringify(botConfigJson));
240
- const headers = yield this.getHeaders(form);
241
- return yield this.apiPost({
242
- apiVersion: 'v2',
243
- path: `bots/${this.botInfo().id}/deploy/`,
244
- body: form,
245
- headers: Object.assign(Object.assign({}, this.headers), headers),
246
- });
247
- });
248
- }
249
- deployStatus(deployId) {
250
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
251
- return this.apiGet({
252
- apiVersion: 'v2',
253
- path: `bots/${this.botInfo().id}/deploy_status/`,
254
- params: { deploy_id: deployId },
255
- });
256
- });
257
- }
258
- getHeaders(form) {
259
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
260
- //https://github.com/axios/axios/issues/1006#issuecomment-352071490
261
- return new Promise((resolve, reject) => {
262
- form.getLength((err, length) => {
263
- if (err) {
264
- reject(err);
265
- }
266
- const headers = Object.assign({ 'Content-Length': length }, form.getHeaders());
267
- resolve(headers);
268
- });
269
- });
270
- });
271
- }
272
- }
273
- exports.BotonicAPIService = BotonicAPIService;
274
- //# sourceMappingURL=botonic-api-service.js.map