@inploi/plugin-chatbot 3.27.0 → 3.27.1

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.
@@ -1,4 +1,4 @@
1
- import { g as get$1, i as isString$2, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, N, c as getFlowSubmissionsPayload, _, d as getDefaultExportFromCjs, h, e as _$1, p, F, o as o$1, f as clsx, y, s as store, j as a$2, l as k, m as k$1, n as getFormSubmitter, q as parse, r as picklist, t as isSubmissionOfType, C as Cn, u as parseAsync, V as ValiError, v as object, w as transform, x as cva, z as maxLength, B as minLength, D as record, E as boolean, G as number, H as minValue, I as maxValue, J as custom, K as string, L as regex, M as email, O as url, P as LoadingIndicator, Q as ERROR_MESSAGES } from "./index-dd385762.js";
1
+ import { g as get$1, i as isString$2, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, N, c as getFlowSubmissionsPayload, _, d as getDefaultExportFromCjs, h, e as _$1, p, F, o as o$1, f as clsx, y, s as store, j as a$2, l as k, m as k$1, n as getFormSubmitter, q as parse, r as picklist, t as isSubmissionOfType, C as Cn, u as parseAsync, V as ValiError, v as object, w as transform, x as cva, z as maxLength, B as minLength, D as record, E as boolean, G as number, H as minValue, I as maxValue, J as custom, K as string, L as regex, M as email, O as url, P as LoadingIndicator, Q as ERROR_MESSAGES } from "./index-bf3e6467.js";
2
2
  import "@inploi/sdk";
