@strimz/shared-types 0.7.0 → 0.8.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.
@@ -29,24 +29,24 @@ declare const webhookEndpointSchema: z.ZodObject<{
29
29
  createdAt: z.ZodString;
30
30
  updatedAt: z.ZodString;
31
31
  }, "strip", z.ZodTypeAny, {
32
- status: "disabled" | "active";
33
- id: string;
34
- merchantId: string;
32
+ status: "active" | "disabled";
35
33
  mode: "test" | "live";
36
- createdAt: string;
34
+ merchantId: string;
37
35
  description: string | null;
36
+ id: string;
37
+ createdAt: string;
38
38
  updatedAt: string;
39
39
  url: string;
40
40
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
41
41
  signingSecretPrefix: string;
42
42
  lastDeliveredAt: string | null;
43
43
  }, {
44
- status: "disabled" | "active";
45
- id: string;
46
- merchantId: string;
44
+ status: "active" | "disabled";
47
45
  mode: "test" | "live";
48
- createdAt: string;
46
+ merchantId: string;
49
47
  description: string | null;
48
+ id: string;
49
+ createdAt: string;
50
50
  updatedAt: string;
51
51
  url: string;
52
52
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -86,24 +86,24 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
86
86
  createdAt: z.ZodString;
87
87
  updatedAt: z.ZodString;
88
88
  }, "strip", z.ZodTypeAny, {
89
- status: "disabled" | "active";
90
- id: string;
91
- merchantId: string;
89
+ status: "active" | "disabled";
92
90
  mode: "test" | "live";
93
- createdAt: string;
91
+ merchantId: string;
94
92
  description: string | null;
93
+ id: string;
94
+ createdAt: string;
95
95
  updatedAt: string;
96
96
  url: string;
97
97
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
98
98
  signingSecretPrefix: string;
99
99
  lastDeliveredAt: string | null;
100
100
  }, {
101
- status: "disabled" | "active";
102
- id: string;
103
- merchantId: string;
101
+ status: "active" | "disabled";
104
102
  mode: "test" | "live";
105
- createdAt: string;
103
+ merchantId: string;
106
104
  description: string | null;
105
+ id: string;
106
+ createdAt: string;
107
107
  updatedAt: string;
108
108
  url: string;
109
109
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -114,12 +114,12 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
114
114
  signingSecret: z.ZodString;
115
115
  }, "strip", z.ZodTypeAny, {
116
116
  endpoint: {
117
- status: "disabled" | "active";
118
- id: string;
119
- merchantId: string;
117
+ status: "active" | "disabled";
120
118
  mode: "test" | "live";
121
- createdAt: string;
119
+ merchantId: string;
122
120
  description: string | null;
121
+ id: string;
122
+ createdAt: string;
123
123
  updatedAt: string;
124
124
  url: string;
125
125
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -129,12 +129,12 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
129
129
  signingSecret: string;
130
130
  }, {
131
131
  endpoint: {
132
- status: "disabled" | "active";
133
- id: string;
134
- merchantId: string;
132
+ status: "active" | "disabled";
135
133
  mode: "test" | "live";
136
- createdAt: string;
134
+ merchantId: string;
137
135
  description: string | null;
136
+ id: string;
137
+ createdAt: string;
138
138
  updatedAt: string;
139
139
  url: string;
140
140
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -162,8 +162,8 @@ declare const webhookDeliverySchema: z.ZodObject<{
162
162
  createdAt: z.ZodString;
163
163
  }, "strip", z.ZodTypeAny, {
164
164
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
165
- id: string;
166
165
  merchantId: string;
166
+ id: string;
167
167
  createdAt: string;
168
168
  endpointId: string;
169
169
  eventId: string;
@@ -176,8 +176,8 @@ declare const webhookDeliverySchema: z.ZodObject<{
176
176
  deliveredAt: string | null;
177
177
  }, {
178
178
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
179
- id: string;
180
179
  merchantId: string;
180
+ id: string;
181
181
  createdAt: string;
182
182
  endpointId: string;
183
183
  eventId: string;
@@ -215,8 +215,8 @@ declare const webhookDeliveryDetailSchema: z.ZodObject<{
215
215
  requestPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
216
216
  }, "strip", z.ZodTypeAny, {
217
217
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
218
- id: string;
219
218
  merchantId: string;
219
+ id: string;
220
220
  createdAt: string;
221
221
  endpointId: string;
222
222
  eventId: string;
@@ -232,8 +232,8 @@ declare const webhookDeliveryDetailSchema: z.ZodObject<{
232
232
  requestPayload: Record<string, unknown>;
233
233
  }, {
234
234
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
235
- id: string;
236
235
  merchantId: string;
236
+ id: string;
237
237
  createdAt: string;
238
238
  endpointId: string;
239
239
  eventId: string;
@@ -29,24 +29,24 @@ declare const webhookEndpointSchema: z.ZodObject<{
29
29
  createdAt: z.ZodString;
30
30
  updatedAt: z.ZodString;
31
31
  }, "strip", z.ZodTypeAny, {
32
- status: "disabled" | "active";
33
- id: string;
34
- merchantId: string;
32
+ status: "active" | "disabled";
35
33
  mode: "test" | "live";
36
- createdAt: string;
34
+ merchantId: string;
37
35
  description: string | null;
36
+ id: string;
37
+ createdAt: string;
38
38
  updatedAt: string;
39
39
  url: string;
40
40
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
41
41
  signingSecretPrefix: string;
42
42
  lastDeliveredAt: string | null;
43
43
  }, {
44
- status: "disabled" | "active";
45
- id: string;
46
- merchantId: string;
44
+ status: "active" | "disabled";
47
45
  mode: "test" | "live";
48
- createdAt: string;
46
+ merchantId: string;
49
47
  description: string | null;
48
+ id: string;
49
+ createdAt: string;
50
50
  updatedAt: string;
51
51
  url: string;
52
52
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -86,24 +86,24 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
86
86
  createdAt: z.ZodString;
87
87
  updatedAt: z.ZodString;
88
88
  }, "strip", z.ZodTypeAny, {
89
- status: "disabled" | "active";
90
- id: string;
91
- merchantId: string;
89
+ status: "active" | "disabled";
92
90
  mode: "test" | "live";
93
- createdAt: string;
91
+ merchantId: string;
94
92
  description: string | null;
93
+ id: string;
94
+ createdAt: string;
95
95
  updatedAt: string;
96
96
  url: string;
97
97
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
98
98
  signingSecretPrefix: string;
99
99
  lastDeliveredAt: string | null;
100
100
  }, {
101
- status: "disabled" | "active";
102
- id: string;
103
- merchantId: string;
101
+ status: "active" | "disabled";
104
102
  mode: "test" | "live";
105
- createdAt: string;
103
+ merchantId: string;
106
104
  description: string | null;
105
+ id: string;
106
+ createdAt: string;
107
107
  updatedAt: string;
108
108
  url: string;
109
109
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -114,12 +114,12 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
114
114
  signingSecret: z.ZodString;
115
115
  }, "strip", z.ZodTypeAny, {
116
116
  endpoint: {
117
- status: "disabled" | "active";
118
- id: string;
119
- merchantId: string;
117
+ status: "active" | "disabled";
120
118
  mode: "test" | "live";
121
- createdAt: string;
119
+ merchantId: string;
122
120
  description: string | null;
121
+ id: string;
122
+ createdAt: string;
123
123
  updatedAt: string;
124
124
  url: string;
125
125
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -129,12 +129,12 @@ declare const createWebhookEndpointOutputSchema: z.ZodObject<{
129
129
  signingSecret: string;
130
130
  }, {
131
131
  endpoint: {
132
- status: "disabled" | "active";
133
- id: string;
134
- merchantId: string;
132
+ status: "active" | "disabled";
135
133
  mode: "test" | "live";
136
- createdAt: string;
134
+ merchantId: string;
137
135
  description: string | null;
136
+ id: string;
137
+ createdAt: string;
138
138
  updatedAt: string;
139
139
  url: string;
140
140
  events: ["payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked", ...("payment.created" | "payment.completed" | "payment.failed" | "subscription.created" | "subscription.charged" | "subscription.charge_failed" | "subscription.recovery_attempt" | "subscription.recovery_outcome" | "subscription.cancelled" | "subscription.lapsed" | "refund.created" | "refund.completed" | "refund.failed" | "invoice.created" | "invoice.paid" | "invoice.overdue" | "agent.action_executed" | "agent.job_proposed" | "agent.job_completed" | "agent.job_disputed" | "compliance.wallet_flagged" | "compliance.wallet_blocked")[]];
@@ -162,8 +162,8 @@ declare const webhookDeliverySchema: z.ZodObject<{
162
162
  createdAt: z.ZodString;
163
163
  }, "strip", z.ZodTypeAny, {
164
164
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
165
- id: string;
166
165
  merchantId: string;
166
+ id: string;
167
167
  createdAt: string;
168
168
  endpointId: string;
169
169
  eventId: string;
@@ -176,8 +176,8 @@ declare const webhookDeliverySchema: z.ZodObject<{
176
176
  deliveredAt: string | null;
177
177
  }, {
178
178
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
179
- id: string;
180
179
  merchantId: string;
180
+ id: string;
181
181
  createdAt: string;
182
182
  endpointId: string;
183
183
  eventId: string;
@@ -215,8 +215,8 @@ declare const webhookDeliveryDetailSchema: z.ZodObject<{
215
215
  requestPayload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
216
216
  }, "strip", z.ZodTypeAny, {
217
217
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
218
- id: string;
219
218
  merchantId: string;
219
+ id: string;
220
220
  createdAt: string;
221
221
  endpointId: string;
222
222
  eventId: string;
@@ -232,8 +232,8 @@ declare const webhookDeliveryDetailSchema: z.ZodObject<{
232
232
  requestPayload: Record<string, unknown>;
233
233
  }, {
234
234
  status: "pending" | "retrying" | "delivered" | "permanently_failed";
235
- id: string;
236
235
  merchantId: string;
236
+ id: string;
237
237
  createdAt: string;
238
238
  endpointId: string;
239
239
  eventId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strimz/shared-types",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Zod schemas and inferred TypeScript types for every Strimz platform entity, API input, and webhook event.",
5
5
  "license": "MIT",
6
6
  "author": "Strimz <hello@strimz.finance>",
@@ -103,6 +103,11 @@
103
103
  "types": "./dist/events.d.ts",
104
104
  "import": "./dist/events.js",
105
105
  "require": "./dist/events.cjs"
106
+ },
107
+ "./analytics": {
108
+ "types": "./dist/analytics.d.ts",
109
+ "import": "./dist/analytics.js",
110
+ "require": "./dist/analytics.cjs"
106
111
  }
107
112
  },
108
113
  "files": [
@@ -0,0 +1,275 @@
1
+ import { z } from 'zod'
2
+ import {
3
+ idSchema,
4
+ isoTimestampSchema,
5
+ modeSchema,
6
+ paymentCurrencySchema,
7
+ tokenAmountSchema,
8
+ uintSchema,
9
+ type PaymentCurrency,
10
+ } from './common.js'
11
+ import { invoiceStatusSchema } from './invoices.js'
12
+ import { paymentSessionStatusSchema } from './payment-sessions.js'
13
+ import { refundStatusSchema } from './refunds.js'
14
+ import { subscriptionStatusSchema } from './subscriptions.js'
15
+
16
+ export const paymentCurrencies = paymentCurrencySchema.options
17
+
18
+ const currencyAmountsShape = {
19
+ USDC: tokenAmountSchema,
20
+ EURC: tokenAmountSchema,
21
+ } satisfies Record<PaymentCurrency, typeof tokenAmountSchema>
22
+
23
+ export const currencyAmountsSchema = z.object(currencyAmountsShape).strict()
24
+ export type CurrencyAmounts = z.infer<typeof currencyAmountsSchema>
25
+
26
+ function countsByStatusSchema<T extends [string, ...string[]]>(statuses: z.ZodEnum<T>) {
27
+ const shape = Object.fromEntries(statuses.options.map((s) => [s, uintSchema])) as {
28
+ [K in T[number]]: typeof uintSchema
29
+ }
30
+ return z.object(shape).strict()
31
+ }
32
+
33
+ export const moneySchema = z.object({
34
+ count: uintSchema,
35
+ amount: currencyAmountsSchema,
36
+ })
37
+ export type Money = z.infer<typeof moneySchema>
38
+
39
+ export const volumeWindowSchema = z.object({
40
+ count: uintSchema,
41
+ gross: currencyAmountsSchema,
42
+ fees: currencyAmountsSchema,
43
+ net: currencyAmountsSchema,
44
+ })
45
+ export type VolumeWindow = z.infer<typeof volumeWindowSchema>
46
+
47
+ export const statsSummarySchema = z.object({
48
+ mode: modeSchema,
49
+ generatedAt: isoTimestampSchema,
50
+ volume: z.object({
51
+ last7d: volumeWindowSchema,
52
+ last30d: volumeWindowSchema,
53
+ allTime: volumeWindowSchema,
54
+ }),
55
+ paymentSessions: z.object({
56
+ total: uintSchema,
57
+ byStatus: countsByStatusSchema(paymentSessionStatusSchema),
58
+ confirmed: moneySchema,
59
+ }),
60
+ invoices: z.object({
61
+ byStatus: countsByStatusSchema(invoiceStatusSchema),
62
+ outstanding: moneySchema,
63
+ overdue: moneySchema,
64
+ paidLast30d: moneySchema,
65
+ }),
66
+ refunds: z.object({
67
+ byStatus: countsByStatusSchema(refundStatusSchema),
68
+ completed: moneySchema,
69
+ }),
70
+ subscriptions: z.object({
71
+ total: uintSchema,
72
+ byStatus: countsByStatusSchema(subscriptionStatusSchema),
73
+ }),
74
+ customers: z.object({
75
+ total: uintSchema,
76
+ }),
77
+ })
78
+ export type StatsSummary = z.infer<typeof statsSummarySchema>
79
+
80
+ export const STATS_VOLUME_MAX_DAYS = 366
81
+ export const STATS_VOLUME_DEFAULT_DAYS = 30
82
+
83
+ export function resolveStatsVolumeRange(
84
+ query: { from?: string; to?: string },
85
+ now: number = Date.now(),
86
+ ): { from: Date; to: Date } {
87
+ const to = query.to ? new Date(query.to) : new Date(now)
88
+ const from = query.from
89
+ ? new Date(query.from)
90
+ : new Date(to.getTime() - STATS_VOLUME_DEFAULT_DAYS * 86_400_000)
91
+ return { from, to }
92
+ }
93
+
94
+ export const statsVolumeQuerySchema = z
95
+ .object({
96
+ from: isoTimestampSchema.optional(),
97
+ to: isoTimestampSchema.optional(),
98
+ })
99
+ .strict()
100
+ .superRefine((q, ctx) => {
101
+ const { from, to } = resolveStatsVolumeRange(q)
102
+ if (from.getTime() > to.getTime()) {
103
+ ctx.addIssue({
104
+ code: z.ZodIssueCode.custom,
105
+ message: 'from must not be after to',
106
+ path: ['from'],
107
+ })
108
+ } else if (to.getTime() - from.getTime() > STATS_VOLUME_MAX_DAYS * 86_400_000) {
109
+ ctx.addIssue({
110
+ code: z.ZodIssueCode.custom,
111
+ message: `from and to must be at most ${STATS_VOLUME_MAX_DAYS} days apart`,
112
+ path: ['to'],
113
+ })
114
+ }
115
+ })
116
+ export type StatsVolumeQuery = z.infer<typeof statsVolumeQuerySchema>
117
+
118
+ const dayKeySchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'must be a YYYY-MM-DD day')
119
+
120
+ export const statsVolumeDaySchema = z.object({
121
+ day: dayKeySchema,
122
+ currency: paymentCurrencySchema,
123
+ count: uintSchema,
124
+ gross: tokenAmountSchema,
125
+ fees: tokenAmountSchema,
126
+ net: tokenAmountSchema,
127
+ })
128
+ export type StatsVolumeDay = z.infer<typeof statsVolumeDaySchema>
129
+
130
+ export const statsVolumeSchema = z.object({
131
+ from: isoTimestampSchema,
132
+ to: isoTimestampSchema,
133
+ data: z.array(statsVolumeDaySchema),
134
+ })
135
+ export type StatsVolume = z.infer<typeof statsVolumeSchema>
136
+
137
+ export const statsMrrSchema = z.object({
138
+ mrr: currencyAmountsSchema,
139
+ activeSubscribers: uintSchema,
140
+ })
141
+ export type StatsMrr = z.infer<typeof statsMrrSchema>
142
+
143
+ export const statsLtvQuerySchema = z
144
+ .object({
145
+ currency: paymentCurrencySchema,
146
+ limit: z.coerce.number().int().min(1).max(100).default(25),
147
+ cursor: z.string().min(1).max(200).optional(),
148
+ })
149
+ .strict()
150
+ export type StatsLtvQuery = z.input<typeof statsLtvQuerySchema>
151
+ export type StatsLtvQueryParsed = z.output<typeof statsLtvQuerySchema>
152
+
153
+ export const statsLtvRowSchema = z.object({
154
+ customerId: idSchema,
155
+ totalSpend: tokenAmountSchema,
156
+ transactionCount: uintSchema,
157
+ })
158
+ export type StatsLtvRow = z.infer<typeof statsLtvRowSchema>
159
+
160
+ export const statsLtvSchema = z.object({
161
+ currency: paymentCurrencySchema,
162
+ data: z.array(statsLtvRowSchema),
163
+ nextCursor: z.string().nullable(),
164
+ hasMore: z.boolean(),
165
+ })
166
+ export type StatsLtv = z.infer<typeof statsLtvSchema>
167
+
168
+ export const forecastConfidenceSchema = z.enum(['low', 'medium', 'high'])
169
+ export type ForecastConfidence = z.infer<typeof forecastConfidenceSchema>
170
+
171
+ export const forecastSchema = z.object({
172
+ confidence: forecastConfidenceSchema,
173
+ last90DayRevenue: tokenAmountSchema,
174
+ next30: tokenAmountSchema,
175
+ next60: tokenAmountSchema,
176
+ next90: tokenAmountSchema,
177
+ })
178
+ export type Forecast = z.infer<typeof forecastSchema>
179
+
180
+ const forecastByCurrencyShape = {
181
+ USDC: forecastSchema,
182
+ EURC: forecastSchema,
183
+ } satisfies Record<PaymentCurrency, typeof forecastSchema>
184
+
185
+ export const statsForecastSchema = z.object({
186
+ byCurrency: z.object(forecastByCurrencyShape).strict(),
187
+ })
188
+ export type StatsForecast = z.infer<typeof statsForecastSchema>
189
+
190
+ export const adminStatsModeQuerySchema = z
191
+ .object({
192
+ mode: modeSchema.default('live'),
193
+ })
194
+ .strict()
195
+ export type AdminStatsModeQuery = z.input<typeof adminStatsModeQuerySchema>
196
+
197
+ export const adminOverviewSchema = z.object({
198
+ mode: modeSchema,
199
+ merchants: z.object({
200
+ total: uintSchema,
201
+ byStatus: z.record(z.string(), uintSchema),
202
+ last30dSignups: uintSchema,
203
+ }),
204
+ volume: z.object({
205
+ lifetime: currencyAmountsSchema,
206
+ lifetimeFees: currencyAmountsSchema,
207
+ last30d: currencyAmountsSchema,
208
+ confirmedSessions: uintSchema,
209
+ }),
210
+ subscriptions: z.object({
211
+ active: uintSchema,
212
+ mrr: currencyAmountsSchema,
213
+ }),
214
+ })
215
+ export type AdminOverview = z.infer<typeof adminOverviewSchema>
216
+
217
+ export const adminMerchantStatsSchema = z.object({
218
+ mode: modeSchema,
219
+ confirmedPayments: uintSchema,
220
+ activeSubscriptions: uintSchema,
221
+ lifetimeVolume: currencyAmountsSchema,
222
+ last30dVolume: currencyAmountsSchema,
223
+ })
224
+ export type AdminMerchantStats = z.infer<typeof adminMerchantStatsSchema>
225
+
226
+ export const adminVolumeQuerySchema = z
227
+ .object({
228
+ from: isoTimestampSchema.optional(),
229
+ to: isoTimestampSchema.optional(),
230
+ mode: modeSchema.default('live'),
231
+ })
232
+ .strict()
233
+ export type AdminVolumeQuery = z.input<typeof adminVolumeQuerySchema>
234
+
235
+ export const adminVolumeDaySchema = z.object({
236
+ day: dayKeySchema,
237
+ currency: paymentCurrencySchema,
238
+ volume: tokenAmountSchema,
239
+ fees: tokenAmountSchema,
240
+ count: uintSchema,
241
+ })
242
+ export type AdminVolumeDay = z.infer<typeof adminVolumeDaySchema>
243
+
244
+ export const adminVolumeSeriesSchema = z.object({
245
+ mode: modeSchema,
246
+ from: isoTimestampSchema,
247
+ to: isoTimestampSchema,
248
+ data: z.array(adminVolumeDaySchema),
249
+ })
250
+ export type AdminVolumeSeries = z.infer<typeof adminVolumeSeriesSchema>
251
+
252
+ export const adminTopMerchantsQuerySchema = z
253
+ .object({
254
+ currency: paymentCurrencySchema,
255
+ mode: modeSchema.default('live'),
256
+ limit: z.coerce.number().int().min(1).max(50).default(10),
257
+ })
258
+ .strict()
259
+ export type AdminTopMerchantsQuery = z.input<typeof adminTopMerchantsQuerySchema>
260
+
261
+ export const adminTopMerchantSchema = z.object({
262
+ merchantId: idSchema,
263
+ businessName: z.string().nullable(),
264
+ email: z.string(),
265
+ volume: tokenAmountSchema,
266
+ transactionCount: uintSchema,
267
+ })
268
+ export type AdminTopMerchant = z.infer<typeof adminTopMerchantSchema>
269
+
270
+ export const adminTopMerchantsSchema = z.object({
271
+ mode: modeSchema,
272
+ currency: paymentCurrencySchema,
273
+ data: z.array(adminTopMerchantSchema),
274
+ })
275
+ export type AdminTopMerchants = z.infer<typeof adminTopMerchantsSchema>
package/src/index.ts CHANGED
@@ -23,3 +23,4 @@ export * from './events.js'
23
23
  export * from './tokens.js'
24
24
  export * from './contact.js'
25
25
  export * from './notifications.js'
26
+ export * from './analytics.js'