@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.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/browser-client-DlZg0Aae.d.cts +223 -0
- package/dist/browser-client-DlZg0Aae.d.ts +223 -0
- package/dist/browser-client.cjs +443 -0
- package/dist/browser-client.cjs.map +1 -0
- package/dist/browser-client.d.cts +4 -0
- package/dist/browser-client.d.ts +4 -0
- package/dist/browser-client.js +439 -0
- package/dist/browser-client.js.map +1 -0
- package/dist/eip712.cjs +70 -0
- package/dist/eip712.cjs.map +1 -0
- package/dist/eip712.d.cts +181 -0
- package/dist/eip712.d.ts +181 -0
- package/dist/eip712.js +65 -0
- package/dist/eip712.js.map +1 -0
- package/dist/errors.cjs +102 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +56 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +90 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +831 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +193 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +806 -0
- package/dist/index.js.map +1 -0
- package/dist/webhooks.cjs +54 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +19 -0
- package/dist/webhooks.d.ts +19 -0
- package/dist/webhooks.js +13 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +94 -0
- package/src/browser-client.ts +97 -0
- package/src/client.ts +122 -0
- package/src/eip712/index.ts +25 -0
- package/src/eip712/permit.ts +74 -0
- package/src/eip712/receive-with-authorization.ts +88 -0
- package/src/eip712/types.ts +46 -0
- package/src/errors.ts +138 -0
- package/src/http/fetcher.ts +226 -0
- package/src/http/headers.ts +32 -0
- package/src/idempotency.ts +20 -0
- package/src/index.ts +77 -0
- package/src/pagination.ts +48 -0
- package/src/resources/agents.ts +64 -0
- package/src/resources/api-keys.ts +29 -0
- package/src/resources/base-resource.ts +116 -0
- package/src/resources/checkout.ts +32 -0
- package/src/resources/customers.ts +25 -0
- package/src/resources/invoices.ts +31 -0
- package/src/resources/merchants.ts +26 -0
- package/src/resources/payment-sessions.ts +41 -0
- package/src/resources/refunds.ts +36 -0
- package/src/resources/storefronts.ts +62 -0
- package/src/resources/subscription-plans.ts +32 -0
- package/src/resources/subscriptions.ts +37 -0
- package/src/resources/tokens.ts +70 -0
- package/src/resources/transactions.ts +20 -0
- package/src/resources/webhook-deliveries.ts +29 -0
- package/src/resources/webhook-endpoints.ts +56 -0
- package/src/webhooks.ts +64 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @strimz/sdk
|
|
3
|
+
*
|
|
4
|
+
* Server SDK for the Strimz API. Use `StrimzClient` with a secret key.
|
|
5
|
+
* For browser code, import `StrimzBrowserClient` from `@strimz/sdk/browser`.
|
|
6
|
+
* For webhook verification helpers, import from `@strimz/sdk/webhooks`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Primary client.
|
|
10
|
+
export { StrimzClient, type StrimzClientOptions } from './client.js'
|
|
11
|
+
|
|
12
|
+
// Browser client (also available via `@strimz/sdk/browser`).
|
|
13
|
+
export { StrimzBrowserClient, type StrimzBrowserClientOptions } from './browser-client.js'
|
|
14
|
+
|
|
15
|
+
// Errors.
|
|
16
|
+
export {
|
|
17
|
+
StrimzError,
|
|
18
|
+
StrimzAuthenticationError,
|
|
19
|
+
StrimzPermissionError,
|
|
20
|
+
StrimzValidationError,
|
|
21
|
+
StrimzNotFoundError,
|
|
22
|
+
StrimzIdempotencyError,
|
|
23
|
+
StrimzRateLimitError,
|
|
24
|
+
StrimzNetworkError,
|
|
25
|
+
StrimzTimeoutError,
|
|
26
|
+
StrimzModeMismatchError,
|
|
27
|
+
classifyError,
|
|
28
|
+
type StrimzErrorCode,
|
|
29
|
+
type StrimzErrorBody,
|
|
30
|
+
} from './errors.js'
|
|
31
|
+
|
|
32
|
+
// Pagination.
|
|
33
|
+
export { AutoPagingIterator, type Page, type PaginationParams } from './pagination.js'
|
|
34
|
+
|
|
35
|
+
// Idempotency.
|
|
36
|
+
export { generateIdempotencyKey, isValidIdempotencyKey } from './idempotency.js'
|
|
37
|
+
|
|
38
|
+
// Webhook helpers (also at `@strimz/sdk/webhooks`).
|
|
39
|
+
export {
|
|
40
|
+
signWebhookPayload,
|
|
41
|
+
verifyWebhookSignature,
|
|
42
|
+
parseWebhookEvent,
|
|
43
|
+
type StrimzWebhookEvent,
|
|
44
|
+
} from './webhooks.js'
|
|
45
|
+
|
|
46
|
+
// Re-export every entity type so consumers don't need to depend on shared-types
|
|
47
|
+
// directly. Apps can `import type { Merchant, PaymentSession } from '@strimz/sdk'`.
|
|
48
|
+
export type {
|
|
49
|
+
Merchant,
|
|
50
|
+
ApiKey,
|
|
51
|
+
Customer,
|
|
52
|
+
PaymentSession,
|
|
53
|
+
Transaction,
|
|
54
|
+
SubscriptionPlan,
|
|
55
|
+
Subscription,
|
|
56
|
+
SubscriptionCharge,
|
|
57
|
+
Refund,
|
|
58
|
+
WebhookEndpoint,
|
|
59
|
+
WebhookDelivery,
|
|
60
|
+
Invoice,
|
|
61
|
+
Storefront,
|
|
62
|
+
StorefrontProduct,
|
|
63
|
+
AgentMerchantConfig,
|
|
64
|
+
AgentActivityLog,
|
|
65
|
+
AgentJob,
|
|
66
|
+
ComplianceLog,
|
|
67
|
+
WebhookEventName,
|
|
68
|
+
// Inputs.
|
|
69
|
+
CreatePaymentSessionInput,
|
|
70
|
+
CreateSubscriptionPlanInput,
|
|
71
|
+
CreateSubscriptionInput,
|
|
72
|
+
CreateRefundInput,
|
|
73
|
+
CreateInvoiceInput,
|
|
74
|
+
CreateAgentJobInput,
|
|
75
|
+
CreateApiKeyInput,
|
|
76
|
+
CreateWebhookEndpointInput,
|
|
77
|
+
} from '@strimz/shared-types'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor-based pagination, identical shape to the API's list responses.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface Page<T> {
|
|
6
|
+
data: T[]
|
|
7
|
+
nextCursor: string | null
|
|
8
|
+
hasMore: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PaginationParams {
|
|
12
|
+
limit?: number
|
|
13
|
+
cursor?: string | null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Async-iterable wrapper that auto-paginates through every page of a list.
|
|
18
|
+
*
|
|
19
|
+
* for await (const tx of strimz.transactions.listAll()) { ... }
|
|
20
|
+
*/
|
|
21
|
+
export class AutoPagingIterator<T> implements AsyncIterable<T> {
|
|
22
|
+
constructor(private readonly fetchPage: (cursor: string | null) => Promise<Page<T>>) {}
|
|
23
|
+
|
|
24
|
+
async *[Symbol.asyncIterator](): AsyncIterator<T> {
|
|
25
|
+
let cursor: string | null = null
|
|
26
|
+
let first = true
|
|
27
|
+
while (first || cursor !== null) {
|
|
28
|
+
first = false
|
|
29
|
+
const page: Page<T> = await this.fetchPage(cursor)
|
|
30
|
+
for (const item of page.data) {
|
|
31
|
+
yield item
|
|
32
|
+
}
|
|
33
|
+
cursor = page.hasMore ? page.nextCursor : null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async forEach(handler: (item: T) => void | Promise<void>): Promise<void> {
|
|
38
|
+
for await (const item of this) {
|
|
39
|
+
await handler(item)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async toArray(): Promise<T[]> {
|
|
44
|
+
const out: T[] = []
|
|
45
|
+
for await (const item of this) out.push(item)
|
|
46
|
+
return out
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agentMerchantConfigSchema,
|
|
3
|
+
updateAgentConfigInputSchema,
|
|
4
|
+
agentActivityLogSchema,
|
|
5
|
+
agentJobSchema,
|
|
6
|
+
createAgentJobInputSchema,
|
|
7
|
+
type AgentMerchantConfig,
|
|
8
|
+
type UpdateAgentConfigInput,
|
|
9
|
+
type AgentActivityLog,
|
|
10
|
+
type AgentJob,
|
|
11
|
+
type CreateAgentJobInput,
|
|
12
|
+
} from '@strimz/shared-types'
|
|
13
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
14
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
15
|
+
|
|
16
|
+
export class AgentsResource extends BaseResource {
|
|
17
|
+
/** Retrieve the merchant's AutoPay Agent config. */
|
|
18
|
+
retrieveConfig(): Promise<AgentMerchantConfig> {
|
|
19
|
+
return this.get('/v1/agents/config', agentMerchantConfigSchema)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
updateConfig(
|
|
23
|
+
input: UpdateAgentConfigInput,
|
|
24
|
+
options?: RequestOptions,
|
|
25
|
+
): Promise<AgentMerchantConfig> {
|
|
26
|
+
updateAgentConfigInputSchema.parse(input)
|
|
27
|
+
return this.patch('/v1/agents/config', input, agentMerchantConfigSchema, options)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
listActivity(
|
|
31
|
+
params?: PaginationParams & {
|
|
32
|
+
capability?: string
|
|
33
|
+
outcome?: string
|
|
34
|
+
from?: string
|
|
35
|
+
to?: string
|
|
36
|
+
},
|
|
37
|
+
): Promise<Page<AgentActivityLog>> {
|
|
38
|
+
return this.listPage('/v1/agents/activity', agentActivityLogSchema, params)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ----- ERC-8183 jobs -----
|
|
42
|
+
|
|
43
|
+
listJobs(params?: PaginationParams & { status?: string }): Promise<Page<AgentJob>> {
|
|
44
|
+
return this.listPage('/v1/agents/jobs', agentJobSchema, params)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
retrieveJob(id: string): Promise<AgentJob> {
|
|
48
|
+
return this.get(`/v1/agents/jobs/${encodeURIComponent(id)}`, agentJobSchema)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
createJob(input: CreateAgentJobInput, options?: RequestOptions): Promise<AgentJob> {
|
|
52
|
+
createAgentJobInputSchema.parse(input)
|
|
53
|
+
return this.post('/v1/agents/jobs', input, agentJobSchema, options)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
approveJob(id: string, options?: RequestOptions): Promise<AgentJob> {
|
|
57
|
+
return this.post(
|
|
58
|
+
`/v1/agents/jobs/${encodeURIComponent(id)}/approve`,
|
|
59
|
+
{},
|
|
60
|
+
agentJobSchema,
|
|
61
|
+
options,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiKeySchema,
|
|
3
|
+
createApiKeyInputSchema,
|
|
4
|
+
createApiKeyOutputSchema,
|
|
5
|
+
type ApiKey,
|
|
6
|
+
type CreateApiKeyInput,
|
|
7
|
+
type CreateApiKeyOutput,
|
|
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 ApiKeysResource extends BaseResource {
|
|
13
|
+
list(params?: PaginationParams): Promise<Page<ApiKey>> {
|
|
14
|
+
return this.listPage('/v1/api-keys', apiKeySchema, params)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
retrieve(id: string): Promise<ApiKey> {
|
|
18
|
+
return this.get(`/v1/api-keys/${encodeURIComponent(id)}`, apiKeySchema)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
create(input: CreateApiKeyInput, options?: RequestOptions): Promise<CreateApiKeyOutput> {
|
|
22
|
+
createApiKeyInputSchema.parse(input)
|
|
23
|
+
return this.post('/v1/api-keys', input, createApiKeyOutputSchema, options)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
revoke(id: string, options?: RequestOptions): Promise<ApiKey> {
|
|
27
|
+
return this.post(`/v1/api-keys/${encodeURIComponent(id)}/revoke`, {}, apiKeySchema, options)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class every resource extends. Centralises endpoint plumbing so
|
|
3
|
+
* resource classes are tiny declarative wrappers.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { z } from 'zod'
|
|
7
|
+
import type { Fetcher, RequestSpec } from '../http/fetcher.js'
|
|
8
|
+
import { generateIdempotencyKey } from '../idempotency.js'
|
|
9
|
+
import { AutoPagingIterator, type Page, type PaginationParams } from '../pagination.js'
|
|
10
|
+
|
|
11
|
+
type AnySchema = z.ZodTypeAny
|
|
12
|
+
type Inferred<S extends AnySchema> = z.output<S>
|
|
13
|
+
|
|
14
|
+
export interface ResourceContext {
|
|
15
|
+
fetcher: Fetcher
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RequestOptions {
|
|
19
|
+
/** Override or supply the idempotency key for a mutating call. */
|
|
20
|
+
idempotencyKey?: string
|
|
21
|
+
/** Per-request timeout in ms. */
|
|
22
|
+
timeoutMs?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export abstract class BaseResource {
|
|
26
|
+
constructor(protected readonly ctx: ResourceContext) {}
|
|
27
|
+
|
|
28
|
+
protected async get<S extends AnySchema>(
|
|
29
|
+
path: string,
|
|
30
|
+
schema?: S,
|
|
31
|
+
query?: RequestSpec['query'],
|
|
32
|
+
): Promise<Inferred<S>> {
|
|
33
|
+
const data = await this.ctx.fetcher.request<unknown>({ method: 'GET', path, query })
|
|
34
|
+
return parse(data, schema)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected async post<S extends AnySchema>(
|
|
38
|
+
path: string,
|
|
39
|
+
body: unknown,
|
|
40
|
+
schema?: S,
|
|
41
|
+
options?: RequestOptions,
|
|
42
|
+
): Promise<Inferred<S>> {
|
|
43
|
+
const data = await this.ctx.fetcher.request<unknown>({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
path,
|
|
46
|
+
body,
|
|
47
|
+
idempotencyKey: options?.idempotencyKey ?? generateIdempotencyKey(),
|
|
48
|
+
timeoutMs: options?.timeoutMs,
|
|
49
|
+
})
|
|
50
|
+
return parse(data, schema)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected async patch<S extends AnySchema>(
|
|
54
|
+
path: string,
|
|
55
|
+
body: unknown,
|
|
56
|
+
schema?: S,
|
|
57
|
+
options?: RequestOptions,
|
|
58
|
+
): Promise<Inferred<S>> {
|
|
59
|
+
const data = await this.ctx.fetcher.request<unknown>({
|
|
60
|
+
method: 'PATCH',
|
|
61
|
+
path,
|
|
62
|
+
body,
|
|
63
|
+
idempotencyKey: options?.idempotencyKey ?? generateIdempotencyKey(),
|
|
64
|
+
timeoutMs: options?.timeoutMs,
|
|
65
|
+
})
|
|
66
|
+
return parse(data, schema)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected async delete<S extends AnySchema>(path: string, schema?: S): Promise<Inferred<S>> {
|
|
70
|
+
const data = await this.ctx.fetcher.request<unknown>({ method: 'DELETE', path })
|
|
71
|
+
return parse(data, schema)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
protected listPage<S extends AnySchema>(
|
|
75
|
+
path: string,
|
|
76
|
+
itemSchema: S,
|
|
77
|
+
params?: PaginationParams | Record<string, ScalarParam>,
|
|
78
|
+
): Promise<Page<Inferred<S>>> {
|
|
79
|
+
return this.ctx.fetcher
|
|
80
|
+
.request<unknown>({ method: 'GET', path, query: toQuery(params) })
|
|
81
|
+
.then((raw) => parsePage(raw, itemSchema))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected listAuto<S extends AnySchema>(
|
|
85
|
+
path: string,
|
|
86
|
+
itemSchema: S,
|
|
87
|
+
params?: Record<string, ScalarParam>,
|
|
88
|
+
): AutoPagingIterator<Inferred<S>> {
|
|
89
|
+
return new AutoPagingIterator((cursor) =>
|
|
90
|
+
this.listPage(path, itemSchema, { ...params, cursor }),
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type ScalarParam = string | number | boolean | null | undefined
|
|
96
|
+
|
|
97
|
+
function toQuery(
|
|
98
|
+
params: PaginationParams | Record<string, ScalarParam> | undefined,
|
|
99
|
+
): Record<string, ScalarParam> {
|
|
100
|
+
if (!params) return {}
|
|
101
|
+
return params as Record<string, ScalarParam>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parse<S extends AnySchema>(data: unknown, schema?: S): Inferred<S> {
|
|
105
|
+
return (schema ? schema.parse(data) : data) as Inferred<S>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parsePage<S extends AnySchema>(raw: unknown, itemSchema: S): Page<Inferred<S>> {
|
|
109
|
+
const obj = raw as { data?: unknown[]; nextCursor?: string | null; hasMore?: boolean }
|
|
110
|
+
const items = (obj?.data ?? []).map((d) => itemSchema.parse(d) as Inferred<S>)
|
|
111
|
+
return {
|
|
112
|
+
data: items,
|
|
113
|
+
nextCursor: obj?.nextCursor ?? null,
|
|
114
|
+
hasMore: obj?.hasMore === true,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
paymentSessionSchema,
|
|
3
|
+
subscriptionPlanSchema,
|
|
4
|
+
type PaymentSession,
|
|
5
|
+
type SubscriptionPlan,
|
|
6
|
+
} from '@strimz/shared-types'
|
|
7
|
+
import { BaseResource } from './base-resource.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Public hosted-checkout reads.
|
|
11
|
+
*
|
|
12
|
+
* Backed by the `/v1/checkout/*` namespace on the Strimz API, which
|
|
13
|
+
* is intentionally unauthenticated — session and plan records are
|
|
14
|
+
* what a merchant offers to payers, so a payer landing on a checkout
|
|
15
|
+
* URL must be able to load the terms without holding any API key.
|
|
16
|
+
*
|
|
17
|
+
* Use this resource (via `StrimzBrowserClient.checkout`) from the
|
|
18
|
+
* browser. The merchant-scoped `paymentSessions` / `subscriptionPlans`
|
|
19
|
+
* resources on `StrimzClient` remain the right call from server-side
|
|
20
|
+
* code with a secret key.
|
|
21
|
+
*/
|
|
22
|
+
export class CheckoutResource extends BaseResource {
|
|
23
|
+
/** Load a payment session by id (public — no merchant scoping). */
|
|
24
|
+
session(id: string): Promise<PaymentSession> {
|
|
25
|
+
return this.get(`/v1/checkout/sessions/${encodeURIComponent(id)}`, paymentSessionSchema)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Load a subscription plan by id (public — no merchant scoping). */
|
|
29
|
+
plan(id: string): Promise<SubscriptionPlan> {
|
|
30
|
+
return this.get(`/v1/checkout/plans/${encodeURIComponent(id)}`, subscriptionPlanSchema)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
customerSchema,
|
|
3
|
+
upsertCustomerInputSchema,
|
|
4
|
+
type Customer,
|
|
5
|
+
type UpsertCustomerInput,
|
|
6
|
+
} from '@strimz/shared-types'
|
|
7
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
8
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
9
|
+
|
|
10
|
+
export class CustomersResource extends BaseResource {
|
|
11
|
+
retrieve(id: string): Promise<Customer> {
|
|
12
|
+
return this.get(`/v1/customers/${encodeURIComponent(id)}`, customerSchema)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
list(
|
|
16
|
+
params?: PaginationParams & { externalRef?: string; walletAddress?: string },
|
|
17
|
+
): Promise<Page<Customer>> {
|
|
18
|
+
return this.listPage('/v1/customers', customerSchema, params)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
upsert(input: UpsertCustomerInput, options?: RequestOptions): Promise<Customer> {
|
|
22
|
+
upsertCustomerInputSchema.parse(input)
|
|
23
|
+
return this.post('/v1/customers', input, customerSchema, options)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
invoiceSchema,
|
|
3
|
+
createInvoiceInputSchema,
|
|
4
|
+
type Invoice,
|
|
5
|
+
type CreateInvoiceInput,
|
|
6
|
+
} from '@strimz/shared-types'
|
|
7
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
8
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
9
|
+
|
|
10
|
+
export class InvoicesResource extends BaseResource {
|
|
11
|
+
create(input: CreateInvoiceInput, options?: RequestOptions): Promise<Invoice> {
|
|
12
|
+
createInvoiceInputSchema.parse(input)
|
|
13
|
+
return this.post('/v1/invoices', input, invoiceSchema, options)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
retrieve(id: string): Promise<Invoice> {
|
|
17
|
+
return this.get(`/v1/invoices/${encodeURIComponent(id)}`, invoiceSchema)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
list(params?: PaginationParams & { status?: string }): Promise<Page<Invoice>> {
|
|
21
|
+
return this.listPage('/v1/invoices', invoiceSchema, params)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
send(id: string, options?: RequestOptions): Promise<Invoice> {
|
|
25
|
+
return this.post(`/v1/invoices/${encodeURIComponent(id)}/send`, {}, invoiceSchema, options)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void(id: string, options?: RequestOptions): Promise<Invoice> {
|
|
29
|
+
return this.post(`/v1/invoices/${encodeURIComponent(id)}/void`, {}, invoiceSchema, options)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
merchantSchema,
|
|
3
|
+
updateMerchantInputSchema,
|
|
4
|
+
changeTierInputSchema,
|
|
5
|
+
type Merchant,
|
|
6
|
+
type UpdateMerchantInput,
|
|
7
|
+
type ChangeTierInput,
|
|
8
|
+
} from '@strimz/shared-types'
|
|
9
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
10
|
+
|
|
11
|
+
export class MerchantsResource extends BaseResource {
|
|
12
|
+
/** The merchant the API key belongs to. */
|
|
13
|
+
me(): Promise<Merchant> {
|
|
14
|
+
return this.get('/v1/merchants/me', merchantSchema)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
update(input: UpdateMerchantInput, options?: RequestOptions): Promise<Merchant> {
|
|
18
|
+
updateMerchantInputSchema.parse(input)
|
|
19
|
+
return this.patch('/v1/merchants/me', input, merchantSchema, options)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
changeTier(input: ChangeTierInput, options?: RequestOptions): Promise<Merchant> {
|
|
23
|
+
changeTierInputSchema.parse(input)
|
|
24
|
+
return this.post('/v1/merchants/me/tier', input, merchantSchema, options)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
paymentSessionSchema,
|
|
3
|
+
createPaymentSessionInputSchema,
|
|
4
|
+
type PaymentSession,
|
|
5
|
+
type CreatePaymentSessionInput,
|
|
6
|
+
} from '@strimz/shared-types'
|
|
7
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
8
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
9
|
+
|
|
10
|
+
export class PaymentSessionsResource extends BaseResource {
|
|
11
|
+
create(input: CreatePaymentSessionInput, options?: RequestOptions): Promise<PaymentSession> {
|
|
12
|
+
createPaymentSessionInputSchema.parse(input)
|
|
13
|
+
return this.post('/v1/payment-sessions', input, paymentSessionSchema, options)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
retrieve(id: string): Promise<PaymentSession> {
|
|
17
|
+
return this.get(`/v1/payment-sessions/${encodeURIComponent(id)}`, paymentSessionSchema)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
list(params?: PaginationParams & { status?: string }): Promise<Page<PaymentSession>> {
|
|
21
|
+
return this.listPage('/v1/payment-sessions', paymentSessionSchema, params)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
cancel(id: string, options?: RequestOptions): Promise<PaymentSession> {
|
|
25
|
+
return this.post(
|
|
26
|
+
`/v1/payment-sessions/${encodeURIComponent(id)}/cancel`,
|
|
27
|
+
{},
|
|
28
|
+
paymentSessionSchema,
|
|
29
|
+
options,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
expire(id: string, options?: RequestOptions): Promise<PaymentSession> {
|
|
34
|
+
return this.post(
|
|
35
|
+
`/v1/payment-sessions/${encodeURIComponent(id)}/expire`,
|
|
36
|
+
{},
|
|
37
|
+
paymentSessionSchema,
|
|
38
|
+
options,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
refundSchema,
|
|
3
|
+
createRefundInputSchema,
|
|
4
|
+
submitRefundSignatureInputSchema,
|
|
5
|
+
type Refund,
|
|
6
|
+
type CreateRefundInput,
|
|
7
|
+
type SubmitRefundSignatureInput,
|
|
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 RefundsResource extends BaseResource {
|
|
13
|
+
create(input: CreateRefundInput, options?: RequestOptions): Promise<Refund> {
|
|
14
|
+
createRefundInputSchema.parse(input)
|
|
15
|
+
return this.post('/v1/refunds', input, refundSchema, options)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
retrieve(id: string): Promise<Refund> {
|
|
19
|
+
return this.get(`/v1/refunds/${encodeURIComponent(id)}`, refundSchema)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
list(params?: PaginationParams & { status?: string }): Promise<Page<Refund>> {
|
|
23
|
+
return this.listPage('/v1/refunds', refundSchema, params)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Record the on-chain refund tx after the merchant signs from their wallet. */
|
|
27
|
+
submitSignature(input: SubmitRefundSignatureInput, options?: RequestOptions): Promise<Refund> {
|
|
28
|
+
submitRefundSignatureInputSchema.parse(input)
|
|
29
|
+
return this.post(
|
|
30
|
+
`/v1/refunds/${encodeURIComponent(input.id)}/signature`,
|
|
31
|
+
input,
|
|
32
|
+
refundSchema,
|
|
33
|
+
options,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
storefrontSchema,
|
|
3
|
+
createStorefrontInputSchema,
|
|
4
|
+
storefrontProductSchema,
|
|
5
|
+
createStorefrontProductInputSchema,
|
|
6
|
+
type Storefront,
|
|
7
|
+
type CreateStorefrontInput,
|
|
8
|
+
type StorefrontProduct,
|
|
9
|
+
type CreateStorefrontProductInput,
|
|
10
|
+
} from '@strimz/shared-types'
|
|
11
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
12
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
13
|
+
|
|
14
|
+
export class StorefrontsResource extends BaseResource {
|
|
15
|
+
/** Retrieve the merchant's own storefront. */
|
|
16
|
+
retrieve(): Promise<Storefront> {
|
|
17
|
+
return this.get('/v1/storefront', storefrontSchema)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
upsert(input: CreateStorefrontInput, options?: RequestOptions): Promise<Storefront> {
|
|
21
|
+
createStorefrontInputSchema.parse(input)
|
|
22
|
+
return this.post('/v1/storefront', input, storefrontSchema, options)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
publish(options?: RequestOptions): Promise<Storefront> {
|
|
26
|
+
return this.post('/v1/storefront/publish', {}, storefrontSchema, options)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
archive(options?: RequestOptions): Promise<Storefront> {
|
|
30
|
+
return this.post('/v1/storefront/archive', {}, storefrontSchema, options)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ----- Products -----
|
|
34
|
+
|
|
35
|
+
listProducts(params?: PaginationParams): Promise<Page<StorefrontProduct>> {
|
|
36
|
+
return this.listPage('/v1/storefront/products', storefrontProductSchema, params)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
createProduct(
|
|
40
|
+
input: CreateStorefrontProductInput,
|
|
41
|
+
options?: RequestOptions,
|
|
42
|
+
): Promise<StorefrontProduct> {
|
|
43
|
+
createStorefrontProductInputSchema.parse(input)
|
|
44
|
+
return this.post('/v1/storefront/products', input, storefrontProductSchema, options)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
retrieveProduct(productId: string): Promise<StorefrontProduct> {
|
|
48
|
+
return this.get(
|
|
49
|
+
`/v1/storefront/products/${encodeURIComponent(productId)}`,
|
|
50
|
+
storefrontProductSchema,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
archiveProduct(productId: string, options?: RequestOptions): Promise<StorefrontProduct> {
|
|
55
|
+
return this.post(
|
|
56
|
+
`/v1/storefront/products/${encodeURIComponent(productId)}/archive`,
|
|
57
|
+
{},
|
|
58
|
+
storefrontProductSchema,
|
|
59
|
+
options,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
subscriptionPlanSchema,
|
|
3
|
+
createSubscriptionPlanInputSchema,
|
|
4
|
+
type SubscriptionPlan,
|
|
5
|
+
type CreateSubscriptionPlanInput,
|
|
6
|
+
} from '@strimz/shared-types'
|
|
7
|
+
import type { PaginationParams, Page } from '../pagination.js'
|
|
8
|
+
import { BaseResource, type RequestOptions } from './base-resource.js'
|
|
9
|
+
|
|
10
|
+
export class SubscriptionPlansResource extends BaseResource {
|
|
11
|
+
create(input: CreateSubscriptionPlanInput, options?: RequestOptions): Promise<SubscriptionPlan> {
|
|
12
|
+
createSubscriptionPlanInputSchema.parse(input)
|
|
13
|
+
return this.post('/v1/subscription-plans', input, subscriptionPlanSchema, options)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
retrieve(id: string): Promise<SubscriptionPlan> {
|
|
17
|
+
return this.get(`/v1/subscription-plans/${encodeURIComponent(id)}`, subscriptionPlanSchema)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
list(params?: PaginationParams & { status?: string }): Promise<Page<SubscriptionPlan>> {
|
|
21
|
+
return this.listPage('/v1/subscription-plans', subscriptionPlanSchema, params)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
archive(id: string, options?: RequestOptions): Promise<SubscriptionPlan> {
|
|
25
|
+
return this.post(
|
|
26
|
+
`/v1/subscription-plans/${encodeURIComponent(id)}/archive`,
|
|
27
|
+
{},
|
|
28
|
+
subscriptionPlanSchema,
|
|
29
|
+
options,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
subscriptionSchema,
|
|
3
|
+
createSubscriptionInputSchema,
|
|
4
|
+
cancelSubscriptionInputSchema,
|
|
5
|
+
type Subscription,
|
|
6
|
+
type CreateSubscriptionInput,
|
|
7
|
+
type CancelSubscriptionInput,
|
|
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 SubscriptionsResource extends BaseResource {
|
|
13
|
+
create(input: CreateSubscriptionInput, options?: RequestOptions): Promise<Subscription> {
|
|
14
|
+
createSubscriptionInputSchema.parse(input)
|
|
15
|
+
return this.post('/v1/subscriptions', input, subscriptionSchema, options)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
retrieve(id: string): Promise<Subscription> {
|
|
19
|
+
return this.get(`/v1/subscriptions/${encodeURIComponent(id)}`, subscriptionSchema)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
list(
|
|
23
|
+
params?: PaginationParams & { status?: string; planId?: string },
|
|
24
|
+
): Promise<Page<Subscription>> {
|
|
25
|
+
return this.listPage('/v1/subscriptions', subscriptionSchema, params)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
cancel(input: CancelSubscriptionInput, options?: RequestOptions): Promise<Subscription> {
|
|
29
|
+
cancelSubscriptionInputSchema.parse(input)
|
|
30
|
+
return this.post(
|
|
31
|
+
`/v1/subscriptions/${encodeURIComponent(input.id)}/cancel`,
|
|
32
|
+
input,
|
|
33
|
+
subscriptionSchema,
|
|
34
|
+
options,
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
}
|