@glowlabs-org/events-sdk 1.0.5 → 1.0.7

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 CHANGED
@@ -54,13 +54,14 @@ Both `createGlowEventListener` and `createGlowEventEmitter` accept the following
54
54
 
55
55
  Currently supported event types and versions:
56
56
 
57
- | Event Name | Version | Payload Type | Description |
58
- | --------------------- | ------- | ----------------------------- | -------------------------------------- |
59
- | `audit.pushed` | "v1" | `AuditPushedV1Payload` | Emitted when an audit is pushed |
60
- | `audit.slashed` | "v1" | `AuditSlashedV1Payload` | Emitted when a farm is slashed |
61
- | `audit.pfees.paid` | "v1" | `AuditPfeesPaidV1Payload` | Paid (by applicationId) |
62
- | `audit.pfees.paid` | "v2" | `AuditPfeesPaidV2Payload` | Paid (by farmId) |
63
- | `application.created` | "v1" | `ApplicationCreatedV1Payload` | Emitted when an application is created |
57
+ | Event Name | Version | Payload Type | Description |
58
+ | --------------------- | ------- | ----------------------------- | --------------------------------------------------- |
59
+ | `audit.pushed` | "v1" | `AuditPushedV1Payload` | Emitted when an audit is pushed |
60
+ | `audit.slashed` | "v1" | `AuditSlashedV1Payload` | Emitted when a farm is slashed |
61
+ | `audit.pfees.paid` | "v1" | `AuditPfeesPaidV1Payload` | Paid (by applicationId) |
62
+ | `audit.pfees.paid` | "v2" | `AuditPfeesPaidV2Payload` | Paid (by farmId) |
63
+ | `application.created` | "v1" | `ApplicationCreatedV1Payload` | Emitted when an application is created |
64
+ | `audit.pushed` | "v2" | `AuditPushedV2Payload` | Emitted when an audit is pushed (farmId is bytes16) |
64
65
 
65
66
  ---
66
67
 
@@ -88,7 +89,7 @@ Use these in your code to avoid hardcoding event names and to benefit from autoc
88
89
 
89
90
  ```ts
90
91
  export interface AuditPushedV1Payload {
91
- farmId: string; // bytes32 hex string (0x...)
92
+ farmId: string; // UUID string
92
93
  protocolFeeUSDPrice_12Decimals: string; // uint256 (decimal) − 12 implied decimals
93
94
  expectedProduction_12Decimals: string; // uint256 (decimal) − 12 implied decimals
94
95
  txHash: string; // bytes32 hex string (0x...)
@@ -97,7 +98,7 @@ export interface AuditPushedV1Payload {
97
98
 
98
99
  **Validation:**
99
100
 
100
- - `farmId` must be a 32-byte hex string (e.g., `0x...`).
101
+ - `farmId` must be a valid UUID string (e.g., `afbc56b6-0b16-4119-b144-025728067ba6`).
101
102
  - `protocolFeeUSDPrice_12Decimals` and `expectedProduction_12Decimals` must be decimal strings representing unsigned big integers.
102
103
  - `txHash` must be a 32-byte hex string (e.g., `0x...`).
103
104
 
@@ -105,7 +106,7 @@ export interface AuditPushedV1Payload {
105
106
 
106
107
  ```ts
107
108
  export interface AuditSlashedV1Payload {
108
- farmId: string; // bytes32 hex string (0x...)
109
+ farmId: string; // bytes16 hex string (0x...)
109
110
  slasher: string; // Ethereum address (0x...)
110
111
  txHash: string; // bytes32 hex string (0x...)
111
112
  }
