@player-ui/external-state-plugin 0.15.4--canary.881.37421

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,196 @@
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-state/core/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ExternalStateError: () => ExternalStateError,
24
+ ExternalStatePlugin: () => ExternalStatePlugin
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+ var import_partial_match_registry = require("@player-ui/partial-match-registry");
28
+
29
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/symbols.ts
30
+ var ExternalStatePluginSymbol = Symbol.for(
31
+ "@player-ui/ExternalStatePlugin"
32
+ );
33
+
34
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/ExternalStateError.ts
35
+ var import_player = require("@player-ui/player");
36
+ var ExternalStateError = class _ExternalStateError extends Error {
37
+ constructor(message, metadata) {
38
+ super(message);
39
+ this.type = import_player.ErrorTypes.EXTERNAL_STATE;
40
+ this.severity = import_player.ErrorSeverity.ERROR;
41
+ this.metadata = metadata;
42
+ }
43
+ /** No handler was registered for the EXTERNAL state's ref. */
44
+ static missingHandler(ref) {
45
+ return new _ExternalStateError(
46
+ `No handler found for external state with ref: "${ref}". Ensure a handler is registered for this state.`,
47
+ { ref, reason: "missing-handler" }
48
+ );
49
+ }
50
+ /** A handler ran but returned no transition value. */
51
+ static missingTransitionValue(ref) {
52
+ return new _ExternalStateError(
53
+ `Handler for external state with ref: "${ref}" did not return a transition value. Ensure the handler returns the name of a valid transition.`,
54
+ { ref, reason: "missing-transition-value" }
55
+ );
56
+ }
57
+ };
58
+
59
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts
60
+ function isExternal(state) {
61
+ return state.state_type === "EXTERNAL";
62
+ }
63
+ function isInProgress(state) {
64
+ return state.status === "in-progress";
65
+ }
66
+ var _ExternalStatePlugin = class _ExternalStatePlugin {
67
+ /** Creates a new ExternalStatePlugin */
68
+ constructor(handlers) {
69
+ this.name = "ExternalStatePlugin";
70
+ this.symbol = _ExternalStatePlugin.Symbol;
71
+ this.handlers = handlers;
72
+ }
73
+ apply(player) {
74
+ const isFirstInstance = this.createRegistry(player);
75
+ this.registerHandlers(player);
76
+ if (!isFirstInstance) {
77
+ return;
78
+ }
79
+ player.hooks.errorController.tap(this.name, (errorController) => {
80
+ this.errorController = errorController;
81
+ });
82
+ player.hooks.flowController.tap(this.name, (flowController) => {
83
+ flowController.hooks.flow.tap(this.name, (flow) => {
84
+ flow.hooks.afterTransition.tap(this.name, (flowInstance) => {
85
+ this.handleAfterTransition(player, flowInstance);
86
+ });
87
+ });
88
+ });
89
+ }
90
+ /**
91
+ * Resolve an EXTERNAL state transition.
92
+ */
93
+ async handleAfterTransition(player, flowInstance) {
94
+ const toState = flowInstance.currentState;
95
+ const currentState = player.getState();
96
+ if (!toState || !toState.value || !isExternal(toState.value) || !isInProgress(currentState)) {
97
+ return;
98
+ }
99
+ try {
100
+ const handler = this.registry?.get(toState.value);
101
+ if (!handler) {
102
+ this.reportError(
103
+ player,
104
+ ExternalStateError.missingHandler(toState.value.ref)
105
+ );
106
+ return;
107
+ }
108
+ const transitionValue = await handler(
109
+ toState.value,
110
+ currentState.controllers
111
+ );
112
+ if (!transitionValue) {
113
+ this.reportError(
114
+ player,
115
+ ExternalStateError.missingTransitionValue(toState.value.ref)
116
+ );
117
+ return;
118
+ }
119
+ const latestState = player.getState();
120
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === toState.name) {
121
+ latestState.controllers.flow.transition(transitionValue);
122
+ } else {
123
+ player.logger.warn(
124
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
125
+ );
126
+ }
127
+ } catch (error) {
128
+ if (error instanceof Error) {
129
+ currentState.fail(error);
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * Report an ExternalStateError via the errorController.
135
+ */
136
+ reportError(player, error) {
137
+ if (!this.errorController) {
138
+ player.logger.error(
139
+ `${error.message} (errorController was unexpectedly undefined; it should always be set by the time this code runs)`
140
+ );
141
+ return;
142
+ }
143
+ this.errorController.captureError(error);
144
+ }
145
+ /**
146
+ * Create or share the registry for this plugin instance.
147
+ *
148
+ * Uses the Player's plugin registry to find if another instance of ExternalStatePlugin
149
+ * has already been registered. If found, this instance will share that plugin's registry.
150
+ * Otherwise, this instance creates a new registry.
151
+ */
152
+ createRegistry(player) {
153
+ const existing = player.findPlugin(
154
+ ExternalStatePluginSymbol
155
+ );
156
+ if (existing && existing !== this) {
157
+ this.registry = existing.registry;
158
+ return false;
159
+ }
160
+ this.registry = new import_partial_match_registry.Registry(
161
+ void 0,
162
+ player.logger
163
+ );
164
+ return true;
165
+ }
166
+ /**
167
+ * Register this plugin's handlers to the shared registry.
168
+ *
169
+ * If a handler with the same specificity already exists, it will be replaced
170
+ * and a debug log will be emitted (accessible via player.logger.debug).
171
+ */
172
+ registerHandlers(player) {
173
+ for (const handler of this.handlers) {
174
+ if (handler.match?.ref) {
175
+ player.logger.warn(
176
+ `An ExternalStateHandler contains a superfluous 'match.ref' property. 'match.ref' will be ignored. 'ref' will be used instead. Handler: ${JSON.stringify({ ref: handler.ref, match: handler.match })}`
177
+ );
178
+ delete handler.match?.["ref"];
179
+ continue;
180
+ }
181
+ this.registry?.set(
182
+ { ref: handler.ref, ...handler.match },
183
+ handler.handlerFunction
184
+ );
185
+ }
186
+ }
187
+ };
188
+ /** Symbol used to identify and find existing instances of this plugin */
189
+ _ExternalStatePlugin.Symbol = ExternalStatePluginSymbol;
190
+ var ExternalStatePlugin = _ExternalStatePlugin;
191
+ // Annotate the CommonJS export names for ESM import in node:
192
+ 0 && (module.exports = {
193
+ ExternalStateError,
194
+ ExternalStatePlugin
195
+ });
196
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/symbols.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/ExternalStateError.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowState,\n NavigationFlowExternalState,\n ErrorController,\n FlowInstance,\n} from \"@player-ui/player\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport { ExternalStatePluginSymbol } from \"./symbols.js\";\nimport { ExternalStateError } from \"./ExternalStateError.js\";\n\nexport { ExternalStateError } from \"./ExternalStateError.js\";\nexport type { ExternalStateErrorMetadata } from \"./ExternalStateError.js\";\n\nexport type ExternalStateHandlerMatch = Record<string, unknown>;\n\nexport type ExternalStateHandlerFunction = (\n state: NavigationFlowExternalState,\n options: InProgressState[\"controllers\"],\n) => string | undefined | Promise<string | undefined>;\n\nexport type ExternalStateHandler = {\n /** The name of the external state. This will appear as it's \"ref\" property in the DSL. */\n ref: string;\n /** Additional properties to match against the external state. */\n match?: ExternalStateHandlerMatch;\n /** The function to run when the external state is transitioned to. This should return the `ref` of the next state to transition to. */\n handlerFunction: ExternalStateHandlerFunction;\n};\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 states\n *\n * This plugin uses a registry-based approach to match external states to handler functions.\n * Multiple plugins can be registered, and handlers are matched using partial object matching\n * with specificity ordering (more specific matches take precedence).\n */\nexport class ExternalStatePlugin implements PlayerPlugin {\n name = \"ExternalStatePlugin\";\n\n /** Symbol used to identify and find existing instances of this plugin */\n static Symbol: symbol = ExternalStatePluginSymbol;\n public readonly symbol: symbol = ExternalStatePlugin.Symbol;\n\n /**\n * The shared registry that maps external states to handlers.\n * All plugin instances use the same registry.\n */\n private registry?: Registry<ExternalStateHandlerFunction>;\n\n /**\n * The handlers for this plugin instance.\n */\n private readonly handlers: ExternalStateHandler[];\n\n /** The error controller to use for this plugin.\n * Only the first instance of the plugin should tap the error controller hook.\n */\n private errorController?: ErrorController;\n\n /** Creates a new ExternalStatePlugin */\n constructor(handlers: ExternalStateHandler[]) {\n this.handlers = handlers;\n }\n\n apply(player: Player): void {\n const isFirstInstance = this.createRegistry(player);\n this.registerHandlers(player);\n\n // Only the first instance should tap the hooks to avoid redundant taps\n if (!isFirstInstance) {\n return;\n }\n\n player.hooks.errorController.tap(this.name, (errorController) => {\n this.errorController = errorController;\n });\n\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, (flowInstance) => {\n this.handleAfterTransition(player, flowInstance);\n });\n });\n });\n }\n\n /**\n * Resolve an EXTERNAL state transition.\n */\n private async handleAfterTransition(\n player: Player,\n flowInstance: FlowInstance,\n ): Promise<void> {\n const toState = flowInstance.currentState;\n const currentState = player.getState();\n\n if (\n !toState ||\n !toState.value ||\n !isExternal(toState.value) ||\n !isInProgress(currentState)\n ) {\n return;\n }\n\n try {\n const handler = this.registry?.get(toState.value);\n\n if (!handler) {\n this.reportError(\n player,\n ExternalStateError.missingHandler(toState.value.ref),\n );\n return;\n }\n\n const transitionValue = await handler(\n toState.value,\n currentState.controllers,\n );\n\n if (!transitionValue) {\n this.reportError(\n player,\n ExternalStateError.missingTransitionValue(toState.value.ref),\n );\n return;\n }\n\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 toState.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 [${toState.name}]`,\n );\n }\n } catch (error) {\n // Thrown errors are treated as purposefully unrecoverable: fail the flow rather than\n // routing through captureError.\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n\n /**\n * Report an ExternalStateError via the errorController.\n */\n private reportError(player: Player, error: ExternalStateError): void {\n // The compiler believes errorController could be nil, but in practice it should always\n // be set by the time this method runs. The logger fallback exists only as defense\n // against an unexpected lifecycle regression — if it ever fires, that's a bug to\n // investigate, not normal operation.\n if (!this.errorController) {\n player.logger.error(\n `${error.message} (errorController was unexpectedly undefined; it should always be set by the time this code runs)`,\n );\n return;\n }\n\n this.errorController.captureError(error);\n }\n\n /**\n * Create or share the registry for this plugin instance.\n *\n * Uses the Player's plugin registry to find if another instance of ExternalStatePlugin\n * has already been registered. If found, this instance will share that plugin's registry.\n * Otherwise, this instance creates a new registry.\n */\n private createRegistry(player: Player): boolean {\n // Find the first instance of this plugin registered to the Player\n const existing = player.findPlugin<ExternalStatePlugin>(\n ExternalStatePluginSymbol,\n );\n\n // If we found a plugin and it's not ourselves, we are not the first plugin instance\n if (existing && existing !== this) {\n // Use the first plugin's registry\n this.registry = existing.registry;\n return false;\n }\n\n // We are the first plugin instance, create the registry\n this.registry = new Registry<ExternalStateHandlerFunction>(\n undefined,\n player.logger,\n );\n return true;\n }\n\n /**\n * Register this plugin's handlers to the shared registry.\n *\n * If a handler with the same specificity already exists, it will be replaced\n * and a debug log will be emitted (accessible via player.logger.debug).\n */\n private registerHandlers(player: Player): void {\n for (const handler of this.handlers) {\n // Runtime check for 'ref' property is necessary despite TypeScript constraint because\n // the Swift bridge allows improperly formatted objects to bypass TypeScript validation.\n // We log this here and not in the constructor because the Logger is not yet available in the constructor.\n if (handler.match?.ref) {\n player.logger.warn(\n `An ExternalStateHandler contains a superfluous 'match.ref' property. 'match.ref' will be ignored. 'ref' will be used instead. Handler: ${JSON.stringify({ ref: handler.ref, match: handler.match })}`,\n );\n delete handler.match?.[\"ref\"];\n continue;\n }\n // Registry will handle keeping only the last handlerFunction for each match\n this.registry?.set(\n { ref: handler.ref, ...handler.match },\n handler.handlerFunction,\n );\n }\n }\n}\n","// We prefix with \"@player-ui\" to avoid conflicts with symbols from other packages\nexport const ExternalStatePluginSymbol: symbol = Symbol.for(\n \"@player-ui/ExternalStatePlugin\",\n);\n","import type { ErrorMetadata, PlayerErrorMetadata } from \"@player-ui/player\";\nimport { ErrorSeverity, ErrorTypes } from \"@player-ui/player\";\n\nexport type ExternalStateErrorReason =\n | \"missing-handler\"\n | \"missing-transition-value\";\n\nexport interface ExternalStateErrorMetadata extends ErrorMetadata {\n /** The `ref` of the EXTERNAL state that produced the error */\n ref: string;\n /** Which failure mode this error represents */\n reason: ExternalStateErrorReason;\n}\n\nexport class ExternalStateError\n extends Error\n implements PlayerErrorMetadata<ExternalStateErrorMetadata>\n{\n readonly type: string = ErrorTypes.EXTERNAL_STATE;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: ExternalStateErrorMetadata;\n\n private constructor(message: string, metadata: ExternalStateErrorMetadata) {\n super(message);\n this.metadata = metadata;\n }\n\n /** No handler was registered for the EXTERNAL state's ref. */\n static missingHandler(ref: string): ExternalStateError {\n return new ExternalStateError(\n `No handler found for external state with ref: \"${ref}\". ` +\n `Ensure a handler is registered for this state.`,\n { ref, reason: \"missing-handler\" },\n );\n }\n\n /** A handler ran but returned no transition value. */\n static missingTransitionValue(ref: string): ExternalStateError {\n return new ExternalStateError(\n `Handler for external state with ref: \"${ref}\" did not return a transition value. ` +\n `Ensure the handler returns the name of a valid transition.`,\n { ref, reason: \"missing-transition-value\" },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,oCAAyB;;;ACTlB,IAAM,4BAAoC,OAAO;AAAA,EACtD;AACF;;;ACFA,oBAA0C;AAanC,IAAM,qBAAN,MAAM,4BACH,MAEV;AAAA,EAKU,YAAY,SAAiB,UAAsC;AACzE,UAAM,OAAO;AALf,SAAS,OAAe,yBAAW;AACnC,SAAS,WAA0B,4BAAc;AAK/C,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA,EAGA,OAAO,eAAe,KAAiC;AACrD,WAAO,IAAI;AAAA,MACT,kDAAkD,GAAG;AAAA,MAErD,EAAE,KAAK,QAAQ,kBAAkB;AAAA,IACnC;AAAA,EACF;AAAA;AAAA,EAGA,OAAO,uBAAuB,KAAiC;AAC7D,WAAO,IAAI;AAAA,MACT,yCAAyC,GAAG;AAAA,MAE5C,EAAE,KAAK,QAAQ,2BAA2B;AAAA,IAC5C;AAAA,EACF;AACF;;;AFXA,SAAS,WACP,OACsC;AACtC,SAAO,MAAM,eAAe;AAC9B;AAEA,SAAS,aAAa,OAAkD;AACtE,SAAO,MAAM,WAAW;AAC1B;AASO,IAAM,uBAAN,MAAM,qBAA4C;AAAA;AAAA,EAwBvD,YAAY,UAAkC;AAvB9C,gBAAO;AAIP,SAAgB,SAAiB,qBAAoB;AAoBnD,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAM,QAAsB;AAC1B,UAAM,kBAAkB,KAAK,eAAe,MAAM;AAClD,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AAe,8CAA8C,QAAQ,IAAI;AAAA,QAC5G;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AAGd,UAAI,iBAAiB,OAAO;AAC1B,qBAAa,KAAK,KAAK;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAY,QAAgB,OAAiC;AAKnE,QAAI,CAAC,KAAK,iBAAiB;AACzB,aAAO,OAAO;AAAA,QACZ,GAAG,MAAM,OAAO;AAAA,MAClB;AACA;AAAA,IACF;AAEA,SAAK,gBAAgB,aAAa,KAAK;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,eAAe,QAAyB;AAE9C,UAAM,WAAW,OAAO;AAAA,MACtB;AAAA,IACF;AAGA,QAAI,YAAY,aAAa,MAAM;AAEjC,WAAK,WAAW,SAAS;AACzB,aAAO;AAAA,IACT;AAGA,SAAK,WAAW,IAAI;AAAA,MAClB;AAAA,MACA,OAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,iBAAiB,QAAsB;AAC7C,eAAW,WAAW,KAAK,UAAU;AAInC,UAAI,QAAQ,OAAO,KAAK;AACtB,eAAO,OAAO;AAAA,UACZ,0IAA0I,KAAK,UAAU,EAAE,KAAK,QAAQ,KAAK,OAAO,QAAQ,MAAM,CAAC,CAAC;AAAA,QACtM;AACA,eAAO,QAAQ,QAAQ,KAAK;AAC5B;AAAA,MACF;AAEA,WAAK,UAAU;AAAA,QACb,EAAE,KAAK,QAAQ,KAAK,GAAG,QAAQ,MAAM;AAAA,QACrC,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;AAAA;AA3La,qBAIJ,SAAiB;AAJnB,IAAM,sBAAN;","names":[]}
@@ -0,0 +1,170 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts
2
+ import { Registry } from "@player-ui/partial-match-registry";
3
+
4
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/symbols.ts
5
+ var ExternalStatePluginSymbol = Symbol.for(
6
+ "@player-ui/ExternalStatePlugin"
7
+ );
8
+
9
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/ExternalStateError.ts
10
+ import { ErrorSeverity, ErrorTypes } from "@player-ui/player";
11
+ var ExternalStateError = class _ExternalStateError extends Error {
12
+ constructor(message, metadata) {
13
+ super(message);
14
+ this.type = ErrorTypes.EXTERNAL_STATE;
15
+ this.severity = ErrorSeverity.ERROR;
16
+ this.metadata = metadata;
17
+ }
18
+ /** No handler was registered for the EXTERNAL state's ref. */
19
+ static missingHandler(ref) {
20
+ return new _ExternalStateError(
21
+ `No handler found for external state with ref: "${ref}". Ensure a handler is registered for this state.`,
22
+ { ref, reason: "missing-handler" }
23
+ );
24
+ }
25
+ /** A handler ran but returned no transition value. */
26
+ static missingTransitionValue(ref) {
27
+ return new _ExternalStateError(
28
+ `Handler for external state with ref: "${ref}" did not return a transition value. Ensure the handler returns the name of a valid transition.`,
29
+ { ref, reason: "missing-transition-value" }
30
+ );
31
+ }
32
+ };
33
+
34
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts
35
+ function isExternal(state) {
36
+ return state.state_type === "EXTERNAL";
37
+ }
38
+ function isInProgress(state) {
39
+ return state.status === "in-progress";
40
+ }
41
+ var _ExternalStatePlugin = class _ExternalStatePlugin {
42
+ /** Creates a new ExternalStatePlugin */
43
+ constructor(handlers) {
44
+ this.name = "ExternalStatePlugin";
45
+ this.symbol = _ExternalStatePlugin.Symbol;
46
+ this.handlers = handlers;
47
+ }
48
+ apply(player) {
49
+ const isFirstInstance = this.createRegistry(player);
50
+ this.registerHandlers(player);
51
+ if (!isFirstInstance) {
52
+ return;
53
+ }
54
+ player.hooks.errorController.tap(this.name, (errorController) => {
55
+ this.errorController = errorController;
56
+ });
57
+ player.hooks.flowController.tap(this.name, (flowController) => {
58
+ flowController.hooks.flow.tap(this.name, (flow) => {
59
+ flow.hooks.afterTransition.tap(this.name, (flowInstance) => {
60
+ this.handleAfterTransition(player, flowInstance);
61
+ });
62
+ });
63
+ });
64
+ }
65
+ /**
66
+ * Resolve an EXTERNAL state transition.
67
+ */
68
+ async handleAfterTransition(player, flowInstance) {
69
+ const toState = flowInstance.currentState;
70
+ const currentState = player.getState();
71
+ if (!toState || !toState.value || !isExternal(toState.value) || !isInProgress(currentState)) {
72
+ return;
73
+ }
74
+ try {
75
+ const handler = this.registry?.get(toState.value);
76
+ if (!handler) {
77
+ this.reportError(
78
+ player,
79
+ ExternalStateError.missingHandler(toState.value.ref)
80
+ );
81
+ return;
82
+ }
83
+ const transitionValue = await handler(
84
+ toState.value,
85
+ currentState.controllers
86
+ );
87
+ if (!transitionValue) {
88
+ this.reportError(
89
+ player,
90
+ ExternalStateError.missingTransitionValue(toState.value.ref)
91
+ );
92
+ return;
93
+ }
94
+ const latestState = player.getState();
95
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === toState.name) {
96
+ latestState.controllers.flow.transition(transitionValue);
97
+ } else {
98
+ player.logger.warn(
99
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
100
+ );
101
+ }
102
+ } catch (error) {
103
+ if (error instanceof Error) {
104
+ currentState.fail(error);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Report an ExternalStateError via the errorController.
110
+ */
111
+ reportError(player, error) {
112
+ if (!this.errorController) {
113
+ player.logger.error(
114
+ `${error.message} (errorController was unexpectedly undefined; it should always be set by the time this code runs)`
115
+ );
116
+ return;
117
+ }
118
+ this.errorController.captureError(error);
119
+ }
120
+ /**
121
+ * Create or share the registry for this plugin instance.
122
+ *
123
+ * Uses the Player's plugin registry to find if another instance of ExternalStatePlugin
124
+ * has already been registered. If found, this instance will share that plugin's registry.
125
+ * Otherwise, this instance creates a new registry.
126
+ */
127
+ createRegistry(player) {
128
+ const existing = player.findPlugin(
129
+ ExternalStatePluginSymbol
130
+ );
131
+ if (existing && existing !== this) {
132
+ this.registry = existing.registry;
133
+ return false;
134
+ }
135
+ this.registry = new Registry(
136
+ void 0,
137
+ player.logger
138
+ );
139
+ return true;
140
+ }
141
+ /**
142
+ * Register this plugin's handlers to the shared registry.
143
+ *
144
+ * If a handler with the same specificity already exists, it will be replaced
145
+ * and a debug log will be emitted (accessible via player.logger.debug).
146
+ */
147
+ registerHandlers(player) {
148
+ for (const handler of this.handlers) {
149
+ if (handler.match?.ref) {
150
+ player.logger.warn(
151
+ `An ExternalStateHandler contains a superfluous 'match.ref' property. 'match.ref' will be ignored. 'ref' will be used instead. Handler: ${JSON.stringify({ ref: handler.ref, match: handler.match })}`
152
+ );
153
+ delete handler.match?.["ref"];
154
+ continue;
155
+ }
156
+ this.registry?.set(
157
+ { ref: handler.ref, ...handler.match },
158
+ handler.handlerFunction
159
+ );
160
+ }
161
+ }
162
+ };
163
+ /** Symbol used to identify and find existing instances of this plugin */
164
+ _ExternalStatePlugin.Symbol = ExternalStatePluginSymbol;
165
+ var ExternalStatePlugin = _ExternalStatePlugin;
166
+ export {
167
+ ExternalStateError,
168
+ ExternalStatePlugin
169
+ };
170
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,170 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts
2
+ import { Registry } from "@player-ui/partial-match-registry";
3
+
4
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/symbols.ts
5
+ var ExternalStatePluginSymbol = Symbol.for(
6
+ "@player-ui/ExternalStatePlugin"
7
+ );
8
+
9
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/ExternalStateError.ts
10
+ import { ErrorSeverity, ErrorTypes } from "@player-ui/player";
11
+ var ExternalStateError = class _ExternalStateError extends Error {
12
+ constructor(message, metadata) {
13
+ super(message);
14
+ this.type = ErrorTypes.EXTERNAL_STATE;
15
+ this.severity = ErrorSeverity.ERROR;
16
+ this.metadata = metadata;
17
+ }
18
+ /** No handler was registered for the EXTERNAL state's ref. */
19
+ static missingHandler(ref) {
20
+ return new _ExternalStateError(
21
+ `No handler found for external state with ref: "${ref}". Ensure a handler is registered for this state.`,
22
+ { ref, reason: "missing-handler" }
23
+ );
24
+ }
25
+ /** A handler ran but returned no transition value. */
26
+ static missingTransitionValue(ref) {
27
+ return new _ExternalStateError(
28
+ `Handler for external state with ref: "${ref}" did not return a transition value. Ensure the handler returns the name of a valid transition.`,
29
+ { ref, reason: "missing-transition-value" }
30
+ );
31
+ }
32
+ };
33
+
34
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts
35
+ function isExternal(state) {
36
+ return state.state_type === "EXTERNAL";
37
+ }
38
+ function isInProgress(state) {
39
+ return state.status === "in-progress";
40
+ }
41
+ var _ExternalStatePlugin = class _ExternalStatePlugin {
42
+ /** Creates a new ExternalStatePlugin */
43
+ constructor(handlers) {
44
+ this.name = "ExternalStatePlugin";
45
+ this.symbol = _ExternalStatePlugin.Symbol;
46
+ this.handlers = handlers;
47
+ }
48
+ apply(player) {
49
+ const isFirstInstance = this.createRegistry(player);
50
+ this.registerHandlers(player);
51
+ if (!isFirstInstance) {
52
+ return;
53
+ }
54
+ player.hooks.errorController.tap(this.name, (errorController) => {
55
+ this.errorController = errorController;
56
+ });
57
+ player.hooks.flowController.tap(this.name, (flowController) => {
58
+ flowController.hooks.flow.tap(this.name, (flow) => {
59
+ flow.hooks.afterTransition.tap(this.name, (flowInstance) => {
60
+ this.handleAfterTransition(player, flowInstance);
61
+ });
62
+ });
63
+ });
64
+ }
65
+ /**
66
+ * Resolve an EXTERNAL state transition.
67
+ */
68
+ async handleAfterTransition(player, flowInstance) {
69
+ const toState = flowInstance.currentState;
70
+ const currentState = player.getState();
71
+ if (!toState || !toState.value || !isExternal(toState.value) || !isInProgress(currentState)) {
72
+ return;
73
+ }
74
+ try {
75
+ const handler = this.registry?.get(toState.value);
76
+ if (!handler) {
77
+ this.reportError(
78
+ player,
79
+ ExternalStateError.missingHandler(toState.value.ref)
80
+ );
81
+ return;
82
+ }
83
+ const transitionValue = await handler(
84
+ toState.value,
85
+ currentState.controllers
86
+ );
87
+ if (!transitionValue) {
88
+ this.reportError(
89
+ player,
90
+ ExternalStateError.missingTransitionValue(toState.value.ref)
91
+ );
92
+ return;
93
+ }
94
+ const latestState = player.getState();
95
+ if (isInProgress(latestState) && latestState.controllers.flow.current?.currentState?.name === toState.name) {
96
+ latestState.controllers.flow.transition(transitionValue);
97
+ } else {
98
+ player.logger.warn(
99
+ `External state resolved with [${transitionValue}], but Player already navigated away from [${toState.name}]`
100
+ );
101
+ }
102
+ } catch (error) {
103
+ if (error instanceof Error) {
104
+ currentState.fail(error);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Report an ExternalStateError via the errorController.
110
+ */
111
+ reportError(player, error) {
112
+ if (!this.errorController) {
113
+ player.logger.error(
114
+ `${error.message} (errorController was unexpectedly undefined; it should always be set by the time this code runs)`
115
+ );
116
+ return;
117
+ }
118
+ this.errorController.captureError(error);
119
+ }
120
+ /**
121
+ * Create or share the registry for this plugin instance.
122
+ *
123
+ * Uses the Player's plugin registry to find if another instance of ExternalStatePlugin
124
+ * has already been registered. If found, this instance will share that plugin's registry.
125
+ * Otherwise, this instance creates a new registry.
126
+ */
127
+ createRegistry(player) {
128
+ const existing = player.findPlugin(
129
+ ExternalStatePluginSymbol
130
+ );
131
+ if (existing && existing !== this) {
132
+ this.registry = existing.registry;
133
+ return false;
134
+ }
135
+ this.registry = new Registry(
136
+ void 0,
137
+ player.logger
138
+ );
139
+ return true;
140
+ }
141
+ /**
142
+ * Register this plugin's handlers to the shared registry.
143
+ *
144
+ * If a handler with the same specificity already exists, it will be replaced
145
+ * and a debug log will be emitted (accessible via player.logger.debug).
146
+ */
147
+ registerHandlers(player) {
148
+ for (const handler of this.handlers) {
149
+ if (handler.match?.ref) {
150
+ player.logger.warn(
151
+ `An ExternalStateHandler contains a superfluous 'match.ref' property. 'match.ref' will be ignored. 'ref' will be used instead. Handler: ${JSON.stringify({ ref: handler.ref, match: handler.match })}`
152
+ );
153
+ delete handler.match?.["ref"];
154
+ continue;
155
+ }
156
+ this.registry?.set(
157
+ { ref: handler.ref, ...handler.match },
158
+ handler.handlerFunction
159
+ );
160
+ }
161
+ }
162
+ };
163
+ /** Symbol used to identify and find existing instances of this plugin */
164
+ _ExternalStatePlugin.Symbol = ExternalStatePluginSymbol;
165
+ var ExternalStatePlugin = _ExternalStatePlugin;
166
+ export {
167
+ ExternalStateError,
168
+ ExternalStatePlugin
169
+ };
170
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/symbols.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/external-state/core/src/ExternalStateError.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n InProgressState,\n PlayerFlowState,\n NavigationFlowState,\n NavigationFlowExternalState,\n ErrorController,\n FlowInstance,\n} from \"@player-ui/player\";\nimport { Registry } from \"@player-ui/partial-match-registry\";\nimport { ExternalStatePluginSymbol } from \"./symbols.js\";\nimport { ExternalStateError } from \"./ExternalStateError.js\";\n\nexport { ExternalStateError } from \"./ExternalStateError.js\";\nexport type { ExternalStateErrorMetadata } from \"./ExternalStateError.js\";\n\nexport type ExternalStateHandlerMatch = Record<string, unknown>;\n\nexport type ExternalStateHandlerFunction = (\n state: NavigationFlowExternalState,\n options: InProgressState[\"controllers\"],\n) => string | undefined | Promise<string | undefined>;\n\nexport type ExternalStateHandler = {\n /** The name of the external state. This will appear as it's \"ref\" property in the DSL. */\n ref: string;\n /** Additional properties to match against the external state. */\n match?: ExternalStateHandlerMatch;\n /** The function to run when the external state is transitioned to. This should return the `ref` of the next state to transition to. */\n handlerFunction: ExternalStateHandlerFunction;\n};\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 states\n *\n * This plugin uses a registry-based approach to match external states to handler functions.\n * Multiple plugins can be registered, and handlers are matched using partial object matching\n * with specificity ordering (more specific matches take precedence).\n */\nexport class ExternalStatePlugin implements PlayerPlugin {\n name = \"ExternalStatePlugin\";\n\n /** Symbol used to identify and find existing instances of this plugin */\n static Symbol: symbol = ExternalStatePluginSymbol;\n public readonly symbol: symbol = ExternalStatePlugin.Symbol;\n\n /**\n * The shared registry that maps external states to handlers.\n * All plugin instances use the same registry.\n */\n private registry?: Registry<ExternalStateHandlerFunction>;\n\n /**\n * The handlers for this plugin instance.\n */\n private readonly handlers: ExternalStateHandler[];\n\n /** The error controller to use for this plugin.\n * Only the first instance of the plugin should tap the error controller hook.\n */\n private errorController?: ErrorController;\n\n /** Creates a new ExternalStatePlugin */\n constructor(handlers: ExternalStateHandler[]) {\n this.handlers = handlers;\n }\n\n apply(player: Player): void {\n const isFirstInstance = this.createRegistry(player);\n this.registerHandlers(player);\n\n // Only the first instance should tap the hooks to avoid redundant taps\n if (!isFirstInstance) {\n return;\n }\n\n player.hooks.errorController.tap(this.name, (errorController) => {\n this.errorController = errorController;\n });\n\n player.hooks.flowController.tap(this.name, (flowController) => {\n flowController.hooks.flow.tap(this.name, (flow) => {\n flow.hooks.afterTransition.tap(this.name, (flowInstance) => {\n this.handleAfterTransition(player, flowInstance);\n });\n });\n });\n }\n\n /**\n * Resolve an EXTERNAL state transition.\n */\n private async handleAfterTransition(\n player: Player,\n flowInstance: FlowInstance,\n ): Promise<void> {\n const toState = flowInstance.currentState;\n const currentState = player.getState();\n\n if (\n !toState ||\n !toState.value ||\n !isExternal(toState.value) ||\n !isInProgress(currentState)\n ) {\n return;\n }\n\n try {\n const handler = this.registry?.get(toState.value);\n\n if (!handler) {\n this.reportError(\n player,\n ExternalStateError.missingHandler(toState.value.ref),\n );\n return;\n }\n\n const transitionValue = await handler(\n toState.value,\n currentState.controllers,\n );\n\n if (!transitionValue) {\n this.reportError(\n player,\n ExternalStateError.missingTransitionValue(toState.value.ref),\n );\n return;\n }\n\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 toState.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 [${toState.name}]`,\n );\n }\n } catch (error) {\n // Thrown errors are treated as purposefully unrecoverable: fail the flow rather than\n // routing through captureError.\n if (error instanceof Error) {\n currentState.fail(error);\n }\n }\n }\n\n /**\n * Report an ExternalStateError via the errorController.\n */\n private reportError(player: Player, error: ExternalStateError): void {\n // The compiler believes errorController could be nil, but in practice it should always\n // be set by the time this method runs. The logger fallback exists only as defense\n // against an unexpected lifecycle regression — if it ever fires, that's a bug to\n // investigate, not normal operation.\n if (!this.errorController) {\n player.logger.error(\n `${error.message} (errorController was unexpectedly undefined; it should always be set by the time this code runs)`,\n );\n return;\n }\n\n this.errorController.captureError(error);\n }\n\n /**\n * Create or share the registry for this plugin instance.\n *\n * Uses the Player's plugin registry to find if another instance of ExternalStatePlugin\n * has already been registered. If found, this instance will share that plugin's registry.\n * Otherwise, this instance creates a new registry.\n */\n private createRegistry(player: Player): boolean {\n // Find the first instance of this plugin registered to the Player\n const existing = player.findPlugin<ExternalStatePlugin>(\n ExternalStatePluginSymbol,\n );\n\n // If we found a plugin and it's not ourselves, we are not the first plugin instance\n if (existing && existing !== this) {\n // Use the first plugin's registry\n this.registry = existing.registry;\n return false;\n }\n\n // We are the first plugin instance, create the registry\n this.registry = new Registry<ExternalStateHandlerFunction>(\n undefined,\n player.logger,\n );\n return true;\n }\n\n /**\n * Register this plugin's handlers to the shared registry.\n *\n * If a handler with the same specificity already exists, it will be replaced\n * and a debug log will be emitted (accessible via player.logger.debug).\n */\n private registerHandlers(player: Player): void {\n for (const handler of this.handlers) {\n // Runtime check for 'ref' property is necessary despite TypeScript constraint because\n // the Swift bridge allows improperly formatted objects to bypass TypeScript validation.\n // We log this here and not in the constructor because the Logger is not yet available in the constructor.\n if (handler.match?.ref) {\n player.logger.warn(\n `An ExternalStateHandler contains a superfluous 'match.ref' property. 'match.ref' will be ignored. 'ref' will be used instead. Handler: ${JSON.stringify({ ref: handler.ref, match: handler.match })}`,\n );\n delete handler.match?.[\"ref\"];\n continue;\n }\n // Registry will handle keeping only the last handlerFunction for each match\n this.registry?.set(\n { ref: handler.ref, ...handler.match },\n handler.handlerFunction,\n );\n }\n }\n}\n","// We prefix with \"@player-ui\" to avoid conflicts with symbols from other packages\nexport const ExternalStatePluginSymbol: symbol = Symbol.for(\n \"@player-ui/ExternalStatePlugin\",\n);\n","import type { ErrorMetadata, PlayerErrorMetadata } from \"@player-ui/player\";\nimport { ErrorSeverity, ErrorTypes } from \"@player-ui/player\";\n\nexport type ExternalStateErrorReason =\n | \"missing-handler\"\n | \"missing-transition-value\";\n\nexport interface ExternalStateErrorMetadata extends ErrorMetadata {\n /** The `ref` of the EXTERNAL state that produced the error */\n ref: string;\n /** Which failure mode this error represents */\n reason: ExternalStateErrorReason;\n}\n\nexport class ExternalStateError\n extends Error\n implements PlayerErrorMetadata<ExternalStateErrorMetadata>\n{\n readonly type: string = ErrorTypes.EXTERNAL_STATE;\n readonly severity: ErrorSeverity = ErrorSeverity.ERROR;\n readonly metadata: ExternalStateErrorMetadata;\n\n private constructor(message: string, metadata: ExternalStateErrorMetadata) {\n super(message);\n this.metadata = metadata;\n }\n\n /** No handler was registered for the EXTERNAL state's ref. */\n static missingHandler(ref: string): ExternalStateError {\n return new ExternalStateError(\n `No handler found for external state with ref: \"${ref}\". ` +\n `Ensure a handler is registered for this state.`,\n { ref, reason: \"missing-handler\" },\n );\n }\n\n /** A handler ran but returned no transition value. */\n static missingTransitionValue(ref: string): ExternalStateError {\n return new ExternalStateError(\n `Handler for external state with ref: \"${ref}\" did not return a transition value. ` +\n `Ensure the handler returns the name of a valid transition.`,\n { ref, reason: \"missing-transition-value\" },\n );\n }\n}\n"],"mappings":";AAUA,SAAS,gBAAgB;;;ACTlB,IAAM,4BAAoC,OAAO;AAAA,EACtD;AACF;;;ACFA,SAAS,eAAe,kBAAkB;AAanC,IAAM,qBAAN,MAAM,4BACH,MAEV;AAAA,EAKU,YAAY,SAAiB,UAAsC;AACzE,UAAM,OAAO;AALf,SAAS,OAAe,WAAW;AACnC,SAAS,WAA0B,cAAc;AAK/C,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA,EAGA,OAAO,eAAe,KAAiC;AACrD,WAAO,IAAI;AAAA,MACT,kDAAkD,GAAG;AAAA,MAErD,EAAE,KAAK,QAAQ,kBAAkB;AAAA,IACnC;AAAA,EACF;AAAA;AAAA,EAGA,OAAO,uBAAuB,KAAiC;AAC7D,WAAO,IAAI;AAAA,MACT,yCAAyC,GAAG;AAAA,MAE5C,EAAE,KAAK,QAAQ,2BAA2B;AAAA,IAC5C;AAAA,EACF;AACF;;;AFXA,SAAS,WACP,OACsC;AACtC,SAAO,MAAM,eAAe;AAC9B;AAEA,SAAS,aAAa,OAAkD;AACtE,SAAO,MAAM,WAAW;AAC1B;AASO,IAAM,uBAAN,MAAM,qBAA4C;AAAA;AAAA,EAwBvD,YAAY,UAAkC;AAvB9C,gBAAO;AAIP,SAAgB,SAAiB,qBAAoB;AAoBnD,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAM,QAAsB;AAC1B,UAAM,kBAAkB,KAAK,eAAe,MAAM;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+ ],
8
+ "name": "@player-ui/external-state-plugin",
9
+ "version": "0.15.4--canary.881.37421",
10
+ "main": "dist/cjs/index.cjs",
11
+ "dependencies": {
12
+ "@player-ui/partial-match-registry": "0.15.4--canary.881.37421",
13
+ "tslib": "^2.6.2"
14
+ },
15
+ "peerDependencies": {
16
+ "@player-ui/player": "0.15.4--canary.881.37421"
17
+ },
18
+ "module": "dist/index.legacy-esm.js",
19
+ "types": "types/index.d.ts",
20
+ "bundle": "dist/ExternalStatePlugin.native.js",
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ "./dist/index.css": "./dist/index.css",
24
+ ".": {
25
+ "types": "./types/index.d.ts",
26
+ "import": "./dist/index.mjs",
27
+ "default": "./dist/cjs/index.cjs"
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,45 @@
1
+ import type { ErrorMetadata, PlayerErrorMetadata } from "@player-ui/player";
2
+ import { ErrorSeverity, ErrorTypes } from "@player-ui/player";
3
+
4
+ export type ExternalStateErrorReason =
5
+ | "missing-handler"
6
+ | "missing-transition-value";
7
+
8
+ export interface ExternalStateErrorMetadata extends ErrorMetadata {
9
+ /** The `ref` of the EXTERNAL state that produced the error */
10
+ ref: string;
11
+ /** Which failure mode this error represents */
12
+ reason: ExternalStateErrorReason;
13
+ }
14
+
15
+ export class ExternalStateError
16
+ extends Error
17
+ implements PlayerErrorMetadata<ExternalStateErrorMetadata>
18
+ {
19
+ readonly type: string = ErrorTypes.EXTERNAL_STATE;
20
+ readonly severity: ErrorSeverity = ErrorSeverity.ERROR;
21
+ readonly metadata: ExternalStateErrorMetadata;
22
+
23
+ private constructor(message: string, metadata: ExternalStateErrorMetadata) {
24
+ super(message);
25
+ this.metadata = metadata;
26
+ }
27
+
28
+ /** No handler was registered for the EXTERNAL state's ref. */
29
+ static missingHandler(ref: string): ExternalStateError {
30
+ return new ExternalStateError(
31
+ `No handler found for external state with ref: "${ref}". ` +
32
+ `Ensure a handler is registered for this state.`,
33
+ { ref, reason: "missing-handler" },
34
+ );
35
+ }
36
+
37
+ /** A handler ran but returned no transition value. */
38
+ static missingTransitionValue(ref: string): ExternalStateError {
39
+ return new ExternalStateError(
40
+ `Handler for external state with ref: "${ref}" did not return a transition value. ` +
41
+ `Ensure the handler returns the name of a valid transition.`,
42
+ { ref, reason: "missing-transition-value" },
43
+ );
44
+ }
45
+ }