@heavybit/ecommerce-contracts 0.0.0-stage → 0.2.2

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 (130) hide show
  1. package/README.md +158 -2
  2. package/dist/cjs/app.js +38 -0
  3. package/dist/cjs/app.js.map +1 -0
  4. package/dist/cjs/bindings.js +127 -0
  5. package/dist/cjs/bindings.js.map +1 -0
  6. package/dist/cjs/events/audit.js +26 -0
  7. package/dist/cjs/events/audit.js.map +1 -0
  8. package/dist/cjs/events/auth.js +68 -0
  9. package/dist/cjs/events/auth.js.map +1 -0
  10. package/dist/cjs/events/base.js +99 -0
  11. package/dist/cjs/events/base.js.map +1 -0
  12. package/dist/cjs/events/cart.js +15 -0
  13. package/dist/cjs/events/cart.js.map +1 -0
  14. package/dist/cjs/events/catalog.js +24 -0
  15. package/dist/cjs/events/catalog.js.map +1 -0
  16. package/dist/cjs/events/gateway.js +24 -0
  17. package/dist/cjs/events/gateway.js.map +1 -0
  18. package/dist/cjs/events/index.js +131 -0
  19. package/dist/cjs/events/index.js.map +1 -0
  20. package/dist/cjs/events/media.js +17 -0
  21. package/dist/cjs/events/media.js.map +1 -0
  22. package/dist/cjs/events/notification.js +43 -0
  23. package/dist/cjs/events/notification.js.map +1 -0
  24. package/dist/cjs/events/order.js +45 -0
  25. package/dist/cjs/events/order.js.map +1 -0
  26. package/dist/cjs/events/payment.js +34 -0
  27. package/dist/cjs/events/payment.js.map +1 -0
  28. package/dist/cjs/events/security.js +36 -0
  29. package/dist/cjs/events/security.js.map +1 -0
  30. package/dist/cjs/events/shipping.js +25 -0
  31. package/dist/cjs/events/shipping.js.map +1 -0
  32. package/dist/cjs/events/store.js +25 -0
  33. package/dist/cjs/events/store.js.map +1 -0
  34. package/dist/cjs/events/usage.js +17 -0
  35. package/dist/cjs/events/usage.js.map +1 -0
  36. package/dist/cjs/identity.js +52 -0
  37. package/dist/cjs/identity.js.map +1 -0
  38. package/dist/cjs/index.js +27 -0
  39. package/dist/cjs/index.js.map +1 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/cjs/permissions.js +10 -0
  42. package/dist/cjs/permissions.js.map +1 -0
  43. package/dist/cjs/scopes.js +57 -0
  44. package/dist/cjs/scopes.js.map +1 -0
  45. package/dist/esm/app.js +35 -0
  46. package/dist/esm/app.js.map +1 -0
  47. package/dist/esm/bindings.js +115 -0
  48. package/dist/esm/bindings.js.map +1 -0
  49. package/dist/esm/events/audit.js +23 -0
  50. package/dist/esm/events/audit.js.map +1 -0
  51. package/dist/esm/events/auth.js +65 -0
  52. package/dist/esm/events/auth.js.map +1 -0
  53. package/dist/esm/events/base.js +90 -0
  54. package/dist/esm/events/base.js.map +1 -0
  55. package/dist/esm/events/cart.js +12 -0
  56. package/dist/esm/events/cart.js.map +1 -0
  57. package/dist/esm/events/catalog.js +21 -0
  58. package/dist/esm/events/catalog.js.map +1 -0
  59. package/dist/esm/events/gateway.js +21 -0
  60. package/dist/esm/events/gateway.js.map +1 -0
  61. package/dist/esm/events/index.js +100 -0
  62. package/dist/esm/events/index.js.map +1 -0
  63. package/dist/esm/events/media.js +14 -0
  64. package/dist/esm/events/media.js.map +1 -0
  65. package/dist/esm/events/notification.js +40 -0
  66. package/dist/esm/events/notification.js.map +1 -0
  67. package/dist/esm/events/order.js +42 -0
  68. package/dist/esm/events/order.js.map +1 -0
  69. package/dist/esm/events/payment.js +31 -0
  70. package/dist/esm/events/payment.js.map +1 -0
  71. package/dist/esm/events/security.js +33 -0
  72. package/dist/esm/events/security.js.map +1 -0
  73. package/dist/esm/events/shipping.js +22 -0
  74. package/dist/esm/events/shipping.js.map +1 -0
  75. package/dist/esm/events/store.js +22 -0
  76. package/dist/esm/events/store.js.map +1 -0
  77. package/dist/esm/events/usage.js +14 -0
  78. package/dist/esm/events/usage.js.map +1 -0
  79. package/dist/esm/identity.js +49 -0
  80. package/dist/esm/identity.js.map +1 -0
  81. package/dist/esm/index.js +11 -0
  82. package/dist/esm/index.js.map +1 -0
  83. package/dist/esm/package.json +1 -0
  84. package/dist/esm/permissions.js +7 -0
  85. package/dist/esm/permissions.js.map +1 -0
  86. package/dist/esm/scopes.js +52 -0
  87. package/dist/esm/scopes.js.map +1 -0
  88. package/dist/types/app.d.ts +40 -0
  89. package/dist/types/app.d.ts.map +1 -0
  90. package/dist/types/bindings.d.ts +88 -0
  91. package/dist/types/bindings.d.ts.map +1 -0
  92. package/dist/types/events/audit.d.ts +86 -0
  93. package/dist/types/events/audit.d.ts.map +1 -0
  94. package/dist/types/events/auth.d.ts +357 -0
  95. package/dist/types/events/auth.d.ts.map +1 -0
  96. package/dist/types/events/base.d.ts +108 -0
  97. package/dist/types/events/base.d.ts.map +1 -0
  98. package/dist/types/events/cart.d.ts +37 -0
  99. package/dist/types/events/cart.d.ts.map +1 -0
  100. package/dist/types/events/catalog.d.ts +126 -0
  101. package/dist/types/events/catalog.d.ts.map +1 -0
  102. package/dist/types/events/gateway.d.ts +77 -0
  103. package/dist/types/events/gateway.d.ts.map +1 -0
  104. package/dist/types/events/index.d.ts +4333 -0
  105. package/dist/types/events/index.d.ts.map +1 -0
  106. package/dist/types/events/media.d.ts +51 -0
  107. package/dist/types/events/media.d.ts.map +1 -0
  108. package/dist/types/events/notification.d.ts +270 -0
  109. package/dist/types/events/notification.d.ts.map +1 -0
  110. package/dist/types/events/order.d.ts +289 -0
  111. package/dist/types/events/order.d.ts.map +1 -0
  112. package/dist/types/events/payment.d.ts +228 -0
  113. package/dist/types/events/payment.d.ts.map +1 -0
  114. package/dist/types/events/security.d.ts +201 -0
  115. package/dist/types/events/security.d.ts.map +1 -0
  116. package/dist/types/events/shipping.d.ts +91 -0
  117. package/dist/types/events/shipping.d.ts.map +1 -0
  118. package/dist/types/events/store.d.ts +134 -0
  119. package/dist/types/events/store.d.ts.map +1 -0
  120. package/dist/types/events/usage.d.ts +59 -0
  121. package/dist/types/events/usage.d.ts.map +1 -0
  122. package/dist/types/identity.d.ts +24 -0
  123. package/dist/types/identity.d.ts.map +1 -0
  124. package/dist/types/index.d.ts +11 -0
  125. package/dist/types/index.d.ts.map +1 -0
  126. package/dist/types/permissions.d.ts +7 -0
  127. package/dist/types/permissions.d.ts.map +1 -0
  128. package/dist/types/scopes.d.ts +57 -0
  129. package/dist/types/scopes.d.ts.map +1 -0
  130. package/package.json +44 -4
