@player-ui/external-action-plugin 0.8.0--canary.307.9621 → 0.8.0-next.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.
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
+ try {
4
+ var info = gen[key](arg);
5
+ var value = info.value;
6
+ } catch (error) {
7
+ reject(error);
8
+ return;
9
+ }
10
+ if (info.done) {
11
+ resolve(value);
12
+ } else {
13
+ Promise.resolve(value).then(_next, _throw);
14
+ }
15
+ }
16
+ function _async_to_generator(fn) {
17
+ return function() {
18
+ var self = this, args = arguments;
19
+ return new Promise(function(resolve, reject) {
20
+ var gen = fn.apply(self, args);
21
+ function _next(value) {
22
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
+ }
24
+ function _throw(err) {
25
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
+ }
27
+ _next(undefined);
28
+ });
29
+ };
30
+ }
31
+ function _class_call_check(instance, Constructor) {
32
+ if (!(instance instanceof Constructor)) {
33
+ throw new TypeError("Cannot call a class as a function");
34
+ }
35
+ }
36
+ function _defineProperties(target, props) {
37
+ for(var i = 0; i < props.length; i++){
38
+ var descriptor = props[i];
39
+ descriptor.enumerable = descriptor.enumerable || false;
40
+ descriptor.configurable = true;
41
+ if ("value" in descriptor) descriptor.writable = true;
42
+ Object.defineProperty(target, descriptor.key, descriptor);
43
+ }
44
+ }
45
+ function _create_class(Constructor, protoProps, staticProps) {
46
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
47
+ if (staticProps) _defineProperties(Constructor, staticProps);
48
+ return Constructor;
49
+ }
50
+ function _instanceof(left, right) {
51
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
52
+ return !!right[Symbol.hasInstance](left);
53
+ } else {
54
+ return left instanceof right;
55
+ }
56
+ }
57
+ function _ts_generator(thisArg, body) {
58
+ var f, y, t, g, _ = {
59
+ label: 0,
60
+ sent: function() {
61
+ if (t[0] & 1) throw t[1];
62
+ return t[1];
63
+ },
64
+ trys: [],
65
+ ops: []
66
+ };
67
+ return g = {
68
+ next: verb(0),
69
+ "throw": verb(1),
70
+ "return": verb(2)
71
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
72
+ return this;
73
+ }), g;
74
+ function verb(n) {
75
+ return function(v) {
76
+ return step([
77
+ n,
78
+ v
79
+ ]);
80
+ };
81
+ }
82
+ function step(op) {
83
+ if (f) throw new TypeError("Generator is already executing.");
84
+ while(_)try {
85
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
86
+ if (y = 0, t) op = [
87
+ op[0] & 2,
88
+ t.value
89
+ ];
90
+ switch(op[0]){
91
+ case 0:
92
+ case 1:
93
+ t = op;
94
+ break;
95
+ case 4:
96
+ _.label++;
97
+ return {
98
+ value: op[1],
99
+ done: false
100
+ };
101
+ case 5:
102
+ _.label++;
103
+ y = op[1];
104
+ op = [
105
+ 0
106
+ ];
107
+ continue;
108
+ case 7:
109
+ op = _.ops.pop();
110
+ _.trys.pop();
111
+ continue;
112
+ default:
113
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
114
+ _ = 0;
115
+ continue;
116
+ }
117
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
118
+ _.label = op[1];
119
+ break;
120
+ }
121
+ if (op[0] === 6 && _.label < t[1]) {
122
+ _.label = t[1];
123
+ t = op;
124
+ break;
125
+ }
126
+ if (t && _.label < t[2]) {
127
+ _.label = t[2];
128
+ _.ops.push(op);
129
+ break;
130
+ }
131
+ if (t[2]) _.ops.pop();
132
+ _.trys.pop();
133
+ continue;
134
+ }
135
+ op = body.call(thisArg, _);
136
+ } catch (e) {
137
+ op = [
138
+ 6,
139
+ e
140
+ ];
141
+ y = 0;
142
+ } finally{
143
+ f = t = 0;
144
+ }
145
+ if (op[0] & 5) throw op[1];
146
+ return {
147
+ value: op[0] ? op[1] : void 0,
148
+ done: true
149
+ };
150
+ }
151
+ }
152
+ var ExternalActionPlugin = function() {
153
+ var __defProp = Object.defineProperty;
154
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
155
+ var __getOwnPropNames = Object.getOwnPropertyNames;
156
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
157
+ var __export = function(target, all) {
158
+ for(var name in all)__defProp(target, name, {
159
+ get: all[name],
160
+ enumerable: true
161
+ });
162
+ };
163
+ var __copyProps = function(to, from, except, desc) {
164
+ if (from && typeof from === "object" || typeof from === "function") {
165
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
166
+ try {
167
+ var _loop = function() {
168
+ var key = _step.value;
169
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
170
+ get: function() {
171
+ return from[key];
172
+ },
173
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
174
+ });
175
+ };
176
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
177
+ } catch (err) {
178
+ _didIteratorError = true;
179
+ _iteratorError = err;
180
+ } finally{
181
+ try {
182
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
183
+ _iterator.return();
184
+ }
185
+ } finally{
186
+ if (_didIteratorError) {
187
+ throw _iteratorError;
188
+ }
189
+ }
190
+ }
191
+ }
192
+ return to;
193
+ };
194
+ var __toCommonJS = function(mod) {
195
+ return __copyProps(__defProp({}, "__esModule", {
196
+ value: true
197
+ }), mod);
198
+ };
199
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
200
+ var src_exports = {};
201
+ __export(src_exports, {
202
+ ExternalActionPlugin: function() {
203
+ return ExternalActionPlugin;
204
+ }
205
+ });
206
+ var ExternalActionPlugin = /*#__PURE__*/ function() {
207
+ function ExternalActionPlugin(handler) {
208
+ _class_call_check(this, ExternalActionPlugin);
209
+ this.name = "ExternalActionPlugin";
210
+ this.handler = handler;
211
+ }
212
+ _create_class(ExternalActionPlugin, [
213
+ {
214
+ key: "apply",
215
+ value: function apply(player) {
216
+ var _this = this;
217
+ player.hooks.flowController.tap(this.name, function(flowController) {
218
+ flowController.hooks.flow.tap(_this.name, function(flow) {
219
+ flow.hooks.transition.tap(_this.name, function(fromState, toState) {
220
+ var state = toState.value;
221
+ if (state.state_type === "EXTERNAL") {
222
+ var _this1 = _this;
223
+ setTimeout(/*#__PURE__*/ _async_to_generator(function() {
224
+ var shouldTransition, currentState, transitionValue, latestState, error;
225
+ return _ts_generator(this, function(_state) {
226
+ switch(_state.label){
227
+ case 0:
228
+ shouldTransition = function(currentState2) {
229
+ var _currentState2_controllers_flow_current_currentState, _currentState2_controllers_flow_current;
230
+ return currentState2.status === "in-progress" && ((_currentState2_controllers_flow_current = currentState2.controllers.flow.current) === null || _currentState2_controllers_flow_current === void 0 ? void 0 : (_currentState2_controllers_flow_current_currentState = _currentState2_controllers_flow_current.currentState) === null || _currentState2_controllers_flow_current_currentState === void 0 ? void 0 : _currentState2_controllers_flow_current_currentState.value) === state;
231
+ };
232
+ currentState = player.getState();
233
+ if (!shouldTransition(currentState)) return [
234
+ 3,
235
+ 4
236
+ ];
237
+ _state.label = 1;
238
+ case 1:
239
+ _state.trys.push([
240
+ 1,
241
+ 3,
242
+ ,
243
+ 4
244
+ ]);
245
+ return [
246
+ 4,
247
+ _this1.handler(state, currentState.controllers)
248
+ ];
249
+ case 2:
250
+ transitionValue = _state.sent();
251
+ if (transitionValue !== void 0) {
252
+ latestState = player.getState();
253
+ if (shouldTransition(latestState)) {
254
+ latestState.controllers.flow.transition(transitionValue);
255
+ } else {
256
+ player.logger.warn("External state resolved with [".concat(transitionValue, "], but Player already navigated away from [").concat(toState.name, "]"));
257
+ }
258
+ }
259
+ return [
260
+ 3,
261
+ 4
262
+ ];
263
+ case 3:
264
+ error = _state.sent();
265
+ if (_instanceof(error, Error)) {
266
+ currentState.fail(error);
267
+ }
268
+ return [
269
+ 3,
270
+ 4
271
+ ];
272
+ case 4:
273
+ return [
274
+ 2
275
+ ];
276
+ }
277
+ });
278
+ }), 0);
279
+ }
280
+ });
281
+ });
282
+ });
283
+ }
284
+ }
285
+ ]);
286
+ return ExternalActionPlugin;
287
+ }();
288
+ return __toCommonJS(src_exports);
289
+ }();
290
+ //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts"],"names":["currentState"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAgBO,MAAM,uBAAN,MAAmD;AAAA,IAIxD,YAAY,SAA+B;AAH3C,kBAAO;AAIL,WAAK,UAAU;AAAA,IACjB;AAAA,IAEA,MAAM,QAAgB;AACpB,aAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,uBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,eAAK,MAAM,WAAW,IAAI,KAAK,MAAM,CAAC,WAAW,YAAY;AAC3D,kBAAM,EAAE,OAAO,MAAM,IAAI;AACzB,gBAAI,MAAM,eAAe,YAAY;AACnC,yBAAW,YAAY;AAErB,sBAAM,mBAAmB,CACvBA,kBAEAA,cAAa,WAAW,iBACxBA,cAAa,YAAY,KAAK,SAAS,cAAc,UACnD;AAEJ,sBAAM,eAAe,OAAO,SAAS;AACrC,oBAAI,iBAAiB,YAAY,GAAG;AAClC,sBAAI;AACF,0BAAM,kBAAkB,MAAM,KAAK;AAAA,sBACjC;AAAA,sBACA,aAAa;AAAA,oBACf;AAEA,wBAAI,oBAAoB,QAAW;AAEjC,4BAAM,cAAc,OAAO,SAAS;AACpC,0BAAI,iBAAiB,WAAW,GAAG;AACjC,oCAAY,YAAY,KAAK,WAAW,eAAe;AAAA,sBACzD,OAAO;AACL,+BAAO,OAAO;AAAA,0BACZ,iCAAiC,eAAe,8CAA8C,QAAQ,IAAI;AAAA,wBAC5G;AAAA,sBACF;AAAA,oBACF;AAAA,kBACF,SAAS,OAAO;AACd,wBAAI,iBAAiB,OAAO;AAC1B,mCAAa,KAAK,KAAK;AAAA,oBACzB;AAAA,kBACF;AAAA,gBACF;AAAA,cACF,GAAG,CAAC;AAAA,YACN;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF","sourcesContent":["import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowExternalState,\n} from \"@player-ui/player\";\n\nexport type ExternalStateHandler = (\n state: NavigationFlowExternalState,\n options: InProgressState[\"controllers\"],\n) => string | undefined | Promise<string | undefined>;\n\n/**\n * A plugin to handle external actions states\n */\nexport class ExternalActionPlugin implements PlayerPlugin {\n name = \"ExternalActionPlugin\";\n private handler: ExternalStateHandler;\n\n constructor(handler: ExternalStateHandler) {\n this.handler = handler;\n }\n\n apply(player: Player) {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.transition.tap(this.name, (fromState, toState) => {\n const { value: state } = toState;\n if (state.state_type === \"EXTERNAL\") {\n setTimeout(async () => {\n /** Helper for ensuring state is still current relative to external state this is handling */\n const shouldTransition = (\n currentState: PlayerFlowState,\n ): currentState is InProgressState =>\n currentState.status === \"in-progress\" &&\n currentState.controllers.flow.current?.currentState?.value ===\n state;\n\n const currentState = player.getState();\n if (shouldTransition(currentState)) {\n try {\n const transitionValue = await this.handler(\n state,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n // Ensure the Player is still in the same state after waiting for transitionValue\n const latestState = player.getState();\n if (shouldTransition(latestState)) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n }, 0);\n }\n });\n });\n });\n }\n}\n"]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ExternalActionPlugin: () => ExternalActionPlugin
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var ExternalActionPlugin = class {
27
+ constructor(handler) {
28
+ this.name = "ExternalActionPlugin";
29
+ this.handler = handler;
30
+ }
31
+ apply(player) {
32
+ player.hooks.flowController.tap(this.name, (flowController) => {
33
+ flowController.hooks.flow.tap(this.name, (flow) => {
34
+ flow.hooks.transition.tap(this.name, (fromState, toState) => {
35
+ const { value: state } = toState;
36
+ if (state.state_type === "EXTERNAL") {
37
+ setTimeout(async () => {
38
+ const shouldTransition = (currentState2) => currentState2.status === "in-progress" && currentState2.controllers.flow.current?.currentState?.value === state;
39
+ const currentState = player.getState();
40
+ if (shouldTransition(currentState)) {
41
+ try {
42
+ const transitionValue = await this.handler(
43
+ state,
44
+ currentState.controllers
45
+ );
46
+ if (transitionValue !== void 0) {
47
+ const latestState = player.getState();
48
+ if (shouldTransition(latestState)) {
49
+ latestState.controllers.flow.transition(transitionValue);
50
+ } else {
51
+ player.logger.warn(
52
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
53
+ );
54
+ }
55
+ }
56
+ } catch (error) {
57
+ if (error instanceof Error) {
58
+ currentState.fail(error);
59
+ }
60
+ }
61
+ }
62
+ }, 0);
63
+ }
64
+ });
65
+ });
66
+ });
67
+ }
68
+ };
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ ExternalActionPlugin
72
+ });
73
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowExternalState,\n} from \"@player-ui/player\";\n\nexport type ExternalStateHandler = (\n state: NavigationFlowExternalState,\n options: InProgressState[\"controllers\"],\n) => string | undefined | Promise<string | undefined>;\n\n/**\n * A plugin to handle external actions states\n */\nexport class ExternalActionPlugin implements PlayerPlugin {\n name = \"ExternalActionPlugin\";\n private handler: ExternalStateHandler;\n\n constructor(handler: ExternalStateHandler) {\n this.handler = handler;\n }\n\n apply(player: Player) {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.transition.tap(this.name, (fromState, toState) => {\n const { value: state } = toState;\n if (state.state_type === \"EXTERNAL\") {\n setTimeout(async () => {\n /** Helper for ensuring state is still current relative to external state this is handling */\n const shouldTransition = (\n currentState: PlayerFlowState,\n ): currentState is InProgressState =>\n currentState.status === \"in-progress\" &&\n currentState.controllers.flow.current?.currentState?.value ===\n state;\n\n const currentState = player.getState();\n if (shouldTransition(currentState)) {\n try {\n const transitionValue = await this.handler(\n state,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n // Ensure the Player is still in the same state after waiting for transitionValue\n const latestState = player.getState();\n if (shouldTransition(latestState)) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n }, 0);\n }\n });\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,IAAM,uBAAN,MAAmD;AAAA,EAIxD,YAAY,SAA+B;AAH3C,gBAAO;AAIL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,WAAW,IAAI,KAAK,MAAM,CAAC,WAAW,YAAY;AAC3D,gBAAM,EAAE,OAAO,MAAM,IAAI;AACzB,cAAI,MAAM,eAAe,YAAY;AACnC,uBAAW,YAAY;AAErB,oBAAM,mBAAmB,CACvBA,kBAEAA,cAAa,WAAW,iBACxBA,cAAa,YAAY,KAAK,SAAS,cAAc,UACnD;AAEJ,oBAAM,eAAe,OAAO,SAAS;AACrC,kBAAI,iBAAiB,YAAY,GAAG;AAClC,oBAAI;AACF,wBAAM,kBAAkB,MAAM,KAAK;AAAA,oBACjC;AAAA,oBACA,aAAa;AAAA,kBACf;AAEA,sBAAI,oBAAoB,QAAW;AAEjC,0BAAM,cAAc,OAAO,SAAS;AACpC,wBAAI,iBAAiB,WAAW,GAAG;AACjC,kCAAY,YAAY,KAAK,WAAW,eAAe;AAAA,oBACzD,OAAO;AACL,6BAAO,OAAO;AAAA,wBACZ,iCAAiC,eAAe,8CAA8C,QAAQ,IAAI;AAAA,sBAC5G;AAAA,oBACF;AAAA,kBACF;AAAA,gBACF,SAAS,OAAO;AACd,sBAAI,iBAAiB,OAAO;AAC1B,iCAAa,KAAK,KAAK;AAAA,kBACzB;AAAA,gBACF;AAAA,cACF;AAAA,YACF,GAAG,CAAC;AAAA,UACN;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["currentState"]}
@@ -0,0 +1,48 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
2
+ var ExternalActionPlugin = class {
3
+ constructor(handler) {
4
+ this.name = "ExternalActionPlugin";
5
+ this.handler = handler;
6
+ }
7
+ apply(player) {
8
+ player.hooks.flowController.tap(this.name, (flowController) => {
9
+ flowController.hooks.flow.tap(this.name, (flow) => {
10
+ flow.hooks.transition.tap(this.name, (fromState, toState) => {
11
+ const { value: state } = toState;
12
+ if (state.state_type === "EXTERNAL") {
13
+ setTimeout(async () => {
14
+ const shouldTransition = (currentState2) => currentState2.status === "in-progress" && currentState2.controllers.flow.current?.currentState?.value === state;
15
+ const currentState = player.getState();
16
+ if (shouldTransition(currentState)) {
17
+ try {
18
+ const transitionValue = await this.handler(
19
+ state,
20
+ currentState.controllers
21
+ );
22
+ if (transitionValue !== void 0) {
23
+ const latestState = player.getState();
24
+ if (shouldTransition(latestState)) {
25
+ latestState.controllers.flow.transition(transitionValue);
26
+ } else {
27
+ player.logger.warn(
28
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
29
+ );
30
+ }
31
+ }
32
+ } catch (error) {
33
+ if (error instanceof Error) {
34
+ currentState.fail(error);
35
+ }
36
+ }
37
+ }
38
+ }, 0);
39
+ }
40
+ });
41
+ });
42
+ });
43
+ }
44
+ };
45
+ export {
46
+ ExternalActionPlugin
47
+ };
48
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,48 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
2
+ var ExternalActionPlugin = class {
3
+ constructor(handler) {
4
+ this.name = "ExternalActionPlugin";
5
+ this.handler = handler;
6
+ }
7
+ apply(player) {
8
+ player.hooks.flowController.tap(this.name, (flowController) => {
9
+ flowController.hooks.flow.tap(this.name, (flow) => {
10
+ flow.hooks.transition.tap(this.name, (fromState, toState) => {
11
+ const { value: state } = toState;
12
+ if (state.state_type === "EXTERNAL") {
13
+ setTimeout(async () => {
14
+ const shouldTransition = (currentState2) => currentState2.status === "in-progress" && currentState2.controllers.flow.current?.currentState?.value === state;
15
+ const currentState = player.getState();
16
+ if (shouldTransition(currentState)) {
17
+ try {
18
+ const transitionValue = await this.handler(
19
+ state,
20
+ currentState.controllers
21
+ );
22
+ if (transitionValue !== void 0) {
23
+ const latestState = player.getState();
24
+ if (shouldTransition(latestState)) {
25
+ latestState.controllers.flow.transition(transitionValue);
26
+ } else {
27
+ player.logger.warn(
28
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
29
+ );
30
+ }
31
+ }
32
+ } catch (error) {
33
+ if (error instanceof Error) {
34
+ currentState.fail(error);
35
+ }
36
+ }
37
+ }
38
+ }, 0);
39
+ }
40
+ });
41
+ });
42
+ });
43
+ }
44
+ };
45
+ export {
46
+ ExternalActionPlugin
47
+ };
48
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowExternalState,\n} from \"@player-ui/player\";\n\nexport type ExternalStateHandler = (\n state: NavigationFlowExternalState,\n options: InProgressState[\"controllers\"],\n) => string | undefined | Promise<string | undefined>;\n\n/**\n * A plugin to handle external actions states\n */\nexport class ExternalActionPlugin implements PlayerPlugin {\n name = \"ExternalActionPlugin\";\n private handler: ExternalStateHandler;\n\n constructor(handler: ExternalStateHandler) {\n this.handler = handler;\n }\n\n apply(player: Player) {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.transition.tap(this.name, (fromState, toState) => {\n const { value: state } = toState;\n if (state.state_type === \"EXTERNAL\") {\n setTimeout(async () => {\n /** Helper for ensuring state is still current relative to external state this is handling */\n const shouldTransition = (\n currentState: PlayerFlowState,\n ): currentState is InProgressState =>\n currentState.status === \"in-progress\" &&\n currentState.controllers.flow.current?.currentState?.value ===\n state;\n\n const currentState = player.getState();\n if (shouldTransition(currentState)) {\n try {\n const transitionValue = await this.handler(\n state,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n // Ensure the Player is still in the same state after waiting for transitionValue\n const latestState = player.getState();\n if (shouldTransition(latestState)) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n }, 0);\n }\n });\n });\n });\n }\n}\n"],"mappings":";AAgBO,IAAM,uBAAN,MAAmD;AAAA,EAIxD,YAAY,SAA+B;AAH3C,gBAAO;AAIL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,WAAW,IAAI,KAAK,MAAM,CAAC,WAAW,YAAY;AAC3D,gBAAM,EAAE,OAAO,MAAM,IAAI;AACzB,cAAI,MAAM,eAAe,YAAY;AACnC,uBAAW,YAAY;AAErB,oBAAM,mBAAmB,CACvBA,kBAEAA,cAAa,WAAW,iBACxBA,cAAa,YAAY,KAAK,SAAS,cAAc,UACnD;AAEJ,oBAAM,eAAe,OAAO,SAAS;AACrC,kBAAI,iBAAiB,YAAY,GAAG;AAClC,oBAAI;AACF,wBAAM,kBAAkB,MAAM,KAAK;AAAA,oBACjC;AAAA,oBACA,aAAa;AAAA,kBACf;AAEA,sBAAI,oBAAoB,QAAW;AAEjC,0BAAM,cAAc,OAAO,SAAS;AACpC,wBAAI,iBAAiB,WAAW,GAAG;AACjC,kCAAY,YAAY,KAAK,WAAW,eAAe;AAAA,oBACzD,OAAO;AACL,6BAAO,OAAO;AAAA,wBACZ,iCAAiC,eAAe,8CAA8C,QAAQ,IAAI;AAAA,sBAC5G;AAAA,oBACF;AAAA,kBACF;AAAA,gBACF,SAAS,OAAO;AACd,sBAAI,iBAAiB,OAAO;AAC1B,iCAAa,KAAK,KAAK;AAAA,kBACzB;AAAA,gBACF;AAAA,cACF;AAAA,YACF,GAAG,CAAC;AAAA,UACN;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["currentState"]}
package/package.json CHANGED
@@ -1,66 +1,29 @@
1
1
  {
2
2
  "name": "@player-ui/external-action-plugin",
3
- "version": "0.8.0--canary.307.9621",
4
- "private": false,
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org"
7
- },
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
8
5
  "peerDependencies": {
9
- "@player-ui/player": "0.8.0--canary.307.9621"
10
- },
11
- "dependencies": {
12
- "@babel/runtime": "7.15.4"
6
+ "@player-ui/player": "0.8.0-next.0"
13
7
  },
