@strimz/shared-types 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/agents.cjs +148 -0
- package/dist/agents.cjs.map +1 -0
- package/dist/agents.d.cts +317 -0
- package/dist/agents.d.ts +317 -0
- package/dist/agents.js +137 -0
- package/dist/agents.js.map +1 -0
- package/dist/api-keys.cjs +91 -0
- package/dist/api-keys.cjs.map +1 -0
- package/dist/api-keys.d.cts +155 -0
- package/dist/api-keys.d.ts +155 -0
- package/dist/api-keys.js +84 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/common.cjs +56 -0
- package/dist/common.cjs.map +1 -0
- package/dist/common.d.cts +82 -0
- package/dist/common.d.ts +82 -0
- package/dist/common.js +37 -0
- package/dist/common.js.map +1 -0
- package/dist/compliance.cjs +61 -0
- package/dist/compliance.cjs.map +1 -0
- package/dist/compliance.d.cts +59 -0
- package/dist/compliance.d.ts +59 -0
- package/dist/compliance.js +56 -0
- package/dist/compliance.js.map +1 -0
- package/dist/customers.cjs +56 -0
- package/dist/customers.cjs.map +1 -0
- package/dist/customers.d.cts +64 -0
- package/dist/customers.d.ts +64 -0
- package/dist/customers.js +53 -0
- package/dist/customers.js.map +1 -0
- package/dist/events.cjs +675 -0
- package/dist/events.cjs.map +1 -0
- package/dist/events.d.cts +7907 -0
- package/dist/events.d.ts +7907 -0
- package/dist/events.js +650 -0
- package/dist/events.js.map +1 -0
- package/dist/index.cjs +976 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +858 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.cjs +72 -0
- package/dist/invoices.cjs.map +1 -0
- package/dist/invoices.d.cts +159 -0
- package/dist/invoices.d.ts +159 -0
- package/dist/invoices.js +67 -0
- package/dist/invoices.js.map +1 -0
- package/dist/merchants.cjs +104 -0
- package/dist/merchants.cjs.map +1 -0
- package/dist/merchants.d.cts +259 -0
- package/dist/merchants.d.ts +259 -0
- package/dist/merchants.js +93 -0
- package/dist/merchants.js.map +1 -0
- package/dist/payment-sessions.cjs +125 -0
- package/dist/payment-sessions.cjs.map +1 -0
- package/dist/payment-sessions.d.cts +180 -0
- package/dist/payment-sessions.d.ts +180 -0
- package/dist/payment-sessions.js +120 -0
- package/dist/payment-sessions.js.map +1 -0
- package/dist/refunds.cjs +81 -0
- package/dist/refunds.cjs.map +1 -0
- package/dist/refunds.d.cts +91 -0
- package/dist/refunds.d.ts +91 -0
- package/dist/refunds.js +75 -0
- package/dist/refunds.js.map +1 -0
- package/dist/storefronts.cjs +223 -0
- package/dist/storefronts.cjs.map +1 -0
- package/dist/storefronts.d.cts +177 -0
- package/dist/storefronts.d.ts +177 -0
- package/dist/storefronts.js +216 -0
- package/dist/storefronts.js.map +1 -0
- package/dist/subscriptions.cjs +175 -0
- package/dist/subscriptions.cjs.map +1 -0
- package/dist/subscriptions.d.cts +290 -0
- package/dist/subscriptions.d.ts +290 -0
- package/dist/subscriptions.js +163 -0
- package/dist/subscriptions.js.map +1 -0
- package/dist/transactions.cjs +67 -0
- package/dist/transactions.cjs.map +1 -0
- package/dist/transactions.d.cts +78 -0
- package/dist/transactions.d.ts +78 -0
- package/dist/transactions.js +63 -0
- package/dist/transactions.js.map +1 -0
- package/dist/webhooks.cjs +116 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +201 -0
- package/dist/webhooks.d.ts +201 -0
- package/dist/webhooks.js +107 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +134 -0
- package/src/agents.ts +149 -0
- package/src/api-keys.ts +78 -0
- package/src/common.ts +113 -0
- package/src/compliance.ts +40 -0
- package/src/customers.ts +40 -0
- package/src/events.ts +176 -0
- package/src/index.ts +23 -0
- package/src/invoices.ts +53 -0
- package/src/merchants.ts +104 -0
- package/src/payment-sessions.ts +131 -0
- package/src/refunds.ts +68 -0
- package/src/storefronts.ts +89 -0
- package/src/subscriptions.ts +180 -0
- package/src/tokens.ts +60 -0
- package/src/transactions.ts +52 -0
- package/src/webhooks.ts +109 -0
package/src/api-keys.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API keys.
|
|
3
|
+
*
|
|
4
|
+
* A merchant has independent test and live keys. The full secret is shown
|
|
5
|
+
* exactly once at creation; the backend stores only a hash and a display prefix.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import { idSchema, isoTimestampSchema, modeSchema } from './common.js'
|
|
10
|
+
|
|
11
|
+
export const apiKeyKindSchema = z.enum(['secret', 'publishable'])
|
|
12
|
+
export type ApiKeyKind = z.infer<typeof apiKeyKindSchema>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Underscore-separated to match the Prisma `ApiKeyScope` enum (Prisma
|
|
16
|
+
* does not allow `:` in enum values). The DB and the wire format use the
|
|
17
|
+
* same form so there is no boundary translation.
|
|
18
|
+
*/
|
|
19
|
+
export const apiKeyScopeSchema = z.enum([
|
|
20
|
+
'sessions_read',
|
|
21
|
+
'sessions_write',
|
|
22
|
+
'subscriptions_read',
|
|
23
|
+
'subscriptions_write',
|
|
24
|
+
'refunds_read',
|
|
25
|
+
'refunds_write',
|
|
26
|
+
'transactions_read',
|
|
27
|
+
'webhooks_read',
|
|
28
|
+
'webhooks_write',
|
|
29
|
+
'invoices_read',
|
|
30
|
+
'invoices_write',
|
|
31
|
+
'storefronts_read',
|
|
32
|
+
'storefronts_write',
|
|
33
|
+
'agents_read',
|
|
34
|
+
'agents_write',
|
|
35
|
+
// Meta-tx relayer — submitting payer-signed EIP-3009 / EIP-2612
|
|
36
|
+
// authorizations on the merchant's behalf. Granted to keys used by
|
|
37
|
+
// hosted checkout and merchants embedding the SDK.
|
|
38
|
+
'relay_read',
|
|
39
|
+
'relay_write',
|
|
40
|
+
])
|
|
41
|
+
export type ApiKeyScope = z.infer<typeof apiKeyScopeSchema>
|
|
42
|
+
|
|
43
|
+
export const apiKeySchema = z.object({
|
|
44
|
+
id: idSchema,
|
|
45
|
+
merchantId: idSchema,
|
|
46
|
+
name: z.string().min(1).max(60),
|
|
47
|
+
kind: apiKeyKindSchema,
|
|
48
|
+
mode: modeSchema,
|
|
49
|
+
prefix: z.string().min(8).max(24),
|
|
50
|
+
lastFour: z.string().length(4),
|
|
51
|
+
scopes: z.array(apiKeyScopeSchema).nonempty(),
|
|
52
|
+
createdAt: isoTimestampSchema,
|
|
53
|
+
lastUsedAt: isoTimestampSchema.nullable(),
|
|
54
|
+
revokedAt: isoTimestampSchema.nullable(),
|
|
55
|
+
})
|
|
56
|
+
export type ApiKey = z.infer<typeof apiKeySchema>
|
|
57
|
+
|
|
58
|
+
// ---------- DTOs ----------
|
|
59
|
+
|
|
60
|
+
export const createApiKeyInputSchema = z.object({
|
|
61
|
+
name: z.string().min(1).max(60),
|
|
62
|
+
kind: apiKeyKindSchema,
|
|
63
|
+
mode: modeSchema,
|
|
64
|
+
scopes: z.array(apiKeyScopeSchema).nonempty(),
|
|
65
|
+
})
|
|
66
|
+
export type CreateApiKeyInput = z.infer<typeof createApiKeyInputSchema>
|
|
67
|
+
|
|
68
|
+
export const createApiKeyOutputSchema = z.object({
|
|
69
|
+
apiKey: apiKeySchema,
|
|
70
|
+
/** Full plaintext key — shown exactly once. */
|
|
71
|
+
secret: z.string(),
|
|
72
|
+
})
|
|
73
|
+
export type CreateApiKeyOutput = z.infer<typeof createApiKeyOutputSchema>
|
|
74
|
+
|
|
75
|
+
export const rotateApiKeyInputSchema = z.object({
|
|
76
|
+
id: idSchema,
|
|
77
|
+
})
|
|
78
|
+
export type RotateApiKeyInput = z.infer<typeof rotateApiKeyInputSchema>
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primitive schemas shared across every entity.
|
|
3
|
+
* Every higher-level schema builds on these so validation is consistent.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
/** CUID2 or UUID-style opaque identifier. */
|
|
9
|
+
export const idSchema = z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.max(64)
|
|
13
|
+
.regex(/^[a-zA-Z0-9_-]+$/, 'id must be URL-safe')
|
|
14
|
+
|
|
15
|
+
/** EVM address. Hex-encoded, 0x-prefixed, 20 bytes. Normalised to lowercase. */
|
|
16
|
+
export const evmAddressSchema = z
|
|
17
|
+
.string()
|
|
18
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, 'must be a 0x-prefixed 40-character hex EVM address')
|
|
19
|
+
.transform((v) => v.toLowerCase())
|
|
20
|
+
|
|
21
|
+
/** EVM transaction hash. 32-byte hex. */
|
|
22
|
+
export const evmTxHashSchema = z
|
|
23
|
+
.string()
|
|
24
|
+
.regex(/^0x[a-fA-F0-9]{64}$/, 'must be a 0x-prefixed 64-character hex EVM transaction hash')
|
|
25
|
+
|
|
26
|
+
/** Email address, trimmed and lower-cased. */
|
|
27
|
+
export const emailSchema = z.string().email().trim().toLowerCase().max(320)
|
|
28
|
+
|
|
29
|
+
/** HTTPS URL. No http:// allowed outside dev. */
|
|
30
|
+
export const httpsUrlSchema = z
|
|
31
|
+
.string()
|
|
32
|
+
.url()
|
|
33
|
+
.refine((v) => v.startsWith('https://'), {
|
|
34
|
+
message: 'must be an https:// URL',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/** URL permitting http and https (dev + prod). */
|
|
38
|
+
export const httpUrlSchema = z.string().url()
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Amount expressed in the token's smallest unit, serialised as a string to
|
|
42
|
+
* preserve precision beyond `Number.MAX_SAFE_INTEGER`. For USDC (6 decimals),
|
|
43
|
+
* 1 USDC is the string "1000000".
|
|
44
|
+
*/
|
|
45
|
+
export const tokenAmountSchema = z
|
|
46
|
+
.string()
|
|
47
|
+
.regex(/^[0-9]+$/, 'must be a non-negative integer string (base-10)')
|
|
48
|
+
.refine((v) => BigInt(v) >= 0n, 'must be >= 0')
|
|
49
|
+
|
|
50
|
+
/** Unsigned integer up to 2^53 - 1; validated and returned as number. */
|
|
51
|
+
export const uintSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)
|
|
52
|
+
|
|
53
|
+
/** ISO-8601 timestamp string (`.toISOString()`-compatible). */
|
|
54
|
+
export const isoTimestampSchema = z
|
|
55
|
+
.string()
|
|
56
|
+
.datetime({ offset: true, message: 'must be an ISO-8601 timestamp' })
|
|
57
|
+
|
|
58
|
+
/** Two-letter ISO-3166 country code. */
|
|
59
|
+
export const countryCodeSchema = z
|
|
60
|
+
.string()
|
|
61
|
+
.length(2)
|
|
62
|
+
.regex(/^[A-Z]{2}$/, 'must be an ISO-3166 alpha-2 country code')
|
|
63
|
+
|
|
64
|
+
/** Pagination inputs used by every list endpoint. */
|
|
65
|
+
export const paginationInputSchema = z.object({
|
|
66
|
+
limit: z.number().int().min(1).max(100).default(25),
|
|
67
|
+
cursor: z.string().min(1).max(200).nullish(),
|
|
68
|
+
})
|
|
69
|
+
export type PaginationInput = z.infer<typeof paginationInputSchema>
|
|
70
|
+
|
|
71
|
+
/** Pagination envelope used by every list response. */
|
|
72
|
+
export const makePaginatedSchema = <T extends z.ZodTypeAny>(item: T) =>
|
|
73
|
+
z.object({
|
|
74
|
+
data: z.array(item),
|
|
75
|
+
nextCursor: z.string().nullable(),
|
|
76
|
+
hasMore: z.boolean(),
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
/** Free-form metadata bag the API round-trips for merchants. */
|
|
80
|
+
export const metadataSchema = z
|
|
81
|
+
.record(
|
|
82
|
+
z.string().min(1).max(40),
|
|
83
|
+
z.union([z.string().max(500), z.number(), z.boolean(), z.null()]),
|
|
84
|
+
)
|
|
85
|
+
.refine((m) => Object.keys(m).length <= 50, 'at most 50 metadata keys')
|
|
86
|
+
.default({})
|
|
87
|
+
|
|
88
|
+
/** Environment mode carried on every mode-scoped resource. */
|
|
89
|
+
export const modeSchema = z.enum(['test', 'live'])
|
|
90
|
+
export type Mode = z.infer<typeof modeSchema>
|
|
91
|
+
|
|
92
|
+
/** Payment token enum — mirrors `@strimz/shared-config`. */
|
|
93
|
+
export const paymentCurrencySchema = z.enum(['USDC', 'EURC'])
|
|
94
|
+
export type PaymentCurrency = z.infer<typeof paymentCurrencySchema>
|
|
95
|
+
|
|
96
|
+
/** Every display-level currency (payment + treasury). */
|
|
97
|
+
export const tokenSymbolSchema = z.enum(['USDC', 'EURC', 'USYC'])
|
|
98
|
+
export type TokenSymbol = z.infer<typeof tokenSymbolSchema>
|
|
99
|
+
|
|
100
|
+
/** Merchant tier enum — mirrors `@strimz/shared-config`. */
|
|
101
|
+
export const merchantTierSchema = z.enum(['free', 'growth', 'business', 'enterprise'])
|
|
102
|
+
export type MerchantTier = z.infer<typeof merchantTierSchema>
|
|
103
|
+
|
|
104
|
+
/** Arc environment enum. */
|
|
105
|
+
export const arcEnvironmentSchema = z.enum(['testnet', 'mainnet'])
|
|
106
|
+
export type ArcEnvironment = z.infer<typeof arcEnvironmentSchema>
|
|
107
|
+
|
|
108
|
+
export type Id = z.infer<typeof idSchema>
|
|
109
|
+
export type EvmAddress = z.infer<typeof evmAddressSchema>
|
|
110
|
+
export type EvmTxHash = z.infer<typeof evmTxHashSchema>
|
|
111
|
+
export type TokenAmount = z.infer<typeof tokenAmountSchema>
|
|
112
|
+
export type IsoTimestamp = z.infer<typeof isoTimestampSchema>
|
|
113
|
+
export type Metadata = z.infer<typeof metadataSchema>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compliance — sanctions/AML screening log.
|
|
3
|
+
*
|
|
4
|
+
* Every wallet address that interacts with Strimz (merchant payout,
|
|
5
|
+
* subscriber, payer) is screened. Results are logged; provider and score
|
|
6
|
+
* are recorded for later audit.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
import { evmAddressSchema, idSchema, isoTimestampSchema } from './common.js'
|
|
11
|
+
|
|
12
|
+
export const complianceProviderSchema = z.enum(['trm', 'elliptic', 'disabled'])
|
|
13
|
+
export type ComplianceProvider = z.infer<typeof complianceProviderSchema>
|
|
14
|
+
|
|
15
|
+
export const complianceStatusSchema = z.enum(['clear', 'flagged', 'blocked', 'error'])
|
|
16
|
+
export type ComplianceStatus = z.infer<typeof complianceStatusSchema>
|
|
17
|
+
|
|
18
|
+
export const complianceScreeningContextSchema = z.enum([
|
|
19
|
+
'merchant_onboarding',
|
|
20
|
+
'payer_checkout',
|
|
21
|
+
'subscriber_signup',
|
|
22
|
+
'refund_recipient',
|
|
23
|
+
])
|
|
24
|
+
export type ComplianceScreeningContext = z.infer<typeof complianceScreeningContextSchema>
|
|
25
|
+
|
|
26
|
+
export const complianceLogSchema = z.object({
|
|
27
|
+
id: idSchema,
|
|
28
|
+
walletAddress: evmAddressSchema,
|
|
29
|
+
provider: complianceProviderSchema,
|
|
30
|
+
status: complianceStatusSchema,
|
|
31
|
+
riskScore: z.number().min(0).max(100).nullable(),
|
|
32
|
+
flags: z.array(z.string().max(120)).default([]),
|
|
33
|
+
context: complianceScreeningContextSchema,
|
|
34
|
+
merchantId: idSchema.nullable(),
|
|
35
|
+
sessionId: idSchema.nullable(),
|
|
36
|
+
subscriptionId: idSchema.nullable(),
|
|
37
|
+
providerRequestId: z.string().max(200).nullable(),
|
|
38
|
+
createdAt: isoTimestampSchema,
|
|
39
|
+
})
|
|
40
|
+
export type ComplianceLog = z.infer<typeof complianceLogSchema>
|
package/src/customers.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer — the payer on the merchant's side.
|
|
3
|
+
*
|
|
4
|
+
* Customers are uniquely identified by (merchantId, walletAddress). Email and
|
|
5
|
+
* externalRef are optional; merchants can associate their own customer id.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import {
|
|
10
|
+
emailSchema,
|
|
11
|
+
evmAddressSchema,
|
|
12
|
+
idSchema,
|
|
13
|
+
isoTimestampSchema,
|
|
14
|
+
metadataSchema,
|
|
15
|
+
} from './common.js'
|
|
16
|
+
|
|
17
|
+
export const customerSchema = z.object({
|
|
18
|
+
id: idSchema,
|
|
19
|
+
merchantId: idSchema,
|
|
20
|
+
walletAddress: evmAddressSchema,
|
|
21
|
+
email: emailSchema.nullable(),
|
|
22
|
+
/** Merchant-provided external identifier (e.g. their own user id). */
|
|
23
|
+
externalRef: z.string().min(1).max(120).nullable(),
|
|
24
|
+
displayName: z.string().min(1).max(120).nullable(),
|
|
25
|
+
metadata: metadataSchema,
|
|
26
|
+
firstSeenAt: isoTimestampSchema,
|
|
27
|
+
lastSeenAt: isoTimestampSchema,
|
|
28
|
+
})
|
|
29
|
+
export type Customer = z.infer<typeof customerSchema>
|
|
30
|
+
|
|
31
|
+
// ---------- DTOs ----------
|
|
32
|
+
|
|
33
|
+
export const upsertCustomerInputSchema = z.object({
|
|
34
|
+
walletAddress: evmAddressSchema,
|
|
35
|
+
email: emailSchema.optional(),
|
|
36
|
+
externalRef: z.string().min(1).max(120).optional(),
|
|
37
|
+
displayName: z.string().min(1).max(120).optional(),
|
|
38
|
+
metadata: metadataSchema.optional(),
|
|
39
|
+
})
|
|
40
|
+
export type UpsertCustomerInput = z.infer<typeof upsertCustomerInputSchema>
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical webhook event envelopes.
|
|
3
|
+
*
|
|
4
|
+
* The event envelope is what Strimz signs, stores, and delivers. Every
|
|
5
|
+
* webhook-delivered payload is an instance of `webhookEventSchema` for a
|
|
6
|
+
* specific event name, with `data` typed to the matching entity schema.
|
|
7
|
+
*
|
|
8
|
+
* SDK consumers import `StrimzWebhookEvent` to get a discriminated union
|
|
9
|
+
* over every possible event name → payload shape.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { z } from 'zod'
|
|
13
|
+
import { idSchema, isoTimestampSchema, modeSchema } from './common.js'
|
|
14
|
+
import { paymentSessionSchema } from './payment-sessions.js'
|
|
15
|
+
import { transactionSchema } from './transactions.js'
|
|
16
|
+
import { subscriptionSchema, subscriptionChargeSchema } from './subscriptions.js'
|
|
17
|
+
import { refundSchema } from './refunds.js'
|
|
18
|
+
import { invoiceSchema } from './invoices.js'
|
|
19
|
+
import { agentActivityLogSchema, agentJobSchema } from './agents.js'
|
|
20
|
+
import { complianceLogSchema } from './compliance.js'
|
|
21
|
+
import { webhookEventNameSchema } from './webhooks.js'
|
|
22
|
+
|
|
23
|
+
/** Common envelope wrapping every webhook payload. */
|
|
24
|
+
const envelope = <N extends string, D extends z.ZodTypeAny>(name: N, data: D) =>
|
|
25
|
+
z.object({
|
|
26
|
+
id: idSchema,
|
|
27
|
+
type: z.literal(name),
|
|
28
|
+
apiVersion: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
29
|
+
mode: modeSchema,
|
|
30
|
+
createdAt: isoTimestampSchema,
|
|
31
|
+
data,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// ---------- Payment ----------
|
|
35
|
+
|
|
36
|
+
export const paymentCreatedEventSchema = envelope('payment.created', paymentSessionSchema)
|
|
37
|
+
export const paymentCompletedEventSchema = envelope(
|
|
38
|
+
'payment.completed',
|
|
39
|
+
z.object({ session: paymentSessionSchema, transaction: transactionSchema }),
|
|
40
|
+
)
|
|
41
|
+
export const paymentFailedEventSchema = envelope(
|
|
42
|
+
'payment.failed',
|
|
43
|
+
z.object({ session: paymentSessionSchema, reason: z.string() }),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
// ---------- Subscription ----------
|
|
47
|
+
|
|
48
|
+
export const subscriptionCreatedEventSchema = envelope('subscription.created', subscriptionSchema)
|
|
49
|
+
export const subscriptionChargedEventSchema = envelope(
|
|
50
|
+
'subscription.charged',
|
|
51
|
+
z.object({
|
|
52
|
+
subscription: subscriptionSchema,
|
|
53
|
+
charge: subscriptionChargeSchema,
|
|
54
|
+
transaction: transactionSchema,
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
export const subscriptionChargeFailedEventSchema = envelope(
|
|
58
|
+
'subscription.charge_failed',
|
|
59
|
+
z.object({ subscription: subscriptionSchema, charge: subscriptionChargeSchema }),
|
|
60
|
+
)
|
|
61
|
+
export const subscriptionRecoveryAttemptEventSchema = envelope(
|
|
62
|
+
'subscription.recovery_attempt',
|
|
63
|
+
z.object({ subscription: subscriptionSchema, attemptNumber: z.number().int().min(1) }),
|
|
64
|
+
)
|
|
65
|
+
export const subscriptionRecoveryOutcomeEventSchema = envelope(
|
|
66
|
+
'subscription.recovery_outcome',
|
|
67
|
+
z.object({
|
|
68
|
+
subscription: subscriptionSchema,
|
|
69
|
+
outcome: z.enum(['recovered', 'churned']),
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
export const subscriptionCancelledEventSchema = envelope(
|
|
73
|
+
'subscription.cancelled',
|
|
74
|
+
subscriptionSchema,
|
|
75
|
+
)
|
|
76
|
+
export const subscriptionLapsedEventSchema = envelope('subscription.lapsed', subscriptionSchema)
|
|
77
|
+
|
|
78
|
+
// ---------- Refund ----------
|
|
79
|
+
|
|
80
|
+
export const refundCreatedEventSchema = envelope('refund.created', refundSchema)
|
|
81
|
+
export const refundCompletedEventSchema = envelope(
|
|
82
|
+
'refund.completed',
|
|
83
|
+
z.object({ refund: refundSchema, transaction: transactionSchema }),
|
|
84
|
+
)
|
|
85
|
+
export const refundFailedEventSchema = envelope(
|
|
86
|
+
'refund.failed',
|
|
87
|
+
z.object({ refund: refundSchema, reason: z.string() }),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
// ---------- Invoice ----------
|
|
91
|
+
|
|
92
|
+
export const invoiceCreatedEventSchema = envelope('invoice.created', invoiceSchema)
|
|
93
|
+
export const invoicePaidEventSchema = envelope(
|
|
94
|
+
'invoice.paid',
|
|
95
|
+
z.object({ invoice: invoiceSchema, transaction: transactionSchema }),
|
|
96
|
+
)
|
|
97
|
+
export const invoiceOverdueEventSchema = envelope('invoice.overdue', invoiceSchema)
|
|
98
|
+
|
|
99
|
+
// ---------- Agent ----------
|
|
100
|
+
|
|
101
|
+
export const agentActionExecutedEventSchema = envelope(
|
|
102
|
+
'agent.action_executed',
|
|
103
|
+
agentActivityLogSchema,
|
|
104
|
+
)
|
|
105
|
+
export const agentJobProposedEventSchema = envelope('agent.job_proposed', agentJobSchema)
|
|
106
|
+
export const agentJobCompletedEventSchema = envelope('agent.job_completed', agentJobSchema)
|
|
107
|
+
export const agentJobDisputedEventSchema = envelope('agent.job_disputed', agentJobSchema)
|
|
108
|
+
|
|
109
|
+
// ---------- Compliance ----------
|
|
110
|
+
|
|
111
|
+
export const complianceWalletFlaggedEventSchema = envelope(
|
|
112
|
+
'compliance.wallet_flagged',
|
|
113
|
+
complianceLogSchema,
|
|
114
|
+
)
|
|
115
|
+
export const complianceWalletBlockedEventSchema = envelope(
|
|
116
|
+
'compliance.wallet_blocked',
|
|
117
|
+
complianceLogSchema,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
// ---------- Discriminated union ----------
|
|
121
|
+
|
|
122
|
+
export const webhookEventSchema = z.discriminatedUnion('type', [
|
|
123
|
+
paymentCreatedEventSchema,
|
|
124
|
+
paymentCompletedEventSchema,
|
|
125
|
+
paymentFailedEventSchema,
|
|
126
|
+
subscriptionCreatedEventSchema,
|
|
127
|
+
subscriptionChargedEventSchema,
|
|
128
|
+
subscriptionChargeFailedEventSchema,
|
|
129
|
+
subscriptionRecoveryAttemptEventSchema,
|
|
130
|
+
subscriptionRecoveryOutcomeEventSchema,
|
|
131
|
+
subscriptionCancelledEventSchema,
|
|
132
|
+
subscriptionLapsedEventSchema,
|
|
133
|
+
refundCreatedEventSchema,
|
|
134
|
+
refundCompletedEventSchema,
|
|
135
|
+
refundFailedEventSchema,
|
|
136
|
+
invoiceCreatedEventSchema,
|
|
137
|
+
invoicePaidEventSchema,
|
|
138
|
+
invoiceOverdueEventSchema,
|
|
139
|
+
agentActionExecutedEventSchema,
|
|
140
|
+
agentJobProposedEventSchema,
|
|
141
|
+
agentJobCompletedEventSchema,
|
|
142
|
+
agentJobDisputedEventSchema,
|
|
143
|
+
complianceWalletFlaggedEventSchema,
|
|
144
|
+
complianceWalletBlockedEventSchema,
|
|
145
|
+
])
|
|
146
|
+
export type StrimzWebhookEvent = z.infer<typeof webhookEventSchema>
|
|
147
|
+
|
|
148
|
+
/** Per-event-name inferred payload types. */
|
|
149
|
+
export type PaymentCreatedEvent = z.infer<typeof paymentCreatedEventSchema>
|
|
150
|
+
export type PaymentCompletedEvent = z.infer<typeof paymentCompletedEventSchema>
|
|
151
|
+
export type PaymentFailedEvent = z.infer<typeof paymentFailedEventSchema>
|
|
152
|
+
export type SubscriptionCreatedEvent = z.infer<typeof subscriptionCreatedEventSchema>
|
|
153
|
+
export type SubscriptionChargedEvent = z.infer<typeof subscriptionChargedEventSchema>
|
|
154
|
+
export type SubscriptionChargeFailedEvent = z.infer<typeof subscriptionChargeFailedEventSchema>
|
|
155
|
+
export type SubscriptionRecoveryAttemptEvent = z.infer<
|
|
156
|
+
typeof subscriptionRecoveryAttemptEventSchema
|
|
157
|
+
>
|
|
158
|
+
export type SubscriptionRecoveryOutcomeEvent = z.infer<
|
|
159
|
+
typeof subscriptionRecoveryOutcomeEventSchema
|
|
160
|
+
>
|
|
161
|
+
export type SubscriptionCancelledEvent = z.infer<typeof subscriptionCancelledEventSchema>
|
|
162
|
+
export type SubscriptionLapsedEvent = z.infer<typeof subscriptionLapsedEventSchema>
|
|
163
|
+
export type RefundCreatedEvent = z.infer<typeof refundCreatedEventSchema>
|
|
164
|
+
export type RefundCompletedEvent = z.infer<typeof refundCompletedEventSchema>
|
|
165
|
+
export type RefundFailedEvent = z.infer<typeof refundFailedEventSchema>
|
|
166
|
+
export type InvoiceCreatedEvent = z.infer<typeof invoiceCreatedEventSchema>
|
|
167
|
+
export type InvoicePaidEvent = z.infer<typeof invoicePaidEventSchema>
|
|
168
|
+
export type InvoiceOverdueEvent = z.infer<typeof invoiceOverdueEventSchema>
|
|
169
|
+
export type AgentActionExecutedEvent = z.infer<typeof agentActionExecutedEventSchema>
|
|
170
|
+
export type AgentJobProposedEvent = z.infer<typeof agentJobProposedEventSchema>
|
|
171
|
+
export type AgentJobCompletedEvent = z.infer<typeof agentJobCompletedEventSchema>
|
|
172
|
+
export type AgentJobDisputedEvent = z.infer<typeof agentJobDisputedEventSchema>
|
|
173
|
+
export type ComplianceWalletFlaggedEvent = z.infer<typeof complianceWalletFlaggedEventSchema>
|
|
174
|
+
export type ComplianceWalletBlockedEvent = z.infer<typeof complianceWalletBlockedEventSchema>
|
|
175
|
+
|
|
176
|
+
export { webhookEventNameSchema }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @strimz/shared-types
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas and inferred TypeScript types for every platform entity,
|
|
5
|
+
* API input, and webhook event. The schema is the source of truth; types
|
|
6
|
+
* are inferred from schemas so wire format and compile-time shape never drift.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from './common.js'
|
|
10
|
+
export * from './merchants.js'
|
|
11
|
+
export * from './api-keys.js'
|
|
12
|
+
export * from './customers.js'
|
|
13
|
+
export * from './payment-sessions.js'
|
|
14
|
+
export * from './transactions.js'
|
|
15
|
+
export * from './subscriptions.js'
|
|
16
|
+
export * from './refunds.js'
|
|
17
|
+
export * from './webhooks.js'
|
|
18
|
+
export * from './compliance.js'
|
|
19
|
+
export * from './agents.js'
|
|
20
|
+
export * from './storefronts.js'
|
|
21
|
+
export * from './invoices.js'
|
|
22
|
+
export * from './events.js'
|
|
23
|
+
export * from './tokens.js'
|
package/src/invoices.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoices — shareable, expirable payment requests with structured line items.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
import {
|
|
7
|
+
emailSchema,
|
|
8
|
+
idSchema,
|
|
9
|
+
isoTimestampSchema,
|
|
10
|
+
paymentCurrencySchema,
|
|
11
|
+
tokenAmountSchema,
|
|
12
|
+
} from './common.js'
|
|
13
|
+
|
|
14
|
+
export const invoiceStatusSchema = z.enum(['draft', 'sent', 'paid', 'overdue', 'void'])
|
|
15
|
+
export type InvoiceStatus = z.infer<typeof invoiceStatusSchema>
|
|
16
|
+
|
|
17
|
+
export const invoiceLineItemSchema = z.object({
|
|
18
|
+
description: z.string().min(1).max(500),
|
|
19
|
+
quantity: z.number().int().min(1).max(10_000),
|
|
20
|
+
unitAmount: tokenAmountSchema,
|
|
21
|
+
})
|
|
22
|
+
export type InvoiceLineItem = z.infer<typeof invoiceLineItemSchema>
|
|
23
|
+
|
|
24
|
+
export const invoiceSchema = z.object({
|
|
25
|
+
id: idSchema,
|
|
26
|
+
merchantId: idSchema,
|
|
27
|
+
number: z.string().min(1).max(40),
|
|
28
|
+
customerName: z.string().min(1).max(200).nullable(),
|
|
29
|
+
customerEmail: emailSchema.nullable(),
|
|
30
|
+
lineItems: z.array(invoiceLineItemSchema).nonempty(),
|
|
31
|
+
subtotal: tokenAmountSchema,
|
|
32
|
+
total: tokenAmountSchema,
|
|
33
|
+
currency: paymentCurrencySchema,
|
|
34
|
+
status: invoiceStatusSchema,
|
|
35
|
+
note: z.string().max(2000).nullable(),
|
|
36
|
+
sessionId: idSchema.nullable(),
|
|
37
|
+
dueAt: isoTimestampSchema,
|
|
38
|
+
paidAt: isoTimestampSchema.nullable(),
|
|
39
|
+
sentAt: isoTimestampSchema.nullable(),
|
|
40
|
+
createdAt: isoTimestampSchema,
|
|
41
|
+
updatedAt: isoTimestampSchema,
|
|
42
|
+
})
|
|
43
|
+
export type Invoice = z.infer<typeof invoiceSchema>
|
|
44
|
+
|
|
45
|
+
export const createInvoiceInputSchema = z.object({
|
|
46
|
+
customerName: z.string().min(1).max(200).optional(),
|
|
47
|
+
customerEmail: emailSchema.optional(),
|
|
48
|
+
lineItems: z.array(invoiceLineItemSchema).nonempty(),
|
|
49
|
+
currency: paymentCurrencySchema,
|
|
50
|
+
note: z.string().max(2000).optional(),
|
|
51
|
+
dueInDays: z.number().int().min(1).max(90).default(7),
|
|
52
|
+
})
|
|
53
|
+
export type CreateInvoiceInput = z.infer<typeof createInvoiceInputSchema>
|
package/src/merchants.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merchant entity and lifecycle DTOs.
|
|
3
|
+
*
|
|
4
|
+
* A merchant is the platform's first-class tenant. Merchants have a tier,
|
|
5
|
+
* a payout wallet address, and an on-chain merchantId registered in the
|
|
6
|
+
* StrimzRegistry contract.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
import {
|
|
11
|
+
emailSchema,
|
|
12
|
+
evmAddressSchema,
|
|
13
|
+
idSchema,
|
|
14
|
+
isoTimestampSchema,
|
|
15
|
+
merchantTierSchema,
|
|
16
|
+
metadataSchema,
|
|
17
|
+
} from './common.js'
|
|
18
|
+
|
|
19
|
+
export const merchantStatusSchema = z.enum(['active', 'suspended', 'closed'])
|
|
20
|
+
export type MerchantStatus = z.infer<typeof merchantStatusSchema>
|
|
21
|
+
|
|
22
|
+
export const merchantRoleSchema = z.enum(['owner', 'admin', 'developer', 'read_only'])
|
|
23
|
+
export type MerchantRole = z.infer<typeof merchantRoleSchema>
|
|
24
|
+
|
|
25
|
+
export const merchantSchema = z.object({
|
|
26
|
+
id: idSchema,
|
|
27
|
+
onchainMerchantId: z.number().int().nonnegative().nullable(),
|
|
28
|
+
businessName: z.string().min(2).max(120),
|
|
29
|
+
email: emailSchema,
|
|
30
|
+
tier: merchantTierSchema,
|
|
31
|
+
status: merchantStatusSchema,
|
|
32
|
+
payoutAddress: evmAddressSchema.nullable(),
|
|
33
|
+
defaultCurrency: z.enum(['USDC', 'EURC']),
|
|
34
|
+
countryCode: z.string().length(2).nullable(),
|
|
35
|
+
websiteUrl: z.string().url().nullable(),
|
|
36
|
+
logoUrl: z.string().url().nullable(),
|
|
37
|
+
whitelabelEnabled: z.boolean(),
|
|
38
|
+
metadata: metadataSchema,
|
|
39
|
+
createdAt: isoTimestampSchema,
|
|
40
|
+
updatedAt: isoTimestampSchema,
|
|
41
|
+
})
|
|
42
|
+
export type Merchant = z.infer<typeof merchantSchema>
|
|
43
|
+
|
|
44
|
+
// ---------- DTOs ----------
|
|
45
|
+
|
|
46
|
+
export const createMerchantInputSchema = z.object({
|
|
47
|
+
businessName: z.string().min(2).max(120),
|
|
48
|
+
email: emailSchema,
|
|
49
|
+
password: z.string().min(12).max(128),
|
|
50
|
+
countryCode: z.string().length(2).optional(),
|
|
51
|
+
websiteUrl: z.string().url().optional(),
|
|
52
|
+
})
|
|
53
|
+
export type CreateMerchantInput = z.infer<typeof createMerchantInputSchema>
|
|
54
|
+
|
|
55
|
+
export const updateMerchantInputSchema = z
|
|
56
|
+
.object({
|
|
57
|
+
businessName: z.string().min(2).max(120),
|
|
58
|
+
payoutAddress: evmAddressSchema,
|
|
59
|
+
defaultCurrency: z.enum(['USDC', 'EURC']),
|
|
60
|
+
websiteUrl: z.string().url().nullable(),
|
|
61
|
+
logoUrl: z.string().url().nullable(),
|
|
62
|
+
countryCode: z.string().length(2).nullable(),
|
|
63
|
+
metadata: metadataSchema,
|
|
64
|
+
})
|
|
65
|
+
.partial()
|
|
66
|
+
export type UpdateMerchantInput = z.infer<typeof updateMerchantInputSchema>
|
|
67
|
+
|
|
68
|
+
export const changeTierInputSchema = z.object({
|
|
69
|
+
tier: merchantTierSchema,
|
|
70
|
+
})
|
|
71
|
+
export type ChangeTierInput = z.infer<typeof changeTierInputSchema>
|
|
72
|
+
|
|
73
|
+
// ---------- Team members ----------
|
|
74
|
+
|
|
75
|
+
export const merchantMemberSchema = z.object({
|
|
76
|
+
id: idSchema,
|
|
77
|
+
merchantId: idSchema,
|
|
78
|
+
email: emailSchema,
|
|
79
|
+
role: merchantRoleSchema,
|
|
80
|
+
invitedAt: isoTimestampSchema,
|
|
81
|
+
acceptedAt: isoTimestampSchema.nullable(),
|
|
82
|
+
})
|
|
83
|
+
export type MerchantMember = z.infer<typeof merchantMemberSchema>
|
|
84
|
+
|
|
85
|
+
export const inviteMemberInputSchema = z.object({
|
|
86
|
+
email: emailSchema,
|
|
87
|
+
role: merchantRoleSchema,
|
|
88
|
+
})
|
|
89
|
+
export type InviteMemberInput = z.infer<typeof inviteMemberInputSchema>
|
|
90
|
+
|
|
91
|
+
// ---------- Auth ----------
|
|
92
|
+
|
|
93
|
+
export const loginInputSchema = z.object({
|
|
94
|
+
email: emailSchema,
|
|
95
|
+
password: z.string().min(1).max(128),
|
|
96
|
+
})
|
|
97
|
+
export type LoginInput = z.infer<typeof loginInputSchema>
|
|
98
|
+
|
|
99
|
+
export const loginOutputSchema = z.object({
|
|
100
|
+
accessToken: z.string(),
|
|
101
|
+
refreshToken: z.string(),
|
|
102
|
+
merchant: merchantSchema,
|
|
103
|
+
})
|
|
104
|
+
export type LoginOutput = z.infer<typeof loginOutputSchema>
|