@player-ui/external-action-plugin 0.15.2-next.2 → 0.15.2-next.3

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.
@@ -150,6 +150,12 @@ function _ts_generator(thisArg, body) {
150
150
  }
151
151
  }
152
152
  var ExternalActionPlugin = function() {
153
+ var isExternal = function isExternal(state) {
154
+ return state.state_type === "EXTERNAL";
155
+ };
156
+ var isInProgress = function isInProgress(state) {
157
+ return state.status === "in-progress";
158
+ };
153
159
  var __defProp = Object.defineProperty;
154
160
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
155
161
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -216,68 +222,61 @@ var ExternalActionPlugin = function() {
216
222
  var _this = this;
217
223
  player.hooks.flowController.tap(this.name, function(flowController) {
218
224
  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
- setTimeout(function() {
223
- return _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
- this.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
- ];
225
+ flow.hooks.afterTransition.tap(_this.name, function(flowInstance) {
226
+ return _async_to_generator(function() {
227
+ var state, currentState, transitionValue, _latestState_controllers_flow_current_currentState, _latestState_controllers_flow_current, latestState, error;
228
+ return _ts_generator(this, function(_state) {
229
+ switch(_state.label){
230
+ case 0:
231
+ state = flowInstance.currentState;
232
+ currentState = player.getState();
233
+ if (!(state && state.value && isExternal(state.value) && isInProgress(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
+ this.handler(state.value, currentState.controllers)
248
+ ];
249
+ case 2:
250
+ transitionValue = _state.sent();
251
+ if (transitionValue !== void 0) {
252
+ ;
253
+ latestState = player.getState();
254
+ if (isInProgress(latestState) && ((_latestState_controllers_flow_current = latestState.controllers.flow.current) === null || _latestState_controllers_flow_current === void 0 ? void 0 : (_latestState_controllers_flow_current_currentState = _latestState_controllers_flow_current.currentState) === null || _latestState_controllers_flow_current_currentState === void 0 ? void 0 : _latestState_controllers_flow_current_currentState.name) === state.name) {
255
+ latestState.controllers.flow.transition(transitionValue);
256
+ } else {
257
+ player.logger.warn("External state resolved with [".concat(transitionValue, "], but Player already navigated away from [").concat(state.name, "]"));
258
+ }
259
+ }
260
+ return [
261
+ 3,
262
+ 4
263
+ ];
264
+ case 3:
265
+ error = _state.sent();
266
+ if (_instanceof(error, Error)) {
267
+ currentState.fail(error);
276
268
  }
277
- });
278
- }).call(_this);
279
- }, 0);
280
- }
269
+ return [
270
+ 3,
271
+ 4
272
+ ];
273
+ case 4:
274
+ return [
275
+ 2
276
+ ];
277
+ }
278
+ });
279
+ }).call(_this);
281
280
  });
282
281
  });
