@sprucelabs/spruce-agent-utils 0.0.1 → 0.1.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 (59) hide show
  1. package/build/.spruce/errors/errors.types.d.ts +13 -0
  2. package/build/.spruce/errors/errors.types.js +2 -0
  3. package/build/.spruce/errors/options.types.d.ts +7 -0
  4. package/build/.spruce/errors/options.types.js +2 -0
  5. package/build/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.d.ts +3 -0
  6. package/build/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.js +11 -0
  7. package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
  8. package/build/.spruce/schemas/fields/fieldClassMap.js +4 -0
  9. package/{src/.spruce/schemas/fields/fields.types.ts → build/.spruce/schemas/fields/fields.types.d.ts} +1 -1
  10. package/build/.spruce/schemas/fields/fields.types.js +2 -0
  11. package/{src → build}/.spruce/settings.json +4 -4
  12. package/build/SpruceAgent.d.ts +15 -0
  13. package/build/SpruceAgent.js +32 -0
  14. package/build/agentAssert.d.ts +7 -0
  15. package/build/agentAssert.js +30 -0
  16. package/build/errors/SpruceError.d.ts +6 -0
  17. package/build/errors/SpruceError.js +25 -0
  18. package/build/errors/agentLoaderNotConfigured.builder.d.ts +6 -0
  19. package/build/errors/agentLoaderNotConfigured.builder.js +8 -0
  20. package/build/esm/.spruce/errors/errors.types.d.ts +13 -0
  21. package/build/esm/.spruce/errors/errors.types.js +1 -0
  22. package/build/esm/.spruce/errors/options.types.d.ts +7 -0
  23. package/build/esm/.spruce/errors/options.types.js +1 -0
  24. package/build/esm/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.d.ts +3 -0
  25. package/build/esm/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.js +9 -0
  26. package/build/esm/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
  27. package/build/esm/.spruce/schemas/fields/fieldClassMap.js +2 -0
  28. package/build/esm/.spruce/schemas/fields/fields.types.d.ts +1 -0
  29. package/build/esm/.spruce/schemas/fields/fields.types.js +1 -0
  30. package/build/esm/SpruceAgent.d.ts +15 -0
  31. package/build/esm/SpruceAgent.js +26 -0
  32. package/build/esm/agentAssert.d.ts +7 -0
  33. package/build/esm/agentAssert.js +25 -0
  34. package/build/esm/errors/SpruceError.d.ts +6 -0
  35. package/build/esm/errors/SpruceError.js +19 -0
  36. package/build/esm/errors/agentLoaderNotConfigured.builder.d.ts +6 -0
  37. package/{src/errors/agentLoaderNotConfigured.builder.ts → build/esm/errors/agentLoaderNotConfigured.builder.js} +2 -3
  38. package/build/esm/index.d.ts +3 -0
  39. package/build/esm/index.js +3 -0
  40. package/build/index.d.ts +3 -0
  41. package/build/index.js +25 -0
  42. package/package.json +20 -2
  43. package/.circleci/config.yml +0 -80
  44. package/.nvmrc +0 -1
  45. package/.vscode/launch.json +0 -58
  46. package/.vscode/settings.json +0 -67
  47. package/.vscode/tasks.json +0 -112
  48. package/eslint.config.mjs +0 -3
  49. package/src/.spruce/errors/errors.types.ts +0 -29
  50. package/src/.spruce/errors/options.types.ts +0 -10
  51. package/src/.spruce/errors/spruceAgentUtils/agentLoaderNotConfigured.schema.ts +0 -16
  52. package/src/.spruce/schemas/fields/fieldClassMap.ts +0 -6
  53. package/src/SpruceAgent.ts +0 -40
  54. package/src/__tests__/behavioral/AgentLoader.test.ts +0 -53
  55. package/src/__tests__/behavioral/TestingAgentLoader.test.ts +0 -74
  56. package/src/agentAssert.ts +0 -35
  57. package/src/errors/SpruceError.ts +0 -23
  58. package/src/index.ts +0 -3
  59. package/tsconfig.json +0 -39
@@ -0,0 +1,13 @@
1
+ import { default as SchemaEntity } from '@sprucelabs/schema';
2
+ import * as SpruceSchema from '@sprucelabs/schema';
3
+ export declare namespace SpruceErrors.SpruceAgentUtils {
4
+ interface AgentLoaderNotConfigured {
5
+ }
6
+ interface AgentLoaderNotConfiguredSchema extends SpruceSchema.Schema {
7
+ id: 'agentLoaderNotConfigured';
8
+ namespace: 'SpruceAgentUtils';
9
+ name: 'agent loader not configured';
10
+ fields: {};
11
+ }
12
+ type AgentLoaderNotConfiguredEntity = SchemaEntity<SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema>;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { SpruceErrors } from "./errors.types";
2
+ import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
3
+ export interface AgentLoaderNotConfiguredErrorOptions extends SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfigured, ISpruceErrorOptions {
4
+ code: 'AGENT_LOADER_NOT_CONFIGURED';
5
+ }
6
+ type ErrorOptions = AgentLoaderNotConfiguredErrorOptions;
7
+ export default ErrorOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { SpruceErrors } from '../errors.types';
2
+ declare const agentLoaderNotConfiguredSchema: SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema;
3
+ export default agentLoaderNotConfiguredSchema;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ const agentLoaderNotConfiguredSchema = {
5
+ id: 'agentLoaderNotConfigured',
6
+ namespace: 'SpruceAgentUtils',
7
+ name: 'agent loader not configured',
8
+ fields: {}
9
+ };
10
+ schema_1.SchemaRegistry.getInstance().trackSchema(agentLoaderNotConfiguredSchema);
11
+ exports.default = agentLoaderNotConfiguredSchema;
@@ -0,0 +1,2 @@
1
+ import { fieldClassMap } from '@sprucelabs/schema';
2
+ export default fieldClassMap;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ exports.default = schema_1.fieldClassMap;
@@ -1 +1 @@
1
- export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema'
1
+ export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,13 +3,13 @@
3
3
  "skipped": []
4
4
  },
