@sprucelabs/spruce-event-plugin 62.3.43 → 62.3.45

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.
@@ -9,7 +9,7 @@ class SpruceError extends error_1.default {
9
9
  friendlyMessage() {
10
10
  const { options } = this;
11
11
  let message;
12
- switch (options === null || options === void 0 ? void 0 : options.code) {
12
+ switch (options?.code) {
13
13
  case 'EVENT_PLUGIN_ERROR':
14
14
  message = 'A event plugin error just happened!';
15
15
  break;
@@ -44,7 +44,7 @@ class EventFeaturePlugin {
44
44
  this.hasLocalContractBeenUpdated = spruce_skill_utils_1.diskUtil.hasFileChanged(this.combinedContractsFile);
45
45
  this._shouldConnectToApi = true;
46
46
  }
47
- catch (_a) {
47
+ catch {
48
48
  this.log.info('Events have not been synced locally.');
49
49
  this._shouldConnectToApi = false;
50
50
  }
@@ -53,7 +53,6 @@ class EventFeaturePlugin {
53
53
  this.bootHandler = cb;
54
54
  }
55
55
  async execute() {
56
- var _a;
57
56
  this.isExecuting = true;
58
57
  let willBootResolve;
59
58
  let willBootReject;
@@ -70,7 +69,7 @@ class EventFeaturePlugin {
70
69
  await willBoot(event);
71
70
  }
72
71
  willBootResolve();
73
- await Promise.all((_a = this.preRequisites) !== null && _a !== void 0 ? _a : []);
72
+ await Promise.all(this.preRequisites ?? []);
74
73
  if (this.getShouldRegisterEventsAndListeners()) {
75
74
  await this.loadEvents();
76
75
  if (!this.hasLocalContractBeenUpdated &&
@@ -107,7 +106,6 @@ class EventFeaturePlugin {
107
106
  }
108
107
  }
109
108
  async finishExecute() {
110
- var _a;
111
109
  this.isExecuting = false;
112
110
  this._isBooted = true;
113
111
  const didBoot = this.getListener('skill', 'did-boot');
@@ -115,7 +113,7 @@ class EventFeaturePlugin {
115
113
  await this.queueDidBoot(didBoot);
116
114
  }
117
115
  else {
118
- (_a = this.bootHandler) === null || _a === void 0 ? void 0 : _a.call(this);
116
+ this.bootHandler?.();
119
117
  }
120
118
  }
121
119
  getShouldCacheListeners() {
@@ -125,7 +123,6 @@ class EventFeaturePlugin {
125
123
  return process.env.SHOULD_REGISTER_EVENTS_AND_LISTENERS !== 'false';
126
124
  }
127
125
  async queueDidBoot(didBoot) {
128
- var _a;
129
126
  const promise = new Promise((resolve, reject) => {
130
127
  this.skill.onBoot(async () => {
131
128
  try {
@@ -140,11 +137,17 @@ class EventFeaturePlugin {
140
137
  }
141
138
  });
142
139
  });
143
- (_a = this.bootHandler) === null || _a === void 0 ? void 0 : _a.call(this);
140
+ this.bootHandler?.();
144
141
  await promise;
145
142
  }
146
143
  async buildSpruceEvent(eventName, targetAndPayload) {
147
- return Object.assign(Object.assign(Object.assign({ skill: this.skill, log: this.log.buildLog(eventName) }, targetAndPayload), this.skill.getContext()), { connectToApiAsSkill: async () => this.connectToApi() });
144
+ return {
145
+ skill: this.skill,
146
+ log: this.log.buildLog(eventName),
147
+ ...targetAndPayload,
148
+ ...this.skill.getContext(),
149
+ connectToApiAsSkill: async () => this.connectToApi(),
150
+ };
148
151
  }
149
152
  async checkHealth() {
150
153
  try {
@@ -212,7 +215,7 @@ class EventFeaturePlugin {
212
215
  await Promise.all([this.loadContracts(), this.loadListeners()]);
213
216
  }
214
217
  async connectToApi(options) {
215
- if ((options === null || options === void 0 ? void 0 : options.shouldWaitForWillBoot) !== false) {
218
+ if (options?.shouldWaitForWillBoot !== false) {
216
219
  await this.willBootPromise;
217
220
  }
218
221
  if (this.isDestroyed) {
@@ -237,7 +240,7 @@ class EventFeaturePlugin {
237
240
  friendlyMessage: `Stop! I need you to run \`spruce set.remote\` so I know where to connect! Or, you can set HOST in the env directly.`,
238
241
  });
239
242
  }
240
- this.log.info('Connecting to Mercury at', host !== null && host !== void 0 ? host : 'Production');
243
+ this.log.info('Connecting to Mercury at', host ?? 'Production');
241
244
  this.apiClientPromise = this.connectAndAuthenticate(MercuryClientFactory, host, contracts);
242
245
  const { client } = await this.apiClientPromise;
243
246
  return client;
@@ -275,7 +278,7 @@ class EventFeaturePlugin {
275
278
  apiKey,
276
279
  });
277
280
  currentSkill = skill;
278
- this.log.info(`Authenticated with namespace: ${currentSkill === null || currentSkill === void 0 ? void 0 : currentSkill.slug}.`);
281
+ this.log.info(`Authenticated with namespace: ${currentSkill?.slug}.`);
279
282
  }
280
283
  catch (err) {
281
284
  await client.disconnect();
@@ -362,11 +365,14 @@ class EventFeaturePlugin {
362
365
  client.setShouldAutoRegisterListeners(false);
363
366
  const remoteListeners = this.listeners
364
367
  .filter((l) => l.eventNamespace !== 'skill')
365
- .map((l) => (Object.assign(Object.assign({}, l), { fqen: spruce_event_utils_1.eventNameUtil.join({
368
+ .map((l) => ({
369
+ ...l,
370
+ fqen: spruce_event_utils_1.eventNameUtil.join({
366
371
  eventName: l.eventName,
367
372
  eventNamespace: l.eventNamespace,
368
373
  version: l.version,
369
- }) })));
374
+ }),
375
+ }));
370
376
  if (remoteListeners.length > 0 && !this.areListenersCached()) {
371
377
  await client.emitAndFlattenResponses('register-listeners::v2020_12_25', {
372
378
  payload: {
@@ -380,18 +386,17 @@ class EventFeaturePlugin {
380
386
  const all = remoteListeners.map(async (listener) => {
381
387
  const { fqen, callback } = listener;
382
388
  await client.on(fqen, async (targetAndPayload) => {
383
- var _a, _b;
384
389
  const now = Date.now();
385
390
  this.log.info(`Incoming - ${fqen}`);
386
391
  const event = await this.buildSpruceEvent(fqen, targetAndPayload);
387
392
  const decorator = spruce_test_fixtures_1.ClientProxyDecorator.getInstance();
388
- event.client = decorator.decorateEmitToPassProxyToken(event.client, (_a = targetAndPayload === null || targetAndPayload === void 0 ? void 0 : targetAndPayload.source) === null || _a === void 0 ? void 0 : _a.proxyToken);
393
+ event.client = decorator.decorateEmitToPassProxyToken(event.client, targetAndPayload?.source?.proxyToken);
389
394
  try {
390
395
  const results = await callback(event);
391
396
  return results;
392
397
  }
393
398
  catch (err) {
394
- this.log.error(`FQEN:`, fqen, (_b = err.stack) !== null && _b !== void 0 ? _b : err.message, '\n\n************************************\n\n', JSON.stringify(targetAndPayload), '\n\n************************************\n\n');
399
+ this.log.error(`FQEN:`, fqen, err.stack ?? err.message, '\n\n************************************\n\n', JSON.stringify(targetAndPayload), '\n\n************************************\n\n');
395
400
  throw err;
396
401
  }
397
402
  finally {
@@ -437,7 +442,6 @@ class EventFeaturePlugin {
437
442
  return undefined;
438
443
  }
439
444
  async loadListeners() {
440
- var _a;
441
445
  this.log.info('Loading listeners');
442
446
  const isInstalled = await this.isInstalled();
443
447
  if (!isInstalled && !this.listenersPath) {
@@ -453,7 +457,7 @@ class EventFeaturePlugin {
453
457
  const cacher = new ListenerCacher_1.default({
454
458
  cwd: this.skill.rootDir,
455
459
  listeners,
456
- host: (_a = this.getHost()) !== null && _a !== void 0 ? _a : '***NO HOST SET***',
460
+ host: this.getHost() ?? '***NO HOST SET***',
457
461
  });
458
462
  this.listenerCacher = cacher; //exposed for testing
459
463
  this.haveListenersChanged = cacher.haveListenersChanged();
@@ -480,12 +484,11 @@ class EventFeaturePlugin {
480
484
  if (currentSkill) {
481
485
  this.eventsIRegistered = [];
482
486
  this.allEventSignatures.forEach((signature) => {
483
- var _a;
484
487
  if (signature.eventNamespace === currentSkill.slug) {
485
488
  this.eventsIRegistered.push({
486
489
  eventName: signature.eventName,
487
490
  eventNamespace: currentSkill.slug,
488
- version: (_a = signature.version) !== null && _a !== void 0 ? _a : '***coming soon***',
491
+ version: signature.version ?? '***coming soon***',
489
492
  signature: signature.signature,
490
493
  fullyQualifiedEventName: signature.fullyQualifiedEventName,
491
494
  });
@@ -46,8 +46,11 @@ class AbstractEventPluginTest extends spruce_test_fixtures_1.AbstractSpruceFixtu
46
46
  return destination;
47
47
  }
48
48
  static async Skill(options) {
49
- const { plugins = [event_plugin_1.default] } = options !== null && options !== void 0 ? options : {};
50
- const skill = await super.Skill(Object.assign({ plugins }, options));
49
+ const { plugins = [event_plugin_1.default] } = options ?? {};
50
+ const skill = await super.Skill({
51
+ plugins,
52
+ ...options,
53
+ });
51
54
  return skill;
52
55
  }
53
56
  static resolveTestPath(pathAfterTestDirsAndFiles) {
@@ -2,9 +2,8 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.DEMO_NUMBER_DELAYED_CONNECT = void 0;
8
7
  const dotenv_1 = __importDefault(require("dotenv"));
9
8
  dotenv_1.default.config();
10
- exports.DEMO_NUMBER_DELAYED_CONNECT = (_a = process.env.DEMO_NUMBER_DELAYED_CONNECT) !== null && _a !== void 0 ? _a : '***missing***';
9
+ exports.DEMO_NUMBER_DELAYED_CONNECT = process.env.DEMO_NUMBER_DELAYED_CONNECT ?? '***missing***';
@@ -27,7 +27,7 @@ class EventFixture {
27
27
  buildEventContract(eventName, eventSignature) {
28
28
  return {
29
29
  eventSignatures: {
30
- [eventName]: eventSignature !== null && eventSignature !== void 0 ? eventSignature : {
30
+ [eventName]: eventSignature ?? {
31
31
  emitPayloadSchema: (0, spruce_event_utils_1.buildEmitTargetAndPayloadSchema)({
32
32
  eventName,
33
33
  targetSchema: {
@@ -77,7 +77,7 @@ class EventFixture {
77
77
  }
78
78
  async registerSkillAndSetupListeners(options) {
79
79
  mercury_client_1.MercuryClientFactory.setIsTestMode(true);
80
- const { eventSignature, onUnregisterListeners, onListen: onSetListener, onAttachListeners, onSetShouldAutoRegisterListeners, onAttachListener, } = options !== null && options !== void 0 ? options : {};
80
+ const { eventSignature, onUnregisterListeners, onListen: onSetListener, onAttachListeners, onSetShouldAutoRegisterListeners, onAttachListener, } = options ?? {};
81
81
  const { skill, client } = await this.skillFixture.loginAsDemoSkill({
82
82
  name: 'skill1',
83
83
  });
@@ -95,7 +95,7 @@ class EventFixture {
95
95
  if (onUnregisterListeners) {
96
96
  const client2 = await this.mercuryFixture.connectToApi();
97
97
  await client2.on('unregister-listeners::v2020_12_25', async () => {
98
- onUnregisterListeners === null || onUnregisterListeners === void 0 ? void 0 : onUnregisterListeners();
98
+ onUnregisterListeners?.();
99
99
  return { unregisterCount: 0 };
100
100
  });
101
101
  }
@@ -108,7 +108,7 @@ class EventFixture {
108
108
  //@ts-ignore
109
109
  pluginClient.on = async (fqen, cb) => {
110
110
  if (fqen.includes('seed-skill')) {
111
- onSetListener === null || onSetListener === void 0 ? void 0 : onSetListener(pluginClient);
111
+ onSetListener?.(pluginClient);
112
112
  }
113
113
  else if (fqen.includes('test')) {
114
114
  return;
@@ -131,7 +131,7 @@ class EventFixture {
131
131
  //@ts-ignore
132
132
  events.attachListeners = async (client) => {
133
133
  const results = await oldAttachListeners(client);
134
- onAttachListeners === null || onAttachListeners === void 0 ? void 0 : onAttachListeners(client);
134
+ onAttachListeners?.(client);
135
135
  return results;
136
136
  };
137
137
  }
@@ -143,12 +143,12 @@ class EventFixture {
143
143
  client.setShouldAutoRegisterListeners = (should) => {
144
144
  //@ts-ignore
145
145
  client.shouldAutoRegisterListeners = should;
146
- onSetShouldAutoRegisterListeners === null || onSetShouldAutoRegisterListeners === void 0 ? void 0 : onSetShouldAutoRegisterListeners(should);
146
+ onSetShouldAutoRegisterListeners?.(should);
147
147
  };
148
148
  //@ts-ignore
149
149
  client.on = () => {
150
150
  //@ts-ignore
151
- onAttachListener === null || onAttachListener === void 0 ? void 0 : onAttachListener(client);
151
+ onAttachListener?.(client);
152
152
  };
153
153
  return client;
154
154
  };
@@ -158,7 +158,7 @@ class EventFixture {
158
158
  generateGoodContractFileForSkill(slug, eventSignature) {
159
159
  const sourceContents = spruce_skill_utils_1.diskUtil.readFile(spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'build', '.spruce', 'events', 'source.events.contract.js'));
160
160
  let updatedContents = sourceContents.replace('{{namespace}}', slug);
161
- updatedContents = updatedContents.replace('{{eventSignature}}', JSON.stringify(eventSignature !== null && eventSignature !== void 0 ? eventSignature : {
161
+ updatedContents = updatedContents.replace('{{eventSignature}}', JSON.stringify(eventSignature ?? {
162
162
  emitPayloadSchema: {
163
163
  id: 'targetAndPayload',
164
164
  fields: {
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "@sprucelabs/spruce-test-fixtures"
11
11
  ]
12
12
  },
13
- "version": "62.3.43",
13
+ "version": "62.3.45",
14
14
  "files": [
15
15
  "build/**/*",
16
16
  "!build/__tests__",
@@ -59,24 +59,24 @@
59
59
  "lint.tsc": "tsc -p . --noEmit"
60
60
  },
61
61
  "dependencies": {
62
- "@sprucelabs/error": "^6.0.475",
63
- "@sprucelabs/mercury-types": "^47.0.526",
64
- "@sprucelabs/schema": "^30.0.484",
65
- "@sprucelabs/spruce-core-schemas": "^40.1.470",
66
- "@sprucelabs/spruce-event-utils": "^40.1.246",
67
- "@sprucelabs/spruce-skill-booter": "^62.3.43",
68
- "@sprucelabs/spruce-skill-utils": "^31.0.543",
69
- "@sprucelabs/spruce-test-fixtures": "^62.3.43"
62
+ "@sprucelabs/error": "^6.0.479",
63
+ "@sprucelabs/mercury-types": "^47.0.529",
64
+ "@sprucelabs/schema": "^30.0.488",
65
+ "@sprucelabs/spruce-core-schemas": "^40.1.473",
66
+ "@sprucelabs/spruce-event-utils": "^40.1.249",
67
+ "@sprucelabs/spruce-skill-booter": "^62.3.45",
68
+ "@sprucelabs/spruce-skill-utils": "^31.0.547",
69
+ "@sprucelabs/spruce-test-fixtures": "^62.3.45"
70
70
  },
71
71
  "devDependencies": {
72
- "@sprucelabs/esm-postbuild": "^6.0.459",
73
- "@sprucelabs/jest-json-reporter": "^8.0.475",
74
- "@sprucelabs/mercury-client": "^42.0.525",
75
- "@sprucelabs/mercury-core-events": "^24.3.287",
76
- "@sprucelabs/resolve-path-aliases": "^2.0.454",
72
+ "@sprucelabs/esm-postbuild": "^6.0.462",
73
+ "@sprucelabs/jest-json-reporter": "^8.0.480",
74
+ "@sprucelabs/mercury-client": "^42.0.528",
75
+ "@sprucelabs/mercury-core-events": "^24.3.290",
76
+ "@sprucelabs/resolve-path-aliases": "^2.0.457",
77
77
  "@sprucelabs/semantic-release": "^5.0.2",
78
- "@sprucelabs/test": "^9.0.50",
79
- "@sprucelabs/test-utils": "^5.1.425",
78
+ "@sprucelabs/test": "^9.0.51",
79
+ "@sprucelabs/test-utils": "^5.1.432",
80
80
  "chokidar-cli": "^3.0.0",
81
81
  "dotenv": "^16.4.5",
82
82
  "eslint": "^9.12.0",
@@ -106,5 +106,5 @@
106
106
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
107
107
  }
108
108
  },
109
- "gitHead": "fe785957ada88b5b1157f978f43eccfcf4cce0c2"
109
+ "gitHead": "59b913c0b16c2e83a7506abd5618082abfcd1f65"
110
110
  }
package/tsconfig.json CHANGED
@@ -3,10 +3,9 @@
3
3
  "skipLibCheck": true,
4
4
  "module": "commonjs",
5
5
  "esModuleInterop": true,
6
- "target": "ES2017",
6
+ "target": "ES2020",
7
7
  "lib": [
8
8
  "DOM",
9
- "es2017",
10
9
  "ES2020"
11
10
  ],
12
11
  "declaration": true,