@botpress/cli 4.3.6 → 4.5.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 (41) hide show
  1. package/.turbo/turbo-build.log +11 -11
  2. package/dist/api/bot-body.js +8 -1
  3. package/dist/api/bot-body.js.map +2 -2
  4. package/dist/api/client.js +50 -33
  5. package/dist/api/client.js.map +3 -3
  6. package/dist/api/integration-body.js +8 -11
  7. package/dist/api/integration-body.js.map +2 -2
  8. package/dist/api/interface-body.js +8 -14
  9. package/dist/api/interface-body.js.map +2 -2
  10. package/dist/api/plugin-body.js +8 -2
  11. package/dist/api/plugin-body.js.map +2 -2
  12. package/dist/api/types.js.map +1 -1
  13. package/dist/code-generation/integration-package/integration-package-definition/events-module.js +5 -6
  14. package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +2 -2
  15. package/dist/code-generation/interface-package/interface-package-definition/events-module.js +5 -6
  16. package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +2 -2
  17. package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js +7 -4
  18. package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js.map +2 -2
  19. package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js +5 -6
  20. package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js.map +2 -2
  21. package/dist/code-generation/typings.js.map +1 -1
  22. package/dist/command-implementations/add-command.js +4 -4
  23. package/dist/command-implementations/add-command.js.map +2 -2
  24. package/dist/command-implementations/deploy-command.js +3 -3
  25. package/dist/command-implementations/deploy-command.js.map +2 -2
  26. package/dist/command-implementations/integration-commands.js +1 -1
  27. package/dist/command-implementations/integration-commands.js.map +2 -2
  28. package/dist/command-implementations/project-command.js +2 -2
  29. package/dist/command-implementations/project-command.js.map +2 -2
  30. package/dist/package-ref.js +0 -3
  31. package/dist/package-ref.js.map +2 -2
  32. package/dist/utils/attribute-utils.js +52 -0
  33. package/dist/utils/attribute-utils.js.map +7 -0
  34. package/dist/utils/index.js +3 -0
  35. package/dist/utils/index.js.map +2 -2
  36. package/package.json +3 -3
  37. package/templates/empty-bot/package.json +2 -2
  38. package/templates/empty-integration/package.json +2 -2
  39. package/templates/empty-plugin/package.json +1 -1
  40. package/templates/hello-world/package.json +2 -2
  41. package/templates/webhook-message/package.json +2 -2
@@ -1,32 +1,32 @@
1
1
 
2
- > @botpress/cli@4.3.6 build /home/runner/work/botpress/botpress/packages/cli
2
+ > @botpress/cli@4.5.0 build /home/runner/work/botpress/botpress/packages/cli
3
3
  > pnpm run bundle && pnpm run template:gen
4
4
 
5
5
 
6
- > @botpress/cli@4.3.6 bundle /home/runner/work/botpress/botpress/packages/cli
6
+ > @botpress/cli@4.5.0 bundle /home/runner/work/botpress/botpress/packages/cli
7
7
  > ts-node -T build.ts
8
8
 
9
9
 