@@ -113,7 +114,7 @@ export interface AuditSlashedV1Payload {
113
114
 
114
115
  **Validation:**
115
116
 
116
- - `farmId` must be a 32-byte hex string (e.g., `0x...`).
117
+ - `farmId` must be a 16-byte hex string (e.g., `0x...`).
117
118
  - `slasher` must be a valid Ethereum address (0x...40 hex chars).
118
119
  - `txHash` must be a 32-byte hex string (e.g., `0x...`).
119
120
 
@@ -121,25 +122,25 @@ export interface AuditSlashedV1Payload {
121
122
 
122
123
  ```ts
123
124
  export interface AuditPfeesPaidV1Payload {
124
- applicationId: string; // bytes32 hex string (0x...)
125
+ applicationId: string; // UUID string
125
126
  payer: string; // Ethereum address (0x...)
126
- amount_12Decimals: string; // uint256 (decimal) − 12 implied decimals
127
+ amount_6Decimals: string; // uint256 (decimal) − 6 implied decimals
127
128
  txHash: string; // bytes32 hex string (0x...)
128
129
  }
129
130
  ```
130
131
 
131
132
  **Validation:**
132
133
 
133
- - `applicationId` must be a 32-byte hex string (e.g., `0x...`).
134
+ - `applicationId` must be a valid UUID string (e.g., `3ed964b1-4f02-475a-9789-fb74b3466c70`).
134
135
  - `payer` must be a valid Ethereum address (0x...40 hex chars).
135
- - `amount_12Decimals` must be a decimal string representing an unsigned big integer (12 implied decimals).
136
+ - `amount_6Decimals` must be a decimal string representing an unsigned big integer (6 implied decimals).
136
137
  - `txHash` must be a 32-byte hex string (e.g., `0x...`).
137
138
 
138
139
  ### `audit.pfees.paid` v2 (by farmId)
139
140
 
140
141
  ```ts
141
142
  export interface AuditPfeesPaidV2Payload {
142
- farmId: string; // bytes32 hex string (0x...)
143
+ farmId: string; // bytes16 hex string (0x...)
143
144
  payer: string; // Ethereum address (0x...)
144
145
  amount_12Decimals: string; // uint256 (decimal) − 12 implied decimals
145
146
  txHash: string; // bytes32 hex string (0x...)
@@ -148,11 +149,28 @@ export interface AuditPfeesPaidV2Payload {
148
149
 
149
150
  **Validation:**
150
151
 
151
- - `farmId` must be a 32-byte hex string (e.g., `0x...`).
152
+ - `farmId` must be a 16-byte hex string (e.g., `0x...`).
152
153
  - `payer` must be a valid Ethereum address (0x...40 hex chars).
153
154
  - `amount_12Decimals` must be a decimal string representing an unsigned big integer (12 implied decimals).
154
155
  - `txHash` must be a 32-byte hex string (e.g., `0x...`).
155
156
 
157
+ ### `audit.pushed` v2
158
+
159
+ ```ts
160
+ export interface AuditPushedV2Payload {
161
+ farmId: string; // bytes16 hex string (0x...)
162
+ protocolFeeUSDPrice_12Decimals: string; // uint256 (decimal) − 12 implied decimals
163
+ expectedProduction_12Decimals: string; // uint256 (decimal) − 12 implied decimals
164
+ txHash: string; // bytes32 hex string (0x...)
165
+ }
166
+ ```
167
+
168
+ **Validation:**
169
+
170
+ - `farmId` must be a 16-byte hex string (e.g., `0x...`).
171
+ - `protocolFeeUSDPrice_12Decimals` and `expectedProduction_12Decimals` must be decimal strings representing unsigned big integers.
172
+ - `txHash` must be a 32-byte hex string (e.g., `0x...`).
173
+
156
174
  ### `application.created` v1
157
175
 
158
176
  ```ts
@@ -215,7 +233,7 @@ listener.onEvent("audit.pfees.paid", "v1", (event) => {
215
233
  "Received audit.pfees.paid v1:",
216
234
  event.payload.applicationId,
217
235
  event.payload.payer,
218
- event.payload.amount_12Decimals
236
+ event.payload.amount_6Decimals
219
237
  );
220
238
  });
221
239
 
@@ -264,7 +282,7 @@ await emitter.emit({
264
282
  eventType: "audit.pushed",
265
283
  schemaVersion: "v1",
266
284
  payload: {
267
- farmId: "0x...",
285
+ farmId: "afbc56b6-0b16-4119-b144-025728067ba6", // UUID string
268
286
  protocolFeeUSDPrice_12Decimals: "...",
269
287
  expectedProduction_12Decimals: "...",
270
288
  txHash: "0x...",
@@ -285,9 +303,9 @@ await emitter.emit({
285
303
  eventType: "audit.pfees.paid",
286
304
  schemaVersion: "v1",
287
305
  payload: {
288
- applicationId: "0x...",
306
+ applicationId: "3ed964b1-4f02-475a-9789-fb74b3466c70", // UUID string
289
307
  payer: "0x...",
290
- amount_12Decimals: "1000000000000",
308
+ amount_6Decimals: "1000000000000",
291
309
  txHash: "0x...",
292
310
  },
293
311
  });
@@ -8,6 +8,7 @@ const audit_pfees_paid_v2_1 = require("./schemas/audit-pfees-paid.v2");
8
8
  const base_event_1 = require("./base-event");
9
9
  const application_created_v1_1 = require("./schemas/application-created.v1");
10
10
  const event_types_1 = require("./event-types");
11
+ const audit_pushed_v2_1 = require("./schemas/audit-pushed.v2");
11
12
  const eventTypeRegistry = {
12
13
  [`${event_types_1.eventTypes.auditPushed}:v1`]: base_event_1.baseEventZ.extend({
13
14
  payload: audit_pushed_v1_1.auditPushedV1PayloadZ,
@@ -24,6 +25,9 @@ const eventTypeRegistry = {
24
25
  [`${event_types_1.eventTypes.applicationCreated}:v1`]: base_event_1.baseEventZ.extend({
25
26
  payload: application_created_v1_1.applicationCreatedV1PayloadZ,
26
27
  }),
28
+ [`${event_types_1.eventTypes.auditPushed}:v2`]: base_event_1.baseEventZ.extend({
29
+ payload: audit_pushed_v2_1.auditPushedV2PayloadZ,
30
+ }),
27
31
  // Add more event types/versions here
28
32
  };
29
33
  function getEventSchema(eventType, version) {
@@ -0,0 +1,5 @@
1
+ export declare const hexBytes32: RegExp;
2
+ export declare const ethAddress: RegExp;
3
+ export declare const uint256: RegExp;
4
+ export declare const exchangeOrQueueNamePattern: RegExp;
5
+ export declare const hexBytes16: RegExp;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hexBytes16 = exports.exchangeOrQueueNamePattern = exports.uint256 = exports.ethAddress = exports.hexBytes32 = void 0;
4
+ exports.hexBytes32 = /^0x[0-9a-fA-F]{64}$/;
5
+ exports.ethAddress = /^0x[0-9a-fA-F]{40}$/;
6
+ exports.uint256 = /^[0-9]+$/;
7
+ exports.exchangeOrQueueNamePattern = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
8
+ exports.hexBytes16 = /^0x[0-9a-fA-F]{32}$/;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applicationCreatedV1PayloadZ = void 0;
4
4
  const zod_1 = require("zod");
5
- const utils_1 = require("../utils");
5
+ const patterns_1 = require("../patterns");
6
6
  exports.applicationCreatedV1PayloadZ = zod_1.z.object({
7
- gcaAddress: zod_1.z.string().regex(utils_1.ethAddress), // eth address
7
+ gcaAddress: zod_1.z.string().regex(patterns_1.ethAddress), // eth address
8
8
  lat: zod_1.z.number(),
9
9
  lng: zod_1.z.number(),
10
10
  estimatedCostOfPowerPerKWh: zod_1.z.number(),
@@ -2,17 +2,17 @@ import { z } from "zod";
2
2
  export declare const auditPfeesPaidV1PayloadZ: z.ZodObject<{
3
3
  applicationId: z.ZodString;
4
4
  payer: z.ZodString;
5
- amount_12Decimals: z.ZodString;
5
+ amount_6Decimals: z.ZodString;
6
6
  txHash: z.ZodString;
7
7
  }, "strip", z.ZodTypeAny, {
8
8
  txHash: string;
9
9
  applicationId: string;
10
10
  payer: string;
11
- amount_12Decimals: string;
11
+ amount_6Decimals: string;
12
12
  }, {
13
13
  txHash: string;
14
14
  applicationId: string;
15
15
  payer: string;
16
- amount_12Decimals: string;
16
+ amount_6Decimals: string;
17
17
  }>;
18
18
  export type AuditPfeesPaidV1Payload = z.infer<typeof auditPfeesPaidV1PayloadZ>;
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.auditPfeesPaidV1PayloadZ = void 0;
4
4
  const zod_1 = require("zod");
5
- const utils_1 = require("../utils");
5
+ const patterns_1 = require("../patterns");
6
6
  exports.auditPfeesPaidV1PayloadZ = zod_1.z.object({
7
- applicationId: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
8
- payer: zod_1.z.string().regex(utils_1.ethAddress, "Ethereum address"),
9
- amount_12Decimals: zod_1.z
7
+ applicationId: zod_1.z.string().uuid("UUID string"),
8
+ payer: zod_1.z.string().regex(patterns_1.ethAddress, "Ethereum address"),
9
+ amount_6Decimals: zod_1.z
10
10
  .string()
11
- .regex(utils_1.uint256, "uint256 (decimal) − 12 implied decimals"),
12
- txHash: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
11
+ .regex(patterns_1.uint256, "uint256 (decimal) − 6 implied decimals"),
12
+ txHash: zod_1.z.string().regex(patterns_1.hexBytes32, "bytes32 hex string"),
13
13
  });
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.auditPfeesPaidV2PayloadZ = void 0;
4
4
  const zod_1 = require("zod");
5
- const utils_1 = require("../utils");
5
+ const patterns_1 = require("../patterns");
6
6
  exports.auditPfeesPaidV2PayloadZ = zod_1.z.object({
7
- farmId: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
8
- payer: zod_1.z.string().regex(utils_1.ethAddress, "Ethereum address"),
7
+ farmId: zod_1.z.string().regex(patterns_1.hexBytes16, "bytes16 hex string"),
8
+ payer: zod_1.z.string().regex(patterns_1.ethAddress, "Ethereum address"),
9
9
  amount_12Decimals: zod_1.z
10
10
  .string()
11
- .regex(utils_1.uint256, "uint256 (decimal) − 12 implied decimals"),
12
- txHash: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
11
+ .regex(patterns_1.uint256, "uint256 (decimal) − 12 implied decimals"),
12
+ txHash: zod_1.z.string().regex(patterns_1.hexBytes32, "bytes32 hex string"),
13
13
  });
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.auditPushedV1PayloadZ = void 0;
4
4
  const zod_1 = require("zod");
5
- const utils_1 = require("../utils");
5
+ const patterns_1 = require("../patterns");
6
6
  exports.auditPushedV1PayloadZ = zod_1.z.object({
7
- farmId: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
7
+ farmId: zod_1.z.string().uuid(),
8
8
  protocolFeeUSDPrice_12Decimals: zod_1.z
9
9
  .string()
10
- .regex(utils_1.uint256, "uint256 (decimal) − 12 implied decimals"),
11
- expectedProduction_12Decimals: zod_1.z.string().regex(utils_1.uint256),
12
- txHash: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
10
+ .regex(patterns_1.uint256, "uint256 (decimal) − 12 implied decimals"),
11
+ expectedProduction_12Decimals: zod_1.z.string().regex(patterns_1.uint256),
12
+ txHash: zod_1.z.string().regex(patterns_1.hexBytes32, "bytes32 hex string"),
13
13
  });
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare const auditPushedV2PayloadZ: z.ZodObject<{
3
+ farmId: z.ZodString;
4
+ protocolFeeUSDPrice_12Decimals: z.ZodString;
5
+ expectedProduction_12Decimals: z.ZodString;
6
+ txHash: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ farmId: string;
9
+ protocolFeeUSDPrice_12Decimals: string;
10
+ expectedProduction_12Decimals: string;
11
+ txHash: string;
12
+ }, {
13
+ farmId: string;
14
+ protocolFeeUSDPrice_12Decimals: string;
15
+ expectedProduction_12Decimals: string;
16
+ txHash: string;
17
+ }>;
18
+ export type AuditPushedV2Payload = z.infer<typeof auditPushedV2PayloadZ>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.auditPushedV2PayloadZ = void 0;
4
+ const zod_1 = require("zod");
5
+ const patterns_1 = require("../patterns");
6
+ exports.auditPushedV2PayloadZ = zod_1.z.object({
7
+ farmId: zod_1.z.string().regex(patterns_1.hexBytes16, "bytes16 hex string"),
8
+ protocolFeeUSDPrice_12Decimals: zod_1.z
9
+ .string()
10
+ .regex(patterns_1.uint256, "uint256 (decimal) − 12 implied decimals"),
11
+ expectedProduction_12Decimals: zod_1.z.string().regex(patterns_1.uint256),
12
+ txHash: zod_1.z.string().regex(patterns_1.hexBytes32, "bytes32 hex string"),
13
+ });
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.auditSlashedV1PayloadZ = void 0;
4
4
  const zod_1 = require("zod");
5
- const utils_1 = require("../utils");
5
+ const patterns_1 = require("../patterns");
6
6
  exports.auditSlashedV1PayloadZ = zod_1.z.object({
7
- farmId: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
8
- slasher: zod_1.z.string().regex(utils_1.ethAddress, "Ethereum address"),
9
- txHash: zod_1.z.string().regex(utils_1.hexBytes32, "bytes32 hex string"),
7
+ farmId: zod_1.z.string().regex(patterns_1.hexBytes16, "bytes16 hex string"),
8
+ slasher: zod_1.z.string().regex(patterns_1.ethAddress, "Ethereum address"),
9
+ txHash: zod_1.z.string().regex(patterns_1.hexBytes32, "bytes32 hex string"),
10
10
  });
package/dist/types.d.ts CHANGED
@@ -4,12 +4,14 @@ import type { AuditSlashedV1Payload } from "./schemas/audit-slashed.v1";
4
4
  import type { AuditPfeesPaidV1Payload } from "./schemas/audit-pfees-paid.v1";
5
5
  import type { AuditPfeesPaidV2Payload } from "./schemas/audit-pfees-paid.v2";
6
6
  import type { ApplicationCreatedV1Payload } from "./schemas/application-created.v1";
7
+ import type { AuditPushedV2Payload } from "./schemas/audit-pushed.v2";
7
8
  import { eventTypes, EventType } from "./event-types";
8
9
  export { EventType, eventTypes };
9
10
  export type EventVersion = "v1" | "v2";
10
11
  export interface EventPayloadMap {
11
12
  [eventTypes.auditPushed]: {
12
13
  v1: AuditPushedV1Payload;
14
+ v2: AuditPushedV2Payload;
13
15
  };
14
16
  [eventTypes.auditSlashed]: {
15
17
  v1: AuditSlashedV1Payload;
package/dist/utils.d.ts CHANGED
@@ -18,10 +18,6 @@ export declare function processEventMessage(msg: {
18
18
  routingKey: string;
19
19
  };
20
20
  }): any;
21
- export declare const hexBytes32: RegExp;
22
- export declare const ethAddress: RegExp;
23
- export declare const uint256: RegExp;
24
- export declare const exchangeOrQueueNamePattern: RegExp;
25
21
  export declare function validateName(name: string, type: "exchange" | "queue"): void;
26
22
  export declare function buildAmqpUrl({ username, password, host, }: {
27
23
  username: string;
package/dist/utils.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exchangeOrQueueNamePattern = exports.uint256 = exports.ethAddress = exports.hexBytes32 = void 0;
4
3
  exports.validateZoneNameAndId = validateZoneNameAndId;
5
4
  exports.validateEventPayload = validateEventPayload;
6
5
  exports.processEventMessage = processEventMessage;
@@ -8,6 +7,7 @@ exports.validateName = validateName;
8
7
  exports.buildAmqpUrl = buildAmqpUrl;
9
8
  const event_registry_1 = require("./event-registry");
10
9
  const zones_1 = require("./zones");
10
+ const patterns_1 = require("./patterns");
11
11
  /**
12
12
  * Validates that the zoneName matches the zoneId using the zoneMap.
13
13
  * Throws an error if the values are inconsistent.
@@ -46,12 +46,8 @@ function processEventMessage(msg) {
46
46
  validateEventPayload(eventType, schemaVersion, decoded);
47
47
  return (0, event_registry_1.getEventSchema)(eventType, schemaVersion).parse(decoded);
48
48
  }
49
- exports.hexBytes32 = /^0x[0-9a-fA-F]{64}$/;
50
- exports.ethAddress = /^0x[0-9a-fA-F]{40}$/;
51
- exports.uint256 = /^[0-9]+$/;
52
- exports.exchangeOrQueueNamePattern = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
53
49
  function validateName(name, type) {
54
- if (!exports.exchangeOrQueueNamePattern.test(name)) {
50
+ if (!patterns_1.exchangeOrQueueNamePattern.test(name)) {
55
51
  throw new Error(`${type} name '${name}' is invalid. Must be dot-separated (e.g., 'glow.zone-1.events').`);
56
52
  }
57
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/events-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Typed event SDK for Glow, powered by RabbitMQ and Zod.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",