@strimz/sdk 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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/dist/browser-client-DlZg0Aae.d.cts +223 -0
  4. package/dist/browser-client-DlZg0Aae.d.ts +223 -0
  5. package/dist/browser-client.cjs +443 -0
  6. package/dist/browser-client.cjs.map +1 -0
  7. package/dist/browser-client.d.cts +4 -0
  8. package/dist/browser-client.d.ts +4 -0
  9. package/dist/browser-client.js +439 -0
  10. package/dist/browser-client.js.map +1 -0
  11. package/dist/eip712.cjs +70 -0
  12. package/dist/eip712.cjs.map +1 -0
  13. package/dist/eip712.d.cts +181 -0
  14. package/dist/eip712.d.ts +181 -0
  15. package/dist/eip712.js +65 -0
  16. package/dist/eip712.js.map +1 -0
  17. package/dist/errors.cjs +102 -0
  18. package/dist/errors.cjs.map +1 -0
  19. package/dist/errors.d.cts +56 -0
  20. package/dist/errors.d.ts +56 -0
  21. package/dist/errors.js +90 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.cjs +831 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +193 -0
  26. package/dist/index.d.ts +193 -0
  27. package/dist/index.js +806 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/webhooks.cjs +54 -0
  30. package/dist/webhooks.cjs.map +1 -0
  31. package/dist/webhooks.d.cts +19 -0
  32. package/dist/webhooks.d.ts +19 -0
  33. package/dist/webhooks.js +13 -0
  34. package/dist/webhooks.js.map +1 -0
  35. package/package.json +94 -0
  36. package/src/browser-client.ts +97 -0
  37. package/src/client.ts +122 -0
  38. package/src/eip712/index.ts +25 -0
  39. package/src/eip712/permit.ts +74 -0
  40. package/src/eip712/receive-with-authorization.ts +88 -0
  41. package/src/eip712/types.ts +46 -0
  42. package/src/errors.ts +138 -0
  43. package/src/http/fetcher.ts +226 -0
  44. package/src/http/headers.ts +32 -0
  45. package/src/idempotency.ts +20 -0
  46. package/src/index.ts +77 -0
  47. package/src/pagination.ts +48 -0
  48. package/src/resources/agents.ts +64 -0
  49. package/src/resources/api-keys.ts +29 -0
  50. package/src/resources/base-resource.ts +116 -0
  51. package/src/resources/checkout.ts +32 -0
  52. package/src/resources/customers.ts +25 -0
  53. package/src/resources/invoices.ts +31 -0
  54. package/src/resources/merchants.ts +26 -0
  55. package/src/resources/payment-sessions.ts +41 -0
  56. package/src/resources/refunds.ts +36 -0
  57. package/src/resources/storefronts.ts +62 -0
  58. package/src/resources/subscription-plans.ts +32 -0
  59. package/src/resources/subscriptions.ts +37 -0
  60. package/src/resources/tokens.ts +70 -0
  61. package/src/resources/transactions.ts +20 -0
  62. package/src/resources/webhook-deliveries.ts +29 -0
  63. package/src/resources/webhook-endpoints.ts +56 -0
  64. package/src/webhooks.ts +64 -0
