@genesislcap/foundation-state-machine 14.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/dts/core/actions.d.ts +61 -0
- package/dist/dts/core/actions.d.ts.map +1 -0
- package/dist/dts/core/binding.d.ts +37 -0
- package/dist/dts/core/binding.d.ts.map +1 -0
- package/dist/dts/core/errors.d.ts +41 -0
- package/dist/dts/core/errors.d.ts.map +1 -0
- package/dist/dts/core/guards.d.ts +67 -0
- package/dist/dts/core/guards.d.ts.map +1 -0
- package/dist/dts/core/index.d.ts +8 -0
- package/dist/dts/core/index.d.ts.map +1 -0
- package/dist/dts/core/inputs.d.ts +19 -0
- package/dist/dts/core/inputs.d.ts.map +1 -0
- package/dist/dts/core/machine.d.ts +338 -0
- package/dist/dts/core/machine.d.ts.map +1 -0
- package/dist/dts/core/state.d.ts +11 -0
- package/dist/dts/core/state.d.ts.map +1 -0
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/index.federated.d.ts +1 -0
- package/dist/dts/index.federated.d.ts.map +1 -0
- package/dist/dts/machines/fetch/errors.d.ts +39 -0
- package/dist/dts/machines/fetch/errors.d.ts.map +1 -0
- package/dist/dts/machines/fetch/index.d.ts +5 -0
- package/dist/dts/machines/fetch/index.d.ts.map +1 -0
- package/dist/dts/machines/fetch/machine.d.ts +57 -0
- package/dist/dts/machines/fetch/machine.d.ts.map +1 -0
- package/dist/dts/machines/fetch/policies.d.ts +25 -0
- package/dist/dts/machines/fetch/policies.d.ts.map +1 -0
- package/dist/dts/machines/fetch/types.d.ts +118 -0
- package/dist/dts/machines/fetch/types.d.ts.map +1 -0
- package/dist/dts/machines/index.d.ts +2 -0
- package/dist/dts/machines/index.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/utils/index.d.ts +2 -0
- package/dist/dts/utils/index.d.ts.map +1 -0
- package/dist/dts/utils/logger.d.ts +5 -0
- package/dist/dts/utils/logger.d.ts.map +1 -0
- package/dist/esm/core/actions.js +46 -0
- package/dist/esm/core/binding.js +16 -0
- package/dist/esm/core/errors.js +70 -0
- package/dist/esm/core/guards.js +73 -0
- package/dist/esm/core/index.js +7 -0
- package/dist/esm/core/inputs.js +10 -0
- package/dist/esm/core/machine.js +180 -0
- package/dist/esm/core/state.js +26 -0
- package/dist/esm/index.federated.js +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/machines/fetch/errors.js +46 -0
- package/dist/esm/machines/fetch/index.js +4 -0
- package/dist/esm/machines/fetch/machine.js +216 -0
- package/dist/esm/machines/fetch/policies.js +48 -0
- package/dist/esm/machines/fetch/types.js +48 -0
- package/dist/esm/machines/index.js +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/logger.js +5 -0
- package/dist/foundation-state-machine.api.json +5594 -0
- package/dist/foundation-state-machine.d.ts +884 -0
- package/docs/.gitattributes +2 -0
- package/docs/api/foundation-state-machine.abstractmachine.actor.md +18 -0
- package/docs/api/foundation-state-machine.abstractmachine.binding.md +27 -0
- package/docs/api/foundation-state-machine.abstractmachine.complete.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.context.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.error.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.errors.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.getfromcontainer.md +23 -0
- package/docs/api/foundation-state-machine.abstractmachine.hastag.md +28 -0
- package/docs/api/foundation-state-machine.abstractmachine.machine.md +18 -0
- package/docs/api/foundation-state-machine.abstractmachine.matches.md +28 -0
- package/docs/api/foundation-state-machine.abstractmachine.md +44 -0
- package/docs/api/foundation-state-machine.abstractmachine.onsendevent.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.output.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.provide.md +24 -0
- package/docs/api/foundation-state-machine.abstractmachine.send.md +24 -0
- package/docs/api/foundation-state-machine.abstractmachine.start.md +28 -0
- package/docs/api/foundation-state-machine.abstractmachine.startingcontext.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.startingstate.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.state.md +13 -0
- package/docs/api/foundation-state-machine.abstractmachine.stop.md +17 -0
- package/docs/api/foundation-state-machine.apierror._constructor_.md +22 -0
- package/docs/api/foundation-state-machine.apierror.data.md +11 -0
- package/docs/api/foundation-state-machine.apierror.md +32 -0
- package/docs/api/foundation-state-machine.apierror.status.md +11 -0
- package/docs/api/foundation-state-machine.assertevent.md +27 -0
- package/docs/api/foundation-state-machine.createerrorstatenode.md +13 -0
- package/docs/api/foundation-state-machine.createfetchpolicy.md +18 -0
- package/docs/api/foundation-state-machine.createresponsedataextractorwithdeserializer.md +13 -0
- package/docs/api/foundation-state-machine.defaultfetchconfig.md +13 -0
- package/docs/api/foundation-state-machine.defaultfetchmachine._constructor_.md +20 -0
- package/docs/api/foundation-state-machine.defaultfetchmachine.getfromcontainer.md +23 -0
- package/docs/api/foundation-state-machine.defaultfetchmachine.md +30 -0
- package/docs/api/foundation-state-machine.defaultfetchmachine.start.md +28 -0
- package/docs/api/foundation-state-machine.defaultfetchmachinecontext.md +13 -0
- package/docs/api/foundation-state-machine.defaultfetchpolicy.md +13 -0
- package/docs/api/foundation-state-machine.defaultresponsedataextractor.md +18 -0
- package/docs/api/foundation-state-machine.defaultresponseokchecker.md +13 -0
- package/docs/api/foundation-state-machine.defaultretrystatscodes.md +13 -0
- package/docs/api/foundation-state-machine.errorworkflowinput.md +15 -0
- package/docs/api/foundation-state-machine.escalateerror.md +42 -0
- package/docs/api/foundation-state-machine.fetchconfig.fetcher.md +13 -0
- package/docs/api/foundation-state-machine.fetchconfig.fetchpolicy.md +13 -0
- package/docs/api/foundation-state-machine.fetchconfig.md +23 -0
- package/docs/api/foundation-state-machine.fetchconfig.responsedataextractor.md +13 -0
- package/docs/api/foundation-state-machine.fetchconfig.responseokchecker.md +13 -0
- package/docs/api/foundation-state-machine.fetchmachine.md +15 -0
- package/docs/api/foundation-state-machine.fetchmachinecontext.controller.md +13 -0
- package/docs/api/foundation-state-machine.fetchmachinecontext.data.md +13 -0
- package/docs/api/foundation-state-machine.fetchmachinecontext.md +28 -0
- package/docs/api/foundation-state-machine.fetchmachinecontext.params.md +17 -0
- package/docs/api/foundation-state-machine.fetchmachinecontext.response.md +13 -0
- package/docs/api/foundation-state-machine.fetchmachineevent.md +24 -0
- package/docs/api/foundation-state-machine.fetchmachineeventmap.md +21 -0
- package/docs/api/foundation-state-machine.fetchmachineoutput.md +21 -0
- package/docs/api/foundation-state-machine.genesisservererror._constructor_.md +22 -0
- package/docs/api/foundation-state-machine.genesisservererror.getdetailserror.md +15 -0
- package/docs/api/foundation-state-machine.genesisservererror.getmessageerror.md +15 -0
- package/docs/api/foundation-state-machine.genesisservererror.haserrorcode.md +22 -0
- package/docs/api/foundation-state-machine.genesisservererror.isignorableerror.md +17 -0
- package/docs/api/foundation-state-machine.genesisservererror.md +41 -0
- package/docs/api/foundation-state-machine.genesisservererror.received.md +11 -0
- package/docs/api/foundation-state-machine.genesisservererror.sent.md +11 -0
- package/docs/api/foundation-state-machine.isaborterror.md +15 -0
- package/docs/api/foundation-state-machine.isactorerrorevent.md +13 -0
- package/docs/api/foundation-state-machine.isapierror.md +11 -0
- package/docs/api/foundation-state-machine.isdoneinvokeevent.md +13 -0
- package/docs/api/foundation-state-machine.iserrorcustomevent.md +18 -0
- package/docs/api/foundation-state-machine.iserrorevent.md +13 -0
- package/docs/api/foundation-state-machine.iserrortype.md +13 -0
- package/docs/api/foundation-state-machine.isgenesisservererror.md +11 -0
- package/docs/api/foundation-state-machine.ismappingerror.md +11 -0
- package/docs/api/foundation-state-machine.isnetworkerror.md +11 -0
- package/docs/api/foundation-state-machine.isnotfounderror.md +13 -0
- package/docs/api/foundation-state-machine.issyntaxerror.md +15 -0
- package/docs/api/foundation-state-machine.istypeerror.md +15 -0
- package/docs/api/foundation-state-machine.logger.md +12 -0
- package/docs/api/foundation-state-machine.machine.actor.md +18 -0
- package/docs/api/foundation-state-machine.machine.binding.md +47 -0
- package/docs/api/foundation-state-machine.machine.complete.md +13 -0
- package/docs/api/foundation-state-machine.machine.context.md +13 -0
- package/docs/api/foundation-state-machine.machine.error.md +13 -0
- package/docs/api/foundation-state-machine.machine.errors.md +13 -0
- package/docs/api/foundation-state-machine.machine.getfromcontainer.md +35 -0
- package/docs/api/foundation-state-machine.machine.hastag.md +35 -0
- package/docs/api/foundation-state-machine.machine.machine.md +18 -0
- package/docs/api/foundation-state-machine.machine.matches.md +35 -0
- package/docs/api/foundation-state-machine.machine.md +101 -0
- package/docs/api/foundation-state-machine.machine.onsendevent.md +24 -0
- package/docs/api/foundation-state-machine.machine.output.md +13 -0
- package/docs/api/foundation-state-machine.machine.provide.md +44 -0
- package/docs/api/foundation-state-machine.machine.send.md +24 -0
- package/docs/api/foundation-state-machine.machine.start.md +28 -0
- package/docs/api/foundation-state-machine.machine.startingcontext.md +13 -0
- package/docs/api/foundation-state-machine.machine.startingstate.md +13 -0
- package/docs/api/foundation-state-machine.machine.state.md +13 -0
- package/docs/api/foundation-state-machine.machine.stop.md +17 -0
- package/docs/api/foundation-state-machine.machinecontext.error.md +13 -0
- package/docs/api/foundation-state-machine.machinecontext.errors.md +13 -0
- package/docs/api/foundation-state-machine.machinecontext.md +36 -0
- package/docs/api/foundation-state-machine.mappingerror._constructor_.md +21 -0
- package/docs/api/foundation-state-machine.mappingerror.dto.md +11 -0
- package/docs/api/foundation-state-machine.mappingerror.md +27 -0
- package/docs/api/foundation-state-machine.md +81 -0
- package/docs/api/foundation-state-machine.networkerror._constructor_.md +21 -0
- package/docs/api/foundation-state-machine.networkerror.md +31 -0
- package/docs/api/foundation-state-machine.networkerror.url.md +11 -0
- package/docs/api/foundation-state-machine.responsedataextractor.md +18 -0
- package/docs/api/foundation-state-machine.responseokchecker.md +13 -0
- package/docs/api/foundation-state-machine.seterror.md +25 -0
- package/docs/api/foundation-state-machine.seterrorbykey.md +25 -0
- package/docs/api/index.md +12 -0
- package/docs/api-report.md +393 -0
- package/license.txt +46 -0
- package/package.json +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.federated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.federated.d.ts","sourceRoot":"","sources":["../../src/index.federated.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NetworkError.
|
|
3
|
+
* @remarks
|
|
4
|
+
* Failed to reach server.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetworkError extends Error {
|
|
8
|
+
url: string;
|
|
9
|
+
constructor(url: string, message?: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* APIError.
|
|
13
|
+
* @remarks
|
|
14
|
+
* Bad server `Response`.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare class APIError extends Error {
|
|
18
|
+
status: number;
|
|
19
|
+
data?: unknown;
|
|
20
|
+
constructor(status: number, data?: unknown, message?: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @param error - An error.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const isAPIError: (error: unknown) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @param error - An error.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare const isNetworkError: (error: unknown) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @param error - An error.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const isNotFoundError: (error: {
|
|
37
|
+
status?: number;
|
|
38
|
+
}) => boolean;
|
|
39
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { IMergedPolicy } from 'cockatiel';
|
|
2
|
+
import type { InterpreterOptions } from 'xstate';
|
|
3
|
+
import { AbstractMachine, Machine } from '../../core';
|
|
4
|
+
import type { FetchMachineContext, FetchMachineEvent, ResponseDataExtractor, ResponseOkChecker } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* FetchConfig interface.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface FetchConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Defaults to {@link typescript#fetch}.
|
|
12
|
+
* @privateRemarks
|
|
13
|
+
* This config property allows us to mock {@link typescript#Response | responses} during testing.
|
|
14
|
+
*/
|
|
15
|
+
fetcher: typeof fetch;
|
|
16
|
+
/**
|
|
17
|
+
* Defaults to {@link defaultFetchPolicy}
|
|
18
|
+
*/
|
|
19
|
+
fetchPolicy?: IMergedPolicy<any, any, any>;
|
|
20
|
+
/**
|
|
21
|
+
* Defaults to {@link defaultResponseOkChecker}
|
|
22
|
+
*/
|
|
23
|
+
responseOkChecker?: ResponseOkChecker;
|
|
24
|
+
/**
|
|
25
|
+
* Defaults to {@link defaultResponseDataExtractor}
|
|
26
|
+
*/
|
|
27
|
+
responseDataExtractor?: ResponseDataExtractor;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* FetchConfig DI key.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare const FetchConfig: import("@microsoft/fast-foundation").InterfaceSymbol<FetchConfig>;
|
|
34
|
+
/**
|
|
35
|
+
* FetchMachine interface.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface FetchMachine extends Machine<FetchMachineContext, FetchMachineEvent> {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Default FetchMachine.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare class DefaultFetchMachine extends AbstractMachine<FetchMachineContext, FetchMachineEvent> implements FetchMachine {
|
|
45
|
+
private config;
|
|
46
|
+
constructor(config?: FetchConfig);
|
|
47
|
+
/** {@inheritDoc Machine.start} */
|
|
48
|
+
start(options?: InterpreterOptions<typeof this.machine>): void;
|
|
49
|
+
/** {@inheritDoc Machine.getFromContainer} */
|
|
50
|
+
getFromContainer(): this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* FetchMachine DI key.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare const FetchMachine: import("@microsoft/fast-foundation").InterfaceSymbol<FetchMachine>;
|
|
57
|
+
//# sourceMappingURL=machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/machine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EACL,eAAe,EAOf,OAAO,EAER,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EAEjB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,OAAO,EAAE,OAAO,KAAK,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,mEAAoC,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;CAAG;AAExF;;;GAGG;AACH,qBAAa,mBACX,SAAQ,eAAe,CAAC,mBAAmB,EAAE,iBAAiB,CAC9D,YAAW,YAAY;IAEY,OAAO,CAAC,MAAM;gBAAN,MAAM,cAAqB;IAkMtE,kCAAkC;IAClC,KAAK,CACH,OAAO,GAAE,kBAAkB,CAAC,OAAO,IAAI,CAAC,OAAO,CAE9C;IAKH,6CAA6C;IAC7C,gBAAgB,IAAI,IAAI;CAGzB;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,oEAExB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IBackoffFactory, IRetryBackoffContext } from 'cockatiel';
|
|
2
|
+
import { StatusCodes } from 'http-status-codes';
|
|
3
|
+
/**
|
|
4
|
+
* Default retry stats codes.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const defaultRetryStatsCodes: StatusCodes[];
|
|
8
|
+
/**
|
|
9
|
+
* A fetch policy factory.
|
|
10
|
+
* @remarks
|
|
11
|
+
* Will retry network errors and responses with certain status codes up to the specified max attempts.
|
|
12
|
+
* @param maxAttempts - Max attempts. Defaults to `2`.
|
|
13
|
+
* @param retryCodes - Status code array to retry. Defaults to {@link defaultRetryStatsCodes}.
|
|
14
|
+
* @param backoff - Backoff algo. Defaults to {@link cockatiel#ExponentialBackoff}.
|
|
15
|
+
* @param timeoutDuration - Timeout duration. Defaults to 3 seconds.
|
|
16
|
+
* @param logEvents - Log events to the console. Defaults to `true`.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare const createFetchPolicy: (maxAttempts?: number, retryCodes?: StatusCodes[] | number[], backoff?: IBackoffFactory<IRetryBackoffContext<unknown>>, timeoutDuration?: number, logEvents?: boolean) => import("cockatiel").IMergedPolicy<import("cockatiel").IRetryContext & import("cockatiel").ICancellationContext, never, [import("cockatiel").RetryPolicy, import("cockatiel").TimeoutPolicy]>;
|
|
20
|
+
/**
|
|
21
|
+
* The default fetch policy.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare const defaultFetchPolicy: import("cockatiel").IMergedPolicy<import("cockatiel").IRetryContext & import("cockatiel").ICancellationContext, never, [import("cockatiel").RetryPolicy, import("cockatiel").TimeoutPolicy]>;
|
|
25
|
+
//# sourceMappingURL=policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/policies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,eAOlC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,iBACf,MAAM,eACP,WAAW,EAAE,GAAG,MAAM,EAAE,YAC3B,gBAAgB,qBAAqB,OAAO,CAAC,CAAC,oBACtC,MAAM,cACZ,OAAO,iMAmBnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,8LAAsB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/// <reference types="webappsec-credential-management" />
|
|
2
|
+
import type { DoneInvokeEvent, ErrorEvent } from 'xstate';
|
|
3
|
+
import type { MachineContext } from '../../core';
|
|
4
|
+
import type { FetchConfig } from './machine';
|
|
5
|
+
/**
|
|
6
|
+
* FetchMachineContext interface.
|
|
7
|
+
* @remarks
|
|
8
|
+
* Transient state during the machine's execution.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface FetchMachineContext extends MachineContext {
|
|
12
|
+
/**
|
|
13
|
+
* The params of the fetch request.
|
|
14
|
+
*/
|
|
15
|
+
params: {
|
|
16
|
+
url: string;
|
|
17
|
+
/**
|
|
18
|
+
* See {@link typescript#RequestInit} or {@link typescript#CMRequestInit}.
|
|
19
|
+
*/
|
|
20
|
+
requestInit?: RequestInit | CMRequestInit;
|
|
21
|
+
/**
|
|
22
|
+
* Individual fetch requests can provide fetch config overrides when necessary.
|
|
23
|
+
*/
|
|
24
|
+
fetchConfig?: FetchConfig;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The abort controller of the fetch request.
|
|
28
|
+
*/
|
|
29
|
+
controller: AbortController;
|
|
30
|
+
/**
|
|
31
|
+
* The fetch response.
|
|
32
|
+
*/
|
|
33
|
+
response: Response | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The extracted response data.
|
|
36
|
+
*/
|
|
37
|
+
data: any;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* FetchMachineOutput type.
|
|
41
|
+
* @remarks
|
|
42
|
+
* The output of the machine when it reaches it's final state, which is provided to host machines via handlers.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export type FetchMachineOutput<TData = any> = Partial<Pick<FetchMachineContext, 'response' | 'error'>> & {
|
|
46
|
+
data: TData;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* FetchMachineEvent type.
|
|
50
|
+
* @remarks
|
|
51
|
+
* The send action events used to invoke the machine.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export type FetchMachineEvent = {
|
|
55
|
+
type: 'fetch';
|
|
56
|
+
params: FetchMachineContext['params'];
|
|
57
|
+
} | {
|
|
58
|
+
type: 'cancel';
|
|
59
|
+
} | DoneInvokeEvent<unknown> | ErrorEvent<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* FetchMachineEventMap type.
|
|
62
|
+
* @remarks
|
|
63
|
+
* The mediation CustomEvent used to invoke machine actions.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export type FetchMachineEventMap = {
|
|
67
|
+
'fetch-machine-event': FetchMachineEvent;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* ResponseOkChecker type.
|
|
71
|
+
* @privateRemarks
|
|
72
|
+
* Genesis HTTP-Based APIs may provide unexpected status codes, so special handling can be required.
|
|
73
|
+
* @param response - The {@link typescript#Response}.
|
|
74
|
+
* @returns A boolean to indicate if the response is ok.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export type ResponseOkChecker = (response: Response) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* {@inheritDoc ResponseOkChecker}
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export declare const defaultResponseOkChecker: ResponseOkChecker;
|
|
83
|
+
/**
|
|
84
|
+
* ResponseDataExtractor type.
|
|
85
|
+
* @remarks
|
|
86
|
+
* Extracts data from the {@link typescript#Response} and processes it accordingly. The default data extractor will inspect
|
|
87
|
+
* `content-type` and call `JSON.parse()` if it includes `application/json`. Custom data extractors can be used here.
|
|
88
|
+
* @privateRemarks
|
|
89
|
+
* Need to find out if the Genesis http layer returns mixed responses. If needed we can catch and return just the text.
|
|
90
|
+
* @typeParam TData - The expected data type. Defaults to any;
|
|
91
|
+
* @param response - The {@link typescript#Response}.
|
|
92
|
+
* @returns The extracted data.
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export type ResponseDataExtractor<TData = any> = (response: Response) => Promise<TData>;
|
|
96
|
+
/**
|
|
97
|
+
* {@inheritDoc ResponseDataExtractor}
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export declare const defaultResponseDataExtractor: ResponseDataExtractor;
|
|
101
|
+
/**
|
|
102
|
+
* Creates an extractor that applies a deserializer to the extracted response data.
|
|
103
|
+
* @param deserializer - The deserializer to apply.
|
|
104
|
+
* @param extractor - An optional data extractor. Defaults to {@link defaultResponseDataExtractor}.
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export declare const createResponseDataExtractorWithDeserializer: <TInput = any, TOutput = any>(deserializer: (data: TInput) => Promise<TOutput>, extractor?: ResponseDataExtractor) => ResponseDataExtractor;
|
|
108
|
+
/**
|
|
109
|
+
* The default fetch config.
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare const defaultFetchConfig: FetchConfig;
|
|
113
|
+
/**
|
|
114
|
+
* Default FetchMachineContext.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export declare const defaultFetchMachineContext: Partial<FetchMachineContext>;
|
|
118
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/types.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD;;OAEG;IACH,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ;;WAEG;QACH,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;QAC1C;;WAEG;QACH,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,CAAC;IACF;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC;IAC5B;;OAEG;IACH,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;CACX;AAED;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,GAAG,GAAG,IAAI,OAAO,CACnD,IAAI,CAAC,mBAAmB,EAAE,UAAU,GAAG,OAAO,CAAC,CAChD,GAAG;IACF,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;CACvC,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;CAChB,GACD,eAAe,CAAC,OAAO,CAAC,GACxB,UAAU,CAAC,OAAO,CAAC,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,iBAAiB,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBAAuD,CAAC;AAE/F;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,qBAO1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2CAA2C,8FAGzC,qBAAqB,KAC/B,qBAIF,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAKhC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,OAAO,CAAC,mBAAmB,CAKnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/machines/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.34.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,MAAM,gDAA2C,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createErrorMap } from '@genesislcap/foundation-utils';
|
|
2
|
+
import { assign } from 'xstate';
|
|
3
|
+
import { escalate } from 'xstate/actions';
|
|
4
|
+
import { logger } from '../utils';
|
|
5
|
+
import { isErrorEvent } from './guards';
|
|
6
|
+
/**
|
|
7
|
+
* Set error action.
|
|
8
|
+
* @remarks
|
|
9
|
+
* Used to set a top level error on the machine. This may equal to {@link @genesislcap/foundation-utils#ErrorMap} `lastError` in the `errors` property.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const setError = assign(({ event }) => {
|
|
13
|
+
logger.debug('setError', event, isErrorEvent(event));
|
|
14
|
+
if (isErrorEvent(event)) {
|
|
15
|
+
return {
|
|
16
|
+
error: event.data,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Set error by key action.
|
|
22
|
+
* @remarks
|
|
23
|
+
* Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
|
|
24
|
+
* @param key - The error key.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export const setErrorByKey = (key) => assign(({ context, event }) => {
|
|
28
|
+
var _a;
|
|
29
|
+
if (isErrorEvent(event)) {
|
|
30
|
+
const errors = (_a = context.errors) !== null && _a !== void 0 ? _a : createErrorMap(logger.error);
|
|
31
|
+
errors.set(key, event.data);
|
|
32
|
+
return {
|
|
33
|
+
errors,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Escalate error action.
|
|
39
|
+
* @remarks
|
|
40
|
+
* Guard this call with a parent check to avoid warnings when there's no parent.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export const escalateError = escalate(({ context }) => ({
|
|
44
|
+
error: context.error,
|
|
45
|
+
data: context.error,
|
|
46
|
+
}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typeParam TTarget - The target interface.
|
|
3
|
+
* @param args - Binding args.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const getBindArgs = (...args) => {
|
|
7
|
+
const [token] = args;
|
|
8
|
+
let binding = (x) => x;
|
|
9
|
+
if (typeof token === 'function') {
|
|
10
|
+
binding = token;
|
|
11
|
+
}
|
|
12
|
+
else if (typeof token === 'string') {
|
|
13
|
+
binding = (x) => x[token];
|
|
14
|
+
}
|
|
15
|
+
return binding;
|
|
16
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenesisServerError.
|
|
3
|
+
* @remarks
|
|
4
|
+
* Represents an error received from a Genesis Server.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class GenesisServerError extends Error {
|
|
8
|
+
constructor(sent, received, message = 'Genesis Server Error Occurred') {
|
|
9
|
+
super(message);
|
|
10
|
+
this.sent = sent;
|
|
11
|
+
this.received = received;
|
|
12
|
+
this.name = 'GenesisServerError';
|
|
13
|
+
Object.setPrototypeOf(this, GenesisServerError.prototype);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Capture known edge cases.
|
|
17
|
+
* @privateRemarks
|
|
18
|
+
* This is ugly, lets figure out if this is still an issue and remove if not.
|
|
19
|
+
*/
|
|
20
|
+
isIgnorableError() {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
if ((_d = (_c = (_b = (_a = this.received) === null || _a === void 0 ? void 0 : _a.DETAILS) === null || _b === void 0 ? void 0 : _b.ERROR) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === null || _d === void 0 ? void 0 : _d.includes('request needs the user to be logged')) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
getMessageError() {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
return Array.isArray((_a = this.received) === null || _a === void 0 ? void 0 : _a.ERROR)
|
|
30
|
+
? (_b = this.received) === null || _b === void 0 ? void 0 : _b.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
31
|
+
: '';
|
|
32
|
+
}
|
|
33
|
+
getDetailsError() {
|
|
34
|
+
var _a, _b, _c, _d;
|
|
35
|
+
return Array.isArray((_b = (_a = this.received) === null || _a === void 0 ? void 0 : _a.DETAILS) === null || _b === void 0 ? void 0 : _b.ERROR)
|
|
36
|
+
? (_d = (_c = this.received) === null || _c === void 0 ? void 0 : _c.DETAILS) === null || _d === void 0 ? void 0 : _d.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
37
|
+
: '';
|
|
38
|
+
}
|
|
39
|
+
hasErrorCode(code) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
return Array.isArray((_a = this.received) === null || _a === void 0 ? void 0 : _a.ERROR)
|
|
42
|
+
? (_b = this.received) === null || _b === void 0 ? void 0 : _b.ERROR.some((error) => error.CODE === code)
|
|
43
|
+
: false;
|
|
44
|
+
}
|
|
45
|
+
errorDetailFormatter(error) {
|
|
46
|
+
return `\n ${error.CODE}: \n ${error.TEXT}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @param error - An error.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export const isGenesisServerError = (error) => error instanceof GenesisServerError;
|
|
54
|
+
/**
|
|
55
|
+
* MappingError.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export class MappingError extends Error {
|
|
59
|
+
constructor(dto, message = 'Mapping Error Occurred') {
|
|
60
|
+
super(message);
|
|
61
|
+
this.dto = dto;
|
|
62
|
+
this.name = 'MappingError';
|
|
63
|
+
Object.setPrototypeOf(this, MappingError.prototype);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @param error - An error.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export const isMappingError = (error) => error instanceof MappingError;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TaskCancelledError } from 'cockatiel';
|
|
2
|
+
/**
|
|
3
|
+
* assertEvent.
|
|
4
|
+
* @privateRemarks
|
|
5
|
+
* Note `asserts` need to be functions to work.
|
|
6
|
+
* @param event - An event.
|
|
7
|
+
* @param type - An event type.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export function assertEvent(event, type) {
|
|
11
|
+
if (event.type !== type) {
|
|
12
|
+
throw new Error(`${type} event type expected, received ${event.type}.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* isDoneInvokeEvent.
|
|
17
|
+
* @param event - An event.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export const isDoneInvokeEvent = (event) => /^done.invoke/.test(event.type);
|
|
21
|
+
/**
|
|
22
|
+
* isErrorEvent.
|
|
23
|
+
* @param event - An event.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export const isErrorEvent = (event) => /^error.platform/.test(event.type);
|
|
27
|
+
/**
|
|
28
|
+
* isErrorCustomEvent.
|
|
29
|
+
* @remarks
|
|
30
|
+
* What `escalate` from a child is typed as.
|
|
31
|
+
* @param event - An event.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export const isErrorCustomEvent = (event) => /^xstate.error/.test(event.type);
|
|
35
|
+
/**
|
|
36
|
+
* isActorErrorEvent.
|
|
37
|
+
* @param actorId - An actor id.
|
|
38
|
+
* @param event - An event.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export const isActorErrorEvent = (actorId, event) => { var _a, _b; return ((_a = event.type) === null || _a === void 0 ? void 0 : _a.includes('error')) && ((_b = event.type) === null || _b === void 0 ? void 0 : _b.includes(actorId)); };
|
|
42
|
+
/**
|
|
43
|
+
* isErrorType.
|
|
44
|
+
* @param type - An event type.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export const isErrorType = (type) => (event) => {
|
|
48
|
+
if (isErrorEvent(event)) {
|
|
49
|
+
return event.data instanceof type;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* isTypeError.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export const isTypeError = ({ event }) => isErrorType(TypeError)(event);
|
|
58
|
+
/**
|
|
59
|
+
* isSyntaxError.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export const isSyntaxError = ({ event }) => isErrorType(SyntaxError)(event);
|
|
63
|
+
/**
|
|
64
|
+
* isAbortError.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export const isAbortError = ({ event }) => {
|
|
68
|
+
if (isErrorEvent(event)) {
|
|
69
|
+
return ((event.data instanceof DOMException && event.data.code == DOMException.ABORT_ERR) ||
|
|
70
|
+
event.data instanceof TaskCancelledError);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|