@inploi/plugin-chatbot 1.0.0 → 1.0.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.
package/.env ADDED
@@ -0,0 +1,3 @@
1
+ VITE_BASE_URL='https://preview.api.inploi.com'
2
+ VITE_PUBLISHABLE_KEY='pk_edce29b92c2773898c482851'
3
+ VITE_MOCKS=true
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @inploi/plugin-chatbot
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e9c1677: (Following 1.0) rewrite exports to new plugin format
8
+ - Updated dependencies [d0f1d33]
9
+ - @inploi/sdk@1.0.1
10
+
3
11
  ## 1.0.0
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@hookform/resolvers": "^3.3.2",
@@ -42,7 +42,7 @@
42
42
  "typescript": "^5.1.6",
43
43
  "vite": "^4.4.5",
44
44
  "vite-tsconfig-paths": "^4.2.1",
45
- "@inploi/sdk": "1.0.0",
45
+ "@inploi/sdk": "1.0.1",
46
46
  "eslint-config-custom": "0.1.0",
47
47
  "tsconfig": "0.1.0"
48
48
  },
@@ -1,9 +1,5 @@
1
1
  import { CHATBOT_ELEMENT_ID } from './chatbot.constants';
2
2
 
3
- function assertElementExists(chatbotElement: HTMLDivElement | null): asserts chatbotElement is HTMLDivElement {
4
- if (!chatbotElement) throw new Error('Chatbot element not found');
5
- }
6
-
7
3
  export const overlayClassNames =
8
4
  'data-[transition=entering]:opacity-0 data-[transition=exiting]:opacity-0 ease-expo-out duration-500 transition-opacity bg-neutral-12/60 fixed inset-0';
9
5
 
package/src/chatbot.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiClient, Logger, createPlugin } from '@inploi/sdk';
1
+ import { createPlugin } from '@inploi/sdk';
2
2
  import { h, render } from 'preact';
3
3
 
4
4
  import { getApplicationData } from './chatbot.api';
@@ -6,72 +6,65 @@ import './chatbot.css';
6
6
  import { ChatbotDomManager, createChatbotDomManager } from './chatbot.dom';
7
7
  import { useChatbotStore, useLocalState } from './chatbot.state';
8
8
 
