@genesislcap/foundation-state-machine 14.71.1-auth-mf.3 → 14.71.1-auth-mf.6

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.
Files changed (35) hide show
  1. package/dist/dts/core/actions.d.ts +1 -1
  2. package/dist/dts/core/actions.d.ts.map +1 -1
  3. package/dist/dts/core/errors.d.ts +2 -2
  4. package/dist/dts/core/errors.d.ts.map +1 -1
  5. package/dist/dts/core/machine.d.ts +28 -1
  6. package/dist/dts/core/machine.d.ts.map +1 -1
  7. package/dist/dts/core/state.d.ts.map +1 -1
  8. package/dist/dts/machines/fetch/errors.d.ts +15 -3
  9. package/dist/dts/machines/fetch/errors.d.ts.map +1 -1
  10. package/dist/esm/core/actions.js +2 -5
  11. package/dist/esm/core/machine.js +39 -12
  12. package/dist/esm/core/state.js +18 -6
  13. package/dist/esm/machines/fetch/errors.js +12 -0
  14. package/dist/foundation-state-machine.api.json +419 -12
  15. package/dist/foundation-state-machine.d.ts +47 -6
  16. package/docs/api/foundation-state-machine.abstractmachine.getmetavaluesbykey.md +28 -0
  17. package/docs/api/foundation-state-machine.abstractmachine.md +3 -0
  18. package/docs/api/foundation-state-machine.abstractmachine.meta.md +13 -0
  19. package/docs/api/foundation-state-machine.abstractmachine.snapshot.md +13 -0
  20. package/docs/api/foundation-state-machine.apierror.isunauthorized.md +16 -0
  21. package/docs/api/foundation-state-machine.apierror.md +6 -0
  22. package/docs/api/foundation-state-machine.escalateerror.md +1 -1
  23. package/docs/api/foundation-state-machine.isapierror.md +3 -1
  24. package/docs/api/foundation-state-machine.isgenesisservererror.md +1 -1
  25. package/docs/api/foundation-state-machine.ismappingerror.md +1 -1
  26. package/docs/api/foundation-state-machine.isnetworkerror.md +1 -1
  27. package/docs/api/foundation-state-machine.isnotfounderror.md +1 -1
  28. package/docs/api/foundation-state-machine.isunauthorizederror.md +13 -0
  29. package/docs/api/foundation-state-machine.machine.getmetavaluesbykey.md +28 -0
  30. package/docs/api/foundation-state-machine.machine.md +3 -0
  31. package/docs/api/foundation-state-machine.machine.meta.md +13 -0
  32. package/docs/api/foundation-state-machine.machine.snapshot.md +13 -0
  33. package/docs/api/foundation-state-machine.md +3 -2
  34. package/docs/api-report.md +22 -6
  35. package/package.json +6 -6
@@ -28,7 +28,7 @@ export declare const setErrorByKey: (key: string) => {
28
28
  }) => import("xstate").AnyState[];
29
29
  };
30
30
  /**
31
- * Escalate error action.
31
+ * Escalate context error action.
32
32
  * @remarks
33
33
  * Guard this call with a parent check to avoid warnings when there's no parent.
34
34
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOnB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM;;;;;;;CASrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAGvB,CAAC"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOnB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM;;;;;;;CASrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAA2C,CAAC"}
@@ -24,7 +24,7 @@ export declare class GenesisServerError extends Error {
24
24
  * @param error - An error.
25
25
  * @public
26
26
  */
27
- export declare const isGenesisServerError: (error: unknown) => boolean;
27
+ export declare const isGenesisServerError: (error: unknown) => error is GenesisServerError;
28
28
  /**
29
29
  * MappingError.
30
30
  * @public
@@ -37,5 +37,5 @@ export declare class MappingError extends Error {
37
37
  * @param error - An error.
38
38
  * @public
39
39
  */
