@strimz/shared-types 0.6.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.
Files changed (85) hide show
  1. package/README.md +7 -4
  2. package/dist/agents.cjs.map +1 -1
  3. package/dist/agents.d.cts +7 -5
  4. package/dist/agents.d.ts +7 -5
  5. package/dist/agents.js.map +1 -1
  6. package/dist/analytics.cjs +568 -0
  7. package/dist/analytics.cjs.map +1 -0
  8. package/dist/analytics.d.cts +1719 -0
  9. package/dist/analytics.d.ts +1719 -0
  10. package/dist/analytics.js +540 -0
  11. package/dist/analytics.js.map +1 -0
  12. package/dist/api-keys.cjs.map +1 -1
  13. package/dist/api-keys.d.cts +19 -17
  14. package/dist/api-keys.d.ts +19 -17
  15. package/dist/api-keys.js.map +1 -1
  16. package/dist/common.cjs.map +1 -1
  17. package/dist/common.d.cts +3 -2
  18. package/dist/common.d.ts +3 -2
  19. package/dist/common.js.map +1 -1
  20. package/dist/compliance.cjs.map +1 -1
  21. package/dist/compliance.d.cts +8 -8
  22. package/dist/compliance.d.ts +8 -8
  23. package/dist/compliance.js.map +1 -1
  24. package/dist/customers.cjs.map +1 -1
  25. package/dist/customers.d.cts +10 -9
  26. package/dist/customers.d.ts +10 -9
  27. package/dist/customers.js.map +1 -1
  28. package/dist/events.cjs.map +1 -1
  29. package/dist/events.d.cts +1936 -1936
  30. package/dist/events.d.ts +1936 -1936
  31. package/dist/events.js.map +1 -1
  32. package/dist/index.cjs +216 -0
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +25 -22
  35. package/dist/index.d.ts +25 -22
  36. package/dist/index.js +190 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/invoices.cjs.map +1 -1
  39. package/dist/invoices.d.cts +19 -18
  40. package/dist/invoices.d.ts +19 -18
  41. package/dist/invoices.js.map +1 -1
  42. package/dist/merchants.cjs.map +1 -1
  43. package/dist/merchants.d.cts +42 -36
  44. package/dist/merchants.d.ts +42 -36
  45. package/dist/merchants.js.map +1 -1
  46. package/dist/payment-sessions.cjs.map +1 -1
  47. package/dist/payment-sessions.d.cts +24 -22
  48. package/dist/payment-sessions.d.ts +24 -22
  49. package/dist/payment-sessions.js.map +1 -1
  50. package/dist/refunds.cjs.map +1 -1
  51. package/dist/refunds.d.cts +55 -53
  52. package/dist/refunds.d.ts +55 -53
  53. package/dist/refunds.js.map +1 -1
  54. package/dist/storefronts.cjs.map +1 -1
  55. package/dist/storefronts.d.cts +31 -28
  56. package/dist/storefronts.d.ts +31 -28
  57. package/dist/storefronts.js.map +1 -1
  58. package/dist/subscriptions.cjs.map +1 -1
  59. package/dist/subscriptions.d.cts +49 -46
  60. package/dist/subscriptions.d.ts +49 -46
  61. package/dist/subscriptions.js.map +1 -1
  62. package/dist/transactions.cjs.map +1 -1
  63. package/dist/transactions.d.cts +14 -14
  64. package/dist/transactions.d.ts +14 -14
  65. package/dist/transactions.js.map +1 -1
  66. package/dist/webhooks.cjs.map +1 -1
  67. package/dist/webhooks.d.cts +33 -31
  68. package/dist/webhooks.d.ts +33 -31
  69. package/dist/webhooks.js.map +1 -1
  70. package/package.json +6 -1
  71. package/src/agents.ts +4 -2
  72. package/src/analytics.ts +275 -0
  73. package/src/api-keys.ts +4 -2
  74. package/src/common.ts +2 -1
  75. package/src/contact.ts +2 -1
  76. package/src/customers.ts +2 -1
  77. package/src/index.ts +1 -0
  78. package/src/invoices.ts +2 -1
  79. package/src/merchants.ts +12 -6
  80. package/src/notifications.ts +2 -1
  81. package/src/payment-sessions.ts +4 -2
  82. package/src/refunds.ts +4 -2
  83. package/src/storefronts.ts +6 -3
  84. package/src/subscriptions.ts +6 -3
  85. package/src/webhooks.ts +4 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/common.ts","../src/webhooks.ts"],"names":["z"],"mappings":";;;AAQO,IAAM,QAAA,GAAW,CAAA,CACrB,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,E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"webhooks.js","sourcesContent":["/**\n * Primitive schemas shared across every entity.\n * Every higher-level schema builds on these so validation is consistent.\n */\n\nimport { z } from 'zod'\n\n/** CUID2 or UUID-style opaque identifier. */\nexport const idSchema = z\n .string()\n .min(1)\n .max(64)\n .regex(/^[a-zA-Z0-9_-]+$/, 'id must be URL-safe')\n\n/** EVM address. Hex-encoded, 0x-prefixed, 20 bytes. Normalised to lowercase. */\nexport const evmAddressSchema = z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, 'must be a 0x-prefixed 40-character hex EVM address')\n .transform((v) => v.toLowerCase())\n\n/** EVM transaction hash. 32-byte hex. */\nexport const evmTxHashSchema = z\n .string()\n .regex(/^0x[a-fA-F0-9]{64}$/, 'must be a 0x-prefixed 64-character hex EVM transaction hash')\n\n/** Email address, trimmed and lower-cased. */\nexport const emailSchema = z.string().email().trim().toLowerCase().max(320)\n\n/** HTTPS URL. No http:// allowed outside dev. */\nexport const httpsUrlSchema = z\n .string()\n .url()\n .refine((v) => v.startsWith('https://'), {\n message: 'must be an https:// URL',\n })\n\n/** URL permitting http and https (dev + prod). */\nexport const httpUrlSchema = z.string().url()\n\n/**\n * Amount expressed in the token's smallest unit, serialised as a string to\n * preserve precision beyond `Number.MAX_SAFE_INTEGER`. For USDC (6 decimals),\n * 1 USDC is the string \"1000000\".\n */\nexport const tokenAmountSchema = z\n .string()\n .regex(/^[0-9]+$/, 'must be a non-negative integer string (base-10)')\n .refine((v) => BigInt(v) >= 0n, 'must be >= 0')\n\n/** Unsigned integer up to 2^53 - 1; validated and returned as number. */\nexport const uintSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)\n\n/** ISO-8601 timestamp string (`.toISOString()`-compatible). */\nexport const isoTimestampSchema = z\n .string()\n .datetime({ offset: true, message: 'must be an ISO-8601 timestamp' })\n\n/** Two-letter ISO-3166 country code. */\nexport const countryCodeSchema = z\n .string()\n .length(2)\n .regex(/^[A-Z]{2}$/, 'must be an ISO-3166 alpha-2 country code')\n\n/** Pagination inputs used by every list endpoint. */\nexport const paginationInputSchema = z.object({\n limit: z.number().int().min(1).max(100).default(25),\n cursor: z.string().min(1).max(200).nullish(),\n})\nexport type PaginationInput = z.infer<typeof paginationInputSchema>\n\n/** Pagination envelope used by every list response. */\nexport const makePaginatedSchema = <T extends z.ZodTypeAny>(item: T) =>\n z.object({\n data: z.array(item),\n nextCursor: z.string().nullable(),\n hasMore: z.boolean(),\n })\n\n/** Free-form metadata bag the API round-trips for merchants. */\nexport const metadataSchema = z\n .record(\n z.string().min(1).max(40),\n z.union([z.string().max(500), z.number(), z.boolean(), z.null()]),\n )\n .refine((m) => Object.keys(m).length <= 50, 'at most 50 metadata keys')\n .default({})\n\n/** Environment mode carried on every mode-scoped resource. */\nexport const modeSchema = z.enum(['test', 'live'])\nexport type Mode = z.infer<typeof modeSchema>\n\n/** Payment token enum. */\nexport const paymentCurrencySchema = z.enum(['USDC', 'EURC'])\nexport type PaymentCurrency = z.infer<typeof paymentCurrencySchema>\n\n/** Every display-level currency (payment + treasury). */\nexport const tokenSymbolSchema = z.enum(['USDC', 'EURC', 'USYC'])\nexport type TokenSymbol = z.infer<typeof tokenSymbolSchema>\n\n/** Merchant tier enum. */\nexport const merchantTierSchema = z.enum(['free', 'growth', 'business', 'enterprise'])\nexport type MerchantTier = z.infer<typeof merchantTierSchema>\n\n/** Arc environment enum. */\nexport const arcEnvironmentSchema = z.enum(['testnet', 'mainnet'])\nexport type ArcEnvironment = z.infer<typeof arcEnvironmentSchema>\n\nexport type Id = z.infer<typeof idSchema>\nexport type EvmAddress = z.infer<typeof evmAddressSchema>\nexport type EvmTxHash = z.infer<typeof evmTxHashSchema>\nexport type TokenAmount = z.infer<typeof tokenAmountSchema>\nexport type IsoTimestamp = z.infer<typeof isoTimestampSchema>\nexport type Metadata = z.infer<typeof metadataSchema>\n","/**\n * Webhook endpoints and deliveries.\n *\n * Endpoint = the URL the merchant registered.\n * Event = the thing that happened.\n * Delivery = one attempt to POST a specific event to a specific endpoint.\n */\n\nimport { z } from 'zod'\nimport { httpsUrlSchema, idSchema, isoTimestampSchema, modeSchema } from './common.js'\n\n// ---------- Event name ----------\n\n/**\n * Every webhook event name in the system. Listed inline so Zod can\n * produce a concrete string union.\n */\nexport const webhookEventNameSchema = z.enum([\n 'payment.created',\n 'payment.completed',\n 'payment.failed',\n 'subscription.created',\n 'subscription.charged',\n 'subscription.charge_failed',\n 'subscription.recovery_attempt',\n 'subscription.recovery_outcome',\n 'subscription.cancelled',\n 'subscription.lapsed',\n 'refund.created',\n 'refund.completed',\n 'refund.failed',\n 'invoice.created',\n 'invoice.paid',\n 'invoice.overdue',\n 'agent.action_executed',\n 'agent.job_proposed',\n 'agent.job_completed',\n 'agent.job_disputed',\n 'compliance.wallet_flagged',\n 'compliance.wallet_blocked',\n])\nexport type WebhookEventName = z.infer<typeof webhookEventNameSchema>\n\n// ---------- Endpoints ----------\n\nexport const webhookEndpointStatusSchema = z.enum(['active', 'disabled'])\nexport type WebhookEndpointStatus = z.infer<typeof webhookEndpointStatusSchema>\n\nexport const webhookEndpointSchema = z.object({\n id: idSchema,\n merchantId: idSchema,\n mode: modeSchema,\n url: httpsUrlSchema,\n description: z.string().max(200).nullable(),\n events: z.array(webhookEventNameSchema).nonempty(),\n status: webhookEndpointStatusSchema,\n signingSecretPrefix: z.string().min(4).max(12),\n lastDeliveredAt: isoTimestampSchema.nullable(),\n createdAt: isoTimestampSchema,\n updatedAt: isoTimestampSchema,\n})\nexport type WebhookEndpoint = z.infer<typeof webhookEndpointSchema>\n\nexport const createWebhookEndpointInputSchema = z.object({\n url: httpsUrlSchema,\n events: z.array(webhookEventNameSchema).nonempty(),\n description: z.string().max(200).optional(),\n mode: modeSchema,\n})\nexport type CreateWebhookEndpointInput = z.infer<typeof createWebhookEndpointInputSchema>\n\nexport const createWebhookEndpointOutputSchema = z.object({\n endpoint: webhookEndpointSchema,\n /** Full signing secret. Shown exactly once. */\n signingSecret: z.string(),\n})\nexport type CreateWebhookEndpointOutput = z.infer<typeof createWebhookEndpointOutputSchema>\n\n// ---------- Deliveries ----------\n\nexport const webhookDeliveryStatusSchema = z.enum([\n 'pending',\n 'delivered',\n 'retrying',\n 'permanently_failed',\n])\nexport type WebhookDeliveryStatus = z.infer<typeof webhookDeliveryStatusSchema>\n\nexport const webhookDeliverySchema = z.object({\n id: idSchema,\n merchantId: idSchema,\n endpointId: idSchema,\n eventId: idSchema,\n eventName: webhookEventNameSchema,\n status: webhookDeliveryStatusSchema,\n attempt: z.number().int().min(1).max(6),\n responseCode: z.number().int().min(100).max(599).nullable(),\n responseMs: z.number().int().min(0).nullable(),\n lastError: z.string().max(1000).nullable(),\n nextAttemptAt: isoTimestampSchema.nullable(),\n deliveredAt: isoTimestampSchema.nullable(),\n createdAt: isoTimestampSchema,\n})\nexport type WebhookDelivery = z.infer<typeof webhookDeliverySchema>\n\n/**\n * Detail projection returned by GET /v1/webhook-deliveries/:id.\n * Carries the payload envelope, response body, and the deliveryId\n * header the receiver saw. Kept separate so list responses stay slim.\n */\nexport const webhookDeliveryDetailSchema = webhookDeliverySchema.extend({\n deliveryId: z.string(),\n responseBody: z.string().nullable(),\n requestPayload: z.record(z.string(), z.unknown()),\n})\nexport type WebhookDeliveryDetail = z.infer<typeof webhookDeliveryDetailSchema>\n\nexport const replayDeliveryInputSchema = z.object({\n id: idSchema,\n})\nexport type ReplayDeliveryInput = z.infer<typeof replayDeliveryInputSchema>\n"]}
