@rawdash/connector-stripe 0.14.0 → 0.16.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/README.md +71 -143
- package/dist/index.d.ts +307 -2
- package/dist/index.js +221 -28
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,89 +1,80 @@
|
|
|
1
|
+
<!-- This file is generated from connector metadata by scripts/generate-connector-docs.ts. Do not edit by hand. -->
|
|
2
|
+
|
|
1
3
|
# @rawdash/connector-stripe
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@rawdash/connector-stripe)
|
|
6
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Sync customers, products, prices, subscriptions, and invoices alongside charge, payment, dispute, and refund events from your Stripe account.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## Install
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
4. Enable **Read** access only for the resources you want to sync. The connector supports any subset of:
|
|
13
|
-
- Customers
|
|
14
|
-
- Subscriptions
|
|
15
|
-
- Invoices
|
|
16
|
-
- Charges
|
|
17
|
-
- Payment Intents
|
|
18
|
-
- Products
|
|
19
|
-
- Prices
|
|
20
|
-
- Disputes
|
|
21
|
-
- Refunds
|
|
22
|
-
5. Click **Create key** and copy the key value starting with `rk_live_…` (or `rk_test_…` for test mode).
|
|
12
|
+
```sh
|
|
13
|
+
npm install @rawdash/connector-stripe
|
|
14
|
+
```
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
## Authentication
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
Authenticates with a Stripe restricted API key that has read-only access to the resources you want to sync.
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
1. Open the Stripe Dashboard → Developers → API keys.
|
|
21
|
+
2. Create a restricted key with Read access for the resources you plan to sync (customers, products, prices, subscriptions, invoices, charges, payment intents, disputes, refunds).
|
|
22
|
+
3. Store the key as a secret and reference it from the connector config as `apiKey: secret("STRIPE_API_KEY")`.
|
|
29
23
|
|
|
30
24
|
## Configuration
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
| Field | Type | Required | Description |
|
|
27
|
+
| ----------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `apiKey` | secret | Yes | Stripe Restricted API key with read-only access. Create one at Dashboard → Developers → API keys. |
|
|
29
|
+
| `accountId` | string | No | Stripe Connect account ID. Only needed if you are a platform accessing a connected account. |
|
|
30
|
+
| `resources` | array | No | Which Stripe resources to sync. Omit to sync all resources. The API key only needs Read scope for the resources listed here. |
|
|
31
|
+
|
|
32
|
+
## Resources
|
|
33
|
+
|
|
34
|
+
- **`stripe_customer`** _(entity)_ - Customers with email, name, default currency, and delinquency state.
|
|
35
|
+
- Endpoint: `GET /v1/customers`
|
|
36
|
+
- **`stripe_product`** _(entity)_ - Products in your catalog, including active state.
|
|
37
|
+
- Endpoint: `GET /v1/products`
|
|
38
|
+
- **`stripe_price`** _(entity)_ - Prices with unit amount, currency, and recurring interval, linked to their product.
|
|
39
|
+
- Endpoint: `GET /v1/prices`
|
|
40
|
+
- **`stripe_subscription`** _(entity)_ - Subscriptions with status, current period, cancellation state, and computed monthly recurring revenue (mrrAmount, in the smallest currency unit).
|
|
41
|
+
- Endpoint: `GET /v1/subscriptions`
|
|
42
|
+
- mrrAmount is computed as unit_amount x quantity, normalized to a monthly cadence (yearly / 12, weekly x 52 / 12, etc.).
|
|
43
|
+
- **`stripe_invoice`** _(entity)_ - Invoices with amount due, amount paid, status, and due date, linked to their customer and subscription.
|
|
44
|
+
- Endpoint: `GET /v1/invoices`
|
|
45
|
+
- **`stripe_charge`** _(event)_ - Charge attempts with amount, currency, status, and failure code, timestamped at creation.
|
|
46
|
+
- Endpoint: `GET /v1/charges`
|
|
47
|
+
- **`stripe_payment_intent`** _(event)_ - Payment intents with amount, currency, and status, timestamped at creation.
|
|
48
|
+
- Endpoint: `GET /v1/payment_intents`
|
|
49
|
+
- **`stripe_dispute`** _(event)_ - Disputes with amount, currency, reason, and status, linked to the disputed charge.
|
|
50
|
+
- Endpoint: `GET /v1/disputes`
|
|
51
|
+
- **`stripe_refund`** _(event)_ - Refunds with amount, currency, reason, and status, linked to the refunded charge.
|
|
52
|
+
- Endpoint: `GET /v1/refunds`
|
|
53
|
+
|
|
54
|
+
## Example
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
```ts
|
|
57
|
+
import {
|
|
58
|
+
defineConfig,
|
|
59
|
+
defineDashboard,
|
|
60
|
+
defineMetric,
|
|
61
|
+
secret,
|
|
62
|
+
} from '@rawdash/core';
|
|
63
|
+
|
|
64
|
+
const stripe = {
|
|
65
|
+
name: 'stripe',
|
|
66
|
+
connectorId: 'stripe',
|
|
67
|
+
config: {
|
|
42
68
|
apiKey: secret('STRIPE_API_KEY'),
|
|
69
|
+
resources: ['customers', 'subscriptions', 'invoices', 'charges'],
|
|
43
70
|
},
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Or using `StripeConnector.create` (validates via `configFields` Zod schema):
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
const stripe = StripeConnector.create({
|
|
51
|
-
apiKey: { $secret: 'STRIPE_API_KEY' },
|
|
52
|
-
// accountId: 'acct_…',
|
|
53
|
-
// resources: ['customers', 'subscriptions', 'invoices'],
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Choosing resources
|
|
58
|
-
|
|
59
|
-
By default the connector syncs every supported resource. To sync only a subset, pass `resources` with any combination of:
|
|
60
|
-
|
|
61
|
-
`customers`, `products`, `prices`, `subscriptions`, `invoices`, `charges`, `payment_intents`, `disputes`, `refunds`
|
|
62
|
-
|
|
63
|
-
Each name is a Stripe API resource. The list you choose should match the Read scopes on your Restricted API key — picking only what you need also reduces API calls during full syncs.
|
|
64
|
-
|
|
65
|
-
Then pass it to `defineConfig`:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { defineConfig, defineDashboard, defineMetric } from '@rawdash/core';
|
|
71
|
+
};
|
|
69
72
|
|
|
70
73
|
export default defineConfig({
|
|
71
|
-
connectors: [
|
|
74
|
+
connectors: [stripe],
|
|
72
75
|
dashboards: {
|
|
73
|
-
|
|
76
|
+
revenue: defineDashboard({
|
|
74
77
|
widgets: {
|
|
75
|
-
mrr: {
|
|
76
|
-
kind: 'stat',
|
|
77
|
-
title: 'MRR',
|
|
78
|
-
metric: defineMetric({
|
|
79
|
-
connector: stripe,
|
|
80
|
-
shape: 'entity',
|
|
81
|
-
entityType: 'stripe_subscription',
|
|
82
|
-
field: 'mrrAmount',
|
|
83
|
-
fn: 'sum',
|
|
84
|
-
filter: [{ field: 'status', op: 'eq', value: 'active' }],
|
|
85
|
-
}),
|
|
86
|
-
},
|
|
87
78
|
active_subscriptions: {
|
|
88
79
|
kind: 'stat',
|
|
89
80
|
title: 'Active subscriptions',
|
|
@@ -95,91 +86,28 @@ export default defineConfig({
|
|
|
95
86
|
filter: [{ field: 'status', op: 'eq', value: 'active' }],
|
|
96
87
|
}),
|
|
97
88
|
},
|
|
98
|
-
failed_charges_today: {
|
|
99
|
-
kind: 'stat',
|
|
100
|
-
title: 'Failed charges today',
|
|
101
|
-
metric: defineMetric({
|
|
102
|
-
connector: stripe,
|
|
103
|
-
shape: 'event',
|
|
104
|
-
name: 'stripe_charge',
|
|
105
|
-
fn: 'count',
|
|
106
|
-
window: '1d',
|
|
107
|
-
filter: [{ field: 'status', op: 'eq', value: 'failed' }],
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
daily_revenue: {
|
|
111
|
-
kind: 'timeseries',
|
|
112
|
-
title: 'Daily revenue',
|
|
113
|
-
window: '30d',
|
|
114
|
-
metric: defineMetric({
|
|
115
|
-
connector: stripe,
|
|
116
|
-
shape: 'event',
|
|
117
|
-
name: 'stripe_charge',
|
|
118
|
-
field: 'amount',
|
|
119
|
-
fn: 'sum',
|
|
120
|
-
window: '30d',
|
|
121
|
-
filter: [{ field: 'status', op: 'eq', value: 'succeeded' }],
|
|
122
|
-
groupBy: { field: 'start_ts', granularity: 'day' },
|
|
123
|
-
}),
|
|
124
|
-
},
|
|
125
89
|
},
|
|
126
90
|
}),
|
|
127
91
|
},
|
|
128
92
|
});
|
|
129
93
|
```
|
|
130
94
|
|
|
131
|
-
##
|
|
132
|
-
|
|
133
|
-
All monetary amounts are in the **smallest currency unit** (e.g. cents for USD).
|
|
134
|
-
|
|
135
|
-
| Storage shape | Entity/event type | Key attributes |
|
|
136
|
-
| ------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
137
|
-
| entity | `stripe_customer` | email, name, created, currency, delinquent, livemode |
|
|
138
|
-
| entity | `stripe_product` | name, active, created |
|
|
139
|
-
| entity | `stripe_price` | productId, unitAmount, currency, interval, intervalCount, active, created |
|
|
140
|
-
| entity | `stripe_subscription` | customerId, status, planId, currentPeriodStart, currentPeriodEnd, cancelAtPeriodEnd, canceledAt, trialEnd, mrrAmount, currency |
|
|
141
|
-
| entity | `stripe_invoice` | customerId, subscriptionId, status, amountDue, amountPaid, currency, created, dueDate, hostedInvoiceUrl |
|
|
142
|
-
| event | `stripe_charge` | id, customerId, amount, currency, status, failureCode, paymentIntentId |
|
|
143
|
-
| event | `stripe_payment_intent` | id, customerId, amount, currency, status |
|
|
144
|
-
| event | `stripe_dispute` | id, chargeId, amount, currency, reason, status |
|
|
145
|
-
| event | `stripe_refund` | id, chargeId, amount, currency, reason, status |
|
|
146
|
-
|
|
147
|
-
### `mrrAmount`
|
|
148
|
-
|
|
149
|
-
Pre-computed monthly-equivalent revenue for each subscription in the smallest currency unit. Formula: `unit_amount × quantity`, normalised to a monthly cadence (yearly ÷ 12, weekly × 52 ÷ 12, etc.).
|
|
95
|
+
## Rate limits
|
|
150
96
|
|
|
151
|
-
|
|
97
|
+
Stripe 429 responses carry a Retry-After header; requests are retried with exponential backoff. List pagination uses the starting_after cursor (limit 100).
|
|
152
98
|
|
|
153
|
-
|
|
154
|
-
- **Incremental** (`mode: 'latest'`): entity phases use a 7-day lookback (`created[gte]`) to catch status mutations; event phases use `created[gt]` to fetch only new records.
|
|
155
|
-
- **Rate limits**: Stripe's 429 responses carry a `Retry-After` header. The built-in HTTP client retries automatically with exponential back-off.
|
|
156
|
-
- **Resumable**: if a sync is interrupted (signal abort), the connector returns a cursor so the engine can resume from the same page.
|
|
99
|
+
## Limitations
|
|
157
100
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
import { StripeConnector, configFields } from '@rawdash/connector-stripe';
|
|
164
|
-
|
|
165
|
-
createMcpServer({
|
|
166
|
-
// ...
|
|
167
|
-
connectorFactories: [
|
|
168
|
-
{
|
|
169
|
-
id: 'stripe',
|
|
170
|
-
configFields,
|
|
171
|
-
create: StripeConnector.create,
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
});
|
|
175
|
-
```
|
|
101
|
+
- Monetary amounts are stored in the smallest currency unit (e.g. cents), matching the Stripe API.
|
|
102
|
+
- The set of synced resources is controlled by the `resources` config field; omit it to sync all of them.
|
|
103
|
+
- Incremental syncs use a 7-day lookback for entities and created[gt] for events.
|
|
176
104
|
|
|
177
|
-
##
|
|
105
|
+
## Links
|
|
178
106
|
|
|
179
|
-
|
|
107
|
+
- [Rawdash docs](https://rawdash.dev/docs/connectors/)
|
|
108
|
+
- [Stripe API docs](https://stripe.com/docs/api)
|
|
109
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
180
110
|
|
|
181
|
-
|
|
182
|
-
2. Pipe them through `connector.sync()` against an `InMemoryStorage` instance.
|
|
183
|
-
3. Assert universal invariants — non-empty entity ids, finite event timestamps, no `undefined` leaking into storage, no thrown errors on any valid input — plus per-resource counts.
|
|
111
|
+
## License
|
|
184
112
|
|
|
185
|
-
|
|
113
|
+
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseConnector, ConnectorContext, SyncOptions, StorageHandle, SyncResult } from '@rawdash/core';
|
|
1
|
+
import { BaseConnector, ConnectorContext, SyncOptions, StorageHandle, SyncResult, ConnectorDoc } from '@rawdash/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
declare const configFields: z.ZodObject<{
|
|
@@ -18,6 +18,7 @@ declare const configFields: z.ZodObject<{
|
|
|
18
18
|
refunds: "refunds";
|
|
19
19
|
}>>>;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
|
+
declare const doc: ConnectorDoc;
|
|
21
22
|
interface StripeSettings {
|
|
22
23
|
accountId?: string;
|
|
23
24
|
resources?: readonly StripeResource[];
|
|
@@ -67,6 +68,310 @@ type StripeResource = StripePhase;
|
|
|
67
68
|
declare function computeMrrAmountCents(subscription: StripeSubscription): number | null;
|
|
68
69
|
declare class StripeConnector extends BaseConnector<StripeSettings, StripeCredentials> {
|
|
69
70
|
static readonly id = "stripe";
|
|
71
|
+
static readonly resources: {
|
|
72
|
+
readonly stripe_customer: {
|
|
73
|
+
readonly shape: "entity";
|
|
74
|
+
readonly description: "Customers with email, name, default currency, and delinquency state.";
|
|
75
|
+
readonly endpoint: "GET /v1/customers";
|
|
76
|
+
readonly responses: {
|
|
77
|
+
readonly customers: z.ZodArray<z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
email: z.ZodNullable<z.ZodString>;
|
|
80
|
+
name: z.ZodNullable<z.ZodString>;
|
|
81
|
+
created: z.ZodNumber;
|
|
82
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
83
|
+
delinquent: z.ZodNullable<z.ZodBoolean>;
|
|
84
|
+
livemode: z.ZodBoolean;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
readonly stripe_product: {
|
|
89
|
+
readonly shape: "entity";
|
|
90
|
+
readonly description: "Products in your catalog, including active state.";
|
|
91
|
+
readonly endpoint: "GET /v1/products";
|
|
92
|
+
readonly responses: {
|
|
93
|
+
readonly products: z.ZodArray<z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
name: z.ZodString;
|
|
96
|
+
active: z.ZodBoolean;
|
|
97
|
+
created: z.ZodNumber;
|
|
98
|
+
}, z.core.$strip>>;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
readonly stripe_price: {
|
|
102
|
+
readonly shape: "entity";
|
|
103
|
+
readonly description: "Prices with unit amount, currency, and recurring interval, linked to their product.";
|
|
104
|
+
readonly endpoint: "GET /v1/prices";
|
|
105
|
+
readonly responses: {
|
|
106
|
+
readonly prices: z.ZodArray<z.ZodObject<{
|
|
107
|
+
id: z.ZodString;
|
|
108
|
+
product: z.ZodString;
|
|
109
|
+
unit_amount: z.ZodNullable<z.ZodNumber>;
|
|
110
|
+
currency: z.ZodString;
|
|
111
|
+
recurring: z.ZodNullable<z.ZodObject<{
|
|
112
|
+
interval: z.ZodEnum<{
|
|
113
|
+
day: "day";
|
|
114
|
+
week: "week";
|
|
115
|
+
month: "month";
|
|
116
|
+
year: "year";
|
|
117
|
+
}>;
|
|
118
|
+
interval_count: z.ZodNumber;
|
|
119
|
+
}, z.core.$strip>>;
|
|
120
|
+
active: z.ZodBoolean;
|
|
121
|
+
created: z.ZodNumber;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
readonly stripe_subscription: {
|
|
126
|
+
readonly shape: "entity";
|
|
127
|
+
readonly description: "Subscriptions with status, current period, cancellation state, and computed monthly recurring revenue (mrrAmount, in the smallest currency unit).";
|
|
128
|
+
readonly endpoint: "GET /v1/subscriptions";
|
|
129
|
+
readonly notes: "mrrAmount is computed as unit_amount x quantity, normalized to a monthly cadence (yearly / 12, weekly x 52 / 12, etc.).";
|
|
130
|
+
readonly responses: {
|
|
131
|
+
readonly subscriptions: z.ZodArray<z.ZodObject<{
|
|
132
|
+
id: z.ZodString;
|
|
133
|
+
customer: z.ZodString;
|
|
134
|
+
status: z.ZodString;
|
|
135
|
+
items: z.ZodObject<{
|
|
136
|
+
data: z.ZodArray<z.ZodObject<{
|
|
137
|
+
price: z.ZodObject<{
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
product: z.ZodString;
|
|
140
|
+
unit_amount: z.ZodNullable<z.ZodNumber>;
|
|
141
|
+
currency: z.ZodString;
|
|
142
|
+
recurring: z.ZodNullable<z.ZodObject<{
|
|
143
|
+
interval: z.ZodEnum<{
|
|
144
|
+
day: "day";
|
|
145
|
+
week: "week";
|
|
146
|
+
month: "month";
|
|
147
|
+
year: "year";
|
|
148
|
+
}>;
|
|
149
|
+
interval_count: z.ZodNumber;
|
|
150
|
+
}, z.core.$strip>>;
|
|
151
|
+
active: z.ZodBoolean;
|
|
152
|
+
created: z.ZodNumber;
|
|
153
|
+
}, z.core.$strip>;
|
|
154
|
+
quantity: z.ZodNullable<z.ZodNumber>;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
current_period_start: z.ZodNumber;
|
|
158
|
+
current_period_end: z.ZodNumber;
|
|
159
|
+
cancel_at_period_end: z.ZodBoolean;
|
|
160
|
+
canceled_at: z.ZodNullable<z.ZodNumber>;
|
|
161
|
+
trial_end: z.ZodNullable<z.ZodNumber>;
|
|
162
|
+
currency: z.ZodString;
|
|
163
|
+
created: z.ZodNumber;
|
|
164
|
+
}, z.core.$strip>>;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
readonly stripe_invoice: {
|
|
168
|
+
readonly shape: "entity";
|
|
169
|
+
readonly description: "Invoices with amount due, amount paid, status, and due date, linked to their customer and subscription.";
|
|
170
|
+
readonly endpoint: "GET /v1/invoices";
|
|
171
|
+
readonly responses: {
|
|
172
|
+
readonly invoices: z.ZodArray<z.ZodObject<{
|
|
173
|
+
id: z.ZodString;
|
|
174
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
175
|
+
subscription: z.ZodNullable<z.ZodString>;
|
|
176
|
+
status: z.ZodNullable<z.ZodString>;
|
|
177
|
+
amount_due: z.ZodNumber;
|
|
178
|
+
amount_paid: z.ZodNumber;
|
|
179
|
+
currency: z.ZodString;
|
|
180
|
+
created: z.ZodNumber;
|
|
181
|
+
due_date: z.ZodNullable<z.ZodNumber>;
|
|
182
|
+
hosted_invoice_url: z.ZodNullable<z.ZodString>;
|
|
183
|
+
}, z.core.$strip>>;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
readonly stripe_charge: {
|
|
187
|
+
readonly shape: "event";
|
|
188
|
+
readonly description: "Charge attempts with amount, currency, status, and failure code, timestamped at creation.";
|
|
189
|
+
readonly endpoint: "GET /v1/charges";
|
|
190
|
+
readonly responses: {
|
|
191
|
+
readonly charges: z.ZodArray<z.ZodObject<{
|
|
192
|
+
id: z.ZodString;
|
|
193
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
194
|
+
amount: z.ZodNumber;
|
|
195
|
+
currency: z.ZodString;
|
|
196
|
+
status: z.ZodString;
|
|
197
|
+
failure_code: z.ZodNullable<z.ZodString>;
|
|
198
|
+
created: z.ZodNumber;
|
|
199
|
+
payment_intent: z.ZodNullable<z.ZodString>;
|
|
200
|
+
}, z.core.$strip>>;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
readonly stripe_payment_intent: {
|
|
204
|
+
readonly shape: "event";
|
|
205
|
+
readonly description: "Payment intents with amount, currency, and status, timestamped at creation.";
|
|
206
|
+
readonly endpoint: "GET /v1/payment_intents";
|
|
207
|
+
readonly responses: {
|
|
208
|
+
readonly payment_intents: z.ZodArray<z.ZodObject<{
|
|
209
|
+
id: z.ZodString;
|
|
210
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
211
|
+
amount: z.ZodNumber;
|
|
212
|
+
currency: z.ZodString;
|
|
213
|
+
status: z.ZodString;
|
|
214
|
+
created: z.ZodNumber;
|
|
215
|
+
}, z.core.$strip>>;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
readonly stripe_dispute: {
|
|
219
|
+
readonly shape: "event";
|
|
220
|
+
readonly description: "Disputes with amount, currency, reason, and status, linked to the disputed charge.";
|
|
221
|
+
readonly endpoint: "GET /v1/disputes";
|
|
222
|
+
readonly responses: {
|
|
223
|
+
readonly disputes: z.ZodArray<z.ZodObject<{
|
|
224
|
+
id: z.ZodString;
|
|
225
|
+
charge: z.ZodString;
|
|
226
|
+
amount: z.ZodNumber;
|
|
227
|
+
currency: z.ZodString;
|
|
228
|
+
reason: z.ZodString;
|
|
229
|
+
status: z.ZodString;
|
|
230
|
+
created: z.ZodNumber;
|
|
231
|
+
}, z.core.$strip>>;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
readonly stripe_refund: {
|
|
235
|
+
readonly shape: "event";
|
|
236
|
+
readonly description: "Refunds with amount, currency, reason, and status, linked to the refunded charge.";
|
|
237
|
+
readonly endpoint: "GET /v1/refunds";
|
|
238
|
+
readonly responses: {
|
|
239
|
+
readonly refunds: z.ZodArray<z.ZodObject<{
|
|
240
|
+
id: z.ZodString;
|
|
241
|
+
charge: z.ZodNullable<z.ZodString>;
|
|
242
|
+
amount: z.ZodNumber;
|
|
243
|
+
currency: z.ZodString;
|
|
244
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
245
|
+
status: z.ZodNullable<z.ZodString>;
|
|
246
|
+
created: z.ZodNumber;
|
|
247
|
+
}, z.core.$strip>>;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
static readonly schemas: {
|
|
252
|
+
readonly customers: z.ZodArray<z.ZodObject<{
|
|
253
|
+
id: z.ZodString;
|
|
254
|
+
email: z.ZodNullable<z.ZodString>;
|
|
255
|
+
name: z.ZodNullable<z.ZodString>;
|
|
256
|
+
created: z.ZodNumber;
|
|
257
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
258
|
+
delinquent: z.ZodNullable<z.ZodBoolean>;
|
|
259
|
+
livemode: z.ZodBoolean;
|
|
260
|
+
}, z.core.$strip>>;
|
|
261
|
+
} & {
|
|
262
|
+
readonly products: z.ZodArray<z.ZodObject<{
|
|
263
|
+
id: z.ZodString;
|
|
264
|
+
name: z.ZodString;
|
|
265
|
+
active: z.ZodBoolean;
|
|
266
|
+
created: z.ZodNumber;
|
|
267
|
+
}, z.core.$strip>>;
|
|
268
|
+
} & {
|
|
269
|
+
readonly prices: z.ZodArray<z.ZodObject<{
|
|
270
|
+
id: z.ZodString;
|
|
271
|
+
product: z.ZodString;
|
|
272
|
+
unit_amount: z.ZodNullable<z.ZodNumber>;
|
|
273
|
+
currency: z.ZodString;
|
|
274
|
+
recurring: z.ZodNullable<z.ZodObject<{
|
|
275
|
+
interval: z.ZodEnum<{
|
|
276
|
+
day: "day";
|
|
277
|
+
week: "week";
|
|
278
|
+
month: "month";
|
|
279
|
+
year: "year";
|
|
280
|
+
}>;
|
|
281
|
+
interval_count: z.ZodNumber;
|
|
282
|
+
}, z.core.$strip>>;
|
|
283
|
+
active: z.ZodBoolean;
|
|
284
|
+
created: z.ZodNumber;
|
|
285
|
+
}, z.core.$strip>>;
|
|
286
|
+
} & {
|
|
287
|
+
readonly subscriptions: z.ZodArray<z.ZodObject<{
|
|
288
|
+
id: z.ZodString;
|
|
289
|
+
customer: z.ZodString;
|
|
290
|
+
status: z.ZodString;
|
|
291
|
+
items: z.ZodObject<{
|
|
292
|
+
data: z.ZodArray<z.ZodObject<{
|
|
293
|
+
price: z.ZodObject<{
|
|
294
|
+
id: z.ZodString;
|
|
295
|
+
product: z.ZodString;
|
|
296
|
+
unit_amount: z.ZodNullable<z.ZodNumber>;
|
|
297
|
+
currency: z.ZodString;
|
|
298
|
+
recurring: z.ZodNullable<z.ZodObject<{
|
|
299
|
+
interval: z.ZodEnum<{
|
|
300
|
+
day: "day";
|
|
301
|
+
week: "week";
|
|
302
|
+
month: "month";
|
|
303
|
+
year: "year";
|
|
304
|
+
}>;
|
|
305
|
+
interval_count: z.ZodNumber;
|
|
306
|
+
}, z.core.$strip>>;
|
|
307
|
+
active: z.ZodBoolean;
|
|
308
|
+
created: z.ZodNumber;
|
|
309
|
+
}, z.core.$strip>;
|
|
310
|
+
quantity: z.ZodNullable<z.ZodNumber>;
|
|
311
|
+
}, z.core.$strip>>;
|
|
312
|
+
}, z.core.$strip>;
|
|
313
|
+
current_period_start: z.ZodNumber;
|
|
314
|
+
current_period_end: z.ZodNumber;
|
|
315
|
+
cancel_at_period_end: z.ZodBoolean;
|
|
316
|
+
canceled_at: z.ZodNullable<z.ZodNumber>;
|
|
317
|
+
trial_end: z.ZodNullable<z.ZodNumber>;
|
|
318
|
+
currency: z.ZodString;
|
|
319
|
+
created: z.ZodNumber;
|
|
320
|
+
}, z.core.$strip>>;
|
|
321
|
+
} & {
|
|
322
|
+
readonly invoices: z.ZodArray<z.ZodObject<{
|
|
323
|
+
id: z.ZodString;
|
|
324
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
325
|
+
subscription: z.ZodNullable<z.ZodString>;
|
|
326
|
+
status: z.ZodNullable<z.ZodString>;
|
|
327
|
+
amount_due: z.ZodNumber;
|
|
328
|
+
amount_paid: z.ZodNumber;
|
|
329
|
+
currency: z.ZodString;
|
|
330
|
+
created: z.ZodNumber;
|
|
331
|
+
due_date: z.ZodNullable<z.ZodNumber>;
|
|
332
|
+
hosted_invoice_url: z.ZodNullable<z.ZodString>;
|
|
333
|
+
}, z.core.$strip>>;
|
|
334
|
+
} & {
|
|
335
|
+
readonly charges: z.ZodArray<z.ZodObject<{
|
|
336
|
+
id: z.ZodString;
|
|
337
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
338
|
+
amount: z.ZodNumber;
|
|
339
|
+
currency: z.ZodString;
|
|
340
|
+
status: z.ZodString;
|
|
341
|
+
failure_code: z.ZodNullable<z.ZodString>;
|
|
342
|
+
created: z.ZodNumber;
|
|
343
|
+
payment_intent: z.ZodNullable<z.ZodString>;
|
|
344
|
+
}, z.core.$strip>>;
|
|
345
|
+
} & {
|
|
346
|
+
readonly payment_intents: z.ZodArray<z.ZodObject<{
|
|
347
|
+
id: z.ZodString;
|
|
348
|
+
customer: z.ZodNullable<z.ZodString>;
|
|
349
|
+
amount: z.ZodNumber;
|
|
350
|
+
currency: z.ZodString;
|
|
351
|
+
status: z.ZodString;
|
|
352
|
+
created: z.ZodNumber;
|
|
353
|
+
}, z.core.$strip>>;
|
|
354
|
+
} & {
|
|
355
|
+
readonly disputes: z.ZodArray<z.ZodObject<{
|
|
356
|
+
id: z.ZodString;
|
|
357
|
+
charge: z.ZodString;
|
|
358
|
+
amount: z.ZodNumber;
|
|
359
|
+
currency: z.ZodString;
|
|
360
|
+
reason: z.ZodString;
|
|
361
|
+
status: z.ZodString;
|
|
362
|
+
created: z.ZodNumber;
|
|
363
|
+
}, z.core.$strip>>;
|
|
364
|
+
} & {
|
|
365
|
+
readonly refunds: z.ZodArray<z.ZodObject<{
|
|
366
|
+
id: z.ZodString;
|
|
367
|
+
charge: z.ZodNullable<z.ZodString>;
|
|
368
|
+
amount: z.ZodNumber;
|
|
369
|
+
currency: z.ZodString;
|
|
370
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
371
|
+
status: z.ZodNullable<z.ZodString>;
|
|
372
|
+
created: z.ZodNumber;
|
|
373
|
+
}, z.core.$strip>>;
|
|
374
|
+
} & Readonly<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
70
375
|
static create(input: unknown, ctx?: ConnectorContext): StripeConnector;
|
|
71
376
|
readonly id = "stripe";
|
|
72
377
|
readonly credentials: {
|
|
@@ -86,4 +391,4 @@ declare class StripeConnector extends BaseConnector<StripeSettings, StripeCreden
|
|
|
86
391
|
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
87
392
|
}
|
|
88
393
|
|
|
89
|
-
export { StripeConnector, type StripeSettings, computeMrrAmountCents, configFields, StripeConnector as default };
|
|
394
|
+
export { StripeConnector, type StripeSettings, computeMrrAmountCents, configFields, StripeConnector as default, doc };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
// ../../connector-shared/dist/index.js
|
|
2
|
+
var HTTP_CLIENT_VERSION = "0.0.0";
|
|
3
|
+
var DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;
|
|
4
|
+
function connectorUserAgent(connectorId) {
|
|
5
|
+
return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
// src/stripe.ts
|
|
2
9
|
import {
|
|
3
10
|
BaseConnector,
|
|
4
11
|
defineConfigFields,
|
|
5
|
-
|
|
12
|
+
defineConnectorDoc,
|
|
13
|
+
defineResources,
|
|
14
|
+
makeChunkedCursorGuard,
|
|
15
|
+
paginateChunked,
|
|
16
|
+
schemasFromResources,
|
|
17
|
+
selectActivePhases
|
|
6
18
|
} from "@rawdash/core";
|
|
7
19
|
import { z } from "zod";
|
|
8
20
|
var configFields = defineConfigFields(
|
|
@@ -36,6 +48,31 @@ var configFields = defineConfigFields(
|
|
|
36
48
|
})
|
|
37
49
|
})
|
|
38
50
|
);
|
|
51
|
+
var doc = defineConnectorDoc({
|
|
52
|
+
displayName: "Stripe",
|
|
53
|
+
category: "finance",
|
|
54
|
+
brandColor: "#635BFF",
|
|
55
|
+
tagline: "Sync customers, products, prices, subscriptions, and invoices alongside charge, payment, dispute, and refund events from your Stripe account.",
|
|
56
|
+
vendor: {
|
|
57
|
+
name: "Stripe",
|
|
58
|
+
apiDocs: "https://stripe.com/docs/api",
|
|
59
|
+
website: "https://stripe.com"
|
|
60
|
+
},
|
|
61
|
+
auth: {
|
|
62
|
+
summary: "Authenticates with a Stripe restricted API key that has read-only access to the resources you want to sync.",
|
|
63
|
+
setup: [
|
|
64
|
+
"Open the Stripe Dashboard \u2192 Developers \u2192 API keys.",
|
|
65
|
+
"Create a restricted key with Read access for the resources you plan to sync (customers, products, prices, subscriptions, invoices, charges, payment intents, disputes, refunds).",
|
|
66
|
+
'Store the key as a secret and reference it from the connector config as `apiKey: secret("STRIPE_API_KEY")`.'
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
rateLimit: "Stripe 429 responses carry a Retry-After header; requests are retried with exponential backoff. List pagination uses the starting_after cursor (limit 100).",
|
|
70
|
+
limitations: [
|
|
71
|
+
"Monetary amounts are stored in the smallest currency unit (e.g. cents), matching the Stripe API.",
|
|
72
|
+
"The set of synced resources is controlled by the `resources` config field; omit it to sync all of them.",
|
|
73
|
+
"Incremental syncs use a 7-day lookback for entities and created[gt] for events."
|
|
74
|
+
]
|
|
75
|
+
});
|
|
39
76
|
var stripeCredentials = {
|
|
40
77
|
apiKey: {
|
|
41
78
|
description: "Stripe API key",
|
|
@@ -53,22 +90,7 @@ var PHASE_ORDER = [
|
|
|
53
90
|
"disputes",
|
|
54
91
|
"refunds"
|
|
55
92
|
];
|
|
56
|
-
|
|
57
|
-
if (typeof value !== "object" || value === null) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
const v = value;
|
|
61
|
-
if (typeof v.phase !== "string") {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (!PHASE_ORDER.includes(v.phase)) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (v.page !== null && typeof v.page !== "string") {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
93
|
+
var isStripeSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);
|
|
72
94
|
var ENTITY_TYPE_BY_PHASE = {
|
|
73
95
|
customers: "stripe_customer",
|
|
74
96
|
products: "stripe_product",
|
|
@@ -121,8 +143,163 @@ function computeMrrAmountCents(subscription) {
|
|
|
121
143
|
}
|
|
122
144
|
return Math.round(sum);
|
|
123
145
|
}
|
|
146
|
+
var idString = z.string().min(1);
|
|
147
|
+
var customerSchema = z.object({
|
|
148
|
+
id: idString,
|
|
149
|
+
email: z.string().nullable(),
|
|
150
|
+
name: z.string().nullable(),
|
|
151
|
+
created: z.number().int().nonnegative(),
|
|
152
|
+
currency: z.string().nullable(),
|
|
153
|
+
delinquent: z.boolean().nullable(),
|
|
154
|
+
livemode: z.boolean()
|
|
155
|
+
});
|
|
156
|
+
var productSchema = z.object({
|
|
157
|
+
id: idString,
|
|
158
|
+
name: z.string(),
|
|
159
|
+
active: z.boolean(),
|
|
160
|
+
created: z.number().int().nonnegative()
|
|
161
|
+
});
|
|
162
|
+
var priceSchema = z.object({
|
|
163
|
+
id: idString,
|
|
164
|
+
product: idString,
|
|
165
|
+
unit_amount: z.number().int().nullable(),
|
|
166
|
+
currency: z.string(),
|
|
167
|
+
recurring: z.object({
|
|
168
|
+
interval: z.enum(["day", "week", "month", "year"]),
|
|
169
|
+
interval_count: z.number().int().positive()
|
|
170
|
+
}).nullable(),
|
|
171
|
+
active: z.boolean(),
|
|
172
|
+
created: z.number().int().nonnegative()
|
|
173
|
+
});
|
|
174
|
+
var subscriptionSchema = z.object({
|
|
175
|
+
id: idString,
|
|
176
|
+
customer: idString,
|
|
177
|
+
status: z.string(),
|
|
178
|
+
items: z.object({
|
|
179
|
+
data: z.array(
|
|
180
|
+
z.object({
|
|
181
|
+
price: priceSchema,
|
|
182
|
+
quantity: z.number().int().nullable()
|
|
183
|
+
})
|
|
184
|
+
)
|
|
185
|
+
}),
|
|
186
|
+
current_period_start: z.number().int().nonnegative(),
|
|
187
|
+
current_period_end: z.number().int().nonnegative(),
|
|
188
|
+
cancel_at_period_end: z.boolean(),
|
|
189
|
+
canceled_at: z.number().int().nullable(),
|
|
190
|
+
trial_end: z.number().int().nullable(),
|
|
191
|
+
currency: z.string(),
|
|
192
|
+
created: z.number().int().nonnegative()
|
|
193
|
+
});
|
|
194
|
+
var invoiceSchema = z.object({
|
|
195
|
+
id: idString,
|
|
196
|
+
customer: idString.nullable(),
|
|
197
|
+
subscription: idString.nullable(),
|
|
198
|
+
status: z.string().nullable(),
|
|
199
|
+
amount_due: z.number().int(),
|
|
200
|
+
amount_paid: z.number().int(),
|
|
201
|
+
currency: z.string(),
|
|
202
|
+
created: z.number().int().nonnegative(),
|
|
203
|
+
due_date: z.number().int().nullable(),
|
|
204
|
+
hosted_invoice_url: z.string().nullable()
|
|
205
|
+
});
|
|
206
|
+
var chargeSchema = z.object({
|
|
207
|
+
id: idString,
|
|
208
|
+
customer: idString.nullable(),
|
|
209
|
+
amount: z.number().int(),
|
|
210
|
+
currency: z.string(),
|
|
211
|
+
status: z.string(),
|
|
212
|
+
failure_code: z.string().nullable(),
|
|
213
|
+
created: z.number().int().nonnegative(),
|
|
214
|
+
payment_intent: idString.nullable()
|
|
215
|
+
});
|
|
216
|
+
var paymentIntentSchema = z.object({
|
|
217
|
+
id: idString,
|
|
218
|
+
customer: idString.nullable(),
|
|
219
|
+
amount: z.number().int(),
|
|
220
|
+
currency: z.string(),
|
|
221
|
+
status: z.string(),
|
|
222
|
+
created: z.number().int().nonnegative()
|
|
223
|
+
});
|
|
224
|
+
var disputeSchema = z.object({
|
|
225
|
+
id: idString,
|
|
226
|
+
charge: idString,
|
|
227
|
+
amount: z.number().int(),
|
|
228
|
+
currency: z.string(),
|
|
229
|
+
reason: z.string(),
|
|
230
|
+
status: z.string(),
|
|
231
|
+
created: z.number().int().nonnegative()
|
|
232
|
+
});
|
|
233
|
+
var refundSchema = z.object({
|
|
234
|
+
id: idString,
|
|
235
|
+
charge: idString.nullable(),
|
|
236
|
+
amount: z.number().int(),
|
|
237
|
+
currency: z.string(),
|
|
238
|
+
reason: z.string().nullable(),
|
|
239
|
+
status: z.string().nullable(),
|
|
240
|
+
created: z.number().int().nonnegative()
|
|
241
|
+
});
|
|
242
|
+
var stripeResources = defineResources({
|
|
243
|
+
stripe_customer: {
|
|
244
|
+
shape: "entity",
|
|
245
|
+
description: "Customers with email, name, default currency, and delinquency state.",
|
|
246
|
+
endpoint: "GET /v1/customers",
|
|
247
|
+
responses: { customers: z.array(customerSchema) }
|
|
248
|
+
},
|
|
249
|
+
stripe_product: {
|
|
250
|
+
shape: "entity",
|
|
251
|
+
description: "Products in your catalog, including active state.",
|
|
252
|
+
endpoint: "GET /v1/products",
|
|
253
|
+
responses: { products: z.array(productSchema) }
|
|
254
|
+
},
|
|
255
|
+
stripe_price: {
|
|
256
|
+
shape: "entity",
|
|
257
|
+
description: "Prices with unit amount, currency, and recurring interval, linked to their product.",
|
|
258
|
+
endpoint: "GET /v1/prices",
|
|
259
|
+
responses: { prices: z.array(priceSchema) }
|
|
260
|
+
},
|
|
261
|
+
stripe_subscription: {
|
|
262
|
+
shape: "entity",
|
|
263
|
+
description: "Subscriptions with status, current period, cancellation state, and computed monthly recurring revenue (mrrAmount, in the smallest currency unit).",
|
|
264
|
+
endpoint: "GET /v1/subscriptions",
|
|
265
|
+
notes: "mrrAmount is computed as unit_amount x quantity, normalized to a monthly cadence (yearly / 12, weekly x 52 / 12, etc.).",
|
|
266
|
+
responses: { subscriptions: z.array(subscriptionSchema) }
|
|
267
|
+
},
|
|
268
|
+
stripe_invoice: {
|
|
269
|
+
shape: "entity",
|
|
270
|
+
description: "Invoices with amount due, amount paid, status, and due date, linked to their customer and subscription.",
|
|
271
|
+
endpoint: "GET /v1/invoices",
|
|
272
|
+
responses: { invoices: z.array(invoiceSchema) }
|
|
273
|
+
},
|
|
274
|
+
stripe_charge: {
|
|
275
|
+
shape: "event",
|
|
276
|
+
description: "Charge attempts with amount, currency, status, and failure code, timestamped at creation.",
|
|
277
|
+
endpoint: "GET /v1/charges",
|
|
278
|
+
responses: { charges: z.array(chargeSchema) }
|
|
279
|
+
},
|
|
280
|
+
stripe_payment_intent: {
|
|
281
|
+
shape: "event",
|
|
282
|
+
description: "Payment intents with amount, currency, and status, timestamped at creation.",
|
|
283
|
+
endpoint: "GET /v1/payment_intents",
|
|
284
|
+
responses: { payment_intents: z.array(paymentIntentSchema) }
|
|
285
|
+
},
|
|
286
|
+
stripe_dispute: {
|
|
287
|
+
shape: "event",
|
|
288
|
+
description: "Disputes with amount, currency, reason, and status, linked to the disputed charge.",
|
|
289
|
+
endpoint: "GET /v1/disputes",
|
|
290
|
+
responses: { disputes: z.array(disputeSchema) }
|
|
291
|
+
},
|
|
292
|
+
stripe_refund: {
|
|
293
|
+
shape: "event",
|
|
294
|
+
description: "Refunds with amount, currency, reason, and status, linked to the refunded charge.",
|
|
295
|
+
endpoint: "GET /v1/refunds",
|
|
296
|
+
responses: { refunds: z.array(refundSchema) }
|
|
297
|
+
}
|
|
298
|
+
});
|
|
124
299
|
var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
125
300
|
static id = "stripe";
|
|
301
|
+
static resources = stripeResources;
|
|
302
|
+
static schemas = schemasFromResources(stripeResources);
|
|
126
303
|
static create(input, ctx) {
|
|
127
304
|
const parsed = configFields.parse(input);
|
|
128
305
|
return new _StripeConnector(
|
|
@@ -137,7 +314,7 @@ var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
|
137
314
|
const headers = {
|
|
138
315
|
Authorization: `Bearer ${this.creds.apiKey}`,
|
|
139
316
|
"Stripe-Version": "2024-06-20",
|
|
140
|
-
"User-Agent": "
|
|
317
|
+
"User-Agent": connectorUserAgent("stripe")
|
|
141
318
|
};
|
|
142
319
|
if (this.settings.accountId) {
|
|
143
320
|
headers["Stripe-Account"] = this.settings.accountId;
|
|
@@ -161,17 +338,28 @@ var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
|
161
338
|
}
|
|
162
339
|
return url.toString();
|
|
163
340
|
}
|
|
164
|
-
// created[gte] cutoff for entity phases in incremental mode
|
|
165
|
-
|
|
166
|
-
|
|
341
|
+
// created[gte] cutoff for entity phases — in incremental (latest) mode adds
|
|
342
|
+
// a 7-day grace so recent edits to slightly older entities still surface.
|
|
343
|
+
// Subscriptions are intentionally exempt in full mode: a subscription's
|
|
344
|
+
// updated_at is derived from current_period_end, so a still-active sub
|
|
345
|
+
// created well before the cutoff would otherwise be dropped on backfill.
|
|
346
|
+
entityCreatedGte(phase, options) {
|
|
347
|
+
if (!options.since) {
|
|
167
348
|
return void 0;
|
|
168
349
|
}
|
|
169
350
|
const sinceMs = new Date(options.since).getTime();
|
|
170
|
-
|
|
351
|
+
if (options.mode === "latest") {
|
|
352
|
+
return String(Math.floor((sinceMs - 7 * 24 * 60 * 60 * 1e3) / 1e3));
|
|
353
|
+
}
|
|
354
|
+
if (phase === "subscriptions") {
|
|
355
|
+
return void 0;
|
|
356
|
+
}
|
|
357
|
+
return String(Math.floor(sinceMs / 1e3));
|
|
171
358
|
}
|
|
172
|
-
// created[gt] cutoff for event phases in incremental
|
|
359
|
+
// created[gt] cutoff for event phases — applied in both full and incremental
|
|
360
|
+
// modes so backfill respects the widget-driven window.
|
|
173
361
|
eventCreatedGt(options) {
|
|
174
|
-
if (
|
|
362
|
+
if (!options.since) {
|
|
175
363
|
return void 0;
|
|
176
364
|
}
|
|
177
365
|
return String(Math.floor(new Date(options.since).getTime() / 1e3));
|
|
@@ -183,7 +371,7 @@ var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
|
183
371
|
return this.buildListUrl(phase, {
|
|
184
372
|
...extra,
|
|
185
373
|
starting_after: startingAfter,
|
|
186
|
-
"created[gte]": this.entityCreatedGte(options)
|
|
374
|
+
"created[gte]": this.entityCreatedGte(phase, options)
|
|
187
375
|
});
|
|
188
376
|
}
|
|
189
377
|
return this.buildListUrl(phase, {
|
|
@@ -364,12 +552,16 @@ var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
|
364
552
|
async sync(options, storage, signal) {
|
|
365
553
|
const cursor = isStripeSyncCursor(options.cursor) ? options.cursor : void 0;
|
|
366
554
|
const isFull = options.mode === "full";
|
|
367
|
-
const
|
|
368
|
-
|
|
555
|
+
const phases = selectActivePhases(
|
|
556
|
+
(r) => r,
|
|
557
|
+
PHASE_ORDER,
|
|
558
|
+
this.settings.resources
|
|
559
|
+
);
|
|
369
560
|
return paginateChunked({
|
|
370
561
|
phases,
|
|
371
562
|
cursor,
|
|
372
563
|
signal,
|
|
564
|
+
logger: this.logger,
|
|
373
565
|
fetchPage: async (phase, page, sig) => {
|
|
374
566
|
const url = this.buildPhaseUrl(phase, page, options);
|
|
375
567
|
const res = await this.fetch(
|
|
@@ -397,6 +589,7 @@ export {
|
|
|
397
589
|
StripeConnector,
|
|
398
590
|
computeMrrAmountCents,
|
|
399
591
|
configFields,
|
|
400
|
-
index_default as default
|
|
592
|
+
index_default as default,
|
|
593
|
+
doc
|
|
401
594
|
};
|
|
402
595
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stripe.ts","../src/index.ts"],"sourcesContent":["import type { HttpResponse } from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ChunkedSyncCursor,\n type ConnectorContext,\n type CredentialsSchema,\n type StorageHandle,\n type SyncOptions,\n type SyncResult,\n defineConfigFields,\n paginateChunked,\n} from '@rawdash/core';\nimport { z } from 'zod';\n\nexport const configFields = defineConfigFields(\n z.object({\n apiKey: z.object({ $secret: z.string() }).meta({\n label: 'API Key',\n description:\n 'Stripe Restricted API key with read-only access. Create one at Dashboard → Developers → API keys.',\n placeholder: 'rk_live_...',\n secret: true,\n }),\n accountId: z.string().optional().meta({\n label: 'Account ID (optional)',\n description:\n 'Stripe Connect account ID. Only needed if you are a platform accessing a connected account.',\n placeholder: 'acct_...',\n }),\n resources: z\n .array(\n z.enum([\n 'customers',\n 'products',\n 'prices',\n 'subscriptions',\n 'invoices',\n 'charges',\n 'payment_intents',\n 'disputes',\n 'refunds',\n ]),\n )\n .nonempty()\n .optional()\n .meta({\n label: 'Resources',\n description:\n 'Which Stripe resources to sync. Omit to sync all resources. The API key only needs Read scope for the resources listed here.',\n }),\n }),\n);\n\nexport interface StripeSettings {\n accountId?: string;\n resources?: readonly StripeResource[];\n}\n\n// ---------------------------------------------------------------------------\n// Stripe API types\n// ---------------------------------------------------------------------------\n\ninterface StripeListResponse<T> {\n object: 'list';\n data: T[];\n has_more: boolean;\n url: string;\n}\n\ninterface StripeCustomer {\n id: string;\n email: string | null;\n name: string | null;\n created: number;\n currency: string | null;\n delinquent: boolean | null;\n livemode: boolean;\n}\n\ninterface StripePriceRecurring {\n interval: 'day' | 'week' | 'month' | 'year';\n interval_count: number;\n}\n\ninterface StripePrice {\n id: string;\n product: string;\n unit_amount: number | null;\n currency: string;\n recurring: StripePriceRecurring | null;\n active: boolean;\n created: number;\n}\n\ninterface StripeSubscriptionItem {\n price: StripePrice;\n quantity: number | null;\n}\n\ninterface StripeSubscription {\n id: string;\n customer: string;\n status: string;\n items: { data: StripeSubscriptionItem[] };\n current_period_start: number;\n current_period_end: number;\n cancel_at_period_end: boolean;\n canceled_at: number | null;\n trial_end: number | null;\n currency: string;\n created: number;\n}\n\ninterface StripeInvoice {\n id: string;\n customer: string | null;\n subscription: string | null;\n status: string | null;\n amount_due: number;\n amount_paid: number;\n currency: string;\n created: number;\n due_date: number | null;\n hosted_invoice_url: string | null;\n}\n\ninterface StripeCharge {\n id: string;\n customer: string | null;\n amount: number;\n currency: string;\n status: string;\n failure_code: string | null;\n created: number;\n payment_intent: string | null;\n}\n\ninterface StripePaymentIntent {\n id: string;\n customer: string | null;\n amount: number;\n currency: string;\n status: string;\n created: number;\n}\n\ninterface StripeProduct {\n id: string;\n name: string;\n active: boolean;\n created: number;\n}\n\ninterface StripeDispute {\n id: string;\n charge: string;\n amount: number;\n currency: string;\n reason: string;\n status: string;\n created: number;\n}\n\ninterface StripeRefund {\n id: string;\n charge: string | null;\n amount: number;\n currency: string;\n reason: string | null;\n status: string | null;\n created: number;\n}\n\n// ---------------------------------------------------------------------------\n// Credentials\n// ---------------------------------------------------------------------------\n\nconst stripeCredentials = {\n apiKey: {\n description: 'Stripe API key',\n auth: 'required' as const,\n },\n} satisfies CredentialsSchema;\n\ntype StripeCredentials = typeof stripeCredentials;\n\n// ---------------------------------------------------------------------------\n// Sync phases + cursor\n// ---------------------------------------------------------------------------\n\nconst PHASE_ORDER = [\n 'customers',\n 'products',\n 'prices',\n 'subscriptions',\n 'invoices',\n 'charges',\n 'payment_intents',\n 'disputes',\n 'refunds',\n] as const;\n\ntype StripePhase = (typeof PHASE_ORDER)[number];\n\nexport type StripeResource = StripePhase;\n\ntype StripeSyncCursor = ChunkedSyncCursor<StripePhase, string>;\n\nfunction isStripeSyncCursor(value: unknown): value is StripeSyncCursor {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const v = value as { phase?: unknown; page?: unknown };\n if (typeof v.phase !== 'string') {\n return false;\n }\n if (!(PHASE_ORDER as readonly string[]).includes(v.phase)) {\n return false;\n }\n if (v.page !== null && typeof v.page !== 'string') {\n return false;\n }\n return true;\n}\n\nconst ENTITY_TYPE_BY_PHASE: Partial<Record<StripePhase, string>> = {\n customers: 'stripe_customer',\n products: 'stripe_product',\n prices: 'stripe_price',\n subscriptions: 'stripe_subscription',\n invoices: 'stripe_invoice',\n};\n\nconst EVENT_NAME_BY_PHASE: Partial<Record<StripePhase, string>> = {\n charges: 'stripe_charge',\n payment_intents: 'stripe_payment_intent',\n disputes: 'stripe_dispute',\n refunds: 'stripe_refund',\n};\n\n// ---------------------------------------------------------------------------\n// MRR helper\n// ---------------------------------------------------------------------------\n\nexport function computeMrrAmountCents(\n subscription: StripeSubscription,\n): number | null {\n let sum = 0;\n let counted = 0;\n for (const item of subscription.items.data) {\n const { unit_amount, recurring } = item.price;\n if (unit_amount === null || unit_amount === undefined || !recurring) {\n continue;\n }\n const quantity = item.quantity ?? 1;\n const total = unit_amount * quantity;\n const intervalCount = recurring.interval_count || 1;\n let monthly: number | null;\n switch (recurring.interval) {\n case 'month':\n monthly = total / intervalCount;\n break;\n case 'year':\n monthly = total / (12 * intervalCount);\n break;\n case 'week':\n monthly = (total * 52) / (12 * intervalCount);\n break;\n case 'day':\n monthly = (total * 365) / (12 * intervalCount);\n break;\n default:\n monthly = null;\n }\n if (monthly === null) {\n continue;\n }\n sum += monthly;\n counted++;\n }\n if (counted === 0) {\n return null;\n }\n return Math.round(sum);\n}\n\n// ---------------------------------------------------------------------------\n// StripeConnector\n// ---------------------------------------------------------------------------\n\nexport class StripeConnector extends BaseConnector<\n StripeSettings,\n StripeCredentials\n> {\n static readonly id = 'stripe';\n\n static create(input: unknown, ctx?: ConnectorContext): StripeConnector {\n const parsed = configFields.parse(input);\n return new StripeConnector(\n { accountId: parsed.accountId, resources: parsed.resources },\n { apiKey: parsed.apiKey },\n ctx,\n );\n }\n\n readonly id = 'stripe';\n override readonly credentials = stripeCredentials;\n\n private buildHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.creds.apiKey}`,\n 'Stripe-Version': '2024-06-20',\n 'User-Agent': 'rawdash/connector-stripe (+https://rawdash.dev)',\n };\n if (this.settings.accountId) {\n headers['Stripe-Account'] = this.settings.accountId;\n }\n return headers;\n }\n\n private fetch<T>(\n url: string,\n resource: string,\n signal?: AbortSignal,\n ): Promise<HttpResponse<T>> {\n return this.get<T>(url, {\n resource,\n headers: this.buildHeaders(),\n signal,\n });\n }\n\n private buildListUrl(\n path: string,\n params: Record<string, string | undefined>,\n ): string {\n const url = new URL(`https://api.stripe.com/v1/${path}`);\n url.searchParams.set('limit', '100');\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, value);\n }\n }\n return url.toString();\n }\n\n // created[gte] cutoff for entity phases in incremental mode (7-day lookback)\n private entityCreatedGte(options: SyncOptions): string | undefined {\n if (options.mode !== 'latest' || !options.since) {\n return undefined;\n }\n const sinceMs = new Date(options.since).getTime();\n return String(Math.floor((sinceMs - 7 * 24 * 60 * 60 * 1000) / 1000));\n }\n\n // created[gt] cutoff for event phases in incremental mode\n private eventCreatedGt(options: SyncOptions): string | undefined {\n if (options.mode !== 'latest' || !options.since) {\n return undefined;\n }\n return String(Math.floor(new Date(options.since).getTime() / 1000));\n }\n\n private buildPhaseUrl(\n phase: StripePhase,\n page: string | null,\n options: SyncOptions,\n ): string {\n const startingAfter = page ?? undefined;\n if (phase in ENTITY_TYPE_BY_PHASE) {\n const extra: Record<string, string | undefined> =\n phase === 'subscriptions' ? { status: 'all' } : {};\n return this.buildListUrl(phase, {\n ...extra,\n starting_after: startingAfter,\n 'created[gte]': this.entityCreatedGte(options),\n });\n }\n return this.buildListUrl(phase, {\n starting_after: startingAfter,\n 'created[gt]': this.eventCreatedGt(options),\n });\n }\n\n private async clearScopeOnFirstPage(\n storage: StorageHandle,\n phase: StripePhase,\n ): Promise<void> {\n const entityType = ENTITY_TYPE_BY_PHASE[phase];\n if (entityType) {\n await storage.entities([], { types: [entityType] });\n return;\n }\n const eventName = EVENT_NAME_BY_PHASE[phase];\n if (eventName) {\n await storage.events([], { names: [eventName] });\n }\n }\n\n private async writePhase(\n storage: StorageHandle,\n phase: StripePhase,\n items: unknown[],\n ): Promise<void> {\n switch (phase) {\n case 'customers':\n for (const c of items as StripeCustomer[]) {\n await storage.entity({\n type: 'stripe_customer',\n id: c.id,\n attributes: {\n email: c.email ?? null,\n name: c.name ?? null,\n created: c.created,\n currency: c.currency ?? null,\n delinquent: c.delinquent ?? false,\n livemode: c.livemode,\n },\n updated_at: c.created * 1000,\n });\n }\n return;\n case 'products':\n for (const p of items as StripeProduct[]) {\n await storage.entity({\n type: 'stripe_product',\n id: p.id,\n attributes: { name: p.name, active: p.active, created: p.created },\n updated_at: p.created * 1000,\n });\n }\n return;\n case 'prices':\n for (const p of items as StripePrice[]) {\n await storage.entity({\n type: 'stripe_price',\n id: p.id,\n attributes: {\n productId: p.product,\n unitAmount: p.unit_amount ?? null,\n currency: p.currency,\n interval: p.recurring?.interval ?? null,\n intervalCount: p.recurring?.interval_count ?? null,\n active: p.active,\n created: p.created,\n },\n updated_at: p.created * 1000,\n });\n }\n return;\n case 'subscriptions':\n for (const s of items as StripeSubscription[]) {\n await storage.entity({\n type: 'stripe_subscription',\n id: s.id,\n attributes: {\n customerId: s.customer,\n status: s.status,\n planId: s.items.data[0]?.price.id ?? null,\n currentPeriodStart: s.current_period_start,\n currentPeriodEnd: s.current_period_end,\n cancelAtPeriodEnd: s.cancel_at_period_end,\n canceledAt: s.canceled_at ?? null,\n trialEnd: s.trial_end ?? null,\n mrrAmount: computeMrrAmountCents(s),\n currency: s.currency,\n created: s.created,\n },\n updated_at: s.current_period_end * 1000,\n });\n }\n return;\n case 'invoices':\n for (const inv of items as StripeInvoice[]) {\n await storage.entity({\n type: 'stripe_invoice',\n id: inv.id,\n attributes: {\n customerId: inv.customer ?? null,\n subscriptionId: inv.subscription ?? null,\n status: inv.status ?? null,\n amountDue: inv.amount_due,\n amountPaid: inv.amount_paid,\n currency: inv.currency,\n created: inv.created,\n dueDate: inv.due_date ?? null,\n hostedInvoiceUrl: inv.hosted_invoice_url ?? null,\n },\n updated_at: inv.created * 1000,\n });\n }\n return;\n case 'charges':\n for (const c of items as StripeCharge[]) {\n await storage.event({\n name: 'stripe_charge',\n start_ts: c.created * 1000,\n end_ts: null,\n attributes: {\n id: c.id,\n customerId: c.customer ?? null,\n amount: c.amount,\n currency: c.currency,\n status: c.status,\n failureCode: c.failure_code ?? null,\n paymentIntentId: c.payment_intent ?? null,\n },\n });\n }\n return;\n case 'payment_intents':\n for (const pi of items as StripePaymentIntent[]) {\n await storage.event({\n name: 'stripe_payment_intent',\n start_ts: pi.created * 1000,\n end_ts: null,\n attributes: {\n id: pi.id,\n customerId: pi.customer ?? null,\n amount: pi.amount,\n currency: pi.currency,\n status: pi.status,\n },\n });\n }\n return;\n case 'disputes':\n for (const d of items as StripeDispute[]) {\n await storage.event({\n name: 'stripe_dispute',\n start_ts: d.created * 1000,\n end_ts: null,\n attributes: {\n id: d.id,\n chargeId: d.charge,\n amount: d.amount,\n currency: d.currency,\n reason: d.reason,\n status: d.status,\n },\n });\n }\n return;\n case 'refunds':\n for (const r of items as StripeRefund[]) {\n await storage.event({\n name: 'stripe_refund',\n start_ts: r.created * 1000,\n end_ts: null,\n attributes: {\n id: r.id,\n chargeId: r.charge ?? null,\n amount: r.amount,\n currency: r.currency,\n reason: r.reason ?? null,\n status: r.status ?? null,\n },\n });\n }\n return;\n }\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const cursor = isStripeSyncCursor(options.cursor)\n ? options.cursor\n : undefined;\n const isFull = options.mode === 'full';\n\n const enabled = this.settings.resources;\n const phases =\n enabled && enabled.length > 0\n ? PHASE_ORDER.filter((p) => enabled.includes(p))\n : PHASE_ORDER;\n\n return paginateChunked<StripePhase, string>({\n phases,\n cursor,\n signal,\n fetchPage: async (phase, page, sig) => {\n const url = this.buildPhaseUrl(phase, page, options);\n const res = await this.fetch<StripeListResponse<{ id: string }>>(\n url,\n phase,\n sig,\n );\n const { data, has_more } = res.body;\n const next = has_more && data.length > 0 ? data.at(-1)!.id : null;\n return { items: data, next };\n },\n writeBatch: async (phase, items, page) => {\n if (isFull && page === null) {\n await this.clearScopeOnFirstPage(storage, phase);\n }\n await this.writePhase(storage, phase, items);\n },\n });\n }\n}\n","import { StripeConnector } from './stripe';\n\nexport { configFields, StripeConnector, computeMrrAmountCents } from './stripe';\nexport type { StripeSettings } from './stripe';\nexport default StripeConnector;\n"],"mappings":";AACA;AAAA,EACE;AAAA,EAOA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAEX,IAAM,eAAe;AAAA,EAC1B,EAAE,OAAO;AAAA,IACP,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK;AAAA,MAC7C,OAAO;AAAA,MACP,aACE;AAAA,MACF,aAAa;AAAA,MACb,QAAQ;AAAA,IACV,CAAC;AAAA,IAC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EAAE;AAAA,cACV,UAAU,EAAE;AAAA,cACZ,QAAQ,EAAE,UAAU;AAAA,cACpB,QAAQ,EAAE,UAAU;AAAA,YACtB;AAAA,UACF,CAAC;AAAA,QACH;AACA;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,MAAM,KACJ,SACA,SACA,QACqB;AACrB,UAAM,SAAS,mBAAmB,QAAQ,MAAM,IAC5C,QAAQ,SACR;AACJ,UAAM,SAAS,QAAQ,SAAS;AAEhC,UAAM,UAAU,KAAK,SAAS;AAC9B,UAAM,SACJ,WAAW,QAAQ,SAAS,IACxB,YAAY,OAAO,CAAC,MAAM,QAAQ,SAAS,CAAC,CAAC,IAC7C;AAEN,WAAO,gBAAqC;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW,OAAO,OAAO,MAAM,QAAQ;AACrC,cAAM,MAAM,KAAK,cAAc,OAAO,MAAM,OAAO;AACnD,cAAM,MAAM,MAAM,KAAK;AAAA,UACrB;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA,cAAM,EAAE,MAAM,SAAS,IAAI,IAAI;AAC/B,cAAM,OAAO,YAAY,KAAK,SAAS,IAAI,KAAK,GAAG,EAAE,EAAG,KAAK;AAC7D,eAAO,EAAE,OAAO,MAAM,KAAK;AAAA,MAC7B;AAAA,MACA,YAAY,OAAO,OAAO,OAAO,SAAS;AACxC,YAAI,UAAU,SAAS,MAAM;AAC3B,gBAAM,KAAK,sBAAsB,SAAS,KAAK;AAAA,QACjD;AACA,cAAM,KAAK,WAAW,SAAS,OAAO,KAAK;AAAA,MAC7C;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACtlBA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../connector-shared/src/errors.ts","../../../connector-shared/src/retry.ts","../../../connector-shared/src/version.ts","../../../connector-shared/src/request.ts","../../../connector-shared/src/rate-limit.ts","../../../connector-shared/src/sanitize.ts","../../../connector-shared/src/epoch.ts","../../../connector-shared/src/pagination.ts","../../../connector-shared/src/logger.ts","../src/stripe.ts","../src/index.ts"],"sourcesContent":["import type { HttpResponse } from './types';\n\nexport type HttpErrorKind =\n | 'transient'\n | 'rate_limit'\n | 'auth'\n | 'upstream_bug'\n | 'client_bug';\n\nexport abstract class HttpClientError extends Error {\n abstract readonly kind: HttpErrorKind;\n readonly response?: HttpResponse;\n\n constructor(message: string, response?: HttpResponse) {\n super(message);\n this.name = new.target.name;\n this.response = response;\n }\n}\n\nexport class TransientError extends HttpClientError {\n readonly kind = 'transient' as const;\n}\n\nexport class RateLimitError extends HttpClientError {\n readonly kind = 'rate_limit' as const;\n readonly retryAfter?: Date;\n\n constructor(message: string, response?: HttpResponse, retryAfter?: Date) {\n super(message, response);\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AuthError extends HttpClientError {\n readonly kind = 'auth' as const;\n}\n\nexport class UpstreamBugError extends HttpClientError {\n readonly kind = 'upstream_bug' as const;\n}\n\nexport class ClientBugError extends HttpClientError {\n readonly kind = 'client_bug' as const;\n}\n\nexport function classifyStatus(status: number): HttpErrorKind {\n if (status === 429) {\n return 'rate_limit';\n }\n if (status === 401 || status === 403) {\n return 'auth';\n }\n if (status === 408) {\n return 'transient';\n }\n if (status >= 500) {\n return 'upstream_bug';\n }\n if (status >= 400) {\n return 'client_bug';\n }\n return 'client_bug';\n}\n\nexport function errorForStatus(\n message: string,\n response: HttpResponse,\n retryAfter?: Date,\n): HttpClientError {\n const kind = classifyStatus(response.status);\n switch (kind) {\n case 'rate_limit':\n return new RateLimitError(message, response, retryAfter);\n case 'auth':\n return new AuthError(message, response);\n case 'transient':\n return new TransientError(message, response);\n case 'upstream_bug':\n return new UpstreamBugError(message, response);\n case 'client_bug':\n return new ClientBugError(message, response);\n }\n}\n","import { HttpClientError, RateLimitError, TransientError } from './errors';\n\nexport interface RetryPolicy {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n retryOn?: (status: number | null, err?: Error) => boolean;\n}\n\nexport const defaultRetryOn = (status: number | null, err?: Error): boolean => {\n if (err instanceof RateLimitError) {\n return true;\n }\n if (err instanceof TransientError) {\n return true;\n }\n if (status === null) {\n return err instanceof Error && !(err instanceof HttpClientError);\n }\n if (status === 408 || status === 429) {\n return true;\n }\n if (status >= 500) {\n return true;\n }\n return false;\n};\n\nexport function backoffDelayMs(\n attempt: number,\n policy: Required<Pick<RetryPolicy, 'initialDelayMs' | 'maxDelayMs'>>,\n): number {\n const base = policy.initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, policy.maxDelayMs);\n}\n\nexport function parseRetryAfter(\n headerValue: string | null,\n now: Date = new Date(),\n): Date | undefined {\n if (!headerValue) {\n return undefined;\n }\n const trimmed = headerValue.trim();\n if (/^\\d+$/.test(trimmed)) {\n return new Date(now.getTime() + Number(trimmed) * 1000);\n }\n const parsed = Date.parse(trimmed);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n return new Date(parsed);\n}\n\nexport function sleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (signal?.aborted) {\n return Promise.reject(signal.reason ?? new Error('Aborted'));\n }\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal!.reason ?? new Error('Aborted'));\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export const HTTP_CLIENT_VERSION = '0.0.0';\n\nexport const DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n\nexport function connectorUserAgent(connectorId: string): string {\n return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n}\n","import {\n AuthError,\n ClientBugError,\n HttpClientError,\n RateLimitError,\n TransientError,\n UpstreamBugError,\n errorForStatus,\n} from './errors';\nimport { defaultRetryOn, parseRetryAfter, sleep } from './retry';\nimport type { FetchLike, HttpMethod, HttpRequest, HttpResponse } from './types';\nimport { DEFAULT_USER_AGENT } from './version';\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst DEFAULT_MAX_ATTEMPTS = 3;\nconst DEFAULT_INITIAL_DELAY_MS = 1000;\nconst DEFAULT_MAX_DELAY_MS = 60_000;\nconst OBSERVER_TIMEOUT_MS = 250;\n\nexport interface RequestObservation {\n url: string;\n method: HttpMethod;\n status: number;\n resource: string;\n requestId: string;\n body: unknown;\n}\n\nexport type RequestObserver = (\n event: RequestObservation,\n) => void | Promise<void>;\n\nexport interface RequestOptions {\n fetch?: FetchLike;\n observer?: RequestObserver;\n resource: string;\n requestId?: string;\n}\n\nasync function notifyObserver(\n observer: RequestObserver,\n event: RequestObservation,\n): Promise<void> {\n let result: void | Promise<void>;\n try {\n result = observer(event);\n } catch (err) {\n console.warn('[connector-shared] request observer threw:', err);\n return;\n }\n if (!(result instanceof Promise)) {\n return;\n }\n const guarded = result.catch((err) => {\n console.warn('[connector-shared] request observer rejected:', err);\n });\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<void>((resolve) => {\n timer = setTimeout(resolve, OBSERVER_TIMEOUT_MS);\n });\n try {\n await Promise.race([guarded, timeout]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n\nfunction newRequestId(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction mergeHeaders(\n defaults: Record<string, string>,\n overrides: Record<string, string> | undefined,\n): Record<string, string> {\n const merged: Record<string, string> = {};\n for (const [k, v] of Object.entries(defaults)) {\n merged[k.toLowerCase()] = v;\n }\n if (overrides) {\n for (const [k, v] of Object.entries(overrides)) {\n merged[k.toLowerCase()] = v;\n }\n }\n return merged;\n}\n\nfunction linkTimeoutSignal(\n parent: AbortSignal | undefined,\n timeoutMs: number,\n): { signal: AbortSignal; cancel: () => void } {\n const controller = new AbortController();\n const onParentAbort = () => {\n controller.abort(parent?.reason);\n };\n if (parent) {\n if (parent.aborted) {\n controller.abort(parent.reason);\n } else {\n parent.addEventListener('abort', onParentAbort, { once: true });\n }\n }\n const timer = setTimeout(() => {\n controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n return {\n signal: controller.signal,\n cancel: () => {\n clearTimeout(timer);\n if (parent) {\n parent.removeEventListener('abort', onParentAbort);\n }\n },\n };\n}\n\nasync function readBody(res: Response, parseJson: boolean): Promise<unknown> {\n if (res.status === 204 || res.status === 205) {\n return null;\n }\n const contentType = res.headers.get('content-type') ?? '';\n if (parseJson && contentType.includes('application/json')) {\n const text = await res.text();\n if (text.length === 0) {\n return null;\n }\n return JSON.parse(text);\n }\n return res.text();\n}\n\nexport async function request<T = unknown>(\n req: HttpRequest,\n options: RequestOptions,\n): Promise<HttpResponse<T>> {\n const fetchImpl: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);\n const retry = req.retry ?? {};\n const maxAttempts = retry.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;\n const initialDelayMs = retry.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;\n const maxDelayMs = retry.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;\n const retryOn = retry.retryOn ?? defaultRetryOn;\n const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const parseJson = req.parseJson ?? true;\n\n const headers = mergeHeaders(\n {\n 'User-Agent': DEFAULT_USER_AGENT,\n Accept: 'application/json',\n },\n req.headers,\n );\n\n let lastErr: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n req.signal?.throwIfAborted();\n\n const { signal, cancel } = linkTimeoutSignal(req.signal, timeoutMs);\n let res: Response;\n try {\n res = await fetchImpl(req.url, {\n method: req.method ?? 'GET',\n headers,\n body: req.body as RequestInit['body'],\n signal,\n });\n } catch (err) {\n cancel();\n if (req.signal?.aborted) {\n throw req.signal.reason ?? err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n lastErr = error;\n if (attempt < maxAttempts - 1 && retryOn(null, error)) {\n const delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n await sleep(delay, req.signal);\n continue;\n }\n throw new TransientError(error.message);\n }\n cancel();\n\n const body = await readBody(res, parseJson);\n const httpResponse: HttpResponse<T> = {\n status: res.status,\n headers: res.headers,\n body: body as T,\n };\n if (req.rateLimit) {\n const state = req.rateLimit.parse(res.headers);\n if (state) {\n httpResponse.rateLimitState = state;\n }\n }\n\n if (options.observer) {\n await notifyObserver(options.observer, {\n url: req.url,\n method: req.method ?? 'GET',\n status: res.status,\n resource: options.resource,\n requestId: options.requestId ?? newRequestId(),\n body,\n });\n }\n\n if (res.ok) {\n return httpResponse;\n }\n\n const retryAfter = parseRetryAfter(res.headers.get('retry-after'));\n const message = `HTTP ${res.status} ${res.statusText} for ${req.method ?? 'GET'} ${req.url}`;\n const err = errorForStatus(message, httpResponse, retryAfter);\n\n if (\n attempt < maxAttempts - 1 &&\n retryOn(res.status, err) &&\n !(err instanceof AuthError) &&\n !(err instanceof ClientBugError)\n ) {\n lastErr = err;\n let delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n if (err instanceof RateLimitError && retryAfter) {\n const wait = retryAfter.getTime() - Date.now();\n if (wait > 0) {\n delay = Math.min(wait, maxDelayMs);\n }\n }\n await sleep(delay, req.signal);\n continue;\n }\n\n throw err;\n }\n\n throw lastErr ?? new UpstreamBugError('Exhausted retry attempts');\n}\n\nfunction computeDelay(\n attempt: number,\n initialDelayMs: number,\n maxDelayMs: number,\n): number {\n const base = initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, maxDelayMs);\n}\n\nexport { HttpClientError };\n","export interface RateLimitState {\n remaining: number;\n resetAt: Date;\n}\n\nexport interface RateLimitPolicy {\n parse(headers: Headers): RateLimitState | null;\n}\n\nexport interface StandardRateLimitPolicyConfig {\n remainingHeader: string;\n resetHeader: string;\n resetUnit: 's' | 'ms';\n resetFallbackMs?: number;\n}\n\nexport function standardRateLimitPolicy(\n config: StandardRateLimitPolicyConfig,\n): RateLimitPolicy {\n const { remainingHeader, resetHeader, resetUnit, resetFallbackMs } = config;\n const multiplier = resetUnit === 's' ? 1000 : 1;\n return {\n parse(h) {\n const remainingRaw = h.get(remainingHeader);\n if (remainingRaw === null || remainingRaw.trim() === '') {\n return null;\n }\n const remaining = Number(remainingRaw);\n if (!Number.isFinite(remaining)) {\n return null;\n }\n const resetRaw = h.get(resetHeader);\n if (resetRaw === null) {\n if (resetFallbackMs === undefined) {\n return null;\n }\n return {\n remaining,\n resetAt: new Date(Date.now() + resetFallbackMs),\n };\n }\n if (resetRaw.trim() === '') {\n return null;\n }\n const reset = Number(resetRaw);\n if (!Number.isFinite(reset) || reset < 0) {\n return null;\n }\n const resetMs = reset * multiplier;\n if (!Number.isFinite(resetMs)) {\n return null;\n }\n return { remaining, resetAt: new Date(resetMs) };\n },\n };\n}\n","export interface SanitizeAllowedUrlOptions {\n url: string | null;\n host: string;\n pathname: string;\n protocol?: 'https:' | 'http:';\n}\n\nexport function sanitizeAllowedUrl(\n options: SanitizeAllowedUrlOptions,\n): string | null {\n const { url, host, pathname, protocol = 'https:' } = options;\n if (url === null) {\n return null;\n }\n try {\n const u = new URL(url);\n if (u.protocol !== protocol || u.host !== host || u.pathname !== pathname) {\n return null;\n }\n return u.toString();\n } catch {\n return null;\n }\n}\n","export type EpochUnit = 'ms' | 's' | 'iso';\n\nexport function parseEpoch(\n value: number | string | null | undefined,\n unit: EpochUnit,\n): number | null {\n if (value === null || value === undefined) {\n return null;\n }\n if (unit === 'iso') {\n if (typeof value !== 'string') {\n return null;\n }\n const ms = new Date(value).getTime();\n return Number.isFinite(ms) ? ms : null;\n }\n if (typeof value === 'string' && value.trim() === '') {\n return null;\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n)) {\n return null;\n }\n const result = unit === 's' ? n * 1000 : n;\n return Number.isFinite(result) ? result : null;\n}\n","import { request } from './request';\nimport type { HttpRequest } from './types';\n\nexport function parseLinkHeader(header: string | null): Record<string, string> {\n if (!header) {\n return {};\n }\n const result: Record<string, string> = {};\n for (const part of header.split(',')) {\n const match = part.match(/<([^>]+)>\\s*;\\s*rel=\"([^\"]+)\"/);\n if (match) {\n result[match[2]!] = match[1]!;\n }\n }\n return result;\n}\n\nexport async function* paginateLink<T>(\n initial: HttpRequest,\n parse: (body: unknown) => T[],\n options: { resource: string },\n): AsyncIterable<T> {\n let next: string | null = initial.url;\n while (next) {\n const res: Awaited<ReturnType<typeof request>> = await request(\n {\n ...initial,\n url: next,\n },\n { resource: options.resource },\n );\n for (const item of parse(res.body)) {\n yield item;\n }\n const links = parseLinkHeader(res.headers.get('link'));\n next = links['next'] ?? null;\n }\n}\n\nexport async function* paginateCursor<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; nextCursor: string | null },\n buildNext: (req: HttpRequest, cursor: string) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let req: HttpRequest = initial;\n while (true) {\n const res = await request(req, { resource: options.resource });\n const { items, nextCursor } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!nextCursor) {\n return;\n }\n req = buildNext(req, nextCursor);\n }\n}\n\nexport async function* paginatePage<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; hasMore: boolean },\n buildPage: (req: HttpRequest, page: number) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let page = 1;\n while (true) {\n const req = page === 1 ? initial : buildPage(initial, page);\n const res = await request(req, { resource: options.resource });\n const { items, hasMore } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!hasMore || items.length === 0) {\n return;\n }\n page++;\n }\n}\n","export type LogFields = Record<string, unknown>;\n\nexport interface ConnectorLogger {\n info(event: string, fields?: LogFields): void;\n warn(event: string, fields?: LogFields): void;\n}\n\nexport interface ConnectorLoggerOptions {\n scope: string;\n}\n\nconst MAX_VALUE_LEN = 120;\n\nfunction truncate(s: string, max = MAX_VALUE_LEN): string {\n if (s.length <= max) {\n return s;\n }\n return `${s.slice(0, max - 1)}…`;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return '';\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'string') {\n const t = truncate(value);\n if (/[\\s\"=]/.test(t)) {\n return JSON.stringify(t);\n }\n return t;\n }\n if (typeof value === 'bigint') {\n return value.toString();\n }\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n json = undefined;\n }\n return truncate(json ?? String(value));\n}\n\nexport function formatLogFields(fields?: LogFields): string {\n if (!fields) {\n return '';\n }\n const parts: string[] = [];\n for (const [k, v] of Object.entries(fields)) {\n if (v === undefined) {\n continue;\n }\n parts.push(`${k}=${formatValue(v)}`);\n }\n return parts.length > 0 ? ` ${parts.join(' ')}` : '';\n}\n\nexport function formatLogLine(\n scope: string,\n event: string,\n fields?: LogFields,\n): string {\n return `[${scope}] ${event}${formatLogFields(fields)}`;\n}\n\nexport function createDefaultConnectorLogger(\n opts: ConnectorLoggerOptions,\n): ConnectorLogger {\n return {\n info(event, fields) {\n console.info(formatLogLine(opts.scope, event, fields));\n },\n warn(event, fields) {\n console.warn(formatLogLine(opts.scope, event, fields));\n },\n };\n}\n\nconst NOOP_LOGGER: ConnectorLogger = {\n info() {},\n warn() {},\n};\n\nexport function noopConnectorLogger(): ConnectorLogger {\n return NOOP_LOGGER;\n}\n","import {\n type HttpResponse,\n connectorUserAgent,\n} from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ConnectorContext,\n type ConnectorDoc,\n type CredentialsSchema,\n type StorageHandle,\n type SyncOptions,\n type SyncResult,\n defineConfigFields,\n defineConnectorDoc,\n defineResources,\n makeChunkedCursorGuard,\n paginateChunked,\n schemasFromResources,\n selectActivePhases,\n} from '@rawdash/core';\nimport { z } from 'zod';\n\nexport const configFields = defineConfigFields(\n z.object({\n apiKey: z.object({ $secret: z.string() }).meta({\n label: 'API Key',\n description:\n 'Stripe Restricted API key with read-only access. Create one at Dashboard → Developers → API keys.',\n placeholder: 'rk_live_...',\n secret: true,\n }),\n accountId: z.string().optional().meta({\n label: 'Account ID (optional)',\n description:\n 'Stripe Connect account ID. Only needed if you are a platform accessing a connected account.',\n placeholder: 'acct_...',\n }),\n resources: z\n .array(\n z.enum([\n 'customers',\n 'products',\n 'prices',\n 'subscriptions',\n 'invoices',\n 'charges',\n 'payment_intents',\n 'disputes',\n 'refunds',\n ]),\n )\n .nonempty()\n .optional()\n .meta({\n label: 'Resources',\n description:\n 'Which Stripe resources to sync. Omit to sync all resources. The API key only needs Read scope for the resources listed here.',\n }),\n }),\n);\n\nexport const doc: ConnectorDoc = defineConnectorDoc({\n displayName: 'Stripe',\n category: 'finance',\n brandColor: '#635BFF',\n tagline:\n 'Sync customers, products, prices, subscriptions, and invoices alongside charge, payment, dispute, and refund events from your Stripe account.',\n vendor: {\n name: 'Stripe',\n apiDocs: 'https://stripe.com/docs/api',\n website: 'https://stripe.com',\n },\n auth: {\n summary:\n 'Authenticates with a Stripe restricted API key that has read-only access to the resources you want to sync.',\n setup: [\n 'Open the Stripe Dashboard → Developers → API keys.',\n 'Create a restricted key with Read access for the resources you plan to sync (customers, products, prices, subscriptions, invoices, charges, payment intents, disputes, refunds).',\n 'Store the key as a secret and reference it from the connector config as `apiKey: secret(\"STRIPE_API_KEY\")`.',\n ],\n },\n rateLimit:\n 'Stripe 429 responses carry a Retry-After header; requests are retried with exponential backoff. List pagination uses the starting_after cursor (limit 100).',\n limitations: [\n 'Monetary amounts are stored in the smallest currency unit (e.g. cents), matching the Stripe API.',\n 'The set of synced resources is controlled by the `resources` config field; omit it to sync all of them.',\n 'Incremental syncs use a 7-day lookback for entities and created[gt] for events.',\n ],\n});\n\nexport interface StripeSettings {\n accountId?: string;\n resources?: readonly StripeResource[];\n}\n\n// ---------------------------------------------------------------------------\n// Stripe API types\n// ---------------------------------------------------------------------------\n\ninterface StripeListResponse<T> {\n object: 'list';\n data: T[];\n has_more: boolean;\n url: string;\n}\n\ninterface StripeCustomer {\n id: string;\n email: string | null;\n name: string | null;\n created: number;\n currency: string | null;\n delinquent: boolean | null;\n livemode: boolean;\n}\n\ninterface StripePriceRecurring {\n interval: 'day' | 'week' | 'month' | 'year';\n interval_count: number;\n}\n\ninterface StripePrice {\n id: string;\n product: string;\n unit_amount: number | null;\n currency: string;\n recurring: StripePriceRecurring | null;\n active: boolean;\n created: number;\n}\n\ninterface StripeSubscriptionItem {\n price: StripePrice;\n quantity: number | null;\n}\n\ninterface StripeSubscription {\n id: string;\n customer: string;\n status: string;\n items: { data: StripeSubscriptionItem[] };\n current_period_start: number;\n current_period_end: number;\n cancel_at_period_end: boolean;\n canceled_at: number | null;\n trial_end: number | null;\n currency: string;\n created: number;\n}\n\ninterface StripeInvoice {\n id: string;\n customer: string | null;\n subscription: string | null;\n status: string | null;\n amount_due: number;\n amount_paid: number;\n currency: string;\n created: number;\n due_date: number | null;\n hosted_invoice_url: string | null;\n}\n\ninterface StripeCharge {\n id: string;\n customer: string | null;\n amount: number;\n currency: string;\n status: string;\n failure_code: string | null;\n created: number;\n payment_intent: string | null;\n}\n\ninterface StripePaymentIntent {\n id: string;\n customer: string | null;\n amount: number;\n currency: string;\n status: string;\n created: number;\n}\n\ninterface StripeProduct {\n id: string;\n name: string;\n active: boolean;\n created: number;\n}\n\ninterface StripeDispute {\n id: string;\n charge: string;\n amount: number;\n currency: string;\n reason: string;\n status: string;\n created: number;\n}\n\ninterface StripeRefund {\n id: string;\n charge: string | null;\n amount: number;\n currency: string;\n reason: string | null;\n status: string | null;\n created: number;\n}\n\n// ---------------------------------------------------------------------------\n// Credentials\n// ---------------------------------------------------------------------------\n\nconst stripeCredentials = {\n apiKey: {\n description: 'Stripe API key',\n auth: 'required' as const,\n },\n} satisfies CredentialsSchema;\n\ntype StripeCredentials = typeof stripeCredentials;\n\n// ---------------------------------------------------------------------------\n// Sync phases + cursor\n// ---------------------------------------------------------------------------\n\nconst PHASE_ORDER = [\n 'customers',\n 'products',\n 'prices',\n 'subscriptions',\n 'invoices',\n 'charges',\n 'payment_intents',\n 'disputes',\n 'refunds',\n] as const;\n\ntype StripePhase = (typeof PHASE_ORDER)[number];\n\nexport type StripeResource = StripePhase;\n\nconst isStripeSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);\n\nconst ENTITY_TYPE_BY_PHASE: Partial<Record<StripePhase, string>> = {\n customers: 'stripe_customer',\n products: 'stripe_product',\n prices: 'stripe_price',\n subscriptions: 'stripe_subscription',\n invoices: 'stripe_invoice',\n};\n\nconst EVENT_NAME_BY_PHASE: Partial<Record<StripePhase, string>> = {\n charges: 'stripe_charge',\n payment_intents: 'stripe_payment_intent',\n disputes: 'stripe_dispute',\n refunds: 'stripe_refund',\n};\n\n// ---------------------------------------------------------------------------\n// MRR helper\n// ---------------------------------------------------------------------------\n\nexport function computeMrrAmountCents(\n subscription: StripeSubscription,\n): number | null {\n let sum = 0;\n let counted = 0;\n for (const item of subscription.items.data) {\n const { unit_amount, recurring } = item.price;\n if (unit_amount === null || unit_amount === undefined || !recurring) {\n continue;\n }\n const quantity = item.quantity ?? 1;\n const total = unit_amount * quantity;\n const intervalCount = recurring.interval_count || 1;\n let monthly: number | null;\n switch (recurring.interval) {\n case 'month':\n monthly = total / intervalCount;\n break;\n case 'year':\n monthly = total / (12 * intervalCount);\n break;\n case 'week':\n monthly = (total * 52) / (12 * intervalCount);\n break;\n case 'day':\n monthly = (total * 365) / (12 * intervalCount);\n break;\n default:\n monthly = null;\n }\n if (monthly === null) {\n continue;\n }\n sum += monthly;\n counted++;\n }\n if (counted === 0) {\n return null;\n }\n return Math.round(sum);\n}\n\n// ---------------------------------------------------------------------------\n// Schemas — describe the per-resource API response shape consumed by request()\n// ---------------------------------------------------------------------------\n\nconst idString = z.string().min(1);\n\nconst customerSchema = z.object({\n id: idString,\n email: z.string().nullable(),\n name: z.string().nullable(),\n created: z.number().int().nonnegative(),\n currency: z.string().nullable(),\n delinquent: z.boolean().nullable(),\n livemode: z.boolean(),\n});\n\nconst productSchema = z.object({\n id: idString,\n name: z.string(),\n active: z.boolean(),\n created: z.number().int().nonnegative(),\n});\n\nconst priceSchema = z.object({\n id: idString,\n product: idString,\n unit_amount: z.number().int().nullable(),\n currency: z.string(),\n recurring: z\n .object({\n interval: z.enum(['day', 'week', 'month', 'year']),\n interval_count: z.number().int().positive(),\n })\n .nullable(),\n active: z.boolean(),\n created: z.number().int().nonnegative(),\n});\n\nconst subscriptionSchema = z.object({\n id: idString,\n customer: idString,\n status: z.string(),\n items: z.object({\n data: z.array(\n z.object({\n price: priceSchema,\n quantity: z.number().int().nullable(),\n }),\n ),\n }),\n current_period_start: z.number().int().nonnegative(),\n current_period_end: z.number().int().nonnegative(),\n cancel_at_period_end: z.boolean(),\n canceled_at: z.number().int().nullable(),\n trial_end: z.number().int().nullable(),\n currency: z.string(),\n created: z.number().int().nonnegative(),\n});\n\nconst invoiceSchema = z.object({\n id: idString,\n customer: idString.nullable(),\n subscription: idString.nullable(),\n status: z.string().nullable(),\n amount_due: z.number().int(),\n amount_paid: z.number().int(),\n currency: z.string(),\n created: z.number().int().nonnegative(),\n due_date: z.number().int().nullable(),\n hosted_invoice_url: z.string().nullable(),\n});\n\nconst chargeSchema = z.object({\n id: idString,\n customer: idString.nullable(),\n amount: z.number().int(),\n currency: z.string(),\n status: z.string(),\n failure_code: z.string().nullable(),\n created: z.number().int().nonnegative(),\n payment_intent: idString.nullable(),\n});\n\nconst paymentIntentSchema = z.object({\n id: idString,\n customer: idString.nullable(),\n amount: z.number().int(),\n currency: z.string(),\n status: z.string(),\n created: z.number().int().nonnegative(),\n});\n\nconst disputeSchema = z.object({\n id: idString,\n charge: idString,\n amount: z.number().int(),\n currency: z.string(),\n reason: z.string(),\n status: z.string(),\n created: z.number().int().nonnegative(),\n});\n\nconst refundSchema = z.object({\n id: idString,\n charge: idString.nullable(),\n amount: z.number().int(),\n currency: z.string(),\n reason: z.string().nullable(),\n status: z.string().nullable(),\n created: z.number().int().nonnegative(),\n});\n\nconst stripeResources = defineResources({\n stripe_customer: {\n shape: 'entity',\n description:\n 'Customers with email, name, default currency, and delinquency state.',\n endpoint: 'GET /v1/customers',\n responses: { customers: z.array(customerSchema) },\n },\n stripe_product: {\n shape: 'entity',\n description: 'Products in your catalog, including active state.',\n endpoint: 'GET /v1/products',\n responses: { products: z.array(productSchema) },\n },\n stripe_price: {\n shape: 'entity',\n description:\n 'Prices with unit amount, currency, and recurring interval, linked to their product.',\n endpoint: 'GET /v1/prices',\n responses: { prices: z.array(priceSchema) },\n },\n stripe_subscription: {\n shape: 'entity',\n description:\n 'Subscriptions with status, current period, cancellation state, and computed monthly recurring revenue (mrrAmount, in the smallest currency unit).',\n endpoint: 'GET /v1/subscriptions',\n notes:\n 'mrrAmount is computed as unit_amount x quantity, normalized to a monthly cadence (yearly / 12, weekly x 52 / 12, etc.).',\n responses: { subscriptions: z.array(subscriptionSchema) },\n },\n stripe_invoice: {\n shape: 'entity',\n description:\n 'Invoices with amount due, amount paid, status, and due date, linked to their customer and subscription.',\n endpoint: 'GET /v1/invoices',\n responses: { invoices: z.array(invoiceSchema) },\n },\n stripe_charge: {\n shape: 'event',\n description:\n 'Charge attempts with amount, currency, status, and failure code, timestamped at creation.',\n endpoint: 'GET /v1/charges',\n responses: { charges: z.array(chargeSchema) },\n },\n stripe_payment_intent: {\n shape: 'event',\n description:\n 'Payment intents with amount, currency, and status, timestamped at creation.',\n endpoint: 'GET /v1/payment_intents',\n responses: { payment_intents: z.array(paymentIntentSchema) },\n },\n stripe_dispute: {\n shape: 'event',\n description:\n 'Disputes with amount, currency, reason, and status, linked to the disputed charge.',\n endpoint: 'GET /v1/disputes',\n responses: { disputes: z.array(disputeSchema) },\n },\n stripe_refund: {\n shape: 'event',\n description:\n 'Refunds with amount, currency, reason, and status, linked to the refunded charge.',\n endpoint: 'GET /v1/refunds',\n responses: { refunds: z.array(refundSchema) },\n },\n});\n\n// ---------------------------------------------------------------------------\n// StripeConnector\n// ---------------------------------------------------------------------------\n\nexport class StripeConnector extends BaseConnector<\n StripeSettings,\n StripeCredentials\n> {\n static readonly id = 'stripe';\n\n static readonly resources = stripeResources;\n\n static readonly schemas = schemasFromResources(stripeResources);\n\n static create(input: unknown, ctx?: ConnectorContext): StripeConnector {\n const parsed = configFields.parse(input);\n return new StripeConnector(\n { accountId: parsed.accountId, resources: parsed.resources },\n { apiKey: parsed.apiKey },\n ctx,\n );\n }\n\n readonly id = 'stripe';\n override readonly credentials = stripeCredentials;\n\n private buildHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.creds.apiKey}`,\n 'Stripe-Version': '2024-06-20',\n 'User-Agent': connectorUserAgent('stripe'),\n };\n if (this.settings.accountId) {\n headers['Stripe-Account'] = this.settings.accountId;\n }\n return headers;\n }\n\n private fetch<T>(\n url: string,\n resource: string,\n signal?: AbortSignal,\n ): Promise<HttpResponse<T>> {\n return this.get<T>(url, {\n resource,\n headers: this.buildHeaders(),\n signal,\n });\n }\n\n private buildListUrl(\n path: string,\n params: Record<string, string | undefined>,\n ): string {\n const url = new URL(`https://api.stripe.com/v1/${path}`);\n url.searchParams.set('limit', '100');\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, value);\n }\n }\n return url.toString();\n }\n\n // created[gte] cutoff for entity phases — in incremental (latest) mode adds\n // a 7-day grace so recent edits to slightly older entities still surface.\n // Subscriptions are intentionally exempt in full mode: a subscription's\n // updated_at is derived from current_period_end, so a still-active sub\n // created well before the cutoff would otherwise be dropped on backfill.\n private entityCreatedGte(\n phase: StripePhase,\n options: SyncOptions,\n ): string | undefined {\n if (!options.since) {\n return undefined;\n }\n const sinceMs = new Date(options.since).getTime();\n if (options.mode === 'latest') {\n return String(Math.floor((sinceMs - 7 * 24 * 60 * 60 * 1000) / 1000));\n }\n if (phase === 'subscriptions') {\n return undefined;\n }\n return String(Math.floor(sinceMs / 1000));\n }\n\n // created[gt] cutoff for event phases — applied in both full and incremental\n // modes so backfill respects the widget-driven window.\n private eventCreatedGt(options: SyncOptions): string | undefined {\n if (!options.since) {\n return undefined;\n }\n return String(Math.floor(new Date(options.since).getTime() / 1000));\n }\n\n private buildPhaseUrl(\n phase: StripePhase,\n page: string | null,\n options: SyncOptions,\n ): string {\n const startingAfter = page ?? undefined;\n if (phase in ENTITY_TYPE_BY_PHASE) {\n const extra: Record<string, string | undefined> =\n phase === 'subscriptions' ? { status: 'all' } : {};\n return this.buildListUrl(phase, {\n ...extra,\n starting_after: startingAfter,\n 'created[gte]': this.entityCreatedGte(phase, options),\n });\n }\n return this.buildListUrl(phase, {\n starting_after: startingAfter,\n 'created[gt]': this.eventCreatedGt(options),\n });\n }\n\n private async clearScopeOnFirstPage(\n storage: StorageHandle,\n phase: StripePhase,\n ): Promise<void> {\n const entityType = ENTITY_TYPE_BY_PHASE[phase];\n if (entityType) {\n await storage.entities([], { types: [entityType] });\n return;\n }\n const eventName = EVENT_NAME_BY_PHASE[phase];\n if (eventName) {\n await storage.events([], { names: [eventName] });\n }\n }\n\n private async writePhase(\n storage: StorageHandle,\n phase: StripePhase,\n items: unknown[],\n ): Promise<void> {\n switch (phase) {\n case 'customers':\n for (const c of items as StripeCustomer[]) {\n await storage.entity({\n type: 'stripe_customer',\n id: c.id,\n attributes: {\n email: c.email ?? null,\n name: c.name ?? null,\n created: c.created,\n currency: c.currency ?? null,\n delinquent: c.delinquent ?? false,\n livemode: c.livemode,\n },\n updated_at: c.created * 1000,\n });\n }\n return;\n case 'products':\n for (const p of items as StripeProduct[]) {\n await storage.entity({\n type: 'stripe_product',\n id: p.id,\n attributes: { name: p.name, active: p.active, created: p.created },\n updated_at: p.created * 1000,\n });\n }\n return;\n case 'prices':\n for (const p of items as StripePrice[]) {\n await storage.entity({\n type: 'stripe_price',\n id: p.id,\n attributes: {\n productId: p.product,\n unitAmount: p.unit_amount ?? null,\n currency: p.currency,\n interval: p.recurring?.interval ?? null,\n intervalCount: p.recurring?.interval_count ?? null,\n active: p.active,\n created: p.created,\n },\n updated_at: p.created * 1000,\n });\n }\n return;\n case 'subscriptions':\n for (const s of items as StripeSubscription[]) {\n await storage.entity({\n type: 'stripe_subscription',\n id: s.id,\n attributes: {\n customerId: s.customer,\n status: s.status,\n planId: s.items.data[0]?.price.id ?? null,\n currentPeriodStart: s.current_period_start,\n currentPeriodEnd: s.current_period_end,\n cancelAtPeriodEnd: s.cancel_at_period_end,\n canceledAt: s.canceled_at ?? null,\n trialEnd: s.trial_end ?? null,\n mrrAmount: computeMrrAmountCents(s),\n currency: s.currency,\n created: s.created,\n },\n updated_at: s.current_period_end * 1000,\n });\n }\n return;\n case 'invoices':\n for (const inv of items as StripeInvoice[]) {\n await storage.entity({\n type: 'stripe_invoice',\n id: inv.id,\n attributes: {\n customerId: inv.customer ?? null,\n subscriptionId: inv.subscription ?? null,\n status: inv.status ?? null,\n amountDue: inv.amount_due,\n amountPaid: inv.amount_paid,\n currency: inv.currency,\n created: inv.created,\n dueDate: inv.due_date ?? null,\n hostedInvoiceUrl: inv.hosted_invoice_url ?? null,\n },\n updated_at: inv.created * 1000,\n });\n }\n return;\n case 'charges':\n for (const c of items as StripeCharge[]) {\n await storage.event({\n name: 'stripe_charge',\n start_ts: c.created * 1000,\n end_ts: null,\n attributes: {\n id: c.id,\n customerId: c.customer ?? null,\n amount: c.amount,\n currency: c.currency,\n status: c.status,\n failureCode: c.failure_code ?? null,\n paymentIntentId: c.payment_intent ?? null,\n },\n });\n }\n return;\n case 'payment_intents':\n for (const pi of items as StripePaymentIntent[]) {\n await storage.event({\n name: 'stripe_payment_intent',\n start_ts: pi.created * 1000,\n end_ts: null,\n attributes: {\n id: pi.id,\n customerId: pi.customer ?? null,\n amount: pi.amount,\n currency: pi.currency,\n status: pi.status,\n },\n });\n }\n return;\n case 'disputes':\n for (const d of items as StripeDispute[]) {\n await storage.event({\n name: 'stripe_dispute',\n start_ts: d.created * 1000,\n end_ts: null,\n attributes: {\n id: d.id,\n chargeId: d.charge,\n amount: d.amount,\n currency: d.currency,\n reason: d.reason,\n status: d.status,\n },\n });\n }\n return;\n case 'refunds':\n for (const r of items as StripeRefund[]) {\n await storage.event({\n name: 'stripe_refund',\n start_ts: r.created * 1000,\n end_ts: null,\n attributes: {\n id: r.id,\n chargeId: r.charge ?? null,\n amount: r.amount,\n currency: r.currency,\n reason: r.reason ?? null,\n status: r.status ?? null,\n },\n });\n }\n return;\n }\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const cursor = isStripeSyncCursor(options.cursor)\n ? options.cursor\n : undefined;\n const isFull = options.mode === 'full';\n\n const phases = selectActivePhases<StripeResource, StripePhase>(\n (r) => r,\n PHASE_ORDER,\n this.settings.resources,\n );\n\n return paginateChunked<StripePhase, string>({\n phases,\n cursor,\n signal,\n logger: this.logger,\n fetchPage: async (phase, page, sig) => {\n const url = this.buildPhaseUrl(phase, page, options);\n const res = await this.fetch<StripeListResponse<{ id: string }>>(\n url,\n phase,\n sig,\n );\n const { data, has_more } = res.body;\n const next = has_more && data.length > 0 ? data.at(-1)!.id : null;\n return { items: data, next };\n },\n writeBatch: async (phase, items, page) => {\n if (isFull && page === null) {\n await this.clearScopeOnFirstPage(storage, phase);\n }\n await this.writePhase(storage, phase, items);\n },\n });\n }\n}\n","import { StripeConnector } from './stripe';\n\nexport {\n configFields,\n doc,\n StripeConnector,\n computeMrrAmountCents,\n} from './stripe';\nexport type { StripeSettings } from './stripe';\nexport default StripeConnector;\n"],"mappings":";AEAO,IAAM,sBAAsB;AAE5B,IAAM,qBAAqB,qBAAqB,mBAAmB;AAEnE,SAAS,mBAAmB,aAA6B;AAC9D,SAAO,qBAAqB,WAAW,IAAI,mBAAmB;AAChE;;;AOFA;AAAA,EACE;AAAA,EAOA;AAAA,EACA;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|
2
2
|
"name": "@rawdash/connector-stripe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Rawdash connector for Stripe — billing, subscriptions, and payments",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"zod": "^4.4.3",
|
|
26
|
-
"@rawdash/core": "0.
|
|
26
|
+
"@rawdash/core": "0.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"fast-check": "^4.8.0",
|
|
30
30
|
"tsup": "^8.0.0",
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
32
|
"vitest": "^4.1.4",
|
|
33
|
-
"@rawdash/connector-shared": "0.
|
|
34
|
-
"@rawdash/connector-test-utils": "0.0.
|
|
33
|
+
"@rawdash/connector-shared": "0.3.0",
|
|
34
|
+
"@rawdash/connector-test-utils": "0.0.3"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsup",
|