@botonic/plugin-flow-builder 0.35.0-alpha.0 → 0.35.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 (61) hide show
  1. package/lib/cjs/action/fallback.d.ts +1 -1
  2. package/lib/cjs/action/fallback.js +2 -2
  3. package/lib/cjs/action/fallback.js.map +1 -1
  4. package/lib/cjs/action/first-interaction.js +5 -5
  5. package/lib/cjs/action/first-interaction.js.map +1 -1
  6. package/lib/cjs/action/index.js +1 -2
  7. package/lib/cjs/action/index.js.map +1 -1
  8. package/lib/cjs/action/knowledge-bases.d.ts +1 -1
  9. package/lib/cjs/action/knowledge-bases.js +2 -2
  10. package/lib/cjs/action/knowledge-bases.js.map +1 -1
  11. package/lib/cjs/action/payload.d.ts +1 -1
  12. package/lib/cjs/action/payload.js +2 -2
  13. package/lib/cjs/action/payload.js.map +1 -1
  14. package/lib/cjs/api.d.ts +4 -1
  15. package/lib/cjs/api.js +20 -2
  16. package/lib/cjs/api.js.map +1 -1
  17. package/lib/cjs/content-fields/flow-handoff.js +2 -2
  18. package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
  19. package/lib/cjs/functions/conditional-country.js +1 -1
  20. package/lib/cjs/functions/conditional-country.js.map +1 -1
  21. package/lib/cjs/index.d.ts +4 -5
  22. package/lib/cjs/index.js +13 -21
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/types.d.ts +1 -2
  25. package/lib/cjs/types.js.map +1 -1
  26. package/lib/esm/action/fallback.d.ts +1 -1
  27. package/lib/esm/action/fallback.js +2 -2
  28. package/lib/esm/action/fallback.js.map +1 -1
  29. package/lib/esm/action/first-interaction.js +5 -5
  30. package/lib/esm/action/first-interaction.js.map +1 -1
  31. package/lib/esm/action/index.js +1 -2
  32. package/lib/esm/action/index.js.map +1 -1
  33. package/lib/esm/action/knowledge-bases.d.ts +1 -1
  34. package/lib/esm/action/knowledge-bases.js +2 -2
  35. package/lib/esm/action/knowledge-bases.js.map +1 -1
  36. package/lib/esm/action/payload.d.ts +1 -1
  37. package/lib/esm/action/payload.js +2 -2
  38. package/lib/esm/action/payload.js.map +1 -1
  39. package/lib/esm/api.d.ts +4 -1
  40. package/lib/esm/api.js +20 -2
  41. package/lib/esm/api.js.map +1 -1
  42. package/lib/esm/content-fields/flow-handoff.js +2 -2
  43. package/lib/esm/content-fields/flow-handoff.js.map +1 -1
  44. package/lib/esm/functions/conditional-country.js +1 -1
  45. package/lib/esm/functions/conditional-country.js.map +1 -1
  46. package/lib/esm/index.d.ts +4 -5
  47. package/lib/esm/index.js +13 -21
  48. package/lib/esm/index.js.map +1 -1
  49. package/lib/esm/types.d.ts +1 -2
  50. package/lib/esm/types.js.map +1 -1
  51. package/package.json +3 -3
  52. package/src/action/fallback.ts +2 -5
  53. package/src/action/first-interaction.ts +3 -6
  54. package/src/action/index.tsx +1 -2
  55. package/src/action/knowledge-bases.ts +1 -3
  56. package/src/action/payload.ts +1 -2
  57. package/src/api.ts +24 -3
  58. package/src/content-fields/flow-handoff.tsx +2 -2
  59. package/src/functions/conditional-country.ts +1 -1
  60. package/src/index.ts +10 -22
  61. package/src/types.ts +0 -1
