@heavybit/ecommerce-contracts 0.0.0-stage → 0.2.1
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 +158 -2
- package/dist/cjs/app.js +38 -0
- package/dist/cjs/app.js.map +1 -0
- package/dist/cjs/bindings.js +127 -0
- package/dist/cjs/bindings.js.map +1 -0
- package/dist/cjs/events/audit.js +26 -0
- package/dist/cjs/events/audit.js.map +1 -0
- package/dist/cjs/events/auth.js +68 -0
- package/dist/cjs/events/auth.js.map +1 -0
- package/dist/cjs/events/base.js +99 -0
- package/dist/cjs/events/base.js.map +1 -0
- package/dist/cjs/events/cart.js +15 -0
- package/dist/cjs/events/cart.js.map +1 -0
- package/dist/cjs/events/catalog.js +24 -0
- package/dist/cjs/events/catalog.js.map +1 -0
- package/dist/cjs/events/gateway.js +24 -0
- package/dist/cjs/events/gateway.js.map +1 -0
- package/dist/cjs/events/index.js +131 -0
- package/dist/cjs/events/index.js.map +1 -0
- package/dist/cjs/events/media.js +17 -0
- package/dist/cjs/events/media.js.map +1 -0
- package/dist/cjs/events/notification.js +43 -0
- package/dist/cjs/events/notification.js.map +1 -0
- package/dist/cjs/events/order.js +45 -0
- package/dist/cjs/events/order.js.map +1 -0
- package/dist/cjs/events/payment.js +34 -0
- package/dist/cjs/events/payment.js.map +1 -0
- package/dist/cjs/events/security.js +36 -0
- package/dist/cjs/events/security.js.map +1 -0
- package/dist/cjs/events/shipping.js +25 -0
- package/dist/cjs/events/shipping.js.map +1 -0
- package/dist/cjs/events/store.js +25 -0
- package/dist/cjs/events/store.js.map +1 -0
- package/dist/cjs/events/usage.js +17 -0
- package/dist/cjs/events/usage.js.map +1 -0
- package/dist/cjs/identity.js +50 -0
- package/dist/cjs/identity.js.map +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/permissions.js +10 -0
- package/dist/cjs/permissions.js.map +1 -0
- package/dist/cjs/scopes.js +57 -0
- package/dist/cjs/scopes.js.map +1 -0
- package/dist/esm/app.js +35 -0
- package/dist/esm/app.js.map +1 -0
- package/dist/esm/bindings.js +115 -0
- package/dist/esm/bindings.js.map +1 -0
- package/dist/esm/events/audit.js +23 -0
- package/dist/esm/events/audit.js.map +1 -0
- package/dist/esm/events/auth.js +65 -0
- package/dist/esm/events/auth.js.map +1 -0
- package/dist/esm/events/base.js +90 -0
- package/dist/esm/events/base.js.map +1 -0
- package/dist/esm/events/cart.js +12 -0
- package/dist/esm/events/cart.js.map +1 -0
- package/dist/esm/events/catalog.js +21 -0
- package/dist/esm/events/catalog.js.map +1 -0
- package/dist/esm/events/gateway.js +21 -0
- package/dist/esm/events/gateway.js.map +1 -0
- package/dist/esm/events/index.js +100 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/events/media.js +14 -0
- package/dist/esm/events/media.js.map +1 -0
- package/dist/esm/events/notification.js +40 -0
- package/dist/esm/events/notification.js.map +1 -0
- package/dist/esm/events/order.js +42 -0
- package/dist/esm/events/order.js.map +1 -0
- package/dist/esm/events/payment.js +31 -0
- package/dist/esm/events/payment.js.map +1 -0
- package/dist/esm/events/security.js +33 -0
- package/dist/esm/events/security.js.map +1 -0
- package/dist/esm/events/shipping.js +22 -0
- package/dist/esm/events/shipping.js.map +1 -0
- package/dist/esm/events/store.js +22 -0
- package/dist/esm/events/store.js.map +1 -0
- package/dist/esm/events/usage.js +14 -0
- package/dist/esm/events/usage.js.map +1 -0
- package/dist/esm/identity.js +47 -0
- package/dist/esm/identity.js.map +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/permissions.js +7 -0
- package/dist/esm/permissions.js.map +1 -0
- package/dist/esm/scopes.js +52 -0
- package/dist/esm/scopes.js.map +1 -0
- package/dist/types/app.d.ts +40 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/bindings.d.ts +88 -0
- package/dist/types/bindings.d.ts.map +1 -0
- package/dist/types/events/audit.d.ts +86 -0
- package/dist/types/events/audit.d.ts.map +1 -0
- package/dist/types/events/auth.d.ts +357 -0
- package/dist/types/events/auth.d.ts.map +1 -0
- package/dist/types/events/base.d.ts +108 -0
- package/dist/types/events/base.d.ts.map +1 -0
- package/dist/types/events/cart.d.ts +37 -0
- package/dist/types/events/cart.d.ts.map +1 -0
- package/dist/types/events/catalog.d.ts +126 -0
- package/dist/types/events/catalog.d.ts.map +1 -0
- package/dist/types/events/gateway.d.ts +77 -0
- package/dist/types/events/gateway.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +4333 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/events/media.d.ts +51 -0
- package/dist/types/events/media.d.ts.map +1 -0
- package/dist/types/events/notification.d.ts +270 -0
- package/dist/types/events/notification.d.ts.map +1 -0
- package/dist/types/events/order.d.ts +289 -0
- package/dist/types/events/order.d.ts.map +1 -0
- package/dist/types/events/payment.d.ts +228 -0
- package/dist/types/events/payment.d.ts.map +1 -0
- package/dist/types/events/security.d.ts +201 -0
- package/dist/types/events/security.d.ts.map +1 -0
- package/dist/types/events/shipping.d.ts +91 -0
- package/dist/types/events/shipping.d.ts.map +1 -0
- package/dist/types/events/store.d.ts +134 -0
- package/dist/types/events/store.d.ts.map +1 -0
- package/dist/types/events/usage.d.ts +59 -0
- package/dist/types/events/usage.d.ts.map +1 -0
- package/dist/types/identity.d.ts +22 -0
- package/dist/types/identity.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/permissions.d.ts +7 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/scopes.d.ts +57 -0
- package/dist/types/scopes.d.ts.map +1 -0
- package/package.json +44 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** order-service events: orders and order issues. Customer contact details are never in payloads. */
|
|
2
|
+
import { z } from '@heavybit/shared-lib';
|
|
3
|
+
import { amount, currency, id, reason, tenantPayload, timestamp } from './base.js';
|
|
4
|
+
/** Routing keys published by order-service. */
|
|
5
|
+
export const ORDER_KEYS = {
|
|
6
|
+
order: {
|
|
7
|
+
created: 'order.order.created',
|
|
8
|
+
paid: 'order.order.paid',
|
|
9
|
+
statusChanged: 'order.order.status_changed',
|
|
10
|
+
shipped: 'order.order.shipped',
|
|
11
|
+
delivered: 'order.order.delivered',
|
|
12
|
+
cancelled: 'order.order.cancelled',
|
|
13
|
+
expired: 'order.order.expired',
|
|
14
|
+
refundRequested: 'order.order.refund_requested',
|
|
15
|
+
},
|
|
16
|
+
issue: {
|
|
17
|
+
opened: 'order.issue.opened',
|
|
18
|
+
replied: 'order.issue.replied',
|
|
19
|
+
escalated: 'order.issue.escalated',
|
|
20
|
+
resolved: 'order.issue.resolved',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const orderNumber = z.string().min(1).max(32);
|
|
24
|
+
const status = z.string().min(1).max(32);
|
|
25
|
+
const orderRef = { orderId: id, orderNumber };
|
|
26
|
+
const k = ORDER_KEYS;
|
|
27
|
+
/** v1 payload schemas of the order events. */
|
|
28
|
+
export const ORDER_EVENTS = {
|
|
29
|
+
[k.order.created]: tenantPayload({ ...orderRef, userId: id, grandTotal: amount, currency }),
|
|
30
|
+
[k.order.paid]: tenantPayload({ ...orderRef, userId: id, grandTotal: amount, currency, paidAt: timestamp }),
|
|
31
|
+
[k.order.statusChanged]: tenantPayload({ ...orderRef, from: status, to: status }),
|
|
32
|
+
[k.order.shipped]: tenantPayload({ ...orderRef, userId: id, shipmentId: id }),
|
|
33
|
+
[k.order.delivered]: tenantPayload({ ...orderRef, userId: id, deliveredAt: timestamp }),
|
|
34
|
+
[k.order.cancelled]: tenantPayload({ ...orderRef, userId: id, reason }),
|
|
35
|
+
[k.order.expired]: tenantPayload({ ...orderRef, userId: id }),
|
|
36
|
+
[k.order.refundRequested]: tenantPayload({ ...orderRef, refundId: id, amount, currency, reason }),
|
|
37
|
+
[k.issue.opened]: tenantPayload({ issueId: id, orderId: id, userId: id, type: z.string().max(64) }),
|
|
38
|
+
[k.issue.replied]: tenantPayload({ issueId: id, orderId: id, from: z.enum(['customer', 'staff']) }),
|
|
39
|
+
[k.issue.escalated]: tenantPayload({ issueId: id, orderId: id }),
|
|
40
|
+
[k.issue.resolved]: tenantPayload({ issueId: id, orderId: id, resolution: z.string().max(64) }),
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/events/order.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnF,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE;QACL,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE,kBAAkB;QACxB,aAAa,EAAE,4BAA4B;QAC3C,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,uBAAuB;QAClC,SAAS,EAAE,uBAAuB;QAClC,OAAO,EAAE,qBAAqB;QAC9B,eAAe,EAAE,8BAA8B;KAChD;IACD,KAAK,EAAE;QACL,MAAM,EAAE,oBAAoB;QAC5B,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,uBAAuB;QAClC,QAAQ,EAAE,sBAAsB;KACjC;CACO,CAAC;AAEX,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,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KAAK,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACjG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;IACnG,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IACnG,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAChE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;CACvF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** payment-service events: M-Pesa payments, refunds and payouts. */
|
|
2
|
+
import { z } from '@heavybit/shared-lib';
|
|
3
|
+
import { amount, currency, id, reason, tenantPayload, timestamp } from './base.js';
|
|
4
|
+
/** Routing keys published by payment-service. */
|
|
5
|
+
export const PAYMENT_KEYS = {
|
|
6
|
+
payment: {
|
|
7
|
+
initiated: 'payment.payment.initiated',
|
|
8
|
+
succeeded: 'payment.payment.succeeded',
|
|
9
|
+
failed: 'payment.payment.failed',
|
|
10
|
+
expired: 'payment.payment.expired',
|
|
11
|
+
},
|
|
12
|
+
refund: { completed: 'payment.refund.completed', failed: 'payment.refund.failed' },
|
|
13
|
+
payout: { scheduled: 'payment.payout.scheduled', paid: 'payment.payout.paid', failed: 'payment.payout.failed' },
|
|
14
|
+
};
|
|
15
|
+
/** Provider receipt or transaction reference (e.g. an M-Pesa receipt number). */
|
|
16
|
+
const providerRef = z.string().min(1).max(64);
|
|
17
|
+
const money = { amount, currency };
|
|
18
|
+
const k = PAYMENT_KEYS;
|
|
19
|
+
/** v1 payload schemas of the payment events. */
|
|
20
|
+
export const PAYMENT_EVENTS = {
|
|
21
|
+
[k.payment.initiated]: tenantPayload({ paymentId: id, orderId: id, ...money, method: z.string().max(32) }),
|
|
22
|
+
[k.payment.succeeded]: tenantPayload({ paymentId: id, orderId: id, ...money, providerRef, paidAt: timestamp }),
|
|
23
|
+
[k.payment.failed]: tenantPayload({ paymentId: id, orderId: id, reason }),
|
|
24
|
+
[k.payment.expired]: tenantPayload({ paymentId: id, orderId: id }),
|
|
25
|
+
[k.refund.completed]: tenantPayload({ refundId: id, orderId: id, paymentId: id, ...money, completedAt: timestamp }),
|
|
26
|
+
[k.refund.failed]: tenantPayload({ refundId: id, orderId: id, reason }),
|
|
27
|
+
[k.payout.scheduled]: tenantPayload({ payoutId: id, ...money, scheduledFor: timestamp }),
|
|
28
|
+
[k.payout.paid]: tenantPayload({ payoutId: id, ...money, providerRef, paidAt: timestamp }),
|
|
29
|
+
[k.payout.failed]: tenantPayload({ payoutId: id, ...money, reason }),
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/events/payment.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EA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AAE,MAAM,EAAE,CAAC;IACzE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;IACnH,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IACvE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IACxF,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC1F,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,CAAC;CAC5D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** auth-admin-service security events (§6, security events feed and alerts). No IPs, emails or tokens. */
|
|
2
|
+
import { z } from '@heavybit/shared-lib';
|
|
3
|
+
import { id, optionalTenantPayload, reason, timestamp } from './base.js';
|
|
4
|
+
/** Routing keys of `auth.security.*`. */
|
|
5
|
+
export const SECURITY_KEYS = {
|
|
6
|
+
loginSucceeded: 'auth.security.login_succeeded',
|
|
7
|
+
loginFailed: 'auth.security.login_failed',
|
|
8
|
+
otpFailed: 'auth.security.otp_failed',
|
|
9
|
+
stepUp: 'auth.security.step_up',
|
|
10
|
+
accountLocked: 'auth.security.account_locked',
|
|
11
|
+
sessionsRevoked: 'auth.security.sessions_revoked',
|
|
12
|
+
roleChanged: 'auth.security.role_changed',
|
|
13
|
+
loginRisky: 'auth.security.login_risky',
|
|
14
|
+
loginUnrecognized: 'auth.security.login_unrecognized',
|
|
15
|
+
alertRaised: 'auth.security.alert_raised',
|
|
16
|
+
};
|
|
17
|
+
const k = SECURITY_KEYS;
|
|
18
|
+
const loginMethod = z.enum(['password', 'otp', 'sso']);
|
|
19
|
+
/** v1 payload schemas of the security events. `companyId` is set when a company was active. */
|
|
20
|
+
export const SECURITY_EVENTS = {
|
|
21
|
+
[k.loginSucceeded]: optionalTenantPayload({ userId: id, sessionId: id, method: loginMethod }),
|
|
22
|
+
/** `userId` is null when the account does not exist (no enumeration of identifiers in payloads). */
|
|
23
|
+
[k.loginFailed]: optionalTenantPayload({ userId: id.nullable(), reason }),
|
|
24
|
+
[k.otpFailed]: optionalTenantPayload({ userId: id, purpose: z.string().max(64) }),
|
|
25
|
+
[k.stepUp]: optionalTenantPayload({ userId: id, sessionId: id, scope: z.string().max(64) }),
|
|
26
|
+
[k.accountLocked]: optionalTenantPayload({ userId: id, lockedUntil: timestamp, reason }),
|
|
27
|
+
[k.sessionsRevoked]: optionalTenantPayload({ userId: id, count: z.number().int().min(0), reason }),
|
|
28
|
+
[k.roleChanged]: optionalTenantPayload({ userId: id, roleId: id, change: z.enum(['assigned', 'revoked']) }),
|
|
29
|
+
[k.loginRisky]: optionalTenantPayload({ userId: id, sessionId: id.nullable(), signals: z.array(z.string().max(64)).max(20) }),
|
|
30
|
+
[k.loginUnrecognized]: optionalTenantPayload({ userId: id, sessionId: id }),
|
|
31
|
+
[k.alertRaised]: optionalTenantPayload({ userId: id.nullable(), alert: z.string().max(100), severity: z.enum(['low', 'medium', 'high', 'critical']) }),
|
|
32
|
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E,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;CAC9I,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** shipping-service events. Shipment addresses stay in shipping-service (snapshot, MS-3). */
|
|
2
|
+
import { z } from '@heavybit/shared-lib';
|
|
3
|
+
import { id, reason, tenantPayload, timestamp } from './base.js';
|
|
4
|
+
/** Routing keys published by shipping-service. */
|
|
5
|
+
export const SHIPPING_KEYS = {
|
|
6
|
+
shipment: {
|
|
7
|
+
created: 'shipping.shipment.created',
|
|
8
|
+
dispatched: 'shipping.shipment.dispatched',
|
|
9
|
+
delivered: 'shipping.shipment.delivered',
|
|
10
|
+
failed: 'shipping.shipment.failed',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const k = SHIPPING_KEYS.shipment;
|
|
14
|
+
const ref = { shipmentId: id, orderId: id };
|
|
15
|
+
/** v1 payload schemas of the shipping events. */
|
|
16
|
+
export const SHIPPING_EVENTS = {
|
|
17
|
+
[k.created]: tenantPayload({ ...ref, method: z.string().max(64) }),
|
|
18
|
+
[k.dispatched]: tenantPayload({ ...ref, trackingNumber: z.string().max(100).nullable() }),
|
|
19
|
+
[k.delivered]: tenantPayload({ ...ref, deliveredAt: timestamp }),
|
|
20
|
+
[k.failed]: tenantPayload({ ...ref, reason }),
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=shipping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shipping.js","sourceRoot":"","sources":["../../../src/events/shipping.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,kDAAkD;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE;QACR,OAAO,EAAE,2BAA2B;QACpC,UAAU,EAAE,8BAA8B;QAC1C,SAAS,EAAE,6BAA6B;QACxC,MAAM,EAAE,0BAA0B;KACnC;CACO,CAAC;AAEX,MAAM,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC;AACjC,MAAM,GAAG,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAE5C,iDAAiD;AACjD,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IACzF,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;IAChE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** store-service events: shop provisioning, settings, theme and domains. */
|
|
2
|
+
import { z } from '@heavybit/shared-lib';
|
|
3
|
+
import { changedFields, id, reason, tenantPayload } from './base.js';
|
|
4
|
+
/** Routing keys published by store-service. */
|
|
5
|
+
export const STORE_KEYS = {
|
|
6
|
+
shop: { provisioned: 'store.shop.provisioned' },
|
|
7
|
+
settings: { changed: 'store.settings.changed' },
|
|
8
|
+
theme: { published: 'store.theme.published' },
|
|
9
|
+
domain: { changed: 'store.domain.changed', verified: 'store.domain.verified', failed: 'store.domain.failed' },
|
|
10
|
+
};
|
|
11
|
+
const hostname = z.string().max(253);
|
|
12
|
+
const k = STORE_KEYS;
|
|
13
|
+
/** v1 payload schemas of the store events. */
|
|
14
|
+
export const STORE_EVENTS = {
|
|
15
|
+
[k.shop.provisioned]: tenantPayload({ shopId: id, slug: z.string().max(120) }),
|
|
16
|
+
[k.settings.changed]: tenantPayload({ shopId: id, changedFields }),
|
|
17
|
+
[k.theme.published]: tenantPayload({ shopId: id, themeId: id, revision: z.number().int().min(1) }),
|
|
18
|
+
[k.domain.changed]: tenantPayload({ shopId: id, domainId: id, hostname }),
|
|
19
|
+
[k.domain.verified]: tenantPayload({ shopId: id, domainId: id, hostname }),
|
|
20
|
+
[k.domain.failed]: tenantPayload({ shopId: id, domainId: id, hostname, reason }),
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/events/store.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAErE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,EAAE,WAAW,EAAE,wBAAwB,EAAE;IAC/C,QAAQ,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;IAC/C,KAAK,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE;IAC7C,MAAM,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,EAAE,qBAAqB,EAAE;CACrG,CAAC;AAEX,MAAM,QAAQ,GAAG,C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import { amount, currency, id, tenantPayload } from './base.js';
|
|
4
|
+
/** Usage routing keys (published by notification-service and shipping-service). */
|
|
5
|
+
export const USAGE_KEYS = {
|
|
6
|
+
sms: { sent: 'usage.sms.sent' },
|
|
7
|
+
delivery: { booked: 'usage.delivery.booked' },
|
|
8
|
+
};
|
|
9
|
+
/** v1 payload schemas of the usage events. */
|
|
10
|
+
export const USAGE_EVENTS = {
|
|
11
|
+
[USAGE_KEYS.sms.sent]: tenantPayload({ messageId: id, segments: z.number().int().min(1), cost: amount, currency }),
|
|
12
|
+
[USAGE_KEYS.delivery.booked]: tenantPayload({ shipmentId: id, provider: z.string().max(64), fee: amount, currency }),
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/events/usage.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEhE,mFAAmF;AACnF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAC/B,QAAQ,EAAE,EAAE,MAAM,EAAE,uBAAuB,EAAE;CACrC,CAAC;AAEX,8CAA8C;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAClH,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;CAC5G,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E-commerce bindings of the shared-lib gateway identity protocol and step-up catalogue (deferred here
|
|
3
|
+
* from Prompt 1.3). The gateway signs with {@link ecommerceIdentityProtocol}; services verify with it.
|
|
4
|
+
*/
|
|
5
|
+
import { defineIdentityProtocol, defineStepUpScopes } from '@heavybit/shared-lib';
|
|
6
|
+
import { COMPANY_SCOPE_KEY } from './scopes.js';
|
|
7
|
+
/** Domain separator mixed into every gateway identity signature of this app. */
|
|
8
|
+
export const GATEWAY_IDENTITY_DOMAIN = 'ecommerce-gateway-identity:v2';
|
|
9
|
+
/** Header carrying the active company id (signed). Maps to `AuthUser.scopes.company`. */
|
|
10
|
+
export const COMPANY_ID_HEADER = 'x-company-id';
|
|
11
|
+
/** Header carrying the active company slug (signed). Maps to `AuthUser.attrs.companySlug`. */
|
|
12
|
+
export const COMPANY_SLUG_HEADER = 'x-company-slug';
|
|
13
|
+
/**
|
|
14
|
+
* The app's identity protocol: generic identity headers plus the signed company headers.
|
|
15
|
+
*
|
|
16
|
+
* @example app.use(authenticateFromGateway({ protocol: ecommerceIdentityProtocol, secret: config.GATEWAY_SIGNING_SECRET }))
|
|
17
|
+
*/
|
|
18
|
+
export const ecommerceIdentityProtocol = defineIdentityProtocol({
|
|
19
|
+
domain: GATEWAY_IDENTITY_DOMAIN,
|
|
20
|
+
scopeHeaders: { [COMPANY_SCOPE_KEY]: COMPANY_ID_HEADER },
|
|
21
|
+
attrHeaders: { companySlug: COMPANY_SLUG_HEADER },
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Step-up scopes (§6.4). `singleUse` proofs are consumed by the gateway on first use. Each sensitive
|
|
25
|
+
* route declares one of these, and the gateway route map must declare the same.
|
|
26
|
+
*
|
|
27
|
+
* @example router.post('/payouts/destination', requireStepUp('payout-destination'), controller.update)
|
|
28
|
+
*/
|
|
29
|
+
export const ecommerceStepUpScopes = defineStepUpScopes({
|
|
30
|
+
'role-assign': { singleUse: true, description: 'Assign or revoke a role' },
|
|
31
|
+
'role-permissions': { description: 'Change the permissions of a role' },
|
|
32
|
+
'staff-remove': { description: 'Remove a staff member' },
|
|
33
|
+
'payment-config': { singleUse: true, description: 'Change payment (M-Pesa) settings' },
|
|
34
|
+
'payout-destination': { singleUse: true, description: 'Change where payouts are sent' },
|
|
35
|
+
'refund-large': { description: 'Refund above the large-refund threshold' },
|
|
36
|
+
'customer-export': { description: 'Export customer data' },
|
|
37
|
+
'domain-change': { singleUse: true, description: 'Change a shop domain' },
|
|
38
|
+
'company-close': { singleUse: true, description: 'Close a company' },
|
|
39
|
+
'api-key-issue': { singleUse: true, description: 'Issue an API key' },
|
|
40
|
+
'approval-decide': { description: 'Approve or reject a two-person approval' },
|
|
41
|
+
'company-status': { description: 'Suspend or reactivate a company (platform)' },
|
|
42
|
+
'ledger-adjust': { singleUse: true, description: 'Post a manual ledger adjustment (platform)' },
|
|
43
|
+
'support-access': { description: 'Open support access to a company (platform)' },
|
|
44
|
+
'user-security': { singleUse: true, description: 'Change own password, email or 2FA' },
|
|
45
|
+
'dlq-replay': { description: 'Replay dead-lettered messages (platform)' },
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,gFAAgF;AAChF,MAAM,CAAC,MAAM,uBAAuB,GAAG,+BAAwC,CAAC;AAEhF,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AE,IAAI,EAAE,WAAW,EAAE,4CAA4C,EAAE;IAC/F,gBAAgB,EAAE,EAAE,WAAW,EAAE,6CAA6C,EAAE;IAChF,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,mCAAmC,EAAE;IACtF,YAAY,EAAE,EAAE,WAAW,EAAE,0CAA0C,EAAE;CAC1E,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@heavybit/ecommerce-contracts` (D40): the e-commerce app's settings, identity and scope bindings,
|
|
3
|
+
* step-up scopes and event catalogue, built on `@heavybit/shared-lib`. No business logic.
|
|
4
|
+
*/
|
|
5
|
+
export * from './app.js';
|
|
6
|
+
export * from './scopes.js';
|
|
7
|
+
export * from './identity.js';
|
|
8
|
+
export * from './permissions.js';
|
|
9
|
+
export * from './bindings.js';
|
|
10
|
+
export * from './events/index.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E-commerce permission names (D40). Phases 4 and 6 add the full catalogue here (and seed it in
|
|
3
|
+
* auth-admin-service); services import names from this module instead of writing literals.
|
|
4
|
+
*/
|
|
5
|
+
/** Held by anyone who may approve or reject two-person approval requests (§7.4), on top of the operation's own permission. */
|
|
6
|
+
export const APPROVAL_DECIDE_PERMISSION = 'approval:decide';
|
|
7
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/permissions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8HAA8H;AAC9H,MAAM,CAAC,MAAM,0BAA0B,GAAG,iBAA0B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineScope, definePlatformScope, OwnerScope } from '@heavybit/shared-lib/database';
|
|
2
|
+
/** Database column that carries the tenant on every company-owned table. */
|
|
3
|
+
export const COMPANY_COLUMN = 'company_id';
|
|
4
|
+
/** Database column that carries the owning shopper on customer-owned rows. */
|
|
5
|
+
export const CUSTOMER_COLUMN = 'user_id';
|
|
6
|
+
/** Key of the company in `AuthUser.scopes` and in a consumer's restored message scope. */
|
|
7
|
+
export const COMPANY_SCOPE_KEY = 'company';
|
|
8
|
+
/** Prefix shared by every platform permission (e.g. `platform:company:read`). */
|
|
9
|
+
export const PLATFORM_PERMISSION_PREFIX = 'platform:';
|
|
10
|
+
/**
|
|
11
|
+
* Company scope. The context is `{ companyId }`, taken from the gateway-signed company header
|
|
12
|
+
* (`x-company-id`, see {@link ecommerceIdentityProtocol}) — never from a request body.
|
|
13
|
+
*
|
|
14
|
+
* @example new ProductRepository(db, products, companyScope).findById({ companyId }, id)
|
|
15
|
+
*/
|
|
16
|
+
export const companyScope = defineScope({ name: 'company', column: COMPANY_COLUMN, contextKey: 'companyId' });
|
|
17
|
+
/**
|
|
18
|
+
* Customer (owner) scope: the shopper's own rows. The context is `{ ownerId: user.id }`.
|
|
19
|
+
*
|
|
20
|
+
* @example new CustomerOrderRepository(db, orders, customerScope).findMany({ ownerId: req.user.id })
|
|
21
|
+
*/
|
|
22
|
+
export const customerScope = new OwnerScope({ name: 'customer', column: CUSTOMER_COLUMN });
|
|
23
|
+
/**
|
|
24
|
+
* True for the platform super admin or anyone holding a `platform:*` permission.
|
|
25
|
+
*
|
|
26
|
+
* @example isPlatformOperator(req.user)
|
|
27
|
+
*/
|
|
28
|
+
export function isPlatformOperator(user) {
|
|
29
|
+
return user.isSuperAdmin === true || (user.permissions ?? []).some((p) => p.startsWith(PLATFORM_PERMISSION_PREFIX));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Platform scope over `company_id`. Grants come only from `platformScope.authorize(req.user)`, which
|
|
33
|
+
* throws 403 `PLATFORM_SCOPE_DENIED` unless {@link isPlatformOperator} approves. Routes still check
|
|
34
|
+
* their specific permission with `requirePermission`.
|
|
35
|
+
*
|
|
36
|
+
* @example new CompanyOrderRepository(db, orders, platformScope).findMany(platformScope.authorize(req.user))
|
|
37
|
+
*/
|
|
38
|
+
export const platformScope = definePlatformScope({
|
|
39
|
+
name: 'platform',
|
|
40
|
+
column: COMPANY_COLUMN,
|
|
41
|
+
predicate: isPlatformOperator,
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Restores the company scope from a tenant event payload for `MessageConsumer.subscribe({ scopeFrom })`
|
|
45
|
+
* (TEN-7). The result is directly usable as a {@link companyScope} context.
|
|
46
|
+
*
|
|
47
|
+
* @example scopeFrom: companyScopeFrom, handler: ({ data, scope }) => service.onPaid(scope!, data)
|
|
48
|
+
*/
|
|
49
|
+
export function companyScopeFrom(data) {
|
|
50
|
+
return { companyId: data.companyId };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/scopes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE7F,4EAA4E;AAC5E,MAAM,CAAC,MAAM,cAAc,GAAG,YAAqB,CAAC;AACpD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,eAAe,GAAG,SAAkB,CAAC;AAClD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAkB,CAAC;AACpD,iFAAiF;AACjF,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAoB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AAE9G;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;AAE3F;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAoD;IACrF,OAAO,IAAI,CAAC,YAAY,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC;AACtH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAiD;IAC/F,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,cAAc;IACtB,SAAS,EAAE,kBAAkB;CAC9B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAmC;IAClE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E-commerce app settings (D40). These are the values `@heavybit/shared-lib` takes as parameters:
|
|
3
|
+
* services pass them in (`createRedisKeyspace({ app: APP_SLUG, … })`, `createMessaging({ app: APP_SLUG, … })`,
|
|
4
|
+
* `Money`/phone helpers, socket tickets) instead of writing literals.
|
|
5
|
+
*/
|
|
6
|
+
import { type NotificationDispatch, type NotificationDispatchInput, type NotificationDispatchSchema } from '@heavybit/shared-lib';
|
|
7
|
+
/** Infra slug for containers, databases, Redis keys and exchanges (D15). */
|
|
8
|
+
export declare const APP_SLUG: "ecommerce";
|
|
9
|
+
/** The only currency in P1 (D5: money travels as decimal strings with this code). */
|
|
10
|
+
export declare const CURRENCY: "KES";
|
|
11
|
+
/** Region for phone parsing and normalisation (`2547XXXXXXXX`). */
|
|
12
|
+
export declare const PHONE_REGION: "KE";
|
|
13
|
+
/** IANA zone used when neither the shop nor the user has one (reports, business days, emails). */
|
|
14
|
+
export declare const DEFAULT_TIME_ZONE: "Africa/Nairobi";
|
|
15
|
+
/** Domain separator for socket handshake tickets, so a ticket from another app or purpose never verifies. */
|
|
16
|
+
export declare const SOCKET_TICKET_DOMAIN: "ecommerce-socket-ticket:v1";
|
|
17
|
+
/** Prefix of every internal (service-to-service) route; passed to `createInternalCallerGuards({ pathPrefix })`. */
|
|
18
|
+
export declare const INTERNAL_PATH_PREFIX: "/api/v1/internal";
|
|
19
|
+
/** Prefix of the public API behind the gateway. */
|
|
20
|
+
export declare const PUBLIC_API_PREFIX: "/api/v1";
|
|
21
|
+
/** What a notification is about; drives preferences and templates in the notification-service. */
|
|
22
|
+
export declare const NOTIFICATION_CATEGORIES: readonly ["security", "account", "order", "payment", "shipping", "support", "staff", "store", "billing"];
|
|
23
|
+
/** Delivery channels the notification-service supports (D20: email via SendGrid, SMS provider with a `log` driver in dev). */
|
|
24
|
+
export declare const NOTIFICATION_CHANNELS: readonly ["email", "sms", "in_app"];
|
|
25
|
+
/** One notification category. */
|
|
26
|
+
export type NotificationCategory = (typeof NOTIFICATION_CATEGORIES)[number];
|
|
27
|
+
/** One notification channel. */
|
|
28
|
+
export type NotificationChannel = (typeof NOTIFICATION_CHANNELS)[number];
|
|
29
|
+
/**
|
|
30
|
+
* Schema of a notification dispatch in this app's vocabulary. Producers stage it with the
|
|
31
|
+
* `notification.send.requested` command; the notification-service validates with the same schema.
|
|
32
|
+
*
|
|
33
|
+
* @example notificationDispatchSchema.parse({ template: 'login-otp', category: 'security', recipient: { email }, channels: ['email'], data: { code }, secretKeys: ['code'] })
|
|
34
|
+
*/
|
|
35
|
+
export declare const notificationDispatchSchema: NotificationDispatchSchema<NotificationCategory, NotificationChannel>;
|
|
36
|
+
/** A validated dispatch (defaults applied). */
|
|
37
|
+
export type EcommerceNotificationDispatch = NotificationDispatch<NotificationCategory, NotificationChannel>;
|
|
38
|
+
/** What a producer stages (`data`, `secretKeys` optional). */
|
|
39
|
+
export type EcommerceNotificationDispatchInput = NotificationDispatchInput<NotificationCategory, NotificationChannel>;
|
|
40
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAE9B,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,EAAG,WAAoB,CAAC;AAE7C,qFAAqF;AACrF,eAAO,MAAM,QAAQ,EAAG,KAAc,CAAC;AAEvC,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAG,IAAa,CAAC;AAE1C,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,EAAG,gBAAyB,CAAC;AAE3D,6GAA6G;AAC7G,eAAO,MAAM,oBAAoB,EAAG,4BAAqC,CAAC;AAE1E,mHAAmH;AACnH,eAAO,MAAM,oBAAoB,EAAG,kBAA2B,CAAC;AAEhE,mDAAmD;AACnD,eAAO,MAAM,iBAAiB,EAAG,SAAkB,CAAC;AAEpD,kGAAkG;AAClG,eAAO,MAAM,uBAAuB,0GAA2G,CAAC;AAEhJ,8HAA8H;AAC9H,eAAO,MAAM,qBAAqB,qCAAsC,CAAC;AAEzE,iCAAiC;AACjC,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5E,gCAAgC;AAChC,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,0BAA0B,CAAC,oBAAoB,EAAE,mBAAmB,CAG3G,CAAC;AAEH,+CAA+C;AAC/C,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,CAAC;AAC5G,8DAA8D;AAC9D,MAAM,MAAM,kCAAkC,GAAG,yBAAyB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin e-commerce bindings of shared-lib's generic helpers (D40): money in KES, Kenyan mobile numbers,
|
|
3
|
+
* business days in the shop's zone, the approval policy, audit payloads and socket tickets. No business
|
|
4
|
+
* logic — only app values plugged into the generic code.
|
|
5
|
+
*/
|
|
6
|
+
import { Money, type ApprovalPolicy, type AuditEvent, type SocketTicketClaims, type SocketTicketInput, type SocketTicketResult } from '@heavybit/shared-lib';
|
|
7
|
+
import type { auditRecordedSchema } from './events/audit.js';
|
|
8
|
+
import type { z } from '@heavybit/shared-lib';
|
|
9
|
+
/**
|
|
10
|
+
* A KES amount from its decimal string (strict: at most 2 decimals, no separators).
|
|
11
|
+
*
|
|
12
|
+
* @param amount e.g. `"1250.00"`.
|
|
13
|
+
* @returns The amount.
|
|
14
|
+
* @example money('1250').add(money('99.50')).toDecimalString() // '1349.50'
|
|
15
|
+
*/
|
|
16
|
+
export declare function money(amount: string): Money;
|
|
17
|
+
/** Zero shillings. */
|
|
18
|
+
export declare const zeroMoney: () => Money;
|
|
19
|
+
/**
|
|
20
|
+
* Normalises a Kenyan mobile number to `2547XXXXXXXX` / `2541XXXXXXXX` (the form M-Pesa and SMS use).
|
|
21
|
+
* Accepts `07…`, `01…`, `7…`, `+254…` and `254…` with spaces or dashes; rejects landlines and foreign numbers.
|
|
22
|
+
*
|
|
23
|
+
* @param phone Number as typed.
|
|
24
|
+
* @returns The MSISDN.
|
|
25
|
+
* @throws BadRequestError `INVALID_PHONE`.
|
|
26
|
+
* @example normalisePhone('0712 345 678') // '254712345678'
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalisePhone(phone: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* The business day containing `at`, in the company's zone (default: the app's `DEFAULT_TIME_ZONE`).
|
|
31
|
+
*
|
|
32
|
+
* @param at Any instant in the day.
|
|
33
|
+
* @param zone The shop's IANA zone when it has one.
|
|
34
|
+
* @returns Half-open `[start, end)` UTC range.
|
|
35
|
+
*/
|
|
36
|
+
export declare function companyDayBounds(at: Date, zone?: string): {
|
|
37
|
+
start: Date;
|
|
38
|
+
end: Date;
|
|
39
|
+
};
|
|
40
|
+
/** How long a pending approval stays decidable. */
|
|
41
|
+
export declare const APPROVAL_TTL_HOURS: 72;
|
|
42
|
+
/**
|
|
43
|
+
* The approval rules with `APPROVAL_DECIDE_PERMISSION` and an `APPROVAL_TTL_HOURS` TTL.
|
|
44
|
+
*
|
|
45
|
+
* @example approvalPolicy.assertCanDecide(approval, req.user); approval.expiresAt = approvalPolicy.expiresAt();
|
|
46
|
+
*/
|
|
47
|
+
export declare const approvalPolicy: ApprovalPolicy;
|
|
48
|
+
/** The `{publisher}.audit.recorded` payload (before the outbox adds `eventId`, `version`, `actorUserId`). */
|
|
49
|
+
export type AuditRecordedPayload = z.input<typeof auditRecordedSchema> & {
|
|
50
|
+
ip: string | null;
|
|
51
|
+
userAgent: string | null;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Maps a shared-lib audit event to this app's `{publisher}.audit.recorded` payload. The company comes from
|
|
55
|
+
* the event's `company` scope; changed field names (never values) go in `metadata.changedFields`; `ip` and
|
|
56
|
+
* `userAgent` are extra (passed-through) fields for audit-service.
|
|
57
|
+
* Stage it with `enqueueOutbox(tx, AUDIT_RECORDED_KEYS.order, toAuditRecordedPayload(event), { actorUserId: event.actorUserId })`.
|
|
58
|
+
*
|
|
59
|
+
* @param event From `buildAuditEvent`.
|
|
60
|
+
* @returns The payload.
|
|
61
|
+
*/
|
|
62
|
+
export declare function toAuditRecordedPayload(event: AuditEvent): AuditRecordedPayload;
|
|
63
|
+
/**
|
|
64
|
+
* Signs a socket ticket under this app's domain separator (`SOCKET_TICKET_DOMAIN`).
|
|
65
|
+
*
|
|
66
|
+
* @param input User, audience (the front-end app), company scope ids and permissions.
|
|
67
|
+
* @param secret The ticket signing secret.
|
|
68
|
+
* @param ttlSeconds 1–60 (default 60).
|
|
69
|
+
*/
|
|
70
|
+
export declare function signAppSocketTicket(input: SocketTicketInput, secret: string, ttlSeconds?: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Verifies a socket ticket under this app's domain separator.
|
|
73
|
+
*
|
|
74
|
+
* @param ticket From the handshake.
|
|
75
|
+
* @param secret The ticket signing secret.
|
|
76
|
+
* @param audience Accepted audience(s).
|
|
77
|
+
*/
|
|
78
|
+
export declare function verifyAppSocketTicket(ticket: unknown, secret: string, audience: string | readonly string[]): SocketTicketResult;
|
|
79
|
+
/** Room for one company's live updates: `company:{companyId}`. */
|
|
80
|
+
export declare const companyRoom: (companyId: string) => string;
|
|
81
|
+
/**
|
|
82
|
+
* True when the ticket holder may join `companyRoom(companyId)` (member of that company, or super admin)
|
|
83
|
+
* and holds `permission` when one is given.
|
|
84
|
+
*
|
|
85
|
+
* @example if (canJoinCompanyRoom(socket.data.identity, companyId, 'order:view')) socket.join(companyRoom(companyId));
|
|
86
|
+
*/
|
|
87
|
+
export declare function canJoinCompanyRoom(claims: SocketTicketClaims, companyId: string, permission?: string): boolean;
|
|
88
|
+
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/bindings.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGL,KAAK,EAML,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,k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,GAAG,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAE/H;AAED,kEAAkE;AAClE,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,KAAG,MAAiD,CAAC;AAElG;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAE9G"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `{publisher}.audit.recorded`: business audit entries each service stages through its outbox for
|
|
3
|
+
* audit-service. Metadata holds small facts only — never secrets, tokens or contact details.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@heavybit/shared-lib';
|
|
6
|
+
/** Binding pattern for audit-service: every publisher's audit entries. */
|
|
7
|
+
export declare const AUDIT_RECORDED_PATTERN: "*.audit.recorded";
|
|
8
|
+
/** `{publisher}.audit.recorded` for each publisher, e.g. `AUDIT_RECORDED_KEYS.order`. */
|
|
9
|
+
export declare const AUDIT_RECORDED_KEYS: {
|
|
10
|
+
readonly order: "order.audit.recorded";
|
|
11
|
+
readonly payment: "payment.audit.recorded";
|
|
12
|
+
readonly shipping: "shipping.audit.recorded";
|
|
13
|
+
readonly store: "store.audit.recorded";
|
|
14
|
+
readonly auth: "auth.audit.recorded";
|
|
15
|
+
readonly gateway: "gateway.audit.recorded";
|
|
16
|
+
readonly catalog: "catalog.audit.recorded";
|
|
17
|
+
readonly media: "media.audit.recorded";
|
|
18
|
+
readonly cart: "cart.audit.recorded";
|
|
19
|
+
readonly notification: "notification.audit.recorded";
|
|
20
|
+
readonly reporting: "reporting.audit.recorded";
|
|
21
|
+
};
|
|
22
|
+
/** v1 payload of an audit entry. `companyId` is null for platform-level actions. */
|
|
23
|
+
export declare const auditRecordedSchema: z.ZodObject<{
|
|
24
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
|
+
} & {
|
|
26
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
27
|
+
action: z.ZodString;
|
|
28
|
+
entityType: z.ZodString;
|
|
29
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
30
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
31
|
+
occurredAt: z.ZodString;
|
|
32
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
33
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
34
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
} & {
|
|
36
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
37
|
+
action: z.ZodString;
|
|
38
|
+
entityType: z.ZodString;
|
|
39
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
40
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
41
|
+
occurredAt: z.ZodString;
|
|
42
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
43
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
44
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
} & {
|
|
46
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
47
|
+
action: z.ZodString;
|
|
48
|
+
entityType: z.ZodString;
|
|
49
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
50
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
51
|
+
occurredAt: z.ZodString;
|
|
52
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
53
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
54
|
+
/** Every audit routing key with its schema. */
|
|
55
|
+
export declare const AUDIT_EVENTS: Record<"order.audit.recorded" | "payment.audit.recorded" | "shipping.audit.recorded" | "store.audit.recorded" | "auth.audit.recorded" | "gateway.audit.recorded" | "catalog.audit.recorded" | "media.audit.recorded" | "cart.audit.recorded" | "notification.audit.recorded" | "reporting.audit.recorded", z.ZodObject<{
|
|
56
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
} & {
|
|
58
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
59
|
+
action: z.ZodString;
|
|
60
|
+
entityType: z.ZodString;
|
|
61
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
62
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
63
|
+
occurredAt: z.ZodString;
|
|
64
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
65
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
66
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
} & {
|
|
68
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
69
|
+
action: z.ZodString;
|
|
70
|
+
entityType: z.ZodString;
|
|
71
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
72
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
73
|
+
occurredAt: z.ZodString;
|
|
74
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
75
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
76
|
+
companyId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
} & {
|
|
78
|
+
/** What happened, e.g. `order.refund.approved`. */
|
|
79
|
+
action: z.ZodString;
|
|
80
|
+
entityType: z.ZodString;
|
|
81
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
82
|
+
outcome: z.ZodEnum<["success", "failure"]>;
|
|
83
|
+
occurredAt: z.ZodString;
|
|
84
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
85
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
86
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/events/audit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAGzC,0EAA0E;AAC1E,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAElE,yFAAyF;AACzF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;CAAiC,CAAC;AAElE,oFAAoF;AACpF,eAAO,MAAM,mBAAmB;;;IAC9B,mDAAmD;;;;;;;;;;IAAnD,mDAAmD;;;;;;;;;;IAAnD,mDAAmD;;;;;;;gCAOnD,CAAC;AAEH,+CAA+C;AAC/C,eAAO,MAAM,YAAY;;;IAVvB,mDAAmD;;;;;;;;;;IAAnD,mDAAmD;;;;;;;;;;IAAnD,mDAAmD;;;;;;;iCAU2B,CAAC"}
|