3
3
  const isIfBlockConditionMet = (ifBlock, {
4
4
  context,
@@ -452,9 +452,11 @@ async function interpretSubmitNode({
452
452
  });
453
453
  N(response).with({
454
454
  integration_response: _.select(_.union({
455
+ service: _.optional(_.string),
455
456
  status: _.number,
456
457
  data: _.any
457
458
  }, {
459
+ service: _.optional(_.string),
458
460
  status: _.number,
459
461
  error: {
460
462
  message: _.string,
@@ -469,6 +471,7 @@ async function interpretSubmitNode({
469
471
  flow_version: flow.version,
470
472
  flow_session_id: flow.data.flowSessionId,
471
473
  flow_build: flow.build,
474
+ service: integrationResponse.service ?? "INVALID_SERVICE",
472
475
  response: {
473
476
  status: integrationResponse.status,
474
477
  payload: "data" in integrationResponse ? integrationResponse.data : integrationResponse.error.data ?? null
@@ -1988,7 +1991,7 @@ const ChatInputBoolean = ({
1988
1991
  const InputError = ({
1989
1992
  error
1990
1993
  }) => {
1991
- if (!error)
1994
+ if (!error || !error.message)
1992
1995
  return null;
1993
1996
  return o$1("div", {
1994
1997
  role: "alert",
@@ -3947,19 +3950,21 @@ const ChatInputNumber = ({
3947
3950
  })]
3948
3951
  });
3949
3952
  };
3950
- const invalidPhoneErrorMessage = "That doesn’t look like a valid phone number";
3951
3953
  const UK_CODE = "44";
3954
+ const invalidPhoneErrorMessage = "That doesn’t look like a valid phone number";
3955
+ const errorMessages = (config) => ({
3956
+ min: `The phone number needs to be at least ${config.minChars} digits long.`,
3957
+ max: `The phone number can't be longer than ${config.maxChars} digits.`
3958
+ });
3959
+ const isTextSubmission$1 = isSubmissionOfType("string");
3952
3960
  const PhoneSchema = string(invalidPhoneErrorMessage, [regex(/^\+?[0-9 -]+$/, invalidPhoneErrorMessage)]);
3953
- const getResolver$1 = (config) => {
3954
- const configErrors = {
3955
- maxLength: `Please enter no more than ${config.maxChars ?? 999} characters`,
3956
- minLength: `Please enter ${config.minChars ?? 1} or more characters`
3957
- };
3961
+ const CountryCodeSchema = string("Please select a country code", [regex(/^\+?[0-9 -]+$/, invalidPhoneErrorMessage)]);
3962
+ const getResolver$1 = () => {
3958
3963
  return i(object({
3959
- text: transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), [minLength(config.minChars ?? 1, configErrors.minLength), maxLength(config.maxChars ?? Infinity, configErrors.maxLength)])
3964
+ text: transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), []),
3965
+ countryCode: CountryCodeSchema
3960
3966
  }));
3961
3967
  };
3962
- const isTextSubmission$1 = isSubmissionOfType("string");
3963
3968
  const ChatInputPhoneNumber = ({
3964
3969
  input,
3965
3970
  onSubmitSuccess
@@ -3967,17 +3972,20 @@ const ChatInputPhoneNumber = ({
3967
3972
  var _a;
3968
3973
  const submission = input.key ? (_a = store.current$.value.flow) == null ? void 0 : _a.data.submissions[input.key] : void 0;
3969
3974
  const defaultValue = input.config.defaultValue;
3975
+ const [error, setError] = h();
3970
3976
  const {
3971
3977
  register,
3972
3978
  handleSubmit,
3973
3979
  formState: {
3974
3980
  errors: errors2
3975
- }
3981
+ },
3982
+ watch
3976
3983
  } = useForm({
3977
3984
  defaultValues: {
3978
- text: defaultValue ? defaultValue : isTextSubmission$1(submission) ? submission.value : ""
3985
+ text: defaultValue ? defaultValue : isTextSubmission$1(submission) ? submission.value : "",
3986
+ countryCode: UK_CODE
3979
3987
  },
3980
- resolver: getResolver$1(input.config)
3988
+ resolver: getResolver$1()
3981
3989
  });
3982
3990
  const {
3983
3991
  ref: setRef,
@@ -3985,10 +3993,8 @@ const ChatInputPhoneNumber = ({
3985
3993
  } = register("text", {
3986
3994
  required: !input.config.optional
3987
3995
  });
3988
- const defaultCode = UK_CODE;
3989
- const [countryCode, setCountryCode] = h(defaultCode);
3990
3996
  const inputRef = _$1();
3991
- const selectRef = _$1(null);
3997
+ const countryCodeValue = watch("countryCode");
3992
3998
  y(() => {
3993
3999
  if (inputRef.current) {
3994
4000
  inputRef.current.focus();
@@ -3999,9 +4005,14 @@ const ChatInputPhoneNumber = ({
3999
4005
  noValidate: true,
4000
4006
  class: "flex flex-col gap-1 p-2.5",
4001
4007
  onSubmit: handleSubmit((submission2) => {
4008
+ setError(void 0);
4009
+ if (submission2.text.length + submission2.countryCode.length > (input.config.maxChars || Infinity))
4010
+ return setError(errorMessages(input.config).max);
4011
+ if (submission2.text.length + submission2.countryCode.length < (input.config.minChars || 0))
4012
+ return setError(errorMessages(input.config).min);
4002
4013
  onSubmitSuccess({
4003
4014
  type: "string",
4004
- value: countryCode + submission2.text
4015
+ value: countryCodeValue + submission2.text
4005
4016
  });
4006
4017
  }),
4007
4018
  children: [o$1("div", {
@@ -4012,22 +4023,15 @@ const ChatInputPhoneNumber = ({
4012
4023
  class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus-within:bg-neutral-5 focus-within:outline-accent-7 relative flex h-full w-12 appearance-none items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-lg border-solid bg-transparent bg-none py-1.5 text-center text-base transition-colors focus-within:outline-none",
4013
4024
  htmlFor: `isdk_phone_${input.key}`,
4014
4025
  children: [o$1("span", {
4015
- children: ["+", countryCode]
4026
+ children: ["+", countryCodeValue]
4016
4027
  }), o$1("select", {
4017
- ref: selectRef,
4018
- onChange: (e) => {
4019
- var _a2;
4020
- const selectedCode = (_a2 = e.currentTarget.selectedOptions[0]) == null ? void 0 : _a2.value;
4021
- setCountryCode(selectedCode);
4022
- },
4023
- required: true,
4024
- defaultValue: defaultCode,
4028
+ ...register("countryCode", {}),
4025
4029
  id: `isdk_phone_${input.key}`,
4026
4030
  class: "absolute inset-0 opacity-0",
4027
- children: Object.entries(countries).map(([countryName, countryCode2]) => o$1("option", {
4028
- value: countryCode2,
4029
- children: [countryName, " (+", countryCode2, ")"]
4030
- }, countryName))
4031
+ children: Object.entries(countries).map(([name, code]) => o$1("option", {
4032
+ value: code,
4033
+ children: [name, " (+", code, ")"]
4034
+ }, name))
4031
4035
  })]
4032
4036
  }), o$1("input", {
4033
4037
  ...props,
@@ -4052,7 +4056,9 @@ const ChatInputPhoneNumber = ({
4052
4056
  })]
4053
4057
  }), o$1(SendButton, {})]
4054
4058
  }), o$1(InputError, {
4055
- error: errors2.text
4059
+ error: errors2.text || errors2.countryCode || {
4060
+ message: error
4061
+ }
4056
4062
  })]
4057
4063
  });
4058
4064
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-0dd235bd.cjs");
3
+ const index = require("./index-9b3fc23b.cjs");
4
4
  require("@inploi/sdk");
5
5
  const isIfBlockConditionMet = (ifBlock, {
6
6
  context,
@@ -454,9 +454,11 @@ async function interpretSubmitNode({
454
454
  });
455
455
  index.N(response).with({
456
456
  integration_response: index._.select(index._.union({
457
+ service: index._.optional(index._.string),
457
458
  status: index._.number,
458
459
  data: index._.any
459
460
  }, {
461
+ service: index._.optional(index._.string),
460
462
  status: index._.number,
461
463
  error: {
462
464
  message: index._.string,
@@ -471,6 +473,7 @@ async function interpretSubmitNode({
471
473
  flow_version: flow.version,
472
474
  flow_session_id: flow.data.flowSessionId,
473
475
  flow_build: flow.build,
476
+ service: integrationResponse.service ?? "INVALID_SERVICE",
474
477
  response: {
475
478
  status: integrationResponse.status,
476
479
  payload: "data" in integrationResponse ? integrationResponse.data : integrationResponse.error.data ?? null
@@ -1990,7 +1993,7 @@ const ChatInputBoolean = ({
1990
1993
  const InputError = ({
1991
1994
  error
1992
1995
  }) => {
1993
- if (!error)
1996
+ if (!error || !error.message)
1994
1997
  return null;
1995
1998
  return index.o("div", {
1996
1999
  role: "alert",
@@ -3949,19 +3952,21 @@ const ChatInputNumber = ({
3949
3952
  })]
3950
3953
  });
3951
3954
  };
3952
- const invalidPhoneErrorMessage = "That doesn’t look like a valid phone number";
3953
3955
  const UK_CODE = "44";
3956
+ const invalidPhoneErrorMessage = "That doesn’t look like a valid phone number";
3957
+ const errorMessages = (config) => ({
3958
+ min: `The phone number needs to be at least ${config.minChars} digits long.`,
3959
+ max: `The phone number can't be longer than ${config.maxChars} digits.`
3960
+ });
3961
+ const isTextSubmission$1 = index.isSubmissionOfType("string");
3954
3962
  const PhoneSchema = index.string(invalidPhoneErrorMessage, [index.regex(/^\+?[0-9 -]+$/, invalidPhoneErrorMessage)]);
3955
- const getResolver$1 = (config) => {
3956
- const configErrors = {
3957
- maxLength: `Please enter no more than ${config.maxChars ?? 999} characters`,
3958
- minLength: `Please enter ${config.minChars ?? 1} or more characters`
3959
- };
3963
+ const CountryCodeSchema = index.string("Please select a country code", [index.regex(/^\+?[0-9 -]+$/, invalidPhoneErrorMessage)]);
3964
+ const getResolver$1 = () => {
3960
3965
  return i(index.object({
3961
- text: index.transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), [index.minLength(config.minChars ?? 1, configErrors.minLength), index.maxLength(config.maxChars ?? Infinity, configErrors.maxLength)])
3966
+ text: index.transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), []),
3967
+ countryCode: CountryCodeSchema
3962
3968
  }));
3963
3969
  };
3964
- const isTextSubmission$1 = index.isSubmissionOfType("string");
3965
3970
  const ChatInputPhoneNumber = ({
3966
3971
  input,
3967
3972
  onSubmitSuccess
@@ -3969,17 +3974,20 @@ const ChatInputPhoneNumber = ({
3969
3974
  var _a;
3970
3975
  const submission = input.key ? (_a = index.store.current$.value.flow) == null ? void 0 : _a.data.submissions[input.key] : void 0;
3971
3976
  const defaultValue = input.config.defaultValue;
3977
+ const [error, setError] = index.h();
3972
3978
  const {
3973
3979
  register,
3974
3980
  handleSubmit,
3975
3981
  formState: {
3976
3982
  errors: errors2
3977
- }
3983
+ },
3984
+ watch
3978
3985
  } = useForm({
3979
3986
  defaultValues: {
3980
- text: defaultValue ? defaultValue : isTextSubmission$1(submission) ? submission.value : ""
3987
+ text: defaultValue ? defaultValue : isTextSubmission$1(submission) ? submission.value : "",
3988
+ countryCode: UK_CODE
3981
3989
  },
3982
- resolver: getResolver$1(input.config)
3990
+ resolver: getResolver$1()
3983
3991
  });
3984
3992
  const {
3985
3993
  ref: setRef,
@@ -3987,10 +3995,8 @@ const ChatInputPhoneNumber = ({
3987
3995
  } = register("text", {
3988
3996
  required: !input.config.optional
3989
3997
  });
3990
- const defaultCode = UK_CODE;
3991
- const [countryCode, setCountryCode] = index.h(defaultCode);
3992
3998
  const inputRef = index._$1();
3993
- const selectRef = index._$1(null);
3999
+ const countryCodeValue = watch("countryCode");
3994
4000
  index.y(() => {
3995
4001
  if (inputRef.current) {
3996
4002
  inputRef.current.focus();
@@ -4001,9 +4007,14 @@ const ChatInputPhoneNumber = ({
4001
4007
  noValidate: true,
4002
4008
  class: "flex flex-col gap-1 p-2.5",
4003
4009
  onSubmit: handleSubmit((submission2) => {
4010
+ setError(void 0);
4011
+ if (submission2.text.length + submission2.countryCode.length > (input.config.maxChars || Infinity))
4012
+ return setError(errorMessages(input.config).max);
4013
+ if (submission2.text.length + submission2.countryCode.length < (input.config.minChars || 0))
4014
+ return setError(errorMessages(input.config).min);
4004
4015
  onSubmitSuccess({
4005
4016
  type: "string",
4006
- value: countryCode + submission2.text
4017
+ value: countryCodeValue + submission2.text
4007
4018
  });
4008
4019
  }),
4009
4020
  children: [index.o("div", {
@@ -4014,22 +4025,15 @@ const ChatInputPhoneNumber = ({
4014
4025
  class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus-within:bg-neutral-5 focus-within:outline-accent-7 relative flex h-full w-12 appearance-none items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-lg border-solid bg-transparent bg-none py-1.5 text-center text-base transition-colors focus-within:outline-none",
4015
4026
  htmlFor: `isdk_phone_${input.key}`,
4016
4027
  children: [index.o("span", {
4017
- children: ["+", countryCode]
4028
+ children: ["+", countryCodeValue]
4018
4029
  }), index.o("select", {
4019
- ref: selectRef,
4020
- onChange: (e) => {
4021
- var _a2;
4022
- const selectedCode = (_a2 = e.currentTarget.selectedOptions[0]) == null ? void 0 : _a2.value;
4023
- setCountryCode(selectedCode);
4024
- },
4025
- required: true,
4026
- defaultValue: defaultCode,
4030
+ ...register("countryCode", {}),
4027
4031
  id: `isdk_phone_${input.key}`,
4028
4032
  class: "absolute inset-0 opacity-0",
4029
- children: Object.entries(countries).map(([countryName, countryCode2]) => index.o("option", {
4030
- value: countryCode2,
4031
- children: [countryName, " (+", countryCode2, ")"]
4032
- }, countryName))
4033
+ children: Object.entries(countries).map(([name, code]) => index.o("option", {
4034
+ value: code,
4035
+ children: [name, " (+", code, ")"]
4036
+ }, name))
4033
4037
  })]
4034
4038
  }), index.o("input", {
4035
4039
  ...props,
@@ -4054,7 +4058,9 @@ const ChatInputPhoneNumber = ({
4054
4058
  })]
4055
4059
  }), index.o(SendButton, {})]
4056
4060
  }), index.o(InputError, {
4057
- error: errors2.text
4061
+ error: errors2.text || errors2.countryCode || {
4062
+ message: error
4063
+ }
4058
4064
  })]
4059
4065
  });
4060
4066
  };
package/dist/chatbot.d.ts CHANGED
@@ -40,7 +40,6 @@ export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
40
40
  /** @deprecated For internal usage only */
41
41
  _internal_domManager?: ChatbotDomManager;
42
42
  }) => ({ apiClient, logger, analytics }: {
43
- /** Optionally eagerly renders the interface ahead of needing the chatbot. */
44
43
  apiClient: import("@inploi/sdk").ApiClient;
45
44
  logger: Logger;
46
45
  analytics: import("@inploi/sdk").AnalyticsService;
@@ -5315,7 +5315,7 @@ const StatusBar = ({
5315
5315
  })
5316
5316
  });
5317
5317
  };
5318
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-ab0ea636.cjs")).then((module2) => module2.ChatbotBody));
5318
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-835049a8.cjs")).then((module2) => module2.ChatbotBody));
5319
5319
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none", {
5320
5320
  variants: {
5321
5321
  view: {
@@ -5314,7 +5314,7 @@ const StatusBar = ({
5314
5314
  })
5315
5315
  });
5316
5316
  };
5317
- const ChatbotBody = M(() => import("./chatbot-body-56129012.js").then((module) => module.ChatbotBody));
5317
+ const ChatbotBody = M(() => import("./chatbot-body-3fff1051.js").then((module) => module.ChatbotBody));
5318
5318
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none", {
5319
5319
  variants: {
5320
5320
  view: {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-0dd235bd.cjs");
3
+ const index = require("./index-9b3fc23b.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,4 +1,4 @@
1
- import { R } from "./index-dd385762.js";
1
+ import { R } from "./index-bf3e6467.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
4
  R as chatbotPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "3.27.0",
3
+ "version": "3.27.1",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",
@@ -69,8 +69,8 @@
69
69
  "vite-tsconfig-paths": "^4.2.1",
70
70
  "@inploi/core": "1.14.3",
71
71
  "@inploi/design-tokens": "0.2.1",
72
- "@inploi/sdk": "1.14.4",
73
72
  "eslint-config-custom": "0.1.0",
73
+ "@inploi/sdk": "1.14.4",
74
74
  "tsconfig": "0.1.0"
75
75
  },
76
76
  "msw": {