@sprucelabs/mercury-client 42.0.556 → 42.0.558
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/build/esm/.spruce/errors/errors.types.d.ts +324 -0
- package/build/esm/.spruce/errors/errors.types.js +1 -0
- package/build/esm/.spruce/errors/mercuryClient/connectionFailed.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/connectionFailed.schema.js +25 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidEventSignature.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidEventSignature.schema.js +25 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidPayload.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidPayload.schema.js +19 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidProtocol.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/invalidProtocol.schema.js +19 -0
- package/build/esm/.spruce/errors/mercuryClient/missingTestCacheDir.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/missingTestCacheDir.schema.js +12 -0
- package/build/esm/.spruce/errors/mercuryClient/mustCreateEvent.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/mustCreateEvent.schema.js +19 -0
- package/build/esm/.spruce/errors/mercuryClient/mustHandleLocally.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/mustHandleLocally.schema.js +19 -0
- package/build/esm/.spruce/errors/mercuryClient/notConnected.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/notConnected.schema.js +25 -0
- package/build/esm/.spruce/errors/mercuryClient/timeout.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/timeout.schema.js +35 -0
- package/build/esm/.spruce/errors/mercuryClient/unauthorizedAccess.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/unauthorizedAccess.schema.js +41 -0
- package/build/esm/.spruce/errors/mercuryClient/unauthorizedTarget.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/unauthorizedTarget.schema.js +38 -0
- package/build/esm/.spruce/errors/mercuryClient/unexpectedPayload.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/unexpectedPayload.schema.js +19 -0
- package/build/esm/.spruce/errors/mercuryClient/unknownError.schema.d.ts +3 -0
- package/build/esm/.spruce/errors/mercuryClient/unknownError.schema.js +12 -0
- package/build/esm/.spruce/errors/options.types.d.ts +40 -0
- package/build/esm/.spruce/errors/options.types.js +1 -0
- package/build/esm/.spruce/event-cache.json +1 -0
- package/build/esm/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
- package/build/esm/.spruce/schemas/fields/fieldClassMap.js +5 -0
- package/build/esm/.spruce/schemas/fields/fields.types.d.ts +1 -0
- package/build/esm/.spruce/schemas/fields/fields.types.js +3 -0
- package/build/esm/.spruce/schemas/schemas.types.d.ts +1 -0
- package/build/esm/.spruce/schemas/schemas.types.js +3 -0
- package/build/esm/.spruce/settings.json +26 -0
- package/build/esm/clients/MercuryClientFactory.d.ts +26 -0
- package/build/esm/clients/MercuryClientFactory.js +96 -0
- package/build/esm/clients/MercurySocketIoClient.d.ts +89 -0
- package/build/esm/clients/MercurySocketIoClient.js +605 -0
- package/build/esm/clients/MercuryTestClient.d.ts +57 -0
- package/build/esm/clients/MercuryTestClient.js +389 -0
- package/build/esm/clients/MutableContractClient.d.ts +10 -0
- package/build/esm/clients/MutableContractClient.js +43 -0
- package/build/esm/clients/statusChangePayloadSchema.d.ts +103 -0
- package/build/esm/clients/statusChangePayloadSchema.js +45 -0
- package/build/esm/constants.d.ts +1 -0
- package/build/esm/constants.js +1 -0
- package/build/esm/errors/SpruceError.d.ts +5 -0
- package/build/esm/errors/SpruceError.js +66 -0
- package/build/esm/errors/connectionFailed.builder.d.ts +16 -0
- package/build/esm/errors/connectionFailed.builder.js +16 -0
- package/build/esm/errors/invalidEventSignature.builder.d.ts +15 -0
- package/build/esm/errors/invalidEventSignature.builder.js +15 -0
- package/build/esm/errors/invalidPayload.builder.d.ts +12 -0
- package/build/esm/errors/invalidPayload.builder.js +12 -0
- package/build/esm/errors/invalidProtocol.builder.d.ts +12 -0
- package/build/esm/errors/invalidProtocol.builder.js +12 -0
- package/build/esm/errors/missingTestCacheDir.builder.d.ts +7 -0
- package/build/esm/errors/missingTestCacheDir.builder.js +7 -0
- package/build/esm/errors/mustCreateEvent.builder.d.ts +11 -0
- package/build/esm/errors/mustCreateEvent.builder.js +11 -0
- package/build/esm/errors/mustHandleLocally.builder.d.ts +11 -0
- package/build/esm/errors/mustHandleLocally.builder.js +11 -0
- package/build/esm/errors/notConnected.builder.d.ts +16 -0
- package/build/esm/errors/notConnected.builder.js +16 -0
- package/build/esm/errors/timeout.builder.d.ts +22 -0
- package/build/esm/errors/timeout.builder.js +22 -0
- package/build/esm/errors/unauthorizedAccess.builder.d.ts +57 -0
- package/build/esm/errors/unauthorizedAccess.builder.js +39 -0
- package/build/esm/errors/unexpectedPayload.builder.d.ts +12 -0
- package/build/esm/errors/unexpectedPayload.builder.js +12 -0
- package/build/esm/errors/unknownError.builder.d.ts +6 -0
- package/build/esm/errors/unknownError.builder.js +6 -0
- package/build/esm/index.d.ts +6 -0
- package/build/esm/index.js +6 -0
- package/build/esm/tests/AbstractClientTest.d.ts +31 -0
- package/build/esm/tests/AbstractClientTest.js +212 -0
- package/build/esm/tests/constants.d.ts +9 -0
- package/build/esm/tests/constants.js +11 -0
- package/build/esm/types/client.types.d.ts +30 -0
- package/build/esm/types/client.types.js +1 -0
- package/build/esm/utilities/socketIoEventUtil.utility.d.ts +5 -0
- package/build/esm/utilities/socketIoEventUtil.utility.js +9 -0
- package/package.json +12 -12
- package/build/__tests__/behavioral/AuthenticatingAndReauthenticating.test.d.ts +0 -21
- package/build/__tests__/behavioral/AuthenticatingAndReauthenticating.test.js +0 -287
- package/build/__tests__/behavioral/AuthenticatingAndReauthenticating.test.js.map +0 -1
- package/build/__tests__/behavioral/DisablingPermissionChecksWhenEmittingLocally.test.d.ts +0 -7
- package/build/__tests__/behavioral/DisablingPermissionChecksWhenEmittingLocally.test.js +0 -49
- package/build/__tests__/behavioral/DisablingPermissionChecksWhenEmittingLocally.test.js.map +0 -1
- package/build/__tests__/behavioral/EmittingAndFlatteningResponses.test.d.ts +0 -52
- package/build/__tests__/behavioral/EmittingAndFlatteningResponses.test.js +0 -123
- package/build/__tests__/behavioral/EmittingAndFlatteningResponses.test.js.map +0 -1
- package/build/__tests__/behavioral/EmittingConnectionChangeInTests.test.d.ts +0 -9
- package/build/__tests__/behavioral/EmittingConnectionChangeInTests.test.js +0 -103
- package/build/__tests__/behavioral/EmittingConnectionChangeInTests.test.js.map +0 -1
- package/build/__tests__/behavioral/LocallyHandlingAuthenticateDelaysConnect.test.d.ts +0 -7
- package/build/__tests__/behavioral/LocallyHandlingAuthenticateDelaysConnect.test.js +0 -91
- package/build/__tests__/behavioral/LocallyHandlingAuthenticateDelaysConnect.test.js.map +0 -1
- package/build/__tests__/behavioral/MercuryClientFactory.test.d.ts +0 -7
- package/build/__tests__/behavioral/MercuryClientFactory.test.js +0 -85
- package/build/__tests__/behavioral/MercuryClientFactory.test.js.map +0 -1
- package/build/__tests__/behavioral/ProxyingEvents.test.d.ts +0 -11
- package/build/__tests__/behavioral/ProxyingEvents.test.js +0 -99
- package/build/__tests__/behavioral/ProxyingEvents.test.js.map +0 -1
- package/build/__tests__/behavioral/ReconnectingAutomatically.test.d.ts +0 -33
- package/build/__tests__/behavioral/ReconnectingAutomatically.test.js +0 -390
- package/build/__tests__/behavioral/ReconnectingAutomatically.test.js.map +0 -1
- package/build/__tests__/behavioral/RequiringLocalListeners.test.d.ts +0 -7
- package/build/__tests__/behavioral/RequiringLocalListeners.test.js +0 -65
- package/build/__tests__/behavioral/RequiringLocalListeners.test.js.map +0 -1
- package/build/__tests__/behavioral/SettingNamespacesThatMustBeHandledLocally.test.d.ts +0 -9
- package/build/__tests__/behavioral/SettingNamespacesThatMustBeHandledLocally.test.js +0 -66
- package/build/__tests__/behavioral/SettingNamespacesThatMustBeHandledLocally.test.js.map +0 -1
- package/build/__tests__/behavioral/SimulatingEventsForTesting.test.d.ts +0 -51
- package/build/__tests__/behavioral/SimulatingEventsForTesting.test.js +0 -821
- package/build/__tests__/behavioral/SimulatingEventsForTesting.test.js.map +0 -1
- package/build/__tests__/behavioral/TestClientSpeedTests.test.d.ts +0 -7
- package/build/__tests__/behavioral/TestClientSpeedTests.test.js +0 -44
- package/build/__tests__/behavioral/TestClientSpeedTests.test.js.map +0 -1
- package/build/__tests__/behavioral/TestingWithDefaultContracts.test.d.ts +0 -7
- package/build/__tests__/behavioral/TestingWithDefaultContracts.test.js +0 -56
- package/build/__tests__/behavioral/TestingWithDefaultContracts.test.js.map +0 -1
- package/build/__tests__/behavioral/TurningOffAListener.test.d.ts +0 -16
- package/build/__tests__/behavioral/TurningOffAListener.test.js +0 -126
- package/build/__tests__/behavioral/TurningOffAListener.test.js.map +0 -1
- package/build/__tests__/behavioral/UsingMercuryClient.test.d.ts +0 -45
- package/build/__tests__/behavioral/UsingMercuryClient.test.js +0 -662
- package/build/__tests__/behavioral/UsingMercuryClient.test.js.map +0 -1
- /package/build/{.spruce → esm/.spruce}/errors/errors.types.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/connectionFailed.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/invalidEventSignature.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/invalidPayload.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/invalidProtocol.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/missingTestCacheDir.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/mustCreateEvent.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/mustHandleLocally.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/notConnected.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/timeout.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/unauthorizedAccess.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/unauthorizedTarget.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/unexpectedPayload.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/mercuryClient/unknownError.schema.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/errors/options.types.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/schemas/fields/fieldClassMap.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/schemas/fields/fields.types.js.map +0 -0
- /package/build/{.spruce → esm/.spruce}/schemas/schemas.types.js.map +0 -0
- /package/build/{clients → esm/clients}/MercuryClientFactory.js.map +0 -0
- /package/build/{clients → esm/clients}/MercurySocketIoClient.js.map +0 -0
- /package/build/{clients → esm/clients}/MercuryTestClient.js.map +0 -0
- /package/build/{clients → esm/clients}/MutableContractClient.js.map +0 -0
- /package/build/{clients → esm/clients}/statusChangePayloadSchema.js.map +0 -0
- /package/build/{constants.js.map → esm/constants.js.map} +0 -0
- /package/build/{errors → esm/errors}/SpruceError.js.map +0 -0
- /package/build/{errors → esm/errors}/connectionFailed.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/invalidEventSignature.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/invalidPayload.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/invalidProtocol.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/missingTestCacheDir.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/mustCreateEvent.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/mustHandleLocally.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/notConnected.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/timeout.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/unauthorizedAccess.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/unexpectedPayload.builder.js.map +0 -0
- /package/build/{errors → esm/errors}/unknownError.builder.js.map +0 -0
- /package/build/{index.js.map → esm/index.js.map} +0 -0
- /package/build/{tests → esm/tests}/AbstractClientTest.js.map +0 -0
- /package/build/{tests → esm/tests}/constants.js.map +0 -0
- /package/build/{types → esm/types}/client.types.js.map +0 -0
- /package/build/{utilities → esm/utilities}/socketIoEventUtil.utility.js.map +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require('@sprucelabs/schema');
|
|
4
|
+
const unexpectedPayloadSchema = {
|
|
5
|
+
id: 'unexpectedPayload',
|
|
6
|
+
namespace: 'MercuryClient',
|
|
7
|
+
name: 'Unexpected payload',
|
|
8
|
+
fields: {
|
|
9
|
+
/** . */
|
|
10
|
+
'eventName': {
|
|
11
|
+
type: 'text',
|
|
12
|
+
isRequired: true,
|
|
13
|
+
options: undefined
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(unexpectedPayloadSchema);
|
|
18
|
+
exports.default = unexpectedPayloadSchema;
|
|
19
|
+
//# sourceMappingURL=unexpectedPayload.schema.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require('@sprucelabs/schema');
|
|
4
|
+
const unknownErrorSchema = {
|
|
5
|
+
id: 'unknownError',
|
|
6
|
+
namespace: 'MercuryClient',
|
|
7
|
+
name: 'Unknown error',
|
|
8
|
+
fields: {}
|
|
9
|
+
};
|
|
10
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(unknownErrorSchema);
|
|
11
|
+
exports.default = unknownErrorSchema;
|
|
12
|
+
//# sourceMappingURL=unknownError.schema.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SpruceErrors } from "./errors.types";
|
|
2
|
+
import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
|
|
3
|
+
export interface UnknownErrorErrorOptions extends SpruceErrors.MercuryClient.UnknownError, ISpruceErrorOptions {
|
|
4
|
+
code: 'UNKNOWN_ERROR';
|
|
5
|
+
}
|
|
6
|
+
export interface UnexpectedPayloadErrorOptions extends SpruceErrors.MercuryClient.UnexpectedPayload, ISpruceErrorOptions {
|
|
7
|
+
code: 'UNEXPECTED_PAYLOAD';
|
|
8
|
+
}
|
|
9
|
+
export interface UnauthorizedAccessErrorOptions extends SpruceErrors.MercuryClient.UnauthorizedAccess, ISpruceErrorOptions {
|
|
10
|
+
code: 'UNAUTHORIZED_ACCESS';
|
|
11
|
+
}
|
|
12
|
+
export interface TimeoutErrorOptions extends SpruceErrors.MercuryClient.Timeout, ISpruceErrorOptions {
|
|
13
|
+
code: 'TIMEOUT';
|
|
14
|
+
}
|
|
15
|
+
export interface NotConnectedErrorOptions extends SpruceErrors.MercuryClient.NotConnected, ISpruceErrorOptions {
|
|
16
|
+
code: 'NOT_CONNECTED';
|
|
17
|
+
}
|
|
18
|
+
export interface MustHandleLocallyErrorOptions extends SpruceErrors.MercuryClient.MustHandleLocally, ISpruceErrorOptions {
|
|
19
|
+
code: 'MUST_HANDLE_LOCALLY';
|
|
20
|
+
}
|
|
21
|
+
export interface MustCreateEventErrorOptions extends SpruceErrors.MercuryClient.MustCreateEvent, ISpruceErrorOptions {
|
|
22
|
+
code: 'MUST_CREATE_EVENT';
|
|
23
|
+
}
|
|
24
|
+
export interface MissingTestCacheDirErrorOptions extends SpruceErrors.MercuryClient.MissingTestCacheDir, ISpruceErrorOptions {
|
|
25
|
+
code: 'MISSING_TEST_CACHE_DIR';
|
|
26
|
+
}
|
|
27
|
+
export interface InvalidProtocolErrorOptions extends SpruceErrors.MercuryClient.InvalidProtocol, ISpruceErrorOptions {
|
|
28
|
+
code: 'INVALID_PROTOCOL';
|
|
29
|
+
}
|
|
30
|
+
export interface InvalidPayloadErrorOptions extends SpruceErrors.MercuryClient.InvalidPayload, ISpruceErrorOptions {
|
|
31
|
+
code: 'INVALID_PAYLOAD';
|
|
32
|
+
}
|
|
33
|
+
export interface InvalidEventSignatureErrorOptions extends SpruceErrors.MercuryClient.InvalidEventSignature, ISpruceErrorOptions {
|
|
34
|
+
code: 'INVALID_EVENT_SIGNATURE';
|
|
35
|
+
}
|
|
36
|
+
export interface ConnectionFailedErrorOptions extends SpruceErrors.MercuryClient.ConnectionFailed, ISpruceErrorOptions {
|
|
37
|
+
code: 'CONNECTION_FAILED';
|
|
38
|
+
}
|
|
39
|
+
type ErrorOptions = UnknownErrorErrorOptions | UnexpectedPayloadErrorOptions | UnauthorizedAccessErrorOptions | TimeoutErrorOptions | NotConnectedErrorOptions | MustHandleLocallyErrorOptions | MustCreateEventErrorOptions | MissingTestCacheDirErrorOptions | InvalidProtocolErrorOptions | InvalidPayloadErrorOptions | InvalidEventSignatureErrorOptions | ConnectionFailedErrorOptions;
|
|
40
|
+
export default ErrorOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SpruceSchemas } from '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skipped": [
|
|
3
|
+
"skill",
|
|
4
|
+
"event"
|
|
5
|
+
],
|
|
6
|
+
"installed": [
|
|
7
|
+
"schema",
|
|
8
|
+
"error",
|
|
9
|
+
"test"
|
|
10
|
+
],
|
|
11
|
+
"writer": {
|
|
12
|
+
"skipped": [
|
|
13
|
+
".gitignore"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"scriptUpdater": {
|
|
17
|
+
"skipped": [
|
|
18
|
+
"rebuild",
|
|
19
|
+
"update.dependencies",
|
|
20
|
+
"build.tsc",
|
|
21
|
+
"fix.lint",
|
|
22
|
+
"lint"
|
|
23
|
+
],
|
|
24
|
+
"skips": []
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventContract, SkillEventContract } from '@sprucelabs/mercury-types';
|
|
2
|
+
import { ConnectionOptions, MercuryClient } from '../types/client.types';
|
|
3
|
+
import MutableContractClient from './MutableContractClient';
|
|
4
|
+
export default class MercuryClientFactory {
|
|
5
|
+
private static isTestMode;
|
|
6
|
+
private static defaultContract;
|
|
7
|
+
private static timeoutMs;
|
|
8
|
+
private static totalClients;
|
|
9
|
+
private static clients;
|
|
10
|
+
static ClientClass: new (...args: any[]) => MutableContractClient<EventContract>;
|
|
11
|
+
static Client<Contract extends SkillEventContract = SkillEventContract>(connectionOptions?: ConnectionOptions): Promise<Client<Contract>>;
|
|
12
|
+
static isInTestMode(): boolean;
|
|
13
|
+
static setIsTestMode(isTestMode: boolean): void;
|
|
14
|
+
static setDefaultContract(contract: EventContract): void;
|
|
15
|
+
static hasDefaultContract(): boolean;
|
|
16
|
+
static clearDefaultContract(): void;
|
|
17
|
+
private static resetTestClient;
|
|
18
|
+
static setDefaultTimeoutMs(ms: number): void;
|
|
19
|
+
static getTotalClients(): number;
|
|
20
|
+
static reset(): void;
|
|
21
|
+
static getClients(): Client<import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventContract>[];
|
|
22
|
+
}
|
|
23
|
+
export type Client<Contract extends EventContract> = MercuryClient<Contract> & {
|
|
24
|
+
doesHandleEvent(eventName: string): boolean;
|
|
25
|
+
mixinContract(eventContract: EventContract): void;
|
|
26
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { SchemaError } from '@sprucelabs/schema';
|
|
11
|
+
import { eventContractUtil } from '@sprucelabs/spruce-event-utils';
|
|
12
|
+
import { DEFAULT_HOST } from '../constants.js';
|
|
13
|
+
import SpruceError from '../errors/SpruceError.js';
|
|
14
|
+
import MutableContractClient from './MutableContractClient.js';
|
|
15
|
+
class MercuryClientFactory {
|
|
16
|
+
static Client(connectionOptions) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const { host: hostOption, contracts, reconnectDelayMs, allowSelfSignedCrt, emitTimeoutMs = this.timeoutMs, shouldReconnect, maxEmitRetries, connectionRetries, } = connectionOptions || {};
|
|
20
|
+
const host = hostOption !== null && hostOption !== void 0 ? hostOption : DEFAULT_HOST;
|
|
21
|
+
if (host.substr(0, 4) !== 'http') {
|
|
22
|
+
throw new SpruceError({ code: 'INVALID_PROTOCOL', uri: host });
|
|
23
|
+
}
|
|
24
|
+
if (contracts && !Array.isArray(contracts)) {
|
|
25
|
+
throw new SchemaError({
|
|
26
|
+
code: 'INVALID_PARAMETERS',
|
|
27
|
+
parameters: ['contracts'],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const eventContract = !contracts && this.defaultContract
|
|
31
|
+
? this.defaultContract
|
|
32
|
+
: //@ts-ignore
|
|
33
|
+
eventContractUtil.unifyContracts(contracts !== null && contracts !== void 0 ? contracts : []);
|
|
34
|
+
let Client = MutableContractClient;
|
|
35
|
+
if (this.isTestMode) {
|
|
36
|
+
//TODO, make this something fitxures sets to make the test client available
|
|
37
|
+
Client = require('../clients/MercuryTestClient.js').default;
|
|
38
|
+
}
|
|
39
|
+
const client = new ((_a = MercuryClientFactory.ClientClass) !== null && _a !== void 0 ? _a :
|
|
40
|
+
//@ts-ignore
|
|
41
|
+
Client)({
|
|
42
|
+
host,
|
|
43
|
+
reconnection: false,
|
|
44
|
+
reconnectDelayMs,
|
|
45
|
+
rejectUnauthorized: !allowSelfSignedCrt,
|
|
46
|
+
eventContract,
|
|
47
|
+
emitTimeoutMs,
|
|
48
|
+
shouldReconnect,
|
|
49
|
+
maxEmitRetries,
|
|
50
|
+
connectionRetries,
|
|
51
|
+
});
|
|
52
|
+
yield client.connect();
|
|
53
|
+
this.totalClients++;
|
|
54
|
+
this.clients.push(client);
|
|
55
|
+
return client;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static isInTestMode() {
|
|
59
|
+
return this.isTestMode;
|
|
60
|
+
}
|
|
61
|
+
static setIsTestMode(isTestMode) {
|
|
62
|
+
this.isTestMode = isTestMode;
|
|
63
|
+
}
|
|
64
|
+
static setDefaultContract(contract) {
|
|
65
|
+
this.defaultContract = contract;
|
|
66
|
+
}
|
|
67
|
+
static hasDefaultContract() {
|
|
68
|
+
return !!this.defaultContract;
|
|
69
|
+
}
|
|
70
|
+
static clearDefaultContract() {
|
|
71
|
+
this.defaultContract = undefined;
|
|
72
|
+
}
|
|
73
|
+
static resetTestClient() {
|
|
74
|
+
const Client = require('../clients/MercuryTestClient.js').default;
|
|
75
|
+
Client.reset();
|
|
76
|
+
}
|
|
77
|
+
static setDefaultTimeoutMs(ms) {
|
|
78
|
+
this.timeoutMs = ms;
|
|
79
|
+
}
|
|
80
|
+
static getTotalClients() {
|
|
81
|
+
return this.totalClients;
|
|
82
|
+
}
|
|
83
|
+
static reset() {
|
|
84
|
+
this.totalClients = 0;
|
|
85
|
+
this.clients = [];
|
|
86
|
+
this.resetTestClient();
|
|
87
|
+
}
|
|
88
|
+
static getClients() {
|
|
89
|
+
return this.clients;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
MercuryClientFactory.isTestMode = false;
|
|
93
|
+
MercuryClientFactory.timeoutMs = 30000;
|
|
94
|
+
MercuryClientFactory.totalClients = 0;
|
|
95
|
+
MercuryClientFactory.clients = [];
|
|
96
|
+
export default MercuryClientFactory;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { EmitCallback, EventContract, EventName, EventSignature, MercuryAggregateResponse, SpruceSchemas } from '@sprucelabs/mercury-types';
|
|
2
|
+
import { Schema, SchemaValues } from '@sprucelabs/schema';
|
|
3
|
+
import { io, SocketOptions, ManagerOptions } from 'socket.io-client';
|
|
4
|
+
import { ConnectionOptions, MercuryClient } from '../types/client.types';
|
|
5
|
+
export default class MercurySocketIoClient<Contract extends EventContract> implements MercuryClient<Contract> {
|
|
6
|
+
protected _eventContract?: Contract;
|
|
7
|
+
protected get eventContract(): Contract;
|
|
8
|
+
protected set eventContract(contract: Contract);
|
|
9
|
+
static io: typeof io;
|
|
10
|
+
private log;
|
|
11
|
+
private host;
|
|
12
|
+
private ioOptions;
|
|
13
|
+
private socket?;
|
|
14
|
+
private proxyToken;
|
|
15
|
+
private emitTimeoutMs;
|
|
16
|
+
private reconnectDelayMs;
|
|
17
|
+
private listenerMap;
|
|
18
|
+
private isReAuthing;
|
|
19
|
+
private reconnectPromise;
|
|
20
|
+
protected lastAuthOptions?: {
|
|
21
|
+
skillId?: string | undefined;
|
|
22
|
+
apiKey?: string | undefined;
|
|
23
|
+
token?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
private shouldReconnect;
|
|
26
|
+
private connectionRetriesRemaining;
|
|
27
|
+
private connectionRetries;
|
|
28
|
+
private registeredListeners;
|
|
29
|
+
private allowNextEventToBeAuthenticate;
|
|
30
|
+
protected auth?: {
|
|
31
|
+
skill?: SpruceSchemas.Spruce.v2020_07_22.Skill;
|
|
32
|
+
person?: SpruceSchemas.Spruce.v2020_07_22.Person;
|
|
33
|
+
};
|
|
34
|
+
private shouldAutoRegisterListeners;
|
|
35
|
+
private isManuallyDisconnected;
|
|
36
|
+
private isReconnecting;
|
|
37
|
+
private id;
|
|
38
|
+
private skipWaitIfReconnecting;
|
|
39
|
+
private maxEmitRetries;
|
|
40
|
+
private authRawResults?;
|
|
41
|
+
protected authPromise?: any;
|
|
42
|
+
protected shouldRegisterProxyOnReconnect: boolean;
|
|
43
|
+
private reconnectKey?;
|
|
44
|
+
constructor(options: {
|
|
45
|
+
host: string;
|
|
46
|
+
eventContract?: Contract;
|
|
47
|
+
} & IoOptions);
|
|
48
|
+
connect(): Promise<void>;
|
|
49
|
+
private emitStatusChange;
|
|
50
|
+
private attachConnectError;
|
|
51
|
+
private attemptReconnectAfterDelay;
|
|
52
|
+
protected reconnect(resolve: any, reject: any, retriesLeft: number): Promise<void>;
|
|
53
|
+
protected waitIfReconnecting(): Promise<void>;
|
|
54
|
+
private reRegisterAllListeners;
|
|
55
|
+
private mapSocketErrorToSpruceError;
|
|
56
|
+
emit<Name extends EventName<Contract>, IEventSignature extends EventSignature = Contract['eventSignatures'][EventName], EmitSchema extends Schema = IEventSignature['emitPayloadSchema'] extends Schema ? IEventSignature['emitPayloadSchema'] : never, ResponseSchema extends Schema = IEventSignature['responsePayloadSchema'] extends Schema ? IEventSignature['responsePayloadSchema'] : never, ResponsePayload = ResponseSchema extends Schema ? SchemaValues<ResponseSchema> : never>(eventName: Name, targetAndPayload?: (EmitSchema extends Schema ? SchemaValues<EmitSchema> : never) | EmitCallback<Contract, Name>, cb?: EmitCallback<Contract, Name>): Promise<MercuryAggregateResponse<ResponsePayload>>;
|
|
57
|
+
private handleLocalEmit;
|
|
58
|
+
emitAndFlattenResponses<Name extends EventName<Contract>, IEventSignature extends EventSignature = Contract['eventSignatures'][EventName], EmitSchema extends Schema = IEventSignature['emitPayloadSchema'] extends Schema ? IEventSignature['emitPayloadSchema'] : never, ResponseSchema extends Schema = IEventSignature['responsePayloadSchema'] extends Schema ? IEventSignature['responsePayloadSchema'] : never, ResponsePayload = ResponseSchema extends Schema ? SchemaValues<ResponseSchema> : never>(eventName: Name, payload?: (EmitSchema extends Schema ? SchemaValues<EmitSchema> : never) | EmitCallback<Contract, Name>, cb?: EmitCallback<Contract, Name>): Promise<ResponsePayload[]>;
|
|
59
|
+
private _emit;
|
|
60
|
+
protected assertValidEmitTargetAndPayload<Name extends EventName<Contract>>(eventName: Name, payload: any): void;
|
|
61
|
+
private handleConfirmPinResponse;
|
|
62
|
+
protected getEventSignatureByName<Name extends EventName<Contract>>(eventName: Name): SpruceSchemas.Mercury.v2020_12_25.EventSignature;
|
|
63
|
+
setShouldAutoRegisterListeners(should: boolean): void;
|
|
64
|
+
on<Name extends EventName<Contract>, IEventSignature extends EventSignature = Contract['eventSignatures'][EventName], EmitSchema extends Schema = IEventSignature['emitPayloadSchema'] extends Schema ? IEventSignature['emitPayloadSchema'] : never>(eventName: Name, cb: (payload: EmitSchema extends Schema ? SchemaValues<EmitSchema> : never) => IEventSignature['responsePayloadSchema'] extends Schema ? Promise<SchemaValues<IEventSignature['responsePayloadSchema']>> | SchemaValues<IEventSignature['responsePayloadSchema']> : Promise<void> | void): Promise<void>;
|
|
65
|
+
private isEventLocal;
|
|
66
|
+
off(eventName: EventName<Contract>, cb?: () => void): Promise<number>;
|
|
67
|
+
private removeLocalListener;
|
|
68
|
+
getId(): string;
|
|
69
|
+
disconnect(): Promise<void>;
|
|
70
|
+
authenticate(options: AuthenticateOptions): Promise<{
|
|
71
|
+
skill: any;
|
|
72
|
+
person: any;
|
|
73
|
+
}>;
|
|
74
|
+
isAuthenticated(): boolean;
|
|
75
|
+
isConnected(): boolean;
|
|
76
|
+
private isSocketConnected;
|
|
77
|
+
getProxyToken(): string | null;
|
|
78
|
+
setProxyToken(token: string): void;
|
|
79
|
+
registerProxyToken(): Promise<any>;
|
|
80
|
+
getIsTestClient(): boolean;
|
|
81
|
+
}
|
|
82
|
+
type IoOptions = Partial<ManagerOptions & SocketOptions & ConnectionOptions>;
|
|
83
|
+
export declare const authenticateFqen = "authenticate::v2020_12_25";
|
|
84
|
+
export interface AuthenticateOptions {
|
|
85
|
+
skillId?: string;
|
|
86
|
+
apiKey?: string;
|
|
87
|
+
token?: string;
|
|
88
|
+
}
|
|
89
|
+
export {};
|