5
5
  "skipped": [
6
- "skill"
6
+ "event",
7
+ "skill",
8
+ "permission"
7
9
  ],
8
10
  "installed": [
9
11
  "test",
10
12
  "schema",
11
- "error",
12
- "permission",
13
- "event"
13
+ "error"
14
14
  ]
15
15
  }
@@ -0,0 +1,15 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ export default class SpruceAgent implements AgentLoader {
3
+ private static instance?;
4
+ private connectToApi;
5
+ private constructor();
6
+ static setup(client: MercuryClient | ConnectFactory): void;
7
+ static reset(): void;
8
+ static getInstance(): SpruceAgent;
9
+ getName(): Promise<string>;
10
+ }
11
+ export interface AgentLoader {
12
+ getName(): Promise<string>;
13
+ }
14
+ type ConnectFactory = () => Promise<MercuryClient>;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
7
+ class SpruceAgent {
8
+ constructor(client) {
9
+ this.connectToApi =
10
+ typeof client === 'function' ? client : async () => client;
11
+ }
12
+ static setup(client) {
13
+ this.instance = new SpruceAgent(client);
14
+ }
15
+ static reset() {
16
+ delete this.instance;
17
+ }
18
+ static getInstance() {
19
+ if (this.instance) {
20
+ return this.instance;
21
+ }
22
+ throw new SpruceError_1.default({
23
+ code: 'AGENT_LOADER_NOT_CONFIGURED',
24
+ });
25
+ }
26
+ async getName() {
27
+ const client = await this.connectToApi();
28
+ const [{ name }] = await client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
29
+ return name;
30
+ }
31
+ }
32
+ exports.default = SpruceAgent;
@@ -0,0 +1,7 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ declare const agentAssert: {
3
+ beforeEach(client: MercuryClient): Promise<void>;
4
+ getName: () => string;
5
+ includesAgentName: (text: string) => void;
6
+ };
7
+ export default agentAssert;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const schema_1 = require("@sprucelabs/schema");
7
+ const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
8
+ const test_utils_1 = require("@sprucelabs/test-utils");
9
+ const SpruceAgent_1 = __importDefault(require("./SpruceAgent"));
10
+ let sharedClient;
11
+ let name = (0, test_utils_1.generateId)();
12
+ const agentAssert = {
13
+ async beforeEach(client) {
14
+ name = (0, test_utils_1.generateId)();
15
+ sharedClient = client;
16
+ await spruce_test_fixtures_1.eventFaker.on('get-agent-name::v2020_12_25', () => {
17
+ return { name };
18
+ });
19
+ },
20
+ getName: () => {
21
+ test_utils_1.assert.isTruthy(sharedClient, 'You must call agentAssert.beforeEach(this.fakedClient) in your test to use agentAssert');
22
+ SpruceAgent_1.default.getInstance();
23
+ return name;
24
+ },
25
+ includesAgentName: (text) => {
26
+ (0, schema_1.assertOptions)({ text }, ['text']);
27
+ test_utils_1.assert.doesInclude(text, name, `The text must include agent name!`);
28
+ },
29
+ };
30
+ exports.default = agentAssert;
@@ -0,0 +1,6 @@
1
+ import BaseSpruceError from '@sprucelabs/error';
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
+ export default class SpruceError extends BaseSpruceError<ErrorOptions> {
4
+ /** an easy to understand version of the errors */
5
+ friendlyMessage(): string;
6
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const error_1 = __importDefault(require("@sprucelabs/error"));
7
+ class SpruceError extends error_1.default {
8
+ /** an easy to understand version of the errors */
9
+ friendlyMessage() {
10
+ const { options } = this;
11
+ let message;
12
+ switch (options?.code) {
13
+ case 'AGENT_LOADER_NOT_CONFIGURED':
14
+ message = `The agent loader has not been configured. Please call SpruceAgent.setup(...) first. Best place is probably in the did-boot of your skill or the constructor of your AppViewController in the front-end.`;
15
+ break;
16
+ default:
17
+ message = super.friendlyMessage();
18
+ }
19
+ const fullMessage = options.friendlyMessage
20
+ ? options.friendlyMessage
21
+ : message;
22
+ return fullMessage;
23
+ }
24
+ }
25
+ exports.default = SpruceError;
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ id: string;
3
+ name: string;
4
+ fields: {};
5
+ };
6
+ export default _default;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ exports.default = (0, schema_1.buildErrorSchema)({
5
+ id: 'agentLoaderNotConfigured',
6
+ name: 'agent loader not configured',
7
+ fields: {},
8
+ });
@@ -0,0 +1,13 @@
1
+ import { default as SchemaEntity } from '@sprucelabs/schema';
2
+ import * as SpruceSchema from '@sprucelabs/schema';
3
+ export declare namespace SpruceErrors.SpruceAgentUtils {
4
+ interface AgentLoaderNotConfigured {
5
+ }
6
+ interface AgentLoaderNotConfiguredSchema extends SpruceSchema.Schema {
7
+ id: 'agentLoaderNotConfigured';
8
+ namespace: 'SpruceAgentUtils';
9
+ name: 'agent loader not configured';
10
+ fields: {};
11
+ }
12
+ type AgentLoaderNotConfiguredEntity = SchemaEntity<SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema>;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { SpruceErrors } from "./errors.types";
2
+ import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
3
+ export interface AgentLoaderNotConfiguredErrorOptions extends SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfigured, ISpruceErrorOptions {
4
+ code: 'AGENT_LOADER_NOT_CONFIGURED';
5
+ }
6
+ type ErrorOptions = AgentLoaderNotConfiguredErrorOptions;
7
+ export default ErrorOptions;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { SpruceErrors } from '../errors.types';
2
+ declare const agentLoaderNotConfiguredSchema: SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema;
3
+ export default agentLoaderNotConfiguredSchema;
@@ -0,0 +1,9 @@
1
+ import { SchemaRegistry } from '@sprucelabs/schema';
2
+ const agentLoaderNotConfiguredSchema = {
3
+ id: 'agentLoaderNotConfigured',
4
+ namespace: 'SpruceAgentUtils',
5
+ name: 'agent loader not configured',
6
+ fields: {}
7
+ };
8
+ SchemaRegistry.getInstance().trackSchema(agentLoaderNotConfiguredSchema);
9
+ export default agentLoaderNotConfiguredSchema;
@@ -0,0 +1,2 @@
1
+ import { fieldClassMap } from '@sprucelabs/schema';
2
+ export default fieldClassMap;
@@ -0,0 +1,2 @@
1
+ import { fieldClassMap } from '@sprucelabs/schema';
2
+ export default fieldClassMap;
@@ -0,0 +1 @@
1
+ export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ export default class SpruceAgent implements AgentLoader {
3
+ private static instance?;
4
+ private connectToApi;
5
+ private constructor();
6
+ static setup(client: MercuryClient | ConnectFactory): void;
7
+ static reset(): void;
8
+ static getInstance(): SpruceAgent;
9
+ getName(): Promise<string>;
10
+ }
11
+ export interface AgentLoader {
12
+ getName(): Promise<string>;
13
+ }
14
+ type ConnectFactory = () => Promise<MercuryClient>;
15
+ export {};
@@ -0,0 +1,26 @@
1
+ import SpruceError from './errors/SpruceError.js';
2
+ export default class SpruceAgent {
3
+ constructor(client) {
4
+ this.connectToApi =
5
+ typeof client === 'function' ? client : async () => client;
6
+ }
7
+ static setup(client) {
8
+ this.instance = new SpruceAgent(client);
9
+ }
10
+ static reset() {
11
+ delete this.instance;
12
+ }
13
+ static getInstance() {
14
+ if (this.instance) {
15
+ return this.instance;
16
+ }
17
+ throw new SpruceError({
18
+ code: 'AGENT_LOADER_NOT_CONFIGURED',
19
+ });
20
+ }
21
+ async getName() {
22
+ const client = await this.connectToApi();
23
+ const [{ name }] = await client.emitAndFlattenResponses('get-agent-name::v2020_12_25');
24
+ return name;
25
+ }
26
+ }
@@ -0,0 +1,7 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ declare const agentAssert: {
3
+ beforeEach(client: MercuryClient): Promise<void>;
4
+ getName: () => string;
5
+ includesAgentName: (text: string) => void;
6
+ };
7
+ export default agentAssert;
@@ -0,0 +1,25 @@
1
+ import { assertOptions } from '@sprucelabs/schema';
2
+ import { eventFaker } from '@sprucelabs/spruce-test-fixtures';
3
+ import { assert, generateId } from '@sprucelabs/test-utils';
4
+ import SpruceAgent from './SpruceAgent.js';
5
+ let sharedClient;
6
+ let name = generateId();
7
+ const agentAssert = {
8
+ async beforeEach(client) {
9
+ name = generateId();
10
+ sharedClient = client;
11
+ await eventFaker.on('get-agent-name::v2020_12_25', () => {
12
+ return { name };
13
+ });
14
+ },
15
+ getName: () => {
16
+ assert.isTruthy(sharedClient, 'You must call agentAssert.beforeEach(this.fakedClient) in your test to use agentAssert');
17
+ SpruceAgent.getInstance();
18
+ return name;
19
+ },
20
+ includesAgentName: (text) => {
21
+ assertOptions({ text }, ['text']);
22
+ assert.doesInclude(text, name, `The text must include agent name!`);
23
+ },
24
+ };
25
+ export default agentAssert;
@@ -0,0 +1,6 @@
1
+ import BaseSpruceError from '@sprucelabs/error';
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
+ export default class SpruceError extends BaseSpruceError<ErrorOptions> {
4
+ /** an easy to understand version of the errors */
5
+ friendlyMessage(): string;
6
+ }
@@ -0,0 +1,19 @@
1
+ import BaseSpruceError from '@sprucelabs/error';
2
+ export default class SpruceError extends BaseSpruceError {
3
+ /** an easy to understand version of the errors */
4
+ friendlyMessage() {
5
+ const { options } = this;
6
+ let message;
7
+ switch (options === null || options === void 0 ? void 0 : options.code) {
8
+ case 'AGENT_LOADER_NOT_CONFIGURED':
9
+ message = `The agent loader has not been configured. Please call SpruceAgent.setup(...) first. Best place is probably in the did-boot of your skill or the constructor of your AppViewController in the front-end.`;
10
+ break;
11
+ default:
12
+ message = super.friendlyMessage();
13
+ }
14
+ const fullMessage = options.friendlyMessage
15
+ ? options.friendlyMessage
16
+ : message;
17
+ return fullMessage;
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ id: string;
3
+ name: string;
4
+ fields: {};
5
+ };
6
+ export default _default;
@@ -1,7 +1,6 @@
1
- import { buildErrorSchema } from '@sprucelabs/schema'
2
-
1
+ import { buildErrorSchema } from '@sprucelabs/schema';
3
2
  export default buildErrorSchema({
4
3
  id: 'agentLoaderNotConfigured',
5
4
  name: 'agent loader not configured',
6
5
  fields: {},
7
- })
6
+ });
@@ -0,0 +1,3 @@
1
+ export { default as SpruceAgent } from './SpruceAgent';
2
+ export * from './SpruceAgent';
3
+ export { default as agentAssert } from './agentAssert';
@@ -0,0 +1,3 @@
1
+ export { default as SpruceAgent } from './SpruceAgent.js';
2
+ export * from './SpruceAgent.js';
3
+ export { default as agentAssert } from './agentAssert.js';
@@ -0,0 +1,3 @@
1
+ export { default as SpruceAgent } from './SpruceAgent';
2
+ export * from './SpruceAgent';
3
+ export { default as agentAssert } from './agentAssert';
package/build/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.agentAssert = exports.SpruceAgent = void 0;
21
+ var SpruceAgent_1 = require("./SpruceAgent");
22
+ Object.defineProperty(exports, "SpruceAgent", { enumerable: true, get: function () { return __importDefault(SpruceAgent_1).default; } });
23
+ __exportStar(require("./SpruceAgent"), exports);
24
+ var agentAssert_1 = require("./agentAssert");
25
+ Object.defineProperty(exports, "agentAssert", { enumerable: true, get: function () { return __importDefault(agentAssert_1).default; } });
package/package.json CHANGED
@@ -1,20 +1,36 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-agent-utils",
3
- "version": "0.0.1",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "files": [
7
+ "build",
8
+ "!build/__tests__",
9
+ "esm"
10
+ ],
11
+ "version": "0.1.0",
12
+ "main": "./build/index.js",
13
+ "types": "./build/index.d.ts",
14
+ "module": "./build/esm/index.js",
15
+ "sideEffects": false,
4
16
  "scripts": {
5
17
  "build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
6
18
  "build.dev": "yarn run build.tsc --sourceMap ; yarn run resolve-paths.lint",
19
+ "build.dist": "tsc --project tsconfig.dist.json && yarn build.resolve-paths && mv build esm && yarn build.esm-postbuild && yarn build.tsc && yarn build.resolve-paths && mv esm build/ && yarn clean.dist",
7
20
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
21
+ "build.esm-postbuild": "esm-postbuild --target esm --patterns '**/*.js'",
8
22
  "build.resolve-paths": "resolve-path-aliases --target build --patterns '**/*.js,**/*.d.ts'",
9
23
  "build.tsc": "yarn run build.copy-files && tsc",
10
24
  "clean": "yarn run clean.build",
11
25
  "clean.all": "yarn run clean.dependencies && yarn run clean.build",
12
26
  "clean.build": "rm -rf build/",
27
+ "clean.dist": "rm -rf build/__tests__ build/esm/__tests__",
13
28
  "clean.dependencies": "rm -rf node_modules/ package-lock.json yarn.lock",
14
29
  "fix.lint": "eslint --fix --cache '**/*.ts'",
15
30
  "lint": "eslint --cache '**/*.ts'",
16
31
  "lint.tsc": "tsc -p . --noEmit",
17
32
  "post.watch.build": "yarn run build.copy-files && yarn run build.resolve-paths",
33
+ "release": "semantic-release",
18
34
  "rebuild": "yarn run clean.all && yarn install && yarn run build.dev",
19
35
  "update.dependencies": "yarn run clean.dependencies && yarn",
20
36
  "resolve-paths.lint": "yarn run build.resolve-paths ; yarn run lint",
@@ -24,8 +40,10 @@
24
40
  "watch.tsc": "tsc -w"
25
41
  },
