@botonic/nx-plugin 2.23.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 (206) hide show
  1. package/CHANGELOG.md +420 -0
  2. package/README.md +279 -0
  3. package/executors.json +55 -0
  4. package/generators.json +61 -0
  5. package/migrations.json +40 -0
  6. package/package.json +54 -0
  7. package/src/cursor-commands/update-bot.md +114 -0
  8. package/src/cursor-commands/update-botonic.md +63 -0
  9. package/src/executors/build-node-app/executor.d.ts +5 -0
  10. package/src/executors/build-node-app/executor.js +65 -0
  11. package/src/executors/build-node-app/schema.d.js +16 -0
  12. package/src/executors/build-node-app/schema.json +25 -0
  13. package/src/executors/delete-bot/executor.d.ts +5 -0
  14. package/src/executors/delete-bot/executor.js +112 -0
  15. package/src/executors/delete-bot/schema.d.js +16 -0
  16. package/src/executors/delete-bot/schema.json +35 -0
  17. package/src/executors/deploy-local-runtime/executor.d.ts +5 -0
  18. package/src/executors/deploy-local-runtime/executor.js +144 -0
  19. package/src/executors/deploy-local-runtime/schema.d.js +16 -0
  20. package/src/executors/deploy-local-runtime/schema.json +34 -0
  21. package/src/executors/deploy-netlify-snapshot/executor.d.ts +8 -0
  22. package/src/executors/deploy-netlify-snapshot/executor.js +79 -0
  23. package/src/executors/deploy-netlify-snapshot/schema.d.js +16 -0
  24. package/src/executors/deploy-netlify-snapshot/schema.json +31 -0
  25. package/src/executors/deploy-to-hubtype/executor.d.ts +5 -0
  26. package/src/executors/deploy-to-hubtype/executor.js +308 -0
  27. package/src/executors/deploy-to-hubtype/schema.d.js +16 -0
  28. package/src/executors/deploy-to-hubtype/schema.json +31 -0
  29. package/src/executors/e2e-webchat/botonic-package-publish.spec.ts +84 -0
  30. package/src/executors/e2e-webchat/executor.d.ts +5 -0
  31. package/src/executors/e2e-webchat/executor.js +134 -0
  32. package/src/executors/e2e-webchat/schema.d.js +16 -0
  33. package/src/executors/e2e-webchat/schema.json +35 -0
  34. package/src/executors/integrate-provider/executor.d.ts +5 -0
  35. package/src/executors/integrate-provider/executor.js +155 -0
  36. package/src/executors/integrate-provider/schema.d.js +16 -0
  37. package/src/executors/integrate-provider/schema.json +30 -0
  38. package/src/executors/login-to-hubtype/executor.d.ts +5 -0
  39. package/src/executors/login-to-hubtype/executor.js +79 -0
  40. package/src/executors/login-to-hubtype/schema.d.js +16 -0
  41. package/src/executors/login-to-hubtype/schema.json +25 -0
  42. package/src/executors/logout-from-hubtype/executor.d.ts +3 -0
  43. package/src/executors/logout-from-hubtype/executor.js +54 -0
  44. package/src/executors/logout-from-hubtype/schema.d.js +16 -0
  45. package/src/executors/logout-from-hubtype/schema.json +9 -0
  46. package/src/executors/run-lambda/executor.d.ts +5 -0
  47. package/src/executors/run-lambda/executor.js +65 -0
  48. package/src/executors/run-lambda/schema.d.js +16 -0
  49. package/src/executors/run-lambda/schema.json +20 -0
  50. package/src/executors/serve-bot/executor.d.ts +5 -0
  51. package/src/executors/serve-bot/executor.js +330 -0
  52. package/src/executors/serve-bot/schema.d.js +16 -0
  53. package/src/executors/serve-bot/schema.json +40 -0
  54. package/src/generators/action/files/__name__.spec.ts.template +15 -0
  55. package/src/generators/action/files/__name__.ts.template +15 -0
  56. package/src/generators/action/generator.d.ts +4 -0
  57. package/src/generators/action/generator.js +112 -0
  58. package/src/generators/action/schema.d.ts +7 -0
  59. package/src/generators/action/schema.js +16 -0
  60. package/src/generators/action/schema.json +43 -0
  61. package/src/generators/bot-app/files/.eslintrc.json.template +18 -0
  62. package/src/generators/bot-app/files/README.md.template +148 -0
  63. package/src/generators/bot-app/files/src/client/custom-messages/index.ts.template +2 -0
  64. package/src/generators/bot-app/files/src/client/webchat/index.html.template +35 -0
  65. package/src/generators/bot-app/files/src/client/webchat/index.tsx.template +107 -0
  66. package/src/generators/bot-app/files/src/client/webchat/styles.css.template +17 -0
  67. package/src/generators/bot-app/files/src/client/webchat/webchat-tokens-overrides.css.template +2 -0
  68. package/src/generators/bot-app/files/src/client/webviews/app.tsx.template +8 -0
  69. package/src/generators/bot-app/files/src/client/webviews/index.html.template +32 -0
  70. package/src/generators/bot-app/files/src/client/webviews/index.tsx.template +18 -0
  71. package/src/generators/bot-app/files/src/server/bot/actions/index.ts.template +2 -0
  72. package/src/generators/bot-app/files/src/server/bot/actions/not-found.ts.template +13 -0
  73. package/src/generators/bot-app/files/src/server/bot/actions/welcome.ts.template +13 -0
  74. package/src/generators/bot-app/files/src/server/bot/index.ts.template +43 -0
  75. package/src/generators/bot-app/files/src/server/bot/plugins/ai-agents/index.ts.template +30 -0
  76. package/src/generators/bot-app/files/src/server/bot/plugins/flow-builder/index.ts.template +28 -0
  77. package/src/generators/bot-app/files/src/server/bot/plugins/index.ts.template +11 -0
  78. package/src/generators/bot-app/files/src/server/bot/routes.ts.template +23 -0
  79. package/src/generators/bot-app/files/src/server/bot/tools/index.ts.template +5 -0
  80. package/src/generators/bot-app/files/src/server/bot/tracking.ts.template +35 -0
  81. package/src/generators/bot-app/files/src/server/bot/types.ts.template +4 -0
  82. package/src/generators/bot-app/files/src/server/bot/utils.ts.template +9 -0
  83. package/src/generators/bot-app/files/src/server/lambda/handler.js.template +24 -0
  84. package/src/generators/bot-app/files/src/server/lambda/package.json +20 -0
  85. package/src/generators/bot-app/files/src/server/lambda/template.yaml.template +20 -0
  86. package/src/generators/bot-app/files/src/shared/constants.ts.template +12 -0
  87. package/src/generators/bot-app/files/vite/base-client.config.ts.template +14 -0
  88. package/src/generators/bot-app/files/vite/base.config.ts.template +20 -0
  89. package/src/generators/bot-app/files/vite/build.config.ts.template +65 -0
  90. package/src/generators/bot-app/files/vite/node.config.ts.template +41 -0
  91. package/src/generators/bot-app/files/vite/plugins/move-html.plugin.ts.template +36 -0
  92. package/src/generators/bot-app/files/vite/webchat.config.ts.template +58 -0
  93. package/src/generators/bot-app/files/vite/webviews.config.ts.template +57 -0
  94. package/src/generators/bot-app/files/vite.config.ts.template +36 -0
  95. package/src/generators/bot-app/generator.d.ts +4 -0
  96. package/src/generators/bot-app/generator.js +294 -0
  97. package/src/generators/bot-app/schema.d.ts +6 -0
  98. package/src/generators/bot-app/schema.js +16 -0
  99. package/src/generators/bot-app/schema.json +36 -0
  100. package/src/generators/bot-app-migrations/migrate-fix-css-code-split/generator.d.ts +5 -0
  101. package/src/generators/bot-app-migrations/migrate-fix-css-code-split/generator.js +92 -0
  102. package/src/generators/bot-app-migrations/migrate-fix-css-code-split/schema.json +15 -0
  103. package/src/generators/bot-app-migrations/migrate-pnpm-compat/generator.d.ts +5 -0
  104. package/src/generators/bot-app-migrations/migrate-pnpm-compat/generator.js +97 -0
  105. package/src/generators/bot-app-migrations/migrate-pnpm-compat/schema.json +15 -0
  106. package/src/generators/bot-app-migrations/migrate-webchat-trigger/generator.d.ts +5 -0
  107. package/src/generators/bot-app-migrations/migrate-webchat-trigger/generator.js +165 -0
  108. package/src/generators/bot-app-migrations/migrate-webchat-trigger/schema.json +15 -0
  109. package/src/generators/custom-message/files/__name__-output.ts.template +21 -0
  110. package/src/generators/custom-message/files/__name__.spec.tsx.template +27 -0
  111. package/src/generators/custom-message/files/__name__.tsx.template +18 -0
  112. package/src/generators/custom-message/generator.d.ts +4 -0
  113. package/src/generators/custom-message/generator.js +235 -0
  114. package/src/generators/custom-message/schema.d.ts +7 -0
  115. package/src/generators/custom-message/schema.js +16 -0
  116. package/src/generators/custom-message/schema.json +44 -0
  117. package/src/generators/preset/files/.cursor/commands/update-bot.md +5 -0
  118. package/src/generators/preset/files/.cursor/commands/update-botonic.md +5 -0
  119. package/src/generators/preset/files/.cursor/scripts/update-bot/discover-bots.sh +67 -0
  120. package/src/generators/preset/files/.cursor/scripts/update-bot/find-migration-guides.sh +70 -0
  121. package/src/generators/preset/files/.cursor/skills/botonic-action/SKILL.md +167 -0
  122. package/src/generators/preset/files/.cursor/skills/botonic-custom-message/SKILL.md +231 -0
  123. package/src/generators/preset/files/.cursor/skills/botonic-webview/SKILL.md +179 -0
  124. package/src/generators/preset/files/.env.prod.template +2 -0
  125. package/src/generators/preset/files/.env.template +2 -0
  126. package/src/generators/preset/files/.npmrc.template +1 -0
  127. package/src/generators/preset/files/README.md.template +174 -0
  128. package/src/generators/preset/files/nx.json +66 -0
  129. package/src/generators/preset/files/package.json +26 -0
  130. package/src/generators/preset/files/tsconfig.base.json +27 -0
  131. package/src/generators/preset/files/tsconfig.base.json.template +27 -0
  132. package/src/generators/preset/files/tsconfig.json +9 -0
  133. package/src/generators/preset/generator.d.ts +4 -0
  134. package/src/generators/preset/generator.js +127 -0
  135. package/src/generators/preset/schema.d.ts +6 -0
  136. package/src/generators/preset/schema.js +16 -0
  137. package/src/generators/preset/schema.json +50 -0
  138. package/src/generators/remove-custom-message/generator.d.ts +4 -0
  139. package/src/generators/remove-custom-message/generator.js +259 -0
  140. package/src/generators/remove-custom-message/schema.d.ts +6 -0
  141. package/src/generators/remove-custom-message/schema.js +16 -0
  142. package/src/generators/remove-custom-message/schema.json +39 -0
  143. package/src/generators/shared/bot-app-utils.d.ts +25 -0
  144. package/src/generators/shared/bot-app-utils.js +209 -0
  145. package/src/generators/webview/files/__name__.spec.tsx.template +20 -0
  146. package/src/generators/webview/files/__name__.tsx.template +19 -0
  147. package/src/generators/webview/generator.d.ts +4 -0
  148. package/src/generators/webview/generator.js +179 -0
  149. package/src/generators/webview/schema.d.ts +5 -0
  150. package/src/generators/webview/schema.js +16 -0
  151. package/src/generators/webview/schema.json +34 -0
  152. package/src/index.d.ts +7 -0
  153. package/src/index.js +56 -0
  154. package/src/lib/api-service.d.ts +110 -0
  155. package/src/lib/api-service.js +591 -0
  156. package/src/lib/bot-config.d.ts +30 -0
  157. package/src/lib/bot-config.js +203 -0
  158. package/src/lib/cloudflared-tunnel.d.ts +29 -0
  159. package/src/lib/cloudflared-tunnel.js +95 -0
  160. package/src/lib/constants.d.ts +13 -0
  161. package/src/lib/constants.js +60 -0
  162. package/src/lib/credentials-handler.d.ts +40 -0
  163. package/src/lib/credentials-handler.js +115 -0
  164. package/src/lib/index.d.ts +10 -0
  165. package/src/lib/index.js +47 -0
  166. package/src/lib/interfaces.d.ts +49 -0
  167. package/src/lib/interfaces.js +16 -0
  168. package/src/lib/util/executor-helpers.d.ts +97 -0
  169. package/src/lib/util/executor-helpers.js +574 -0
  170. package/src/lib/util/file-system.d.ts +8 -0
  171. package/src/lib/util/file-system.js +65 -0
  172. package/src/lib/util/sam-container-cleanup.d.ts +11 -0
  173. package/src/lib/util/sam-container-cleanup.js +55 -0
  174. package/src/lib/util/sam-template.d.ts +9 -0
  175. package/src/lib/util/sam-template.js +71 -0
  176. package/src/lib/util/system.d.ts +1 -0
  177. package/src/lib/util/system.js +30 -0
  178. package/src/migrations/add-botonic-update-bots-skill/add-botonic-update-bots-skill.migration.d.ts +2 -0
  179. package/src/migrations/add-botonic-update-bots-skill/add-botonic-update-bots-skill.migration.js +52 -0
  180. package/src/migrations/add-botonic-update-bots-skill/add-botonic-update-bots-skill.migration.md +23 -0
  181. package/src/migrations/add-botonic-update-bots-skill/files/.cursor/commands/update-bot.md +5 -0
  182. package/src/migrations/add-botonic-update-bots-skill/files/.cursor/commands/update-botonic.md +5 -0
  183. package/src/migrations/add-botonic-update-bots-skill/files/.cursor/scripts/update-bot/discover-bots.sh +67 -0
  184. package/src/migrations/add-botonic-update-bots-skill/files/.cursor/scripts/update-bot/find-migration-guides.sh +70 -0
  185. package/src/migrations/add-botonic-update-bots-skill/schema.json +5 -0
  186. package/src/migrations/add-lilara-registry/add-lilara-registry.migration.d.ts +2 -0
  187. package/src/migrations/add-lilara-registry/add-lilara-registry.migration.js +49 -0
  188. package/src/migrations/add-lilara-registry/schema.json +5 -0
  189. package/src/migrations/fix-css-code-split/fix-css-code-split.migration.md +45 -0
  190. package/src/migrations/remove-codeartifact-registry/remove-codeartifact-registry.migration.d.ts +2 -0
  191. package/src/migrations/remove-codeartifact-registry/remove-codeartifact-registry.migration.js +59 -0
  192. package/src/migrations/remove-codeartifact-registry/schema.json +5 -0
  193. package/src/migrations/sync-pending-bot-migrations/schema.json +5 -0
  194. package/src/migrations/sync-pending-bot-migrations/sync-pending-bot-migrations.migration.d.ts +2 -0
  195. package/src/migrations/sync-pending-bot-migrations/sync-pending-bot-migrations.migration.js +137 -0
  196. package/src/migrations/sync-pending-bot-migrations/sync-pending-bot-migrations.migration.md +19 -0
  197. package/src/migrations/update-cursor-commands-to-stubs/schema.json +5 -0
  198. package/src/migrations/update-cursor-commands-to-stubs/update-cursor-commands-to-stubs.migration.d.ts +2 -0
  199. package/src/migrations/update-cursor-commands-to-stubs/update-cursor-commands-to-stubs.migration.js +61 -0
  200. package/src/migrations/update-pnpm-workspace-scripts/schema.json +4 -0
  201. package/src/migrations/update-pnpm-workspace-scripts/update-pnpm-workspace-scripts.migration.d.ts +2 -0
  202. package/src/migrations/update-pnpm-workspace-scripts/update-pnpm-workspace-scripts.migration.js +47 -0
  203. package/src/migrations/utils/migration-utils.d.ts +109 -0
  204. package/src/migrations/utils/migration-utils.js +448 -0
  205. package/src/plugin.d.ts +15 -0
  206. package/src/plugin.js +246 -0
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var bot_app_utils_exports = {};
20
+ __export(bot_app_utils_exports, {
21
+ addActionImportToRoutes: () => addActionImportToRoutes,
22
+ addConstEntry: () => addConstEntry,
23
+ addExportToIndex: () => addExportToIndex,
24
+ insertRouteBeforeFlowBuilder: () => insertRouteBeforeFlowBuilder,
25
+ resolveStandardPaths: () => resolveStandardPaths,
26
+ validateBotAppProject: () => validateBotAppProject
27
+ });
28
+ module.exports = __toCommonJS(bot_app_utils_exports);
29
+ var import_devkit = require("@nx/devkit");
30
+ function validateBotAppProject(tree, projectName) {
31
+ const projects = (0, import_devkit.getProjects)(tree);
32
+ const project = projects.get(projectName);
33
+ if (!project) {
34
+ throw new Error(`Project "${projectName}" not found`);
35
+ }
36
+ if (!project.tags?.includes("botonic:bot-app")) {
37
+ throw new Error(
38
+ `Project "${projectName}" is not a botonic bot application. Make sure it has the "botonic:bot-app" tag.`
39
+ );
40
+ }
41
+ const projectConfig = (0, import_devkit.readProjectConfiguration)(tree, projectName);
42
+ const projectRoot = projectConfig.root;
43
+ const sourceRoot = projectConfig.sourceRoot || `${projectRoot}/src`;
44
+ return { projectRoot, sourceRoot };
45
+ }
46
+ function resolveStandardPaths(sourceRoot) {
47
+ return {
48
+ constantsPath: `${sourceRoot}/shared/constants.ts`,
49
+ actionsPath: `${sourceRoot}/server/bot/actions`,
50
+ routesPath: `${sourceRoot}/server/bot/routes.ts`,
51
+ customMessagesPath: `${sourceRoot}/client/custom-messages`,
52
+ webviewsPath: `${sourceRoot}/client/webviews`
53
+ };
54
+ }
55
+ function addExportToIndex(tree, indexPath, exportStatement) {
56
+ if (!tree.exists(indexPath)) {
57
+ tree.write(indexPath, `${exportStatement}
58
+ `);
59
+ return;
60
+ }
61
+ const content = tree.read(indexPath, "utf-8");
62
+ if (!content.includes(exportStatement)) {
63
+ tree.write(indexPath, content.trimEnd() + "\n" + exportStatement + "\n");
64
+ }
65
+ }
66
+ function addConstEntry(tree, filePath, constName, key, value) {
67
+ if (!tree.exists(filePath)) {
68
+ return;
69
+ }
70
+ const content = tree.read(filePath, "utf-8");
71
+ if (content.includes(`${key}:`) || content.includes(`${key} =`)) {
72
+ return;
73
+ }
74
+ const lines = content.split("\n");
75
+ const constStartIndex = lines.findIndex(
76
+ (line) => line.includes(`export const ${constName}`)
77
+ );
78
+ if (constStartIndex === -1) {
79
+ return;
80
+ }
81
+ let closingBraceIndex = constStartIndex;
82
+ let braceCount = 0;
83
+ for (let i = constStartIndex; i < lines.length; i++) {
84
+ for (const char of lines[i]) {
85
+ if (char === "{") braceCount++;
86
+ if (char === "}") braceCount--;
87
+ }
88
+ if (braceCount === 0 && i > constStartIndex) {
89
+ closingBraceIndex = i;
90
+ break;
91
+ }
92
+ if (i === constStartIndex && braceCount === 0) {
93
+ closingBraceIndex = i;
94
+ break;
95
+ }
96
+ }
97
+ const newEntry = ` ${key}: '${value}',`;
98
+ if (closingBraceIndex === constStartIndex) {
99
+ lines[closingBraceIndex] = lines[closingBraceIndex].replace(
100
+ "{}",
101
+ `{
102
+ ${newEntry}
103
+ }`
104
+ );
105
+ } else {
106
+ lines.splice(closingBraceIndex, 0, newEntry);
107
+ }
108
+ tree.write(filePath, lines.join("\n"));
109
+ }
110
+ function insertRouteBeforeFlowBuilder(tree, routesPath, routeLines) {
111
+ if (!tree.exists(routesPath)) {
112
+ console.warn(
113
+ `Routes file not found at ${routesPath}. Skipping route addition.`
114
+ );
115
+ return;
116
+ }
117
+ const content = tree.read(routesPath, "utf-8");
118
+ const lines = content.split("\n");
119
+ let insertIndex = -1;
120
+ for (let i = 0; i < lines.length; i++) {
121
+ if (lines[i].includes("path: 'flow-builder'") || lines[i].includes("path:") && lines[i].includes("flow-builder")) {
122
+ for (let j = i - 1; j >= 0; j--) {
123
+ if (lines[j].trim() === "{") {
124
+ insertIndex = j;
125
+ break;
126
+ }
127
+ }
128
+ break;
129
+ }
130
+ }
131
+ if (insertIndex === -1) {
132
+ console.warn("Could not find flow-builder route. Skipping route addition.");
133
+ return;
134
+ }
135
+ const routeAlreadyExists = routeLines.some(
136
+ (rl) => lines.some((l) => l.includes(rl.trim()) && rl.trim().length > 2)
137
+ );
138
+ if (routeAlreadyExists) {
139
+ return;
140
+ }
141
+ for (let i = routeLines.length - 1; i >= 0; i--) {
142
+ lines.splice(insertIndex, 0, routeLines[i]);
143
+ }
144
+ tree.write(routesPath, lines.join("\n"));
145
+ }
146
+ function addActionImportToRoutes(tree, routesPath, actionName) {
147
+ if (!tree.exists(routesPath)) {
148
+ return;
149
+ }
150
+ const content = tree.read(routesPath, "utf-8");
151
+ if (content.includes(actionName)) {
152
+ return;
153
+ }
154
+ const lines = content.split("\n");
155
+ let importStartIndex = -1;
156
+ let importEndIndex = -1;
157
+ for (let i = 0; i < lines.length; i++) {
158
+ if (lines[i].includes("import") && lines[i].includes("'./actions'")) {
159
+ importStartIndex = i;
160
+ importEndIndex = i;
161
+ break;
162
+ }
163
+ if (lines[i].includes("import {") && lines.slice(i, i + 15).some((l) => l.includes("from './actions'"))) {
164
+ importStartIndex = i;
165
+ for (let j = i; j < lines.length; j++) {
166
+ if (lines[j].includes("from './actions'")) {
167
+ importEndIndex = j;
168
+ break;
169
+ }
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ if (importStartIndex === -1) {
175
+ let lastImportIndex = -1;
176
+ for (let i = 0; i < lines.length; i++) {
177
+ if (lines[i].startsWith("import ")) lastImportIndex = i;
178
+ }
179
+ const insertAt = lastImportIndex + 1;
180
+ lines.splice(insertAt, 0, `import { ${actionName} } from './actions'`);
181
+ tree.write(routesPath, lines.join("\n"));
182
+ return;
183
+ }
184
+ if (importStartIndex === importEndIndex) {
185
+ const importMatch = lines[importStartIndex].match(
186
+ /import\s*\{([^}]*)\}\s*from/
187
+ );
188
+ if (importMatch) {
189
+ const existing = importMatch[1].trim();
190
+ const newImports = existing ? `${existing}, ${actionName}` : actionName;
191
+ lines[importStartIndex] = lines[importStartIndex].replace(
192
+ importMatch[1],
193
+ ` ${newImports} `
194
+ );
195
+ }
196
+ } else {
197
+ lines.splice(importEndIndex, 0, ` ${actionName},`);
198
+ }
199
+ tree.write(routesPath, lines.join("\n"));
200
+ }
201
+ // Annotate the CommonJS export names for ESM import in node:
202
+ 0 && (module.exports = {
203
+ addActionImportToRoutes,
204
+ addConstEntry,
205
+ addExportToIndex,
206
+ insertRouteBeforeFlowBuilder,
207
+ resolveStandardPaths,
208
+ validateBotAppProject
209
+ });
@@ -0,0 +1,20 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+
4
+ vi.mock('@botonic/webviews', () => ({
5
+ useWebviewRequest: () => ({ closeWebview: vi.fn() }),
6
+ WebviewFrame: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
7
+ WebviewHeader: ({ title }: { title: string }) => <div>{title}</div>,
8
+ WebviewBody: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
9
+ }))
10
+
11
+ import React from 'react'
12
+
13
+ import { <%= className %> } from './<%= fileName %>'
14
+
15
+ describe('<%= className %>', () => {
16
+ it('should render successfully', () => {
17
+ render(<<%= className %> />)
18
+ expect(screen.getByText('<%= className %>')).toBeInTheDocument()
19
+ })
20
+ })
@@ -0,0 +1,19 @@
1
+ import {
2
+ useWebviewRequest,
3
+ WebviewBody,
4
+ WebviewFrame,
5
+ WebviewHeader,
6
+ } from '@botonic/webviews'
7
+
8
+ export const <%= className %> = () => {
9
+ const { closeWebview } = useWebviewRequest()
10
+
11
+ return (
12
+ <WebviewFrame>
13
+ <WebviewHeader title='<%= className %>' />
14
+ <WebviewBody variant='padded'>
15
+ <p>TODO: Implement <%= className %> webview</p>
16
+ </WebviewBody>
17
+ </WebviewFrame>
18
+ )
19
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { WebviewGeneratorSchema } from './schema';
3
+ export default function (tree: Tree, options: WebviewGeneratorSchema): Promise<void>;
4
+ export { WebviewGeneratorSchema };
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var generator_exports = {};
20
+ __export(generator_exports, {
21
+ default: () => generator_default
22
+ });
23
+ module.exports = __toCommonJS(generator_exports);
24
+ var import_devkit = require("@nx/devkit");
25
+ var import_bot_app_utils = require("../shared/bot-app-utils");
26
+ const MODULE_DIR = __dirname;
27
+ function normalizeOptions(tree, options) {
28
+ const { projectRoot, sourceRoot } = (0, import_bot_app_utils.validateBotAppProject)(
29
+ tree,
30
+ options.project
31
+ );
32
+ const paths = (0, import_bot_app_utils.resolveStandardPaths)(sourceRoot);
33
+ const name = (0, import_devkit.names)(options.name);
34
+ const fileName = name.fileName;
35
+ const className = name.className;
36
+ const constantName = name.constantName.toUpperCase();
37
+ return {
38
+ ...options,
39
+ projectName: options.project,
40
+ projectRoot,
41
+ fileName,
42
+ className,
43
+ constantName,
44
+ webviewsPath: paths.webviewsPath,
45
+ constantsPath: paths.constantsPath
46
+ };
47
+ }
48
+ function addFilesToProject(tree, options) {
49
+ const name = (0, import_devkit.names)(options.name);
50
+ const templateOptions = {
51
+ ...options,
52
+ ...name,
53
+ name: name.fileName
54
+ // __name__ in filenames must be kebab-case
55
+ };
56
+ (0, import_devkit.generateFiles)(
57
+ tree,
58
+ (0, import_devkit.joinPathFragments)(MODULE_DIR, "files"),
59
+ options.webviewsPath,
60
+ templateOptions
61
+ );
62
+ if (options.skipTests) {
63
+ const testFilePath = `${options.webviewsPath}/${options.fileName}.spec.tsx`;
64
+ if (tree.exists(testFilePath)) {
65
+ tree.delete(testFilePath);
66
+ }
67
+ }
68
+ }
69
+ function updateConstantsFile(tree, options) {
70
+ if (!tree.exists(options.constantsPath)) {
71
+ tree.write(
72
+ options.constantsPath,
73
+ `export const CUSTOM_MESSAGE_TYPES = {
74
+ // Add your custom message types here
75
+ } as const
76
+
77
+ export const WEBVIEWS = {
78
+ ${options.constantName}: '${options.fileName}',
79
+ } as const
80
+
81
+ export const PAYLOADS = {
82
+ // Add your payloads here
83
+ } as const
84
+ `
85
+ );
86
+ return;
87
+ }
88
+ (0, import_bot_app_utils.addConstEntry)(
89
+ tree,
90
+ options.constantsPath,
91
+ "WEBVIEWS",
92
+ options.constantName,
93
+ options.fileName
94
+ );
95
+ }
96
+ function updateWebviewsIndex(tree, options) {
97
+ const indexPath = `${options.webviewsPath}/index.tsx`;
98
+ if (!tree.exists(indexPath)) {
99
+ console.warn(
100
+ `Webviews index not found at ${indexPath}. Skipping registration.`
101
+ );
102
+ return;
103
+ }
104
+ const content = tree.read(indexPath, "utf-8");
105
+ const lines = content.split("\n");
106
+ const componentImport = `import { ${options.className} } from './${options.fileName}'`;
107
+ if (!content.includes(componentImport)) {
108
+ let lastImportIndex = -1;
109
+ for (let i = 0; i < lines.length; i++) {
110
+ if (lines[i].startsWith("import ")) lastImportIndex = i;
111
+ }
112
+ lines.splice(lastImportIndex + 1, 0, componentImport);
113
+ }
114
+ if (!content.includes("WEBVIEWS")) {
115
+ const sharedImport = `import { WEBVIEWS } from '../../shared/constants'`;
116
+ let lastImportIndex = -1;
117
+ for (let i = 0; i < lines.length; i++) {
118
+ if (lines[i].startsWith("import ")) lastImportIndex = i;
119
+ }
120
+ lines.splice(lastImportIndex, 0, sharedImport);
121
+ }
122
+ const newEntry = [
123
+ ` {`,
124
+ ` path: WEBVIEWS.${options.constantName},`,
125
+ ` component: ${options.className},`,
126
+ ` allowClose: true,`,
127
+ ` },`
128
+ ];
129
+ const alreadyRegistered = lines.some(
130
+ (l) => l.includes(`WEBVIEWS.${options.constantName}`)
131
+ );
132
+ if (!alreadyRegistered) {
133
+ let arrayCloseIndex = -1;
134
+ let inArray = false;
135
+ let depth = 0;
136
+ for (let i = 0; i < lines.length; i++) {
137
+ if (lines[i].includes("WebviewDefinition[]") || lines[i].includes("const webviews")) {
138
+ inArray = true;
139
+ }
140
+ if (inArray) {
141
+ for (const char of lines[i]) {
142
+ if (char === "[") depth++;
143
+ if (char === "]") depth--;
144
+ }
145
+ if (depth === 0 && inArray && lines[i].includes("]")) {
146
+ arrayCloseIndex = i;
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ if (arrayCloseIndex !== -1) {
152
+ for (let i = newEntry.length - 1; i >= 0; i--) {
153
+ lines.splice(arrayCloseIndex, 0, newEntry[i]);
154
+ }
155
+ }
156
+ }
157
+ tree.write(indexPath, lines.join("\n"));
158
+ }
159
+ async function generator_default(tree, options) {
160
+ console.log(`Creating webview: ${options.name}`);
161
+ const normalizedOptions = normalizeOptions(tree, options);
162
+ console.log(`Project: ${normalizedOptions.projectName}`);
163
+ console.log(`Location: ${normalizedOptions.webviewsPath}`);
164
+ addFilesToProject(tree, normalizedOptions);
165
+ updateConstantsFile(tree, normalizedOptions);
166
+ updateWebviewsIndex(tree, normalizedOptions);
167
+ await (0, import_devkit.formatFiles)(tree);
168
+ console.log(`
169
+ Successfully created webview: ${normalizedOptions.className}`);
170
+ console.log(`Next steps:`);
171
+ console.log(
172
+ ` 1. Implement the UI in: ${normalizedOptions.webviewsPath}/${normalizedOptions.fileName}.tsx`
173
+ );
174
+ if (!options.skipTests) {
175
+ console.log(
176
+ ` 2. Update the tests in: ${normalizedOptions.webviewsPath}/${normalizedOptions.fileName}.spec.tsx`
177
+ );
178
+ }
179
+ }
@@ -0,0 +1,5 @@
1
+ export interface WebviewGeneratorSchema {
2
+ name: string;
3
+ project: string;
4
+ skipTests?: boolean;
5
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var schema_exports = {};
16
+ module.exports = __toCommonJS(schema_exports);
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "Webview",
5
+ "title": "Create a webview component for Botonic",
6
+ "description": "Generate a client-side webview component with automatic registration in the webviews app.",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "type": "string",
11
+ "description": "The name of the webview component.",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "What name would you like to use for the webview?",
17
+ "pattern": "^[a-zA-Z].*$"
18
+ },
19
+ "project": {
20
+ "type": "string",
21
+ "description": "The name of the botonic project to add the webview to.",
22
+ "x-prompt": "Which botonic project should this webview be added to?",
23
+ "$default": {
24
+ "$source": "projectName"
25
+ }
26
+ },
27
+ "skipTests": {
28
+ "type": "boolean",
29
+ "description": "Skip generating test files.",
30
+ "default": false
31
+ }
32
+ },
33
+ "required": ["name", "project"]
34
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './generators/bot-app/generator';
2
+ export * from './generators/preset/generator';
3
+ export { default as buildNodeAppExecutor } from './executors/build-node-app/executor';
4
+ export { default as runLambdaExecutor } from './executors/run-lambda/executor';
5
+ export { default as serveBotExecutor } from './executors/serve-bot/executor';
6
+ export * from './lib';
7
+ export { BotonicPlugin, createNodesV2 } from './plugin';
package/src/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ BotonicPlugin: () => import_plugin.BotonicPlugin,
33
+ buildNodeAppExecutor: () => import_executor.default,
34
+ createNodesV2: () => import_plugin.createNodesV2,
35
+ runLambdaExecutor: () => import_executor2.default,
36
+ serveBotExecutor: () => import_executor3.default
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+ __reExport(src_exports, require("./generators/bot-app/generator"), module.exports);
40
+ __reExport(src_exports, require("./generators/preset/generator"), module.exports);
41
+ var import_executor = __toESM(require("./executors/build-node-app/executor"));
42
+ var import_executor2 = __toESM(require("./executors/run-lambda/executor"));
43
+ var import_executor3 = __toESM(require("./executors/serve-bot/executor"));
44
+ __reExport(src_exports, require("./lib"), module.exports);
45
+ var import_plugin = require("./plugin");
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ BotonicPlugin,
49
+ buildNodeAppExecutor,
50
+ createNodesV2,
51
+ runLambdaExecutor,
52
+ serveBotExecutor,
53
+ ...require("./generators/bot-app/generator"),
54
+ ...require("./generators/preset/generator"),
55
+ ...require("./lib")
56
+ });
@@ -0,0 +1,110 @@
1
+ import { AxiosHeaders, AxiosInstance, AxiosResponse } from 'axios';
2
+ import { BotConfigJSON } from './bot-config';
3
+ import { BotCredentialsHandler, GlobalCredentialsHandler } from './credentials-handler';
4
+ import type { BotDetail, Me, OAuth } from './interfaces';
5
+ interface IntegrationResponse {
6
+ detail: string;
7
+ provider_account: {
8
+ id: string;
9
+ bot_id: string;
10
+ provider: string;
11
+ name: string;
12
+ username: string;
13
+ phone_number: string | null;
14
+ credentials: string | null;
15
+ credentials_json: any;
16
+ netlify_url: string;
17
+ is_playground: boolean;
18
+ is_whatsapp_cloud: boolean;
19
+ created_by_id: string;
20
+ chat_count: number;
21
+ is_active: boolean;
22
+ is_test: boolean;
23
+ imp_id: string;
24
+ is_preview: boolean;
25
+ };
26
+ netlify_url: string | null;
27
+ }
28
+ interface BotonicAPIServiceConfig {
29
+ isLocalRuntimeDeployment?: boolean;
30
+ projectRoot?: string;
31
+ /** Monorepo/workspace root. When set, global credentials are stored at workspaceRoot/.botonic/credentials.json (source of truth). */
32
+ workspaceRoot?: string;
33
+ environmentVariables?: Record<string, string>;
34
+ targetEnvironment?: string;
35
+ }
36
+ export declare class BotonicAPIService {
37
+ clientId: string;
38
+ baseUrl: string;
39
+ loginUrl: string;
40
+ botCredentialsHandler: InstanceType<typeof BotCredentialsHandler>;
41
+ globalCredentialsHandler: InstanceType<typeof GlobalCredentialsHandler>;
42
+ oauth?: OAuth;
43
+ me?: Me;
44
+ /** Cached from credentials for display when me is not loaded yet. */
45
+ loggedUserName?: string;
46
+ loggedEnvironmentUrl?: string;
47
+ bot: BotDetail | null;
48
+ localRuntimeBot: BotDetail | null;
49
+ headers: AxiosHeaders;
50
+ apiClient: AxiosInstance;
51
+ isLocalRuntimeDeployment?: boolean;
52
+ projectRoot?: string;
53
+ targetEnvironment?: string;
54
+ constructor(config?: BotonicAPIServiceConfig);
55
+ saveAllCredentials(): void;
56
+ botInfo(): BotDetail;
57
+ getOauth(): OAuth;
58
+ isAuthenticated(): boolean;
59
+ /** True when in local runtime mode and a bot was loaded (e.g. from app .botonic.json). */
60
+ hasLocalRuntimeBot(): boolean;
61
+ ensureAuthenticated(): Promise<void>;
62
+ setCurrentBot(bot: any): void;
63
+ setLocalRuntimeBot(bot: any): void;
64
+ private loadGlobalCredentials;
65
+ /**
66
+ * Returns store as env -> credentials. Migrates old single-credential format to { local: creds }.
67
+ */
68
+ private normalizeCredentialsStore;
69
+ private loadBotCredentials;
70
+ private setHeaders;
71
+ private saveGlobalCredentials;
72
+ private saveBotCredentials;
73
+ private refreshToken;
74
+ login(email: string, password: string): Promise<void>;
75
+ logout(): Promise<void>;
76
+ /**
77
+ * Ensures me is loaded (for display). Call before showing "Working as ...".
78
+ */
79
+ ensureMeLoaded(): Promise<void>;
80
+ /**
81
+ * Display name for the logged-in user (for "Working as X in environment ...").
82
+ */
83
+ getDisplayName(): string;
84
+ createWebchatIntegration(botId: string, integrationName: string): Promise<AxiosResponse<IntegrationResponse>>;
85
+ signup(email: string, password: string, orgName: string, campaign: any): Promise<any>;
86
+ createBot(botName: string): Promise<AxiosResponse>;
87
+ getBots(): Promise<AxiosResponse>;
88
+ deleteBot(botId: string): Promise<AxiosResponse>;
89
+ getProviders(botId?: string): Promise<AxiosResponse>;
90
+ deployBot(bundlePath: string, botConfigJson: any): Promise<any>;
91
+ deployStatus(deployId: string): Promise<AxiosResponse>;
92
+ deployLocalRuntime({ botConfigJson, lambdaFunctionName, lambdaEndpoint, }: {
93
+ botConfigJson: BotConfigJSON;
94
+ lambdaFunctionName: string;
95
+ lambdaEndpoint: string;
96
+ }): Promise<AxiosResponse<unknown, any, {}>>;
97
+ build({ projectRoot, projectName, }: {
98
+ projectRoot: string;
99
+ projectName: string;
100
+ }): Promise<boolean>;
101
+ private prepareLambda;
102
+ private apiPost;
103
+ private apiGet;
104
+ private apiDelete;
105
+ private getMe;
106
+ private validateToken;
107
+ private isTokenExpired;
108
+ private getHeaders;
109
+ }
110
+ export {};