@rawdash/connector-stripe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +175 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +649 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @rawdash/connector-stripe
|
|
2
|
+
|
|
3
|
+
Rawdash connector for Stripe — syncs customers, subscriptions, invoices, charges, payment intents, products, prices, disputes, and refunds into the six-shape storage model.
|
|
4
|
+
|
|
5
|
+
## Auth setup
|
|
6
|
+
|
|
7
|
+
### Creating a Restricted API key
|
|
8
|
+
|
|
9
|
+
1. Log in to your Stripe Dashboard and navigate to **Developers → API keys**.
|
|
10
|
+
2. Click **+ Create restricted key**.
|
|
11
|
+
3. Give it a name (e.g. `rawdash-readonly`).
|
|
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).
|
|
23
|
+
|
|
24
|
+
> **Note:** Never use your full Secret key — a Restricted key with only the scopes above is safer and sufficient.
|
|
25
|
+
|
|
26
|
+
### Stripe Connect platforms
|
|
27
|
+
|
|
28
|
+
If you are a platform and want to sync data for a connected account, supply the `accountId` field (format: `acct_…`). The connector will send the `Stripe-Account` header on every request.
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { StripeConnector, configFields } from '@rawdash/connector-stripe';
|
|
34
|
+
import { secret } from '@rawdash/core';
|
|
35
|
+
|
|
36
|
+
const stripe = new StripeConnector(
|
|
37
|
+
{
|
|
38
|
+
// accountId: 'acct_…', // optional, Stripe Connect only
|
|
39
|
+
// resources: ['customers', 'subscriptions', 'invoices'], // optional, defaults to all
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
apiKey: secret('STRIPE_API_KEY'),
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or using `StripeConnector.create` (validates via `configFields` Zod schema):
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const { connector: 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';
|
|
69
|
+
|
|
70
|
+
export default defineConfig({
|
|
71
|
+
connectors: [{ connector: stripe }],
|
|
72
|
+
dashboards: {
|
|
73
|
+
billing: defineDashboard({
|
|
74
|
+
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
|
+
active_subscriptions: {
|
|
88
|
+
kind: 'stat',
|
|
89
|
+
title: 'Active subscriptions',
|
|
90
|
+
metric: defineMetric({
|
|
91
|
+
connector: stripe,
|
|
92
|
+
shape: 'entity',
|
|
93
|
+
entityType: 'stripe_subscription',
|
|
94
|
+
fn: 'count',
|
|
95
|
+
filter: [{ field: 'status', op: 'eq', value: 'active' }],
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
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
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Data model
|
|
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.).
|
|
150
|
+
|
|
151
|
+
## Sync behaviour
|
|
152
|
+
|
|
153
|
+
- **Backfill** (`mode: 'full'`): fetches all records via `starting_after` cursor pagination (`limit=100`).
|
|
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.
|
|
157
|
+
|
|
158
|
+
## Registering in the MCP server
|
|
159
|
+
|
|
160
|
+
To make the connector available via the `add_connector` MCP tool, include it in `connectorFactories`:
|
|
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
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BaseConnector, SyncOptions, StorageHandle, SyncResult } from '@rawdash/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const configFields: z.ZodObject<{
|
|
5
|
+
apiKey: z.ZodObject<{
|
|
6
|
+
$secret: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
9
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
10
|
+
customers: "customers";
|
|
11
|
+
products: "products";
|
|
12
|
+
prices: "prices";
|
|
13
|
+
subscriptions: "subscriptions";
|
|
14
|
+
invoices: "invoices";
|
|
15
|
+
charges: "charges";
|
|
16
|
+
payment_intents: "payment_intents";
|
|
17
|
+
disputes: "disputes";
|
|
18
|
+
refunds: "refunds";
|
|
19
|
+
}>>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
interface StripeSettings {
|
|
22
|
+
accountId?: string;
|
|
23
|
+
resources?: readonly StripeResource[];
|
|
24
|
+
}
|
|
25
|
+
interface StripePriceRecurring {
|
|
26
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
27
|
+
interval_count: number;
|
|
28
|
+
}
|
|
29
|
+
interface StripePrice {
|
|
30
|
+
id: string;
|
|
31
|
+
product: string;
|
|
32
|
+
unit_amount: number | null;
|
|
33
|
+
currency: string;
|
|
34
|
+
recurring: StripePriceRecurring | null;
|
|
35
|
+
active: boolean;
|
|
36
|
+
created: number;
|
|
37
|
+
}
|
|
38
|
+
interface StripeSubscriptionItem {
|
|
39
|
+
price: StripePrice;
|
|
40
|
+
quantity: number | null;
|
|
41
|
+
}
|
|
42
|
+
interface StripeSubscription {
|
|
43
|
+
id: string;
|
|
44
|
+
customer: string;
|
|
45
|
+
status: string;
|
|
46
|
+
items: {
|
|
47
|
+
data: StripeSubscriptionItem[];
|
|
48
|
+
};
|
|
49
|
+
current_period_start: number;
|
|
50
|
+
current_period_end: number;
|
|
51
|
+
cancel_at_period_end: boolean;
|
|
52
|
+
canceled_at: number | null;
|
|
53
|
+
trial_end: number | null;
|
|
54
|
+
currency: string;
|
|
55
|
+
created: number;
|
|
56
|
+
}
|
|
57
|
+
declare const stripeCredentials: {
|
|
58
|
+
apiKey: {
|
|
59
|
+
description: string;
|
|
60
|
+
auth: "required";
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
type StripeCredentials = typeof stripeCredentials;
|
|
64
|
+
declare const PHASE_ORDER: readonly ["customers", "products", "prices", "subscriptions", "invoices", "charges", "payment_intents", "disputes", "refunds"];
|
|
65
|
+
type StripePhase = (typeof PHASE_ORDER)[number];
|
|
66
|
+
type StripeResource = StripePhase;
|
|
67
|
+
declare function computeMrrAmountCents(subscription: StripeSubscription): number | null;
|
|
68
|
+
declare class StripeConnector extends BaseConnector<StripeSettings, StripeCredentials> {
|
|
69
|
+
static readonly id = "stripe";
|
|
70
|
+
static create(input: unknown): {
|
|
71
|
+
connector: StripeConnector;
|
|
72
|
+
};
|
|
73
|
+
readonly id = "stripe";
|
|
74
|
+
readonly credentials: {
|
|
75
|
+
apiKey: {
|
|
76
|
+
description: string;
|
|
77
|
+
auth: "required";
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
private buildHeaders;
|
|
81
|
+
private get;
|
|
82
|
+
private buildListUrl;
|
|
83
|
+
private entityCreatedGte;
|
|
84
|
+
private eventCreatedGt;
|
|
85
|
+
private buildPhaseUrl;
|
|
86
|
+
private clearScopeOnFirstPage;
|
|
87
|
+
private writePhase;
|
|
88
|
+
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { StripeConnector, type StripeSettings, computeMrrAmountCents, configFields };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
// ../../connector-shared/dist/index.js
|
|
2
|
+
var HttpClientError = class extends Error {
|
|
3
|
+
response;
|
|
4
|
+
constructor(message, response) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = new.target.name;
|
|
7
|
+
this.response = response;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var TransientError = class extends HttpClientError {
|
|
11
|
+
kind = "transient";
|
|
12
|
+
};
|
|
13
|
+
var RateLimitError = class extends HttpClientError {
|
|
14
|
+
kind = "rate_limit";
|
|
15
|
+
retryAfter;
|
|
16
|
+
constructor(message, response, retryAfter) {
|
|
17
|
+
super(message, response);
|
|
18
|
+
this.retryAfter = retryAfter;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var AuthError = class extends HttpClientError {
|
|
22
|
+
kind = "auth";
|
|
23
|
+
};
|
|
24
|
+
var UpstreamBugError = class extends HttpClientError {
|
|
25
|
+
kind = "upstream_bug";
|
|
26
|
+
};
|
|
27
|
+
var ClientBugError = class extends HttpClientError {
|
|
28
|
+
kind = "client_bug";
|
|
29
|
+
};
|
|
30
|
+
function classifyStatus(status) {
|
|
31
|
+
if (status === 429) {
|
|
32
|
+
return "rate_limit";
|
|
33
|
+
}
|
|
34
|
+
if (status === 401 || status === 403) {
|
|
35
|
+
return "auth";
|
|
36
|
+
}
|
|
37
|
+
if (status === 408) {
|
|
38
|
+
return "transient";
|
|
39
|
+
}
|
|
40
|
+
if (status >= 500) {
|
|
41
|
+
return "upstream_bug";
|
|
42
|
+
}
|
|
43
|
+
if (status >= 400) {
|
|
44
|
+
return "client_bug";
|
|
45
|
+
}
|
|
46
|
+
return "client_bug";
|
|
47
|
+
}
|
|
48
|
+
function errorForStatus(message, response, retryAfter) {
|
|
49
|
+
const kind = classifyStatus(response.status);
|
|
50
|
+
switch (kind) {
|
|
51
|
+
case "rate_limit":
|
|
52
|
+
return new RateLimitError(message, response, retryAfter);
|
|
53
|
+
case "auth":
|
|
54
|
+
return new AuthError(message, response);
|
|
55
|
+
case "transient":
|
|
56
|
+
return new TransientError(message, response);
|
|
57
|
+
case "upstream_bug":
|
|
58
|
+
return new UpstreamBugError(message, response);
|
|
59
|
+
case "client_bug":
|
|
60
|
+
return new ClientBugError(message, response);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var defaultRetryOn = (status, err) => {
|
|
64
|
+
if (err instanceof RateLimitError) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (err instanceof TransientError) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (status === null) {
|
|
71
|
+
return err instanceof Error && !(err instanceof HttpClientError);
|
|
72
|
+
}
|
|
73
|
+
if (status === 408 || status === 429) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (status >= 500) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
function parseRetryAfter(headerValue, now = /* @__PURE__ */ new Date()) {
|
|
82
|
+
if (!headerValue) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
const trimmed = headerValue.trim();
|
|
86
|
+
if (/^\d+$/.test(trimmed)) {
|
|
87
|
+
return new Date(now.getTime() + Number(trimmed) * 1e3);
|
|
88
|
+
}
|
|
89
|
+
const parsed = Date.parse(trimmed);
|
|
90
|
+
if (Number.isNaN(parsed)) {
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
return new Date(parsed);
|
|
94
|
+
}
|
|
95
|
+
function sleep(ms, signal) {
|
|
96
|
+
if (signal?.aborted) {
|
|
97
|
+
return Promise.reject(signal.reason ?? new Error("Aborted"));
|
|
98
|
+
}
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const onAbort = () => {
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
reject(signal.reason ?? new Error("Aborted"));
|
|
103
|
+
};
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
signal?.removeEventListener("abort", onAbort);
|
|
106
|
+
resolve();
|
|
107
|
+
}, ms);
|
|
108
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
var HTTP_CLIENT_VERSION = "0.0.0";
|
|
112
|
+
var DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;
|
|
113
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
114
|
+
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
115
|
+
var DEFAULT_INITIAL_DELAY_MS = 1e3;
|
|
116
|
+
var DEFAULT_MAX_DELAY_MS = 6e4;
|
|
117
|
+
function mergeHeaders(defaults, overrides) {
|
|
118
|
+
const merged = {};
|
|
119
|
+
for (const [k, v] of Object.entries(defaults)) {
|
|
120
|
+
merged[k.toLowerCase()] = v;
|
|
121
|
+
}
|
|
122
|
+
if (overrides) {
|
|
123
|
+
for (const [k, v] of Object.entries(overrides)) {
|
|
124
|
+
merged[k.toLowerCase()] = v;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return merged;
|
|
128
|
+
}
|
|
129
|
+
function linkTimeoutSignal(parent, timeoutMs) {
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const onParentAbort = () => {
|
|
132
|
+
controller.abort(parent?.reason);
|
|
133
|
+
};
|
|
134
|
+
if (parent) {
|
|
135
|
+
if (parent.aborted) {
|
|
136
|
+
controller.abort(parent.reason);
|
|
137
|
+
} else {
|
|
138
|
+
parent.addEventListener("abort", onParentAbort, { once: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const timer = setTimeout(() => {
|
|
142
|
+
controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));
|
|
143
|
+
}, timeoutMs);
|
|
144
|
+
return {
|
|
145
|
+
signal: controller.signal,
|
|
146
|
+
cancel: () => {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
if (parent) {
|
|
149
|
+
parent.removeEventListener("abort", onParentAbort);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async function readBody(res, parseJson) {
|
|
155
|
+
if (res.status === 204 || res.status === 205) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
159
|
+
if (parseJson && contentType.includes("application/json")) {
|
|
160
|
+
const text = await res.text();
|
|
161
|
+
if (text.length === 0) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return JSON.parse(text);
|
|
165
|
+
}
|
|
166
|
+
return res.text();
|
|
167
|
+
}
|
|
168
|
+
async function request(req, options = {}) {
|
|
169
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
170
|
+
const retry = req.retry ?? {};
|
|
171
|
+
const maxAttempts = retry.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
172
|
+
const initialDelayMs = retry.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
|
|
173
|
+
const maxDelayMs = retry.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
|
|
174
|
+
const retryOn = retry.retryOn ?? defaultRetryOn;
|
|
175
|
+
const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
176
|
+
const parseJson = req.parseJson ?? true;
|
|
177
|
+
const headers = mergeHeaders(
|
|
178
|
+
{
|
|
179
|
+
"User-Agent": DEFAULT_USER_AGENT,
|
|
180
|
+
Accept: "application/json"
|
|
181
|
+
},
|
|
182
|
+
req.headers
|
|
183
|
+
);
|
|
184
|
+
let lastErr;
|
|
185
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
186
|
+
req.signal?.throwIfAborted();
|
|
187
|
+
const { signal, cancel } = linkTimeoutSignal(req.signal, timeoutMs);
|
|
188
|
+
let res;
|
|
189
|
+
try {
|
|
190
|
+
res = await fetchImpl(req.url, {
|
|
191
|
+
method: req.method ?? "GET",
|
|
192
|
+
headers,
|
|
193
|
+
body: req.body,
|
|
194
|
+
signal
|
|
195
|
+
});
|
|
196
|
+
} catch (err2) {
|
|
197
|
+
cancel();
|
|
198
|
+
if (req.signal?.aborted) {
|
|
199
|
+
throw req.signal.reason ?? err2;
|
|
200
|
+
}
|
|
201
|
+
const error = err2 instanceof Error ? err2 : new Error(String(err2));
|
|
202
|
+
lastErr = error;
|
|
203
|
+
if (attempt < maxAttempts - 1 && retryOn(null, error)) {
|
|
204
|
+
const delay = computeDelay(attempt, initialDelayMs, maxDelayMs);
|
|
205
|
+
await sleep(delay, req.signal);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
throw new TransientError(error.message);
|
|
209
|
+
}
|
|
210
|
+
cancel();
|
|
211
|
+
const body = await readBody(res, parseJson);
|
|
212
|
+
const httpResponse = {
|
|
213
|
+
status: res.status,
|
|
214
|
+
headers: res.headers,
|
|
215
|
+
body
|
|
216
|
+
};
|
|
217
|
+
if (req.rateLimit) {
|
|
218
|
+
const state = req.rateLimit.parse(res.headers);
|
|
219
|
+
if (state) {
|
|
220
|
+
httpResponse.rateLimitState = state;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (res.ok) {
|
|
224
|
+
return httpResponse;
|
|
225
|
+
}
|
|
226
|
+
const retryAfter = parseRetryAfter(res.headers.get("retry-after"));
|
|
227
|
+
const message = `HTTP ${res.status} ${res.statusText} for ${req.method ?? "GET"} ${req.url}`;
|
|
228
|
+
const err = errorForStatus(message, httpResponse, retryAfter);
|
|
229
|
+
if (attempt < maxAttempts - 1 && retryOn(res.status, err) && !(err instanceof AuthError) && !(err instanceof ClientBugError)) {
|
|
230
|
+
lastErr = err;
|
|
231
|
+
let delay = computeDelay(attempt, initialDelayMs, maxDelayMs);
|
|
232
|
+
if (err instanceof RateLimitError && retryAfter) {
|
|
233
|
+
const wait = retryAfter.getTime() - Date.now();
|
|
234
|
+
if (wait > 0) {
|
|
235
|
+
delay = Math.min(wait, maxDelayMs);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
await sleep(delay, req.signal);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
throw err;
|
|
242
|
+
}
|
|
243
|
+
throw lastErr ?? new UpstreamBugError("Exhausted retry attempts");
|
|
244
|
+
}
|
|
245
|
+
function computeDelay(attempt, initialDelayMs, maxDelayMs) {
|
|
246
|
+
const base = initialDelayMs * 2 ** attempt;
|
|
247
|
+
const jitter = base * 0.25 * Math.random();
|
|
248
|
+
return Math.min(base + jitter, maxDelayMs);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/stripe.ts
|
|
252
|
+
import {
|
|
253
|
+
BaseConnector,
|
|
254
|
+
defineConfigFields,
|
|
255
|
+
paginateChunked
|
|
256
|
+
} from "@rawdash/core";
|
|
257
|
+
import { z } from "zod";
|
|
258
|
+
var configFields = defineConfigFields(
|
|
259
|
+
z.object({
|
|
260
|
+
apiKey: z.object({ $secret: z.string() }).meta({
|
|
261
|
+
label: "API Key",
|
|
262
|
+
description: "Stripe Restricted API key with read-only access. Create one at Dashboard \u2192 Developers \u2192 API keys.",
|
|
263
|
+
placeholder: "rk_live_...",
|
|
264
|
+
secret: true
|
|
265
|
+
}),
|
|
266
|
+
accountId: z.string().optional().meta({
|
|
267
|
+
label: "Account ID (optional)",
|
|
268
|
+
description: "Stripe Connect account ID. Only needed if you are a platform accessing a connected account.",
|
|
269
|
+
placeholder: "acct_..."
|
|
270
|
+
}),
|
|
271
|
+
resources: z.array(
|
|
272
|
+
z.enum([
|
|
273
|
+
"customers",
|
|
274
|
+
"products",
|
|
275
|
+
"prices",
|
|
276
|
+
"subscriptions",
|
|
277
|
+
"invoices",
|
|
278
|
+
"charges",
|
|
279
|
+
"payment_intents",
|
|
280
|
+
"disputes",
|
|
281
|
+
"refunds"
|
|
282
|
+
])
|
|
283
|
+
).nonempty().optional().meta({
|
|
284
|
+
label: "Resources",
|
|
285
|
+
description: "Which Stripe resources to sync. Omit to sync all resources. The API key only needs Read scope for the resources listed here."
|
|
286
|
+
})
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
var stripeCredentials = {
|
|
290
|
+
apiKey: {
|
|
291
|
+
description: "Stripe API key",
|
|
292
|
+
auth: "required"
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
var PHASE_ORDER = [
|
|
296
|
+
"customers",
|
|
297
|
+
"products",
|
|
298
|
+
"prices",
|
|
299
|
+
"subscriptions",
|
|
300
|
+
"invoices",
|
|
301
|
+
"charges",
|
|
302
|
+
"payment_intents",
|
|
303
|
+
"disputes",
|
|
304
|
+
"refunds"
|
|
305
|
+
];
|
|
306
|
+
function isStripeSyncCursor(value) {
|
|
307
|
+
if (typeof value !== "object" || value === null) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
const v = value;
|
|
311
|
+
if (typeof v.phase !== "string") {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (!PHASE_ORDER.includes(v.phase)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
if (v.page !== null && typeof v.page !== "string") {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
var ENTITY_TYPE_BY_PHASE = {
|
|
323
|
+
customers: "stripe_customer",
|
|
324
|
+
products: "stripe_product",
|
|
325
|
+
prices: "stripe_price",
|
|
326
|
+
subscriptions: "stripe_subscription",
|
|
327
|
+
invoices: "stripe_invoice"
|
|
328
|
+
};
|
|
329
|
+
var EVENT_NAME_BY_PHASE = {
|
|
330
|
+
charges: "stripe_charge",
|
|
331
|
+
payment_intents: "stripe_payment_intent",
|
|
332
|
+
disputes: "stripe_dispute",
|
|
333
|
+
refunds: "stripe_refund"
|
|
334
|
+
};
|
|
335
|
+
function computeMrrAmountCents(subscription) {
|
|
336
|
+
let sum = 0;
|
|
337
|
+
let counted = 0;
|
|
338
|
+
for (const item of subscription.items.data) {
|
|
339
|
+
const { unit_amount, recurring } = item.price;
|
|
340
|
+
if (unit_amount === null || unit_amount === void 0 || !recurring) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const quantity = item.quantity ?? 1;
|
|
344
|
+
const total = unit_amount * quantity;
|
|
345
|
+
const intervalCount = recurring.interval_count || 1;
|
|
346
|
+
let monthly;
|
|
347
|
+
switch (recurring.interval) {
|
|
348
|
+
case "month":
|
|
349
|
+
monthly = total / intervalCount;
|
|
350
|
+
break;
|
|
351
|
+
case "year":
|
|
352
|
+
monthly = total / (12 * intervalCount);
|
|
353
|
+
break;
|
|
354
|
+
case "week":
|
|
355
|
+
monthly = total * 52 / (12 * intervalCount);
|
|
356
|
+
break;
|
|
357
|
+
case "day":
|
|
358
|
+
monthly = total * 365 / (12 * intervalCount);
|
|
359
|
+
break;
|
|
360
|
+
default:
|
|
361
|
+
monthly = null;
|
|
362
|
+
}
|
|
363
|
+
if (monthly === null) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
sum += monthly;
|
|
367
|
+
counted++;
|
|
368
|
+
}
|
|
369
|
+
if (counted === 0) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
return Math.round(sum);
|
|
373
|
+
}
|
|
374
|
+
var StripeConnector = class _StripeConnector extends BaseConnector {
|
|
375
|
+
static id = "stripe";
|
|
376
|
+
static create(input) {
|
|
377
|
+
const parsed = configFields.parse(input);
|
|
378
|
+
return {
|
|
379
|
+
connector: new _StripeConnector(
|
|
380
|
+
{ accountId: parsed.accountId, resources: parsed.resources },
|
|
381
|
+
{ apiKey: parsed.apiKey }
|
|
382
|
+
)
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
id = "stripe";
|
|
386
|
+
credentials = stripeCredentials;
|
|
387
|
+
buildHeaders() {
|
|
388
|
+
const headers = {
|
|
389
|
+
Authorization: `Bearer ${this.creds.apiKey}`,
|
|
390
|
+
"Stripe-Version": "2024-06-20",
|
|
391
|
+
"User-Agent": "rawdash/connector-stripe (+https://rawdash.dev)"
|
|
392
|
+
};
|
|
393
|
+
if (this.settings.accountId) {
|
|
394
|
+
headers["Stripe-Account"] = this.settings.accountId;
|
|
395
|
+
}
|
|
396
|
+
return headers;
|
|
397
|
+
}
|
|
398
|
+
get(url, signal) {
|
|
399
|
+
const req = {
|
|
400
|
+
url,
|
|
401
|
+
headers: this.buildHeaders(),
|
|
402
|
+
signal
|
|
403
|
+
};
|
|
404
|
+
return request(req);
|
|
405
|
+
}
|
|
406
|
+
buildListUrl(path, params) {
|
|
407
|
+
const url = new URL(`https://api.stripe.com/v1/${path}`);
|
|
408
|
+
url.searchParams.set("limit", "100");
|
|
409
|
+
for (const [key, value] of Object.entries(params)) {
|
|
410
|
+
if (value !== void 0) {
|
|
411
|
+
url.searchParams.set(key, value);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return url.toString();
|
|
415
|
+
}
|
|
416
|
+
// created[gte] cutoff for entity phases in incremental mode (7-day lookback)
|
|
417
|
+
entityCreatedGte(options) {
|
|
418
|
+
if (options.mode !== "latest" || !options.since) {
|
|
419
|
+
return void 0;
|
|
420
|
+
}
|
|
421
|
+
const sinceMs = new Date(options.since).getTime();
|
|
422
|
+
return String(Math.floor((sinceMs - 7 * 24 * 60 * 60 * 1e3) / 1e3));
|
|
423
|
+
}
|
|
424
|
+
// created[gt] cutoff for event phases in incremental mode
|
|
425
|
+
eventCreatedGt(options) {
|
|
426
|
+
if (options.mode !== "latest" || !options.since) {
|
|
427
|
+
return void 0;
|
|
428
|
+
}
|
|
429
|
+
return String(Math.floor(new Date(options.since).getTime() / 1e3));
|
|
430
|
+
}
|
|
431
|
+
buildPhaseUrl(phase, page, options) {
|
|
432
|
+
const startingAfter = page ?? void 0;
|
|
433
|
+
if (phase in ENTITY_TYPE_BY_PHASE) {
|
|
434
|
+
const extra = phase === "subscriptions" ? { status: "all" } : {};
|
|
435
|
+
return this.buildListUrl(phase, {
|
|
436
|
+
...extra,
|
|
437
|
+
starting_after: startingAfter,
|
|
438
|
+
"created[gte]": this.entityCreatedGte(options)
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return this.buildListUrl(phase, {
|
|
442
|
+
starting_after: startingAfter,
|
|
443
|
+
"created[gt]": this.eventCreatedGt(options)
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
async clearScopeOnFirstPage(storage, phase) {
|
|
447
|
+
const entityType = ENTITY_TYPE_BY_PHASE[phase];
|
|
448
|
+
if (entityType) {
|
|
449
|
+
await storage.entities([], { types: [entityType] });
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const eventName = EVENT_NAME_BY_PHASE[phase];
|
|
453
|
+
if (eventName) {
|
|
454
|
+
await storage.events([], { names: [eventName] });
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
async writePhase(storage, phase, items) {
|
|
458
|
+
switch (phase) {
|
|
459
|
+
case "customers":
|
|
460
|
+
for (const c of items) {
|
|
461
|
+
await storage.entity({
|
|
462
|
+
type: "stripe_customer",
|
|
463
|
+
id: c.id,
|
|
464
|
+
attributes: {
|
|
465
|
+
email: c.email ?? null,
|
|
466
|
+
name: c.name ?? null,
|
|
467
|
+
created: c.created,
|
|
468
|
+
currency: c.currency ?? null,
|
|
469
|
+
delinquent: c.delinquent ?? false,
|
|
470
|
+
livemode: c.livemode
|
|
471
|
+
},
|
|
472
|
+
updated_at: c.created * 1e3
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return;
|
|
476
|
+
case "products":
|
|
477
|
+
for (const p of items) {
|
|
478
|
+
await storage.entity({
|
|
479
|
+
type: "stripe_product",
|
|
480
|
+
id: p.id,
|
|
481
|
+
attributes: { name: p.name, active: p.active, created: p.created },
|
|
482
|
+
updated_at: p.created * 1e3
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
return;
|
|
486
|
+
case "prices":
|
|
487
|
+
for (const p of items) {
|
|
488
|
+
await storage.entity({
|
|
489
|
+
type: "stripe_price",
|
|
490
|
+
id: p.id,
|
|
491
|
+
attributes: {
|
|
492
|
+
productId: p.product,
|
|
493
|
+
unitAmount: p.unit_amount ?? null,
|
|
494
|
+
currency: p.currency,
|
|
495
|
+
interval: p.recurring?.interval ?? null,
|
|
496
|
+
intervalCount: p.recurring?.interval_count ?? null,
|
|
497
|
+
active: p.active,
|
|
498
|
+
created: p.created
|
|
499
|
+
},
|
|
500
|
+
updated_at: p.created * 1e3
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
return;
|
|
504
|
+
case "subscriptions":
|
|
505
|
+
for (const s of items) {
|
|
506
|
+
await storage.entity({
|
|
507
|
+
type: "stripe_subscription",
|
|
508
|
+
id: s.id,
|
|
509
|
+
attributes: {
|
|
510
|
+
customerId: s.customer,
|
|
511
|
+
status: s.status,
|
|
512
|
+
planId: s.items.data[0]?.price.id ?? null,
|
|
513
|
+
currentPeriodStart: s.current_period_start,
|
|
514
|
+
currentPeriodEnd: s.current_period_end,
|
|
515
|
+
cancelAtPeriodEnd: s.cancel_at_period_end,
|
|
516
|
+
canceledAt: s.canceled_at ?? null,
|
|
517
|
+
trialEnd: s.trial_end ?? null,
|
|
518
|
+
mrrAmount: computeMrrAmountCents(s),
|
|
519
|
+
currency: s.currency,
|
|
520
|
+
created: s.created
|
|
521
|
+
},
|
|
522
|
+
updated_at: s.current_period_end * 1e3
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
case "invoices":
|
|
527
|
+
for (const inv of items) {
|
|
528
|
+
await storage.entity({
|
|
529
|
+
type: "stripe_invoice",
|
|
530
|
+
id: inv.id,
|
|
531
|
+
attributes: {
|
|
532
|
+
customerId: inv.customer ?? null,
|
|
533
|
+
subscriptionId: inv.subscription ?? null,
|
|
534
|
+
status: inv.status ?? null,
|
|
535
|
+
amountDue: inv.amount_due,
|
|
536
|
+
amountPaid: inv.amount_paid,
|
|
537
|
+
currency: inv.currency,
|
|
538
|
+
created: inv.created,
|
|
539
|
+
dueDate: inv.due_date ?? null,
|
|
540
|
+
hostedInvoiceUrl: inv.hosted_invoice_url ?? null
|
|
541
|
+
},
|
|
542
|
+
updated_at: inv.created * 1e3
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
return;
|
|
546
|
+
case "charges":
|
|
547
|
+
for (const c of items) {
|
|
548
|
+
await storage.event({
|
|
549
|
+
name: "stripe_charge",
|
|
550
|
+
start_ts: c.created * 1e3,
|
|
551
|
+
end_ts: null,
|
|
552
|
+
attributes: {
|
|
553
|
+
id: c.id,
|
|
554
|
+
customerId: c.customer ?? null,
|
|
555
|
+
amount: c.amount,
|
|
556
|
+
currency: c.currency,
|
|
557
|
+
status: c.status,
|
|
558
|
+
failureCode: c.failure_code ?? null,
|
|
559
|
+
paymentIntentId: c.payment_intent ?? null
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
case "payment_intents":
|
|
565
|
+
for (const pi of items) {
|
|
566
|
+
await storage.event({
|
|
567
|
+
name: "stripe_payment_intent",
|
|
568
|
+
start_ts: pi.created * 1e3,
|
|
569
|
+
end_ts: null,
|
|
570
|
+
attributes: {
|
|
571
|
+
id: pi.id,
|
|
572
|
+
customerId: pi.customer ?? null,
|
|
573
|
+
amount: pi.amount,
|
|
574
|
+
currency: pi.currency,
|
|
575
|
+
status: pi.status
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return;
|
|
580
|
+
case "disputes":
|
|
581
|
+
for (const d of items) {
|
|
582
|
+
await storage.event({
|
|
583
|
+
name: "stripe_dispute",
|
|
584
|
+
start_ts: d.created * 1e3,
|
|
585
|
+
end_ts: null,
|
|
586
|
+
attributes: {
|
|
587
|
+
id: d.id,
|
|
588
|
+
chargeId: d.charge,
|
|
589
|
+
amount: d.amount,
|
|
590
|
+
currency: d.currency,
|
|
591
|
+
reason: d.reason,
|
|
592
|
+
status: d.status
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
return;
|
|
597
|
+
case "refunds":
|
|
598
|
+
for (const r of items) {
|
|
599
|
+
await storage.event({
|
|
600
|
+
name: "stripe_refund",
|
|
601
|
+
start_ts: r.created * 1e3,
|
|
602
|
+
end_ts: null,
|
|
603
|
+
attributes: {
|
|
604
|
+
id: r.id,
|
|
605
|
+
chargeId: r.charge ?? null,
|
|
606
|
+
amount: r.amount,
|
|
607
|
+
currency: r.currency,
|
|
608
|
+
reason: r.reason ?? null,
|
|
609
|
+
status: r.status ?? null
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async sync(options, storage, signal) {
|
|
617
|
+
const cursor = isStripeSyncCursor(options.cursor) ? options.cursor : void 0;
|
|
618
|
+
const isFull = options.mode === "full";
|
|
619
|
+
const enabled = this.settings.resources;
|
|
620
|
+
const phases = enabled && enabled.length > 0 ? PHASE_ORDER.filter((p) => enabled.includes(p)) : PHASE_ORDER;
|
|
621
|
+
return paginateChunked({
|
|
622
|
+
phases,
|
|
623
|
+
cursor,
|
|
624
|
+
signal,
|
|
625
|
+
fetchPage: async (phase, page, sig) => {
|
|
626
|
+
const url = this.buildPhaseUrl(phase, page, options);
|
|
627
|
+
const res = await this.get(
|
|
628
|
+
url,
|
|
629
|
+
sig
|
|
630
|
+
);
|
|
631
|
+
const { data, has_more } = res.body;
|
|
632
|
+
const next = has_more && data.length > 0 ? data.at(-1).id : null;
|
|
633
|
+
return { items: data, next };
|
|
634
|
+
},
|
|
635
|
+
writeBatch: async (phase, items, page) => {
|
|
636
|
+
if (isFull && page === null) {
|
|
637
|
+
await this.clearScopeOnFirstPage(storage, phase);
|
|
638
|
+
}
|
|
639
|
+
await this.writePhase(storage, phase, items);
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
export {
|
|
645
|
+
StripeConnector,
|
|
646
|
+
computeMrrAmountCents,
|
|
647
|
+
configFields
|
|
648
|
+
};
|
|
649
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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/pagination.ts","../src/stripe.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","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, 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;\n\nexport interface RequestOptions {\n fetch?: FetchLike;\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 (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 const githubRateLimit: RateLimitPolicy = {\n parse(h) {\n const remainingRaw = h.get('x-ratelimit-remaining');\n const resetRaw = h.get('x-ratelimit-reset');\n if (remainingRaw === null || resetRaw === null) {\n return null;\n }\n const remaining = Number(remainingRaw);\n const reset = Number(resetRaw);\n if (!Number.isFinite(remaining) || !Number.isFinite(reset) || reset < 0) {\n return null;\n }\n return { remaining, resetAt: new Date(reset * 1000) };\n },\n};\n\nexport const sentryRateLimit: RateLimitPolicy = {\n parse(h) {\n const concurrent = h.get('x-sentry-rate-limit-remaining');\n const reset = h.get('x-sentry-rate-limit-reset');\n if (concurrent === null || reset === null) {\n return null;\n }\n const remaining = Number(concurrent);\n const resetSec = Number(reset);\n if (\n !Number.isFinite(remaining) ||\n !Number.isFinite(resetSec) ||\n resetSec < 0\n ) {\n return null;\n }\n return { remaining, resetAt: new Date(resetSec * 1000) };\n },\n};\n\nexport const linearRateLimit: RateLimitPolicy = {\n parse(h) {\n const remainingRaw = h.get('x-ratelimit-requests-remaining');\n const resetRaw = h.get('x-ratelimit-requests-reset');\n if (remainingRaw === null) {\n return null;\n }\n const remaining = Number(remainingRaw);\n if (!Number.isFinite(remaining)) {\n return null;\n }\n let resetAt: Date;\n if (resetRaw !== null) {\n const reset = Number(resetRaw);\n if (!Number.isFinite(reset) || reset < 0) {\n return null;\n }\n resetAt = new Date(reset);\n } else {\n resetAt = new Date(Date.now() + 60_000);\n }\n return { remaining, resetAt };\n },\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): AsyncIterable<T> {\n let next: string | null = initial.url;\n while (next) {\n const res: Awaited<ReturnType<typeof request>> = await request({\n ...initial,\n url: next,\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): AsyncIterable<T> {\n let req: HttpRequest = initial;\n while (true) {\n const res = await request(req);\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): AsyncIterable<T> {\n let page = 1;\n while (true) {\n const req = page === 1 ? initial : buildPage(initial, page);\n const res = await request(req);\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","import {\n type HttpRequest,\n type HttpResponse,\n request,\n} from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ChunkedSyncCursor,\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): { connector: StripeConnector } {\n const parsed = configFields.parse(input);\n return {\n connector: new StripeConnector(\n { accountId: parsed.accountId, resources: parsed.resources },\n { apiKey: parsed.apiKey },\n ),\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 get<T>(url: string, signal?: AbortSignal): Promise<HttpResponse<T>> {\n const req: HttpRequest = {\n url,\n headers: this.buildHeaders(),\n signal,\n };\n return request<T>(req);\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.get<StripeListResponse<{ id: string }>>(\n url,\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"],"mappings":";AASO,IAAe,kBAAf,cAAuC,MAAM;EAEzC;EAET,YAAY,SAAiB,UAAyB;AACpD,UAAM,OAAO;AACb,SAAK,OAAO,WAAW;AACvB,SAAK,WAAW;EAClB;AACF;AAEO,IAAM,iBAAN,cAA6B,gBAAgB;EACzC,OAAO;AAClB;AAEO,IAAM,iBAAN,cAA6B,gBAAgB;EACzC,OAAO;EACP;EAET,YAAY,SAAiB,UAAyB,YAAmB;AACvE,UAAM,SAAS,QAAQ;AACvB,SAAK,aAAa;EACpB;AACF;AAEO,IAAM,YAAN,cAAwB,gBAAgB;EACpC,OAAO;AAClB;AAEO,IAAM,mBAAN,cAA+B,gBAAgB;EAC3C,OAAO;AAClB;AAEO,IAAM,iBAAN,cAA6B,gBAAgB;EACzC,OAAO;AAClB;AAEO,SAAS,eAAe,QAA+B;AAC5D,MAAI,WAAW,KAAK;AAClB,WAAO;EACT;AACA,MAAI,WAAW,OAAO,WAAW,KAAK;AACpC,WAAO;EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO;EACT;AACA,MAAI,UAAU,KAAK;AACjB,WAAO;EACT;AACA,MAAI,UAAU,KAAK;AACjB,WAAO;EACT;AACA,SAAO;AACT;AAEO,SAAS,eACd,SACA,UACA,YACiB;AACjB,QAAM,OAAO,eAAe,SAAS,MAAM;AAC3C,UAAQ,MAAM;IACZ,KAAK;AACH,aAAO,IAAI,eAAe,SAAS,UAAU,UAAU;IACzD,K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V,IAAI,EAAE;AAAA,cACN,UAAU,EAAE,UAAU;AAAA,cACtB,QAAQ,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,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;","names":["err"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rawdash/connector-stripe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rawdash connector for Stripe — billing, subscriptions, and payments",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/rawdash/rawdash.git",
|
|
10
|
+
"directory": "packages/connectors/stripe"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"@rawdash/source": "./src/index.ts",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "eslint src",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@rawdash/core": "workspace:*",
|
|
32
|
+
"zod": "^4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@rawdash/connector-shared": "workspace:*",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.7.2",
|
|
38
|
+
"vitest": "^4.1.4"
|
|
39
|
+
}
|
|
40
|
+
}
|