9
- type CreateChatbotActionsParams = {
10
- apiClient: ApiClient;
11
- dom: ChatbotDomManager;
12
- logger?: Logger;
13
- };
14
- const createChatbotActions = ({ apiClient, dom, logger }: CreateChatbotActionsParams) => {
15
- const { resetLocalState } = useLocalState.getState();
16
- const { startApplication, cancelCurrentApplication } = useChatbotStore.getState();
9
+ export const chatbotPlugin = ({
10
+ _internal_domManager: dom = createChatbotDomManager(),
11
+ geolocationApiKey,
12
+ }: {
13
+ geolocationApiKey?: string;
14
+ _internal_domManager?: ChatbotDomManager;
15
+ }) =>
16
+ createPlugin(({ apiClient, logger }) => {
17
+ const { resetLocalState } = useLocalState.getState();
18
+ const { startApplication, cancelCurrentApplication } = useChatbotStore.getState();
17
19
 
18
- return {
19
- /** Optionally eagerly loads the code to handle applications. */
20
- prepare: async () => {
21
- try {
22
- await import('~/ui/chatbot');
23
- logger?.info('Chatbot plugin prepared');
24
- } catch (error) {
25
- console.error(error);
26
- logger?.error('Error preparing chatbot plugin', error);
27
- }
28
- },
29
- startApplication: async ({ jobId }: { jobId: string }) => {
30
- try {
31
- const chatbotElement = dom.getOrCreateChatbotElement();
32
- cancelCurrentApplication();
20
+ return {
21
+ /** Optionally eagerly loads the code to handle applications. */
22
+ prepare: async () => {
23
+ try {
24
+ await import('~/ui/chatbot');
25
+ logger?.info('Chatbot plugin prepared');
26
+ } catch (error) {
27
+ console.error(error);
28
+ logger?.error('Error preparing chatbot plugin', error);
29
+ }
30
+ },
31
+ startApplication: async ({ jobId }: { jobId: string }) => {
32
+ try {
33
+ const chatbotElement = dom.getOrCreateChatbotElement();
34
+ cancelCurrentApplication();
33
35
 
34
- dom.renderLoading(chatbotElement);
36
+ dom.renderLoading(chatbotElement);
35
37
 
36
- /** We concurrently lazy load the module and data */
37
- const [dataPromise, chatbotPromise] = await Promise.allSettled([
38
- getApplicationData({ jobId, apiClient }),
39
- import('~/ui/chatbot').then(m => m.Chatbot),
40
- ]);
38
+ /** We concurrently lazy load the module and data */
39
+ const [dataPromise, chatbotPromise] = await Promise.allSettled([
40
+ getApplicationData({ jobId, apiClient }),
41
+ import('~/ui/chatbot').then(m => m.Chatbot),
42
+ ]);
41
43
 
42
- if (dataPromise.status === 'rejected') throw dataPromise.reason;
43
- if (chatbotPromise.status === 'rejected') throw chatbotPromise.reason;
44
-
45
- const Chatbot = chatbotPromise.value;
46
- const application = dataPromise.value;
47
- startApplication(application);
48
- logger?.info(`Starting application for job "${application.job.id}" using flow "${application.flow.id}"`);
49
- chatbotElement.innerHTML = '';
44
+ if (dataPromise.status === 'rejected') throw dataPromise.reason;
45
+ if (chatbotPromise.status === 'rejected') throw chatbotPromise.reason;
50
46
 
51
- render(h(Chatbot, { apiClient, logger }), chatbotElement);
52
- } catch (error) {
53
- console.error(error);
54
- logger?.error('Error starting application', error);
55
- }
56
- },
57
- closeApplication: async () => {
58
- const chatbotElement = dom.getOrCreateChatbotElement();
59
- chatbotElement.innerHTML = '';
60
- cancelCurrentApplication();
61
- },
62
- /** Resets the user saved data for every application. */
63
- resetLocalState: async () => {
64
- resetLocalState();
65
- cancelCurrentApplication();
66
- },
67
- };
68
- };
47
+ const Chatbot = chatbotPromise.value;
48
+ const application = dataPromise.value;
49
+ startApplication(application);
50
+ logger?.info(`Starting application for job "${application.job.id}" using flow "${application.flow.id}"`);
51
+ chatbotElement.innerHTML = '';
69
52
 
70
- export const chatbotPlugin = createPlugin('chatbot', {
71
- pure_createActions: ({ apiClient, logger }) =>
72
- createChatbotActions({
73
- apiClient,
74
- dom: createChatbotDomManager(),
75
- logger,
76
- }),
77
- });
53
+ render(h(Chatbot, { apiClient, logger }), chatbotElement);
54
+ } catch (error) {
55
+ console.error(error);
56
+ logger?.error('Error starting application', error);
57
+ }
58
+ },
59
+ closeApplication: async () => {
60
+ const chatbotElement = dom.getOrCreateChatbotElement();
61
+ chatbotElement.innerHTML = '';
62
+ cancelCurrentApplication();
63
+ },
64
+ /** Resets the user saved data for every application. */
65
+ resetLocalState: async () => {
66
+ resetLocalState();
67
+ cancelCurrentApplication();
68
+ },
69
+ };
70
+ });
package/src/index.dev.ts CHANGED
@@ -7,7 +7,7 @@ export { chatbotPlugin } from './chatbot';
7
7
 
8
8
  declare global {
9
9
  interface Window {
10
- chatbot: ReturnType<typeof chatbotPlugin.pure_createActions>;
10
+ chatbot: ReturnType<ReturnType<typeof chatbotPlugin>>;
11
11
  }
12
12
  }
13
13
 
@@ -21,7 +21,7 @@ async function enableMocking() {
21
21
  }
22
22
 
23
23
  enableMocking().then(() => {
24
- window.chatbot = chatbotPlugin.pure_createActions({
24
+ window.chatbot = chatbotPlugin({})({
25
25
  apiClient: createApiClient({
26
26
  baseUrl: import.meta.env.VITE_BASE_URL,
27
27
  publishableKey: import.meta.env.VITE_PUBLISHABLE_KEY,