14
- "main": "dist/index.cjs.js",
15
- "module": "dist/index.esm.js",
16
- "typings": "dist/index.d.ts",
8
+ "module": "dist/index.legacy-esm.js",
9
+ "types": "types/index.d.ts",
10
+ "bundle": "dist/ExternalActionPlugin.native.js",
17
11
  "sideEffects": false,
18
- "license": "MIT",
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/player-ui/player-ui"
22
- },
23
- "bugs": {
24
- "url": "https://github.com/player-ui/player-ui/issues"
25
- },
26
- "homepage": "https://player-ui.github.io",
27
- "contributors": [
28
- {
29
- "name": "Adam Dierkens",
30
- "url": "https://github.com/adierkens"
31
- },
32
- {
33
- "name": "Spencer Hamm",
34
- "url": "https://github.com/spentacular"
35
- },
36
- {
37
- "name": "Harris Borawski",
38
- "url": "https://github.com/hborawski"
39
- },
40
- {
41
- "name": "Jeremiah Zucker",
42
- "url": "https://github.com/sugarmanz"
43
- },
44
- {
45
- "name": "Ketan Reddy",
46
- "url": "https://github.com/KetanReddy"
47
- },
48
- {
49
- "name": "Brocollie08",
50
- "url": "https://github.com/brocollie08"
51
- },
52
- {
53
- "name": "Kelly Harrop",
54
- "url": "https://github.com/kharrop"
55
- },
56
- {
57
- "name": "Alejandro Fimbres",
58
- "url": "https://github.com/lexfm"
59
- },
60
- {
61
- "name": "Rafael Campos",
62
- "url": "https://github.com/rafbcampos"
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ "./dist/index.css": "./dist/index.css",
15
+ ".": {
16
+ "types": "./types/index.d.ts",
17
+ "import": "./dist/index.mjs",
18
+ "default": "./dist/cjs/index.cjs"
63
19
  }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src",
24
+ "types"
64
25
  ],
65
- "bundle": "./dist/external-action-plugin.prod.js"
26
+ "dependencies": {
27
+ "tslib": "^2.6.2"
28
+ }
66
29
  }