26
42
  "devDependencies": {
43
+ "@sprucelabs/esm-postbuild": "^9.0.8",
27
44
  "@sprucelabs/jest-json-reporter": "^10.0.12",
28
45
  "@sprucelabs/resolve-path-aliases": "^4.0.9",
46
+ "@sprucelabs/semantic-release": "^6.0.0",
29
47
  "@sprucelabs/spruce-test-fixtures": "^76.0.15",
30
48
  "@sprucelabs/test": "^11.0.3",
31
49
  "@sprucelabs/test-utils": "^7.0.16",
@@ -35,7 +53,7 @@
35
53
  "eslint-config-spruce": "^11.2.26",
36
54
  "jest": "^30.2.0",
37
55
  "jest-circus": "^30.2.0",
38
- "prettier": "^3.7.3",
56
+ "prettier": "^3.7.4",
39
57
  "ts-node": "^10.9.2",
40
58
  "tsc-watch": "^7.2.0",
41
59
  "typescript": "^5.9.3"
@@ -1,80 +0,0 @@
1
- version: 2.1
2
- orbs:
3
- spruce: sprucelabsai/orb@1
4
- jobs:
5
- test:
6
- docker:
7
- - image: cimg/node:lts
8
- working_directory: /mnt/ramdisk
9
- steps:
10
- - run:
11
- name: Yolo perms
12
- command: sudo chmod -R 777 /mnt/ramdisk
13
- - add_ssh_keys:
14
- fingerprints:
15
- - "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
16
- - checkout
17
- - spruce/check_and_skip_if_npm_publish
18
- - spruce/create_env_from_base64_env
19
- - spruce/install_rsync
20
- - spruce/install_deps_build_ci_test
21
- - spruce/exit_if_not_auto_upgrade
22
- - spruce/merge_auto_upgrade
23
- npm_publish:
24
- docker:
25
- - image: cimg/node:lts
26
- working_directory: /mnt/ramdisk
27
- steps:
28
- - run:
29
- name: Yolo perms
30
- command: sudo chmod -R 777 /mnt/ramdisk
31
- - add_ssh_keys:
32
- fingerprints:
33
- - "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
34
- - checkout
35
- - spruce/check_and_skip_if_npm_publish
36
- - spruce/install_rsync
37
- - spruce/install_deps_build_dist_release
38
- upgrade:
39
- docker:
40
- - image: cimg/node:lts
41
- working_directory: /mnt/ramdisk
42
- steps:
43
- - run:
44
- name: Yolo perms
45
- command: sudo chmod -R 777 /mnt/ramdisk
46
- - spruce/check_for_autoupgrade_dns
47
- - add_ssh_keys:
48
- fingerprints:
49
- - "ec:9f:2e:aa:1f:c9:ab:49:57:8f:c0:cd:2e:5b:f3:b0"
50
- - spruce/check_for_ssh_keys_env
51
- - spruce/setup_ct_npm_cache
52
- - checkout
53
- - spruce/set_target_branch_env
54
- - spruce/install_rsync
55
- - spruce/install_cli
56
- - spruce/upgrade_check_for_major
57
- - spruce/check_for_newline_only_diff
58
- - spruce/create_pr
59
- workflows:
60
- version: 2.1
61
- do_build:
62
- jobs:
63
- - test:
64
- context: public_package_publish
65
- - npm_publish:
66
- requires:
67
- - test
68
- context: public_package_publish
69
- filters:
70
- branches:
71
- only:
72
- - master
73
- upgrade:
74
- jobs:
75
- - upgrade:
76
- context: public_package_publish
77
- filters:
78
- branches:
79
- only:
80
- - never_run_only_for_cron
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- lts/*
@@ -1,58 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "type": "node",
6
- "request": "attach",
7
- "name": "attach.tests",
8
- "port": 5200,
9
- "restart": true,
10
- "timeout": 10000
11
- },
12
- {
13
- "type": "node",
14
- "request": "launch",
15
- "name": "test.file",
16
- "runtimeExecutable": "node",
17
- "runtimeArgs": [
18
- "--inspect-brk",
19
- "--trace-warnings",
20
- "${workspaceFolder}/node_modules/.bin/jest",
21
- "${fileBasenameNoExtension}",
22
- "--detectOpenHandles"
23
- ],
24
- "cwd": "${workspaceFolder}",
25
- "console": "integratedTerminal",
26
- "internalConsoleOptions": "neverOpen"
27
- },
28
- {
29
- "type": "node",
30
- "request": "launch",
31
- "name": "test.all",
32
- "runtimeExecutable": "node",
33
- "runtimeArgs": [
34
- "--inspect-brk",
35
- "--trace-warnings",
36
- "${workspaceFolder}/node_modules/.bin/jest"
37
- ],
38
- "cwd": "${workspaceFolder}",
39
- "console": "integratedTerminal",
40
- "internalConsoleOptions": "neverOpen"
41
- },
42
- {
43
- "type": "node",
44
- "request": "launch",
45
- "name": "boot",
46
- "runtimeExecutable": "yarn",
47
- "runtimeArgs": [
48
- "run",
49
- "--inspect-brk",
50
- "--trace-warnings",
51
- "boot"
52
- ],
53
- "cwd": "${workspaceFolder}",
54
- "console": "integratedTerminal",
55
- "internalConsoleOptions": "neverOpen"
56
- }
57
- ]
58
- }
@@ -1,67 +0,0 @@
1
- {
2
- "debug.node.autoAttach": "on",
3
- "git.ignoreLimitWarning": true,
4
- "javascript.validate.enable": false,
5
- "files.watcherExclude": {
6
- "**/.git/objects/**": true,
7
- "**/.git/subtree-cache/**": true,
8
- "**/build/**": true,
9
- "**/node_modules/**": true,
10
- },
11
- "search.exclude": {
12
- "**/build/**": true,
13
- "**/node_modules/**": true,
14
- "**/.next/**": true
15
- },
16
- "editor.maxTokenizationLineLength": 20000000,
17
- "[javascript]": {
18
- "editor.formatOnSave": false
19
- },
20
- "[javascriptreact]": {
21
- "editor.formatOnSave": false
22
- },
23
- "[typescript]": {
24
- "editor.formatOnSave": false
25
- },
26
- "[typescriptreact]": {
27
- "editor.formatOnSave": false
28
- },
29
- "[handlebars]": {
30
- "editor.formatOnSave": false
31
- },
32
- "typescript.tsdk": "node_modules/typescript/lib",
33
- "cSpell.ignorePaths": [
34
- "**/package-lock.json",
35
- "**/node_modules/**",
36
- "**/build/**",
37
- "**/vscode-extension/**",
38
- "**/.git/objects/**",
39
- ".vscode",
40
- ".spruce"
41
- ],
42
- "cSpell.words": [
43
- "arkit",
44
- "autogenerated",
45
- "scrollable",
46
- "serializable"
47
- ],
48
- "debug.javascript.unmapMissingSources": true,
49
- "javascript.preferences.importModuleSpecifier": "relative",
50
- "typescript.preferences.importModuleSpecifier": "relative",
51
- "eslint.useFlatConfig": true,
52
- "eslint.enable": true,
53
- "eslint.validate": [
54
- "javascript",
55
- "javascriptreact",
56
- "typescript",
57
- "typescriptreact"
58
- ],
59
- "eslint.workingDirectories": [
60
- "./"
61
- ],
62
- "typescript.validate.enable": true,
63
- "editor.formatOnSave": false,
64
- "editor.codeActionsOnSave": {
65
- "source.fixAll.eslint": "always"
66
- }
67
- }
@@ -1,112 +0,0 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "type": "npm",
6
- "script": "watch.build.dev",
7
- "group": "build",
8
- "label": "watch.build.dev & problem.watcher",
9
- "isBackground": true,
10
- "runOptions": {
11
- "runOn": "folderOpen"
12
- },
13
- "promptOnClose": false,
14
- "presentation": {
15
- "focus": false,
16
- "reveal": "never"
17
- },
18
- "problemMatcher": {
19
- "base": "$tsc-watch",
20
- "applyTo": "allDocuments"
21
- }
22
- },
23
- {
24
- "label": "test.file",
25
- "command": "spruce",
26
- "args": [
27
- "test",
28
- "--inspect",
29
- "5200",
30
- "--pattern",
31
- "${fileBasenameNoExtension}",
32
- "--watchMode",
33
- "standard"
34
- ],
35
- "promptOnClose": false,
36
- "group": {
37
- "kind": "test",
38
- "isDefault": true
39
- },
40
- "presentation": {
41
- "reveal": "always",
42
- "panel": "dedicated",
43
- },
44
- "problemMatcher": []
45
- },
46
- {
47
- "label": "test.reporter",
48
- "command": "spruce",
49
- "args": [
50
- "test",
51
- "--shouldHoldAtStart",
52
- "true",
53
- "--watchMode",
54
- "smart"
55
- ],
56
- "promptOnClose": false,
57
- "group": "test",
58
- "runOptions": {
59
- "runOn": "folderOpen"
60
- },
61
- "presentation": {
62
- "panel": "shared",
63
- "focus": true,
64
- "reveal": "always"
65
- }
66
- },
67
- {
68
- "label": "spruce",
69
- "type": "shell",
70
- "command": "spruce ${input:spruceCommand}",
71
- "problemMatcher": [],
72
- "presentation": {
73
- "reveal": "always",
74
- "focus": true,
75
- "panel": "new",
76
- "clear": false
77
- }
78
- },
79
- {
80
- "label": "shell",
81
- "type": "shell",
82
- "command": "${input:command} ${input:optionsCommand}",
83
- "problemMatcher": [],
84
- "presentation": {
85
- "reveal": "always",
86
- "focus": true,
87
- "panel": "new",
88
- "clear": false
89
- }
90
- }
91
- ],
92
- "inputs": [
93
- {
94
- "id": "spruceCommand",
95
- "description": "spruce command",
96
- "default": "create.test",
97
- "type": "promptString"
98
- },
99
- {
100
- "id": "command",
101
- "description": "command",
102
- "default": "yarn",
103
- "type": "promptString"
104
- },
105
- {
106
- "id": "optionsCommand",
107
- "description": "optionsCommand",
108
- "default": "add",
109
- "type": "promptString"
110
- }
111
- ]
112
- }
package/eslint.config.mjs DELETED
@@ -1,3 +0,0 @@
1
- import eslintConfigSpruce from 'eslint-config-spruce'
2
-
3
- export default eslintConfigSpruce
@@ -1,29 +0,0 @@
1
- import { default as SchemaEntity } from '@sprucelabs/schema'
2
- import * as SpruceSchema from '@sprucelabs/schema'
3
-
4
-
5
-
6
-
7
-
8
- export declare namespace SpruceErrors.SpruceAgentUtils {
9
-
10
-
11
- export interface AgentLoaderNotConfigured {
12
-
13
- }
14
-
15
- export interface AgentLoaderNotConfiguredSchema extends SpruceSchema.Schema {
16
- id: 'agentLoaderNotConfigured',
17
- namespace: 'SpruceAgentUtils',
18
- name: 'agent loader not configured',
19
- fields: {
20
- }
21
- }
22
-
23
- export type AgentLoaderNotConfiguredEntity = SchemaEntity<SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema>
24
-
25
- }
26
-
27
-
28
-
29
-
@@ -1,10 +0,0 @@
1
- import { SpruceErrors } from "#spruce/errors/errors.types"
2
- import { ErrorOptions as ISpruceErrorOptions} from "@sprucelabs/error"
3
-
4
- export interface AgentLoaderNotConfiguredErrorOptions extends SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfigured, ISpruceErrorOptions {
5
- code: 'AGENT_LOADER_NOT_CONFIGURED'
6
- }
7
-
8
- type ErrorOptions = | AgentLoaderNotConfiguredErrorOptions
9
-
10
- export default ErrorOptions
@@ -1,16 +0,0 @@
1
- import { SchemaRegistry } from '@sprucelabs/schema'
2
- import { SpruceErrors } from '../errors.types'
3
-
4
-
5
-
6
- const agentLoaderNotConfiguredSchema: SpruceErrors.SpruceAgentUtils.AgentLoaderNotConfiguredSchema = {
7
- id: 'agentLoaderNotConfigured',
8
- namespace: 'SpruceAgentUtils',
9
- name: 'agent loader not configured',
10
- fields: {
11
- }
12
- }
13
-
14
- SchemaRegistry.getInstance().trackSchema(agentLoaderNotConfiguredSchema)
15
-
16
- export default agentLoaderNotConfiguredSchema
@@ -1,6 +0,0 @@
1
- import { fieldClassMap } from '@sprucelabs/schema'
2
-
3
-
4
-
5
-
6
- export default fieldClassMap
@@ -1,40 +0,0 @@
1
- import { MercuryClient } from '@sprucelabs/mercury-client'
2
- import SpruceError from './errors/SpruceError'
3
-
4
- export default class SpruceAgent implements AgentLoader {
5
- private static instance?: SpruceAgent
6
- private client: MercuryClient
7
-
8
- private constructor(client: MercuryClient) {
9
- this.client = client
10
- }
11
-
12
- public static setup(client: MercuryClient) {
13
- this.instance = new SpruceAgent(client)
14
- }
15
-
16
- public static reset() {
17
- delete this.instance
18
- }
19
-
20
- public static getInstance() {
21
- if (this.instance) {
22
- return this.instance
23
- }
24
- throw new SpruceError({
25
- code: 'AGENT_LOADER_NOT_CONFIGURED',
26
- })
27
- }
28
-
29
- public async getName() {
30
- const [{ name }] = await this.client.emitAndFlattenResponses(
31
- 'get-agent-name::v2020_12_25'
32
- )
33
-
34
- return name
35
- }
36
- }
37
-
38
- export interface AgentLoader {
39
- getName(): Promise<string>
40
- }
@@ -1,53 +0,0 @@
1
- import {
2
- AbstractSpruceFixtureTest,
3
- eventFaker,
4
- fake,
5
- } from '@sprucelabs/spruce-test-fixtures'
6
- import {
7
- test,
8
- suite,
9
- assert,
10
- errorAssert,
11
- generateId,
12
- } from '@sprucelabs/test-utils'
13
- import SpruceAgent from '../../SpruceAgent'
14
-
15
- @fake.login()
16
- @suite()
17
- export default class AgentLoaderTest extends AbstractSpruceFixtureTest {
18
- private agents!: SpruceAgent
19
- private agentName = generateId()
20
-
21
- protected async beforeEach(): Promise<void> {
22
- await super.beforeEach()
23
- SpruceAgent.setup(this.fakedClient)
24
- this.agents = SpruceAgent.getInstance()
25
- }
26
-
27
- @test()
28
- protected async getInstanceThrowsWithoutConfiguring() {
29
- SpruceAgent.reset()
30
- const err = assert.doesThrow(() => SpruceAgent.getInstance())
31
- errorAssert.assertError(err, 'AGENT_LOADER_NOT_CONFIGURED')
32
- }
33
-
34
- @test()
35
- protected async getInstanceReturnsSameInstanceEachTime() {
36
- assert.isEqual(
37
- this.agents,
38
- SpruceAgent.getInstance(),
39
- 'should be the same instance'
40
- )
41
- }
42
-
43
- @test()
44
- protected async emitsGetAgentOnEmit() {
45
- await eventFaker.on('get-agent-name::v2020_12_25', () => {
46
- return { name: this.agentName }
47
- })
48
-
49
- const name = await this.agents.getName()
50
-
51
- assert.isEqual(name, this.agentName, 'agent name does not match')
52
- }
53
- }
@@ -1,74 +0,0 @@
1
- import { fake } from '@sprucelabs/spruce-test-fixtures'
2
- import { AbstractSpruceFixtureTest } from '@sprucelabs/spruce-test-fixtures'
3
- import { test, suite, assert, errorAssert } from '@sprucelabs/test-utils'
4
- import agentAssert from '../../agentAssert'
5
- import SpruceAgent from '../../SpruceAgent'
6
-
7
- @fake.login()
8
- @suite()
9
- export default class TestingAgentLoaderTest extends AbstractSpruceFixtureTest {
10
- @test()
11
- protected async throwsIfDidNotBeforeEach() {
12
- assert.doesThrow(() => agentAssert.getName(), 'beforeEach')
13
- }
14
-
15
- @test()
16
- protected async throwsAgentLoaderNotConfiguredIfGettingNameBeforeConfigured() {
17
- await agentAssert.beforeEach(this.fakedClient)
18
- const err = assert.doesThrow(() => agentAssert.getName())
19
-
20
- errorAssert.assertError(err, 'AGENT_LOADER_NOT_CONFIGURED')
21
- }
22
-
23
- @test()
24
- protected async nameMatchesNameFromAgent() {
25
- await this.fullBeforeEach()
26
- const actual = agentAssert.getName()
27
- const expected = await SpruceAgent.getInstance().getName()
28
- assert.isEqual(
29
- actual,
30
- expected,
31
- 'agentAssert should return the same name as SpruceAgent'
32
- )
33
- }
34
-
35
- @test()
36
- protected async nameShouldDifferEachTest() {
37
- await agentAssert.beforeEach(this.fakedClient)
38
- const name1 = agentAssert.getName()
39
- await agentAssert.beforeEach(this.fakedClient)
40
- const name2 = agentAssert.getName()
41
-
42
- assert.isNotEqual(name1, name2, 'names should differ between tests')
43
- }
44
-
45
- @test()
46
- protected async assertIncludesAgentNameThrowsWithMissing() {
47
- await this.fullBeforeEach()
48
-
49
- //@ts-ignore
50
- const err = assert.doesThrow(() => agentAssert.includesAgentName())
51
- errorAssert.assertError(err, 'MISSING_PARAMETERS', {
52
- parameters: ['text'],
53
- })
54
- }
55
-
56
- @test()
57
- protected async canAssertIncludesName() {
58
- await this.fullBeforeEach()
59
-
60
- const includesName = `Hello, my agent name is ${await SpruceAgent.getInstance().getName()}!`
61
- const doesNotIncludeName = `Hello, I have no agent name!`
62
-
63
- agentAssert.includesAgentName(includesName)
64
-
65
- assert.doesThrow(() =>
66
- agentAssert.includesAgentName(doesNotIncludeName)
67
- )
68
- }
69
-
70
- private async fullBeforeEach() {
71
- await agentAssert.beforeEach(this.fakedClient)
72
- SpruceAgent.setup(this.fakedClient)
73
- }
74
- }
@@ -1,35 +0,0 @@
1
- import { MercuryClient } from '@sprucelabs/mercury-client'
2
- import { assertOptions } from '@sprucelabs/schema'
3
- import { eventFaker } from '@sprucelabs/spruce-test-fixtures'
4
- import { assert, generateId } from '@sprucelabs/test-utils'
5
- import SpruceAgent from './SpruceAgent'
6
-
7
- let sharedClient: MercuryClient
8
- let name: string = generateId()
9
-
10
- const agentAssert = {
11
- async beforeEach(client: MercuryClient) {
12
- name = generateId()
13
- sharedClient = client
14
- await eventFaker.on('get-agent-name::v2020_12_25', () => {
15
- return { name }
16
- })
17
- },
18
- getName: () => {
19
- assert.isTruthy(
20
- sharedClient,
21
- 'You must call agentAssert.beforeEach(this.fakedClient) in your test to use agentAssert'
22
- )
23
-
24
- SpruceAgent.getInstance()
25
-
26
- return name
27
- },
28
-
29
- includesAgentName: (text: string) => {
30
- assertOptions({ text }, ['text'])
31
- assert.doesInclude(text, name, `The tex must include agent name!`)
32
- },
33
- }
34
-
35
- export default agentAssert
@@ -1,23 +0,0 @@
1
- import BaseSpruceError from '@sprucelabs/error'
2
- import ErrorOptions from '#spruce/errors/options.types'
3
-
4
- export default class SpruceError extends BaseSpruceError<ErrorOptions> {
5
- /** an easy to understand version of the errors */
6
- public friendlyMessage(): string {
7
- const { options } = this
8
- let message
9
- switch (options?.code) {
10
- case 'AGENT_LOADER_NOT_CONFIGURED':
11
- message = `The agent loader has not been configured. Please call AgentLoader.setup(...) first. Best place is probably in the did-boot of your skill.`
12
- break
13
- default:
14
- message = super.friendlyMessage()
15
- }
16
-
17
- const fullMessage = options.friendlyMessage
18
- ? options.friendlyMessage
19
- : message
20
-
21
- return fullMessage
22
- }
23
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as SpruceAgent } from './SpruceAgent'
2
- export * from './SpruceAgent'
3
- export { default as agentAssert } from './agentAssert'
package/tsconfig.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "skipLibCheck": true,
4
- "module": "commonjs",
5
- "esModuleInterop": true,
6
- "target": "ES2020",
7
- "lib": [
8
- "DOM",
9
- "ES2022"
10
- ],
11
- "declaration": true,
12
- "noImplicitAny": true,
13
- "allowJs": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "noImplicitReturns": true,
16
- "strict": true,
17
- "noUnusedLocals": true,
18
- "resolveJsonModule": true,
19
- "moduleResolution": "node",
20
- "sourceMap": false,
21
- "outDir": "build",
22
- "baseUrl": "src",
23
- "experimentalDecorators": true,
24
- "paths": {
25
- "#spruce/*": [
26
- ".spruce/*"
27
- ]
28
- }
29
- },
30
- "include": [
31
- "./src/*.ts",
32
- "./src/**/*.ts",
33
- "./src/.spruce/**/*"
34
- ],
35
- "exclude": [
36
- "build",
37
- "esm"
38
- ]
39
- }