package/README.md CHANGED
@@ -1,3 +1,159 @@
1
- # Temporary Holding Version
1
+ # @heavybit/ecommerce-contracts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The e-commerce app's own shared contracts (decision D40), built on the generic
4
+ [`@heavybit/shared-lib`](../shared-lib/README.md). Every value that shared-lib takes as a parameter
5
+ — the app slug, currency, region, time zone, identity headers, step-up scopes, scope columns, event
6
+ names and payload schemas — is defined here once. **No business logic** lives in this package, and
7
+ nothing here may move into shared-lib (D39).
8
+
9
+ Version **0.2.0** (unpublished). Until it is published, services map it in Jest:
10
+ `'^@heavybit/ecommerce-contracts$': '<rootDir>/../ecommerce-contracts/src/index.ts'`.
11
+
12
+ ## Export map
13
+
14
+ One import path, `@heavybit/ecommerce-contracts`, verified against the built `dist/` (CJS and ESM) in
15
+ Prompt 1.10.
16
+
17
+ | Area (source) | Exports |
18
+ |---|---|
19
+ | App settings (`app.ts`) | `APP_SLUG`, `CURRENCY`, `PHONE_REGION`, `DEFAULT_TIME_ZONE`, `SOCKET_TICKET_DOMAIN`, `INTERNAL_PATH_PREFIX`, `PUBLIC_API_PREFIX`, `NOTIFICATION_CATEGORIES`, `NOTIFICATION_CHANNELS`, `notificationDispatchSchema` |
20
+ | Identity (`identity.ts`) | `ecommerceIdentityProtocol`, `ecommerceStepUpScopes` |
21
+ | Scopes (`scopes.ts`) | `companyScope`, `customerScope`, `platformScope`, `companyScopeFrom`, `isPlatformOperator`, `COMPANY_COLUMN`, `CUSTOMER_COLUMN`, `COMPANY_SCOPE_KEY`, `PLATFORM_PERMISSION_PREFIX` |
22
+ | Bindings (`bindings.ts`) | `money`, `zeroMoney`, `normalisePhone`, `companyDayBounds`, `APPROVAL_TTL_HOURS`, `approvalPolicy`, `toAuditRecordedPayload`, `signAppSocketTicket`, `verifyAppSocketTicket`, `companyRoom`, `canJoinCompanyRoom` |
23
+ | Permissions (`permissions.ts`) | `APPROVAL_DECIDE_PERMISSION` |
24
+ | Events (`events/`) | `ROUTING_KEYS`, `ALL_ROUTING_KEYS`, `schemaFor`, `envelopeDataSchemaFor`, `isRoutingKey`, `isCompanyScopedEvent`, `EVENT_SCHEMAS`, `COMMAND_SCHEMAS`, `MESSAGE_SCHEMAS`, `EVENT_EXCHANGE`, `COMMAND_EXCHANGE`, `EVENT_PUBLISHERS`, `auditRecordedSchema`, audit/socket-rejected keys and binding patterns; types `EventPayload<K>`, `EventPayloadInput<K>` |
25
+
26
+ ## Commands
27
+
28
+ ```bash
29
+ npm test # jest --runInBand
30
+ npx tsc --noEmit # type-check
31
+ npm run build # dist/esm, dist/cjs, dist/types
32
+ ```
33
+
34
+ The `@heavybit/shared-lib` dependency is `file:../shared-lib` while both live in this repository; switch
35
+ it to the published range (`^2.7.1` or later) when shared-lib is published. Jest maps shared-lib to
36
+ `../shared-lib/src`, so tests always run against the current library code.
37
+
38
+ ## App settings (`src/app.ts`)
39
+
40
+ | Export | Value | Used for |
41
+ |---|---|---|
42
+ | `APP_SLUG` | `ecommerce` | `createRedisKeyspace({ app })`, `createMessaging({ app })`, DB and container names (D15) |
43
+ | `CURRENCY` | `KES` | Every amount on the wire (decimal string + currency, D5) |
44
+ | `PHONE_REGION` | `KE` | Phone parsing; numbers are stored as `2547XXXXXXXX` |
45
+ | `DEFAULT_TIME_ZONE` | `Africa/Nairobi` | Fallback zone for reports, business days and emails |
46
+ | `SOCKET_TICKET_DOMAIN` | `ecommerce-socket-ticket:v1` | Domain separator of socket handshake tickets |
47
+ | `INTERNAL_PATH_PREFIX` | `/api/v1/internal` | `createInternalCallerGuards({ pathPrefix })` |
48
+ | `PUBLIC_API_PREFIX` | `/api/v1` | Public routes behind the gateway |
49
+ | `NOTIFICATION_CATEGORIES` | security, account, order, payment, shipping, support, staff, store, billing | Dispatch vocabulary |
50
+ | `NOTIFICATION_CHANNELS` | email, sms, in_app | Dispatch vocabulary (D20) |
51
+ | `notificationDispatchSchema` | `createNotificationDispatchSchema(...)` | The `notification.send.requested` command body |
52
+
53
+ ## Identity and step-up (`src/identity.ts`)
54
+
55
+ - `ecommerceIdentityProtocol`: domain `ecommerce-gateway-identity:v2`; signed company headers
56
+ `x-company-id` → `AuthUser.scopes.company` and `x-company-slug` → `AuthUser.attrs.companySlug` and `x-company-status` → `AuthUser.attrs.companyStatus` (D22).
57
+ The gateway signs with it; every service passes it to `authenticateFromGateway({ protocol })`.
58
+ - `ecommerceStepUpScopes` (§6.4): `role-assign`*, `role-permissions`, `staff-remove`, `payment-config`*,
59
+ `payout-destination`*, `refund-large`, `customer-export`, `domain-change`*, `company-close`*,
60
+ `api-key-issue`*, `approval-decide`, `company-status`, `ledger-adjust`*, `support-access`,
61
+ `user-security`*, `dlq-replay` (* = single use).
62
+
63
+ ## Scope bindings (`src/scopes.ts`)
64
+
65
+ | Export | Column | Context | Rule |
66
+ |---|---|---|---|
67
+ | `companyScope` | `company_id` | `{ companyId }` from the signed `x-company-id` header, never a body | TEN-1, TEN-2 |
68
+ | `customerScope` | `user_id` | `{ ownerId: user.id }` | TEN-8 |
69
+ | `platformScope` | `company_id` (`IS NOT NULL`) | `platformScope.authorize(req.user)` — super admin or any `platform:*` permission | TEN-8 |
70
+ | `companyScopeFrom` | — | `scopeFrom` for consumers of company events | TEN-7 |
71
+
72
+ ```ts
73
+ class ProductRepository extends ScopedRepository<typeof products, { companyId: string }> {}
74
+ const repo = new ProductRepository(db, products, companyScope);
75
+ await repo.findById({ companyId: req.user.scopes.company[0] }, id);
76
+ ```
77
+
78
+ ## Helper bindings (`src/bindings.ts`)
79
+
80
+ shared-lib's generic helpers with this app's values plugged in (no business logic):
81
+
82
+ | Export | Binds |
83
+ |---|---|
84
+ | `money(amount)`, `zeroMoney()` | `Money` in `CURRENCY` (KES, 2 dp; strict decimal strings) |
85
+ | `normalisePhone(phone)` | `toMsisdn(phone, 'KE', { mobileOnly, regionOnly })` → `2547…`/`2541…`; throws `INVALID_PHONE` |
86
+ | `companyDayBounds(at, zone?)` | `zonedDayBounds` in the shop's zone, default `Africa/Nairobi` |
87
+ | `APPROVAL_DECIDE_PERMISSION`, `APPROVAL_TTL_HOURS`, `approvalPolicy` | `createApprovalPolicy({ decidePermission: 'approval:decide', ttlSeconds: 72 h })` |
88
+ | `toAuditRecordedPayload(event)` | `buildAuditEvent` output → `{publisher}.audit.recorded` payload (company from the `company` scope; changed field names only) |
89
+ | `signAppSocketTicket`, `verifyAppSocketTicket` | socket tickets under `SOCKET_TICKET_DOMAIN` |
90
+ | `companyRoom(id)`, `canJoinCompanyRoom(claims, id, permission?)` | `scopeRoom` / `canJoinScopeRoom` on the `company` scope |
91
+
92
+ ## Event catalogue (`src/events/`)
93
+
94
+ One Zod schema per routing key, version 1. A payload schema describes the envelope `data` **without**
95
+ the reserved fields `eventId`, `version` and `actorUserId` — `enqueueOutbox` adds them and
96
+ `MessageConsumer` strips them before validating. Every payload is `.passthrough()` (MSG-3). Amounts are
97
+ 2-dp decimal strings with `currency: 'KES'` (D5). Payloads carry ids and small facts; contact details
98
+ travel only in the `notification.send.requested` command.
99
+
100
+ | Family | Keys | `companyId` |
101
+ |---|---|---|
102
+ | `auth.user.*` | registered, verified, password_reset_requested, password_changed, email_changed, deleted, authz_changed | — (authz_changed: optional) |
103
+ | `auth.company.*` | created, updated, suspended, reactivated, closed | required |
104
+ | `auth.staff.*`, `auth.membership.changed` | invited, joined, removed; changed | required |
105
+ | `auth.role.changed`, `auth.approval.*` | changed; requested, approved, rejected, expired, executed, failed | optional (platform roles/approvals) |
106
+ | `auth.security.*` | login_succeeded, login_failed, otp_failed, step_up, account_locked, sessions_revoked, role_changed, login_risky, login_unrecognized, alert_raised | optional |
107
+ | `gateway.security.*` | access_denied, rate_limited, bad_signature | optional |
108
+ | `store.*` | shop.provisioned, settings.changed, theme.published, domain.{changed,verified,failed} | required |
109
+ | `catalog.*` | product.{created,updated,deleted}, category.updated, inventory.{adjusted,low_stock} | required |
110
+ | `media.file.*` | uploaded, processed | required |
111
+ | `cart.cart.updated` | — | required |
112
+ | `order.order.*` | created, paid, status_changed, shipped, delivered, cancelled, expired, refund_requested | required |
113
+ | `order.issue.*` | opened, replied, escalated, resolved | required |
114
+ | `payment.*` | payment.{initiated,succeeded,failed,expired}, refund.{completed,failed}, payout.{scheduled,paid,failed} | required |
115
+ | `shipping.shipment.*` | created, dispatched, delivered, failed | required |
116
+ | `usage.*` | sms.sent, delivery.booked | required |
117
+ | `{publisher}.audit.recorded` | one per publisher; bind `*.audit.recorded` | optional |
118
+ | `{publisher}.security.socket_rejected` | one per publisher; bind `*.security.socket_rejected` | optional |
119
+ | **Command** `notification.send.requested` | `commands` exchange; dispatch + `companyId` | nullable, required field |
120
+
121
+ Publishers (`EVENT_PUBLISHERS`): auth, gateway, store, catalog, media, cart, order, payment, shipping,
122
+ notification, reporting. The field list of each key is in its `src/events/<domain>.ts` file.
123
+
124
+ ### API
125
+
126
+ ```ts
127
+ import { ROUTING_KEYS, schemaFor, envelopeDataSchemaFor, isCompanyScopedEvent, companyScopeFrom, type EventPayload } from '@heavybit/ecommerce-contracts';
128
+
129
+ // Producer (inside the domain change's transaction)
130
+ const payload: EventPayload<'order.order.paid'> = { companyId, orderId, orderNumber, userId, grandTotal: '1250.00', currency: 'KES', paidAt };
131
+ await enqueueOutbox(tx, ROUTING_KEYS.order.order.paid, schemaFor('order.order.paid').parse(payload), { actorUserId });
132
+
133
+ // Command
134
+ await enqueueOutbox(tx, ROUTING_KEYS.notification.send.requested, dispatch, { exchange: 'commands', actorUserId: null });
135
+
136
+ // Consumer
137
+ await messaging.consumer.subscribe({
138
+ queue: 'order-paid',
139
+ bindings: [{ exchange: 'events', routingKey: ROUTING_KEYS.order.order.paid }],
140
+ schema: schemaFor('order.order.paid'),
141
+ scopeFrom: companyScopeFrom, // only for isCompanyScopedEvent(key)
142
+ dedupe: new ProcessedEventsDeduper(db),
143
+ handler: ({ data, scope, tx }) => service.onOrderPaid(scope!, data, tx!),
144
+ });
145
+ ```
146
+
147
+ - `schemaFor(key)` — payload schema; throws for an unknown key.
148
+ - `envelopeDataSchemaFor(key)` — payload + `eventId` (ULID), `version` (literal 1), `actorUserId` (ULID or null).
149
+ - `EventPayload<K>` / `EventPayloadInput<K>` — parsed / producer types.
150
+ - `isCompanyScopedEvent(key)` — `companyId` required; the consumer must use `scopeFrom: companyScopeFrom`.
151
+ - `ALL_ROUTING_KEYS`, `EVENT_SCHEMAS`, `COMMAND_SCHEMAS`, `MESSAGE_SCHEMAS`, `isRoutingKey`.
152
+
153
+ ### Changing the catalogue
154
+
155
+ - P2/P3 events are added by their phases: add the key to the domain's `*_KEYS`, its schema to `*_EVENTS`,
156
+ and the key to `EXPECTED_FIXED_KEYS` in `tests/event-schemas.test.ts`.
157
+ - Adding an optional field is compatible. Renaming or removing a field, or making one required, needs a
158
+ version-2 schema next to version 1 for at least one release (MS-4).
159
+ - Never use the reserved names `eventId`, `version`, `actorUserId` in a payload (a test enforces it).
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notificationDispatchSchema = exports.NOTIFICATION_CHANNELS = exports.NOTIFICATION_CATEGORIES = exports.PUBLIC_API_PREFIX = exports.INTERNAL_PATH_PREFIX = exports.SOCKET_TICKET_DOMAIN = exports.DEFAULT_TIME_ZONE = exports.PHONE_REGION = exports.CURRENCY = exports.APP_SLUG = void 0;
4
+ /**
5
+ * E-commerce app settings (D40). These are the values `@heavybit/shared-lib` takes as parameters:
6
+ * services pass them in (`createRedisKeyspace({ app: APP_SLUG, … })`, `createMessaging({ app: APP_SLUG, … })`,
7
+ * `Money`/phone helpers, socket tickets) instead of writing literals.
8
+ */
9
+ const shared_lib_1 = require("@heavybit/shared-lib");
10
+ /** Infra slug for containers, databases, Redis keys and exchanges (D15). */
11
+ exports.APP_SLUG = 'ecommerce';
12
+ /** The only currency in P1 (D5: money travels as decimal strings with this code). */
13
+ exports.CURRENCY = 'KES';
14
+ /** Region for phone parsing and normalisation (`2547XXXXXXXX`). */
15
+ exports.PHONE_REGION = 'KE';
16
+ /** IANA zone used when neither the shop nor the user has one (reports, business days, emails). */
17
+ exports.DEFAULT_TIME_ZONE = 'Africa/Nairobi';
18
+ /** Domain separator for socket handshake tickets, so a ticket from another app or purpose never verifies. */
19
+ exports.SOCKET_TICKET_DOMAIN = 'ecommerce-socket-ticket:v1';
20
+ /** Prefix of every internal (service-to-service) route; passed to `createInternalCallerGuards({ pathPrefix })`. */
21
+ exports.INTERNAL_PATH_PREFIX = '/api/v1/internal';
22
+ /** Prefix of the public API behind the gateway. */
23
+ exports.PUBLIC_API_PREFIX = '/api/v1';
24
+ /** What a notification is about; drives preferences and templates in the notification-service. */
25
+ exports.NOTIFICATION_CATEGORIES = ['security', 'account', 'order', 'payment', 'shipping', 'support', 'staff', 'store', 'billing'];
26
+ /** Delivery channels the notification-service supports (D20: email via SendGrid, SMS provider with a `log` driver in dev). */
27
+ exports.NOTIFICATION_CHANNELS = ['email', 'sms', 'in_app'];
28
+ /**
29
+ * Schema of a notification dispatch in this app's vocabulary. Producers stage it with the
30
+ * `notification.send.requested` command; the notification-service validates with the same schema.
31
+ *
32
+ * @example notificationDispatchSchema.parse({ template: 'login-otp', category: 'security', recipient: { email }, channels: ['email'], data: { code }, secretKeys: ['code'] })
33
+ */
34
+ exports.notificationDispatchSchema = (0, shared_lib_1.createNotificationDispatchSchema)({
35
+ categories: exports.NOTIFICATION_CATEGORIES,
36
+ channels: exports.NOTIFICATION_CHANNELS,
37
+ });
38
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,qDAK8B;AAE9B,4EAA4E;AAC/D,QAAA,QAAQ,GAAG,WAAoB,CAAC;AAE7C,qFAAqF;AACxE,QAAA,QAAQ,GAAG,KAAc,CAAC;AAEvC,mEAAmE;AACtD,QAAA,YAAY,GAAG,IAAa,CAAC;AAE1C,kGAAkG;AACrF,QAAA,iBAAiB,GAAG,gBAAyB,CAAC;AAE3D,6GAA6G;AAChG,QAAA,oBAAoB,GAAG,4BAAqC,CAAC;AAE1E,mHAAmH;AACtG,QAAA,oBAAoB,GAAG,kBAA2B,CAAC;AAEhE,mDAAmD;AACtC,QAAA,iBAAiB,GAAG,SAAkB,CAAC;AAEpD,kGAAkG;AACrF,QAAA,uBAAuB,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAEhJ,8HAA8H;AACjH,QAAA,qBAAqB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAOzE;;;;;GAKG;AACU,QAAA,0BAA0B,GAA0E,IAAA,6CAAgC,EAAC;IAChJ,UAAU,EAAE,+BAAuB;IACnC,QAAQ,EAAE,6BAAqB;CAChC,CAAC,CAAC"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.companyRoom = exports.approvalPolicy = exports.APPROVAL_TTL_HOURS = exports.zeroMoney = void 0;
4
+ exports.money = money;
5
+ exports.normalisePhone = normalisePhone;
6
+ exports.companyDayBounds = companyDayBounds;
7
+ exports.toAuditRecordedPayload = toAuditRecordedPayload;
8
+ exports.signAppSocketTicket = signAppSocketTicket;
9
+ exports.verifyAppSocketTicket = verifyAppSocketTicket;
10
+ exports.canJoinCompanyRoom = canJoinCompanyRoom;
11
+ /**
12
+ * Thin e-commerce bindings of shared-lib's generic helpers (D40): money in KES, Kenyan mobile numbers,
13
+ * business days in the shop's zone, the approval policy, audit payloads and socket tickets. No business
14
+ * logic — only app values plugged into the generic code.
15
+ */
16
+ const shared_lib_1 = require("@heavybit/shared-lib");
17
+ const app_js_1 = require("./app.js");
18
+ const permissions_js_1 = require("./permissions.js");
19
+ const scopes_js_1 = require("./scopes.js");
20
+ // ── Money ────────────────────────────────────────────────────────────────────────────────────────────
21
+ /**
22
+ * A KES amount from its decimal string (strict: at most 2 decimals, no separators).
23
+ *
24
+ * @param amount e.g. `"1250.00"`.
25
+ * @returns The amount.
26
+ * @example money('1250').add(money('99.50')).toDecimalString() // '1349.50'
27
+ */
28
+ function money(amount) {
29
+ return shared_lib_1.Money.fromDecimalString(amount, app_js_1.CURRENCY);
30
+ }
31
+ /** Zero shillings. */
32
+ const zeroMoney = () => shared_lib_1.Money.zero(app_js_1.CURRENCY);
33
+ exports.zeroMoney = zeroMoney;
34
+ // ── Phones ───────────────────────────────────────────────────────────────────────────────────────────
35
+ /**
36
+ * Normalises a Kenyan mobile number to `2547XXXXXXXX` / `2541XXXXXXXX` (the form M-Pesa and SMS use).
37
+ * Accepts `07…`, `01…`, `7…`, `+254…` and `254…` with spaces or dashes; rejects landlines and foreign numbers.
38
+ *
39
+ * @param phone Number as typed.
40
+ * @returns The MSISDN.
41
+ * @throws BadRequestError `INVALID_PHONE`.
42
+ * @example normalisePhone('0712 345 678') // '254712345678'
43
+ */
44
+ function normalisePhone(phone) {
45
+ return (0, shared_lib_1.toMsisdn)(phone, app_js_1.PHONE_REGION, { mobileOnly: true, regionOnly: true });
46
+ }
47
+ // ── Time ─────────────────────────────────────────────────────────────────────────────────────────────
48
+ /**
49
+ * The business day containing `at`, in the company's zone (default: the app's `DEFAULT_TIME_ZONE`).
50
+ *
51
+ * @param at Any instant in the day.
52
+ * @param zone The shop's IANA zone when it has one.
53
+ * @returns Half-open `[start, end)` UTC range.
54
+ */
55
+ function companyDayBounds(at, zone = app_js_1.DEFAULT_TIME_ZONE) {
56
+ return (0, shared_lib_1.zonedDayBounds)(at, zone);
57
+ }
58
+ // ── Approvals ────────────────────────────────────────────────────────────────────────────────────────
59
+ /** How long a pending approval stays decidable. */
60
+ exports.APPROVAL_TTL_HOURS = 72;
61
+ /**
62
+ * The approval rules with `APPROVAL_DECIDE_PERMISSION` and an `APPROVAL_TTL_HOURS` TTL.
63
+ *
64
+ * @example approvalPolicy.assertCanDecide(approval, req.user); approval.expiresAt = approvalPolicy.expiresAt();
65
+ */
66
+ exports.approvalPolicy = (0, shared_lib_1.createApprovalPolicy)({
67
+ decidePermission: permissions_js_1.APPROVAL_DECIDE_PERMISSION,
68
+ ttlSeconds: exports.APPROVAL_TTL_HOURS * 3600,
69
+ });
70
+ /**
71
+ * Maps a shared-lib audit event to this app's `{publisher}.audit.recorded` payload. The company comes from
72
+ * the event's `company` scope; changed field names (never values) go in `metadata.changedFields`; `ip` and
73
+ * `userAgent` are extra (passed-through) fields for audit-service.
74
+ * Stage it with `enqueueOutbox(tx, AUDIT_RECORDED_KEYS.order, toAuditRecordedPayload(event), { actorUserId: event.actorUserId })`.
75
+ *
76
+ * @param event From `buildAuditEvent`.
77
+ * @returns The payload.
78
+ */
79
+ function toAuditRecordedPayload(event) {
80
+ const changed = [...Object.keys(event.changes), ...event.redactedFields].sort();
81
+ return {
82
+ companyId: event.scope?.key === scopes_js_1.COMPANY_SCOPE_KEY ? event.scope.id : null,
83
+ action: event.action,
84
+ entityType: event.entityType,
85
+ entityId: event.entityId,
86
+ outcome: event.outcome,
87
+ occurredAt: event.occurredAt,
88
+ metadata: { changedFields: changed.join(',').slice(0, 500) },
89
+ // Request facts ride as extra payload fields (the schema passes them through), not in `metadata`.
90
+ ip: event.ip,
91
+ userAgent: event.userAgent,
92
+ };
93
+ }
94
+ // ── Sockets ──────────────────────────────────────────────────────────────────────────────────────────
95
+ /**
96
+ * Signs a socket ticket under this app's domain separator (`SOCKET_TICKET_DOMAIN`).
97
+ *
98
+ * @param input User, audience (the front-end app), company scope ids and permissions.
99
+ * @param secret The ticket signing secret.
100
+ * @param ttlSeconds 1–60 (default 60).
101
+ */
102
+ function signAppSocketTicket(input, secret, ttlSeconds) {
103
+ return (0, shared_lib_1.signSocketTicket)(input, { secret, domain: app_js_1.SOCKET_TICKET_DOMAIN, ttlSeconds });
104
+ }
105
+ /**
106
+ * Verifies a socket ticket under this app's domain separator.
107
+ *
108
+ * @param ticket From the handshake.
109
+ * @param secret The ticket signing secret.
110
+ * @param audience Accepted audience(s).
111
+ */
112
+ function verifyAppSocketTicket(ticket, secret, audience) {
113
+ return (0, shared_lib_1.verifySocketTicket)(ticket, { secret, domain: app_js_1.SOCKET_TICKET_DOMAIN, audience });
114
+ }
115
+ /** Room for one company's live updates: `company:{companyId}`. */
116
+ const companyRoom = (companyId) => (0, shared_lib_1.scopeRoom)(scopes_js_1.COMPANY_SCOPE_KEY, companyId);
117
+ exports.companyRoom = companyRoom;
118
+ /**
119
+ * True when the ticket holder may join `companyRoom(companyId)` (member of that company, or super admin)
120
+ * and holds `permission` when one is given.
121
+ *
122
+ * @example if (canJoinCompanyRoom(socket.data.identity, companyId, 'order:view')) socket.join(companyRoom(companyId));
123
+ */
124
+ function canJoinCompanyRoom(claims, companyId, permission) {
125
+ return (0, shared_lib_1.canJoinScopeRoom)(claims, scopes_js_1.COMPANY_SCOPE_KEY, companyId, permission);
126
+ }
127
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../src/bindings.ts"],"names":[],"mappings":";;;AAmCA,sBAEC;AAgBD,wCAEC;AAWD,4CAEC;AA+BD,wDAcC;AAWD,kDAEC;AASD,sDAEC;AAWD,gDAEC;AAtJD;;;;GAIG;AACH,qDAc8B;AAC9B,qCAA2F;AAE3F,qDAA8D;AAC9D,2CAAgD;AAGhD,wGAAwG;AAExG;;;;;;GAMG;AACH,SAAgB,KAAK,CAAC,MAAc;IAClC,OAAO,kBAAK,CAAC,iBAAiB,CAAC,MAAM,EAAE,iBAAQ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,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;QAC5D,kGAAkG;QAClG,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC;AAED,wGAAwG;AAExG;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,KAAwB,EAAE,MAAc,EAAE,UAAmB;IAC/F,OAAO,IAAA,6BAAgB,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,6BAAoB,EAAE,UAAU,EAAE,CAAC,CAAC;AACvF,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,MAAe,EAAE,MAAc,EAAE,QAAoC;IACzG,OAAO,IAAA,+BAAkB,EAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,6BAAoB,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,kEAAkE;AAC3D,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,IAAA,sBAAS,EAAC,6BAAiB,EAAE,SAAS,CAAC,CAAC;AAArF,QAAA,WAAW,eAA0E;AAElG;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAA0B,EAAE,SAAiB,EAAE,UAAmB;IACnG,OAAO,IAAA,6BAAgB,EAAC,MAAM,EAAE,6BAAiB,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AUDIT_EVENTS = exports.auditRecordedSchema = exports.AUDIT_RECORDED_KEYS = exports.AUDIT_RECORDED_PATTERN = void 0;
4
+ /**
5
+ * `{publisher}.audit.recorded`: business audit entries each service stages through its outbox for
6
+ * audit-service. Metadata holds small facts only — never secrets, tokens or contact details.
7
+ */
8
+ const shared_lib_1 = require("@heavybit/shared-lib");
9
+ const base_js_1 = require("./base.js");
10
+ /** Binding pattern for audit-service: every publisher's audit entries. */
11
+ exports.AUDIT_RECORDED_PATTERN = '*.audit.recorded';
12
+ /** `{publisher}.audit.recorded` for each publisher, e.g. `AUDIT_RECORDED_KEYS.order`. */
13
+ exports.AUDIT_RECORDED_KEYS = (0, base_js_1.perPublisher)('audit.recorded');
14
+ /** v1 payload of an audit entry. `companyId` is null for platform-level actions. */
15
+ exports.auditRecordedSchema = (0, base_js_1.optionalTenantPayload)({
16
+ /** What happened, e.g. `order.refund.approved`. */
17
+ action: shared_lib_1.z.string().min(1).max(100),
18
+ entityType: shared_lib_1.z.string().min(1).max(64),
19
+ entityId: base_js_1.id.nullable(),
20
+ outcome: shared_lib_1.z.enum(['success', 'failure']),
21
+ occurredAt: base_js_1.timestamp,
22
+ metadata: base_js_1.facts.optional(),
23
+ });
24
+ /** Every audit routing key with its schema. */
25
+ exports.AUDIT_EVENTS = (0, base_js_1.forEachKey)(exports.AUDIT_RECORDED_KEYS, exports.auditRecordedSchema);
26
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/events/audit.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,qDAAyC;AACzC,uCAAkG;AAElG,0EAA0E;AAC7D,QAAA,sBAAsB,GAAG,kBAA2B,CAAC;AAElE,yFAAyF;AAC5E,QAAA,mBAAmB,GAAG,IAAA,sBAAY,EAAC,gBAAgB,CAAC,CAAC;AAElE,oFAAoF;AACvE,QAAA,mBAAmB,GAAG,IAAA,+BAAqB,EAAC;IACvD,mDAAmD;IACnD,MAAM,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAClC,UAAU,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IACrC,QAAQ,EAAE,YAAE,CAAC,QAAQ,EAAE;IACvB,OAAO,EAAE,cAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvC,UAAU,EAAE,mBAAS;IACrB,QAAQ,EAAE,eAAK,CAAC,QAAQ,EAAE;CAC3B,CAAC,CAAC;AAEH,+CAA+C;AAClC,QAAA,YAAY,GAAG,IAAA,oBAAU,EAAC,2BAAmB,EAAE,2BAAmB,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AUTH_EVENTS = exports.AUTH_KEYS = void 0;
4
+ /** auth-admin-service events: users, companies, staff, memberships, roles, approvals, security (§7). */
5
+ const shared_lib_1 = require("@heavybit/shared-lib");
6
+ const base_js_1 = require("./base.js");
7
+ /** Routing keys published by auth-admin-service. */
8
+ exports.AUTH_KEYS = {
9
+ user: {
10
+ registered: 'auth.user.registered',
11
+ verified: 'auth.user.verified',
12
+ passwordResetRequested: 'auth.user.password_reset_requested',
13
+ passwordChanged: 'auth.user.password_changed',
14
+ emailChanged: 'auth.user.email_changed',
15
+ deleted: 'auth.user.deleted',
16
+ authzChanged: 'auth.user.authz_changed',
17
+ },
18
+ company: {
19
+ created: 'auth.company.created',
20
+ updated: 'auth.company.updated',
21
+ suspended: 'auth.company.suspended',
22
+ reactivated: 'auth.company.reactivated',
23
+ closed: 'auth.company.closed',
24
+ },
25
+ staff: { invited: 'auth.staff.invited', joined: 'auth.staff.joined', removed: 'auth.staff.removed' },
26
+ membership: { changed: 'auth.membership.changed' },
27
+ role: { changed: 'auth.role.changed' },
28
+ approval: {
29
+ requested: 'auth.approval.requested',
30
+ approved: 'auth.approval.approved',
31
+ rejected: 'auth.approval.rejected',
32
+ expired: 'auth.approval.expired',
33
+ executed: 'auth.approval.executed',
34
+ failed: 'auth.approval.failed',
35
+ },
36
+ };
37
+ /** Approval type, e.g. `refund.large`, `payout.destination.change` (§7.4). */
38
+ const approvalAction = shared_lib_1.z.string().min(1).max(100);
39
+ const k = exports.AUTH_KEYS;
40
+ /** v1 payload schemas of the auth user/company/staff/role/approval events. */
41
+ exports.AUTH_EVENTS = {
42
+ [k.user.registered]: (0, base_js_1.userPayload)({ userId: base_js_1.id }),
43
+ [k.user.verified]: (0, base_js_1.userPayload)({ userId: base_js_1.id, channel: shared_lib_1.z.enum(['email', 'phone']) }),
44
+ [k.user.passwordResetRequested]: (0, base_js_1.userPayload)({ userId: base_js_1.id }),
45
+ [k.user.passwordChanged]: (0, base_js_1.userPayload)({ userId: base_js_1.id }),
46
+ [k.user.emailChanged]: (0, base_js_1.userPayload)({ userId: base_js_1.id }),
47
+ [k.user.deleted]: (0, base_js_1.userPayload)({ userId: base_js_1.id }),
48
+ /** Roles, permissions or memberships changed: drop cached permissions for this user (and company, when given). */
49
+ [k.user.authzChanged]: (0, base_js_1.optionalTenantPayload)({ userId: base_js_1.id }),
50
+ [k.company.created]: (0, base_js_1.tenantPayload)({ ownerUserId: base_js_1.id, slug: shared_lib_1.z.string().max(120), name: shared_lib_1.z.string().max(200) }),
51
+ [k.company.updated]: (0, base_js_1.tenantPayload)({ changedFields: base_js_1.changedFields }),
52
+ [k.company.suspended]: (0, base_js_1.tenantPayload)({ reason: base_js_1.reason }),
53
+ [k.company.reactivated]: (0, base_js_1.tenantPayload)({}),
54
+ [k.company.closed]: (0, base_js_1.tenantPayload)({}),
55
+ [k.staff.invited]: (0, base_js_1.tenantPayload)({ invitationId: base_js_1.id, roleId: base_js_1.id }),
56
+ [k.staff.joined]: (0, base_js_1.tenantPayload)({ userId: base_js_1.id, membershipId: base_js_1.id }),
57
+ [k.staff.removed]: (0, base_js_1.tenantPayload)({ userId: base_js_1.id, membershipId: base_js_1.id }),
58
+ [k.membership.changed]: (0, base_js_1.tenantPayload)({ membershipId: base_js_1.id, userId: base_js_1.id, roleIds: shared_lib_1.z.array(base_js_1.id).max(50) }),
59
+ /** Company roles carry a company; platform roles do not. */
60
+ [k.role.changed]: (0, base_js_1.optionalTenantPayload)({ roleId: base_js_1.id, change: shared_lib_1.z.enum(['created', 'updated', 'deleted', 'permissions_changed']) }),
61
+ [k.approval.requested]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction, requestedBy: base_js_1.id, expiresAt: base_js_1.timestamp }),
62
+ [k.approval.approved]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction, decidedBy: base_js_1.id }),
63
+ [k.approval.rejected]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction, decidedBy: base_js_1.id }),
64
+ [k.approval.expired]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction }),
65
+ [k.approval.executed]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction }),
66
+ [k.approval.failed]: (0, base_js_1.optionalTenantPayload)({ approvalId: base_js_1.id, action: approvalAction, reason: base_js_1.reason }),
67
+ };
68
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/events/auth.ts"],"names":[],"mappings":";;;AAAA,wGAAwG;AACxG,qDAAyC;AACzC,uCAAoH;AAEpH,oDAAoD;AACvC,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE;QACJ,UAAU,EAAE,sBAAsB;QAClC,QAAQ,EAAE,oBAAoB;QAC9B,sBAAsB,EAAE,oCAAoC;QAC5D,eAAe,EAAE,4BAA4B;QAC7C,YAAY,EAAE,yBAAyB;QACvC,OAAO,EAAE,mBAAmB;QAC5B,YAAY,EAAE,yBAAyB;KACxC;IACD,OAAO,EAAE;QACP,OAAO,EAAE,sBAAsB;QAC/B,OAAO,EAAE,sBAAsB;QAC/B,SAAS,EAAE,wBAAwB;QACnC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAA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A,+BAAqB,EAAC,EAAE,UAAU,EAAE,YAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACxF,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAA,+BAAqB,EAAC,EAAE,UAAU,EAAE,YAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAN,gBAAM,EAAE,CAAC;CACtF,CAAC"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVENT_PUBLISHERS = exports.eventMetaShape = exports.facts = exports.changedFields = exports.reason = exports.timestamp = exports.currency = exports.amount = exports.id = exports.EVENT_VERSION = void 0;
4
+ exports.tenantPayload = tenantPayload;
5
+ exports.optionalTenantPayload = optionalTenantPayload;
6
+ exports.userPayload = userPayload;
7
+ exports.withEventMeta = withEventMeta;
8
+ exports.perPublisher = perPublisher;
9
+ exports.forEachKey = forEachKey;
10
+ /**
11
+ * Building blocks for v1 event payload schemas.
12
+ *
13
+ * A payload schema describes the envelope `data` **without** the reserved fields (`eventId`, `version`,
14
+ * `actorUserId`), because shared-lib's `enqueueOutbox` adds them and `MessageConsumer` strips them before
15
+ * validating. {@link withEventMeta} adds them back for checks of a complete `data` object.
16
+ *
17
+ * Every payload is `.passthrough()` (MSG-3): a consumer on an older version keeps fields it does not know.
18
+ * Payloads carry ids and small facts only — never an email, phone or address when a user id will do.
19
+ */
20
+ const shared_lib_1 = require("@heavybit/shared-lib");
21
+ const app_js_1 = require("../app.js");
22
+ /** Payload schema version for every event in this catalogue. */
23
+ exports.EVENT_VERSION = 1;
24
+ /** Canonical ULID (D7). */
25
+ exports.id = shared_lib_1.idSchema;
26
+ /** Money amount as a decimal string with exactly 2 dp, as `DECIMAL(12,2)` stores it (D5), e.g. `"1250.00"`. */
27
+ exports.amount = shared_lib_1.z.string().regex(/^-?\d{1,10}\.\d{2}$/, 'Use a decimal string with 2 decimal places');
28
+ /** The currency code that travels with every amount. */
29
+ exports.currency = shared_lib_1.z.literal(app_js_1.CURRENCY);
30
+ /** ISO-8601 timestamp with an offset (`toISOString()` output). */
31
+ exports.timestamp = shared_lib_1.z.string().datetime({ offset: true });
32
+ /** Short machine reason, e.g. `insufficient_funds`. */
33
+ exports.reason = shared_lib_1.z.string().min(1).max(100);
34
+ /** Names of the fields that changed (never their values). */
35
+ exports.changedFields = shared_lib_1.z.array(shared_lib_1.z.string().max(64)).max(50);
36
+ /** Small string-to-scalar map for facts that do not deserve their own field (never secrets or PII). */
37
+ exports.facts = shared_lib_1.z.record(shared_lib_1.z.string().max(64), shared_lib_1.z.union([shared_lib_1.z.string().max(500), shared_lib_1.z.number(), shared_lib_1.z.boolean(), shared_lib_1.z.null()]));
38
+ /**
39
+ * Payload of an event about one company's data: `companyId` is required (TEN-7).
40
+ *
41
+ * @example tenantPayload({ orderId: id })
42
+ */
43
+ function tenantPayload(shape) {
44
+ return shared_lib_1.z.object({ companyId: exports.id, ...shape }).passthrough();
45
+ }
46
+ /**
47
+ * Payload of an event that may or may not concern a company (e.g. a platform-level approval or a
48
+ * security event before a company is chosen): `companyId` is a ULID or null.
49
+ *
50
+ * @example optionalTenantPayload({ approvalId: id })
51
+ */
52
+ function optionalTenantPayload(shape) {
53
+ return shared_lib_1.z.object({ companyId: exports.id.nullable().optional(), ...shape }).passthrough();
54
+ }
55
+ /**
56
+ * Payload of an event about a user account, not a company (e.g. `auth.user.registered`).
57
+ *
58
+ * @example userPayload({ userId: id })
59
+ */
60
+ function userPayload(shape) {
61
+ return shared_lib_1.z.object(shape).passthrough();
62
+ }
63
+ /** The reserved envelope fields as validated in a complete `data` object. */
64
+ exports.eventMetaShape = {
65
+ eventId: exports.id,
66
+ version: shared_lib_1.z.literal(exports.EVENT_VERSION),
67
+ /** The acting user; `null` for the system. Producers in this app always pass it. */
68
+ actorUserId: exports.id.nullable(),
69
+ };
70
+ /**
71
+ * Adds the reserved envelope fields to a payload schema, for validating a complete envelope `data`.
72
+ *
73
+ * @example withEventMeta(schema).parse(envelope.data)
74
+ */
75
+ function withEventMeta(schema) {
76
+ return schema.and(shared_lib_1.z.object(exports.eventMetaShape));
77
+ }
78
+ /**
79
+ * Services that publish the per-publisher families `{publisher}.audit.recorded` and
80
+ * `{publisher}.security.socket_rejected` (the first routing-key segment of each service).
81
+ */
82
+ exports.EVENT_PUBLISHERS = ['auth', 'gateway', 'store', 'catalog', 'media', 'cart', 'order', 'payment', 'shipping', 'notification', 'reporting'];
83
+ /**
84
+ * Builds one routing key per publisher for a per-publisher family, e.g. `order.audit.recorded`.
85
+ *
86
+ * @example perPublisher('audit.recorded').order === 'order.audit.recorded'
87
+ */
88
+ function perPublisher(suffix) {
89
+ return Object.freeze(Object.fromEntries(exports.EVENT_PUBLISHERS.map((p) => [p, `${p}.${suffix}`])));
90
+ }
91
+ /**
92
+ * The same schema under every key of a per-publisher family.
93
+ *
94
+ * @example forEachKey(AUDIT_RECORDED_KEYS, auditRecordedSchema)
95
+ */
96
+ function forEachKey(keys, schema) {
97
+ return Object.fromEntries(Object.values(keys).map((key) => [key, schema]));
98
+ }
99
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/events/base.ts"],"names":[],"mappings":";;;AA0CA,sCAEC;AAQD,sDAEC;AAOD,kCAEC;AAeD,sCAEC;AAgBD,oCAEC;AAOD,gCAEC;AA3GD;;;;;;;;;GASG;AACH,qDAAmD;AACnD,sCAAqC;AAErC,gEAAgE;AACnD,QAAA,aAAa,GAAG,CAAU,CAAC;AAExC,2BAA2B;AACd,QAAA,EAAE,GAAG,qBAAQ,CAAC;AAE3B,+GAA+G;AAClG,QAAA,MAAM,GAAG,cAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,EAAE,4CAA4C,CAAC,CAAC;AAE5G,wDAAwD;AAC3C,QAAA,QAAQ,GAAG,cAAC,CAAC,OAAO,CAAC,iBAAQ,CAAC,CAAC;AAE5C,k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EAAE,CAAC;AACvC,CAAC;AAED,6EAA6E;AAChE,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,UAAE;IACX,OAAO,EAAE,cAAC,CAAC,OAAO,CAAC,qBAAa,CAAC;IACjC,oFAAoF;IACpF,WAAW,EAAE,UAAE,CAAC,QAAQ,EAAE;CAC3B,CAAC;AAEF;;;;GAIG;AACH,SAAgB,aAAa,CAAyB,MAAS;IAC7D,OAAO,MAAM,CAAC,GAAG,CAAC,cAAC,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACU,QAAA,gBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,CAAU,CAAC;AAK/J;;;;GAIG;AACH,SAAgB,YAAY,CAAyB,MAAS;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,wBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,CAAoD,CAAC;AAClJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAsB,IAA2C,EAAE,MAAS;IACpG,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAiB,CAAC;AAChG,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CART_EVENTS = exports.CART_KEYS = void 0;
4
+ /** cart-service events. */
5
+ const shared_lib_1 = require("@heavybit/shared-lib");
6
+ const base_js_1 = require("./base.js");
7
+ /** Routing keys published by cart-service. */
8
+ exports.CART_KEYS = {
9
+ cart: { updated: 'cart.cart.updated' },
10
+ };
11
+ /** v1 payload schemas of the cart events. `userId` is null for a guest cart. */
12
+ exports.CART_EVENTS = {
13
+ [exports.CART_KEYS.cart.updated]: (0, base_js_1.tenantPayload)({ cartId: base_js_1.id, userId: base_js_1.id.nullable(), itemCount: shared_lib_1.z.number().int().min(0), subtotal: base_js_1.amount, currency: base_js_1.currency }),
14
+ };
15
+ //# sourceMappingURL=cart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart.js","sourceRoot":"","sources":["../../../src/events/cart.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,qDAAyC;AACzC,uCAAgE;AAEhE,8CAA8C;AACjC,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,EAAE,OAAO,EAAE,mBAAmB,EAAE;CAC9B,CAAC;AAEX,gFAAgF;AACnE,QAAA,WAAW,GAAG;IACzB,CAAC,iBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,MAAM,EAAE,YAAE,EAAE,MAAM,EAAE,YAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAM,EAAE,QAAQ,EAAR,kBAAQ,EAAE,CAAC;CACtI,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CATALOG_EVENTS = exports.CATALOG_KEYS = void 0;
4
+ /** catalog-service events: products, categories, inventory. */
5
+ const shared_lib_1 = require("@heavybit/shared-lib");
6
+ const base_js_1 = require("./base.js");
7
+ /** Routing keys published by catalog-service. */
8
+ exports.CATALOG_KEYS = {
9
+ product: { created: 'catalog.product.created', updated: 'catalog.product.updated', deleted: 'catalog.product.deleted' },
10
+ category: { updated: 'catalog.category.updated' },
11
+ inventory: { adjusted: 'catalog.inventory.adjusted', lowStock: 'catalog.inventory.low_stock' },
12
+ };
13
+ const quantity = shared_lib_1.z.number().int();
14
+ const k = exports.CATALOG_KEYS;
15
+ /** v1 payload schemas of the catalog events. */
16
+ exports.CATALOG_EVENTS = {
17
+ [k.product.created]: (0, base_js_1.tenantPayload)({ productId: base_js_1.id, status: shared_lib_1.z.string().max(32) }),
18
+ [k.product.updated]: (0, base_js_1.tenantPayload)({ productId: base_js_1.id, changedFields: base_js_1.changedFields }),
19
+ [k.product.deleted]: (0, base_js_1.tenantPayload)({ productId: base_js_1.id }),
20
+ [k.category.updated]: (0, base_js_1.tenantPayload)({ categoryId: base_js_1.id }),
21
+ [k.inventory.adjusted]: (0, base_js_1.tenantPayload)({ productId: base_js_1.id, variantId: base_js_1.id.nullable(), delta: quantity, onHand: quantity, reason: base_js_1.reason }),
22
+ [k.inventory.lowStock]: (0, base_js_1.tenantPayload)({ productId: base_js_1.id, variantId: base_js_1.id.nullable(), onHand: quantity, threshold: quantity }),
23
+ };
24
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/events/catalog.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAC/D,qDAAyC;AACzC,uCAAqE;AAErE,iDAAiD;AACpC,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,yBAAyB,EAAE;IACvH,QAAQ,EAAE,EAAE,OAAO,EAAE,0BAA0B,EAAE;IACjD,SAAS,EAAE,EAAE,QAAQ,EAAE,4BAA4B,EAAE,QAAQ,EAAE,6BAA6B,EAAE;CACtF,CAAC;AAEX,MAAM,QAAQ,GAAG,cAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,GAAG,oBAAY,CAAC;AAEvB,gDAAgD;AACnC,QAAA,cAAc,GAAG;IAC5B,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,SAAS,EAAE,YAAE,EAAE,MAAM,EAAE,cAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;IACjF,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,SAAS,EAAE,YAAE,EAAE,aAAa,EAAb,uBAAa,EAAE,CAAC;IACpE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,SAAS,EAAE,YAAE,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,UAAU,EAAE,YAAE,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,SAAS,EAAE,YAAE,EAAE,SAAS,EAAE,YAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAN,gBAAM,EAAE,CAAC;IAC7H,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAA,uBAAa,EAAC,EAAE,SAAS,EAAE,YAAE,EAAE,SAAS,EAAE,YAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;CACjH,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GATEWAY_EVENTS = exports.GATEWAY_KEYS = void 0;
4
+ /** api-gateway security events (rejected requests). Route and method only — no headers, bodies or IPs. */
5
+ const shared_lib_1 = require("@heavybit/shared-lib");
6
+ const base_js_1 = require("./base.js");
7
+ /** Routing keys published by api-gateway. */
8
+ exports.GATEWAY_KEYS = {
9
+ security: {
10
+ accessDenied: 'gateway.security.access_denied',
11
+ rateLimited: 'gateway.security.rate_limited',
12
+ badSignature: 'gateway.security.bad_signature',
13
+ },
14
+ };
15
+ const route = shared_lib_1.z.string().max(200);
16
+ const method = shared_lib_1.z.string().max(10);
17
+ const k = exports.GATEWAY_KEYS.security;
18
+ /** v1 payload schemas of the gateway events. */
19
+ exports.GATEWAY_EVENTS = {
20
+ [k.accessDenied]: (0, base_js_1.optionalTenantPayload)({ userId: base_js_1.id.nullable(), route, method, code: shared_lib_1.z.string().max(64) }),
21
+ [k.rateLimited]: (0, base_js_1.optionalTenantPayload)({ userId: base_js_1.id.nullable(), route, method, limiter: shared_lib_1.z.string().max(64) }),
22
+ [k.badSignature]: (0, base_js_1.optionalTenantPayload)({ route, method, reason: base_js_1.reason }),
23
+ };
24
+ //# sourceMappingURL=gateway.js.map