@palmetto/dispatch-pubsub 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.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @palmetto/dispatch-pubsub
2
+
3
+ Shared configurations for Dispatch Service messages.
4
+
5
+ ## Installation
6
+
7
+ First, install peer dependencies
8
+
9
+ ```sh
10
+ yarn add @palmetto/pubsub amqp-connection-manager amqplib zod
11
+ ```
12
+
13
+ ```sh
14
+ yarn add @palmetto/dispatch-pubsub
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Get and use a configuration
20
+
21
+ ```ts
22
+ import { SupplierEvent, SupplierMessage, SuppliersPubSubConfig } from "@palmetto/dispatch-pubsub";
23
+ import { MessageResult, RabbitMqSubscriber, Subscriber } from "@palmetto/pubsub";
24
+
25
+ const rabbitMqSubscriber = new RabbitMqSubscriber(...);
26
+ const subscriber = new Subscriber(console, [rabbitMqSubscriber]);
27
+
28
+ function onMessage(message: SupplierMessage) {
29
+ switch (message.event) {
30
+ case SupplierEvent.Created:
31
+ console.log(`Got new Supplier: ${message.data.id}`)
32
+ // ...
33
+ }
34
+
35
+ return MessageResult.Ok;
36
+ };
37
+
38
+ await subscriber.startSubscribe({
39
+ retries: 3, // add custom parameters first
40
+ ...SuppliersPubSubConfig, // override with shared config
41
+ }, onMessage);
42
+ ```
43
+
44
+ ## Events
45
+
46
+ ### `dispatch.accepted`
47
+
48
+ Fired when a Dispatch's status is changed to `ACCEPTED`. A Dispatch's status is set to `ACCEPTED` via the API when a Supplier choses to accept a Project. Auto-accepted Dispatches do **NOT** fire this event, since the status is not _changed_ into `ACCEPTED`.
49
+
50
+ ### `dispatch.created`
51
+
52
+ Fired when a Dispatch is created. Dispatches are created when the matching engine pairs a Project with a Supplier. If conditions are met for auto-acceptance, the Dispatch will be created in the `ACCEPTED` status and a [`dispatch.accepted`](#dispatchaccepted) event will **NOT** be fired.
53
+
54
+ ### `dispatch.rejected`
55
+
56
+ Fired when a Dispatch's status is changed to `REJECTED`. A Dispatch's status is set to `REJECTED` via the API when a Supplier choses to reject a Project.
57
+
58
+ ### `dispatch.withdrawn`
59
+
60
+ Fired when a Dispatch's status is changed to `WITHDRAWN`. A Dispatch's status is set to `WITHDRAWN` automatically when a Dispatch is not accepted or rejected by a Supplier within a certain timeframe.
61
+
62
+ ### `project.created`
63
+
64
+ Fired when a Project is created. Projects are created via the API.
65
+
66
+ ### `supplier.created`
67
+
68
+ Fired when a Supplier is created. Suppliers are created via the API.
@@ -0,0 +1,17 @@
1
+ import { BaseMessage, IdMetaSchema, RabbitQueueExchangeConfiguration } from "@palmetto/pubsub";
2
+ import { $ZodObject, $ZodType } from "zod/v4/core";
3
+ type IdMetaShape = typeof IdMetaSchema.shape;
4
+ export interface MessageSchemaShape<T extends string> extends IdMetaShape {
5
+ event: $ZodType<T>;
6
+ data: $ZodObject;
7
+ }
8
+ export type MessageSchema<T extends string> = $ZodObject<Readonly<MessageSchemaShape<T>>>;
9
+ export interface Message<T extends string> extends BaseMessage {
10
+ event: T;
11
+ data: Record<string, unknown>;
12
+ }
13
+ export interface PubSubEventConfig<T extends string> extends Omit<RabbitQueueExchangeConfiguration, "schema"> {
14
+ schema: MessageSchema<T>;
15
+ }
16
+ export declare function rabbitMqConfig<T extends string>(name: string, schema: MessageSchema<T>): PubSubEventConfig<T>;
17
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rabbitMqConfig = rabbitMqConfig;
4
+ const pubsub_1 = require("@palmetto/pubsub");
5
+ function rabbitMqConfig(name, schema) {
6
+ return {
7
+ name,
8
+ schema,
9
+ exchangeType: "fanout",
10
+ transport: pubsub_1.RABBITMQ_TRANSPORT,
11
+ };
12
+ }
13
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAgCA,wCAUC;AA1CD,6CAK0B;AA2B1B,SAAgB,cAAc,CAC5B,IAAY,EACZ,MAAwB;IAExB,OAAO;QACL,IAAI;QACJ,MAAM;QACN,YAAY,EAAE,QAAQ;QACtB,SAAS,EAAE,2BAAkB;KAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare enum DispatchEvent {
3
+ Created = "dispatch.created"
4
+ }
5
+ export declare const DispatchMessageSchema: z.ZodObject<{
6
+ event: z.ZodEnum<typeof DispatchEvent>;
7
+ data: z.ZodObject<{
8
+ id: z.ZodString;
9
+ }, z.core.$strip>;
10
+ id: z.ZodOptional<z.ZodString>;
11
+ meta: z.ZodOptional<z.ZodObject<{
12
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
13
+ schemaId: z.ZodOptional<z.ZodString>;
14
+ publishedBy: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>>;
16
+ }, z.core.$strip>;
17
+ export type DispatchMessage = z.infer<typeof DispatchMessageSchema>;
18
+ export declare const DispatchesPubSubConfig: import("../config.js").PubSubEventConfig<DispatchEvent>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DispatchesPubSubConfig = exports.DispatchMessageSchema = exports.DispatchEvent = void 0;
4
+ const pubsub_1 = require("@palmetto/pubsub");
5
+ const zod_1 = require("zod");
6
+ const config_js_1 = require("../config.js");
7
+ var DispatchEvent;
8
+ (function (DispatchEvent) {
9
+ DispatchEvent["Created"] = "dispatch.created";
10
+ })(DispatchEvent || (exports.DispatchEvent = DispatchEvent = {}));
11
+ exports.DispatchMessageSchema = zod_1.z.object(Object.assign(Object.assign({}, pubsub_1.IdMetaSchema.shape), { event: zod_1.z.enum(DispatchEvent), data: zod_1.z.object({
12
+ id: zod_1.z.string().meta({ description: "ID of the Dispatch" }),
13
+ }) }));
14
+ exports.DispatchesPubSubConfig = (0, config_js_1.rabbitMqConfig)("dispatch.dispatches", exports.DispatchMessageSchema);
15
+ //# sourceMappingURL=dispatches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatches.js","sourceRoot":"","sources":["../../src/configs/dispatches.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAEhD,6BAAwB;AAExB,4CAA8C;AAE9C,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,6CAA4B,CAAA;AAC9B,CAAC,EAFW,aAAa,6BAAb,aAAa,QAExB;AAEY,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,iCACxC,qBAAY,CAAC,KAAK,KACrB,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,aAAa,CAAC,EAC5B,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC;QACb,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;KAC3D,CAAC,IACF,CAAC;AAIU,QAAA,sBAAsB,GAAG,IAAA,0BAAc,EAClD,qBAAqB,EACrB,6BAAqB,CACtB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare enum ProjectEvent {
3
+ Created = "project.created"
4
+ }
5
+ export declare const ProjectMessageSchema: z.ZodObject<{
6
+ event: z.ZodEnum<typeof ProjectEvent>;
7
+ data: z.ZodObject<{
8
+ id: z.ZodString;
9
+ }, z.core.$strip>;
10
+ id: z.ZodOptional<z.ZodString>;
11
+ meta: z.ZodOptional<z.ZodObject<{
12
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
13
+ schemaId: z.ZodOptional<z.ZodString>;
14
+ publishedBy: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>>;
16
+ }, z.core.$strip>;
17
+ export type ProjectMessage = z.infer<typeof ProjectMessageSchema>;
18
+ export declare const ProjectsPubSubConfig: import("../config.js").PubSubEventConfig<ProjectEvent>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectsPubSubConfig = exports.ProjectMessageSchema = exports.ProjectEvent = void 0;
4
+ const pubsub_1 = require("@palmetto/pubsub");
5
+ const zod_1 = require("zod");
6
+ const config_js_1 = require("../config.js");
7
+ var ProjectEvent;
8
+ (function (ProjectEvent) {
9
+ ProjectEvent["Created"] = "project.created";
10
+ })(ProjectEvent || (exports.ProjectEvent = ProjectEvent = {}));
11
+ exports.ProjectMessageSchema = zod_1.z.object(Object.assign(Object.assign({}, pubsub_1.IdMetaSchema.shape), { event: zod_1.z.enum(ProjectEvent), data: zod_1.z.object({
12
+ id: zod_1.z.string().meta({ description: "ID of the Project" }),
13
+ }) }));
14
+ exports.ProjectsPubSubConfig = (0, config_js_1.rabbitMqConfig)("dispatch.projects", exports.ProjectMessageSchema);
15
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/configs/projects.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAEhD,6BAAwB;AAExB,4CAA8C;AAE9C,IAAY,YAEX;AAFD,WAAY,YAAY;IACtB,2CAA2B,CAAA;AAC7B,CAAC,EAFW,YAAY,4BAAZ,YAAY,QAEvB;AAEY,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,iCACvC,qBAAY,CAAC,KAAK,KACrB,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,YAAY,CAAC,EAC3B,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC;QACb,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;KAC1D,CAAC,IACF,CAAC;AAIU,QAAA,oBAAoB,GAAG,IAAA,0BAAc,EAChD,mBAAmB,EACnB,4BAAoB,CACrB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare enum SupplierEvent {
3
+ Created = "supplier.created"
4
+ }
5
+ export declare const SupplierMessageSchema: z.ZodObject<{
6
+ event: z.ZodEnum<typeof SupplierEvent>;
7
+ data: z.ZodObject<{
8
+ id: z.ZodString;
9
+ }, z.core.$strip>;
10
+ id: z.ZodOptional<z.ZodString>;
11
+ meta: z.ZodOptional<z.ZodObject<{
12
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
13
+ schemaId: z.ZodOptional<z.ZodString>;
14
+ publishedBy: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>>;
16
+ }, z.core.$strip>;
17
+ export type SupplierMessage = z.infer<typeof SupplierMessageSchema>;
18
+ export declare const SuppliersPubSubConfig: import("../config.js").PubSubEventConfig<SupplierEvent>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SuppliersPubSubConfig = exports.SupplierMessageSchema = exports.SupplierEvent = void 0;
4
+ const pubsub_1 = require("@palmetto/pubsub");
5
+ const zod_1 = require("zod");
6
+ const config_js_1 = require("../config.js");
7
+ var SupplierEvent;
8
+ (function (SupplierEvent) {
9
+ SupplierEvent["Created"] = "supplier.created";
10
+ })(SupplierEvent || (exports.SupplierEvent = SupplierEvent = {}));
11
+ exports.SupplierMessageSchema = zod_1.z.object(Object.assign(Object.assign({}, pubsub_1.IdMetaSchema.shape), { event: zod_1.z.enum(SupplierEvent), data: zod_1.z.object({
12
+ id: zod_1.z.string().meta({ description: "ID of the Supplier" }),
13
+ }) }));
14
+ exports.SuppliersPubSubConfig = (0, config_js_1.rabbitMqConfig)("dispatch.suppliers", exports.SupplierMessageSchema);
15
+ //# sourceMappingURL=suppliers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suppliers.js","sourceRoot":"","sources":["../../src/configs/suppliers.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAEhD,6BAAwB;AAExB,4CAA8C;AAE9C,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,6CAA4B,CAAA;AAC9B,CAAC,EAFW,aAAa,6BAAb,aAAa,QAExB;AAEY,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,iCACxC,qBAAY,CAAC,KAAK,KACrB,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,aAAa,CAAC,EAC5B,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC;QACb,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;KAC3D,CAAC,IACF,CAAC;AAIU,QAAA,qBAAqB,GAAG,IAAA,0BAAc,EACjD,oBAAoB,EACpB,6BAAqB,CACtB,CAAC"}
package/dist/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type * from "./config.ts";
2
+ export * from "./configs/dispatches.js";
3
+ export * from "./configs/projects.js";
4
+ export * from "./configs/suppliers.js";
package/dist/main.js ADDED
@@ -0,0 +1,20 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./configs/dispatches.js"), exports);
18
+ __exportStar(require("./configs/projects.js"), exports);
19
+ __exportStar(require("./configs/suppliers.js"), exports);
20
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,0DAAwC;AACxC,wDAAsC;AACtC,yDAAuC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@palmetto/dispatch-pubsub",
3
+ "version": "0.1.0",
4
+ "main": "./dist/main.js",
5
+ "scripts": {
6
+ "lint": "yarn run -T eslint --fix ./src",
7
+ "format": "yarn run -T prettier --write --log-level warn .",
8
+ "tc": "tsc --noEmit",
9
+ "test": "yarn test-runner 'vitest run'",
10
+ "test:watch": "yarn test-runner 'vitest watch'",
11
+ "build": "yarn clean && yarn ci:build",
12
+ "start:dev": "yarn ci:build --watch",
13
+ "clean": "rm -rf ./dist/",
14
+ "ci:build": "yarn run -T tsc -p tsconfig.build.json",
15
+ "ci:lint": "yarn run -T eslint . && yarn run -T prettier --check --log-level warn .",
16
+ "ci:tc": "yarn tc",
17
+ "ci:test": "yarn run -T ci:test --project @palmetto/dispatch-pubsub",
18
+ "hook:lint": "eslint --cache --fix",
19
+ "hook:format": "prettier --write --log-level warn",
20
+ "hook:tc": "yarn tc",
21
+ "prepublishOnly": "yarn build",
22
+ "test-runner": "yarn run -T $0 --project @palmetto/dispatch-pubsub"
23
+ },
24
+ "devDependencies": {
25
+ "@palmetto/pubsub": "^3.5.1",
26
+ "typescript": "^5.9.3",
27
+ "vitest": "^4.1.5",
28
+ "zod": "^4.4.2"
29
+ },
30
+ "files": [
31
+ "dist/**/*",
32
+ "README.md"
33
+ ],
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "peerDependencies": {
41
+ "@palmetto/pubsub": "^3.5",
42
+ "zod": "^4.3"
43
+ }
44
+ }