10
- > @botpress/cli@4.3.6 template:gen /home/runner/work/botpress/botpress/packages/cli
10
+ > @botpress/cli@4.5.0 template:gen /home/runner/work/botpress/botpress/packages/cli
11
11
  > pnpm -r --stream -F @bp-templates/* exec bp gen
12
12
 
13
- 🤖 Botpress CLI v4.3.6
14
- 🤖 Botpress CLI v4.3.6
15
- 🤖 Botpress CLI v4.3.6
16
- 🤖 Botpress CLI v4.3.6
17
- ○ Generating typings for plugin empty-plugin...
18
- ✓ Typings available at .botpress
19
-
13
+ 🤖 Botpress CLI v4.5.0
14
+ 🤖 Botpress CLI v4.5.0
15
+ 🤖 Botpress CLI v4.5.0
16
+ 🤖 Botpress CLI v4.5.0
20
17
  ○ Generating typings for integration empty-integration...
21
18
  ✓ Typings available at .botpress
22
19
 
23
20
  ○ Generating typings for bot...
24
21
  ✓ Typings available at .botpress
25
22
 
23
+ ○ Generating typings for plugin empty-plugin...
24
+ ✓ Typings available at .botpress
25
+
26
26
  ○ Generating typings for integration hello-world...
27
27
  ✓ Typings available at .botpress
28
28
 
29
- 🤖 Botpress CLI v4.3.6
29
+ 🤖 Botpress CLI v4.5.0
30
30
  ○ Generating typings for integration webhook-message...
31
31
  ✓ Typings available at .botpress
32
32
 
@@ -66,7 +66,14 @@ const prepareUpdateBotBody = (localBot, remoteBot) => ({
66
66
  ...localBot,
67
67
  states: utils.records.setNullOnMissingValues(localBot.states, remoteBot.states),
68
68
  recurringEvents: utils.records.setNullOnMissingValues(localBot.recurringEvents, remoteBot.recurringEvents),
69
- events: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),
69
+ events: utils.attributes.prepareAttributeUpdateBody({
70
+ localItems: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),
71
+ remoteItems: remoteBot.events
72
+ }),
73
+ actions: utils.attributes.prepareAttributeUpdateBody({
74
+ localItems: utils.records.setNullOnMissingValues(localBot.actions, remoteBot.actions),
75
+ remoteItems: remoteBot.actions
76
+ }),
70
77
  user: {
71
78
  ...localBot.user,
72
79
  tags: utils.records.setNullOnMissingValues(localBot.user?.tags, remoteBot.user?.tags)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/bot-body.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateBotBody = async (bot: sdk.BotDefinition): Promise<types.CreateBotRequestBody> => ({\n user: bot.user,\n conversation: bot.conversation,\n message: bot.message,\n recurringEvents: bot.recurringEvents,\n actions: bot.actions\n ? await utils.records.mapValuesAsync(bot.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n configuration: bot.configuration\n ? {\n ...bot.configuration,\n schema: await utils.schema.mapZodToJsonSchema(bot.configuration),\n }\n : undefined,\n events: bot.events\n ? await utils.records.mapValuesAsync(bot.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n states: bot.states\n ? await utils.records.mapValuesAsync(bot.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdateBotBody = (\n localBot: types.UpdateBotRequestBody,\n remoteBot: client.Bot\n): types.UpdateBotRequestBody => ({\n ...localBot,\n states: utils.records.setNullOnMissingValues(localBot.states, remoteBot.states),\n recurringEvents: utils.records.setNullOnMissingValues(localBot.recurringEvents, remoteBot.recurringEvents),\n events: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),\n user: {\n ...localBot.user,\n tags: utils.records.setNullOnMissingValues(localBot.user?.tags, remoteBot.user?.tags),\n },\n conversation: {\n ...localBot.conversation,\n tags: utils.records.setNullOnMissingValues(localBot.conversation?.tags, remoteBot.conversation?.tags),\n },\n message: {\n ...localBot.message,\n tags: utils.records.setNullOnMissingValues(localBot.message?.tags, remoteBot.message?.tags),\n },\n integrations: utils.records.setNullOnMissingValues(localBot.integrations, remoteBot.integrations),\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAGhB,MAAM,uBAAuB,OAAO,SAAiE;AAAA,EAC1G,MAAM,IAAI;AAAA,EACV,cAAc,IAAI;AAAA,EAClB,SAAS,IAAI;AAAA,EACb,iBAAiB,IAAI;AAAA,EACrB,SAAS,IAAI,UACT,MAAM,MAAM,QAAQ,eAAe,IAAI,SAAS,OAAO,YAAY;AAAA,IACjE,GAAG;AAAA,IACH,OAAO;AAAA,MACL,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,KAAK;AAAA,IAC5D;AAAA,IACA,QAAQ;AAAA,MACN,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,MAAM;AAAA,IAC7D;AAAA,EACF,EAAE,IACF;AAAA,EACJ,eAAe,IAAI,gBACf;AAAA,IACE,GAAG,IAAI;AAAA,IACP,QAAQ,MAAM,MAAM,OAAO,mBAAmB,IAAI,aAAa;AAAA,EACjE,IACA;AAAA,EACJ,QAAQ,IAAI,SACR,MAAM,MAAM,QAAQ,eAAe,IAAI,QAAQ,OAAO,WAAW;AAAA,IAC/D,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AAAA,EACJ,QAAQ,IAAI,SACR,MAAM,MAAM,QAAQ,eAAe,IAAI,QAAQ,OAAO,WAAW;AAAA,IAC/D,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AACN;AAEO,MAAM,uBAAuB,CAClC,UACA,eACgC;AAAA,EAChC,GAAG;AAAA,EACH,QAAQ,MAAM,QAAQ,uBAAuB,SAAS,QAAQ,UAAU,MAAM;AAAA,EAC9E,iBAAiB,MAAM,QAAQ,uBAAuB,SAAS,iBAAiB,UAAU,eAAe;AAAA,EACzG,QAAQ,MAAM,QAAQ,uBAAuB,SAAS,QAAQ,UAAU,MAAM;AAAA,EAC9E,MAAM;AAAA,IACJ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,MAAM,MAAM,UAAU,MAAM,IAAI;AAAA,EACtF;AAAA,EACA,cAAc;AAAA,IACZ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,cAAc,MAAM,UAAU,cAAc,IAAI;AAAA,EACtG;AAAA,EACA,SAAS;AAAA,IACP,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,SAAS,MAAM,UAAU,SAAS,IAAI;AAAA,EAC5F;AAAA,EACA,cAAc,MAAM,QAAQ,uBAAuB,SAAS,cAAc,UAAU,YAAY;AAClG;",
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateBotBody = async (bot: sdk.BotDefinition): Promise<types.CreateBotRequestBody> => ({\n user: bot.user,\n conversation: bot.conversation,\n message: bot.message,\n recurringEvents: bot.recurringEvents,\n actions: bot.actions\n ? await utils.records.mapValuesAsync(bot.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n configuration: bot.configuration\n ? {\n ...bot.configuration,\n schema: await utils.schema.mapZodToJsonSchema(bot.configuration),\n }\n : undefined,\n events: bot.events\n ? await utils.records.mapValuesAsync(bot.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n states: bot.states\n ? await utils.records.mapValuesAsync(bot.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdateBotBody = (\n localBot: types.UpdateBotRequestBody,\n remoteBot: client.Bot\n): types.UpdateBotRequestBody => ({\n ...localBot,\n states: utils.records.setNullOnMissingValues(localBot.states, remoteBot.states),\n recurringEvents: utils.records.setNullOnMissingValues(localBot.recurringEvents, remoteBot.recurringEvents),\n events: utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),\n remoteItems: remoteBot.events,\n }),\n actions: utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localBot.actions, remoteBot.actions),\n remoteItems: remoteBot.actions,\n }),\n user: {\n ...localBot.user,\n tags: utils.records.setNullOnMissingValues(localBot.user?.tags, remoteBot.user?.tags),\n },\n conversation: {\n ...localBot.conversation,\n tags: utils.records.setNullOnMissingValues(localBot.conversation?.tags, remoteBot.conversation?.tags),\n },\n message: {\n ...localBot.message,\n tags: utils.records.setNullOnMissingValues(localBot.message?.tags, remoteBot.message?.tags),\n },\n integrations: utils.records.setNullOnMissingValues(localBot.integrations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AS,iBAAiB,UAAU,eAAe;AAAA,EACzG,QAAQ,MAAM,WAAW,2BAA2B;AAAA,IAClD,YAAY,MAAM,QAAQ,uBAAuB,SAAS,QAAQ,UAAU,MAAM;AAAA,IAClF,aAAa,UAAU;AAAA,EACzB,CAAC;AAAA,EACD,SAAS,MAAM,WAAW,2BAA2B;AAAA,IACnD,YAAY,MAAM,QAAQ,uBAAuB,SAAS,SAAS,UAAU,OAAO;AAAA,IACpF,aAAa,UAAU;AAAA,EACzB,CAAC;AAAA,EACD,MAAM;AAAA,IACJ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,MAAM,MAAM,UAAU,MAAM,IAAI;AAAA,EACtF;AAAA,EACA,cAAc;AAAA,IACZ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,cAAc,MAAM,UAAU,cAAc,IAAI;AAAA,EACtG;AAAA,EACA,SAAS;AAAA,IACP,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,SAAS,MAAM,UAAU,SAAS,IAAI;AAAA,EAC5F;AAAA,EACA,cAAc,MAAM,QAAQ,uBAAuB,SAAS,cAAc,UAAU,YAAY;AAClG;",
6
6
  "names": []
7
7
  }
@@ -33,7 +33,6 @@ __export(client_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(client_exports);
35
35
  var client = __toESM(require("@botpress/client"));
36
- var import_semver = __toESM(require("semver"));
37
36
  var import_yn = __toESM(require("yn"));
38
37
  var import_package_ref = require("../package-ref");
39
38
  var import_find_previous_version = require("./find-previous-version");
@@ -85,14 +84,14 @@ class ApiClient {
85
84
  async updateWorkspace(props) {
86
85
  return this.client.updateWorkspace({ id: this.workspaceId, ...props });
87
86
  }
88
- async getIntegration(ref) {
89
- const integration = await this.findIntegration(ref);
87
+ async getPublicOrPrivateIntegration(ref) {
88
+ const integration = await this.findPublicOrPrivateIntegration(ref);
90
89
  if (!integration) {
91
90
  throw new Error(`Integration "${(0, import_package_ref.formatPackageRef)(ref)}" not found`);
92
91
  }
93
92
  return integration;
94
93
  }
95
- async findIntegration(ref) {
94
+ async findPublicOrPrivateIntegration(ref) {
96
95
  const formatted = (0, import_package_ref.formatPackageRef)(ref);
97
96
  const privateIntegration = await this.findPrivateIntegration(ref);
98
97
  if (privateIntegration) {
@@ -115,9 +114,30 @@ class ApiClient {
115
114
  }
116
115
  async findPublicIntegration(ref) {
117
116
  if (ref.type === "id") {
118
- return this.client.getPublicIntegrationById(ref).then((r) => r.integration).catch(this._returnUndefinedOnError("ResourceNotFound"));
117
+ return this.client.getPublicIntegrationById(ref).then((r) => ({ ...r.integration, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
119
118
  }
120
- return this.client.getPublicIntegration(ref).then((r) => r.integration).catch(this._returnUndefinedOnError("ResourceNotFound"));
119
+ return this.client.getPublicIntegration(ref).then((r) => ({ ...r.integration, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
120
+ }
121
+ async findPublicOrPrivateInterface(ref) {
122
+ const formatted = (0, import_package_ref.formatPackageRef)(ref);
123
+ const privateInterface = await this.findPrivateInterface(ref);
124
+ if (privateInterface) {
125
+ this._logger.debug(`Found interface "${formatted}" in workspace`);
126
+ return privateInterface;
127
+ }
128
+ const publicInterface = await this.findPublicInterface(ref);
129
+ if (publicInterface) {
130
+ this._logger.debug(`Found interface "${formatted}" in hub`);
131
+ return publicInterface;
132
+ }
133
+ return;
134
+ }
135
+ async findPrivateInterface(ref) {
136
+ const { workspaceId } = this;
137
+ if (ref.type === "id") {
138
+ return this.client.getInterface(ref).then((r) => ({ ...r.interface, workspaceId })).catch(this._returnUndefinedOnError("ResourceNotFound"));
139
+ }
140
+ return this.client.getInterfaceByName(ref).then((r) => ({ ...r.interface, workspaceId })).catch(this._returnUndefinedOnError("ResourceNotFound"));
121
141
  }
122
142
  async getPublicInterface(ref) {
123
143
  const intrface = await this.findPublicInterface(ref);
@@ -128,40 +148,37 @@ class ApiClient {
128
148
  }
129
149
  async findPublicInterface(ref) {
130
150
  if (ref.type === "id") {
131
- return this.client.getInterface(ref).then((r) => r.interface).catch(this._returnUndefinedOnError("ResourceNotFound"));
151
+ return this.client.getPublicInterfaceById(ref).then((r) => ({ ...r.interface, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
132
152
  }
133
- if ((0, import_package_ref.isLatest)(ref)) {
134
- return this._findLatestInterfaceVersion(ref);
135
- }
136
- return this.client.getInterfaceByName(ref).then((r) => r.interface).catch(this._returnUndefinedOnError("ResourceNotFound"));
153
+ return this.client.getPublicInterface(ref).then((r) => ({ ...r.interface, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
137
154
  }
138
155
  async findPublicPlugin(ref) {
139
156
  if (ref.type === "id") {
140
- return this.client.getPlugin(ref).then((r) => r.plugin).catch(this._returnUndefinedOnError("ResourceNotFound"));
141
- }
142
- if ((0, import_package_ref.isLatest)(ref)) {
143
- return this._findLatestPluginVersion(ref);
157
+ return this.client.getPublicPluginById(ref).then((r) => ({ ...r.plugin, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
144
158
  }
145
- return this.client.getPluginByName(ref).then((r) => r.plugin).catch(this._returnUndefinedOnError("ResourceNotFound"));
159
+ return this.client.getPublicPlugin(ref).then((r) => ({ ...r.plugin, public: true })).catch(this._returnUndefinedOnError("ResourceNotFound"));
146
160
  }
147
- _findLatestInterfaceVersion = async ({ name }) => {
148
- const { interfaces: allVersions } = await this.client.listInterfaces({ name });
149
- const sorted = allVersions.sort((a, b) => import_semver.default.compare(b.version, a.version));
150
- const latestVersion = sorted[0];
151
- if (!latestVersion) {
152
- return;
161
+ async findPublicOrPrivatePlugin(ref) {
162
+ const formatted = (0, import_package_ref.formatPackageRef)(ref);
163
+ const privatePlugin = await this.findPrivatePlugin(ref);
164
+ if (privatePlugin) {
165
+ this._logger.debug(`Found plugin "${formatted}" in workspace`);
166
+ return privatePlugin;
153
167
  }
154
- return this.client.getInterface({ id: latestVersion.id }).then((r) => r.interface);
155
- };
156
- _findLatestPluginVersion = async ({ name }) => {
157
- const { plugins: allVersions } = await this.client.listPlugins({ name });
158
- const sorted = allVersions.sort((a, b) => import_semver.default.compare(b.version, a.version));
159
- const latestVersion = sorted[0];
160
- if (!latestVersion) {
161
- return;
168
+ const publicPlugin = await this.findPublicPlugin(ref);
169
+ if (publicPlugin) {
170
+ this._logger.debug(`Found plugin "${formatted}" in hub`);
171
+ return publicPlugin;
162
172
  }
163
- return this.client.getPlugin({ id: latestVersion.id }).then((r) => r.plugin);
164
- };
173
+ return;
174
+ }
175
+ async findPrivatePlugin(ref) {
176
+ const { workspaceId } = this;
177
+ if (ref.type === "id") {
178
+ return this.client.getPlugin(ref).then((r) => ({ ...r.plugin, workspaceId })).catch(this._returnUndefinedOnError("ResourceNotFound"));
179
+ }
180
+ return this.client.getPluginByName(ref).then((r) => ({ ...r.plugin, workspaceId })).catch(this._returnUndefinedOnError("ResourceNotFound"));
181
+ }
165
182
  async testLogin() {
166
183
  await this.client.listBots({});
167
184
  }
@@ -171,7 +188,7 @@ class ApiClient {
171
188
  if (!previous) {
172
189
  return;
173
190
  }
174
- return this.findIntegration({ type: "id", id: previous.id });
191
+ return this.findPublicOrPrivateIntegration({ type: "id", id: previous.id });
175
192
  }
176
193
  async findBotByName(name) {
177
194
  const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/client.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport semver from 'semver'\nimport yn from 'yn'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef, isLatest } from '../package-ref'\nimport * as utils from '../utils'\nimport { findPreviousIntegrationVersion } from './find-previous-version'\nimport * as paging from './paging'\n\nimport {\n ApiClientProps,\n PublicIntegration,\n PrivateIntegration,\n Integration,\n Interface,\n Plugin,\n BotSummary,\n} from './types'\n\nexport * from './types'\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n public readonly botId?: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(\n props: ApiClientProps,\n private _logger: Logger\n ) {\n const { apiUrl, token, workspaceId, botId } = props\n this.client = new client.Client({ apiUrl, token, workspaceId, botId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n this.botId = botId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async getWorkspace(): Promise<client.ClientOutputs['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async findWorkspaceByHandle(handle: string): Promise<client.ClientOutputs['getWorkspace'] | undefined> {\n const { workspaces } = await this.client.listWorkspaces({ handle })\n return workspaces[0] // There should be only one workspace with a given handle\n }\n\n public switchWorkspace(workspaceId: string): ApiClient {\n return ApiClient.newClient({ apiUrl: this.url, token: this.token, workspaceId }, this._logger)\n }\n\n public switchBot(botId: string): ApiClient {\n return ApiClient.newClient(\n { apiUrl: this.url, token: this.token, botId, workspaceId: this.workspaceId },\n this._logger\n )\n }\n\n public async updateWorkspace(\n props: utils.types.SafeOmit<client.ClientInputs['updateWorkspace'], 'id'>\n ): Promise<client.ClientOutputs['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async getIntegration(ref: ApiPackageRef): Promise<Integration> {\n const integration = await this.findIntegration(ref)\n if (!integration) {\n throw new Error(`Integration \"${formatPackageRef(ref)}\" not found`)\n }\n return integration\n }\n\n public async findIntegration(ref: ApiPackageRef): Promise<Integration | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicInterface(ref: ApiPackageRef): Promise<Interface> {\n const intrface = await this.findPublicInterface(ref)\n if (!intrface) {\n throw new Error(`Interface \"${formatPackageRef(ref)}\" not found`)\n }\n return intrface\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<Interface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n if (isLatest(ref)) {\n // TODO: handle latest keyword in backend\n return this._findLatestInterfaceVersion(ref)\n }\n\n return this.client\n .getInterfaceByName(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicPlugin(ref: ApiPackageRef): Promise<Plugin | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPlugin(ref)\n .then((r) => r.plugin)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n if (isLatest(ref)) {\n // TODO: handle latest keyword in backend\n return this._findLatestPluginVersion(ref)\n }\n\n return this.client\n .getPluginByName(ref)\n .then((r) => r.plugin)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n private _findLatestInterfaceVersion = async ({ name }: NamePackageRef): Promise<Interface | undefined> => {\n const { interfaces: allVersions } = await this.client.listInterfaces({ name })\n const sorted = allVersions.sort((a, b) => semver.compare(b.version, a.version))\n const latestVersion = sorted[0]\n if (!latestVersion) {\n return\n }\n return this.client.getInterface({ id: latestVersion.id }).then((r) => r.interface)\n }\n\n private _findLatestPluginVersion = async ({ name }: NamePackageRef): Promise<Plugin | undefined> => {\n const { plugins: allVersions } = await this.client.listPlugins({ name })\n const sorted = allVersions.sort((a, b) => semver.compare(b.version, a.version))\n const latestVersion = sorted[0]\n if (!latestVersion) {\n return\n }\n return this.client.getPlugin({ id: latestVersion.id }).then((r) => r.plugin)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<Integration | undefined> {\n const previous = await findPreviousIntegrationVersion(this.client, ref)\n if (!previous) {\n return\n }\n return this.findIntegration({ type: 'id', id: previous.id })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thrown.type === type) {\n return\n }\n throw thrown\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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,0BACN,CAAC,SACD,CAAC,WAA2B;AAC1B,QAAI,OAAO,WAAW,MAAM,KAAK,OAAO,SAAS,MAAM;AACrD;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACJ;",
6
- "names": ["yn", "semver"]
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport yn from 'yn'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef } from '../package-ref'\nimport * as utils from '../utils'\nimport { findPreviousIntegrationVersion } from './find-previous-version'\nimport * as paging from './paging'\n\nimport {\n ApiClientProps,\n PublicIntegration,\n PrivateIntegration,\n PublicOrPrivateIntegration,\n PublicInterface,\n PrivateInterface,\n PublicOrPrivateInterface,\n PrivatePlugin,\n PublicPlugin,\n PublicOrPrivatePlugin,\n BotSummary,\n} from './types'\n\nexport * from './types'\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n public readonly botId?: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(\n props: ApiClientProps,\n private _logger: Logger\n ) {\n const { apiUrl, token, workspaceId, botId } = props\n this.client = new client.Client({ apiUrl, token, workspaceId, botId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n this.botId = botId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async getWorkspace(): Promise<client.ClientOutputs['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async findWorkspaceByHandle(handle: string): Promise<client.ClientOutputs['getWorkspace'] | undefined> {\n const { workspaces } = await this.client.listWorkspaces({ handle })\n return workspaces[0] // There should be only one workspace with a given handle\n }\n\n public switchWorkspace(workspaceId: string): ApiClient {\n return ApiClient.newClient({ apiUrl: this.url, token: this.token, workspaceId }, this._logger)\n }\n\n public switchBot(botId: string): ApiClient {\n return ApiClient.newClient(\n { apiUrl: this.url, token: this.token, botId, workspaceId: this.workspaceId },\n this._logger\n )\n }\n\n public async updateWorkspace(\n props: utils.types.SafeOmit<client.ClientInputs['updateWorkspace'], 'id'>\n ): Promise<client.ClientOutputs['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async getPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration> {\n const integration = await this.findPublicOrPrivateIntegration(ref)\n if (!integration) {\n throw new Error(`Integration \"${formatPackageRef(ref)}\" not found`)\n }\n return integration\n }\n\n public async findPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => ({ ...r.integration, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => ({ ...r.integration, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicOrPrivateInterface(ref: ApiPackageRef): Promise<PublicOrPrivateInterface | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateInterface = await this.findPrivateInterface(ref)\n if (privateInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in workspace`)\n return privateInterface\n }\n\n const publicInterface = await this.findPublicInterface(ref)\n if (publicInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in hub`)\n return publicInterface\n }\n\n return\n }\n\n public async findPrivateInterface(ref: ApiPackageRef): Promise<PrivateInterface | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getInterfaceByName(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicInterface(ref: ApiPackageRef): Promise<PublicInterface> {\n const intrface = await this.findPublicInterface(ref)\n if (!intrface) {\n throw new Error(`Interface \"${formatPackageRef(ref)}\" not found`)\n }\n return intrface\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<PublicInterface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicInterfaceById(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicInterface(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicPlugin(ref: ApiPackageRef): Promise<PublicPlugin | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicPluginById(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicPlugin(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicOrPrivatePlugin(ref: ApiPackageRef): Promise<PublicOrPrivatePlugin | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privatePlugin = await this.findPrivatePlugin(ref)\n if (privatePlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in workspace`)\n return privatePlugin\n }\n\n const publicPlugin = await this.findPublicPlugin(ref)\n if (publicPlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in hub`)\n return publicPlugin\n }\n\n return\n }\n\n public async findPrivatePlugin(ref: ApiPackageRef): Promise<PrivatePlugin | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getPlugin(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPluginByName(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const previous = await findPreviousIntegrationVersion(this.client, ref)\n if (!previous) {\n return\n }\n return this.findPublicOrPrivateIntegration({ type: 'id', id: previous.id })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thrown.type === type) {\n return\n }\n throw thrown\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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QAAQ,YAAY,EAAE,EAC1C,MAAM,KAAK,wBAAwB,kBAAkB,CAAC;AAAA,IAC3D;AACA,WAAO,KAAK,OACT,gBAAgB,GAAG,EACnB,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,YAAY,EAAE,EAC1C,MAAM,KAAK,wBAAwB,kBAAkB,CAAC;AAAA,EAC3D;AAAA,EAEA,MAAa,YAA2B;AACtC,UAAM,KAAK,OAAO,SAAS,CAAC,CAAC;AAAA,EAC/B;AAAA,EAEO,eAAe,OAAO;AAAA,EAE7B,MAAa,+BAA+B,KAAsE;AAChH,UAAM,WAAW,UAAM,6DAA+B,KAAK,QAAQ,GAAG;AACtE,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AACA,WAAO,KAAK,+BAA+B,EAAE,MAAM,MAAM,IAAI,SAAS,GAAG,CAAC;AAAA,EAC5E;AAAA,EAEA,MAAa,cAAc,MAA+C;AAExE,UAAM,UAAU,MAAM,KAAK,aAAa,KAAK,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI;AAC3E,WAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAAA,EAC5C;AAAA,EAEQ,0BACN,CAAC,SACD,CAAC,WAA2B;AAC1B,QAAI,OAAO,WAAW,MAAM,KAAK,OAAO,SAAS,MAAM;AACrD;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACJ;",
6
+ "names": ["yn"]
7
7
  }
@@ -71,17 +71,14 @@ const prepareCreateIntegrationBody = async (integration) => ({
71
71
  })) : void 0
72
72
  });
73
73
  const prepareUpdateIntegrationBody = (localIntegration, remoteIntegration) => {
74
- const actions = utils.records.setNullOnMissingValues(localIntegration.actions, remoteIntegration.actions);
75
- for (const [actionName, action] of Object.entries(actions)) {
76
- if (!action || !remoteIntegration.actions[actionName]) {
77
- continue;
78
- }
79
- action.attributes = utils.records.setNullOnMissingValues(
80
- action.attributes,
81
- remoteIntegration.actions[actionName].attributes
82
- );
83
- }
84
- const events = utils.records.setNullOnMissingValues(localIntegration.events, remoteIntegration.events);
74
+ const actions = utils.attributes.prepareAttributeUpdateBody({
75
+ localItems: utils.records.setNullOnMissingValues(localIntegration.actions, remoteIntegration.actions),
76
+ remoteItems: remoteIntegration.actions
77
+ });
78
+ const events = utils.attributes.prepareAttributeUpdateBody({
79
+ localItems: utils.records.setNullOnMissingValues(localIntegration.events, remoteIntegration.events),
80
+ remoteItems: remoteIntegration.events
81
+ });
85
82
  const states = utils.records.setNullOnMissingValues(localIntegration.states, remoteIntegration.states);
86
83
  const entities = utils.records.setNullOnMissingValues(localIntegration.entities, remoteIntegration.entities);
87
84
  const user = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/integration-body.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateIntegrationBody = async (\n integration: sdk.IntegrationDefinition | sdk.IntegrationPackage['definition']\n): Promise<types.CreateIntegrationRequestBody> => ({\n name: integration.name,\n version: integration.version,\n title: 'title' in integration ? integration.title : undefined,\n description: 'description' in integration ? integration.description : undefined,\n user: integration.user,\n events: integration.events\n ? await utils.records.mapValuesAsync(integration.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: integration.actions\n ? await utils.records.mapValuesAsync(integration.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n channels: integration.channels\n ? await utils.records.mapValuesAsync(integration.channels, async (channel) => ({\n ...channel,\n messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({\n ...message,\n schema: await utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : undefined,\n states: integration.states\n ? await utils.records.mapValuesAsync(integration.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n entities: integration.entities\n ? await utils.records.mapValuesAsync(integration.entities, async (entity) => ({\n ...entity,\n schema: await utils.schema.mapZodToJsonSchema(entity),\n }))\n : undefined,\n})\n\ntype UpdateIntegrationChannelsBody = NonNullable<types.UpdateIntegrationRequestBody['channels']>\ntype UpdateIntegrationChannelBody = UpdateIntegrationChannelsBody[string]\ntype Channels = client.Integration['channels']\ntype Channel = client.Integration['channels'][string]\nexport const prepareUpdateIntegrationBody = (\n localIntegration: types.UpdateIntegrationRequestBody,\n remoteIntegration: client.Integration\n): types.UpdateIntegrationRequestBody => {\n const actions = utils.records.setNullOnMissingValues(localIntegration.actions, remoteIntegration.actions)\n\n for (const [actionName, action] of Object.entries(actions)) {\n if (!action || !remoteIntegration.actions[actionName]) {\n continue\n }\n\n action.attributes = utils.records.setNullOnMissingValues(\n action.attributes,\n remoteIntegration.actions[actionName].attributes\n )\n }\n\n const events = utils.records.setNullOnMissingValues(localIntegration.events, remoteIntegration.events)\n const states = utils.records.setNullOnMissingValues(localIntegration.states, remoteIntegration.states)\n const entities = utils.records.setNullOnMissingValues(localIntegration.entities, remoteIntegration.entities)\n const user = {\n ...localIntegration.user,\n tags: utils.records.setNullOnMissingValues(localIntegration.user?.tags, remoteIntegration.user?.tags),\n }\n\n const channels = _prepareUpdateIntegrationChannelsBody(localIntegration.channels ?? {}, remoteIntegration.channels)\n\n const interfaces = utils.records.setNullOnMissingValues(localIntegration.interfaces, remoteIntegration.interfaces)\n\n const configurations = utils.records.setNullOnMissingValues(\n localIntegration.configurations,\n remoteIntegration.configurations\n )\n\n return {\n ..._maybeRemoveVrlScripts(localIntegration, remoteIntegration),\n actions,\n events,\n states,\n entities,\n user,\n channels,\n interfaces,\n configurations,\n }\n}\n\nconst _maybeRemoveVrlScripts = (\n localIntegration: types.UpdateIntegrationRequestBody,\n remoteIntegration: client.Integration\n): types.UpdateIntegrationRequestBody => {\n const newIntegration = structuredClone(localIntegration)\n\n if (\n remoteIntegration.configuration?.identifier?.linkTemplateScript &&\n !localIntegration.configuration?.identifier?.linkTemplateScript\n ) {\n newIntegration.configuration ??= remoteIntegration.configuration\n newIntegration.configuration.identifier ??= remoteIntegration.configuration.identifier\n newIntegration.configuration.identifier.linkTemplateScript = null\n newIntegration.configuration.identifier.required = false\n }\n\n if (remoteIntegration.identifier.extractScript && !localIntegration.identifier?.extractScript) {\n newIntegration.identifier ??= remoteIntegration.identifier\n newIntegration.identifier.extractScript = null\n }\n\n if (remoteIntegration.identifier.fallbackHandlerScript && !localIntegration.identifier?.fallbackHandlerScript) {\n newIntegration.identifier ??= remoteIntegration.identifier\n newIntegration.identifier.fallbackHandlerScript = null\n }\n\n for (const configName of Object.keys(localIntegration.configurations ?? {})) {\n if (\n remoteIntegration.configurations[configName]?.identifier.linkTemplateScript &&\n !localIntegration.configurations?.[configName]?.identifier?.linkTemplateScript\n ) {\n newIntegration.configurations ??= remoteIntegration.configurations\n newIntegration.configurations[configName] ??= remoteIntegration.configurations[configName]\n newIntegration.configurations[configName].identifier ??= remoteIntegration.configurations[configName].identifier\n newIntegration.configurations[configName].identifier.linkTemplateScript = null\n newIntegration.configurations[configName].identifier.required = false\n }\n }\n\n return newIntegration\n}\n\nconst _prepareUpdateIntegrationChannelsBody = (\n localChannels: UpdateIntegrationChannelsBody,\n remoteChannels: Channels\n): UpdateIntegrationChannelsBody => {\n const channelBody: UpdateIntegrationChannelsBody = {}\n\n const zipped = utils.records.zipObjects(localChannels, remoteChannels)\n for (const [channelName, [localChannel, remoteChannel]] of Object.entries(zipped)) {\n if (localChannel && remoteChannel) {\n // channel has to be updated\n channelBody[channelName] = _prepareUpdateIntegrationChannelBody(localChannel, remoteChannel)\n } else if (localChannel) {\n // channel has to be created\n channelBody[channelName] = localChannel\n continue\n } else if (remoteChannel) {\n // channel has to be deleted\n channelBody[channelName] = null\n continue\n }\n }\n\n return channelBody\n}\n\nconst _prepareUpdateIntegrationChannelBody = (\n localChannel: UpdateIntegrationChannelBody,\n remoteChannel: Channel\n): UpdateIntegrationChannelBody => ({\n ...localChannel,\n messages: utils.records.setNullOnMissingValues(localChannel?.messages, remoteChannel.messages),\n message: {\n ...localChannel?.message,\n tags: utils.records.setNullOnMissingValues(localChannel?.message?.tags, remoteChannel.message.tags),\n },\n conversation: {\n ...localChannel?.conversation,\n tags: utils.records.setNullOnMissingValues(localChannel?.conversation?.tags, remoteChannel.conversation.tags),\n },\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAGhB,MAAM,+BAA+B,OAC1C,iBACiD;AAAA,EACjD,MAAM,YAAY;AAAA,EAClB,SAAS,YAAY;AAAA,EACrB,OAAO,WAAW,cAAc,YAAY,QAAQ;AAAA,EACpD,aAAa,iBAAiB,cAAc,YAAY,cAAc;AAAA,EACtE,MAAM,YAAY;AAAA,EAClB,QAAQ,YAAY,SAChB,MAAM,MAAM,QAAQ,eAAe,YAAY,QAAQ,OAAO,WAAW;AAAA,IACvE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AAAA,EACJ,SAAS,YAAY,UACjB,MAAM,MAAM,QAAQ,eAAe,YAAY,SAAS,OAAO,YAAY;AAAA,IACzE,GAAG;AAAA,IACH,OAAO;AAAA,MACL,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,KAAK;AAAA,IAC5D;AAAA,IACA,QAAQ;AAAA,MACN,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,MAAM;AAAA,IAC7D;AAAA,EACF,EAAE,IACF;AAAA,EACJ,UAAU,YAAY,WAClB,MAAM,MAAM,QAAQ,eAAe,YAAY,UAAU,OAAO,aAAa;AAAA,IAC3E,GAAG;AAAA,IACH,UAAU,MAAM,MAAM,QAAQ,eAAe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AAe,UAAU,EAAE,WAAW,qBAAqB;AAC1E,qBAAe,eAAe,UAAU,EAAE,WAAW,WAAW;AAAA,IAClE;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,wCAAwC,CAC5C,eACA,mBACkC;AAClC,QAAM,cAA6C,CAAC;AAEpD,QAAM,SAAS,MAAM,QAAQ,WAAW,eAAe,cAAc;AACrE,aAAW,CAAC,aAAa,CAAC,cAAc,aAAa,CAAC,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjF,QAAI,gBAAgB,eAAe;AAEjC,kBAAY,WAAW,IAAI,qCAAqC,cAAc,aAAa;AAAA,IAC7F,WAAW,cAAc;AAEvB,kBAAY,WAAW,IAAI;AAC3B;AAAA,IACF,WAAW,eAAe;AAExB,kBAAY,WAAW,IAAI;AAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,uCAAuC,CAC3C,cACA,mBACkC;AAAA,EAClC,GAAG;AAAA,EACH,UAAU,MAAM,QAAQ,uBAAuB,cAAc,UAAU,cAAc,QAAQ;AAAA,EAC7F,SAAS;AAAA,IACP,GAAG,cAAc;AAAA,IACjB,MAAM,MAAM,QAAQ,uBAAuB,cAAc,SAAS,MAAM,cAAc,QAAQ,IAAI;AAAA,EACpG;AAAA,EACA,cAAc;AAAA,IACZ,GAAG,cAAc;AAAA,IACjB,MAAM,MAAM,QAAQ,uBAAuB,cAAc,cAAc,MAAM,cAAc,aAAa,IAAI;AAAA,EAC9G;AACF;",
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateIntegrationBody = async (\n integration: sdk.IntegrationDefinition | sdk.IntegrationPackage['definition']\n): Promise<types.CreateIntegrationRequestBody> => ({\n name: integration.name,\n version: integration.version,\n title: 'title' in integration ? integration.title : undefined,\n description: 'description' in integration ? integration.description : undefined,\n user: integration.user,\n events: integration.events\n ? await utils.records.mapValuesAsync(integration.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: integration.actions\n ? await utils.records.mapValuesAsync(integration.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n channels: integration.channels\n ? await utils.records.mapValuesAsync(integration.channels, async (channel) => ({\n ...channel,\n messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({\n ...message,\n schema: await utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : undefined,\n states: integration.states\n ? await utils.records.mapValuesAsync(integration.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n entities: integration.entities\n ? await utils.records.mapValuesAsync(integration.entities, async (entity) => ({\n ...entity,\n schema: await utils.schema.mapZodToJsonSchema(entity),\n }))\n : undefined,\n})\n\ntype UpdateIntegrationChannelsBody = NonNullable<types.UpdateIntegrationRequestBody['channels']>\ntype UpdateIntegrationChannelBody = UpdateIntegrationChannelsBody[string]\ntype Channels = client.Integration['channels']\ntype Channel = client.Integration['channels'][string]\nexport const prepareUpdateIntegrationBody = (\n localIntegration: types.UpdateIntegrationRequestBody,\n remoteIntegration: client.Integration\n): types.UpdateIntegrationRequestBody => {\n const actions = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localIntegration.actions, remoteIntegration.actions),\n remoteItems: remoteIntegration.actions,\n })\n const events = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localIntegration.events, remoteIntegration.events),\n remoteItems: remoteIntegration.events,\n })\n const states = utils.records.setNullOnMissingValues(localIntegration.states, remoteIntegration.states)\n const entities = utils.records.setNullOnMissingValues(localIntegration.entities, remoteIntegration.entities)\n const user = {\n ...localIntegration.user,\n tags: utils.records.setNullOnMissingValues(localIntegration.user?.tags, remoteIntegration.user?.tags),\n }\n\n const channels = _prepareUpdateIntegrationChannelsBody(localIntegration.channels ?? {}, remoteIntegration.channels)\n\n const interfaces = utils.records.setNullOnMissingValues(localIntegration.interfaces, remoteIntegration.interfaces)\n\n const configurations = utils.records.setNullOnMissingValues(\n localIntegration.configurations,\n remoteIntegration.configurations\n )\n\n return {\n ..._maybeRemoveVrlScripts(localIntegration, remoteIntegration),\n actions,\n events,\n states,\n entities,\n user,\n channels,\n interfaces,\n configurations,\n }\n}\n\nconst _maybeRemoveVrlScripts = (\n localIntegration: types.UpdateIntegrationRequestBody,\n remoteIntegration: client.Integration\n): types.UpdateIntegrationRequestBody => {\n const newIntegration = structuredClone(localIntegration)\n\n if (\n remoteIntegration.configuration?.identifier?.linkTemplateScript &&\n !localIntegration.configuration?.identifier?.linkTemplateScript\n ) {\n newIntegration.configuration ??= remoteIntegration.configuration\n newIntegration.configuration.identifier ??= remoteIntegration.configuration.identifier\n newIntegration.configuration.identifier.linkTemplateScript = null\n newIntegration.configuration.identifier.required = false\n }\n\n if (remoteIntegration.identifier.extractScript && !localIntegration.identifier?.extractScript) {\n newIntegration.identifier ??= remoteIntegration.identifier\n newIntegration.identifier.extractScript = null\n }\n\n if (remoteIntegration.identifier.fallbackHandlerScript && !localIntegration.identifier?.fallbackHandlerScript) {\n newIntegration.identifier ??= remoteIntegration.identifier\n newIntegration.identifier.fallbackHandlerScript = null\n }\n\n for (const configName of Object.keys(localIntegration.configurations ?? {})) {\n if (\n remoteIntegration.configurations[configName]?.identifier.linkTemplateScript &&\n !localIntegration.configurations?.[configName]?.identifier?.linkTemplateScript\n ) {\n newIntegration.configurations ??= remoteIntegration.configurations\n newIntegration.configurations[configName] ??= remoteIntegration.configurations[configName]\n newIntegration.configurations[configName].identifier ??= remoteIntegration.configurations[configName].identifier\n newIntegration.configurations[configName].identifier.linkTemplateScript = null\n newIntegration.configurations[configName].identifier.required = false\n }\n }\n\n return newIntegration\n}\n\nconst _prepareUpdateIntegrationChannelsBody = (\n localChannels: UpdateIntegrationChannelsBody,\n remoteChannels: Channels\n): UpdateIntegrationChannelsBody => {\n const channelBody: UpdateIntegrationChannelsBody = {}\n\n const zipped = utils.records.zipObjects(localChannels, remoteChannels)\n for (const [channelName, [localChannel, remoteChannel]] of Object.entries(zipped)) {\n if (localChannel && remoteChannel) {\n // channel has to be updated\n channelBody[channelName] = _prepareUpdateIntegrationChannelBody(localChannel, remoteChannel)\n } else if (localChannel) {\n // channel has to be created\n channelBody[channelName] = localChannel\n continue\n } else if (remoteChannel) {\n // channel has to be deleted\n channelBody[channelName] = null\n continue\n }\n }\n\n return channelBody\n}\n\nconst _prepareUpdateIntegrationChannelBody = (\n localChannel: UpdateIntegrationChannelBody,\n remoteChannel: Channel\n): UpdateIntegrationChannelBody => ({\n ...localChannel,\n messages: utils.records.setNullOnMissingValues(localChannel?.messages, remoteChannel.messages),\n message: {\n ...localChannel?.message,\n tags: utils.records.setNullOnMissingValues(localChannel?.message?.tags, remoteChannel.message.tags),\n },\n conversation: {\n ...localChannel?.conversation,\n tags: utils.records.setNullOnMissingValues(localChannel?.conversation?.tags, remoteChannel.conversation.tags),\n },\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAGhB,MAAM,+BAA+B,OAC1C,iBACiD;AAAA,EACjD,MAAM,YAAY;AAAA,EAClB,SAAS,YAAY;AAAA,EACrB,OAAO,WAAW,cAAc,YAAY,QAAQ;AAAA,EACpD,aAAa,iBAAiB,cAAc,YAAY,cAAc;AAAA,EACtE,MAAM,YAAY;AAAA,EAClB,QAAQ,YAAY,SAChB,MAAM,MAAM,QAAQ,eAAe,YAAY,QAAQ,OAAO,WAAW;AAAA,IACvE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AAAA,EACJ,SAAS,YAAY,UACjB,MAAM,MAAM,QAAQ,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M,cAAc,aAAa,IAAI;AAAA,EAC9G;AACF;",
6
6
  "names": []
7
7
  }
@@ -66,20 +66,14 @@ const prepareCreateInterfaceBody = async (intrface) => ({
66
66
  })) : {}
67
67
  });
68
68
  const prepareUpdateInterfaceBody = (localInterface, remoteInterface) => {
69
- const actions = utils.records.setNullOnMissingValues(
70
- localInterface.actions,
71
- remoteInterface.actions
72
- );
73
- for (const [actionName, action] of Object.entries(actions)) {
74
- if (!action || !remoteInterface.actions[actionName]) {
75
- continue;
76
- }
77
- action.attributes = utils.records.setNullOnMissingValues(
78
- action.attributes,
79
- remoteInterface.actions[actionName].attributes
80
- );
81
- }
82
- const events = utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events);
69
+ const actions = utils.attributes.prepareAttributeUpdateBody({
70
+ localItems: utils.records.setNullOnMissingValues(localInterface.actions, remoteInterface.actions),
71
+ remoteItems: remoteInterface.actions
72
+ });
73
+ const events = utils.attributes.prepareAttributeUpdateBody({
74
+ localItems: utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events),
75
+ remoteItems: remoteInterface.events
76
+ });
83
77
  const entities = utils.records.setNullOnMissingValues(localInterface.entities, remoteInterface.entities);
84
78
  const currentChannels = localInterface.channels ? utils.records.mapValues(localInterface.channels, (channel, channelName) => ({
85
79
  ...channel,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/interface-body.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateInterfaceBody = async (\n intrface: sdk.InterfaceDefinition | sdk.InterfacePackage['definition']\n): Promise<types.CreateInterfaceRequestBody> => ({\n name: intrface.name,\n version: intrface.version,\n title: 'title' in intrface ? intrface.title : undefined,\n description: 'description' in intrface ? intrface.description : undefined,\n entities: intrface.entities\n ? await utils.records.mapValuesAsync(intrface.entities, async (entity) => ({\n ...entity,\n schema: await utils.schema.mapZodToJsonSchema(entity),\n }))\n : {},\n events: intrface.events\n ? await utils.records.mapValuesAsync(intrface.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : {},\n actions: intrface.actions\n ? await utils.records.mapValuesAsync(intrface.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : {},\n channels: intrface.channels\n ? await utils.records.mapValuesAsync(intrface.channels, async (channel) => ({\n ...channel,\n messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({\n ...message,\n schema: await utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : {},\n})\n\nexport const prepareUpdateInterfaceBody = (\n localInterface: types.CreateInterfaceRequestBody & { id: string },\n remoteInterface: client.Interface\n): types.UpdateInterfaceRequestBody => {\n const actions = utils.records.setNullOnMissingValues(\n localInterface.actions,\n remoteInterface.actions\n ) as types.CreateInterfaceRequestBody['actions'] &\n Pick<NonNullable<types.UpdateInterfaceRequestBody['actions']>, 'attributes'>\n\n for (const [actionName, action] of Object.entries(actions)) {\n if (!action || !remoteInterface.actions[actionName]) {\n continue\n }\n\n action.attributes = utils.records.setNullOnMissingValues(\n action.attributes,\n remoteInterface.actions[actionName].attributes\n )\n }\n\n const events = utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events)\n const entities = utils.records.setNullOnMissingValues(localInterface.entities, remoteInterface.entities)\n\n const currentChannels: types.UpdateInterfaceRequestBody['channels'] = localInterface.channels\n ? utils.records.mapValues(localInterface.channels, (channel, channelName) => ({\n ...channel,\n messages: utils.records.setNullOnMissingValues(\n channel?.messages,\n remoteInterface.channels[channelName]?.messages\n ),\n }))\n : undefined\n\n const channels = utils.records.setNullOnMissingValues(currentChannels, remoteInterface.channels)\n\n return {\n ...localInterface,\n entities,\n actions,\n events,\n channels,\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;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AA6B,CACxC,gBACA,oBACqC;AACrC,QAAM,UAAU,MAAM,QAAQ;AAAA,IAC5B,eAAe;AAAA,IACf,gBAAgB;AAAA,EAClB;AAGA,aAAW,CAAC,YAAY,MAAM,KAAK,OAAO,QAAQ,OAAO,GAAG;AAC1D,QAAI,CAAC,UAAU,CAAC,gBAAgB,QAAQ,UAAU,GAAG;AACnD;AAAA,IACF;AAEA,WAAO,aAAa,MAAM,QAAQ;AAAA,MAChC,OAAO;AAAA,MACP,gBAAgB,QAAQ,UAAU,EAAE;AAAA,IACtC;AAAA,EACF;AAEA,QAAM,SAAS,MAAM,QAAQ,uBAAuB,eAAe,QAAQ,gBAAgB,MAAM;AACjG,QAAM,WAAW,MAAM,QAAQ,uBAAuB,eAAe,UAAU,gBAAgB,QAAQ;AAEvG,QAAM,kBAAgE,eAAe,WACjF,MAAM,QAAQ,UAAU,eAAe,UAAU,CAAC,SAAS,iBAAiB;AAAA,IAC1E,GAAG;AAAA,IACH,UAAU,MAAM,QAAQ;AAAA,MACtB,SAAS;AAAA,MACT,gBAAgB,SAAS,WAAW,GAAG;AAAA,IACzC;AAAA,EACF,EAAE,IACF;AAEJ,QAAM,WAAW,MAAM,QAAQ,uBAAuB,iBAAiB,gBAAgB,QAAQ;AAE/F,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreateInterfaceBody = async (\n intrface: sdk.InterfaceDefinition | sdk.InterfacePackage['definition']\n): Promise<types.CreateInterfaceRequestBody> => ({\n name: intrface.name,\n version: intrface.version,\n title: 'title' in intrface ? intrface.title : undefined,\n description: 'description' in intrface ? intrface.description : undefined,\n entities: intrface.entities\n ? await utils.records.mapValuesAsync(intrface.entities, async (entity) => ({\n ...entity,\n schema: await utils.schema.mapZodToJsonSchema(entity),\n }))\n : {},\n events: intrface.events\n ? await utils.records.mapValuesAsync(intrface.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : {},\n actions: intrface.actions\n ? await utils.records.mapValuesAsync(intrface.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : {},\n channels: intrface.channels\n ? await utils.records.mapValuesAsync(intrface.channels, async (channel) => ({\n ...channel,\n messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({\n ...message,\n schema: await utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : {},\n})\n\nexport const prepareUpdateInterfaceBody = (\n localInterface: types.CreateInterfaceRequestBody & { id: string },\n remoteInterface: client.Interface\n): types.UpdateInterfaceRequestBody => {\n const actions = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localInterface.actions, remoteInterface.actions),\n remoteItems: remoteInterface.actions,\n })\n const events = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events),\n remoteItems: remoteInterface.events,\n })\n const entities = utils.records.setNullOnMissingValues(localInterface.entities, remoteInterface.entities)\n\n const currentChannels: types.UpdateInterfaceRequestBody['channels'] = localInterface.channels\n ? utils.records.mapValues(localInterface.channels, (channel, channelName) => ({\n ...channel,\n messages: utils.records.setNullOnMissingValues(\n channel?.messages,\n remoteInterface.channels[channelName]?.messages\n ),\n }))\n : undefined\n\n const channels = utils.records.setNullOnMissingValues(currentChannels, remoteInterface.channels)\n\n return {\n ...localInterface,\n entities,\n actions,\n events,\n channels,\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAGhB,MAAM,6BAA6B,OACxC,cAC+C;AAAA,EAC/C,MAAM,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gB,OAAO;AAAA,IAChG,aAAa,gBAAgB;AAAA,EAC/B,CAAC;AACD,QAAM,SAAS,MAAM,WAAW,2BAA2B;AAAA,IACzD,YAAY,MAAM,QAAQ,uBAAuB,eAAe,QAAQ,gBAAgB,MAAM;AAAA,IAC9F,aAAa,gBAAgB;AAAA,EAC/B,CAAC;AACD,QAAM,WAAW,MAAM,QAAQ,uBAAuB,eAAe,UAAU,gBAAgB,QAAQ;AAEvG,QAAM,kBAAgE,eAAe,WACjF,MAAM,QAAQ,UAAU,eAAe,UAAU,CAAC,SAAS,iBAAiB;AAAA,IAC1E,GAAG;AAAA,IACH,UAAU,MAAM,QAAQ;AAAA,MACtB,SAAS;AAAA,MACT,gBAAgB,SAAS,WAAW,GAAG;AAAA,IACzC;AAAA,EACF,EAAE,IACF;AAEJ,QAAM,WAAW,MAAM,QAAQ,uBAAuB,iBAAiB,gBAAgB,QAAQ;AAE/F,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -69,8 +69,14 @@ const prepareCreatePluginBody = async (plugin) => ({
69
69
  })) : void 0
70
70
  });
71
71
  const prepareUpdatePluginBody = (localPlugin, remotePlugin) => {
72
- const actions = utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions);
73
- const events = utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events);
72
+ const actions = utils.attributes.prepareAttributeUpdateBody({
73
+ localItems: utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions),
74
+ remoteItems: remotePlugin.actions
75
+ });
76
+ const events = utils.attributes.prepareAttributeUpdateBody({
77
+ localItems: utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events),
78
+ remoteItems: remotePlugin.events
79
+ });
74
80
  const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states);
75
81
  return {
76
82
  ...localPlugin,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/plugin-body.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreatePluginBody = async (\n plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']\n): Promise<types.CreatePluginRequestBody> => ({\n name: plugin.name,\n version: plugin.version,\n title: 'title' in plugin ? plugin.title : undefined,\n description: 'description' in plugin ? plugin.description : undefined,\n user: {\n tags: plugin.user?.tags ?? {},\n },\n conversation: {\n tags: plugin.conversation?.tags ?? {},\n },\n configuration: plugin.configuration\n ? {\n ...plugin.configuration,\n schema: await utils.schema.mapZodToJsonSchema(plugin.configuration),\n }\n : undefined,\n events: plugin.events\n ? await utils.records.mapValuesAsync(plugin.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: plugin.actions\n ? await utils.records.mapValuesAsync(plugin.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n states: plugin.states\n ? await utils.records.mapValuesAsync(plugin.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdatePluginBody = (\n localPlugin: types.UpdatePluginRequestBody,\n remotePlugin: client.Plugin\n): types.UpdatePluginRequestBody => {\n const actions = utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions)\n const events = utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events)\n const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states)\n\n return {\n ...localPlugin,\n actions,\n events,\n states,\n user: localPlugin.user, // TODO: allow deleting user tags with null\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAA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B,YAAY,SAAS,aAAa,OAAO;AAC9F,QAAM,SAAS,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAC3F,QAAM,SAAS,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAE3F,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,YAAY;AAAA;AAAA,EACpB;AACF;",
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\nimport * as types from './types'\n\nexport const prepareCreatePluginBody = async (\n plugin: sdk.PluginDefinition | sdk.PluginPackage['definition']\n): Promise<types.CreatePluginRequestBody> => ({\n name: plugin.name,\n version: plugin.version,\n title: 'title' in plugin ? plugin.title : undefined,\n description: 'description' in plugin ? plugin.description : undefined,\n user: {\n tags: plugin.user?.tags ?? {},\n },\n conversation: {\n tags: plugin.conversation?.tags ?? {},\n },\n configuration: plugin.configuration\n ? {\n ...plugin.configuration,\n schema: await utils.schema.mapZodToJsonSchema(plugin.configuration),\n }\n : undefined,\n events: plugin.events\n ? await utils.records.mapValuesAsync(plugin.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: plugin.actions\n ? await utils.records.mapValuesAsync(plugin.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n states: plugin.states\n ? await utils.records.mapValuesAsync(plugin.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdatePluginBody = (\n localPlugin: types.UpdatePluginRequestBody,\n remotePlugin: client.Plugin\n): types.UpdatePluginRequestBody => {\n const actions = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions),\n remoteItems: remotePlugin.actions,\n })\n const events = utils.attributes.prepareAttributeUpdateBody({\n localItems: utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events),\n remoteItems: remotePlugin.events,\n })\n const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states)\n\n return {\n ...localPlugin,\n actions,\n events,\n states,\n user: localPlugin.user, // TODO: allow deleting user tags with null\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAGhB,MAAM,0BAA0B,OACrC,YAC4C;AAAA,EAC5C,MAAM,OAAO;AAAA,EACb,SAAS,OAAO;AAAA,EAChB,OAAO,WAAW,SAAS,OAAO,QAAQ;AAAA,EAC1C,aAAa,iBAAiB,SAAS,OAAO,cAAc;AAAA,EAC5D,MAAM;AAAA,IACJ,MAAM,OAAO,MAAM,QAAQ,CAAC;AAAA,EAC9B;AAAA,EACA,cAAc;AAAA,IACZ,MAAM,OAAO,cAAc,QAAQ,CAAC;AAAA,EACtC;AAAA,EACA,eAAe,OAAO,gBAClB;AAAA,IACE,GAAG,OAAO;AAAA,IACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,aAAa;AAAA,EACpE,IACA;AAAA,EACJ,QAAQ,OAAO,SACX,MAAM,MAAM,QAAQ,eAAe,OAAO,QAAQ,OAAO,WAAW;AAAA,IAClE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AAAA,EACJ,SAAS,OAAO,UACZ,MAAM,MAAM,QAAQ,eAAe,OAAO,SAAS,OAAO,YAAY;AAAA,IACpE,GAAG;AAAA,IACH,OAAO;AAAA,MACL,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,KAAK;AAAA,IAC5D;AAAA,IACA,QAAQ;AAAA,MACN,GAAG,OAAO;AAAA,MACV,QAAQ,MAAM,MAAM,OAAO,mBAAmB,OAAO,MAAM;AAAA,IAC7D;AAAA,EACF,EAAE,IACF;AAAA,EACJ,QAAQ,OAAO,SACX,MAAM,MAAM,QAAQ,eAAe,OAAO,QAAQ,OAAO,WAAW;AAAA,IAClE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF;AACN;AAEO,MAAM,0BAA0B,CACrC,aACA,iBACkC;AAClC,QAAM,UAAU,MAAM,WAAW,2BAA2B;AAAA,IAC1D,YAAY,MAAM,QAAQ,uBAAuB,YAAY,SAAS,aAAa,OAAO;AAAA,IAC1F,aAAa,aAAa;AAAA,EAC5B,CAAC;AACD,QAAM,SAAS,MAAM,WAAW,2BAA2B;AAAA,IACzD,YAAY,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAAA,IACxF,aAAa,aAAa;AAAA,EAC5B,CAAC;AACD,QAAM,SAAS,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAE3F,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,YAAY;AAAA;AAAA,EACpB;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/types.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport { Logger } from '../logger'\nimport { SafeOmit, Merge } from '../utils/type-utils'\nimport { ApiClient } from './client'\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n botId?: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\nexport type PublicIntegration = client.Integration\nexport type PrivateIntegration = client.Integration & { workspaceId: string }\nexport type Integration = client.Integration & { workspaceId?: string }\nexport type IntegrationSummary = client.ClientOutputs['listIntegrations']['integrations'][number]\nexport type BotSummary = client.ClientOutputs['listBots']['bots'][number]\nexport type Interface = client.Interface\nexport type Plugin = client.Plugin\n\nexport type CreateBotRequestBody = client.ClientInputs['createBot']\nexport type UpdateBotRequestBody = client.ClientInputs['updateBot']\n\nexport type CreateIntegrationRequestBody = client.ClientInputs['createIntegration']\nexport type UpdateIntegrationRequestBody = client.ClientInputs['updateIntegration']\n\nexport type CreateInterfaceRequestBody = client.ClientInputs['createInterface']\nexport type UpdateInterfaceRequestBody = client.ClientInputs['updateInterface']\n\ntype PluginDependency = client.Plugin['dependencies']['integrations'][string]\n\nexport type CreatePluginRequestBody = Merge<\n SafeOmit<client.ClientInputs['createPlugin'], 'code'>,\n {\n dependencies?: {\n integrations?: Record<string, PluginDependency>\n interfaces?: Record<string, PluginDependency>\n }\n }\n>\n\nexport type UpdatePluginRequestBody = Merge<\n client.ClientInputs['updatePlugin'],\n {\n dependencies?: {\n integrations?: Record<string, PluginDependency | null>\n interfaces?: Record<string, PluginDependency | null>\n }\n }\n>\n"],
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport { Logger } from '../logger'\nimport { SafeOmit, Merge } from '../utils/type-utils'\nimport { ApiClient } from './client'\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n botId?: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\nexport type PublicIntegration = client.Integration & { public: true }\nexport type PrivateIntegration = client.Integration & { workspaceId: string }\nexport type PublicOrPrivateIntegration = client.Integration & { workspaceId?: string }\nexport type IntegrationSummary = client.ClientOutputs['listIntegrations']['integrations'][number]\nexport type BotSummary = client.ClientOutputs['listBots']['bots'][number]\nexport type PublicInterface = client.Interface & { public: true }\nexport type PrivateInterface = client.Interface & { workspaceId: string }\nexport type PublicOrPrivateInterface = client.Interface & { workspaceId?: string }\nexport type PublicPlugin = client.Plugin & { public: true }\nexport type PrivatePlugin = client.Plugin & { workspaceId: string }\nexport type PublicOrPrivatePlugin = client.Plugin & { workspaceId?: string }\n\nexport type CreateBotRequestBody = client.ClientInputs['createBot']\nexport type UpdateBotRequestBody = client.ClientInputs['updateBot']\n\nexport type CreateIntegrationRequestBody = client.ClientInputs['createIntegration']\nexport type UpdateIntegrationRequestBody = client.ClientInputs['updateIntegration']\n\nexport type CreateInterfaceRequestBody = client.ClientInputs['createInterface']\nexport type UpdateInterfaceRequestBody = client.ClientInputs['updateInterface']\n\ntype PluginDependency = client.Plugin['dependencies']['integrations'][string]\n\nexport type CreatePluginRequestBody = Merge<\n SafeOmit<client.ClientInputs['createPlugin'], 'code'>,\n {\n dependencies?: {\n integrations?: Record<string, PluginDependency>\n interfaces?: Record<string, PluginDependency>\n }\n }\n>\n\nexport type UpdatePluginRequestBody = Merge<\n client.ClientInputs['updatePlugin'],\n {\n dependencies?: {\n integrations?: Record<string, PluginDependency | null>\n interfaces?: Record<string, PluginDependency | null>\n }\n }\n>\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -44,14 +44,13 @@ class EventModule extends import_module.Module {
44
44
  this._event = _event;
45
45
  }
46
46
  async getContent() {
47
- return (0, import_generators.jsonSchemaToTypescriptZuiSchema)(
48
- this._event.schema,
49
- this.exportName,
50
- gen.primitiveRecordToTypescriptValues({
47
+ return (0, import_generators.jsonSchemaToTypescriptZuiSchema)(this._event.schema, this.exportName, {
48
+ ...gen.primitiveRecordToTypescriptValues({
51
49
  title: this._event.title,
52
50
  description: this._event.description
53
- })
54
- );
51
+ }),
52
+ ...this._event.attributes ? { attributes: gen.stringifySingleLine(this._event.attributes) } : void 0
53
+ });
55
54
  }
56
55
  }
57
56
  class EventsModule extends import_module.ReExportVariableModule {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/code-generation/integration-package/integration-package-definition/events-module.ts"],
4
- "sourcesContent": ["import { jsonSchemaToTypescriptZuiSchema } from '../../generators'\nimport * as gen from '../../generators'\nimport { Module, ReExportVariableModule } from '../../module'\nimport * as strings from '../../strings'\nimport * as types from './typings'\n\nexport class EventModule extends Module {\n public constructor(\n name: string,\n private _event: types.EventDefinition\n ) {\n const eventName = name\n const exportName = strings.varName(eventName)\n super({ path: `${name}.ts`, exportName })\n }\n\n public async getContent() {\n return jsonSchemaToTypescriptZuiSchema(\n this._event.schema,\n this.exportName,\n gen.primitiveRecordToTypescriptValues({\n title: this._event.title,\n description: this._event.description,\n })\n )\n }\n}\n\nexport class EventsModule extends ReExportVariableModule {\n public constructor(events: Record<string, types.EventDefinition>) {\n super({ exportName: strings.varName('events') })\n for (const [eventName, event] of Object.entries(events)) {\n const module = new EventModule(eventName, event)\n this.pushDep(module)\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgD;AAChD,UAAqB;AACrB,oBAA+C;AAC/C,cAAyB;AAGlB,MAAM,oBAAoB,qBAAO;AAAA,EAC/B,YACL,MACQ,QACR;AACA,UAAM,YAAY;AAClB,UAAM,aAAa,QAAQ,QAAQ,SAAS;AAC5C,UAAM,EAAE,MAAM,GAAG,WAAW,WAAW,CAAC;AAJhC;AAAA,EAKV;AAAA,EAEA,MAAa,aAAa;AACxB,eAAO;AAAA,MACL,KAAK,OAAO;AAAA,MACZ,KAAK;AAAA,MACL,IAAI,kCAAkC;AAAA,QACpC,OAAO,KAAK,OAAO;AAAA,QACnB,aAAa,KAAK,OAAO;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,qBAAqB,qCAAuB;AAAA,EAChD,YAAY,QAA+C;AAChE,UAAM,EAAE,YAAY,QAAQ,QAAQ,QAAQ,EAAE,CAAC;AAC/C,eAAW,CAAC,WAAW,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACvD,YAAMA,UAAS,IAAI,YAAY,WAAW,KAAK;AAC/C,WAAK,QAAQA,OAAM;AAAA,IACrB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { jsonSchemaToTypescriptZuiSchema } from '../../generators'\nimport * as gen from '../../generators'\nimport { Module, ReExportVariableModule } from '../../module'\nimport * as strings from '../../strings'\nimport * as types from './typings'\n\nexport class EventModule extends Module {\n public constructor(\n name: string,\n private _event: types.EventDefinition\n ) {\n const eventName = name\n const exportName = strings.varName(eventName)\n super({ path: `${name}.ts`, exportName })\n }\n\n public async getContent() {\n return jsonSchemaToTypescriptZuiSchema(this._event.schema, this.exportName, {\n ...gen.primitiveRecordToTypescriptValues({\n title: this._event.title,\n description: this._event.description,\n }),\n ...(this._event.attributes ? { attributes: gen.stringifySingleLine(this._event.attributes) } : undefined),\n })\n }\n}\n\nexport class EventsModule extends ReExportVariableModule {\n public constructor(events: Record<string, types.EventDefinition>) {\n super({ exportName: strings.varName('events') })\n for (const [eventName, event] of Object.entries(events)) {\n const module = new EventModule(eventName, event)\n this.pushDep(module)\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgD;AAChD,UAAqB;AACrB,oBAA+C;AAC/C,cAAyB;AAGlB,MAAM,oBAAoB,qBAAO;AAAA,EAC/B,YACL,MACQ,QACR;AACA,UAAM,YAAY;AAClB,UAAM,aAAa,QAAQ,QAAQ,SAAS;AAC5C,UAAM,EAAE,MAAM,GAAG,WAAW,WAAW,CAAC;AAJhC;AAAA,EAKV;AAAA,EAEA,MAAa,aAAa;AACxB,eAAO,mDAAgC,KAAK,OAAO,QAAQ,KAAK,YAAY;AAAA,MAC1E,GAAG,IAAI,kCAAkC;AAAA,QACvC,OAAO,KAAK,OAAO;AAAA,QACnB,aAAa,KAAK,OAAO;AAAA,MAC3B,CAAC;AAAA,MACD,GAAI,KAAK,OAAO,aAAa,EAAE,YAAY,IAAI,oBAAoB,KAAK,OAAO,UAAU,EAAE,IAAI;AAAA,IACjG,CAAC;AAAA,EACH;AACF;AAEO,MAAM,qBAAqB,qCAAuB;AAAA,EAChD,YAAY,QAA+C;AAChE,UAAM,EAAE,YAAY,QAAQ,QAAQ,QAAQ,EAAE,CAAC;AAC/C,eAAW,CAAC,WAAW,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACvD,YAAMA,UAAS,IAAI,YAAY,WAAW,KAAK;AAC/C,WAAK,QAAQA,OAAM;AAAA,IACrB;AAAA,EACF;AACF;",
6
6
  "names": ["module"]
7
7
  }
@@ -47,14 +47,13 @@ class EventModule extends import_module.Module {
47
47
  if (!this._event.schema) {
48
48
  return `export const ${this.exportName} = z.object({});`;
49
49
  }
50
- return (0, import_generators.jsonSchemaToTypescriptZuiSchema)(
51
- this._event.schema,
52
- this.exportName,
53
- gen.primitiveRecordToTypescriptValues({
50
+ return (0, import_generators.jsonSchemaToTypescriptZuiSchema)(this._event.schema, this.exportName, {
51
+ ...gen.primitiveRecordToTypescriptValues({
54
52
  title: this._event.title,
55
53
  description: this._event.description
56
- })
57
- );
54
+ }),
55
+ ...this._event.attributes ? { attributes: gen.stringifySingleLine(this._event.attributes) } : void 0
56
+ });
58
57
  }
59
58
  }
60
59
  class EventsModule extends import_module.ReExportVariableModule {