1
+ {"version":3,"sources":["../src/common.ts","../src/webhooks.ts"],"names":["z"],"mappings":";;;AAQO,IAAM,QAAA,GAAW,CAAA,CACrB,MAAA,EAAO,CACP,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,EAAE,CAAA,CACN,KAAA,CAAM,kBAAA,EAAoB,qBAAqB,CAAA;AAGlB,CAAA,CAC7B,MAAA,EAAO,CACP,KAAA,CAAM,qBAAA,EAAuB,oDAAoD,CAAA,CACjF,SAAA,CAAU,CAAC,CAAA,KAAM,CAAA,CAAE,aA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;AAAA,EACZ,UAAA,EAAY,QAAA;AAAA,EACZ,OAAA,EAAS,QAAA;AAAA,EACT,SAAA,EAAW,sBAAA;AAAA,EACX,MAAA,EAAQ,2BAAA;AAAA,EACR,OAAA,EAASA,CAAAA,CAAE,MAAA,EAAO,CAAE,GAAA,GAAM,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA;AAAA,EACtC,YAAA,EAAcA,CAAAA,CAAE,MAAA,EAAO,CAAE,GAAA,EAAI,CAAE,GAAA,CAAI,GAAG,CAAA,CAAE,GAAA,CAAI,GAAG,CAAA,CAAE,QAAA,EAAS;AAAA,EAC1D,UAAA,EAAYA,EAAE,MAAA,EAAO,CAAE,KAAI,CAAE,GAAA,CAAI,CAAC,CAAA,CAAE,QAAA,EAAS;AAAA,EAC7C,WAAWA,CAAAA,CAAE,MAAA,GAAS,GAAA,CAAI,GAAI,EAAE,QAAA,EAAS;AAAA,EACzC,aAAA,EAAe,mBAAmB,QAAA,EAAS;AAAA,EAC3C,WAAA,EAAa,mBAAmB,QAAA,EAAS;AAAA,EACzC,SAAA,EAAW;AACb,CAAC;AAQM,IAAM,2BAAA,GAA8B,sBAAsB,MAAA,CAAO;AAAA,EACtE,UAAA,EAAYA,EAAE,MAAA,EAAO;AAAA,EACrB,YAAA,EAAcA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAClC,cAAA,EAAgBA,EAAE,MAAA,CAAOA,CAAAA,CAAE,QAAO,EAAGA,CAAAA,CAAE,SAAS;AAClD,CAAC;AAGM,IAAM,yBAAA,GAA4BA,EAAE,MAAA,CAAO;AAAA,EAChD,EAAA,EAAI;AACN,CAAC","file":"webhooks.js","sourcesContent":["/**\n * Primitive schemas shared across every entity.\n * Every higher-level schema builds on these so validation is consistent.\n */\n\nimport { z } from 'zod'\n\n/** CUID2 or UUID-style opaque identifier. */\nexport const idSchema = z\n .string()\n .min(1)\n .max(64)\n .regex(/^[a-zA-Z0-9_-]+$/, 'id must be URL-safe')\n\n/** EVM address. Hex-encoded, 0x-prefixed, 20 bytes. Normalised to lowercase. */\nexport const evmAddressSchema = z\n .string()\n .regex(/^0x[a-fA-F0-9]{40}$/, 'must be a 0x-prefixed 40-character hex EVM address')\n .transform((v) => v.toLowerCase())\n\n/** EVM transaction hash. 32-byte hex. */\nexport const evmTxHashSchema = z\n .string()\n .regex(/^0x[a-fA-F0-9]{64}$/, 'must be a 0x-prefixed 64-character hex EVM transaction hash')\n\n/** Email address, trimmed and lower-cased. */\nexport const emailSchema = z.string().email().trim().toLowerCase().max(320)\n\n/** HTTPS URL. No http:// allowed outside dev. */\nexport const httpsUrlSchema = z\n .string()\n .url()\n .refine((v) => v.startsWith('https://'), {\n message: 'must be an https:// URL',\n })\n\n/** URL permitting http and https (dev + prod). */\nexport const httpUrlSchema = z.string().url()\n\n/**\n * Amount expressed in the token's smallest unit, serialised as a string to\n * preserve precision beyond `Number.MAX_SAFE_INTEGER`. For USDC (6 decimals),\n * 1 USDC is the string \"1000000\".\n */\nexport const tokenAmountSchema = z\n .string()\n .regex(/^[0-9]+$/, 'must be a non-negative integer string (base-10)')\n .refine((v) => BigInt(v) >= 0n, 'must be >= 0')\n\n/** Unsigned integer up to 2^53 - 1; validated and returned as number. */\nexport const uintSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)\n\n/** ISO-8601 timestamp string (`.toISOString()`-compatible). */\nexport const isoTimestampSchema = z\n .string()\n .datetime({ offset: true, message: 'must be an ISO-8601 timestamp' })\n\n/** Two-letter ISO-3166 country code. */\nexport const countryCodeSchema = z\n .string()\n .length(2)\n .regex(/^[A-Z]{2}$/, 'must be an ISO-3166 alpha-2 country code')\n\n/** Pagination inputs used by every list endpoint. */\nexport const paginationInputSchema = z.object({\n limit: z.number().int().min(1).max(100).default(25),\n cursor: z.string().min(1).max(200).nullish(),\n})\nexport type PaginationInput = z.input<typeof paginationInputSchema>\nexport type PaginationParsed = z.output<typeof paginationInputSchema>\n\n/** Pagination envelope used by every list response. */\nexport const makePaginatedSchema = <T extends z.ZodTypeAny>(item: T) =>\n z.object({\n data: z.array(item),\n nextCursor: z.string().nullable(),\n hasMore: z.boolean(),\n })\n\n/** Free-form metadata bag the API round-trips for merchants. */\nexport const metadataSchema = z\n .record(\n z.string().min(1).max(40),\n z.union([z.string().max(500), z.number(), z.boolean(), z.null()]),\n )\n .refine((m) => Object.keys(m).length <= 50, 'at most 50 metadata keys')\n .default({})\n\n/** Environment mode carried on every mode-scoped resource. */\nexport const modeSchema = z.enum(['test', 'live'])\nexport type Mode = z.infer<typeof modeSchema>\n\n/** Payment token enum. */\nexport const paymentCurrencySchema = z.enum(['USDC', 'EURC'])\nexport type PaymentCurrency = z.infer<typeof paymentCurrencySchema>\n\n/** Every display-level currency (payment + treasury). */\nexport const tokenSymbolSchema = z.enum(['USDC', 'EURC', 'USYC'])\nexport type TokenSymbol = z.infer<typeof tokenSymbolSchema>\n\n/** Merchant tier enum. */\nexport const merchantTierSchema = z.enum(['free', 'growth', 'business', 'enterprise'])\nexport type MerchantTier = z.infer<typeof merchantTierSchema>\n\n/** Arc environment enum. */\nexport const arcEnvironmentSchema = z.enum(['testnet', 'mainnet'])\nexport type ArcEnvironment = z.infer<typeof arcEnvironmentSchema>\n\nexport type Id = z.infer<typeof idSchema>\nexport type EvmAddress = z.infer<typeof evmAddressSchema>\nexport type EvmTxHash = z.infer<typeof evmTxHashSchema>\nexport type TokenAmount = z.infer<typeof tokenAmountSchema>\nexport type IsoTimestamp = z.infer<typeof isoTimestampSchema>\nexport type Metadata = z.infer<typeof metadataSchema>\n","/**\n * Webhook endpoints and deliveries.\n *\n * Endpoint = the URL the merchant registered.\n * Event = the thing that happened.\n * Delivery = one attempt to POST a specific event to a specific endpoint.\n */\n\nimport { z } from 'zod'\nimport { httpsUrlSchema, idSchema, isoTimestampSchema, modeSchema } from './common.js'\n\n// ---------- Event name ----------\n\n/**\n * Every webhook event name in the system. Listed inline so Zod can\n * produce a concrete string union.\n */\nexport const webhookEventNameSchema = z.enum([\n 'payment.created',\n 'payment.completed',\n 'payment.failed',\n 'subscription.created',\n 'subscription.charged',\n 'subscription.charge_failed',\n 'subscription.recovery_attempt',\n 'subscription.recovery_outcome',\n 'subscription.cancelled',\n 'subscription.lapsed',\n 'refund.created',\n 'refund.completed',\n 'refund.failed',\n 'invoice.created',\n 'invoice.paid',\n 'invoice.overdue',\n 'agent.action_executed',\n 'agent.job_proposed',\n 'agent.job_completed',\n 'agent.job_disputed',\n 'compliance.wallet_flagged',\n 'compliance.wallet_blocked',\n])\nexport type WebhookEventName = z.infer<typeof webhookEventNameSchema>\n\n// ---------- Endpoints ----------\n\nexport const webhookEndpointStatusSchema = z.enum(['active', 'disabled'])\nexport type WebhookEndpointStatus = z.infer<typeof webhookEndpointStatusSchema>\n\nexport const webhookEndpointSchema = z.object({\n id: idSchema,\n merchantId: idSchema,\n mode: modeSchema,\n url: httpsUrlSchema,\n description: z.string().max(200).nullable(),\n events: z.array(webhookEventNameSchema).nonempty(),\n status: webhookEndpointStatusSchema,\n signingSecretPrefix: z.string().min(4).max(12),\n lastDeliveredAt: isoTimestampSchema.nullable(),\n createdAt: isoTimestampSchema,\n updatedAt: isoTimestampSchema,\n})\nexport type WebhookEndpoint = z.infer<typeof webhookEndpointSchema>\n\nexport const createWebhookEndpointInputSchema = z.object({\n url: httpsUrlSchema,\n events: z.array(webhookEventNameSchema).nonempty(),\n description: z.string().max(200).optional(),\n mode: modeSchema,\n})\nexport type CreateWebhookEndpointInput = z.input<typeof createWebhookEndpointInputSchema>\nexport type CreateWebhookEndpointParsed = z.output<typeof createWebhookEndpointInputSchema>\n\nexport const createWebhookEndpointOutputSchema = z.object({\n endpoint: webhookEndpointSchema,\n /** Full signing secret. Shown exactly once. */\n signingSecret: z.string(),\n})\nexport type CreateWebhookEndpointOutput = z.infer<typeof createWebhookEndpointOutputSchema>\n\n// ---------- Deliveries ----------\n\nexport const webhookDeliveryStatusSchema = z.enum([\n 'pending',\n 'delivered',\n 'retrying',\n 'permanently_failed',\n])\nexport type WebhookDeliveryStatus = z.infer<typeof webhookDeliveryStatusSchema>\n\nexport const webhookDeliverySchema = z.object({\n id: idSchema,\n merchantId: idSchema,\n endpointId: idSchema,\n eventId: idSchema,\n eventName: webhookEventNameSchema,\n status: webhookDeliveryStatusSchema,\n attempt: z.number().int().min(1).max(6),\n responseCode: z.number().int().min(100).max(599).nullable(),\n responseMs: z.number().int().min(0).nullable(),\n lastError: z.string().max(1000).nullable(),\n nextAttemptAt: isoTimestampSchema.nullable(),\n deliveredAt: isoTimestampSchema.nullable(),\n createdAt: isoTimestampSchema,\n})\nexport type WebhookDelivery = z.infer<typeof webhookDeliverySchema>\n\n/**\n * Detail projection returned by GET /v1/webhook-deliveries/:id.\n * Carries the payload envelope, response body, and the deliveryId\n * header the receiver saw. Kept separate so list responses stay slim.\n */\nexport const webhookDeliveryDetailSchema = webhookDeliverySchema.extend({\n deliveryId: z.string(),\n responseBody: z.string().nullable(),\n requestPayload: z.record(z.string(), z.unknown()),\n})\nexport type WebhookDeliveryDetail = z.infer<typeof webhookDeliveryDetailSchema>\n\nexport const replayDeliveryInputSchema = z.object({\n id: idSchema,\n})\nexport type ReplayDeliveryInput = z.input<typeof replayDeliveryInputSchema>\nexport type ReplayDeliveryParsed = z.output<typeof replayDeliveryInputSchema>\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strimz/shared-types",
3
- "version": "0.6.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": [
package/src/agents.ts CHANGED
@@ -65,7 +65,8 @@ export type AgentMerchantConfig = z.infer<typeof agentMerchantConfigSchema>
65
65
  export const updateAgentConfigInputSchema = agentMerchantConfigSchema
66
66
  .omit({ merchantId: true, updatedAt: true })
67
67
  .partial()
68
- export type UpdateAgentConfigInput = z.infer<typeof updateAgentConfigInputSchema>
68
+ export type UpdateAgentConfigInput = z.input<typeof updateAgentConfigInputSchema>
69
+ export type UpdateAgentConfigParsed = z.output<typeof updateAgentConfigInputSchema>
69
70
 
70
71
  // ---------- Activity log ----------
71
72
 
@@ -153,4 +154,5 @@ export const createAgentJobInputSchema = z.object({
153
154
  currency: z.enum(['USDC', 'EURC']),
154
155
  assessorAddress: evmAddressSchema.optional(),
155
156
  })
156
- export type CreateAgentJobInput = z.infer<typeof createAgentJobInputSchema>
157
+ export type CreateAgentJobInput = z.input<typeof createAgentJobInputSchema>
158
+ export type CreateAgentJobParsed = z.output<typeof createAgentJobInputSchema>
@@ -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/api-keys.ts CHANGED
@@ -71,7 +71,8 @@ export const createApiKeyInputSchema = z.object({
71
71
  mode: modeSchema,
72
72
  scopes: z.array(apiKeyScopeSchema).nonempty(),
73
73
  })
74
- export type CreateApiKeyInput = z.infer<typeof createApiKeyInputSchema>
74
+ export type CreateApiKeyInput = z.input<typeof createApiKeyInputSchema>
75
+ export type CreateApiKeyParsed = z.output<typeof createApiKeyInputSchema>
75
76
 
76
77
  export const createApiKeyOutputSchema = z.object({
77
78
  apiKey: apiKeySchema,
@@ -83,4 +84,5 @@ export type CreateApiKeyOutput = z.infer<typeof createApiKeyOutputSchema>
83
84
  export const rotateApiKeyInputSchema = z.object({
84
85
  id: idSchema,
85
86
  })
86
- export type RotateApiKeyInput = z.infer<typeof rotateApiKeyInputSchema>
87
+ export type RotateApiKeyInput = z.input<typeof rotateApiKeyInputSchema>
88
+ export type RotateApiKeyParsed = z.output<typeof rotateApiKeyInputSchema>
package/src/common.ts CHANGED
@@ -66,7 +66,8 @@ export const paginationInputSchema = z.object({
66
66
  limit: z.number().int().min(1).max(100).default(25),
67
67
  cursor: z.string().min(1).max(200).nullish(),
68
68
  })
69
- export type PaginationInput = z.infer<typeof paginationInputSchema>
69
+ export type PaginationInput = z.input<typeof paginationInputSchema>
70
+ export type PaginationParsed = z.output<typeof paginationInputSchema>
70
71
 
71
72
  /** Pagination envelope used by every list response. */
72
73
  export const makePaginatedSchema = <T extends z.ZodTypeAny>(item: T) =>
package/src/contact.ts CHANGED
@@ -18,7 +18,8 @@ export const contactRequestInputSchema = z.object({
18
18
  topic: contactTopicSchema,
19
19
  message: z.string().min(20).max(4000),
20
20
  })
21
- export type ContactRequestInput = z.infer<typeof contactRequestInputSchema>
21
+ export type ContactRequestInput = z.input<typeof contactRequestInputSchema>
22
+ export type ContactRequestParsed = z.output<typeof contactRequestInputSchema>
22
23
 
23
24
  export const contactRequestOutputSchema = z.object({
24
25
  ok: z.literal(true),
package/src/customers.ts CHANGED
@@ -37,4 +37,5 @@ export const upsertCustomerInputSchema = z.object({
37
37
  displayName: z.string().min(1).max(120).optional(),
38
38
  metadata: metadataSchema.optional(),
39
39
  })
40
- export type UpsertCustomerInput = z.infer<typeof upsertCustomerInputSchema>
40
+ export type UpsertCustomerInput = z.input<typeof upsertCustomerInputSchema>
41
+ export type UpsertCustomerParsed = z.output<typeof upsertCustomerInputSchema>
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'
package/src/invoices.ts CHANGED
@@ -50,4 +50,5 @@ export const createInvoiceInputSchema = z.object({
50
50
  note: z.string().max(2000).optional(),
51
51
  dueInDays: z.number().int().min(1).max(90).default(7),
52
52
  })
53
- export type CreateInvoiceInput = z.infer<typeof createInvoiceInputSchema>
53
+ export type CreateInvoiceInput = z.input<typeof createInvoiceInputSchema>
54
+ export type CreateInvoiceParsed = z.output<typeof createInvoiceInputSchema>
package/src/merchants.ts CHANGED
@@ -52,7 +52,8 @@ export const createMerchantInputSchema = z.object({
52
52
  countryCode: z.string().length(2).optional(),
53
53
  websiteUrl: z.string().url().optional(),
54
54
  })
55
- export type CreateMerchantInput = z.infer<typeof createMerchantInputSchema>
55
+ export type CreateMerchantInput = z.input<typeof createMerchantInputSchema>
56
+ export type CreateMerchantParsed = z.output<typeof createMerchantInputSchema>
56
57
 
57
58
  /**
58
59
  * Merchant email opt-outs, persisted at `Merchant.metadata.emailPrefs`.
@@ -83,12 +84,14 @@ export const updateMerchantInputSchema = z
83
84
  emailPrefs: merchantEmailPrefsSchema.partial(),
84
85
  })
85
86
  .partial()
86
- export type UpdateMerchantInput = z.infer<typeof updateMerchantInputSchema>
87
+ export type UpdateMerchantInput = z.input<typeof updateMerchantInputSchema>
88
+ export type UpdateMerchantParsed = z.output<typeof updateMerchantInputSchema>
87
89
 
88
90
  export const changeTierInputSchema = z.object({
89
91
  tier: merchantTierSchema,
90
92
  })
91
- export type ChangeTierInput = z.infer<typeof changeTierInputSchema>
93
+ export type ChangeTierInput = z.input<typeof changeTierInputSchema>
94
+ export type ChangeTierParsed = z.output<typeof changeTierInputSchema>
92
95
 
93
96
  /**
94
97
  * Self-attested onboarding form the dashboard collects after a
@@ -110,7 +113,8 @@ export const onboardMerchantInputSchema = z.object({
110
113
  payoutAddress: evmAddressSchema,
111
114
  defaultCurrency: z.enum(['USDC', 'EURC']).optional(),
112
115
  })
113
- export type OnboardMerchantInput = z.infer<typeof onboardMerchantInputSchema>
116
+ export type OnboardMerchantInput = z.input<typeof onboardMerchantInputSchema>
117
+ export type OnboardMerchantParsed = z.output<typeof onboardMerchantInputSchema>
114
118
 
115
119
  export const merchantPublicBrandSchema = z.object({
116
120
  id: idSchema,
@@ -170,7 +174,8 @@ export const inviteMemberInputSchema = z.object({
170
174
  email: emailSchema,
171
175
  role: merchantRoleSchema,
172
176
  })
173
- export type InviteMemberInput = z.infer<typeof inviteMemberInputSchema>
177
+ export type InviteMemberInput = z.input<typeof inviteMemberInputSchema>
178
+ export type InviteMemberParsed = z.output<typeof inviteMemberInputSchema>
174
179
 
175
180
  // ---------- Auth ----------
176
181
 
@@ -178,7 +183,8 @@ export const loginInputSchema = z.object({
178
183
  email: emailSchema,
179
184
  password: z.string().min(1).max(128),
180
185
  })
181
- export type LoginInput = z.infer<typeof loginInputSchema>
186
+ export type LoginInput = z.input<typeof loginInputSchema>
187
+ export type LoginParsed = z.output<typeof loginInputSchema>
182
188
 
183
189
  export const loginOutputSchema = z.object({
184
190
  accessToken: z.string(),
@@ -37,7 +37,8 @@ export const createBroadcastInputSchema = z
37
37
  message: 'merchantId is required when audience is merchant',
38
38
  path: ['merchantId'],
39
39
  })
40
- export type CreateBroadcastInput = z.infer<typeof createBroadcastInputSchema>
40
+ export type CreateBroadcastInput = z.input<typeof createBroadcastInputSchema>
41
+ export type CreateBroadcastParsed = z.output<typeof createBroadcastInputSchema>
41
42
 
42
43
  export const broadcastSchema = z.object({
43
44
  id: idSchema,
@@ -133,7 +133,8 @@ export const createPaymentSessionInputSchema = z.object({
133
133
  .optional(),
134
134
  metadata: metadataSchema.optional(),
135
135
  })
136
- export type CreatePaymentSessionInput = z.infer<typeof createPaymentSessionInputSchema>
136
+ export type CreatePaymentSessionInput = z.input<typeof createPaymentSessionInputSchema>
137
+ export type CreatePaymentSessionParsed = z.output<typeof createPaymentSessionInputSchema>
137
138
 
138
139
  export const submitPaymentSessionInputSchema = z.object({
139
140
  sourceChain: z.enum([
@@ -150,4 +151,5 @@ export const submitPaymentSessionInputSchema = z.object({
150
151
  bridgeTxHash: evmTxHashSchema.optional(),
151
152
  payerWalletAddress: evmAddressSchema,
152
153
  })
153
- export type SubmitPaymentSessionInput = z.infer<typeof submitPaymentSessionInputSchema>
154
+ export type SubmitPaymentSessionInput = z.input<typeof submitPaymentSessionInputSchema>
155
+ export type SubmitPaymentSessionParsed = z.output<typeof submitPaymentSessionInputSchema>
package/src/refunds.ts CHANGED
@@ -59,13 +59,15 @@ export const createRefundInputSchema = z.object({
59
59
  reason: refundReasonSchema,
60
60
  note: z.string().max(500).optional(),
61
61
  })
62
- export type CreateRefundInput = z.infer<typeof createRefundInputSchema>
62
+ export type CreateRefundInput = z.input<typeof createRefundInputSchema>
63
+ export type CreateRefundParsed = z.output<typeof createRefundInputSchema>
63
64
 
64
65
  export const submitRefundSignatureInputSchema = z.object({
65
66
  id: idSchema,
66
67
  refundTxHash: evmTxHashSchema,
67
68
  })
68
- export type SubmitRefundSignatureInput = z.infer<typeof submitRefundSignatureInputSchema>
69
+ export type SubmitRefundSignatureInput = z.input<typeof submitRefundSignatureInputSchema>
70
+ export type SubmitRefundSignatureParsed = z.output<typeof submitRefundSignatureInputSchema>
69
71
 
70
72
  /**
71
73
  * Response envelope for `POST /v1/refunds`. The API returns the newly
@@ -47,7 +47,8 @@ export const createStorefrontInputSchema = storefrontSchema.pick({
47
47
  accentColor: true,
48
48
  socialLinks: true,
49
49
  })
50
- export type CreateStorefrontInput = z.infer<typeof createStorefrontInputSchema>
50
+ export type CreateStorefrontInput = z.input<typeof createStorefrontInputSchema>
51
+ export type CreateStorefrontParsed = z.output<typeof createStorefrontInputSchema>
51
52
 
52
53
  // ---------- Products ----------
53
54
 
@@ -103,7 +104,8 @@ export const createStorefrontProductInputSchema = storefrontProductSchema
103
104
  })
104
105
  }
105
106
  })
106
- export type CreateStorefrontProductInput = z.infer<typeof createStorefrontProductInputSchema>
107
+ export type CreateStorefrontProductInput = z.input<typeof createStorefrontProductInputSchema>
108
+ export type CreateStorefrontProductParsed = z.output<typeof createStorefrontProductInputSchema>
107
109
 
108
110
  /**
109
111
  * Payload for the public `/store/:slug/products/:id/checkout` endpoint.
@@ -116,7 +118,8 @@ export const storefrontCheckoutInputSchema = z.object({
116
118
  customerEmail: z.string().email().optional(),
117
119
  returnPath: z.string().max(200).optional(),
118
120
  })
119
- export type StorefrontCheckoutInput = z.infer<typeof storefrontCheckoutInputSchema>
121
+ export type StorefrontCheckoutInput = z.input<typeof storefrontCheckoutInputSchema>
122
+ export type StorefrontCheckoutParsed = z.output<typeof storefrontCheckoutInputSchema>
120
123
 
121
124
  /** Response shape from the public product-checkout endpoint. */
122
125
  export const storefrontCheckoutResponseSchema = z.object({
@@ -81,7 +81,8 @@ export const createSubscriptionPlanInputSchema = z.object({
81
81
  trialPeriodDays: z.number().int().min(0).max(365).optional(),
82
82
  metadata: metadataSchema.optional(),
83
83
  })
84
- export type CreateSubscriptionPlanInput = z.infer<typeof createSubscriptionPlanInputSchema>
84
+ export type CreateSubscriptionPlanInput = z.input<typeof createSubscriptionPlanInputSchema>
85
+ export type CreateSubscriptionPlanParsed = z.output<typeof createSubscriptionPlanInputSchema>
85
86
 
86
87
  // ---------- Subscriptions ----------
87
88
 
@@ -143,13 +144,15 @@ export const createSubscriptionInputSchema = z.object({
143
144
  gracePeriodHours: z.union([z.literal(24), z.literal(48), z.literal(72)]).default(48),
144
145
  metadata: metadataSchema.optional(),
145
146
  })
146
- export type CreateSubscriptionInput = z.infer<typeof createSubscriptionInputSchema>
147
+ export type CreateSubscriptionInput = z.input<typeof createSubscriptionInputSchema>
148
+ export type CreateSubscriptionParsed = z.output<typeof createSubscriptionInputSchema>
147
149
 
148
150
  export const cancelSubscriptionInputSchema = z.object({
149
151
  id: idSchema,
150
152
  reason: z.string().max(500).optional(),
151
153
  })
152
- export type CancelSubscriptionInput = z.infer<typeof cancelSubscriptionInputSchema>
154
+ export type CancelSubscriptionInput = z.input<typeof cancelSubscriptionInputSchema>
155
+ export type CancelSubscriptionParsed = z.output<typeof cancelSubscriptionInputSchema>
153
156
 
154
157
  // ---------- Charges ----------
155
158
 
package/src/webhooks.ts CHANGED
@@ -67,7 +67,8 @@ export const createWebhookEndpointInputSchema = z.object({
67
67
  description: z.string().max(200).optional(),
68
68
  mode: modeSchema,
69
69
  })
70
- export type CreateWebhookEndpointInput = z.infer<typeof createWebhookEndpointInputSchema>
70
+ export type CreateWebhookEndpointInput = z.input<typeof createWebhookEndpointInputSchema>
71
+ export type CreateWebhookEndpointParsed = z.output<typeof createWebhookEndpointInputSchema>
71
72
 
72
73
  export const createWebhookEndpointOutputSchema = z.object({
73
74
  endpoint: webhookEndpointSchema,
@@ -118,4 +119,5 @@ export type WebhookDeliveryDetail = z.infer<typeof webhookDeliveryDetailSchema>
118
119
  export const replayDeliveryInputSchema = z.object({
119
120
  id: idSchema,
120
121
  })
121
- export type ReplayDeliveryInput = z.infer<typeof replayDeliveryInputSchema>
122
+ export type ReplayDeliveryInput = z.input<typeof replayDeliveryInputSchema>
123
+ export type ReplayDeliveryParsed = z.output<typeof replayDeliveryInputSchema>