package/src/index.ts CHANGED
@@ -56,7 +56,6 @@ export default class BotonicPluginFlowBuilder implements Plugin {
56
56
  private functions: Record<any, any>
57
57
  private currentRequest: PluginPreRequest
58
58
  public getAccessToken: (session: Session) => string
59
- public getLocale: (session: Session) => string
60
59
  public trackEvent?: TrackEventFunction
61
60
  public getKnowledgeBaseResponse?: KnowledgeBaseFunction
62
61
  public smartIntentsConfig: SmartIntentsInferenceConfig
@@ -70,12 +69,6 @@ export default class BotonicPluginFlowBuilder implements Plugin {
70
69
  this.apiUrl = options.apiUrl || FLOW_BUILDER_API_URL_PROD
71
70
  this.jsonVersion = options.jsonVersion || FlowBuilderJSONVersion.LATEST
72
71
  this.flow = options.flow
73
- this.getLocale =
74
- typeof options.getLocale === 'function'
75
- ? options.getLocale
76
- : (session: Session) => {
77
- return session.user.system_locale
78
- }
79
72
  this.getAccessToken = resolveGetAccessToken(options.getAccessToken)
80
73
  this.trackEvent = options.trackEvent
81
74
  this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse
@@ -113,8 +106,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
113
106
  inputHasTextData(request.input) && !request.input.payload
114
107
 
115
108
  if (checkUserTextInput) {
116
- const locale = this.getLocale(request.session)
117
- const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
109
+ const resolvedLocale = this.cmsApi.getResolvedLocale()
118
110
  const nodeByUserInput = await getNodeByUserInput(
119
111
  this.cmsApi,
120
112
  resolvedLocale,
@@ -129,7 +121,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
129
121
 
130
122
  private updateRequestBeforeRoutes(request: PluginPreRequest): void {
131
123
  if (request.input.payload) {
132
- request.input.payload = this.removeSourceSufix(request.input.payload)
124
+ request.input.payload = this.removeSourceSuffix(request.input.payload)
133
125
 
134
126
  if (this.cmsApi.isBotAction(request.input.payload)) {
135
127
  const cmsBotAction = this.cmsApi.getNodeById<HtBotActionNode>(
@@ -142,7 +134,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
142
134
  }
143
135
  }
144
136
 
145
- private removeSourceSufix(payload: string): string {
137
+ private removeSourceSuffix(payload: string): string {
146
138
  return payload.split(SOURCE_INFO_SEPARATOR)[0]
147
139
  }
148
140
 
@@ -152,11 +144,10 @@ export default class BotonicPluginFlowBuilder implements Plugin {
152
144
 
153
145
  async getContentsByContentID(
154
146
  contentID: string,
155
- locale: string,
156
147
  prevContents?: FlowContent[]
157
148
  ): Promise<FlowContent[]> {
158
149
  const node = this.cmsApi.getNodeByContentID(contentID) as HtNodeWithContent
159
- return await this.getContentsByNode(node, locale, prevContents)
150
+ return await this.getContentsByNode(node, prevContents)
160
151
  }
161
152
 
162
153
  getUUIDByContentID(contentID: string): string {
@@ -166,31 +157,28 @@ export default class BotonicPluginFlowBuilder implements Plugin {
166
157
 
167
158
  private async getContentsById(
168
159
  id: string,
169
- locale: string,
170
160
  prevContents?: FlowContent[]
171
161
  ): Promise<FlowContent[]> {
172
162
  const node = this.cmsApi.getNodeById(id) as HtNodeWithContent
173
- return await this.getContentsByNode(node, locale, prevContents)
163
+ return await this.getContentsByNode(node, prevContents)
174
164
  }
175
165
 
176
- async getStartContents(locale: string): Promise<FlowContent[]> {
177
- const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
166
+ async getStartContents(): Promise<FlowContent[]> {
178
167
  const startNode = this.cmsApi.getStartNode()
179
168
  this.currentRequest.session.flow_thread_id = uuidv7()
180
- return await this.getContentsByNode(startNode, resolvedLocale)
169
+ return await this.getContentsByNode(startNode)
181
170
  }
182
171
 
183
172
  async getContentsByNode(
184
173
  node: HtNodeWithContent,
185
- locale: string,
186
174
  prevContents?: FlowContent[]
187
175
  ): Promise<FlowContent[]> {
188
176
  const contents = prevContents || []
189
- const resolvedLocale = this.cmsApi.getResolvedLocale(locale)
177
+ const resolvedLocale = this.cmsApi.getResolvedLocale()
190
178
 
191
179
  if (node.type === HtNodeWithContentType.FUNCTION) {
192
180
  const targetId = await this.callFunction(node, resolvedLocale)
193
- return this.getContentsById(targetId, resolvedLocale, contents)
181
+ return this.getContentsById(targetId, contents)
194
182
  }
195
183
 
196
184
  const content = this.getFlowContent(node, resolvedLocale)
@@ -205,7 +193,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
205
193
 
206
194
  // TODO: prevent infinite recursive calls
207
195
  if (node.follow_up) {
208
- return this.getContentsById(node.follow_up.id, resolvedLocale, contents)
196
+ return this.getContentsById(node.follow_up.id, contents)
209
197
  }
210
198
 
211
199
  return contents
package/src/types.ts CHANGED
@@ -21,7 +21,6 @@ export interface BotonicPluginFlowBuilderOptions<
21
21
  jsonVersion?: FlowBuilderJSONVersion
22
22
  flow?: HtFlowBuilderData
23
23
  customFunctions?: Record<any, any>
24
- getLocale?: (session: Session) => string
25
24
  getAccessToken: () => string
26
25
  trackEvent?: TrackEventFunction<TPlugins, TExtraData>
27
26
  getKnowledgeBaseResponse?: KnowledgeBaseFunction<TPlugins, TExtraData>