@botonic/plugin-flow-builder 0.26.1 → 0.27.0-alpha.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.
- package/lib/cjs/action/index.js +39 -19
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +14 -4
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +4 -6
- package/lib/cjs/api.js +7 -33
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-button.d.ts +0 -1
- package/lib/cjs/content-fields/flow-button.js +0 -10
- package/lib/cjs/content-fields/flow-button.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +7 -19
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/button.d.ts +1 -2
- package/lib/cjs/content-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +7 -1
- package/lib/cjs/functions/conditional-queue-status.js +34 -12
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/index.d.ts +7 -1
- package/lib/cjs/index.js +29 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tracking.d.ts +18 -14
- package/lib/cjs/tracking.js +27 -20
- package/lib/cjs/tracking.js.map +1 -1
- package/lib/cjs/types.d.ts +14 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/index.d.ts +2 -1
- package/lib/cjs/user-input/index.js +9 -3
- package/lib/cjs/user-input/index.js.map +1 -1
- package/lib/cjs/user-input/intent.js +12 -8
- package/lib/cjs/user-input/intent.js.map +1 -1
- package/lib/cjs/user-input/keyword.d.ts +21 -1
- package/lib/cjs/user-input/keyword.js +68 -13
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.d.ts +18 -1
- package/lib/cjs/user-input/smart-intent.js +46 -29
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/esm/action/index.js +39 -19
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +15 -5
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +4 -6
- package/lib/esm/api.js +8 -34
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-button.d.ts +0 -1
- package/lib/esm/content-fields/flow-button.js +0 -10
- package/lib/esm/content-fields/flow-button.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +7 -19
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/button.d.ts +1 -2
- package/lib/esm/content-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/index.js +1 -0
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +7 -1
- package/lib/esm/functions/conditional-queue-status.js +32 -11
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/index.d.ts +7 -1
- package/lib/esm/index.js +30 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/tracking.d.ts +18 -14
- package/lib/esm/tracking.js +25 -19
- package/lib/esm/tracking.js.map +1 -1
- package/lib/esm/types.d.ts +14 -1
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/index.d.ts +2 -1
- package/lib/esm/user-input/index.js +11 -5
- package/lib/esm/user-input/index.js.map +1 -1
- package/lib/esm/user-input/intent.js +13 -9
- package/lib/esm/user-input/intent.js.map +1 -1
- package/lib/esm/user-input/keyword.d.ts +21 -1
- package/lib/esm/user-input/keyword.js +67 -12
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.d.ts +18 -1
- package/lib/esm/user-input/smart-intent.js +44 -27
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/package.json +3 -3
- package/src/action/index.tsx +58 -24
- package/src/action/knowledge-bases.ts +16 -5
- package/src/api.ts +12 -55
- package/src/constants.ts +1 -0
- package/src/content-fields/flow-button.tsx +0 -10
- package/src/content-fields/flow-handoff.tsx +8 -28
- package/src/content-fields/hubtype-fields/button.ts +1 -7
- package/src/content-fields/index.ts +1 -0
- package/src/functions/conditional-queue-status.ts +36 -13
- package/src/index.ts +48 -7
- package/src/tracking.ts +25 -14
- package/src/types.ts +13 -1
- package/src/user-input/index.ts +13 -7
- package/src/user-input/intent.ts +17 -10
- package/src/user-input/keyword.ts +93 -14
- package/src/user-input/smart-intent.ts +57 -30
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
2
3
|
import { FlowBuilderApi } from './api';
|
|
3
|
-
import { FLOW_BUILDER_API_URL_PROD, SEPARATOR, SOURCE_INFO_SEPARATOR, } from './constants';
|
|
4
|
+
import { BOT_ACTION_PAYLOAD_PREFIX, FLOW_BUILDER_API_URL_PROD, SEPARATOR, SOURCE_INFO_SEPARATOR, } from './constants';
|
|
4
5
|
import { FlowCarousel, FlowHandoff, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList, } from './content-fields';
|
|
5
6
|
import { FlowWhatsappCtaUrlButtonNode } from './content-fields/flow-whatsapp-cta-url-button';
|
|
6
7
|
import { HtNodeWithContentType, } from './content-fields/hubtype-fields';
|
|
7
8
|
import { DEFAULT_FUNCTIONS } from './functions';
|
|
9
|
+
import { EventAction, getNodeEventArgs, trackEvent } from './tracking';
|
|
8
10
|
import { FlowBuilderJSONVersion, } from './types';
|
|
9
11
|
import { getNodeByUserInput } from './user-input';
|
|
10
12
|
import { resolveGetAccessToken } from './utils';
|
|
@@ -19,11 +21,11 @@ export default class BotonicPluginFlowBuilder {
|
|
|
19
21
|
this.getAccessToken = resolveGetAccessToken(options);
|
|
20
22
|
this.trackEvent = options.trackEvent;
|
|
21
23
|
this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse;
|
|
24
|
+
this.smartIntentsConfig = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.smartIntentsConfig), { useLatest: jsonVersion === FlowBuilderJSONVersion.LATEST });
|
|
22
25
|
const customFunctions = options.customFunctions || {};
|
|
23
26
|
this.functions = Object.assign(Object.assign({}, DEFAULT_FUNCTIONS), customFunctions);
|
|
24
27
|
}
|
|
25
28
|
pre(request) {
|
|
26
|
-
var _a;
|
|
27
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
30
|
this.currentRequest = request;
|
|
29
31
|
this.cmsApi = yield FlowBuilderApi.create({
|
|
@@ -38,14 +40,28 @@ export default class BotonicPluginFlowBuilder {
|
|
|
38
40
|
if (checkUserTextInput) {
|
|
39
41
|
const locale = this.getLocale(request.session);
|
|
40
42
|
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
41
|
-
const nodeByUserInput = yield getNodeByUserInput(this.cmsApi, resolvedLocale, request);
|
|
43
|
+
const nodeByUserInput = yield getNodeByUserInput(this.cmsApi, resolvedLocale, request, this.smartIntentsConfig);
|
|
42
44
|
request.input.payload = this.cmsApi.getPayload(nodeByUserInput === null || nodeByUserInput === void 0 ? void 0 : nodeByUserInput.target);
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
request.input.payload = (_a = request.input.payload) === null || _a === void 0 ? void 0 : _a.split(SOURCE_INFO_SEPARATOR)[0];
|
|
46
|
-
}
|
|
46
|
+
this.updateRequestBeforeRoutes(request);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
updateRequestBeforeRoutes(request) {
|
|
50
|
+
if (request.input.payload) {
|
|
51
|
+
request.input.payload = this.removeSourceSufix(request.input.payload);
|
|
52
|
+
if (request.input.payload.startsWith(BOT_ACTION_PAYLOAD_PREFIX)) {
|
|
53
|
+
request.input.payload = this.replacePayload(request.input.payload);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
removeSourceSufix(payload) {
|
|
58
|
+
return payload.split(SOURCE_INFO_SEPARATOR)[0];
|
|
59
|
+
}
|
|
60
|
+
replacePayload(payload) {
|
|
61
|
+
const botActionId = payload.split(SEPARATOR)[1];
|
|
62
|
+
const botActionNode = this.cmsApi.getNodeById(botActionId);
|
|
63
|
+
return this.cmsApi.createPayloadWithParams(botActionNode);
|
|
64
|
+
}
|
|
49
65
|
getContentsByContentID(contentID, locale, prevContents) {
|
|
50
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
67
|
const node = this.cmsApi.getNodeByContentID(contentID);
|
|
@@ -64,8 +80,12 @@ export default class BotonicPluginFlowBuilder {
|
|
|
64
80
|
}
|
|
65
81
|
getStartContents(locale) {
|
|
66
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
67
84
|
const startNode = this.cmsApi.getStartNode();
|
|
68
|
-
|
|
85
|
+
this.currentRequest.session.flow_thread_id = uuid();
|
|
86
|
+
const eventArgs = getNodeEventArgs(this.currentRequest, startNode);
|
|
87
|
+
yield trackEvent(this.currentRequest, EventAction.flowNode, eventArgs);
|
|
88
|
+
return yield this.getContentsByNode(startNode, resolvedLocale);
|
|
69
89
|
});
|
|
70
90
|
}
|
|
71
91
|
getContentsByNode(node, locale, prevContents) {
|
|
@@ -143,6 +163,9 @@ export default class BotonicPluginFlowBuilder {
|
|
|
143
163
|
const payloadParams = JSON.parse(payload.split(SEPARATOR)[1] || '{}');
|
|
144
164
|
return payloadParams;
|
|
145
165
|
}
|
|
166
|
+
getFlowName(flowId) {
|
|
167
|
+
return this.cmsApi.getFlowName(flowId);
|
|
168
|
+
}
|
|
146
169
|
}
|
|
147
170
|
export * from './action';
|
|
148
171
|
export * from './content-fields';
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,SAAS,EACT,qBAAqB,GACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,sBAAsB,GACvB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAA;AAC5F,OAAO,EAQL,qBAAqB,GACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACtE,OAAO,EAEL,sBAAsB,GAGvB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC/C,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAkB3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,yBAAyB,CAAA;QAC1D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,sBAAsB,CAAC,MAAM,CAAA;QACxE,IAAI,CAAC,OAAO,GAAG,GAAG,MAAM,SAAS,WAAW,EAAE,CAAA;QAC9C,IAAI,CAAC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
|
|
14
|
-
fallback = "fallback",
|
|
2
|
+
import { HtNodeWithContent } from './content-fields/hubtype-fields';
|
|
3
|
+
export declare function trackEvent(request: ActionRequest, eventAction: EventAction, args?: Record<string, any>): Promise<void>;
|
|
4
|
+
export declare function getNodeEventArgs(request: ActionRequest, node: HtNodeWithContent): {
|
|
5
|
+
flowThreadId: string | undefined;
|
|
6
|
+
flowId: string;
|
|
7
|
+
flowName: string;
|
|
8
|
+
flowNodeId: string;
|
|
9
|
+
flowNodeContentId: string;
|
|
10
|
+
flowNodeIsMeaningful: undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare enum EventAction {
|
|
13
|
+
flowNode = "flow_node",
|
|
15
14
|
handoffOption = "handoff_option",
|
|
16
15
|
handoffSuccess = "handoff_success",
|
|
17
|
-
handoffFail = "handoff_fail"
|
|
16
|
+
handoffFail = "handoff_fail",
|
|
17
|
+
keyword = "nlu_keyword",
|
|
18
|
+
intent = "nlu_intent",
|
|
19
|
+
intentSmart = "nlu_intent_smart",
|
|
20
|
+
knowledgebase = "knowledgebase",
|
|
21
|
+
fallback = "fallback"
|
|
18
22
|
}
|
package/lib/esm/tracking.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getFlowBuilderPlugin } from './helpers';
|
|
3
|
-
export function trackEvent(request,
|
|
3
|
+
export function trackEvent(request, eventAction, args) {
|
|
4
4
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
5
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
6
6
|
if (flowBuilderPlugin.trackEvent) {
|
|
7
|
-
yield flowBuilderPlugin.trackEvent(request,
|
|
7
|
+
yield flowBuilderPlugin.trackEvent(request, eventAction, args);
|
|
8
8
|
}
|
|
9
9
|
return;
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
export function getNodeEventArgs(request, node) {
|
|
13
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
14
|
+
return {
|
|
15
|
+
flowThreadId: request.session.flow_thread_id,
|
|
16
|
+
flowId: node.flow_id,
|
|
17
|
+
flowName: flowBuilderPlugin.getFlowName(node.flow_id),
|
|
18
|
+
flowNodeId: node.id,
|
|
19
|
+
flowNodeContentId: node.code,
|
|
20
|
+
flowNodeIsMeaningful: undefined, //node?.isMeaningful,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export var EventAction;
|
|
24
|
+
(function (EventAction) {
|
|
25
|
+
EventAction["flowNode"] = "flow_node";
|
|
26
|
+
EventAction["handoffOption"] = "handoff_option";
|
|
27
|
+
EventAction["handoffSuccess"] = "handoff_success";
|
|
28
|
+
EventAction["handoffFail"] = "handoff_fail";
|
|
29
|
+
EventAction["keyword"] = "nlu_keyword";
|
|
30
|
+
EventAction["intent"] = "nlu_intent";
|
|
31
|
+
EventAction["intentSmart"] = "nlu_intent_smart";
|
|
32
|
+
EventAction["knowledgebase"] = "knowledgebase";
|
|
33
|
+
EventAction["fallback"] = "fallback";
|
|
34
|
+
})(EventAction || (EventAction = {}));
|
|
29
35
|
//# sourceMappingURL=tracking.js.map
|
package/lib/esm/tracking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../src/tracking.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,UAAgB,UAAU,CAC9B,OAAsB,EACtB,WAAwB,EACxB,IAA0B;;QAE1B,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC/D,IAAI,iBAAiB,CAAC,UAAU,EAAE;YAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;SAC/D;QACD,OAAM;IACR,CAAC;CAAA;AAED,MAAM,UAAU,gBAAgB,CAC9B,OAAsB,EACtB,IAAuB;IAEvB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,OAAO;QACL,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc;QAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;QACpB,QAAQ,EAAE,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QACrD,UAAU,EAAE,IAAI,CAAC,EAAE;QACnB,iBAAiB,EAAE,IAAI,CAAC,IAAI;QAC5B,oBAAoB,EAAE,SAAS,EAAE,qBAAqB;KACvD,CAAA;AACH,CAAC;AAED,MAAM,CAAN,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,qCAAsB,CAAA;IACtB,+CAAgC,CAAA;IAChC,iDAAkC,CAAA;IAClC,2CAA4B,CAAA;IAC5B,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,+CAAgC,CAAA;IAChC,8CAA+B,CAAA;IAC/B,oCAAqB,CAAA;AACvB,CAAC,EAVW,WAAW,KAAX,WAAW,QAUtB"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -8,8 +8,11 @@ export interface BotonicPluginFlowBuilderOptions {
|
|
|
8
8
|
customFunctions?: Record<any, any>;
|
|
9
9
|
getLocale: (session: Session) => string;
|
|
10
10
|
getAccessToken: () => string;
|
|
11
|
-
trackEvent?: (request: ActionRequest,
|
|
11
|
+
trackEvent?: (request: ActionRequest, eventAction: string, args?: Record<string, any>) => Promise<void>;
|
|
12
12
|
getKnowledgeBaseResponse?: (request: ActionRequest) => Promise<KnowledgeBaseResponse>;
|
|
13
|
+
smartIntentsConfig?: {
|
|
14
|
+
numSmartIntentsToUse: number;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
export interface FlowBuilderApiOptions {
|
|
15
18
|
url: string;
|
|
@@ -33,6 +36,16 @@ export interface KnowledgeBaseResponse {
|
|
|
33
36
|
page?: number;
|
|
34
37
|
}[];
|
|
35
38
|
}
|
|
39
|
+
export interface SmartIntentResponse {
|
|
40
|
+
data: {
|
|
41
|
+
smart_intent_title: string;
|
|
42
|
+
text: string;
|
|
43
|
+
smart_intents_used: {
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
}
|
|
36
49
|
export interface PayloadParamsBase {
|
|
37
50
|
followUpContentID?: string;
|
|
38
51
|
}
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,CAAN,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,QAGjC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtIntentNode, HtKeywordNode, HtSmartIntentNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
import { SmartIntentsInferenceConfig } from './smart-intent';
|
|
5
|
+
export declare function getNodeByUserInput(cmsApi: FlowBuilderApi, locale: string, request: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig): Promise<HtSmartIntentNode | HtIntentNode | HtKeywordNode | undefined>;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getIntentNodeByInput } from './intent';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export function getNodeByUserInput(cmsApi, locale, request) {
|
|
3
|
+
import { KeywordMatcher } from './keyword';
|
|
4
|
+
import { SmartIntentsApi } from './smart-intent';
|
|
5
|
+
export function getNodeByUserInput(cmsApi, locale, request, smartIntentsConfig) {
|
|
6
6
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7
7
|
if (request.input.data) {
|
|
8
|
-
const
|
|
8
|
+
const keywordMatcher = new KeywordMatcher({
|
|
9
|
+
cmsApi,
|
|
10
|
+
locale,
|
|
11
|
+
request,
|
|
12
|
+
});
|
|
13
|
+
const keywordNode = yield keywordMatcher.getNodeByInput(request.input.data);
|
|
9
14
|
if (keywordNode)
|
|
10
15
|
return keywordNode;
|
|
11
|
-
const
|
|
16
|
+
const smartIntentsApi = new SmartIntentsApi(cmsApi, request, smartIntentsConfig);
|
|
17
|
+
const smartIntentNode = smartIntentsApi.getNodeByInput();
|
|
12
18
|
if (smartIntentNode)
|
|
13
19
|
return smartIntentNode;
|
|
14
20
|
const intentNode = yield getIntentNodeByInput(cmsApi, locale, request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-input/index.ts"],"names":[],"mappings":";AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-input/index.ts"],"names":[],"mappings":";AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,eAAe,EAA+B,MAAM,gBAAgB,CAAA;AAE7E,MAAM,UAAgB,kBAAkB,CACtC,MAAsB,EACtB,MAAc,EACd,OAAsB,EACtB,kBAA+C;;QAE/C,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC;gBACxC,MAAM;gBACN,MAAM;gBACN,OAAO;aACR,CAAC,CAAA;YACF,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAC3E,IAAI,WAAW;gBAAE,OAAO,WAAW,CAAA;YAEnC,MAAM,eAAe,GAAG,IAAI,eAAe,CACzC,MAAM,EACN,OAAO,EACP,kBAAkB,CACnB,CAAA;YACD,MAAM,eAAe,GAAG,eAAe,CAAC,cAAc,EAAE,CAAA;YACxD,IAAI,eAAe;gBAAE,OAAO,eAAe,CAAA;YAE3C,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;YACtE,IAAI,UAAU;gBAAE,OAAO,UAAU,CAAA;SAClC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { EventAction, trackEvent } from '../tracking';
|
|
3
3
|
export function getIntentNodeByInput(cmsApi, locale, request) {
|
|
4
4
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
5
|
const intentNode = cmsApi.getIntentNode(request.input, locale);
|
|
6
|
-
const eventArgs = {
|
|
7
|
-
intent: request.input.intent,
|
|
8
|
-
confidence: request.input.confidence,
|
|
9
|
-
confidence_successful: true,
|
|
10
|
-
};
|
|
11
6
|
if (request.input.confidence && request.input.intent && intentNode) {
|
|
7
|
+
yield trackIntentEvent(request, intentNode);
|
|
12
8
|
if (isIntentValid(intentNode, request, cmsApi)) {
|
|
13
|
-
yield trackEvent(request, EventName.botAiModel, eventArgs);
|
|
14
9
|
return intentNode;
|
|
15
10
|
}
|
|
16
|
-
eventArgs.confidence_successful = false;
|
|
17
|
-
yield trackEvent(request, EventName.botAiModel, eventArgs);
|
|
18
11
|
}
|
|
19
12
|
return undefined;
|
|
20
13
|
});
|
|
21
14
|
}
|
|
15
|
+
function trackIntentEvent(request, intentNode) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const eventArgs = {
|
|
18
|
+
nluIntentLabel: request.input.intent,
|
|
19
|
+
nluIntentConfidence: request.input.confidence,
|
|
20
|
+
nluIntentThreshold: intentNode === null || intentNode === void 0 ? void 0 : intentNode.content.confidence,
|
|
21
|
+
nluIntentMessageId: request.input.message_id,
|
|
22
|
+
};
|
|
23
|
+
yield trackEvent(request, EventAction.intent, eventArgs);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
22
26
|
function isIntentValid(intentNode, request, cmsApi) {
|
|
23
27
|
return (request.input.confidence &&
|
|
24
28
|
cmsApi.hasMetConfidenceThreshold(intentNode, request.input.confidence));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/user-input/intent.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,UAAgB,oBAAoB,CACxC,MAAsB,EACtB,MAAc,EACd,OAAsB;;QAEtB,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAE9D,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,UAAU,EAAE;YAClE,MAAM,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;YAE3C,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC9C,OAAO,UAAU,CAAA;aAClB;SACF;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CAAA;AAED,SAAe,gBAAgB,CAC7B,OAAsB,EACtB,UAAwB;;QAExB,MAAM,SAAS,GAAG;YAChB,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;YACpC,mBAAmB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;YAC7C,kBAAkB,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAC,UAAU;YAClD,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;SAC7C,CAAA;QACD,MAAM,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC1D,CAAC;CAAA;AAED,SAAS,aAAa,CACpB,UAAwB,EACxB,OAAsB,EACtB,MAAsB;IAEtB,OAAO,CACL,OAAO,CAAC,KAAK,CAAC,UAAU;QACxB,MAAM,CAAC,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CACvE,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtKeywordNode } from '../content-fields/hubtype-fields';
|
|
4
|
-
|
|
4
|
+
interface KeywordProps {
|
|
5
|
+
cmsApi: FlowBuilderApi;
|
|
6
|
+
locale: string;
|
|
7
|
+
request: ActionRequest;
|
|
8
|
+
}
|
|
9
|
+
export declare class KeywordMatcher {
|
|
10
|
+
cmsApi: FlowBuilderApi;
|
|
11
|
+
locale: string;
|
|
12
|
+
request: ActionRequest;
|
|
13
|
+
isRegExp: boolean;
|
|
14
|
+
matchedKeyword?: string;
|
|
15
|
+
keywordNodeId?: string;
|
|
16
|
+
constructor({ cmsApi, locale, request }: KeywordProps);
|
|
17
|
+
getNodeByInput(userInput: string): Promise<HtKeywordNode | undefined>;
|
|
18
|
+
private getNodeByKeyword;
|
|
19
|
+
private matchKeywords;
|
|
20
|
+
private inputMatchesAnyKeyword;
|
|
21
|
+
private resolveKeywordAsRegExp;
|
|
22
|
+
private trackKeywordEvent;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,16 +1,71 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { REG_EXP_PATTERN } from '../constants';
|
|
3
|
+
import { EventAction, trackEvent } from '../tracking';
|
|
4
|
+
export class KeywordMatcher {
|
|
5
|
+
constructor({ cmsApi, locale, request }) {
|
|
6
|
+
this.cmsApi = cmsApi;
|
|
7
|
+
this.locale = locale;
|
|
8
|
+
this.request = request;
|
|
9
|
+
this.isRegExp = false;
|
|
10
|
+
}
|
|
11
|
+
getNodeByInput(userInput) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const keywordNodes = this.cmsApi.getKeywordNodes();
|
|
14
|
+
const keywordNode = this.getNodeByKeyword(userInput, keywordNodes);
|
|
15
|
+
if (!keywordNode) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
this.trackKeywordEvent();
|
|
19
|
+
return keywordNode;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getNodeByKeyword(userInput, keywordNodes) {
|
|
23
|
+
const matchedKeywordNodes = keywordNodes.filter(node => this.matchKeywords(userInput, node));
|
|
24
|
+
if (matchedKeywordNodes.length > 0 && matchedKeywordNodes[0].target) {
|
|
25
|
+
return matchedKeywordNodes[0];
|
|
8
26
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
matchKeywords(userInput, node) {
|
|
30
|
+
const result = node.content.keywords.find(keywords => {
|
|
31
|
+
if (keywords.locale === this.locale) {
|
|
32
|
+
this.keywordNodeId = node.id;
|
|
33
|
+
return this.inputMatchesAnyKeyword(userInput, keywords.values);
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
return Boolean(result);
|
|
38
|
+
}
|
|
39
|
+
inputMatchesAnyKeyword(userInput, keywords) {
|
|
40
|
+
return keywords.some(keyword => {
|
|
41
|
+
const regExpMatchArray = keyword.match(REG_EXP_PATTERN);
|
|
42
|
+
if (regExpMatchArray) {
|
|
43
|
+
const keywordAsRegExp = this.resolveKeywordAsRegExp(regExpMatchArray);
|
|
44
|
+
const match = userInput.match(keywordAsRegExp);
|
|
45
|
+
this.isRegExp = true;
|
|
46
|
+
this.matchedKeyword = match ? match[0] : undefined;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.isRegExp = false;
|
|
50
|
+
this.matchedKeyword = userInput.includes(keyword) ? keyword : undefined;
|
|
51
|
+
}
|
|
52
|
+
return this.matchedKeyword !== undefined;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
resolveKeywordAsRegExp(regExpMatchArray) {
|
|
56
|
+
const [, pattern, flags] = regExpMatchArray;
|
|
57
|
+
return new RegExp(pattern, flags);
|
|
58
|
+
}
|
|
59
|
+
trackKeywordEvent() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const eventArgs = {
|
|
62
|
+
nluKeywordId: this.keywordNodeId,
|
|
63
|
+
nluKeywordName: this.matchedKeyword,
|
|
64
|
+
nluKeywordIsRegex: this.isRegExp,
|
|
65
|
+
nluKeywordMessageId: this.request.input.message_id,
|
|
66
|
+
};
|
|
67
|
+
yield trackEvent(this.request, EventAction.keyword, eventArgs);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
15
70
|
}
|
|
16
71
|
//# sourceMappingURL=keyword.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOrD,MAAM,OAAO,cAAc;IAQzB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAgB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;IACvB,CAAC;IAEK,cAAc,CAAC,SAAiB;;YACpC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAA;YAClD,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;YAClE,IAAI,CAAC,WAAW,EAAE;gBAChB,OAAO,SAAS,CAAA;aACjB;YACD,IAAI,CAAC,iBAAiB,EAAE,CAAA;YACxB,OAAO,WAAW,CAAA;QACpB,CAAC;KAAA;IAEO,gBAAgB,CACtB,SAAiB,EACjB,YAA6B;QAE7B,MAAM,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACrD,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,CACpC,CAAA;QAED,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;YACnE,OAAO,mBAAm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AC1C,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,sBAAsB,CAAC,gBAAkC;QAC/D,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,gBAAgB,CAAA;QAC3C,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACnC,CAAC;IAEa,iBAAiB;;YAC7B,MAAM,SAAS,GAAG;gBAChB,YAAY,EAAE,IAAI,CAAC,aAAa;gBAChC,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,iBAAiB,EAAE,IAAI,CAAC,QAAQ;gBAChC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU;aACnD,CAAA;YACD,MAAM,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QAChE,CAAC;KAAA;CACF"}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
2
|
import { FlowBuilderApi } from '../api';
|
|
3
3
|
import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent';
|
|
4
|
-
export
|
|
4
|
+
export interface SmartIntentsInferenceParams {
|
|
5
|
+
bot_id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
num_smart_intents_to_use?: number;
|
|
8
|
+
use_latest: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SmartIntentsInferenceConfig {
|
|
11
|
+
useLatest: boolean;
|
|
12
|
+
numSmartIntentsToUse?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class SmartIntentsApi {
|
|
15
|
+
cmsApi: FlowBuilderApi;
|
|
16
|
+
currentRequest: ActionRequest;
|
|
17
|
+
smartIntentsConfig: SmartIntentsInferenceConfig;
|
|
18
|
+
constructor(cmsApi: FlowBuilderApi, currentRequest: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig);
|
|
19
|
+
getNodeByInput(): Promise<HtSmartIntentNode | undefined>;
|
|
20
|
+
private getInference;
|
|
21
|
+
}
|
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { EventAction, trackEvent } from '../tracking';
|
|
4
|
+
export class SmartIntentsApi {
|
|
5
|
+
constructor(cmsApi, currentRequest, smartIntentsConfig) {
|
|
6
|
+
this.cmsApi = cmsApi;
|
|
7
|
+
this.currentRequest = currentRequest;
|
|
8
|
+
this.smartIntentsConfig = smartIntentsConfig;
|
|
9
|
+
}
|
|
10
|
+
getNodeByInput() {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
if (!this.currentRequest.input.data)
|
|
13
|
+
return undefined;
|
|
14
|
+
const smartIntentNodes = this.cmsApi.getSmartIntentNodes();
|
|
15
|
+
if (!smartIntentNodes.length)
|
|
16
|
+
return undefined;
|
|
17
|
+
const params = {
|
|
18
|
+
bot_id: this.currentRequest.session.bot.id,
|
|
19
|
+
text: this.currentRequest.input.data,
|
|
20
|
+
num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse,
|
|
21
|
+
use_latest: this.smartIntentsConfig.useLatest,
|
|
13
22
|
};
|
|
23
|
+
try {
|
|
24
|
+
const response = yield this.getInference(params);
|
|
25
|
+
const smartIntentNode = smartIntentNodes.find(smartIntentNode => smartIntentNode.content.title === response.data.smart_intent_title);
|
|
26
|
+
if (smartIntentNode) {
|
|
27
|
+
trackEvent(this.currentRequest, EventAction.intentSmart, {
|
|
28
|
+
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
29
|
+
nluIntentSmartNumUsed: response.data.smart_intents_used,
|
|
30
|
+
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
31
|
+
});
|
|
32
|
+
return smartIntentNode;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
14
39
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const response = yield axios({
|
|
40
|
+
}
|
|
41
|
+
getInference(inferenceParams) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return yield axios({
|
|
21
44
|
method: 'POST',
|
|
22
|
-
url: `${process.env.HUBTYPE_API_URL}/external/
|
|
45
|
+
url: `${process.env.HUBTYPE_API_URL}/external/v2/ai/smart_intents/inference/`,
|
|
23
46
|
headers: {
|
|
24
|
-
Authorization: `Bearer ${
|
|
47
|
+
Authorization: `Bearer ${this.currentRequest.session._access_token}`,
|
|
25
48
|
'Content-Type': 'application/json',
|
|
26
49
|
},
|
|
27
|
-
data:
|
|
50
|
+
data: inferenceParams,
|
|
28
51
|
timeout: 10000,
|
|
29
52
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
console.error(e);
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
}
|
|
39
56
|
//# sourceMappingURL=smart-intent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAerD,MAAM,OAAO,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,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AE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;aACjB;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;KAAA;IAEa,YAAY,CACxB,eAA4C;;YAE5C,OAAO,MAAM,KAAK,CAAC;gBACjB,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,0CAA0C;gBAC7E,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,EAAE;oBACpE,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,KAAK;aACf,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0-alpha.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
|
|
9
9
|
"build:watch": "npm run build -- --watch",
|
|
10
|
-
"test": "
|
|
10
|
+
"test": "../../node_modules/.bin/jest --coverage",
|
|
11
11
|
"cloc": "../../scripts/qa/cloc-package.sh .",
|
|
12
12
|
"prepublishOnly": "rm -rf lib && npm i && npm run build",
|
|
13
13
|
"lint": "npm run lint_core -- --fix",
|
|
14
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/react": "^0.
|
|
17
|
+
"@botonic/react": "^0.27.0-alpha.0",
|
|
18
18
|
"axios": "^1.6.8",
|
|
19
19
|
"uuid": "^9.0.1"
|
|
20
20
|
},
|