40
- export declare const isMappingError: (error: unknown) => boolean;
40
+ export declare const isMappingError: (error: unknown) => error is MappingError;
41
41
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,IAAI,CAAC,EAAE,OAAO;IACd,QAAQ,CAAC,EAAE,OAAO;gBADlB,IAAI,CAAC,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,OAAO,EACzB,OAAO,GAAE,MAAwC;IAOnD;;;;OAIG;IACH,gBAAgB;IAUhB,eAAe;IAMf,eAAe,IAAI,MAAM;IAMzB,YAAY,CAAC,IAAI,EAAE,MAAM;IAMzB,OAAO,CAAC,oBAAoB;CAG7B;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,YAAwC,CAAC;AAE5F;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,CAAC,EAAE,OAAO;gBAAb,GAAG,CAAC,EAAE,OAAO,EACpB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,YAAkC,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,IAAI,CAAC,EAAE,OAAO;IACd,QAAQ,CAAC,EAAE,OAAO;gBADlB,IAAI,CAAC,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,OAAO,EACzB,OAAO,GAAE,MAAwC;IAOnD;;;;OAIG;IACH,gBAAgB;IAUhB,eAAe;IAMf,eAAe,IAAI,MAAM;IAMzB,YAAY,CAAC,IAAI,EAAE,MAAM;IAMzB,OAAO,CAAC,oBAAoB;CAG7B;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,gCACd,CAAC;AAEtC;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,CAAC,EAAE,OAAO;gBAAb,GAAG,CAAC,EAAE,OAAO,EACpB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,0BACd,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ErrorDetailMap, ErrorMap } from '@genesislcap/foundation-utils';
2
2
  import { BindingObserver, ExecutionContext } from '@microsoft/fast-element';
3
3
  import { Container } from '@microsoft/fast-foundation';
4
- import type { AnyEventObject, EventObject, InternalMachineImplementations, InterpreterFrom, InterpreterOptions, MachineContext as XMachineContext, NoInfer, ParameterizedObject, ProvidedActor, ResolveTypegenMeta, StateMachine, StateValue, StateValueFrom, TypegenDisabled } from 'xstate';
4
+ import type { AnyEventObject, EventObject, InternalMachineImplementations, InterpreterFrom, InterpreterOptions, MachineContext as XMachineContext, NoInfer, ParameterizedObject, ProvidedActor, ResolveTypegenMeta, State, StateMachine, StateValue, StateValueFrom, TypegenDisabled } from 'xstate';
5
5
  import { SubscriberChangeCallback } from './binding';
6
6
  /**
7
7
  * MachineContext interface.
@@ -97,6 +97,10 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
97
97
  * Callers can decide to reuse/reference if set or create their own.
98
98
  */
99
99
  readonly actor?: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
100
+ /**
101
+ * The last `snapshot` from the actor.
102
+ */
103
+ readonly snapshot: State<TContext, TEvent, TActor, TResolvedTypesMeta>;
100
104
  /**
101
105
  * The current `state` of the machine itself. This is not to be confused with state in the data or store sense.
102
106
  */
@@ -116,6 +120,10 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
116
120
  * The `context` of the machine when started.
117
121
  */
118
122
  readonly startingContext: Partial<TContext>;
123
+ /**
124
+ * The `meta` from the current `state`.
125
+ */
126
+ readonly meta: Record<string, any>;
119
127
  /**
120
128
  * Indicates if the machine has completed the happy path.
121
129
  */
@@ -201,6 +209,15 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
201
209
  * @param tag - A tag.
202
210
  */
203
211
  hasTag(tag: string): boolean;
212
+ /**
213
+ * Get `meta` values by key.
214
+ *
215
+ * @remarks
216
+ * Meta is cumulative across all state nodes represented by the state value.
217
+ *
218
+ * @param key - A key within the `meta` object. Defaults to `content`.
219
+ */
220
+ getMetaValuesByKey<T = string>(key?: string): T[];
204
221
  /**
205
222
  * An api to send events to the machine.
206
223
  *
@@ -276,6 +293,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
276
293
  machine: StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>;
277
294
  /** {@inheritDoc Machine.actor} */
