@sprucelabs/mercury-client 41.0.385 → 42.0.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.
Files changed (39) hide show
  1. package/build/.spruce/errors/errors.types.d.ts +50 -50
  2. package/build/.spruce/errors/errors.types.js +0 -2
  3. package/build/.spruce/errors/mercuryClient/connectionFailed.schema.js +5 -5
  4. package/build/.spruce/errors/mercuryClient/invalidEventSignature.schema.js +5 -5
  5. package/build/.spruce/errors/mercuryClient/invalidPayload.schema.js +3 -3
  6. package/build/.spruce/errors/mercuryClient/invalidProtocol.schema.js +3 -3
  7. package/build/.spruce/errors/mercuryClient/missingTestCacheDir.schema.js +1 -1
  8. package/build/.spruce/errors/mercuryClient/mustCreateEvent.schema.js +3 -3
  9. package/build/.spruce/errors/mercuryClient/mustHandleLocally.schema.js +3 -3
  10. package/build/.spruce/errors/mercuryClient/notConnected.schema.js +5 -5
  11. package/build/.spruce/errors/mercuryClient/timeout.schema.js +9 -9
  12. package/build/.spruce/errors/mercuryClient/unauthorizedAccess.schema.js +9 -9
  13. package/build/.spruce/errors/mercuryClient/unauthorizedTarget.schema.js +11 -11
  14. package/build/.spruce/errors/mercuryClient/unexpectedPayload.schema.js +3 -3
  15. package/build/.spruce/errors/mercuryClient/unknownError.schema.js +1 -1
  16. package/build/.spruce/errors/options.types.d.ts +2 -2
  17. package/build/.spruce/schemas/fields/fields.types.d.ts +1 -1
  18. package/build/.spruce/schemas/schemas.types.js +0 -2
  19. package/build/clients/MercuryClientFactory.js +11 -10
  20. package/build/clients/MercurySocketIoClient.d.ts +3 -1
  21. package/build/clients/MercurySocketIoClient.js +79 -81
  22. package/build/clients/MercuryTestClient.d.ts +1 -1
  23. package/build/clients/MercuryTestClient.js +50 -41
  24. package/build/clients/MutableContractClient.js +7 -6
  25. package/build/errors/SpruceError.d.ts +1 -1
  26. package/build/errors/SpruceError.js +7 -5
  27. package/build/esm/.spruce/errors/errors.types.d.ts +50 -50
  28. package/build/esm/.spruce/errors/errors.types.js +0 -2
  29. package/build/esm/.spruce/errors/options.types.d.ts +2 -2
  30. package/build/esm/clients/MercurySocketIoClient.d.ts +3 -1
  31. package/build/esm/clients/MercurySocketIoClient.js +11 -2
  32. package/build/esm/clients/MercuryTestClient.d.ts +1 -1
  33. package/build/esm/clients/MercuryTestClient.js +18 -9
  34. package/build/esm/clients/MutableContractClient.js +3 -1
  35. package/build/esm/errors/SpruceError.d.ts +1 -1
  36. package/build/esm/errors/SpruceError.js +5 -2
  37. package/build/tests/AbstractClientTest.js +12 -18
  38. package/build/tests/constants.js +9 -10
  39. package/package.json +115 -129
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
7
7
  const MercurySocketIoClient_1 = __importDefault(require("./MercurySocketIoClient"));