@@ -0,0 +1,198 @@
1
+ import { expect, test } from "vitest";
2
+ import type { Flow, InProgressState } from "@player-ui/player";
3
+ import { Player } from "@player-ui/player";
4
+ import { ExternalActionPlugin } from "..";
5
+
6
+ const externalFlow = {
7
+ id: "test-flow",
8
+ data: {
9
+ transitionValue: "Next",
10
+ },
11
+ navigation: {
12
+ BEGIN: "FLOW_1",
13
+ FLOW_1: {
14
+ startState: "EXT_1",
15
+ EXT_1: {
16
+ state_type: "EXTERNAL",
17
+ ref: "test-1",
18
+ transitions: {
19
+ Next: "END_FWD",
20
+ Prev: "END_BCK",
21
+ },
22
+ },
23
+ END_FWD: {
24
+ state_type: "END",
25
+ outcome: "FWD",
26
+ },
27
+ END_BCK: {
28
+ state_type: "END",
29
+ outcome: "BCK",
30
+ },
31
+ },
32
+ },
33
+ };
34
+
35
+ test("handles the external state", async () => {
36
+ const player = new Player({
37
+ plugins: [
38
+ new ExternalActionPlugin((state, options) => {
39
+ return options.data.get("transitionValue");
40
+ }),
41
+ ],
42
+ });
43
+
44
+ const completed = await player.start(externalFlow as Flow);
45
+
46
+ expect(completed.endState.outcome).toBe("FWD");
47
+ });
48
+
49
+ test("thrown errors will fail player", async () => {
50
+ const player = new Player({
51
+ plugins: [
52
+ new ExternalActionPlugin((state, options) => {
53
+ throw new Error("Bad Code");
54
+ }),
55
+ ],
56
+ });
57
+
58
+ await expect(player.start(externalFlow as Flow)).rejects.toThrow();
59
+
60
+ expect(player.getState().status).toBe("error");
61
+ });
62
+
63
+ test("works async", async () => {
64
+ const player = new Player({
65
+ plugins: [
66
+ new ExternalActionPlugin(() => {
67
+ return Promise.resolve("Prev");
68
+ }),
69
+ ],
70
+ });
71
+
72
+ const completed = await player.start(externalFlow as Flow);
73
+
74
+ expect(completed.endState.outcome).toBe("BCK");
75
+ });
76
+
77
+ test("allows multiple plugins", async () => {
78
+ const player = new Player({
79
+ plugins: [
80
+ new ExternalActionPlugin(() => {
81
+ return new Promise((resolve) => {
82
+ setTimeout(() => {
83
+ resolve("Next");
84
+ }, 100);
85
+ });
86
+ }),
87
+ new ExternalActionPlugin(() => {
88
+ return new Promise((resolve) => {
89
+ setTimeout(() => {
90
+ resolve("Prev");
91
+ }, 50);
92
+ });
93
+ }),
94
+ new ExternalActionPlugin(() => {
95
+ return new Promise((resolve) => {
96
+ setTimeout(() => {
97
+ resolve(undefined);
98
+ }, 10);
99
+ });
100
+ }),
101
+ ],
102
+ });
103
+
104
+ const completed = await player.start(externalFlow as Flow);
105
+
106
+ // Prev should win
107
+ expect(completed.endState.outcome).toBe("BCK");
108
+ });
109
+
110
+ test("only transitions if player still on this external state", async () => {
111
+ let resolver: (() => void) | undefined;
112
+ const player = new Player({
113
+ plugins: [
114
+ new ExternalActionPlugin((state, options) => {
115
+ return new Promise((res) => {
116
+ // Only save resolver for first external action
117
+ if (!resolver) {
118
+ resolver = () => {
119
+ res(options.data.get("transitionValue"));
120
+ };
121
+ }
122
+ });
123
+ }),
124
+ ],
125
+ });
126
+
127
+ player.start({
128
+ id: "test-flow",
129
+ data: {
130
+ transitionValue: "Next",
131
+ },
132
+ navigation: {
133
+ BEGIN: "FLOW_1",
134
+ FLOW_1: {
135
+ startState: "EXT_1",
136
+ EXT_1: {
137
+ state_type: "EXTERNAL",
138
+ ref: "test-1",
139
+ transitions: {
140
+ Next: "EXT_2",
141
+ Prev: "END_BCK",
142
+ },
143
+ },
144
+ EXT_2: {
145
+ state_type: "EXTERNAL",
146
+ ref: "test-2",
147
+ transitions: {
148
+ Next: "END_FWD",
149
+ Prev: "END_BCK",
150
+ },
151
+ },
152
+ END_FWD: {
153
+ state_type: "END",
154
+ outcome: "FWD",
155
+ },
156
+ END_BCK: {
157
+ state_type: "END",
158
+ outcome: "BCK",
159
+ },
160
+ },
161
+ },
162
+ } as Flow);
163
+
164
+ let state = player.getState();
165
+ expect(state.status).toBe("in-progress");
166
+ expect(
167
+ (state as InProgressState).controllers.flow.current?.currentState?.name,
168
+ ).toBe("EXT_1");
169
+
170
+ // probably dumb way to wait for async stuff to resolve
171
+ await new Promise<void>((res) => {
172
+ /**
173
+ *
174
+ */
175
+ function waitForResolver() {
176
+ if (resolver) res();
177
+ else setTimeout(waitForResolver, 50);
178
+ }
179
+
180
+ waitForResolver();
181
+ });
182
+
183
+ (state as InProgressState).controllers.flow.transition("Next");
184
+
185
+ state = player.getState();
186
+ expect(
187
+ (state as InProgressState).controllers.flow.current?.currentState?.name,
188
+ ).toBe("EXT_2");
189
+
190
+ // Attempt to resolve _after_ Player has transitioned
191
+ resolver?.();
192
+
193
+ // Should be same as prev
194
+ state = player.getState();
195
+ expect(
196
+ (state as InProgressState).controllers.flow.current?.currentState?.name,
197
+ ).toBe("EXT_2");
198
+ });
package/src/index.ts CHANGED
@@ -3,19 +3,19 @@ import type {
3
3
  PlayerPlugin,
4
4
  InProgressState,
5
5
  PlayerFlowState,
6
- } from '@player-ui/player';
7
- import type { NavigationFlowExternalState } from '@player-ui/types';
6
+ NavigationFlowExternalState,
7
+ } from "@player-ui/player";
8
8
 