278
295
  actor: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
296
+ /** {@inheritDoc Machine.snapshot} */
297
+ snapshot: State<TContext, TEvent, TActor, TResolvedTypesMeta>;
279
298
  /** {@inheritDoc Machine.state} */
280
299
  state: StateValue;
281
300
  /** {@inheritDoc Machine.startingState} */
@@ -284,6 +303,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
284
303
  context: Partial<TContext>;
285
304
  /** {@inheritDoc Machine.startingContext} */
286
305
  startingContext: Partial<TContext>;
306
+ /** {@inheritDoc Machine.meta} */
307
+ meta: Record<string, any>;
287
308
  /** {@inheritDoc Machine.complete} */
288
309
  complete: boolean;
289
310
  /** {@inheritDoc Machine.output} */
@@ -308,6 +329,10 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
308
329
  * @internal
309
330
  */
310
331
  protected subscribe(): void;
332
+ /**
333
+ * @internal
334
+ */
335
+ protected applySnapshot(snapshot?: typeof this.snapshot): void;
311
336
  /**
312
337
  * @internal
313
338
  */
@@ -326,6 +351,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
326
351
  matches(value: StateValueFrom<typeof this.machine>): boolean;
327
352
  /** {@inheritDoc Machine.hasTag} */
328
353
  hasTag(tag: string): boolean;
354
+ /** {@inheritDoc Machine.getMetaValuesByKey} */
355
+ getMetaValuesByKey<T = string>(key?: string): T[];
329
356
  /** {@inheritDoc Machine.send} */
330
357
  send(event: TEvent): void;
331
358
  /** {@inheritDoc Machine.onSendEvent} */
@@ -1 +1 @@
1
- {"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../../../src/core/machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EACL,eAAe,EAEf,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,8BAA8B,EAC9B,eAAe,EACf,kBAAkB,EAClB,cAAc,IAAI,eAAe,EACjC,OAAO,EACP,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,EAEd,eAAe,EAChB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAe,wBAAwB,EAAoB,MAAM,WAAW,CAAC;AAEpF;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC1C;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,WAAW,OAAO,CACtB,QAAQ,SAAS,cAAc,EAC/B,MAAM,SAAS,WAAW,GAAG,cAAc,EAC3C,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C,CAAC"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/core/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAC1B,MAAM,gBACG,MAAM,UACb,OAAO,KACb,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CA4BpC,CAAC"}
@@ -18,22 +18,34 @@ export declare class APIError extends Error {
18
18
  status: number;
19
19
  data?: unknown;
20
20
  constructor(status: number, data?: unknown, message?: string);
21
+ /**
22
+ * @public
23
+ */
24
+ isUnauthorized(): boolean;
21
25
  }
22
26
  /**
27
+ * isAPIError.
23
28
  * @param error - An error.
24
29
  * @public
25
30
  */
26
- export declare const isAPIError: (error: unknown) => boolean;
31
+ export declare const isAPIError: (error: unknown) => error is APIError;
27
32
  /**
28
33
  * @param error - An error.
29
34
  * @public
30
35
  */
31
- export declare const isNetworkError: (error: unknown) => boolean;
36
+ export declare const isNetworkError: (error: unknown) => error is NetworkError;
32
37
  /**
33
38
  * @param error - An error.
34
39
  * @public
35
40
  */
36
41
  export declare const isNotFoundError: (error: {
37
42
  status?: number;
38
- }) => boolean;
43
+ }) => error is APIError;
44
+ /**
45
+ * @param error - An error.
46
+ * @public
47
+ */
48
+ export declare const isUnauthorizedError: (error: {
49
+ status?: number;
50
+ }) => error is APIError;
39
51
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAClB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,OAAO;gBADd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACrB,OAAO,GAAE,MAA6B;CAMzC;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,YAA8B,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,YAEwB,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,eAAe,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,YACG,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAClB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,OAAO;gBADd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACrB,OAAO,GAAE,MAA6B;IAOxC;;OAEG;IACH,cAAc;CAGf;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,sBAAiD,CAAC;AAE3F;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,0BAEwB,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,eAAe,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,sBACG,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,sBACjB,CAAC"}
@@ -35,12 +35,9 @@ export const setErrorByKey = (key) => assign(({ context, event }) => {
35
35
  }
36
36
  });