8
8
  class MutableContractClient extends MercurySocketIoClient_1.default {
9
+ static inMemoryContract;
9
10
  static mixinContract(contract) {
10
- var _a;
11
11
  this.inMemoryContract = spruce_event_utils_1.eventContractUtil.unifyContracts([
12
- (_a = this.inMemoryContract) !== null && _a !== void 0 ? _a : { eventSignatures: {} },
12
+ this.inMemoryContract ?? { eventSignatures: {} },
13
13
  contract,
14
14
  ]);
15
15
  }
@@ -26,20 +26,21 @@ class MutableContractClient extends MercurySocketIoClient_1.default {
26
26
  this.getEventSignatureByName(eventName);
27
27
  return true;
28
28
  }
29
- catch (_a) {
29
+ catch {
30
30
  return false;
31
31
  }
32
32
  }
33
33
  getEventSignatureByName(eventName) {
34
- var _a, _b;
35
34
  try {
36
35
  const sig = this.eventContract || MutableContractClient.inMemoryContract
37
- ? spruce_event_utils_1.eventContractUtil.getSignatureByName((_a = this.eventContract) !== null && _a !== void 0 ? _a : { eventSignatures: {} }, eventName)
36
+ ? spruce_event_utils_1.eventContractUtil.getSignatureByName(this.eventContract ?? { eventSignatures: {} }, eventName)
38
37
  : {};
39
38
  return sig;
40
39
  }
41
40
  catch (err) {
42
- const inMemorySig = spruce_event_utils_1.eventContractUtil.getSignatureByName((_b = MutableContractClient.inMemoryContract) !== null && _b !== void 0 ? _b : { eventSignatures: {} }, eventName);
41
+ const inMemorySig = spruce_event_utils_1.eventContractUtil.getSignatureByName(MutableContractClient.inMemoryContract ?? {
42
+ eventSignatures: {},
43
+ }, eventName);
43
44
  return inMemorySig;
44
45
  }
45
46
  }
@@ -1,5 +1,5 @@
1
1
  import AbstractSpruceError from '@sprucelabs/error';
2
- import ErrorOptions from "./../.spruce/errors/options.types";
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
3
  export default class SpruceError extends AbstractSpruceError<ErrorOptions> {
4
4
  friendlyMessage(): string;
5
5
  }
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const error_1 = __importDefault(require("@sprucelabs/error"));
7
7
  class SpruceError extends error_1.default {
8
8
  friendlyMessage() {
9
- var _a;
10
9
  const { options } = this;
11
10
  let message;
12
- switch (options === null || options === void 0 ? void 0 : options.code) {
11
+ switch (options?.code) {
13
12
  case 'INVALID_PROTOCOL':
14
13
  message = `You must connect via the https protocol. The uri you used was ${options.uri}!`;
15
14
  break;
@@ -17,7 +16,9 @@ class SpruceError extends error_1.default {
17
16
  message = `You passed a payload to "${options.eventName}" that has no emit payload defined.`;
18
17
  break;
19
18
  case 'INVALID_PAYLOAD':
20
- message = `The emit payload you passed to "${options.eventName}" is invalid${options.originalError ? `:\n\n${options.originalError.message}` : '.'}`;
19
+ message = `The emit payload you passed to "${options.eventName}" is invalid${options.originalError
20
+ ? `:\n\n${options.originalError.message}`
21
+ : '.'}`;
21
22
  break;
22
23
  case 'CONNECTION_FAILED':
23
24
  message = `I couldn't connect to ${options.host}. The code I got back was ${options.statusCode}.`;
@@ -32,7 +33,8 @@ class SpruceError extends error_1.default {
32
33
  const each = options.totalRetries ? ' each ' : ' ';
33
34
  message = `Dang it, I didn't hear back after emitting "${options.eventName}"${retries}for ${options.timeoutMs / 1000} seconds${each}...`;
34
35
  if (options.isConnected === false) {
35
- message += "\n\nAlso, it appears I'm not connected to the api.";
36
+ message +=
37
+ "\n\nAlso, it appears I'm not connected to the api.";
36
38
  }
37
39
  break;
38
40
  }
@@ -62,7 +64,7 @@ class SpruceError extends error_1.default {
62
64
  default:
63
65
  message = super.friendlyMessage();
64
66
  }
65
- message = (_a = options.friendlyMessage) !== null && _a !== void 0 ? _a : message;
67
+ message = options.friendlyMessage ?? message;
66
68
  return message;
67
69
  }
68
70
  }
@@ -13,7 +13,7 @@ export declare namespace SpruceErrors.MercuryClient {
13
13
  }
14
14
  export declare namespace SpruceErrors.MercuryClient {
15
15
  interface UnexpectedPayload {
16
- 'eventName': string;
16
+ eventName: string;
17
17
  }
18
18
  interface UnexpectedPayloadSchema extends SpruceSchema.Schema {
19
19
  id: 'unexpectedPayload';
@@ -21,7 +21,7 @@ export declare namespace SpruceErrors.MercuryClient {
21
21
  name: 'Unexpected payload';
22
22
  fields: {
23
23
  /** . */
24
- 'eventName': {
24
+ eventName: {
25
25
  type: 'text';
26
26
  isRequired: true;
27
27
  options: undefined;
@@ -32,11 +32,11 @@ export declare namespace SpruceErrors.MercuryClient {
32
32
  }
33
33
  export declare namespace SpruceErrors.MercuryClient {
34
34
  interface UnauthorizedTarget {
35
- 'locationId'?: string | undefined | null;
36
- 'personId'?: string | undefined | null;
37
- 'organizationId'?: string | undefined | null;
38
- 'skillId'?: string | undefined | null;
39
- 'roleId'?: string | undefined | null;
35
+ locationId?: string | undefined | null;
36
+ personId?: string | undefined | null;
37
+ organizationId?: string | undefined | null;
38
+ skillId?: string | undefined | null;
39
+ roleId?: string | undefined | null;
40
40
  }
41
41
  interface UnauthorizedTargetSchema extends SpruceSchema.Schema {
42
42
  id: 'unauthorizedTarget';
@@ -44,27 +44,27 @@ export declare namespace SpruceErrors.MercuryClient {
44
44
  name: '';
45
45
  fields: {
46
46
  /** . */
47
- 'locationId': {
47
+ locationId: {
48
48
  type: 'id';
49
49
  options: undefined;
50
50
  };
51
51
  /** . */
52
- 'personId': {
52
+ personId: {
53
53
  type: 'id';
54
54
  options: undefined;
55
55
  };
56
56
  /** . */
57
- 'organizationId': {
57
+ organizationId: {
58
58
  type: 'id';
59
59
  options: undefined;
60
60
  };
61
61
  /** . */
62
- 'skillId': {
62
+ skillId: {
63
63
  type: 'id';
64
64
  options: undefined;
65
65
  };
66
66
  /** . */
67
- 'roleId': {
67
+ roleId: {
68
68
  type: 'id';
69
69
  options: undefined;
70
70
  };
@@ -74,10 +74,10 @@ export declare namespace SpruceErrors.MercuryClient {
74
74
  }
75
75
  export declare namespace SpruceErrors.MercuryClient {
76
76
  interface UnauthorizedAccess {
77
- 'fqen': string;
78
- 'action': ("emit");
79
- 'target': SpruceErrors.MercuryClient.UnauthorizedTarget;
80
- 'permissionContractId': string;
77
+ fqen: string;
78
+ action: 'emit';
79
+ target: SpruceErrors.MercuryClient.UnauthorizedTarget;
80
+ permissionContractId: string;
81
81
  }
82
82
  interface UnauthorizedAccessSchema extends SpruceSchema.Schema {
83
83
  id: 'unauthorizedAccess';
@@ -85,24 +85,24 @@ export declare namespace SpruceErrors.MercuryClient {
85
85
  name: 'Unauthorized Access';
86
86
  fields: {
87
87
  /** . */
88
- 'fqen': {
88
+ fqen: {
89
89
  type: 'text';
90
90
  isRequired: true;
91
91
  options: undefined;
92
92
  };
93
93
  /** . */
94
- 'action': {
94
+ action: {
95
95
  type: 'select';
96
96
  isRequired: true;
97
97
  options: {
98
98
  choices: [{
99
- "value": "emit";
100
- "label": "emit";
99
+ value: 'emit';
100
+ label: 'emit';
101
101
  }];
102
102
  };
103
103
  };
104
104
  /** . */
105
- 'target': {
105
+ target: {
106
106
  type: 'schema';
107
107
  isRequired: true;
108
108
  options: {
@@ -110,7 +110,7 @@ export declare namespace SpruceErrors.MercuryClient {
110
110
  };
111
111
  };
112
112
  /** . */
113
- 'permissionContractId': {
113
+ permissionContractId: {
114
114
  type: 'id';
115
115
  isRequired: true;
116
116
  options: undefined;
@@ -121,10 +121,10 @@ export declare namespace SpruceErrors.MercuryClient {
121
121
  }
122
122
  export declare namespace SpruceErrors.MercuryClient {
123
123
  interface Timeout {
124
- 'eventName': string;
125
- 'timeoutMs': number;
126
- 'isConnected'?: boolean | undefined | null;
127
- 'totalRetries'?: number | undefined | null;
124
+ eventName: string;
125
+ timeoutMs: number;
126
+ isConnected?: boolean | undefined | null;
127
+ totalRetries?: number | undefined | null;
128
128
  }
129
129
  interface TimeoutSchema extends SpruceSchema.Schema {
130
130
  id: 'timeout';
@@ -132,24 +132,24 @@ export declare namespace SpruceErrors.MercuryClient {
132
132
  name: 'Timeout';
133
133
  fields: {
134
134
  /** . */
135
- 'eventName': {
135
+ eventName: {
136
136
  type: 'text';
137
137
  isRequired: true;
138
138
  options: undefined;
139
139
  };
140
140
  /** . */
141
- 'timeoutMs': {
141
+ timeoutMs: {
142
142
  type: 'number';
143
143
  isRequired: true;
144
144
  options: undefined;
145
145
  };
146
146
  /** . */
147
- 'isConnected': {
147
+ isConnected: {
148
148
  type: 'boolean';
149
149
  options: undefined;
150
150
  };
151
151
  /** . */
152
- 'totalRetries': {
152
+ totalRetries: {
153
153
  type: 'number';
154
154
  options: undefined;
155
155
  };
@@ -159,8 +159,8 @@ export declare namespace SpruceErrors.MercuryClient {
159
159
  }
160
160
  export declare namespace SpruceErrors.MercuryClient {
161
161
  interface NotConnected {
162
- 'action': string;
163
- 'fqen': string;
162
+ action: string;
163
+ fqen: string;
164
164
  }
165
165
  interface NotConnectedSchema extends SpruceSchema.Schema {
166
166
  id: 'notConnected';
@@ -168,13 +168,13 @@ export declare namespace SpruceErrors.MercuryClient {
168
168
  name: 'Not connected';
169
169
  fields: {
170
170
  /** . */
171
- 'action': {
171
+ action: {
172
172
  type: 'text';
173
173
  isRequired: true;
174
174
  options: undefined;
175
175
  };
176
176
  /** . */
177
- 'fqen': {
177
+ fqen: {
178
178
  type: 'id';
179
179
  isRequired: true;
180
180
  options: undefined;
@@ -185,7 +185,7 @@ export declare namespace SpruceErrors.MercuryClient {
185
185
  }
186
186
  export declare namespace SpruceErrors.MercuryClient {
187
187
  interface MustHandleLocally {
188
- 'fqen': string;
188
+ fqen: string;
189
189
  }
190
190
  interface MustHandleLocallySchema extends SpruceSchema.Schema {
191
191
  id: 'mustHandleLocally';
@@ -193,7 +193,7 @@ export declare namespace SpruceErrors.MercuryClient {
193
193
  name: 'Must handle locally';
194
194
  fields: {
195
195
  /** . */
196
- 'fqen': {
196
+ fqen: {
197
197
  type: 'text';
198
198
  isRequired: true;
199
199
  options: undefined;
@@ -204,7 +204,7 @@ export declare namespace SpruceErrors.MercuryClient {
204
204
  }
205
205
  export declare namespace SpruceErrors.MercuryClient {
206
206
  interface MustCreateEvent {
207
- 'fqen': string;
207
+ fqen: string;
208
208
  }
209
209
  interface MustCreateEventSchema extends SpruceSchema.Schema {
210
210
  id: 'mustCreateEvent';
@@ -212,7 +212,7 @@ export declare namespace SpruceErrors.MercuryClient {
212
212
  name: 'must create event';
213
213
  fields: {
214
214
  /** . */
215
- 'fqen': {
215
+ fqen: {
216
216
  type: 'text';
217
217
  isRequired: true;
218
218
  options: undefined;
@@ -234,7 +234,7 @@ export declare namespace SpruceErrors.MercuryClient {
234
234
  }
235
235
  export declare namespace SpruceErrors.MercuryClient {
236
236
  interface InvalidProtocol {
237
- 'uri': string;
237
+ uri: string;
238
238
  }
239
239
  interface InvalidProtocolSchema extends SpruceSchema.Schema {
240
240
  id: 'invalidProtocol';
@@ -242,7 +242,7 @@ export declare namespace SpruceErrors.MercuryClient {
242
242
  name: 'Invalid protocol';
243
243
  fields: {
244
244
  /** . */
245
- 'uri': {
245
+ uri: {
246
246
  type: 'text';
247
247
  isRequired: true;
248
248
  options: undefined;
@@ -253,7 +253,7 @@ export declare namespace SpruceErrors.MercuryClient {
253
253
  }
254
254
  export declare namespace SpruceErrors.MercuryClient {
255
255
  interface InvalidPayload {
256
- 'eventName': string;
256
+ eventName: string;
257
257
  }
258
258
  interface InvalidPayloadSchema extends SpruceSchema.Schema {
259
259
  id: 'invalidPayload';
@@ -261,7 +261,7 @@ export declare namespace SpruceErrors.MercuryClient {
261
261
  name: 'Invalid payload';
262
262
  fields: {
263
263
  /** . */
264
- 'eventName': {
264
+ eventName: {
265
265
  type: 'text';
266
266
  isRequired: true;
267
267
  options: undefined;
@@ -272,8 +272,8 @@ export declare namespace SpruceErrors.MercuryClient {
272
272
  }
273
273
  export declare namespace SpruceErrors.MercuryClient {
274
274
  interface InvalidEventSignature {
275
- 'fqen': string;
276
- 'instructions': string;
275
+ fqen: string;
276
+ instructions: string;
277
277
  }
278
278
  interface InvalidEventSignatureSchema extends SpruceSchema.Schema {
279
279
  id: 'invalidEventSignature';
@@ -281,13 +281,13 @@ export declare namespace SpruceErrors.MercuryClient {
281
281
  name: 'Invalid event contract';
282
282
  fields: {
283
283
  /** . */
284
- 'fqen': {
284
+ fqen: {
285
285
  type: 'text';
286
286
  isRequired: true;
287
287
  options: undefined;
288
288
  };
289
289
  /** . */
290
- 'instructions': {
290
+ instructions: {
291
291
  type: 'text';
292
292
  isRequired: true;
293
293
  options: undefined;
@@ -298,8 +298,8 @@ export declare namespace SpruceErrors.MercuryClient {
298
298
  }
299
299
  export declare namespace SpruceErrors.MercuryClient {
300
300
  interface ConnectionFailed {
301
- 'host': string;
302
- 'statusCode': number;
301
+ host: string;
302
+ statusCode: number;
303
303
  }
304
304
  interface ConnectionFailedSchema extends SpruceSchema.Schema {
305
305
  id: 'connectionFailed';
@@ -307,13 +307,13 @@ export declare namespace SpruceErrors.MercuryClient {
307
307
  name: 'Connection failed';
308
308
  fields: {
309
309
  /** . */
310
- 'host': {
310
+ host: {
311
311
  type: 'text';
312
312
  isRequired: true;
313
313
  options: undefined;
314
314
  };
315
315
  /** . */
316
- 'statusCode': {
316
+ statusCode: {
317
317
  type: 'number';
318
318
  isRequired: true;
319
319
  options: undefined;
@@ -1,3 +1 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
- /* eslint-disable no-redeclare */
3
1
  export {};
@@ -1,5 +1,5 @@
1
- import { SpruceErrors } from "./errors.types";
2
- import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
1
+ import { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
2
+ import { SpruceErrors } from './errors.types';
3
3
  export interface UnknownErrorErrorOptions extends SpruceErrors.MercuryClient.UnknownError, ISpruceErrorOptions {
4
4
  code: 'UNKNOWN_ERROR';
5
5
  }
@@ -3,7 +3,9 @@ import { Schema, SchemaValues } from '@sprucelabs/schema';
3
3
  import { io, SocketOptions, ManagerOptions } from 'socket.io-client';
4
4
  import { ConnectionOptions, MercuryClient } from '../types/client.types';
5
5
  export default class MercurySocketIoClient<Contract extends EventContract> implements MercuryClient<Contract> {
6
- protected eventContract?: Contract;
6
+ protected _eventContract?: Contract;
7
+ protected get eventContract(): Contract;
8
+ protected set eventContract(contract: Contract);
7
9
  static io: typeof io;
8
10
  private host;
9
11
  private ioOptions;
@@ -25,6 +25,12 @@ import { io } from 'socket.io-client';
25
25
  import SpruceError from '../errors/SpruceError.js';
26
26
  import socketIoEventUtil from '../utilities/socketIoEventUtil.utility.js';
27
27
  class MercurySocketIoClient {
28
+ get eventContract() {
29
+ return this._eventContract;
30
+ }
31
+ set eventContract(contract) {
32
+ this._eventContract = contract;
33
+ }
28
34
  constructor(options) {
29
35
  this.proxyToken = null;
30
36
  this.isReAuthing = false;
@@ -322,7 +328,9 @@ class MercurySocketIoClient {
322
328
  const args = [];
323
329
  if (payload || this.proxyToken) {
324
330
  const p = Object.assign({}, payload);
325
- if (eventName !== authenticateFqen && this.proxyToken && !p.source) {
331
+ if (eventName !== authenticateFqen &&
332
+ this.proxyToken &&
333
+ !p.source) {
326
334
  p.source = {
327
335
  proxyToken: this.proxyToken,
328
336
  };
@@ -348,7 +356,8 @@ class MercurySocketIoClient {
348
356
  }
349
357
  retriesRemaining--;
350
358
  try {
351
- if (eventName === authenticateFqen && this.authRawResults) {
359
+ if (eventName === authenticateFqen &&
360
+ this.authRawResults) {
352
361
  resolve(this.authRawResults);
353
362
  return;
354
363
  }
@@ -8,6 +8,7 @@ declare class InternalEmitter<Contract extends EventContract> extends AbstractEv
8
8
  mixinOnlyUniqueSignatures(contract: EventContract): void;
9
9
  overrideSignatures(contract: EventContract): void;
10
10
  getContract(): SpruceSchemas.Mercury.v2020_12_25.EventContract;
11
+ setContract(contract: Contract): void;
11
12
  }
12
13
  export default class MercuryTestClient<
13
14
  /** @ts-ignore */
@@ -21,7 +22,6 @@ Contract extends EventContract = SkillEventContract> extends MutableContractClie
21
22
  private static namespacesThatHaveToBeHandledLocally;
22
23
  private shouldWaitForDelayedConnectIfAuthing;
23
24
  private static shouldRequireLocalListeners;
24
- /** @ts-ignore */
25
25
  protected get eventContract(): Contract;
26
26
  protected set eventContract(contract: Contract);
27
27
  static setShouldCheckPermissionsOnLocalEvents(should: boolean): void;
@@ -41,21 +41,22 @@ class InternalEmitter extends AbstractEventEmitter {
41
41
  overrideSignatures(contract) {
42
42
  const fqens = Object.keys(contract.eventSignatures);
43
43
  for (const fqen of fqens) {
44
- this.eventContract.eventSignatures[fqen] = contract.eventSignatures[fqen];
44
+ this.eventContract.eventSignatures[fqen] =
45
+ contract.eventSignatures[fqen];
45
46
  }
46
47
  }
47
48
  getContract() {
48
49
  return this.eventContract;
49
50
  }
51
+ setContract(contract) {
52
+ this.eventContract = contract;
53
+ }
50
54
  }
51
55
  class MercuryTestClient extends MutableContractClient {
52
- /** @ts-ignore */
53
56
  get eventContract() {
54
57
  return MercuryTestClient.emitter.getContract();
55
58
  }
56
- set eventContract(contract) {
57
- MercuryTestClient.getInternalEmitter().overrideSignatures(contract);
58
- }
59
+ set eventContract(contract) { }
59
60
  static setShouldCheckPermissionsOnLocalEvents(should) {
60
61
  this.shouldCheckPermissionsOnLocalEvents = should;
61
62
  }
@@ -72,14 +73,21 @@ class MercuryTestClient extends MutableContractClient {
72
73
  this.isConnectedToApi = false;
73
74
  this.shouldHandleAuthenticateLocallyIfListenerSet = true;
74
75
  this.shouldWaitForDelayedConnectIfAuthing = true;
75
- MercuryTestClient.getInternalEmitter(contract);
76
+ if (!MercuryTestClient.emitter) {
77
+ MercuryTestClient.getInternalEmitter(contract);
78
+ }
79
+ else if (contract) {
80
+ MercuryTestClient.emitter.overrideSignatures(contract);
81
+ }
76
82
  }
77
83
  /** @ts-ignore */
78
84
  static getInternalEmitter(contract) {
79
- const mixed = mixinConnectionEvents(contract);
80
85
  if (!MercuryTestClient.emitter) {
81
- MercuryTestClient.emitter = new InternalEmitter({ eventSignatures: {} });
86
+ MercuryTestClient.emitter = new InternalEmitter({
87
+ eventSignatures: {},
88
+ });
82
89
  }
90
+ const mixed = mixinConnectionEvents(contract);
83
91
  MercuryTestClient.emitter.mixinOnlyUniqueSignatures(mixed);
84
92
  /** @ts-ignore */
85
93
  return MercuryTestClient.emitter;
@@ -142,7 +150,8 @@ class MercuryTestClient extends MutableContractClient {
142
150
  //@ts-ignore
143
151
  const results = yield _super.emit.call(this, ...args);
144
152
  const firstError = (_c = (_b = (_a = results.responses) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.errors) === null || _c === void 0 ? void 0 : _c[0];
145
- if (firstError && ((_d = firstError.options) === null || _d === void 0 ? void 0 : _d.code) === 'INVALID_EVENT_NAME') {
153
+ if (firstError &&
154
+ ((_d = firstError.options) === null || _d === void 0 ? void 0 : _d.code) === 'INVALID_EVENT_NAME') {
146
155
  firstError.message = `Event not found! Make sure you are booting your skill in your test with \`await this.bootSkill()\`. If you haven't, you'll need to create a listener with \`spruce create.listener\`.\n\nOriginal Error:\n\n${firstError.options.friendlyMessage}`;
147
156
  }
148
157
  return results;
@@ -34,7 +34,9 @@ export default class MutableContractClient extends MercurySocketIoClient {
34
34
  return sig;
35
35
  }
36
36
  catch (err) {
37
- const inMemorySig = eventContractUtil.getSignatureByName((_b = MutableContractClient.inMemoryContract) !== null && _b !== void 0 ? _b : { eventSignatures: {} }, eventName);
37
+ const inMemorySig = eventContractUtil.getSignatureByName((_b = MutableContractClient.inMemoryContract) !== null && _b !== void 0 ? _b : {
38
+ eventSignatures: {},
39
+ }, eventName);
38
40
  return inMemorySig;
39
41
  }
40
42
  }
@@ -1,5 +1,5 @@
1
1
  import AbstractSpruceError from '@sprucelabs/error';
2
- import ErrorOptions from "./../.spruce/errors/options.types";
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
3
  export default class SpruceError extends AbstractSpruceError<ErrorOptions> {
4
4
  friendlyMessage(): string;
5
5
  }
@@ -12,7 +12,9 @@ export default class SpruceError extends AbstractSpruceError {
12
12
  message = `You passed a payload to "${options.eventName}" that has no emit payload defined.`;
13
13
  break;
14
14
  case 'INVALID_PAYLOAD':
15
- message = `The emit payload you passed to "${options.eventName}" is invalid${options.originalError ? `:\n\n${options.originalError.message}` : '.'}`;
15
+ message = `The emit payload you passed to "${options.eventName}" is invalid${options.originalError
16
+ ? `:\n\n${options.originalError.message}`
17
+ : '.'}`;
16
18
  break;
17
19
  case 'CONNECTION_FAILED':
18
20
  message = `I couldn't connect to ${options.host}. The code I got back was ${options.statusCode}.`;
@@ -27,7 +29,8 @@ export default class SpruceError extends AbstractSpruceError {
27
29
  const each = options.totalRetries ? ' each ' : ' ';
28
30
  message = `Dang it, I didn't hear back after emitting "${options.eventName}"${retries}for ${options.timeoutMs / 1000} seconds${each}...`;
29
31
  if (options.isConnected === false) {
30
- message += "\n\nAlso, it appears I'm not connected to the api.";
32
+ message +=
33
+ "\n\nAlso, it appears I'm not connected to the api.";
31
34
  }
32
35
  break;
33
36
  }
@@ -22,17 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __rest = (this && this.__rest) || function (s, e) {
26
- var t = {};
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
- t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
- t[p[i]] = s[p[i]];
33
- }
34
- return t;
35
- };
36
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
27
  };
@@ -45,6 +34,9 @@ const MercuryClientFactory_1 = __importDefault(require("../clients/MercuryClient
45
34
  const MutableContractClient_1 = __importDefault(require("../clients/MutableContractClient"));
46
35
  const constants_1 = require("./constants");
47
36
  class AbstractClientTest extends test_1.default {
37
+ static dummySkillCount = 0;
38
+ static clients = [];
39
+ static skillName = 'Dummy skill';
48
40
  static async afterEach() {
49
41
  await super.afterEach();
50
42
  for (const client of this.clients) {
@@ -69,8 +61,14 @@ class AbstractClientTest extends test_1.default {
69
61
  MercuryClientFactory_1.default.reset();
70
62
  }
71
63
  static async connectToApi(options) {
72
- const _a = options || {}, { host = constants_1.TEST_HOST } = _a, rest = __rest(_a, ["host"]);
73
- const client = await MercuryClientFactory_1.default.Client(Object.assign({ host, contracts: mercury_core_events_1.coreEventContracts, reconnectDelayMs: 10, emitTimeoutMs: 10000 }, rest));
64
+ const { host = constants_1.TEST_HOST, ...rest } = options || {};
65
+ const client = await MercuryClientFactory_1.default.Client({
66
+ host,
67
+ contracts: mercury_core_events_1.coreEventContracts,
68
+ reconnectDelayMs: 10,
69
+ emitTimeoutMs: 10000,
70
+ ...rest,
71
+ });
74
72
  this.clients.push(client);
75
73
  return client;
76
74
  }
@@ -131,13 +129,12 @@ class AbstractClientTest extends test_1.default {
131
129
  return skill;
132
130
  }
133
131
  static async seedDemoSkill(client) {
134
- var _a;
135
132
  const skill1Results = await client.emit('register-skill::v2020_12_25', {
136
133
  payload: {
137
134
  name: `${this.skillName} ${++this.dummySkillCount} ${new Date().getTime() * Math.random()}`,
138
135
  },
139
136
  });
140
- const skill = (_a = skill1Results.responses[0].payload) === null || _a === void 0 ? void 0 : _a.skill;
137
+ const skill = skill1Results.responses[0].payload?.skill;
141
138
  test_1.assert.isTruthy(skill);
142
139
  return skill;
143
140
  }
@@ -191,7 +188,4 @@ class AbstractClientTest extends test_1.default {
191
188
  return contract;
192
189
  }
193
190
  }
194
- AbstractClientTest.dummySkillCount = 0;
195
- AbstractClientTest.clients = [];
196
- AbstractClientTest.skillName = 'Dummy skill';
197
191
  exports.default = AbstractClientTest;