@@ -0,0 +1,70 @@
1
+ import {
2
+ tokenMetadataSchema,
3
+ tokenPermitNonceSchema,
4
+ type TokenMetadata,
5
+ type TokenPermitNonce,
6
+ } from '@strimz/shared-types'
7
+ import { BaseResource } from './base-resource.js'
8
+
9
+ /**
10
+ * Token metadata + capability lookup.
11
+ *
12
+ * The two endpoints are public on the API (no key required) — token
13
+ * metadata is purely chain-derived, has no PII, and is what the
14
+ * browser SDK consults to pick which meta-tx path to take for a
15
+ * given token. Bundled here so consumers don't have to write the HTTP
16
+ * fetch themselves.
17
+ */
18
+ export class TokensResource extends BaseResource {
19
+ /**
20
+ * Fetch full metadata for a token. Throws via the underlying fetcher
21
+ * (404 → `StrimzNotFoundError`) if the token isn't whitelisted.
22
+ */
23
+ retrieve(address: string): Promise<TokenMetadata> {
24
+ return this.get(`/v1/tokens/${encodeURIComponent(address.toLowerCase())}`, tokenMetadataSchema)
25
+ }
26
+
27
+ /**
28
+ * Read an owner's current EIP-2612 permit nonce. Call this
29
+ * immediately before signing a Permit — the token contract rejects
30
+ * stale nonces, and the value advances on every successful permit.
31
+ */
32
+ permitNonce(address: string, owner: string): Promise<TokenPermitNonce> {
33
+ return this.get(
34
+ `/v1/tokens/${encodeURIComponent(address.toLowerCase())}/permit-nonce`,
35
+ tokenPermitNonceSchema,
36
+ { owner: owner.toLowerCase() },
37
+ )
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Path selector — decides which meta-tx flow to take given a token's
43
+ * capabilities and the action a merchant wants to perform.
44
+ *
45
+ * The choice is unambiguous in 99% of cases:
46
+ * - One-shot pay → EIP-3009 (preferred). Falls back to
47
+ * approve+pay if the token has neither.
48
+ * - Subscription enrol → EIP-2612 (the only meta-tx path that
49
+ * grants the recurring allowance subscribers
50
+ * need). If unavailable, the merchant must
51
+ * use the classic approve+create flow.
52
+ *
53
+ * Returned `path` values are strings (not enums) so future schemes
54
+ * can extend the union without breaking existing call sites.
55
+ */
56
+ export type RelayPath =
57
+ | 'pay_with_authorization'
58
+ | 'permit_and_create_subscription'
59
+ | 'approve_then_pay'
60
+ | 'approve_then_create_subscription'
61
+
62
+ export function selectPaymentPath(meta: TokenMetadata): RelayPath {
63
+ return meta.capabilities.transferAuth3009 ? 'pay_with_authorization' : 'approve_then_pay'
64
+ }
65
+
66
+ export function selectSubscriptionPath(meta: TokenMetadata): RelayPath {
67
+ return meta.capabilities.permit2612
68
+ ? 'permit_and_create_subscription'
69
+ : 'approve_then_create_subscription'
70
+ }
@@ -0,0 +1,20 @@
1
+ import { transactionSchema, type Transaction } from '@strimz/shared-types'
2
+ import type { PaginationParams, Page } from '../pagination.js'
3
+ import { BaseResource } from './base-resource.js'
4
+
5
+ export class TransactionsResource extends BaseResource {
6
+ retrieve(id: string): Promise<Transaction> {
7
+ return this.get(`/v1/transactions/${encodeURIComponent(id)}`, transactionSchema)
8
+ }
9
+
10
+ list(
11
+ params?: PaginationParams & {
12
+ kind?: string
13
+ status?: string
14
+ from?: string
15
+ to?: string
16
+ },
17
+ ): Promise<Page<Transaction>> {
18
+ return this.listPage('/v1/transactions', transactionSchema, params)
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ import { webhookDeliverySchema, type WebhookDelivery } from '@strimz/shared-types'
2
+ import type { PaginationParams, Page } from '../pagination.js'
3
+ import { BaseResource, type RequestOptions } from './base-resource.js'
4
+
5
+ export class WebhookDeliveriesResource extends BaseResource {
6
+ retrieve(id: string): Promise<WebhookDelivery> {
7
+ return this.get(`/v1/webhook-deliveries/${encodeURIComponent(id)}`, webhookDeliverySchema)
8
+ }
9
+
10
+ list(
11
+ params?: PaginationParams & {
12
+ endpointId?: string
13
+ status?: string
14
+ eventName?: string
15
+ },
16
+ ): Promise<Page<WebhookDelivery>> {
17
+ return this.listPage('/v1/webhook-deliveries', webhookDeliverySchema, params)
18
+ }
19
+
20
+ /** Manually replay a permanently-failed delivery. */
21
+ replay(id: string, options?: RequestOptions): Promise<WebhookDelivery> {
22
+ return this.post(
23
+ `/v1/webhook-deliveries/${encodeURIComponent(id)}/replay`,
24
+ {},
25
+ webhookDeliverySchema,
26
+ options,
27
+ )
28
+ }
29
+ }
@@ -0,0 +1,56 @@
1
+ import {
2
+ webhookEndpointSchema,
3
+ createWebhookEndpointInputSchema,
4
+ createWebhookEndpointOutputSchema,
5
+ type WebhookEndpoint,
6
+ type CreateWebhookEndpointInput,
7
+ type CreateWebhookEndpointOutput,
8
+ } from '@strimz/shared-types'
9
+ import type { PaginationParams, Page } from '../pagination.js'
10
+ import { BaseResource, type RequestOptions } from './base-resource.js'
11
+
12
+ export class WebhookEndpointsResource extends BaseResource {
13
+ create(
14
+ input: CreateWebhookEndpointInput,
15
+ options?: RequestOptions,
16
+ ): Promise<CreateWebhookEndpointOutput> {
17
+ createWebhookEndpointInputSchema.parse(input)
18
+ return this.post('/v1/webhook-endpoints', input, createWebhookEndpointOutputSchema, options)
19
+ }
20
+
21
+ retrieve(id: string): Promise<WebhookEndpoint> {
22
+ return this.get(`/v1/webhook-endpoints/${encodeURIComponent(id)}`, webhookEndpointSchema)
23
+ }
24
+
25
+ list(params?: PaginationParams): Promise<Page<WebhookEndpoint>> {
26
+ return this.listPage('/v1/webhook-endpoints', webhookEndpointSchema, params)
27
+ }
28
+
29
+ disable(id: string, options?: RequestOptions): Promise<WebhookEndpoint> {
30
+ return this.post(
31
+ `/v1/webhook-endpoints/${encodeURIComponent(id)}/disable`,
32
+ {},
33
+ webhookEndpointSchema,
34
+ options,
35
+ )
36
+ }
37
+
38
+ enable(id: string, options?: RequestOptions): Promise<WebhookEndpoint> {
39
+ return this.post(
40
+ `/v1/webhook-endpoints/${encodeURIComponent(id)}/enable`,
41
+ {},
42
+ webhookEndpointSchema,
43
+ options,
44
+ )
45
+ }
46
+
47
+ /** Rotates the signing secret. Returns the new full secret exactly once. */
48
+ rotateSecret(id: string, options?: RequestOptions): Promise<CreateWebhookEndpointOutput> {
49
+ return this.post(
50
+ `/v1/webhook-endpoints/${encodeURIComponent(id)}/rotate-secret`,
51
+ {},
52
+ createWebhookEndpointOutputSchema,
53
+ options,
54
+ )
55
+ }
56
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Webhook utilities — re-exports the verified-and-tested Web Crypto
3
+ * primitives from `@strimz/shared-crypto` and the typed event union from
4
+ * `@strimz/shared-types`. Consumers should import from here, not directly
5
+ * from the shared packages.
6
+ */
7
+
8
+ export {
9
+ signWebhookPayload,
10
+ verifyWebhookSignature,
11
+ WEBHOOK_SIGNATURE_VERSION,
12
+ type SignWebhookOptions,
13
+ type VerifyWebhookOptions,
14
+ type VerifyWebhookReason,
15
+ type VerifyWebhookResult,
16
+ } from '@strimz/shared-crypto'
17
+
18
+ export {
19
+ webhookEventSchema,
20
+ webhookEventNameSchema,
21
+ type StrimzWebhookEvent,
22
+ type WebhookEventName,
23
+ // Per-event typed payloads.
24
+ type PaymentCreatedEvent,
25
+ type PaymentCompletedEvent,
26
+ type PaymentFailedEvent,
27
+ type SubscriptionCreatedEvent,
28
+ type SubscriptionChargedEvent,
29
+ type SubscriptionChargeFailedEvent,
30
+ type SubscriptionRecoveryAttemptEvent,
31
+ type SubscriptionRecoveryOutcomeEvent,
32
+ type SubscriptionCancelledEvent,
33
+ type SubscriptionLapsedEvent,
34
+ type RefundCreatedEvent,
35
+ type RefundCompletedEvent,
36
+ type RefundFailedEvent,
37
+ type InvoiceCreatedEvent,
38
+ type InvoicePaidEvent,
39
+ type InvoiceOverdueEvent,
40
+ type AgentActionExecutedEvent,
41
+ type AgentJobProposedEvent,
42
+ type AgentJobCompletedEvent,
43
+ type AgentJobDisputedEvent,
44
+ type ComplianceWalletFlaggedEvent,
45
+ type ComplianceWalletBlockedEvent,
46
+ } from '@strimz/shared-types'
47
+
48
+ export {
49
+ WEBHOOK_RETRY_SCHEDULE_SECONDS,
50
+ WEBHOOK_MAX_ATTEMPTS,
51
+ WEBHOOK_SIGNATURE_TOLERANCE_SECONDS,
52
+ WEBHOOK_SIGNATURE_HEADER,
53
+ WEBHOOK_DELIVERY_ID_HEADER,
54
+ } from '@strimz/shared-config'
55
+
56
+ import { webhookEventSchema, type StrimzWebhookEvent } from '@strimz/shared-types'
57
+
58
+ /**
59
+ * Parse a webhook payload into a typed `StrimzWebhookEvent`.
60
+ * Use after `verifyWebhookSignature` succeeds — never trust raw payloads.
61
+ */
62
+ export function parseWebhookEvent(rawJson: string): StrimzWebhookEvent {
63
+ return webhookEventSchema.parse(JSON.parse(rawJson))
64
+ }