37
37
  /**
38
- * Escalate error action.
38
+ * Escalate context error action.
39
39
  * @remarks
40
40
  * Guard this call with a parent check to avoid warnings when there's no parent.
41
41
  * @public
42
42
  */
43
- export const escalateError = escalate(({ context }) => ({
44
- error: context.error,
45
- data: context.error,
46
- }));
43
+ export const escalateError = escalate(({ context }) => context.error);
@@ -42,12 +42,13 @@ export class AbstractMachine {
42
42
  this.startingContext = (options.input
43
43
  ? Object.assign(Object.assign({}, contextWithErrors), options.input) : contextWithErrors);
44
44
  this.actor = interpret(this.machine, Object.assign(Object.assign({}, options), { input: this.startingContext, state: this.startingState }));
45
- const { value: currentValue, context: currentContext } = this.actor.getSnapshot();
46
- this.state = currentValue;
47
- this.context = currentContext;
45
+ this.snapshot = this.actor.getSnapshot();
46
+ this.state = this.snapshot.value;
47
+ this.context = this.snapshot.context;
48
+ this.meta = this.snapshot.meta;
48
49
  this.complete = false;
49
50
  this.output = undefined;
50
- this.errors = currentContext.errors;
51
+ this.errors = this.context.errors;
51
52
  this.error = undefined;
52
53
  }
53
54
  /**
@@ -59,24 +60,34 @@ export class AbstractMachine {
59
60
  }
60
61
  this.subscription = this.actor.subscribe({
61
62
  next: (snapshot) => {
62
- var _a;
63
- this.state = snapshot.value;
64
- this.context = snapshot.context;
65
- this.errors = this.context.errors;
66
- this.error = (_a = this.context.error) !== null && _a !== void 0 ? _a : this.errors.lastError;
63
+ this.applySnapshot(snapshot);
67
64
  logger.debug(`${this.machine.id} changed, state:`, this.state, `context:`, this.context);
68
65
  },
69
66
  error: (err) => {
67
+ this.applySnapshot();
70
68
  this.error = err;
71
69
  logger.error(`${this.machine.id} error:`, err);
72
70
  },
73
71
  complete: () => {
72
+ this.applySnapshot();
74
73
  this.complete = true;
75
- this.output = this.actor.getSnapshot().output;
74
+ this.output = this.snapshot.output;
76
75
  logger.debug(`${this.machine.id} complete:`, this.output);
77
76
  },
78
77
  });
79
78
  }
79
+ /**
80
+ * @internal
81
+ */
82
+ applySnapshot(snapshot = this.actor.getSnapshot()) {
83
+ var _a;
84
+ this.snapshot = snapshot;
85
+ this.state = this.snapshot.value;
86
+ this.context = this.snapshot.context;
87
+ this.meta = this.snapshot.meta;
88
+ this.errors = this.context.errors;
89
+ this.error = (_a = this.context.error) !== null && _a !== void 0 ? _a : this.errors.lastError;
90
+ }
80
91
  /**
81
92
  * @internal
82
93
  */
@@ -117,14 +128,24 @@ export class AbstractMachine {
117
128
  if (!this.actor) {
118
129
  throw new Error('Call interpret() before calling matches()');
119
130
  }
120
- return this.actor.getSnapshot().matches(value);
131
+ return this.snapshot.matches(value);
121
132
  }
122
133
  /** {@inheritDoc Machine.hasTag} */
