@plitzi/sdk-interactions 0.30.19
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/CHANGELOG.md +1717 -0
- package/dist/InteractionsContext.d.ts +5 -0
- package/dist/InteractionsContext.mjs +5 -0
- package/dist/InteractionsContextProvider.d.ts +10 -0
- package/dist/InteractionsContextProvider.mjs +26 -0
- package/dist/InteractionsHelper.d.ts +7 -0
- package/dist/InteractionsHelper.mjs +145 -0
- package/dist/InteractionsManager.d.ts +31 -0
- package/dist/InteractionsManager.mjs +110 -0
- package/dist/hooks/useInteractions.d.ts +10 -0
- package/dist/hooks/useInteractions.mjs +18 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.mjs +8 -0
- package/dist/sources/AuthSource/AuthInteractions.d.ts +7 -0
- package/dist/sources/AuthSource/AuthInteractions.mjs +119 -0
- package/dist/sources/AuthSource/index.d.ts +3 -0
- package/dist/sources/AuthSource/index.mjs +2 -0
- package/dist/sources/index.d.ts +3 -0
- package/dist/sources/index.mjs +2 -0
- package/dist/utility/delayTime.d.ts +5 -0
- package/dist/utility/delayTime.mjs +16 -0
- package/dist/utility/index.d.ts +17 -0
- package/dist/utility/index.mjs +11 -0
- package/dist/utility/transformer.d.ts +1 -0
- package/dist/utility/twigTemplate.d.ts +6 -0
- package/dist/utility/twigTemplate.mjs +77 -0
- package/dist/utility/webHook.d.ts +9 -0
- package/dist/utility/webHook.mjs +117 -0
- package/package.json +99 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as InteractionsManager } from './InteractionsManager';
|
|
2
|
+
import { InteractionsContextValue as InteractionsContextValueShared } from '@plitzi/sdk-shared';
|
|
3
|
+
export type InteractionsContextValue = InteractionsContextValueShared<InstanceType<typeof InteractionsManager>>;
|
|
4
|
+
declare const InteractionsContext: import('react').Context<InteractionsContextValue>;
|
|
5
|
+
export default InteractionsContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryParams, RouteParams } from '@plitzi/sdk-shared';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export type InteractionsContextProviderProps = {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
currentPageId: string;
|
|
6
|
+
routeParams: RouteParams;
|
|
7
|
+
queryParams: QueryParams;
|
|
8
|
+
};
|
|
9
|
+
declare const InteractionsContextProvider: ({ children, currentPageId, routeParams, queryParams }: InteractionsContextProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default InteractionsContextProvider;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import e from "./InteractionsContext.mjs";
|
|
2
|
+
import t from "./hooks/useInteractions.mjs";
|
|
3
|
+
import n from "./InteractionsManager.mjs";
|
|
4
|
+
import { useMemo as r } from "react";
|
|
5
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
6
|
+
//#region src/InteractionsContextProvider.tsx
|
|
7
|
+
var a = ({ children: a, currentPageId: o, routeParams: s, queryParams: c }) => {
|
|
8
|
+
let l = r(() => new n(o, s, c), []);
|
|
9
|
+
return l.interactionsData = r(() => ({
|
|
10
|
+
currentPageId: o,
|
|
11
|
+
...s,
|
|
12
|
+
...c
|
|
13
|
+
}), [
|
|
14
|
+
o,
|
|
15
|
+
s,
|
|
16
|
+
c
|
|
17
|
+
]), /* @__PURE__ */ i(e, {
|
|
18
|
+
value: r(() => ({
|
|
19
|
+
interactionsManager: l,
|
|
20
|
+
useInteractions: t
|
|
21
|
+
}), [l]),
|
|
22
|
+
children: a
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { a as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElementInteraction } from '@plitzi/sdk-shared';
|
|
2
|
+
declare const flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {}, postCallbacksTotal?: never[]) => Promise<void>;
|
|
3
|
+
export { flowTrigger };
|
|
4
|
+
declare const InteractionsHelper: {
|
|
5
|
+
flowTrigger: (triggerNode: ElementInteraction, nodes?: {}, callbacksAvailables?: {}, flowParams?: Record<string, unknown>, globalParams?: {}, postCallbacksTotal?: never[]) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export default InteractionsHelper;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import e from "./utility/index.mjs";
|
|
2
|
+
import { get as t, omit as n } from "@plitzi/plitzi-ui/helpers";
|
|
3
|
+
import { QueryBuilderEvaluator as r } from "@plitzi/plitzi-ui/QueryBuilder";
|
|
4
|
+
import { pConsole as i } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
|
|
5
|
+
import { hasValidToken as a, processTwig as o } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
6
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
7
|
+
//#region src/InteractionsHelper.tsx
|
|
8
|
+
var l = (e, t, n, r, i) => e === "utility" && i === "twigTemplate" ? t : Object.keys(t).reduce((i, s) => {
|
|
9
|
+
let c = t[s];
|
|
10
|
+
if (e !== "trigger") {
|
|
11
|
+
let e = 5;
|
|
12
|
+
for (; typeof c == "string" && a(c) && e > 0;) c = o(c, {
|
|
13
|
+
...n,
|
|
14
|
+
...r
|
|
15
|
+
}, !1, !0), e--;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...i,
|
|
19
|
+
[s]: c
|
|
20
|
+
};
|
|
21
|
+
}, {}), u = async (n, i = {}, a = {}, o = {}) => {
|
|
22
|
+
let s = {}, c = [], { id: u, action: d, enabled: f, params: p, elementId: m, type: h, when: g } = n;
|
|
23
|
+
if (!d || !f) return {
|
|
24
|
+
status: "disabled",
|
|
25
|
+
result: s,
|
|
26
|
+
postCallbacks: c
|
|
27
|
+
};
|
|
28
|
+
let _ = {
|
|
29
|
+
...o,
|
|
30
|
+
...a,
|
|
31
|
+
[u]: p
|
|
32
|
+
};
|
|
33
|
+
if (g && !r(g, _)) return {
|
|
34
|
+
status: "skipped",
|
|
35
|
+
result: s,
|
|
36
|
+
postCallbacks: c,
|
|
37
|
+
whenParams: _
|
|
38
|
+
};
|
|
39
|
+
let v = {
|
|
40
|
+
...a,
|
|
41
|
+
...o,
|
|
42
|
+
...l(h, p, a, o, d)
|
|
43
|
+
};
|
|
44
|
+
switch (h) {
|
|
45
|
+
case "callback":
|
|
46
|
+
case "globalCallback": {
|
|
47
|
+
if (!m) return {
|
|
48
|
+
status: "failed",
|
|
49
|
+
result: s,
|
|
50
|
+
postCallbacks: c,
|
|
51
|
+
whenParams: _
|
|
52
|
+
};
|
|
53
|
+
let e = t(i, `${m}.${d}`);
|
|
54
|
+
if (!e) return {
|
|
55
|
+
status: "failed",
|
|
56
|
+
result: s,
|
|
57
|
+
postCallbacks: c,
|
|
58
|
+
whenParams: _
|
|
59
|
+
};
|
|
60
|
+
let { callback: n, postCallback: r } = e;
|
|
61
|
+
n && (s = await n(v)), r && c.push({
|
|
62
|
+
id: u,
|
|
63
|
+
callback: r,
|
|
64
|
+
params: {
|
|
65
|
+
...v,
|
|
66
|
+
[u]: s
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "utility": {
|
|
72
|
+
let { callback: n, postCallback: r } = t(e, d, {});
|
|
73
|
+
n && (s = await n(v)), r && c.push({
|
|
74
|
+
id: u,
|
|
75
|
+
callback: r,
|
|
76
|
+
params: {
|
|
77
|
+
...v,
|
|
78
|
+
[u]: s
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
status: "success",
|
|
87
|
+
result: s,
|
|
88
|
+
postCallbacks: c,
|
|
89
|
+
whenParams: _
|
|
90
|
+
};
|
|
91
|
+
}, d = async (e = []) => {
|
|
92
|
+
let t = {};
|
|
93
|
+
return await Promise.all(e.reverse().map(async ({ id: e, callback: r, params: i }) => {
|
|
94
|
+
t[e] = await r?.(n(i, [e]), i[e]);
|
|
95
|
+
})), t;
|
|
96
|
+
}, f = async (e, n = {}, r = {}, a = {}, o = {}, s = [], c = {}) => {
|
|
97
|
+
if (!e) return c;
|
|
98
|
+
let l = t(n, e.afterNode);
|
|
99
|
+
if (!l && s.length > 0 && await d(s), !l) return c;
|
|
100
|
+
let p = i.getTime().valueOf(), { status: m, result: h, postCallbacks: g, whenParams: _ } = await u(l, r, a, o);
|
|
101
|
+
return c[l.id] = {
|
|
102
|
+
node: l,
|
|
103
|
+
status: m,
|
|
104
|
+
result: h,
|
|
105
|
+
postCallbacks: g,
|
|
106
|
+
whenParams: _,
|
|
107
|
+
startTime: p,
|
|
108
|
+
endTime: i.getTime().valueOf()
|
|
109
|
+
}, s.push(...g), f(l, n, r, {
|
|
110
|
+
...a,
|
|
111
|
+
[l.id]: h
|
|
112
|
+
}, o, s, c);
|
|
113
|
+
}, p = (e, t, n = {}, r) => {
|
|
114
|
+
let a = i.getTime().valueOf(), o = "skipped";
|
|
115
|
+
r === "completed" && (o = "success"), i.info("interactions", /* @__PURE__ */ c("span", { children: ["Interaction triggered ", /* @__PURE__ */ s("b", { children: `${e.title} [${e.action}]` })] }), {
|
|
116
|
+
status: r,
|
|
117
|
+
node: e,
|
|
118
|
+
elementId: e.elementId,
|
|
119
|
+
nodes: {
|
|
120
|
+
...n,
|
|
121
|
+
[e.id]: {
|
|
122
|
+
node: e,
|
|
123
|
+
status: o,
|
|
124
|
+
result: void 0,
|
|
125
|
+
postCallbacks: [],
|
|
126
|
+
startTime: t,
|
|
127
|
+
endTime: a
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
startTime: t,
|
|
131
|
+
endTime: a
|
|
132
|
+
});
|
|
133
|
+
}, m = async (e, t = {}, n = {}, a = {}, o = {}, s = []) => {
|
|
134
|
+
let c = i.getTime().valueOf(), { action: l, enabled: u, when: d } = e;
|
|
135
|
+
if (!l || !u || d && !r(d, {
|
|
136
|
+
...o,
|
|
137
|
+
...a
|
|
138
|
+
})) {
|
|
139
|
+
p(e, c, {}, "skipped");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
p(e, c, await f(e, t, n, a, o, s), "completed");
|
|
143
|
+
}, h = { flowTrigger: m };
|
|
144
|
+
//#endregion
|
|
145
|
+
export { h as default, m as flowTrigger };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { default as EventBridge } from '@plitzi/sdk-event-bridge';
|
|
2
|
+
import { ElementInteraction, InteractionCallback, QueryParams, RouteParams, Subscriptor } from '@plitzi/sdk-shared';
|
|
3
|
+
type InteractionUpdateListener = (timestamp: number) => void;
|
|
4
|
+
declare class InteractionsManager {
|
|
5
|
+
eventBridge: InstanceType<typeof EventBridge>;
|
|
6
|
+
parentManager?: InteractionsManager;
|
|
7
|
+
childManagers: InteractionsManager[];
|
|
8
|
+
interactionsData: Record<string, string | number | boolean>;
|
|
9
|
+
subscriptors: Record<string, Subscriptor>;
|
|
10
|
+
callbacksAvailables: Record<string, Record<string, InteractionCallback<any>>>;
|
|
11
|
+
interactionsRunning: Record<string, boolean>;
|
|
12
|
+
lastUpdate: number;
|
|
13
|
+
private listeners;
|
|
14
|
+
constructor(currentPageId?: string, routeParams?: RouteParams, queryParams?: QueryParams);
|
|
15
|
+
eventBridgeCallback: (interactions?: Record<string, ElementInteraction>) => (subscriptorId: string, eventName: string, params: Record<string, unknown>) => Promise<void>;
|
|
16
|
+
subscribe<TParams extends Record<string, unknown> = Record<string, unknown>>(id: string, interactions?: Record<string, ElementInteraction>, triggers?: Record<string, InteractionCallback<TParams>>, callbacks?: Record<string, InteractionCallback<TParams>>, getAdditionalParams?: Subscriptor<TParams>['getAdditionalParams']): boolean;
|
|
17
|
+
unsubscribe(id: string): boolean;
|
|
18
|
+
getRootManager(): this | undefined;
|
|
19
|
+
private getSubscriptorInternal;
|
|
20
|
+
getSubscriptor(subscriptorId: string): Subscriptor | undefined;
|
|
21
|
+
private getCallbacksAvailablesInternal;
|
|
22
|
+
getCallbacksAvailables(): {
|
|
23
|
+
[x: string]: Record<string, InteractionCallback> | Record<string, InteractionCallback<any>>;
|
|
24
|
+
};
|
|
25
|
+
interactionTrigger(subscriptorId: string, eventName: string, params?: Record<string, unknown>): Promise<unknown[]>;
|
|
26
|
+
createChildManager: (routeParams?: Record<string, string>, queryParams?: Record<string, string>) => InteractionsManager;
|
|
27
|
+
removeChildManager: (childManager: InteractionsManager) => void;
|
|
28
|
+
onUpdate(listener: InteractionUpdateListener): () => void;
|
|
29
|
+
private touch;
|
|
30
|
+
}
|
|
31
|
+
export default InteractionsManager;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { flowTrigger as e } from "./InteractionsHelper.mjs";
|
|
2
|
+
import { get as t, set as n } from "@plitzi/plitzi-ui/helpers";
|
|
3
|
+
import r from "@plitzi/sdk-event-bridge";
|
|
4
|
+
//#region src/InteractionsManager.ts
|
|
5
|
+
var i = class i {
|
|
6
|
+
eventBridge;
|
|
7
|
+
parentManager;
|
|
8
|
+
childManagers;
|
|
9
|
+
interactionsData;
|
|
10
|
+
subscriptors;
|
|
11
|
+
callbacksAvailables;
|
|
12
|
+
interactionsRunning;
|
|
13
|
+
lastUpdate;
|
|
14
|
+
listeners = /* @__PURE__ */ new Set();
|
|
15
|
+
constructor(e = "", t = {}, n = {}) {
|
|
16
|
+
this.eventBridge = new r(), this.parentManager = void 0, this.childManagers = [], this.subscriptors = {}, this.callbacksAvailables = {}, this.interactionsRunning = {}, this.interactionsData = {
|
|
17
|
+
currentPageId: e,
|
|
18
|
+
...t,
|
|
19
|
+
...n
|
|
20
|
+
}, this.lastUpdate = Date.now();
|
|
21
|
+
}
|
|
22
|
+
eventBridgeCallback = (r) => async (i, a, o) => {
|
|
23
|
+
if (!r || !a || !i || t(this.interactionsRunning, `${i}.${a}`)) return;
|
|
24
|
+
n(this.interactionsRunning, `${i}.${a}`, !0);
|
|
25
|
+
let s = t(this.subscriptors, `${i}.getAdditionalParams`, void 0), c;
|
|
26
|
+
typeof s == "function" && ({dataSource: c} = s());
|
|
27
|
+
let l = Object.values(r).filter((e) => e.type === "trigger" && e.action === a && e.enabled);
|
|
28
|
+
await Promise.all(l.map((t) => e(t, r, this.getCallbacksAvailables(), { [t.id]: o }, {
|
|
29
|
+
...this.interactionsData,
|
|
30
|
+
...c
|
|
31
|
+
}))), n(this.interactionsRunning, `${i}.${a}`, !1);
|
|
32
|
+
};
|
|
33
|
+
subscribe(e, t = {}, r = {}, i = {}, a) {
|
|
34
|
+
if (this.subscriptors[e]) return !1;
|
|
35
|
+
n(this.subscriptors, e, {
|
|
36
|
+
id: e,
|
|
37
|
+
triggers: r,
|
|
38
|
+
getAdditionalParams: a
|
|
39
|
+
});
|
|
40
|
+
let o = Object.keys(i);
|
|
41
|
+
return o.length > 0 && (this.callbacksAvailables[e] = o.reduce((t, n) => {
|
|
42
|
+
let { title: r, callback: a, postCallback: o, params: s, preview: c, type: l } = i[n];
|
|
43
|
+
return typeof a == "function" ? {
|
|
44
|
+
...t,
|
|
45
|
+
[n]: {
|
|
46
|
+
elementId: e,
|
|
47
|
+
title: r,
|
|
48
|
+
action: n,
|
|
49
|
+
type: l,
|
|
50
|
+
callback: a,
|
|
51
|
+
postCallback: o,
|
|
52
|
+
params: s,
|
|
53
|
+
preview: c
|
|
54
|
+
}
|
|
55
|
+
} : t;
|
|
56
|
+
}, {})), Object.keys(r).length > 0 && this.eventBridge.on("interaction", e, this.eventBridgeCallback(t), { override: !0 }), this.touch(), !0;
|
|
57
|
+
}
|
|
58
|
+
unsubscribe(e) {
|
|
59
|
+
return this.subscriptors[e] ? (this.eventBridge.off("interaction", e), delete this.subscriptors[e], this.callbacksAvailables[e] && delete this.callbacksAvailables[e], this.touch(), !0) : !1;
|
|
60
|
+
}
|
|
61
|
+
getRootManager() {
|
|
62
|
+
return this.parentManager ? this.parentManager.getRootManager() : this;
|
|
63
|
+
}
|
|
64
|
+
getSubscriptorInternal(e) {
|
|
65
|
+
let n = t(this.subscriptors, e);
|
|
66
|
+
if (!n && this.childManagers.length > 0) {
|
|
67
|
+
for (let t of this.childManagers) if (n = t.getSubscriptorInternal(e), n) break;
|
|
68
|
+
}
|
|
69
|
+
return n;
|
|
70
|
+
}
|
|
71
|
+
getSubscriptor(e) {
|
|
72
|
+
return this.parentManager ? this.getRootManager()?.getSubscriptorInternal(e) : this.getSubscriptorInternal(e);
|
|
73
|
+
}
|
|
74
|
+
getCallbacksAvailablesInternal() {
|
|
75
|
+
let e = {};
|
|
76
|
+
if (this.childManagers.length > 0) for (let t of this.childManagers) e = {
|
|
77
|
+
...e,
|
|
78
|
+
...t.getCallbacksAvailablesInternal()
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
...e,
|
|
82
|
+
...this.callbacksAvailables
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
getCallbacksAvailables() {
|
|
86
|
+
return this.parentManager ? this.getRootManager()?.getCallbacksAvailablesInternal() ?? {} : this.getCallbacksAvailablesInternal();
|
|
87
|
+
}
|
|
88
|
+
interactionTrigger(e, t, n = {}) {
|
|
89
|
+
return this.eventBridge.emit("interaction", e, e, t, n);
|
|
90
|
+
}
|
|
91
|
+
createChildManager = (e = {}, t = {}) => {
|
|
92
|
+
let n = new i(this.interactionsData.currentPageId, e, t);
|
|
93
|
+
return n.parentManager = this, this.childManagers.push(n), n;
|
|
94
|
+
};
|
|
95
|
+
removeChildManager = (e) => {
|
|
96
|
+
this.childManagers = this.childManagers.filter((t) => t !== e);
|
|
97
|
+
};
|
|
98
|
+
onUpdate(e) {
|
|
99
|
+
return this.listeners.add(e), () => {
|
|
100
|
+
this.listeners.delete(e);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
touch() {
|
|
104
|
+
let e = Date.now();
|
|
105
|
+
this.lastUpdate = e;
|
|
106
|
+
for (let t of this.listeners) t(e);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
export { i as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ElementInteraction, InteractionCallback, Subscriptor } from '@plitzi/sdk-shared';
|
|
2
|
+
export type UseInteractionsProps<TParams extends Record<string, unknown> = Record<string, unknown>> = {
|
|
3
|
+
id: string;
|
|
4
|
+
interactions?: Record<string, ElementInteraction>;
|
|
5
|
+
triggers?: Record<string, InteractionCallback<TParams>>;
|
|
6
|
+
callbacks?: Record<string, InteractionCallback<TParams>>;
|
|
7
|
+
getAdditionalParams?: Subscriptor<TParams>['getAdditionalParams'];
|
|
8
|
+
};
|
|
9
|
+
declare const useInteractions: <TParams extends Record<string, unknown> = Record<string, unknown>>({ id, interactions, triggers, callbacks, getAdditionalParams }: UseInteractionsProps<TParams>) => void;
|
|
10
|
+
export default useInteractions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import e from "../InteractionsContext.mjs";
|
|
2
|
+
import { use as t, useEffect as n } from "react";
|
|
3
|
+
//#region src/hooks/useInteractions.ts
|
|
4
|
+
var r = ({ id: r, interactions: i, triggers: a, callbacks: o, getAdditionalParams: s }) => {
|
|
5
|
+
let { interactionsManager: c } = t(e);
|
|
6
|
+
n(() => (c.subscribe(r, i, a, o, s), () => {
|
|
7
|
+
c.unsubscribe(r);
|
|
8
|
+
}), [
|
|
9
|
+
r,
|
|
10
|
+
i,
|
|
11
|
+
a,
|
|
12
|
+
o,
|
|
13
|
+
s,
|
|
14
|
+
c
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { r as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as useInteractions } from './hooks/useInteractions';
|
|
2
|
+
import { default as InteractionsContext } from './InteractionsContext';
|
|
3
|
+
import { default as InteractionsContextProvider } from './InteractionsContextProvider';
|
|
4
|
+
import { default as InteractionsHelper } from './InteractionsHelper';
|
|
5
|
+
import { default as InteractionsManager } from './InteractionsManager';
|
|
6
|
+
import { AuthInteractions } from './sources';
|
|
7
|
+
import { default as utility } from './utility';
|
|
8
|
+
export * from './utility';
|
|
9
|
+
export * from './InteractionsContext';
|
|
10
|
+
export * from './InteractionsContextProvider';
|
|
11
|
+
export * from './InteractionsHelper';
|
|
12
|
+
export * from './hooks/useInteractions';
|
|
13
|
+
export * from './sources';
|
|
14
|
+
export * from './InteractionsManager';
|
|
15
|
+
export { InteractionsManager, utility, InteractionsContext, InteractionsContextProvider, InteractionsHelper, useInteractions, AuthInteractions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import e from "./InteractionsContext.mjs";
|
|
2
|
+
import t from "./hooks/useInteractions.mjs";
|
|
3
|
+
import n from "./utility/index.mjs";
|
|
4
|
+
import r, { flowTrigger as i } from "./InteractionsHelper.mjs";
|
|
5
|
+
import a from "./InteractionsManager.mjs";
|
|
6
|
+
import o from "./InteractionsContextProvider.mjs";
|
|
7
|
+
import s from "./sources/AuthSource/AuthInteractions.mjs";
|
|
8
|
+
export { s as AuthInteractions, e as InteractionsContext, o as InteractionsContextProvider, r as InteractionsHelper, a as InteractionsManager, i as flowTrigger, t as useInteractions, n as utility };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type AuthInteractionsProps = {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
authProvider?: '' | 'auth0' | 'basic' | 'custom';
|
|
5
|
+
};
|
|
6
|
+
declare const AuthInteractions: ({ children, authProvider }: AuthInteractionsProps) => ReactNode;
|
|
7
|
+
export default AuthInteractions;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import e from "../../InteractionsContext.mjs";
|
|
2
|
+
import { use as t, useCallback as n, useMemo as r } from "react";
|
|
3
|
+
import { AuthContext as i } from "@plitzi/sdk-auth";
|
|
4
|
+
//#region src/sources/AuthSource/AuthInteractions.tsx
|
|
5
|
+
var a = ({ children: a, authProvider: o = "basic" }) => {
|
|
6
|
+
let { login: s, refresh: c, logout: l } = t(i), { useInteractions: u } = t(e), d = n((e) => s(e), [s]), f = n((e) => c(e), [c]), p = n(() => l(), [l]);
|
|
7
|
+
return u({
|
|
8
|
+
id: "auth",
|
|
9
|
+
callbacks: r(() => {
|
|
10
|
+
let e = {};
|
|
11
|
+
return o === "auth0" ? e = {
|
|
12
|
+
login: {
|
|
13
|
+
action: "authLogin",
|
|
14
|
+
title: "Auth Login",
|
|
15
|
+
type: "globalCallback",
|
|
16
|
+
callback: d,
|
|
17
|
+
params: {}
|
|
18
|
+
},
|
|
19
|
+
logout: {
|
|
20
|
+
action: "authLogout",
|
|
21
|
+
title: "Auth Logout",
|
|
22
|
+
type: "globalCallback",
|
|
23
|
+
callback: p,
|
|
24
|
+
params: {}
|
|
25
|
+
}
|
|
26
|
+
} : o === "basic" && (e = {
|
|
27
|
+
login: {
|
|
28
|
+
action: "authLogin",
|
|
29
|
+
title: "Auth Login",
|
|
30
|
+
type: "globalCallback",
|
|
31
|
+
callback: d,
|
|
32
|
+
params: {
|
|
33
|
+
mode: {
|
|
34
|
+
label: "Mode",
|
|
35
|
+
canBind: !1,
|
|
36
|
+
type: "select",
|
|
37
|
+
defaultValue: "normal",
|
|
38
|
+
options: [{
|
|
39
|
+
label: "Token",
|
|
40
|
+
value: "token"
|
|
41
|
+
}, {
|
|
42
|
+
label: "User and Password",
|
|
43
|
+
value: "normal"
|
|
44
|
+
}]
|
|
45
|
+
},
|
|
46
|
+
username: {
|
|
47
|
+
type: "text",
|
|
48
|
+
defaultValue: "",
|
|
49
|
+
when: (e) => e.mode === "normal"
|
|
50
|
+
},
|
|
51
|
+
password: {
|
|
52
|
+
type: "text",
|
|
53
|
+
defaultValue: "",
|
|
54
|
+
when: (e) => e.mode === "normal"
|
|
55
|
+
},
|
|
56
|
+
token: {
|
|
57
|
+
type: "text",
|
|
58
|
+
defaultValue: "",
|
|
59
|
+
when: (e) => e.mode === "token"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
preview: {
|
|
63
|
+
errors: {
|
|
64
|
+
username: "",
|
|
65
|
+
password: "",
|
|
66
|
+
token: ""
|
|
67
|
+
},
|
|
68
|
+
success: "",
|
|
69
|
+
access_token: "",
|
|
70
|
+
expires_at: "",
|
|
71
|
+
details: {
|
|
72
|
+
id: "",
|
|
73
|
+
username: "",
|
|
74
|
+
email: "",
|
|
75
|
+
verified: "",
|
|
76
|
+
permissions: ""
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
refreshDetails: {
|
|
81
|
+
action: "authRefreshDetails",
|
|
82
|
+
title: "Auth Refresh Details",
|
|
83
|
+
type: "globalCallback",
|
|
84
|
+
callback: f,
|
|
85
|
+
params: {},
|
|
86
|
+
preview: {
|
|
87
|
+
errors: "",
|
|
88
|
+
success: "",
|
|
89
|
+
access_token: "",
|
|
90
|
+
expires_at: "",
|
|
91
|
+
details: {
|
|
92
|
+
id: "",
|
|
93
|
+
username: "",
|
|
94
|
+
email: "",
|
|
95
|
+
roles: "",
|
|
96
|
+
permissions: "",
|
|
97
|
+
verified: ""
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
logout: {
|
|
102
|
+
action: "authLogout",
|
|
103
|
+
title: "Auth Logout",
|
|
104
|
+
type: "globalCallback",
|
|
105
|
+
callback: p,
|
|
106
|
+
preview: {},
|
|
107
|
+
params: {}
|
|
108
|
+
}
|
|
109
|
+
}), e;
|
|
110
|
+
}, [
|
|
111
|
+
d,
|
|
112
|
+
p,
|
|
113
|
+
f,
|
|
114
|
+
o
|
|
115
|
+
])
|
|
116
|
+
}), a;
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
export { a as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utility/delayTime.ts
|
|
2
|
+
var e = {
|
|
3
|
+
action: "delayTime",
|
|
4
|
+
title: "Delay Time",
|
|
5
|
+
type: "utility",
|
|
6
|
+
params: { time: {
|
|
7
|
+
label: "Time (Milliseconds)",
|
|
8
|
+
type: "text"
|
|
9
|
+
} },
|
|
10
|
+
preview: {},
|
|
11
|
+
callback: ({ time: e }) => new Promise((t) => {
|
|
12
|
+
setTimeout(t, e);
|
|
13
|
+
})
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
delayTime: import('@plitzi/sdk-shared').InteractionCallback<{
|
|
3
|
+
time: number;
|
|
4
|
+
}>;
|
|
5
|
+
twigTemplate: import('@plitzi/sdk-shared').InteractionCallback<{
|
|
6
|
+
returnMode: "jsonObject" | "json" | "text";
|
|
7
|
+
template: string;
|
|
8
|
+
}>;
|
|
9
|
+
webHook: import('@plitzi/sdk-shared').InteractionCallback<{
|
|
10
|
+
url: string;
|
|
11
|
+
method: string;
|
|
12
|
+
body: Record<string, string | Blob>;
|
|
13
|
+
authorizationToken: string;
|
|
14
|
+
credentials: RequestCredentials;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|