283
282
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2525/execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.global.js","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts"],"names":["ExternalActionPlugin","__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","src_exports","handler","apply","player","hooks","flowController","tap","flow","transition","fromState","toState","state","state_type","setTimeout","shouldTransition","currentState","transitionValue","latestState","error","status","controllers","current","getState","logger","warn","Error","fail"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,uBAAuB,AAAC;IAC1B,IAAIC,YAAYC,OAAOC,cAAc;IACrC,IAAIC,mBAAmBF,OAAOG,wBAAwB;IACtD,IAAIC,oBAAoBJ,OAAOK,mBAAmB;IAClD,IAAIC,eAAeN,OAAOO,SAAS,CAACC,cAAc;IAClD,IAAIC,WAAW,SAACC,QAAQC;QACtB,IAAK,IAAIC,QAAQD,IACfZ,UAAUW,QAAQE,MAAM;YAAEC,KAAKF,GAAG,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jBX;gCACR,IAAIY,MAAMC,UAAA,KAAe,YAAY;oCACnCC,WAAW;;gDAEHC,kBAOAC,cAGIC,iBAOEC,aASDC;;;;wDA1BLJ,mBAAmB,SACvBC;gEAGAA,sDAAAA;mEADAA,cAAaI,MAAA,KAAW,iBACxBJ,EAAAA,0CAAAA,cAAaK,WAAA,CAAYb,IAAA,CAAKc,OAAA,cAA9BN,+DAAAA,uDAAAA,wCAAuCA,YAAA,cAAvCA,2EAAAA,qDAAqDhB,KAAA,MACnDY;;wDAEEI,eAAeZ,OAAOmB,QAAA;6DACxBR,iBAAiBC,eAAjBD;;;;;;;;;;;;wDAEwB;;4DAAM,IAAA,CAAKb,OAAA,CACjCU,OACAI,aAAaK,WAAA;;;wDAFTJ,kBAAkB;wDAKxB,IAAIA,oBAAoB,KAAA,GAAW;4DAE3BC,cAAcd,OAAOmB,QAAA;4DAC3B,IAAIR,iBAAiBG,cAAc;gEACjCA,YAAYG,WAAA,CAAYb,IAAA,CAAKC,UAAA,CAAWQ;4DAC1C,OAAO;gEACLb,OAAOoB,MAAA,CAAOC,IAAA,CACZ,iCAA8Fd,OAA7DM,iBAAe,+CAA0D,OAAZN,QAAQvB,IAAI,EAAA;4DAE9G;wDACF;;;;;;wDACO+B;wDACP,IAAIA,AAAA,YAAAA,OAAiBO,QAAO;4DAC1BV,aAAaW,IAAA,CAAKR;wDACpB;;;;;;;;;;;wCAGN;uCAAG;gCACL;4BACF;wBACF;oBACF;gBACF;;;;;IDDA,OAAOrB,aAAaG;AACtB","sourcesContent":["\"use strict\";\nvar ExternalActionPlugin = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n ExternalActionPlugin: () => ExternalActionPlugin\n });\n var ExternalActionPlugin = class {\n constructor(handler) {\n this.name = \"ExternalActionPlugin\";\n this.handler = handler;\n }\n apply(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 const shouldTransition = (currentState2) => currentState2.status === \"in-progress\" && currentState2.controllers.flow.current?.currentState?.value === state;\n const currentState = player.getState();\n if (shouldTransition(currentState)) {\n try {\n const transitionValue = await this.handler(\n state,\n currentState.controllers\n );\n if (transitionValue !== void 0) {\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 return __toCommonJS(src_exports);\n})();\n","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"]}
1
+ {"version":3,"sources":["/home/circleci/.cache/bazel/_bazel_circleci/e8362d362e14c7d23506d1dfa3aea8b8/sandbox/processwrapper-sandbox/2543/execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/dist/index.global.js","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts"],"names":["ExternalActionPlugin","isExternal","state","state_type","isInProgress","status","__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","src_exports","handler","apply","player","hooks","flowController","tap","flow","afterTransition","flowInstance","currentState","transitionValue","latestState","error","getState","controllers","current","transition","logger","warn","Error","fail"],"mappings":"AAAA;;;;;;;;;;;;;;;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MAAA,CAAOC,IAAA,CACZ,iCAA8FjD,OAA7DyC,iBAAe,+CAAwD,OAAVzC,MAAMiB,IAAI,EAAA;oDAE5G;gDACF;;;;;;gDACO0B;gDACP,IAAIA,AAAA,YAAAA,OAAiBO,QAAO;oDAC1BV,aAAaW,IAAA,CAAKR;gDACpB;;;;;;;;;;;gCAGN;;wBACF;oBACF;gBACF;;;;;IDVA,OAAOhB,aAAaG;AACtB","sourcesContent":["\"use strict\";\nvar ExternalActionPlugin = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts\n var src_exports = {};\n __export(src_exports, {\n ExternalActionPlugin: () => ExternalActionPlugin\n });\n function isExternal(state) {\n return state.state_type === \"EXTERNAL\";\n }\n function isInProgress(state) {\n return state.status === \"in-progress\";\n }\n var ExternalActionPlugin = class {\n constructor(handler) {\n this.name = \"ExternalActionPlugin\";\n this.handler = handler;\n }\n apply(player) {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {\n const state = flowInstance.currentState;\n const currentState = player.getState();\n if (state && state.value && isExternal(state.value) && isInProgress(currentState)) {\n try {\n const transitionValue = await this.handler(\n state.value,\n currentState.controllers\n );\n if (transitionValue !== void 0) {\n const latestState = player.getState();\n if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === state.name) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n });\n });\n });\n }\n };\n return __toCommonJS(src_exports);\n})();\n","import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowState,\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\nfunction isExternal(\n state: NavigationFlowState,\n): state is NavigationFlowExternalState {\n return state.state_type === \"EXTERNAL\";\n}\n\nfunction isInProgress(state: PlayerFlowState): state is InProgressState {\n return state.status === \"in-progress\";\n}\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): void {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {\n const state = flowInstance.currentState;\n const currentState = player.getState();\n\n if (\n state &&\n state.value &&\n isExternal(state.value) &&\n isInProgress(currentState)\n ) {\n try {\n const transitionValue = await this.handler(\n state.value,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n const latestState = player.getState();\n\n // Ensure the Player is still in the same state after waiting for transitionValue\n if (\n isInProgress(latestState) &&\n latestState.controllers.flow.current?.currentState?.name ===\n state.name\n ) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n });\n });\n });\n }\n}\n"]}
@@ -23,6 +23,12 @@ __export(src_exports, {
23
23
  ExternalActionPlugin: () => ExternalActionPlugin
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
+ function isExternal(state) {
27
+ return state.state_type === "EXTERNAL";
28
+ }
29
+ function isInProgress(state) {
30
+ return state.status === "in-progress";
31
+ }
26
32
  var ExternalActionPlugin = class {
27
33
  constructor(handler) {
28
34
  this.name = "ExternalActionPlugin";
@@ -31,35 +37,30 @@ var ExternalActionPlugin = class {
31
37
  apply(player) {
32
38
  player.hooks.flowController.tap(this.name, (flowController) => {
33
39
  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
40
+ flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {
41
+ const state = flowInstance.currentState;
42
+ const currentState = player.getState();
43
+ if (state && state.value && isExternal(state.value) && isInProgress(currentState)) {
44
+ try {
45
+ const transitionValue = await this.handler(
46
+ state.value,
47
+ currentState.controllers
48
+ );
49
+ if (transitionValue !== void 0) {
50
+ const latestState = player.getState();
51
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === state.name) {
52
+ latestState.controllers.flow.transition(transitionValue);
53
+ } else {
54
+ player.logger.warn(
55
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`
45
56
  );
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
57
  }
61
58
  }
62
- }, 0);
59
+ } catch (error) {
60
+ if (error instanceof Error) {
61
+ currentState.fail(error);
62
+ }
63
+ }
63
64
  }
64
65
  });
65
66
  });
@@ -1 +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) {\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AACF;","names":["currentState"]}
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 NavigationFlowState,\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\nfunction isExternal(\n state: NavigationFlowState,\n): state is NavigationFlowExternalState {\n return state.state_type === \"EXTERNAL\";\n}\n\nfunction isInProgress(state: PlayerFlowState): state is InProgressState {\n return state.status === \"in-progress\";\n}\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): void {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {\n const state = flowInstance.currentState;\n const currentState = player.getState();\n\n if (\n state &&\n state.value &&\n isExternal(state.value) &&\n isInProgress(currentState)\n ) {\n try {\n const transitionValue = await this.handler(\n state.value,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n const latestState = player.getState();\n\n // Ensure the Player is still in the same state after waiting for transitionValue\n if (\n isInProgress(latestState) &&\n latestState.controllers.flow.current?.currentState?.name ===\n state.name\n ) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n });\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,SAAS,WACP,OACsC;AACtC,SAAO,MAAM,eAAe;AAC9B;AAEA,SAAS,aAAa,OAAkD;AACtE,SAAO,MAAM,WAAW;AAC1B;AAKO,IAAM,uBAAN,MAAmD;AAAA,EAIxD,YAAY,SAA+B;AAH3C,gBAAO;AAIL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAsB;AAC1B,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,gBAAgB,IAAI,KAAK,MAAM,OAAO,iBAAiB;AAChE,gBAAM,QAAQ,aAAa;AAC3B,gBAAM,eAAe,OAAO,SAAS;AAErC,cACE,SACA,MAAM,SACN,WAAW,MAAM,KAAK,KACtB,aAAa,YAAY,GACzB;AACA,gBAAI;AACF,oBAAM,kBAAkB,MAAM,KAAK;AAAA,gBACjC,MAAM;AAAA,gBACN,aAAa;AAAA,cACf;AAEA,kBAAI,oBAAoB,QAAW;AACjC,sBAAM,cAAc,OAAO,SAAS;AAGpC,oBACE,aAAa,WAAW,KACxB,YAAY,YAAY,KAAK,SAAS,cAAc,SAClD,MAAM,MACR;AACA,8BAAY,YAAY,KAAK,WAAW,eAAe;AAAA,gBACzD,OAAO;AACL,yBAAO,OAAO;AAAA,oBACZ,iCAAiC,eAAe,8CAA8C,MAAM,IAAI;AAAA,kBAC1G;AAAA,gBACF;AAAA,cACF;AAAA,YACF,SAAS,OAAO;AACd,kBAAI,iBAAiB,OAAO;AAC1B,6BAAa,KAAK,KAAK;AAAA,cACzB;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,4 +1,10 @@
1
1
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
2
+ function isExternal(state) {
3
+ return state.state_type === "EXTERNAL";
4
+ }
5
+ function isInProgress(state) {
6
+ return state.status === "in-progress";
7
+ }
2
8
  var ExternalActionPlugin = class {
3
9
  constructor(handler) {
4
10
  this.name = "ExternalActionPlugin";
@@ -7,35 +13,30 @@ var ExternalActionPlugin = class {
7
13
  apply(player) {
8
14
  player.hooks.flowController.tap(this.name, (flowController) => {
9
15
  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
16
+ flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {
17
+ const state = flowInstance.currentState;
18
+ const currentState = player.getState();
19
+ if (state && state.value && isExternal(state.value) && isInProgress(currentState)) {
20
+ try {
21
+ const transitionValue = await this.handler(
22
+ state.value,
23
+ currentState.controllers
24
+ );
25
+ if (transitionValue !== void 0) {
26
+ const latestState = player.getState();
27
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === state.name) {
28
+ latestState.controllers.flow.transition(transitionValue);
29
+ } else {
30
+ player.logger.warn(
31
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`
21
32
  );
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
33
  }
37
34
  }
38
- }, 0);
35
+ } catch (error) {
36
+ if (error instanceof Error) {
37
+ currentState.fail(error);
38
+ }
39
+ }
39
40
  }
40
41
  });
41
42
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,10 @@
1
1
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-action/core/src/index.ts
2
+ function isExternal(state) {
3
+ return state.state_type === "EXTERNAL";
4
+ }
5
+ function isInProgress(state) {
6
+ return state.status === "in-progress";
7
+ }
2
8
  var ExternalActionPlugin = class {
3
9
  constructor(handler) {
4
10
  this.name = "ExternalActionPlugin";
@@ -7,35 +13,30 @@ var ExternalActionPlugin = class {
7
13
  apply(player) {
8
14
  player.hooks.flowController.tap(this.name, (flowController) => {
9
15
  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
16
+ flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {
17
+ const state = flowInstance.currentState;
18
+ const currentState = player.getState();
19
+ if (state && state.value && isExternal(state.value) && isInProgress(currentState)) {
20
+ try {
21
+ const transitionValue = await this.handler(
22
+ state.value,
23
+ currentState.controllers
24
+ );
25
+ if (transitionValue !== void 0) {
26
+ const latestState = player.getState();
27
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === state.name) {
28
+ latestState.controllers.flow.transition(transitionValue);
29
+ } else {
30
+ player.logger.warn(
31
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`
21
32
  );
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
33
  }
37
34
  }
38
- }, 0);
35
+ } catch (error) {
36
+ if (error instanceof Error) {
37
+ currentState.fail(error);
38
+ }
39
+ }
39
40
  }
40
41
  });
41
42
  });
@@ -1 +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"]}
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 NavigationFlowState,\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\nfunction isExternal(\n state: NavigationFlowState,\n): state is NavigationFlowExternalState {\n return state.state_type === \"EXTERNAL\";\n}\n\nfunction isInProgress(state: PlayerFlowState): state is InProgressState {\n return state.status === \"in-progress\";\n}\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): void {\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {\n const state = flowInstance.currentState;\n const currentState = player.getState();\n\n if (\n state &&\n state.value &&\n isExternal(state.value) &&\n isInProgress(currentState)\n ) {\n try {\n const transitionValue = await this.handler(\n state.value,\n currentState.controllers,\n );\n\n if (transitionValue !== undefined) {\n const latestState = player.getState();\n\n // Ensure the Player is still in the same state after waiting for transitionValue\n if (\n isInProgress(latestState) &&\n latestState.controllers.flow.current?.currentState?.name ===\n state.name\n ) {\n latestState.controllers.flow.transition(transitionValue);\n } else {\n player.logger.warn(\n `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`,\n );\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n });\n });\n });\n }\n}\n"],"mappings":";AAcA,SAAS,WACP,OACsC;AACtC,SAAO,MAAM,eAAe;AAC9B;AAEA,SAAS,aAAa,OAAkD;AACtE,SAAO,MAAM,WAAW;AAC1B;AAKO,IAAM,uBAAN,MAAmD;AAAA,EAIxD,YAAY,SAA+B;AAH3C,gBAAO;AAIL,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAsB;AAC1B,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,SAAS;AACjD,aAAK,MAAM,gBAAgB,IAAI,KAAK,MAAM,OAAO,iBAAiB;AAChE,gBAAM,QAAQ,aAAa;AAC3B,gBAAM,eAAe,OAAO,SAAS;AAErC,cACE,SACA,MAAM,SACN,WAAW,MAAM,KAAK,KACtB,aAAa,YAAY,GACzB;AACA,gBAAI;AACF,oBAAM,kBAAkB,MAAM,KAAK;AAAA,gBACjC,MAAM;AAAA,gBACN,aAAa;AAAA,cACf;AAEA,kBAAI,oBAAoB,QAAW;AACjC,sBAAM,cAAc,OAAO,SAAS;AAGpC,oBACE,aAAa,WAAW,KACxB,YAAY,YAAY,KAAK,SAAS,cAAc,SAClD,MAAM,MACR;AACA,8BAAY,YAAY,KAAK,WAAW,eAAe;AAAA,gBACzD,OAAO;AACL,yBAAO,OAAO;AAAA,oBACZ,iCAAiC,eAAe,8CAA8C,MAAM,IAAI;AAAA,kBAC1G;AAAA,gBACF;AAAA,cACF;AAAA,YACF,SAAS,OAAO;AACd,kBAAI,iBAAiB,OAAO;AAC1B,6BAAa,KAAK,KAAK;AAAA,cACzB;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
package/package.json CHANGED
@@ -6,10 +6,10 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/external-action-plugin",
9
- "version": "0.15.2-next.2",
9
+ "version": "0.15.2-next.3",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "peerDependencies": {
12
- "@player-ui/player": "0.15.2-next.2"
12
+ "@player-ui/player": "0.15.2-next.3"
13
13
  },
14
14
  "module": "dist/index.legacy-esm.js",
15
15
  "types": "types/index.d.ts",
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  PlayerPlugin,
4
4
  InProgressState,
5
5
  PlayerFlowState,
6
+ NavigationFlowState,
6
7
  NavigationFlowExternalState,
7
8
  } from "@player-ui/player";
8
9
 
@@ -11,6 +12,16 @@ export type ExternalStateHandler = (
11
12
  options: InProgressState["controllers"],
12
13
  ) => string | undefined | Promise<string | undefined>;
13
14
 
15
+ function isExternal(
16
+ state: NavigationFlowState,
17
+ ): state is NavigationFlowExternalState {
18
+ return state.state_type === "EXTERNAL";
19
+ }
20
+
21
+ function isInProgress(state: PlayerFlowState): state is InProgressState {
22
+ return state.status === "in-progress";
23
+ }
24
+
14
25
  /**
15
26
  * A plugin to handle external actions states
16
27
  */
@@ -22,47 +33,46 @@ export class ExternalActionPlugin implements PlayerPlugin {
22
33
  this.handler = handler;
23
34
  }
24
35
 
25
- apply(player: Player) {
36
+ apply(player: Player): void {
26
37
  player.hooks.flowController.tap(this.name, (flowController) => {
27
38
  flowController.hooks.flow.tap(this.name, (flow) => {
28
- flow.hooks.transition.tap(this.name, (fromState, toState) => {
29
- const { value: state } = toState;
30
- if (state.state_type === "EXTERNAL") {
31
- setTimeout(async () => {
32
- /** Helper for ensuring state is still current relative to external state this is handling */
33
- const shouldTransition = (
34
- currentState: PlayerFlowState,
35
- ): currentState is InProgressState =>
36
- currentState.status === "in-progress" &&
37
- currentState.controllers.flow.current?.currentState?.value ===
38
- state;
39
+ flow.hooks.afterTransition.tap(this.name, async (flowInstance) => {
40
+ const state = flowInstance.currentState;
41
+ const currentState = player.getState();
39
42
 
40
- const currentState = player.getState();
41
- if (shouldTransition(currentState)) {
42
- try {
43
- const transitionValue = await this.handler(
44
- state,
45
- currentState.controllers,
46
- );
43
+ if (
44
+ state &&
45
+ state.value &&
46
+ isExternal(state.value) &&
47
+ isInProgress(currentState)
48
+ ) {
49
+ try {
50
+ const transitionValue = await this.handler(
51
+ state.value,
52
+ currentState.controllers,
53
+ );
54
+
55
+ if (transitionValue !== undefined) {
56
+ const latestState = player.getState();
47
57
 
48
- if (transitionValue !== undefined) {
49
- // Ensure the Player is still in the same state after waiting for transitionValue
50
- const latestState = player.getState();
51
- if (shouldTransition(latestState)) {
52
- latestState.controllers.flow.transition(transitionValue);
53
- } else {
54
- player.logger.warn(
55
- `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`,
56
- );
57
- }
58
- }
59
- } catch (error) {
60
- if (error instanceof Error) {
61
- currentState.fail(error);
62
- }
58
+ // Ensure the Player is still in the same state after waiting for transitionValue
59
+ if (
60
+ isInProgress(latestState) &&
61
+ latestState.controllers.flow.current?.currentState?.name ===
62
+ state.name
63
+ ) {
64
+ latestState.controllers.flow.transition(transitionValue);
65
+ } else {
66
+ player.logger.warn(
67
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${state.name}]`,
68
+ );
63
69
  }
64
70
  }
65
- }, 0);
71
+ } catch (error) {
72
+ if (error instanceof Error) {
73
+ currentState.fail(error);
74
+ }
75
+ }
66
76
  }
67
77
  });
68
78
  });