123
134
  hasTag(tag) {
124
135
  if (!this.actor) {
125
136
  throw new Error('Call interpret() before calling hasTag()');
126
137
  }
127
- return this.actor.getSnapshot().hasTag(tag);
138
+ return this.snapshot.hasTag(tag);
139
+ }
140
+ /** {@inheritDoc Machine.getMetaValuesByKey} */
141
+ getMetaValuesByKey(key = 'content') {
142
+ const metaValues = [];
143
+ if (this.meta) {
144
+ for (const value of Object.values(this.meta)) {
145
+ metaValues.push(typeof value === 'object' ? value[key] : value);
146
+ }
147
+ }
148
+ return metaValues;
128
149
  }
129
150
  /** {@inheritDoc Machine.send} */
130
151
  send(event) {
@@ -154,6 +175,9 @@ __decorate([
154
175
  __decorate([
155
176
  observable
156
177
  ], AbstractMachine.prototype, "actor", void 0);
178
+ __decorate([
179
+ observable
180
+ ], AbstractMachine.prototype, "snapshot", void 0);
157
181
  __decorate([
158
182
  observable
159
183
  ], AbstractMachine.prototype, "state", void 0);
@@ -166,6 +190,9 @@ __decorate([
166
190
  __decorate([
167
191
  observable
168
192
  ], AbstractMachine.prototype, "startingContext", void 0);
193
+ __decorate([
194
+ observable
195
+ ], AbstractMachine.prototype, "meta", void 0);
169
196
  __decorate([
170
197
  observable
171
198
  ], AbstractMachine.prototype, "complete", void 0);
@@ -1,4 +1,4 @@
1
- import { setErrorByKey } from './actions';
1
+ import { escalateError, setErrorByKey } from './actions';
2
2
  /**
3
3
  * Creates an error state node.
4
4
  *
@@ -8,19 +8,31 @@ import { setErrorByKey } from './actions';
8
8
  * @public
9
9
  */
10
10
  export const createErrorStateNode = (key, metaContent, final = true) => {
11
+ /**
12
+ * Raised question on reuse and dynamic parent detection, regarding error escalation.
13
+ * https://github.com/statelyai/xstate/discussions/4268
14
+ */
15
+ let hasParentMachine = false;
16
+ let sentToParentMachine = false;
11
17
  return {
12
18
  tags: ['error', key],
13
19
  meta: {
14
20
  content: metaContent ? metaContent : `${key} error.`,
15
21
  },
16
- entry: [setErrorByKey(`${key}-error`)],
22
+ entry: [
23
+ setErrorByKey(`${key}-error`),
24
+ (args) => (hasParentMachine = args.self._parent !== undefined),
25
+ ],
26
+ always: [
27
+ {
28
+ guard: () => hasParentMachine && !sentToParentMachine,
29
+ actions: [escalateError, () => (sentToParentMachine = true)],
30
+ },
31
+ ],
17
32
  /**
18
33
  * Provide final output to parent machines.
19
34
  */
20
35
  type: final ? 'final' : 'atomic',
21
- output: ({ context }) => ({
22
- error: context.error,
23
- data: context.error,
24
- }),
36
+ output: ({ context }) => context.error,
25
37
  };
26
38
  };
@@ -27,8 +27,15 @@ export class APIError extends Error {
27
27
  this.name = 'APIError';
28
28
  Object.setPrototypeOf(this, APIError.prototype);
29
29
  }
30
+ /**
31
+ * @public
32
+ */
33
+ isUnauthorized() {
34
+ return this.status === StatusCodes.UNAUTHORIZED;
35
+ }
30
36
  }
31
37
  /**
38
+ * isAPIError.
32
39
  * @param error - An error.
33
40
  * @public
34
41
  */
@@ -44,3 +51,8 @@ export const isNetworkError = (error) => error instanceof NetworkError ||
44
51
  * @public
45
52
  */
46
53
  export const isNotFoundError = (error) => isAPIError(error) && error.status === StatusCodes.NOT_FOUND;
54
+ /**
55
+ * @param error - An error.
56
+ * @public
57
+ */
58
+ export const isUnauthorizedError = (error) => isAPIError(error) && error.isUnauthorized();