9
9
  export type ExternalStateHandler = (
10
10
  state: NavigationFlowExternalState,
11
- options: InProgressState['controllers']
11
+ options: InProgressState["controllers"],
12
12
  ) => string | undefined | Promise<string | undefined>;
13
13
 
14
14
  /**
15
15
  * A plugin to handle external actions states
16
16
  */
17
17
  export class ExternalActionPlugin implements PlayerPlugin {
18
- name = 'ExternalActionPlugin';
18
+ name = "ExternalActionPlugin";
19
19
  private handler: ExternalStateHandler;
20
20
 
21
21
  constructor(handler: ExternalStateHandler) {
@@ -27,13 +27,13 @@ export class ExternalActionPlugin implements PlayerPlugin {
27
27
  flowController.hooks.flow.tap(this.name, (flow) => {
28
28
  flow.hooks.transition.tap(this.name, (fromState, toState) => {
29
29
  const { value: state } = toState;
30
- if (state.state_type === 'EXTERNAL') {
30
+ if (state.state_type === "EXTERNAL") {
31
31
  setTimeout(async () => {
32
32
  /** Helper for ensuring state is still current relative to external state this is handling */
33
33
  const shouldTransition = (
34
- currentState: PlayerFlowState
34
+ currentState: PlayerFlowState,
35
35
  ): currentState is InProgressState =>
36
- currentState.status === 'in-progress' &&
36
+ currentState.status === "in-progress" &&
37
37
  currentState.controllers.flow.current?.currentState?.value ===
38
38
  state;
39
39
 
@@ -42,7 +42,7 @@ export class ExternalActionPlugin implements PlayerPlugin {
42
42
  try {
43
43
  const transitionValue = await this.handler(
44
44
  state,
45
- currentState.controllers
45
+ currentState.controllers,
46
46
  );
47
47
 
48
48
  if (transitionValue !== undefined) {
@@ -52,7 +52,7 @@ export class ExternalActionPlugin implements PlayerPlugin {
52
52
  latestState.controllers.flow.transition(transitionValue);
53
53
  } else {
54
54
  player.logger.warn(
55
- `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
55
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`,
56
56
  );
57
57
  }
58
58
  }
@@ -0,0 +1,12 @@
1
+ import type { Player, PlayerPlugin, InProgressState, NavigationFlowExternalState } from "@player-ui/player";
2
+ export type ExternalStateHandler = (state: NavigationFlowExternalState, options: InProgressState["controllers"]) => string | undefined | Promise<string | undefined>;
3
+ /**
4
+ * A plugin to handle external actions states
5
+ */
6
+ export declare class ExternalActionPlugin implements PlayerPlugin {
7
+ name: string;
8
+ private handler;
9
+ constructor(handler: ExternalStateHandler);
10
+ apply(player: Player): void;
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -1,178 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
4
- else if(typeof define === 'function' && define.amd)
5
- define([], factory);
6
- else if(typeof exports === 'object')
7
- exports["ExternalActionPlugin"] = factory();
8
- else
9
- root["ExternalActionPlugin"] = factory();
10
- })(this, function() {
11
- return /******/ (function(modules) { // webpackBootstrap
12
- /******/ // The module cache
13
- /******/ var installedModules = {};
14
- /******/
15
- /******/ // The require function
16
- /******/ function __webpack_require__(moduleId) {
17
- /******/
18
- /******/ // Check if module is in cache
19
- /******/ if(installedModules[moduleId]) {
20
- /******/ return installedModules[moduleId].exports;
21
- /******/ }
22
- /******/ // Create a new module (and put it into the cache)
23
- /******/ var module = installedModules[moduleId] = {
24
- /******/ i: moduleId,
25
- /******/ l: false,
26
- /******/ exports: {}
27
- /******/ };
28
- /******/
29
- /******/ // Execute the module function
30
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
- /******/
32
- /******/ // Flag the module as loaded
33
- /******/ module.l = true;
34
- /******/
35
- /******/ // Return the exports of the module
36
- /******/ return module.exports;
37
- /******/ }
38
- /******/
39
- /******/
40
- /******/ // expose the modules object (__webpack_modules__)
41
- /******/ __webpack_require__.m = modules;
42
- /******/
43
- /******/ // expose the module cache
44
- /******/ __webpack_require__.c = installedModules;
45
- /******/
46
- /******/ // define getter function for harmony exports
47
- /******/ __webpack_require__.d = function(exports, name, getter) {
48
- /******/ if(!__webpack_require__.o(exports, name)) {
49
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50
- /******/ }
51
- /******/ };
52
- /******/
53
- /******/ // define __esModule on exports
54
- /******/ __webpack_require__.r = function(exports) {
55
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57
- /******/ }
58
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
59
- /******/ };
60
- /******/
61
- /******/ // create a fake namespace object
62
- /******/ // mode & 1: value is a module id, require it
63
- /******/ // mode & 2: merge all properties of value into the ns
64
- /******/ // mode & 4: return value when already ns object
65
- /******/ // mode & 8|1: behave like require
66
- /******/ __webpack_require__.t = function(value, mode) {
67
- /******/ if(mode & 1) value = __webpack_require__(value);
68
- /******/ if(mode & 8) return value;
69
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70
- /******/ var ns = Object.create(null);
71
- /******/ __webpack_require__.r(ns);
72
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74
- /******/ return ns;
75
- /******/ };
76
- /******/
77
- /******/ // getDefaultExport function for compatibility with non-harmony modules
78
- /******/ __webpack_require__.n = function(module) {
79
- /******/ var getter = module && module.__esModule ?
80
- /******/ function getDefault() { return module['default']; } :
81
- /******/ function getModuleExports() { return module; };
82
- /******/ __webpack_require__.d(getter, 'a', getter);
83
- /******/ return getter;
84
- /******/ };
85
- /******/
86
- /******/ // Object.prototype.hasOwnProperty.call
87
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88
- /******/
89
- /******/ // __webpack_public_path__
90
- /******/ __webpack_require__.p = "";
91
- /******/
92
- /******/
93
- /******/ // Load entry module and return exports
94
- /******/ return __webpack_require__(__webpack_require__.s = "./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js");
95
- /******/ })
96
- /************************************************************************/
97
- /******/ ({
98
-
99
- /***/ "./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js":
100
- /*!***********************************************************************************!*\
101
- !*** ./bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.esm.js ***!
102
- \***********************************************************************************/
103
- /*! exports provided: ExternalActionPlugin */
104
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
105
-
106
- "use strict";
107
- __webpack_require__.r(__webpack_exports__);
108
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExternalActionPlugin", function() { return ExternalActionPlugin; });
109
- var __async = (__this, __arguments, generator) => {
110
- return new Promise((resolve, reject) => {
111
- var fulfilled = (value) => {
112
- try {
113
- step(generator.next(value));
114
- } catch (e) {
115
- reject(e);
116
- }
117
- };
118
- var rejected = (value) => {
119
- try {
120
- step(generator.throw(value));
121
- } catch (e) {
122
- reject(e);
123
- }
124
- };
125
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
126
- step((generator = generator.apply(__this, __arguments)).next());
127
- });
128
- };
129
- class ExternalActionPlugin {
130
- constructor(handler) {
131
- this.name = "ExternalActionPlugin";
132
- this.handler = handler;
133
- }
134
- apply(player) {
135
- player.hooks.flowController.tap(this.name, (flowController) => {
136
- flowController.hooks.flow.tap(this.name, (flow) => {
137
- flow.hooks.transition.tap(this.name, (fromState, toState) => {
138
- const { value: state } = toState;
139
- if (state.state_type === "EXTERNAL") {
140
- setTimeout(() => __async(this, null, function* () {
141
- const shouldTransition = (currentState2) => {
142
- var _a, _b;
143
- return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
144
- };
145
- const currentState = player.getState();
146
- if (shouldTransition(currentState)) {
147
- try {
148
- const transitionValue = yield this.handler(state, currentState.controllers);
149
- if (transitionValue !== void 0) {
150
- const latestState = player.getState();
151
- if (shouldTransition(latestState)) {
152
- latestState.controllers.flow.transition(transitionValue);
153
- } else {
154
- player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
155
- }
156
- }
157
- } catch (error) {
158
- if (error instanceof Error) {
159
- currentState.fail(error);
160
- }
161
- }
162
- }
163
- }), 0);
164
- }
165
- });
166
- });
167
- });
168
- }
169
- }
170
-
171
-
172
- //# sourceMappingURL=index.esm.js.map
173
-
174
-
175
- /***/ })
176
-
177
- /******/ });
178
- });
@@ -1 +0,0 @@
1
- !function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports.ExternalActionPlugin=e():t.ExternalActionPlugin=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e),n.d(e,"ExternalActionPlugin",(function(){return r}));class r{constructor(t){this.name="ExternalActionPlugin",this.handler=t}apply(t){t.hooks.flowController.tap(this.name,(e=>{e.hooks.flow.tap(this.name,(e=>{e.hooks.transition.tap(this.name,((e,n)=>{const{value:r}=n;"EXTERNAL"===r.state_type&&setTimeout((()=>{return e=this,o=null,i=function*(){const e=t=>{var e,n;return"in-progress"===t.status&&(null==(n=null==(e=t.controllers.flow.current)?void 0:e.currentState)?void 0:n.value)===r},o=t.getState();if(e(o))try{const i=yield this.handler(r,o.controllers);if(void 0!==i){const r=t.getState();e(r)?r.controllers.flow.transition(i):t.logger.warn(`External state resolved with [${i}], but Player already navigated away from [${n.name}]`)}}catch(i){i instanceof Error&&o.fail(i)}},new Promise(((t,n)=>{var r=t=>{try{a(i.next(t))}catch(e){n(e)}},l=t=>{try{a(i.throw(t))}catch(e){n(e)}},a=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,l);a((i=i.apply(e,o)).next())}));var e,o,i}),0)}))}))}))}}}])}));
package/dist/index.cjs.js DELETED
@@ -1,68 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var __async = (__this, __arguments, generator) => {
6
- return new Promise((resolve, reject) => {
7
- var fulfilled = (value) => {
8
- try {
9
- step(generator.next(value));
10
- } catch (e) {
11
- reject(e);
12
- }
13
- };
14
- var rejected = (value) => {
15
- try {
16
- step(generator.throw(value));
17
- } catch (e) {
18
- reject(e);
19
- }
20
- };
21
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
- step((generator = generator.apply(__this, __arguments)).next());
23
- });
24
- };
25
- class ExternalActionPlugin {
26
- constructor(handler) {
27
- this.name = "ExternalActionPlugin";
28
- this.handler = handler;
29
- }
30
- apply(player) {
31
- player.hooks.flowController.tap(this.name, (flowController) => {
32
- flowController.hooks.flow.tap(this.name, (flow) => {
33
- flow.hooks.transition.tap(this.name, (fromState, toState) => {
34
- const { value: state } = toState;
35
- if (state.state_type === "EXTERNAL") {
36
- setTimeout(() => __async(this, null, function* () {
37
- const shouldTransition = (currentState2) => {
38
- var _a, _b;
39
- return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
40
- };
41
- const currentState = player.getState();
42
- if (shouldTransition(currentState)) {
43
- try {
44
- const transitionValue = yield this.handler(state, currentState.controllers);
45
- if (transitionValue !== void 0) {
46
- const latestState = player.getState();
47
- if (shouldTransition(latestState)) {
48
- latestState.controllers.flow.transition(transitionValue);
49
- } else {
50
- player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
51
- }
52
- }
53
- } catch (error) {
54
- if (error instanceof Error) {
55
- currentState.fail(error);
56
- }
57
- }
58
- }
59
- }), 0);
60
- }
61
- });
62
- });
63
- });
64
- }
65
- }
66
-
67
- exports.ExternalActionPlugin = ExternalActionPlugin;
68
- //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { InProgressState, PlayerPlugin, Player } from '@player-ui/player';
2
- import { NavigationFlowExternalState } from '@player-ui/types';
3
-
4
- declare type ExternalStateHandler = (state: NavigationFlowExternalState, options: InProgressState['controllers']) => string | undefined | Promise<string | undefined>;
5
- /**
6
- * A plugin to handle external actions states
7
- */
8
- declare class ExternalActionPlugin implements PlayerPlugin {
9
- name: string;
10
- private handler;
11
- constructor(handler: ExternalStateHandler);
12
- apply(player: Player): void;
13
- }
14
-
15
- export { ExternalActionPlugin, ExternalStateHandler };
package/dist/index.esm.js DELETED
@@ -1,64 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- class ExternalActionPlugin {
22
- constructor(handler) {
23
- this.name = "ExternalActionPlugin";
24
- this.handler = handler;
25
- }
26
- apply(player) {
27
- player.hooks.flowController.tap(this.name, (flowController) => {
28
- flowController.hooks.flow.tap(this.name, (flow) => {
29
- flow.hooks.transition.tap(this.name, (fromState, toState) => {
30
- const { value: state } = toState;
31
- if (state.state_type === "EXTERNAL") {
32
- setTimeout(() => __async(this, null, function* () {
33
- const shouldTransition = (currentState2) => {
34
- var _a, _b;
35
- return currentState2.status === "in-progress" && ((_b = (_a = currentState2.controllers.flow.current) == null ? void 0 : _a.currentState) == null ? void 0 : _b.value) === state;
36
- };
37
- const currentState = player.getState();
38
- if (shouldTransition(currentState)) {
39
- try {
40
- const transitionValue = yield this.handler(state, currentState.controllers);
41
- if (transitionValue !== void 0) {
42
- const latestState = player.getState();
43
- if (shouldTransition(latestState)) {
44
- latestState.controllers.flow.transition(transitionValue);
45
- } else {
46
- player.logger.warn(`External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`);
47
- }
48
- }
49
- } catch (error) {
50
- if (error instanceof Error) {
51
- currentState.fail(error);
52
- }
53
- }
54
- }
55
- }), 0);
56
- }
57
- });
58
- });
59
- });
60
- }
61
- }
62
-
63
- export { ExternalActionPlugin };
64
- //# sourceMappingURL=index.esm.js.map