@rawdash/connector-klaviyo 0.0.1
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 +125 -0
- package/dist/index.d.ts +472 -0
- package/dist/index.js +511 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<!-- This file is generated from connector metadata by scripts/generate-connector-docs.ts. Do not edit by hand. -->
|
|
2
|
+
|
|
3
|
+
# @rawdash/connector-klaviyo
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@rawdash/connector-klaviyo)
|
|
6
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Sync campaigns, flows, lists, and segments from Klaviyo for ecommerce email and SMS marketing analytics.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @rawdash/connector-klaviyo
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Authentication
|
|
17
|
+
|
|
18
|
+
A Klaviyo Private API Key with read access to campaigns, flows, lists, and segments.
|
|
19
|
+
|
|
20
|
+
1. Open Klaviyo -> Settings -> API Keys and create a new Private API Key.
|
|
21
|
+
2. Grant read access to Campaigns, Flows, Lists, and Segments (or only the scopes you intend to sync).
|
|
22
|
+
3. Copy the generated key and store it as a secret, referencing it from the connector config as `apiKey: secret("KLAVIYO_API_KEY")`.
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
| Field | Type | Required | Description |
|
|
27
|
+
| ------------- | --------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `apiKey` | secret | Yes | Klaviyo Private API Key with read scopes for campaigns, flows, lists, and segments. Create one at Klaviyo -> Settings -> API Keys. |
|
|
29
|
+
| `apiRevision` | string | No | Value sent in the revision header. Defaults to 2024-10-15; pin a specific date here when upgrading deliberately. |
|
|
30
|
+
| `channel` | `email` \| `sms` \| `mobile_push` | No | Which campaign channel to sync. The Klaviyo campaigns endpoint requires a channel filter and only returns one channel per call; defaults to 'email'. |
|
|
31
|
+
| `resources` | array | No | Which Klaviyo resources to sync. Omit to sync all of them. The key only needs read scopes for the resources listed here. |
|
|
32
|
+
|
|
33
|
+
## Resources
|
|
34
|
+
|
|
35
|
+
- **`klaviyo_list`** _(entity)_ - Klaviyo lists (manually managed subscriber collections) with opt-in process and created/updated timestamps.
|
|
36
|
+
- Endpoint: `GET /api/lists`
|
|
37
|
+
- `name`: List display name.
|
|
38
|
+
- `optInProcess`: Opt-in process (e.g. single_opt_in, double_opt_in).
|
|
39
|
+
- `createdAt`: When the list was created (Unix ms).
|
|
40
|
+
- **`klaviyo_segment`** _(entity)_ - Klaviyo segments (rule-based dynamic groups) with active, starred, and processing flags.
|
|
41
|
+
- Endpoint: `GET /api/segments`
|
|
42
|
+
- `name`: Segment display name.
|
|
43
|
+
- `isActive`: Whether the segment is active.
|
|
44
|
+
- `isStarred`: Whether the segment is starred.
|
|
45
|
+
- `isProcessing`: Whether the segment is currently recomputing.
|
|
46
|
+
- `createdAt`: When the segment was created (Unix ms).
|
|
47
|
+
- **`klaviyo_campaign`** _(entity)_ - Klaviyo campaigns for the configured channel, with status, archived flag, send strategy, and send time.
|
|
48
|
+
- Endpoint: `GET /api/campaigns`
|
|
49
|
+
- Klaviyo requires a channel filter on /campaigns; this connector syncs one channel per instance (the configured `channel` setting).
|
|
50
|
+
- `name`: Campaign name.
|
|
51
|
+
- `status`: Campaign status (Draft, Sent, etc.).
|
|
52
|
+
- `archived`: Whether the campaign is archived.
|
|
53
|
+
- `channel`: Campaign channel (email, sms, mobile_push).
|
|
54
|
+
- `sendStrategy`: Send strategy method (static, smart_send_time, etc.).
|
|
55
|
+
- `sendTime`: Scheduled or actual send time (Unix ms).
|
|
56
|
+
- `createdAt`: When the campaign was created (Unix ms).
|
|
57
|
+
- **`klaviyo_flow`** _(entity)_ - Klaviyo flows (automation series) with status, trigger type, and archived flag.
|
|
58
|
+
- Endpoint: `GET /api/flows`
|
|
59
|
+
- `name`: Flow name.
|
|
60
|
+
- `status`: Flow status (live, draft, manual).
|
|
61
|
+
- `archived`: Whether the flow is archived.
|
|
62
|
+
- `triggerType`: Flow trigger type (e.g. list, segment, metric).
|
|
63
|
+
- `createdAt`: When the flow was created (Unix ms).
|
|
64
|
+
|
|
65
|
+
## Example
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import {
|
|
69
|
+
defineConfig,
|
|
70
|
+
defineDashboard,
|
|
71
|
+
defineMetric,
|
|
72
|
+
secret,
|
|
73
|
+
} from '@rawdash/core';
|
|
74
|
+
|
|
75
|
+
const klaviyo = {
|
|
76
|
+
name: 'klaviyo',
|
|
77
|
+
connectorId: 'klaviyo',
|
|
78
|
+
config: {
|
|
79
|
+
apiKey: secret('KLAVIYO_API_KEY'),
|
|
80
|
+
apiRevision: '2024-10-15',
|
|
81
|
+
channel: 'email',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default defineConfig({
|
|
86
|
+
connectors: [klaviyo],
|
|
87
|
+
dashboards: {
|
|
88
|
+
marketing: defineDashboard({
|
|
89
|
+
widgets: {
|
|
90
|
+
active_segments: {
|
|
91
|
+
kind: 'stat',
|
|
92
|
+
title: 'Active segments',
|
|
93
|
+
metric: defineMetric({
|
|
94
|
+
connector: klaviyo,
|
|
95
|
+
shape: 'entity',
|
|
96
|
+
entityType: 'klaviyo_segment',
|
|
97
|
+
fn: 'count',
|
|
98
|
+
filter: [{ field: 'isActive', op: 'eq', value: true }],
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Rate limits
|
|
108
|
+
|
|
109
|
+
Klaviyo enforces per-endpoint burst and steady rate limits and signals them via the RateLimit-Remaining and RateLimit-Reset response headers. The shared HTTP client backs off on 429 and honors Retry-After.
|
|
110
|
+
|
|
111
|
+
## Limitations
|
|
112
|
+
|
|
113
|
+
- Campaign and flow statistics (campaign-values-reports / flow-values-reports) are not synced; the reports endpoints require a per-account conversion metric id and are deferred to a follow-up.
|
|
114
|
+
- Profile, event, catalog, and coupon objects are out of scope (niche for dashboard use).
|
|
115
|
+
- Only one campaign channel per sync (email, sms, or mobile_push) - the Klaviyo campaigns endpoint requires the filter and does not allow OR across channels.
|
|
116
|
+
|
|
117
|
+
## Links
|
|
118
|
+
|
|
119
|
+
- [Rawdash docs](https://rawdash.dev/docs/connectors/)
|
|
120
|
+
- [Klaviyo API docs](https://developers.klaviyo.com/en/reference/api_overview)
|
|
121
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { BaseConnector, ConnectorContext, SyncOptions, StorageHandle, SyncResult, ConnectorDoc } 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
|
+
apiRevision: z.ZodDefault<z.ZodString>;
|
|
9
|
+
channel: z.ZodDefault<z.ZodEnum<{
|
|
10
|
+
email: "email";
|
|
11
|
+
sms: "sms";
|
|
12
|
+
mobile_push: "mobile_push";
|
|
13
|
+
}>>;
|
|
14
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
15
|
+
lists: "lists";
|
|
16
|
+
segments: "segments";
|
|
17
|
+
campaigns: "campaigns";
|
|
18
|
+
flows: "flows";
|
|
19
|
+
}>>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
declare const doc: ConnectorDoc;
|
|
22
|
+
type KlaviyoChannel = 'email' | 'sms' | 'mobile_push';
|
|
23
|
+
interface KlaviyoSettings {
|
|
24
|
+
apiRevision: string;
|
|
25
|
+
channel: KlaviyoChannel;
|
|
26
|
+
resources?: readonly KlaviyoResource[];
|
|
27
|
+
}
|
|
28
|
+
declare const klaviyoCredentials: {
|
|
29
|
+
apiKey: {
|
|
30
|
+
description: string;
|
|
31
|
+
auth: "required";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
type KlaviyoCredentials = typeof klaviyoCredentials;
|
|
35
|
+
declare const PHASE_ORDER: readonly ["lists", "segments", "campaigns", "flows"];
|
|
36
|
+
type KlaviyoPhase = (typeof PHASE_ORDER)[number];
|
|
37
|
+
type KlaviyoResource = KlaviyoPhase;
|
|
38
|
+
declare const klaviyoResources: {
|
|
39
|
+
readonly klaviyo_list: {
|
|
40
|
+
readonly shape: "entity";
|
|
41
|
+
readonly description: "Klaviyo lists (manually managed subscriber collections) with opt-in process and created/updated timestamps.";
|
|
42
|
+
readonly endpoint: "GET /api/lists";
|
|
43
|
+
readonly fields: [{
|
|
44
|
+
readonly name: "name";
|
|
45
|
+
readonly description: "List display name.";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "optInProcess";
|
|
48
|
+
readonly description: "Opt-in process (e.g. single_opt_in, double_opt_in).";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "createdAt";
|
|
51
|
+
readonly description: "When the list was created (Unix ms).";
|
|
52
|
+
}];
|
|
53
|
+
readonly responses: {
|
|
54
|
+
readonly lists: z.ZodObject<{
|
|
55
|
+
data: z.ZodArray<z.ZodObject<{
|
|
56
|
+
type: z.ZodString;
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
attributes: z.ZodObject<{
|
|
59
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
61
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
62
|
+
opt_in_process: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
66
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
}, z.core.$strip>>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
readonly klaviyo_segment: {
|
|
72
|
+
readonly shape: "entity";
|
|
73
|
+
readonly description: "Klaviyo segments (rule-based dynamic groups) with active, starred, and processing flags.";
|
|
74
|
+
readonly endpoint: "GET /api/segments";
|
|
75
|
+
readonly fields: [{
|
|
76
|
+
readonly name: "name";
|
|
77
|
+
readonly description: "Segment display name.";
|
|
78
|
+
}, {
|
|
79
|
+
readonly name: "isActive";
|
|
80
|
+
readonly description: "Whether the segment is active.";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "isStarred";
|
|
83
|
+
readonly description: "Whether the segment is starred.";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "isProcessing";
|
|
86
|
+
readonly description: "Whether the segment is currently recomputing.";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "createdAt";
|
|
89
|
+
readonly description: "When the segment was created (Unix ms).";
|
|
90
|
+
}];
|
|
91
|
+
readonly responses: {
|
|
92
|
+
readonly segments: z.ZodObject<{
|
|
93
|
+
data: z.ZodArray<z.ZodObject<{
|
|
94
|
+
type: z.ZodString;
|
|
95
|
+
id: z.ZodString;
|
|
96
|
+
attributes: z.ZodObject<{
|
|
97
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
98
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
99
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
100
|
+
is_active: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
101
|
+
is_starred: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
102
|
+
is_processing: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
106
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
107
|
+
}, z.core.$strip>>>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
readonly klaviyo_campaign: {
|
|
112
|
+
readonly shape: "entity";
|
|
113
|
+
readonly description: "Klaviyo campaigns for the configured channel, with status, archived flag, send strategy, and send time.";
|
|
114
|
+
readonly endpoint: "GET /api/campaigns";
|
|
115
|
+
readonly notes: "Klaviyo requires a channel filter on /campaigns; this connector syncs one channel per instance (the configured `channel` setting).";
|
|
116
|
+
readonly fields: [{
|
|
117
|
+
readonly name: "name";
|
|
118
|
+
readonly description: "Campaign name.";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "status";
|
|
121
|
+
readonly description: "Campaign status (Draft, Sent, etc.).";
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "archived";
|
|
124
|
+
readonly description: "Whether the campaign is archived.";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "channel";
|
|
127
|
+
readonly description: "Campaign channel (email, sms, mobile_push).";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "sendStrategy";
|
|
130
|
+
readonly description: "Send strategy method (static, smart_send_time, etc.).";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "sendTime";
|
|
133
|
+
readonly description: "Scheduled or actual send time (Unix ms).";
|
|
134
|
+
}, {
|
|
135
|
+
readonly name: "createdAt";
|
|
136
|
+
readonly description: "When the campaign was created (Unix ms).";
|
|
137
|
+
}];
|
|
138
|
+
readonly responses: {
|
|
139
|
+
readonly campaigns: z.ZodObject<{
|
|
140
|
+
data: z.ZodArray<z.ZodObject<{
|
|
141
|
+
type: z.ZodString;
|
|
142
|
+
id: z.ZodString;
|
|
143
|
+
attributes: z.ZodObject<{
|
|
144
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
145
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
146
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
147
|
+
channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
148
|
+
send_time: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
149
|
+
scheduled_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
150
|
+
send_strategy: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
151
|
+
method: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
152
|
+
}, z.core.$strip>>>;
|
|
153
|
+
created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
154
|
+
updated_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
}, z.core.$strip>>;
|
|
157
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
158
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
159
|
+
}, z.core.$strip>>>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
readonly klaviyo_flow: {
|
|
164
|
+
readonly shape: "entity";
|
|
165
|
+
readonly description: "Klaviyo flows (automation series) with status, trigger type, and archived flag.";
|
|
166
|
+
readonly endpoint: "GET /api/flows";
|
|
167
|
+
readonly fields: [{
|
|
168
|
+
readonly name: "name";
|
|
169
|
+
readonly description: "Flow name.";
|
|
170
|
+
}, {
|
|
171
|
+
readonly name: "status";
|
|
172
|
+
readonly description: "Flow status (live, draft, manual).";
|
|
173
|
+
}, {
|
|
174
|
+
readonly name: "archived";
|
|
175
|
+
readonly description: "Whether the flow is archived.";
|
|
176
|
+
}, {
|
|
177
|
+
readonly name: "triggerType";
|
|
178
|
+
readonly description: "Flow trigger type (e.g. list, segment, metric).";
|
|
179
|
+
}, {
|
|
180
|
+
readonly name: "createdAt";
|
|
181
|
+
readonly description: "When the flow was created (Unix ms).";
|
|
182
|
+
}];
|
|
183
|
+
readonly responses: {
|
|
184
|
+
readonly flows: z.ZodObject<{
|
|
185
|
+
data: z.ZodArray<z.ZodObject<{
|
|
186
|
+
type: z.ZodString;
|
|
187
|
+
id: z.ZodString;
|
|
188
|
+
attributes: z.ZodObject<{
|
|
189
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
190
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
191
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
192
|
+
trigger_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
193
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
194
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
}, z.core.$strip>>;
|
|
197
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
198
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
199
|
+
}, z.core.$strip>>>;
|
|
200
|
+
}, z.core.$strip>;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
declare const id = "klaviyo";
|
|
205
|
+
declare class KlaviyoConnector extends BaseConnector<KlaviyoSettings, KlaviyoCredentials> {
|
|
206
|
+
static readonly id = "klaviyo";
|
|
207
|
+
static readonly resources: {
|
|
208
|
+
readonly klaviyo_list: {
|
|
209
|
+
readonly shape: "entity";
|
|
210
|
+
readonly description: "Klaviyo lists (manually managed subscriber collections) with opt-in process and created/updated timestamps.";
|
|
211
|
+
readonly endpoint: "GET /api/lists";
|
|
212
|
+
readonly fields: [{
|
|
213
|
+
readonly name: "name";
|
|
214
|
+
readonly description: "List display name.";
|
|
215
|
+
}, {
|
|
216
|
+
readonly name: "optInProcess";
|
|
217
|
+
readonly description: "Opt-in process (e.g. single_opt_in, double_opt_in).";
|
|
218
|
+
}, {
|
|
219
|
+
readonly name: "createdAt";
|
|
220
|
+
readonly description: "When the list was created (Unix ms).";
|
|
221
|
+
}];
|
|
222
|
+
readonly responses: {
|
|
223
|
+
readonly lists: z.ZodObject<{
|
|
224
|
+
data: z.ZodArray<z.ZodObject<{
|
|
225
|
+
type: z.ZodString;
|
|
226
|
+
id: z.ZodString;
|
|
227
|
+
attributes: z.ZodObject<{
|
|
228
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
229
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
230
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
231
|
+
opt_in_process: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
232
|
+
}, z.core.$strip>;
|
|
233
|
+
}, z.core.$strip>>;
|
|
234
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
235
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
236
|
+
}, z.core.$strip>>>;
|
|
237
|
+
}, z.core.$strip>;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
readonly klaviyo_segment: {
|
|
241
|
+
readonly shape: "entity";
|
|
242
|
+
readonly description: "Klaviyo segments (rule-based dynamic groups) with active, starred, and processing flags.";
|
|
243
|
+
readonly endpoint: "GET /api/segments";
|
|
244
|
+
readonly fields: [{
|
|
245
|
+
readonly name: "name";
|
|
246
|
+
readonly description: "Segment display name.";
|
|
247
|
+
}, {
|
|
248
|
+
readonly name: "isActive";
|
|
249
|
+
readonly description: "Whether the segment is active.";
|
|
250
|
+
}, {
|
|
251
|
+
readonly name: "isStarred";
|
|
252
|
+
readonly description: "Whether the segment is starred.";
|
|
253
|
+
}, {
|
|
254
|
+
readonly name: "isProcessing";
|
|
255
|
+
readonly description: "Whether the segment is currently recomputing.";
|
|
256
|
+
}, {
|
|
257
|
+
readonly name: "createdAt";
|
|
258
|
+
readonly description: "When the segment was created (Unix ms).";
|
|
259
|
+
}];
|
|
260
|
+
readonly responses: {
|
|
261
|
+
readonly segments: z.ZodObject<{
|
|
262
|
+
data: z.ZodArray<z.ZodObject<{
|
|
263
|
+
type: z.ZodString;
|
|
264
|
+
id: z.ZodString;
|
|
265
|
+
attributes: z.ZodObject<{
|
|
266
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
267
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
268
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
269
|
+
is_active: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
270
|
+
is_starred: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
271
|
+
is_processing: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
272
|
+
}, z.core.$strip>;
|
|
273
|
+
}, z.core.$strip>>;
|
|
274
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
275
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
276
|
+
}, z.core.$strip>>>;
|
|
277
|
+
}, z.core.$strip>;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
readonly klaviyo_campaign: {
|
|
281
|
+
readonly shape: "entity";
|
|
282
|
+
readonly description: "Klaviyo campaigns for the configured channel, with status, archived flag, send strategy, and send time.";
|
|
283
|
+
readonly endpoint: "GET /api/campaigns";
|
|
284
|
+
readonly notes: "Klaviyo requires a channel filter on /campaigns; this connector syncs one channel per instance (the configured `channel` setting).";
|
|
285
|
+
readonly fields: [{
|
|
286
|
+
readonly name: "name";
|
|
287
|
+
readonly description: "Campaign name.";
|
|
288
|
+
}, {
|
|
289
|
+
readonly name: "status";
|
|
290
|
+
readonly description: "Campaign status (Draft, Sent, etc.).";
|
|
291
|
+
}, {
|
|
292
|
+
readonly name: "archived";
|
|
293
|
+
readonly description: "Whether the campaign is archived.";
|
|
294
|
+
}, {
|
|
295
|
+
readonly name: "channel";
|
|
296
|
+
readonly description: "Campaign channel (email, sms, mobile_push).";
|
|
297
|
+
}, {
|
|
298
|
+
readonly name: "sendStrategy";
|
|
299
|
+
readonly description: "Send strategy method (static, smart_send_time, etc.).";
|
|
300
|
+
}, {
|
|
301
|
+
readonly name: "sendTime";
|
|
302
|
+
readonly description: "Scheduled or actual send time (Unix ms).";
|
|
303
|
+
}, {
|
|
304
|
+
readonly name: "createdAt";
|
|
305
|
+
readonly description: "When the campaign was created (Unix ms).";
|
|
306
|
+
}];
|
|
307
|
+
readonly responses: {
|
|
308
|
+
readonly campaigns: z.ZodObject<{
|
|
309
|
+
data: z.ZodArray<z.ZodObject<{
|
|
310
|
+
type: z.ZodString;
|
|
311
|
+
id: z.ZodString;
|
|
312
|
+
attributes: z.ZodObject<{
|
|
313
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
314
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
315
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
316
|
+
channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
317
|
+
send_time: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
318
|
+
scheduled_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
319
|
+
send_strategy: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
320
|
+
method: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
321
|
+
}, z.core.$strip>>>;
|
|
322
|
+
created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
323
|
+
updated_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
324
|
+
}, z.core.$strip>;
|
|
325
|
+
}, z.core.$strip>>;
|
|
326
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
327
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
328
|
+
}, z.core.$strip>>>;
|
|
329
|
+
}, z.core.$strip>;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
readonly klaviyo_flow: {
|
|
333
|
+
readonly shape: "entity";
|
|
334
|
+
readonly description: "Klaviyo flows (automation series) with status, trigger type, and archived flag.";
|
|
335
|
+
readonly endpoint: "GET /api/flows";
|
|
336
|
+
readonly fields: [{
|
|
337
|
+
readonly name: "name";
|
|
338
|
+
readonly description: "Flow name.";
|
|
339
|
+
}, {
|
|
340
|
+
readonly name: "status";
|
|
341
|
+
readonly description: "Flow status (live, draft, manual).";
|
|
342
|
+
}, {
|
|
343
|
+
readonly name: "archived";
|
|
344
|
+
readonly description: "Whether the flow is archived.";
|
|
345
|
+
}, {
|
|
346
|
+
readonly name: "triggerType";
|
|
347
|
+
readonly description: "Flow trigger type (e.g. list, segment, metric).";
|
|
348
|
+
}, {
|
|
349
|
+
readonly name: "createdAt";
|
|
350
|
+
readonly description: "When the flow was created (Unix ms).";
|
|
351
|
+
}];
|
|
352
|
+
readonly responses: {
|
|
353
|
+
readonly flows: z.ZodObject<{
|
|
354
|
+
data: z.ZodArray<z.ZodObject<{
|
|
355
|
+
type: z.ZodString;
|
|
356
|
+
id: z.ZodString;
|
|
357
|
+
attributes: z.ZodObject<{
|
|
358
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
359
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
360
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
361
|
+
trigger_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
362
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
363
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
364
|
+
}, z.core.$strip>;
|
|
365
|
+
}, z.core.$strip>>;
|
|
366
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
367
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
368
|
+
}, z.core.$strip>>>;
|
|
369
|
+
}, z.core.$strip>;
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
static readonly schemas: {
|
|
374
|
+
readonly lists: z.ZodObject<{
|
|
375
|
+
data: z.ZodArray<z.ZodObject<{
|
|
376
|
+
type: z.ZodString;
|
|
377
|
+
id: z.ZodString;
|
|
378
|
+
attributes: z.ZodObject<{
|
|
379
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
380
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
381
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
382
|
+
opt_in_process: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
383
|
+
}, z.core.$strip>;
|
|
384
|
+
}, z.core.$strip>>;
|
|
385
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
386
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
387
|
+
}, z.core.$strip>>>;
|
|
388
|
+
}, z.core.$strip>;
|
|
389
|
+
} & {
|
|
390
|
+
readonly segments: z.ZodObject<{
|
|
391
|
+
data: z.ZodArray<z.ZodObject<{
|
|
392
|
+
type: z.ZodString;
|
|
393
|
+
id: z.ZodString;
|
|
394
|
+
attributes: z.ZodObject<{
|
|
395
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
396
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
397
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
398
|
+
is_active: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
399
|
+
is_starred: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
400
|
+
is_processing: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
401
|
+
}, z.core.$strip>;
|
|
402
|
+
}, z.core.$strip>>;
|
|
403
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
404
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
405
|
+
}, z.core.$strip>>>;
|
|
406
|
+
}, z.core.$strip>;
|
|
407
|
+
} & {
|
|
408
|
+
readonly campaigns: z.ZodObject<{
|
|
409
|
+
data: z.ZodArray<z.ZodObject<{
|
|
410
|
+
type: z.ZodString;
|
|
411
|
+
id: z.ZodString;
|
|
412
|
+
attributes: z.ZodObject<{
|
|
413
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
414
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
415
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
416
|
+
channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
417
|
+
send_time: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
418
|
+
scheduled_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
419
|
+
send_strategy: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
420
|
+
method: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
421
|
+
}, z.core.$strip>>>;
|
|
422
|
+
created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
423
|
+
updated_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
424
|
+
}, z.core.$strip>;
|
|
425
|
+
}, z.core.$strip>>;
|
|
426
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
427
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
428
|
+
}, z.core.$strip>>>;
|
|
429
|
+
}, z.core.$strip>;
|
|
430
|
+
} & {
|
|
431
|
+
readonly flows: z.ZodObject<{
|
|
432
|
+
data: z.ZodArray<z.ZodObject<{
|
|
433
|
+
type: z.ZodString;
|
|
434
|
+
id: z.ZodString;
|
|
435
|
+
attributes: z.ZodObject<{
|
|
436
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
437
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
438
|
+
archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
439
|
+
trigger_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
440
|
+
created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
441
|
+
updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
442
|
+
}, z.core.$strip>;
|
|
443
|
+
}, z.core.$strip>>;
|
|
444
|
+
links: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
445
|
+
next: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
446
|
+
}, z.core.$strip>>>;
|
|
447
|
+
}, z.core.$strip>;
|
|
448
|
+
} & Readonly<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
449
|
+
static create(input: unknown, ctx?: ConnectorContext): KlaviyoConnector;
|
|
450
|
+
readonly id = "klaviyo";
|
|
451
|
+
readonly credentials: {
|
|
452
|
+
apiKey: {
|
|
453
|
+
description: string;
|
|
454
|
+
auth: "required";
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
private buildHeaders;
|
|
458
|
+
private apiGet;
|
|
459
|
+
private allowedPagePath;
|
|
460
|
+
private sanitizePageUrl;
|
|
461
|
+
private resolveCursor;
|
|
462
|
+
private buildInitialUrl;
|
|
463
|
+
private fetchPhasePage;
|
|
464
|
+
private writeLists;
|
|
465
|
+
private writeSegments;
|
|
466
|
+
private writeCampaigns;
|
|
467
|
+
private writeFlows;
|
|
468
|
+
private writePhase;
|
|
469
|
+
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export { type KlaviyoChannel, KlaviyoConnector, type KlaviyoResource, type KlaviyoSettings, configFields, KlaviyoConnector as default, doc, id, klaviyoResources as resources };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
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
|
+
function sanitizeAllowedUrl(options) {
|
|
8
|
+
const { url, host, pathname, protocol = "https:" } = options;
|
|
9
|
+
if (url === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const u = new URL(url);
|
|
14
|
+
if (u.protocol !== protocol || u.host !== host || u.pathname !== pathname) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return u.toString();
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function parseEpoch(value, unit) {
|
|
23
|
+
if (value === null || value === void 0) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (unit === "iso") {
|
|
27
|
+
if (typeof value !== "string") {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const ms = new Date(value).getTime();
|
|
31
|
+
return Number.isFinite(ms) ? ms : null;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
37
|
+
if (!Number.isFinite(n)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const result = unit === "s" ? n * 1e3 : n;
|
|
41
|
+
return Number.isFinite(result) ? result : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/klaviyo.ts
|
|
45
|
+
import {
|
|
46
|
+
BaseConnector,
|
|
47
|
+
defineConfigFields,
|
|
48
|
+
defineConnectorDoc,
|
|
49
|
+
defineResources,
|
|
50
|
+
makeChunkedCursorGuard,
|
|
51
|
+
paginateChunked,
|
|
52
|
+
schemasFromResources,
|
|
53
|
+
selectActivePhases
|
|
54
|
+
} from "@rawdash/core";
|
|
55
|
+
import { z } from "zod";
|
|
56
|
+
var configFields = defineConfigFields(
|
|
57
|
+
z.object({
|
|
58
|
+
apiKey: z.object({ $secret: z.string() }).meta({
|
|
59
|
+
label: "Private API Key",
|
|
60
|
+
description: "Klaviyo Private API Key with read scopes for campaigns, flows, lists, and segments. Create one at Klaviyo -> Settings -> API Keys.",
|
|
61
|
+
placeholder: "pk_...",
|
|
62
|
+
secret: true
|
|
63
|
+
}),
|
|
64
|
+
apiRevision: z.string().trim().regex(
|
|
65
|
+
/^\d{4}-\d{2}-\d{2}(\.pre)?$/,
|
|
66
|
+
'Use a Klaviyo API revision date like "2024-10-15".'
|
|
67
|
+
).default("2024-10-15").meta({
|
|
68
|
+
label: "API revision",
|
|
69
|
+
description: "Value sent in the revision header. Defaults to 2024-10-15; pin a specific date here when upgrading deliberately.",
|
|
70
|
+
placeholder: "2024-10-15"
|
|
71
|
+
}),
|
|
72
|
+
channel: z.enum(["email", "sms", "mobile_push"]).default("email").meta({
|
|
73
|
+
label: "Campaign channel",
|
|
74
|
+
description: "Which campaign channel to sync. The Klaviyo campaigns endpoint requires a channel filter and only returns one channel per call; defaults to 'email'.",
|
|
75
|
+
placeholder: "email"
|
|
76
|
+
}),
|
|
77
|
+
resources: z.array(z.enum(["lists", "segments", "campaigns", "flows"])).nonempty().optional().meta({
|
|
78
|
+
label: "Resources",
|
|
79
|
+
description: "Which Klaviyo resources to sync. Omit to sync all of them. The key only needs read scopes for the resources listed here."
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
var doc = defineConnectorDoc({
|
|
84
|
+
displayName: "Klaviyo",
|
|
85
|
+
category: "marketing",
|
|
86
|
+
brandColor: "#000000",
|
|
87
|
+
tagline: "Sync campaigns, flows, lists, and segments from Klaviyo for ecommerce email and SMS marketing analytics.",
|
|
88
|
+
vendor: {
|
|
89
|
+
name: "Klaviyo",
|
|
90
|
+
apiDocs: "https://developers.klaviyo.com/en/reference/api_overview",
|
|
91
|
+
website: "https://www.klaviyo.com"
|
|
92
|
+
},
|
|
93
|
+
auth: {
|
|
94
|
+
summary: "A Klaviyo Private API Key with read access to campaigns, flows, lists, and segments.",
|
|
95
|
+
setup: [
|
|
96
|
+
"Open Klaviyo -> Settings -> API Keys and create a new Private API Key.",
|
|
97
|
+
"Grant read access to Campaigns, Flows, Lists, and Segments (or only the scopes you intend to sync).",
|
|
98
|
+
'Copy the generated key and store it as a secret, referencing it from the connector config as `apiKey: secret("KLAVIYO_API_KEY")`.'
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
rateLimit: "Klaviyo enforces per-endpoint burst and steady rate limits and signals them via the RateLimit-Remaining and RateLimit-Reset response headers. The shared HTTP client backs off on 429 and honors Retry-After.",
|
|
102
|
+
limitations: [
|
|
103
|
+
"Campaign and flow statistics (campaign-values-reports / flow-values-reports) are not synced; the reports endpoints require a per-account conversion metric id and are deferred to a follow-up.",
|
|
104
|
+
"Profile, event, catalog, and coupon objects are out of scope (niche for dashboard use).",
|
|
105
|
+
"Only one campaign channel per sync (email, sms, or mobile_push) - the Klaviyo campaigns endpoint requires the filter and does not allow OR across channels."
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
var klaviyoCredentials = {
|
|
109
|
+
apiKey: {
|
|
110
|
+
description: "Klaviyo Private API Key",
|
|
111
|
+
auth: "required"
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var PHASE_ORDER = ["lists", "segments", "campaigns", "flows"];
|
|
115
|
+
var isKlaviyoSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);
|
|
116
|
+
var KLAVIYO_API_HOST = "a.klaviyo.com";
|
|
117
|
+
var KLAVIYO_API_BASE = `https://${KLAVIYO_API_HOST}/api`;
|
|
118
|
+
var PAGE_SIZE = 100;
|
|
119
|
+
var LIST_ENTITY = "klaviyo_list";
|
|
120
|
+
var SEGMENT_ENTITY = "klaviyo_segment";
|
|
121
|
+
var CAMPAIGN_ENTITY = "klaviyo_campaign";
|
|
122
|
+
var FLOW_ENTITY = "klaviyo_flow";
|
|
123
|
+
var ENTITY_TYPE_BY_PHASE = {
|
|
124
|
+
lists: LIST_ENTITY,
|
|
125
|
+
segments: SEGMENT_ENTITY,
|
|
126
|
+
campaigns: CAMPAIGN_ENTITY,
|
|
127
|
+
flows: FLOW_ENTITY
|
|
128
|
+
};
|
|
129
|
+
var UPDATED_FIELD_BY_PHASE = {
|
|
130
|
+
lists: "updated",
|
|
131
|
+
segments: "updated",
|
|
132
|
+
campaigns: "updated_at",
|
|
133
|
+
flows: "updated"
|
|
134
|
+
};
|
|
135
|
+
var idString = z.string().min(1);
|
|
136
|
+
function jsonApiList(attributes) {
|
|
137
|
+
return z.object({
|
|
138
|
+
data: z.array(
|
|
139
|
+
z.object({
|
|
140
|
+
type: z.string(),
|
|
141
|
+
id: idString,
|
|
142
|
+
attributes
|
|
143
|
+
})
|
|
144
|
+
),
|
|
145
|
+
links: z.object({ next: z.string().nullish() }).nullish()
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
var listsResponseSchema = jsonApiList(
|
|
149
|
+
z.object({
|
|
150
|
+
name: z.string().nullish(),
|
|
151
|
+
created: z.string().nullish(),
|
|
152
|
+
updated: z.string().nullish(),
|
|
153
|
+
opt_in_process: z.string().nullish()
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
var segmentsResponseSchema = jsonApiList(
|
|
157
|
+
z.object({
|
|
158
|
+
name: z.string().nullish(),
|
|
159
|
+
created: z.string().nullish(),
|
|
160
|
+
updated: z.string().nullish(),
|
|
161
|
+
is_active: z.boolean().nullish(),
|
|
162
|
+
is_starred: z.boolean().nullish(),
|
|
163
|
+
is_processing: z.boolean().nullish()
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
var campaignsResponseSchema = jsonApiList(
|
|
167
|
+
z.object({
|
|
168
|
+
name: z.string().nullish(),
|
|
169
|
+
status: z.string().nullish(),
|
|
170
|
+
archived: z.boolean().nullish(),
|
|
171
|
+
channel: z.string().nullish(),
|
|
172
|
+
send_time: z.string().nullish(),
|
|
173
|
+
scheduled_at: z.string().nullish(),
|
|
174
|
+
send_strategy: z.object({ method: z.string().nullish() }).nullish(),
|
|
175
|
+
created_at: z.string().nullish(),
|
|
176
|
+
updated_at: z.string().nullish()
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
var flowsResponseSchema = jsonApiList(
|
|
180
|
+
z.object({
|
|
181
|
+
name: z.string().nullish(),
|
|
182
|
+
status: z.string().nullish(),
|
|
183
|
+
archived: z.boolean().nullish(),
|
|
184
|
+
trigger_type: z.string().nullish(),
|
|
185
|
+
created: z.string().nullish(),
|
|
186
|
+
updated: z.string().nullish()
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
var klaviyoResources = defineResources({
|
|
190
|
+
[LIST_ENTITY]: {
|
|
191
|
+
shape: "entity",
|
|
192
|
+
description: "Klaviyo lists (manually managed subscriber collections) with opt-in process and created/updated timestamps.",
|
|
193
|
+
endpoint: "GET /api/lists",
|
|
194
|
+
fields: [
|
|
195
|
+
{ name: "name", description: "List display name." },
|
|
196
|
+
{
|
|
197
|
+
name: "optInProcess",
|
|
198
|
+
description: "Opt-in process (e.g. single_opt_in, double_opt_in)."
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "createdAt",
|
|
202
|
+
description: "When the list was created (Unix ms)."
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
responses: { lists: listsResponseSchema }
|
|
206
|
+
},
|
|
207
|
+
[SEGMENT_ENTITY]: {
|
|
208
|
+
shape: "entity",
|
|
209
|
+
description: "Klaviyo segments (rule-based dynamic groups) with active, starred, and processing flags.",
|
|
210
|
+
endpoint: "GET /api/segments",
|
|
211
|
+
fields: [
|
|
212
|
+
{ name: "name", description: "Segment display name." },
|
|
213
|
+
{ name: "isActive", description: "Whether the segment is active." },
|
|
214
|
+
{ name: "isStarred", description: "Whether the segment is starred." },
|
|
215
|
+
{
|
|
216
|
+
name: "isProcessing",
|
|
217
|
+
description: "Whether the segment is currently recomputing."
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "createdAt",
|
|
221
|
+
description: "When the segment was created (Unix ms)."
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
responses: { segments: segmentsResponseSchema }
|
|
225
|
+
},
|
|
226
|
+
[CAMPAIGN_ENTITY]: {
|
|
227
|
+
shape: "entity",
|
|
228
|
+
description: "Klaviyo campaigns for the configured channel, with status, archived flag, send strategy, and send time.",
|
|
229
|
+
endpoint: "GET /api/campaigns",
|
|
230
|
+
notes: "Klaviyo requires a channel filter on /campaigns; this connector syncs one channel per instance (the configured `channel` setting).",
|
|
231
|
+
fields: [
|
|
232
|
+
{ name: "name", description: "Campaign name." },
|
|
233
|
+
{ name: "status", description: "Campaign status (Draft, Sent, etc.)." },
|
|
234
|
+
{ name: "archived", description: "Whether the campaign is archived." },
|
|
235
|
+
{
|
|
236
|
+
name: "channel",
|
|
237
|
+
description: "Campaign channel (email, sms, mobile_push)."
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "sendStrategy",
|
|
241
|
+
description: "Send strategy method (static, smart_send_time, etc.)."
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "sendTime",
|
|
245
|
+
description: "Scheduled or actual send time (Unix ms)."
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "createdAt",
|
|
249
|
+
description: "When the campaign was created (Unix ms)."
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
responses: { campaigns: campaignsResponseSchema }
|
|
253
|
+
},
|
|
254
|
+
[FLOW_ENTITY]: {
|
|
255
|
+
shape: "entity",
|
|
256
|
+
description: "Klaviyo flows (automation series) with status, trigger type, and archived flag.",
|
|
257
|
+
endpoint: "GET /api/flows",
|
|
258
|
+
fields: [
|
|
259
|
+
{ name: "name", description: "Flow name." },
|
|
260
|
+
{ name: "status", description: "Flow status (live, draft, manual)." },
|
|
261
|
+
{ name: "archived", description: "Whether the flow is archived." },
|
|
262
|
+
{
|
|
263
|
+
name: "triggerType",
|
|
264
|
+
description: "Flow trigger type (e.g. list, segment, metric)."
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: "createdAt",
|
|
268
|
+
description: "When the flow was created (Unix ms)."
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
responses: { flows: flowsResponseSchema }
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
var id = "klaviyo";
|
|
275
|
+
var KlaviyoConnector = class _KlaviyoConnector extends BaseConnector {
|
|
276
|
+
static id = id;
|
|
277
|
+
static resources = klaviyoResources;
|
|
278
|
+
static schemas = schemasFromResources(klaviyoResources);
|
|
279
|
+
static create(input, ctx) {
|
|
280
|
+
const parsed = configFields.parse(input);
|
|
281
|
+
return new _KlaviyoConnector(
|
|
282
|
+
{
|
|
283
|
+
apiRevision: parsed.apiRevision,
|
|
284
|
+
channel: parsed.channel,
|
|
285
|
+
resources: parsed.resources
|
|
286
|
+
},
|
|
287
|
+
{ apiKey: parsed.apiKey },
|
|
288
|
+
ctx
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
id = id;
|
|
292
|
+
credentials = klaviyoCredentials;
|
|
293
|
+
buildHeaders() {
|
|
294
|
+
return {
|
|
295
|
+
Authorization: `Klaviyo-API-Key ${this.creds.apiKey}`,
|
|
296
|
+
revision: this.settings.apiRevision,
|
|
297
|
+
Accept: "application/vnd.api+json",
|
|
298
|
+
"User-Agent": connectorUserAgent("klaviyo")
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
apiGet(url, resource, signal) {
|
|
302
|
+
return this.get(url, {
|
|
303
|
+
resource,
|
|
304
|
+
headers: this.buildHeaders(),
|
|
305
|
+
signal
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
// -------------------------------------------------------------------------
|
|
309
|
+
// URL building + sanitization
|
|
310
|
+
// -------------------------------------------------------------------------
|
|
311
|
+
allowedPagePath(phase) {
|
|
312
|
+
switch (phase) {
|
|
313
|
+
case "lists":
|
|
314
|
+
return "/api/lists";
|
|
315
|
+
case "segments":
|
|
316
|
+
return "/api/segments";
|
|
317
|
+
case "campaigns":
|
|
318
|
+
return "/api/campaigns";
|
|
319
|
+
case "flows":
|
|
320
|
+
return "/api/flows";
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
sanitizePageUrl(phase, pageUrl) {
|
|
324
|
+
return sanitizeAllowedUrl({
|
|
325
|
+
url: pageUrl,
|
|
326
|
+
host: KLAVIYO_API_HOST,
|
|
327
|
+
pathname: this.allowedPagePath(phase)
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
resolveCursor(cursor) {
|
|
331
|
+
if (!isKlaviyoSyncCursor(cursor)) {
|
|
332
|
+
return void 0;
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
phase: cursor.phase,
|
|
336
|
+
page: this.sanitizePageUrl(cursor.phase, cursor.page)
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
buildInitialUrl(phase, options) {
|
|
340
|
+
const u = new URL(`${KLAVIYO_API_BASE}${this.allowedPagePath(phase)}`);
|
|
341
|
+
u.searchParams.set("page[size]", String(PAGE_SIZE));
|
|
342
|
+
u.searchParams.set("sort", UPDATED_FIELD_BY_PHASE[phase]);
|
|
343
|
+
const filters = [];
|
|
344
|
+
if (phase === "campaigns") {
|
|
345
|
+
filters.push(`equals(messages.channel,'${this.settings.channel}')`);
|
|
346
|
+
}
|
|
347
|
+
if (options.since) {
|
|
348
|
+
const date = new Date(options.since);
|
|
349
|
+
if (Number.isFinite(date.getTime())) {
|
|
350
|
+
filters.push(
|
|
351
|
+
`greater-than(${UPDATED_FIELD_BY_PHASE[phase]},${date.toISOString()})`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (filters.length > 0) {
|
|
356
|
+
u.searchParams.set("filter", filters.join(","));
|
|
357
|
+
}
|
|
358
|
+
return u.toString();
|
|
359
|
+
}
|
|
360
|
+
// -------------------------------------------------------------------------
|
|
361
|
+
// Fetchers
|
|
362
|
+
// -------------------------------------------------------------------------
|
|
363
|
+
async fetchPhasePage(phase, page, options, signal) {
|
|
364
|
+
const url = page ?? this.buildInitialUrl(phase, options);
|
|
365
|
+
const res = await this.apiGet(url, phase, signal);
|
|
366
|
+
const nextRaw = res.body.links?.next ?? null;
|
|
367
|
+
const next = nextRaw ? this.sanitizePageUrl(phase, nextRaw) : null;
|
|
368
|
+
return { items: res.body.data ?? [], next };
|
|
369
|
+
}
|
|
370
|
+
// -------------------------------------------------------------------------
|
|
371
|
+
// Writers
|
|
372
|
+
// -------------------------------------------------------------------------
|
|
373
|
+
async writeLists(storage, items) {
|
|
374
|
+
for (const item of items) {
|
|
375
|
+
const attrs = item.attributes ?? {};
|
|
376
|
+
const createdMs = parseEpoch(attrs.created ?? null, "iso");
|
|
377
|
+
const updatedMs = parseEpoch(attrs.updated ?? null, "iso");
|
|
378
|
+
await storage.entity({
|
|
379
|
+
type: LIST_ENTITY,
|
|
380
|
+
id: item.id,
|
|
381
|
+
attributes: {
|
|
382
|
+
name: attrs.name ?? null,
|
|
383
|
+
optInProcess: attrs.opt_in_process ?? null,
|
|
384
|
+
createdAt: createdMs
|
|
385
|
+
},
|
|
386
|
+
updated_at: updatedMs ?? createdMs ?? 0
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
async writeSegments(storage, items) {
|
|
391
|
+
for (const item of items) {
|
|
392
|
+
const attrs = item.attributes ?? {};
|
|
393
|
+
const createdMs = parseEpoch(attrs.created ?? null, "iso");
|
|
394
|
+
const updatedMs = parseEpoch(attrs.updated ?? null, "iso");
|
|
395
|
+
await storage.entity({
|
|
396
|
+
type: SEGMENT_ENTITY,
|
|
397
|
+
id: item.id,
|
|
398
|
+
attributes: {
|
|
399
|
+
name: attrs.name ?? null,
|
|
400
|
+
isActive: attrs.is_active ?? null,
|
|
401
|
+
isStarred: attrs.is_starred ?? null,
|
|
402
|
+
isProcessing: attrs.is_processing ?? null,
|
|
403
|
+
createdAt: createdMs
|
|
404
|
+
},
|
|
405
|
+
updated_at: updatedMs ?? createdMs ?? 0
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async writeCampaigns(storage, items) {
|
|
410
|
+
for (const item of items) {
|
|
411
|
+
const attrs = item.attributes ?? {};
|
|
412
|
+
const createdMs = parseEpoch(attrs.created_at ?? null, "iso");
|
|
413
|
+
const updatedMs = parseEpoch(attrs.updated_at ?? null, "iso");
|
|
414
|
+
const sendTimeMs = parseEpoch(
|
|
415
|
+
attrs.send_time ?? attrs.scheduled_at ?? null,
|
|
416
|
+
"iso"
|
|
417
|
+
);
|
|
418
|
+
await storage.entity({
|
|
419
|
+
type: CAMPAIGN_ENTITY,
|
|
420
|
+
id: item.id,
|
|
421
|
+
attributes: {
|
|
422
|
+
name: attrs.name ?? null,
|
|
423
|
+
status: attrs.status ?? null,
|
|
424
|
+
archived: attrs.archived ?? null,
|
|
425
|
+
channel: attrs.channel ?? this.settings.channel,
|
|
426
|
+
sendStrategy: attrs.send_strategy?.method ?? null,
|
|
427
|
+
sendTime: sendTimeMs,
|
|
428
|
+
createdAt: createdMs
|
|
429
|
+
},
|
|
430
|
+
updated_at: updatedMs ?? createdMs ?? 0
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async writeFlows(storage, items) {
|
|
435
|
+
for (const item of items) {
|
|
436
|
+
const attrs = item.attributes ?? {};
|
|
437
|
+
const createdMs = parseEpoch(attrs.created ?? null, "iso");
|
|
438
|
+
const updatedMs = parseEpoch(attrs.updated ?? null, "iso");
|
|
439
|
+
await storage.entity({
|
|
440
|
+
type: FLOW_ENTITY,
|
|
441
|
+
id: item.id,
|
|
442
|
+
attributes: {
|
|
443
|
+
name: attrs.name ?? null,
|
|
444
|
+
status: attrs.status ?? null,
|
|
445
|
+
archived: attrs.archived ?? null,
|
|
446
|
+
triggerType: attrs.trigger_type ?? null,
|
|
447
|
+
createdAt: createdMs
|
|
448
|
+
},
|
|
449
|
+
updated_at: updatedMs ?? createdMs ?? 0
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async writePhase(storage, phase, items) {
|
|
454
|
+
switch (phase) {
|
|
455
|
+
case "lists":
|
|
456
|
+
return this.writeLists(
|
|
457
|
+
storage,
|
|
458
|
+
items
|
|
459
|
+
);
|
|
460
|
+
case "segments":
|
|
461
|
+
return this.writeSegments(
|
|
462
|
+
storage,
|
|
463
|
+
items
|
|
464
|
+
);
|
|
465
|
+
case "campaigns":
|
|
466
|
+
return this.writeCampaigns(
|
|
467
|
+
storage,
|
|
468
|
+
items
|
|
469
|
+
);
|
|
470
|
+
case "flows":
|
|
471
|
+
return this.writeFlows(
|
|
472
|
+
storage,
|
|
473
|
+
items
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
async sync(options, storage, signal) {
|
|
478
|
+
const cursor = this.resolveCursor(options.cursor);
|
|
479
|
+
const isFull = options.mode === "full";
|
|
480
|
+
const phases = selectActivePhases(
|
|
481
|
+
(r) => r,
|
|
482
|
+
PHASE_ORDER,
|
|
483
|
+
this.settings.resources
|
|
484
|
+
);
|
|
485
|
+
return paginateChunked({
|
|
486
|
+
phases,
|
|
487
|
+
cursor,
|
|
488
|
+
signal,
|
|
489
|
+
logger: this.logger,
|
|
490
|
+
fetchPage: async (phase, page, sig) => this.fetchPhasePage(phase, page, options, sig),
|
|
491
|
+
writeBatch: async (phase, items, page) => {
|
|
492
|
+
if (isFull && page === null) {
|
|
493
|
+
await storage.entities([], { types: [ENTITY_TYPE_BY_PHASE[phase]] });
|
|
494
|
+
}
|
|
495
|
+
await this.writePhase(storage, phase, items);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/index.ts
|
|
502
|
+
var index_default = KlaviyoConnector;
|
|
503
|
+
export {
|
|
504
|
+
KlaviyoConnector,
|
|
505
|
+
configFields,
|
|
506
|
+
index_default as default,
|
|
507
|
+
doc,
|
|
508
|
+
id,
|
|
509
|
+
klaviyoResources as resources
|
|
510
|
+
};
|
|
511
|
+
//# 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/sanitize.ts","../../../connector-shared/src/epoch.ts","../../../connector-shared/src/pagination.ts","../../../connector-shared/src/logger.ts","../src/klaviyo.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 parseEpoch,\n sanitizeAllowedUrl,\n} from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ChunkedSyncCursor,\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\n// ---------------------------------------------------------------------------\n// configFields\n// ---------------------------------------------------------------------------\n\nexport const configFields = defineConfigFields(\n z.object({\n apiKey: z.object({ $secret: z.string() }).meta({\n label: 'Private API Key',\n description:\n 'Klaviyo Private API Key with read scopes for campaigns, flows, lists, and segments. Create one at Klaviyo -> Settings -> API Keys.',\n placeholder: 'pk_...',\n secret: true,\n }),\n apiRevision: z\n .string()\n .trim()\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}(\\.pre)?$/,\n 'Use a Klaviyo API revision date like \"2024-10-15\".',\n )\n .default('2024-10-15')\n .meta({\n label: 'API revision',\n description:\n 'Value sent in the revision header. Defaults to 2024-10-15; pin a specific date here when upgrading deliberately.',\n placeholder: '2024-10-15',\n }),\n channel: z.enum(['email', 'sms', 'mobile_push']).default('email').meta({\n label: 'Campaign channel',\n description:\n \"Which campaign channel to sync. The Klaviyo campaigns endpoint requires a channel filter and only returns one channel per call; defaults to 'email'.\",\n placeholder: 'email',\n }),\n resources: z\n .array(z.enum(['lists', 'segments', 'campaigns', 'flows']))\n .nonempty()\n .optional()\n .meta({\n label: 'Resources',\n description:\n 'Which Klaviyo resources to sync. Omit to sync all of them. The key only needs read scopes for the resources listed here.',\n }),\n }),\n);\n\n// ---------------------------------------------------------------------------\n// Connector doc (catalog metadata)\n// ---------------------------------------------------------------------------\n\nexport const doc: ConnectorDoc = defineConnectorDoc({\n displayName: 'Klaviyo',\n category: 'marketing',\n brandColor: '#000000',\n tagline:\n 'Sync campaigns, flows, lists, and segments from Klaviyo for ecommerce email and SMS marketing analytics.',\n vendor: {\n name: 'Klaviyo',\n apiDocs: 'https://developers.klaviyo.com/en/reference/api_overview',\n website: 'https://www.klaviyo.com',\n },\n auth: {\n summary:\n 'A Klaviyo Private API Key with read access to campaigns, flows, lists, and segments.',\n setup: [\n 'Open Klaviyo -> Settings -> API Keys and create a new Private API Key.',\n 'Grant read access to Campaigns, Flows, Lists, and Segments (or only the scopes you intend to sync).',\n 'Copy the generated key and store it as a secret, referencing it from the connector config as `apiKey: secret(\"KLAVIYO_API_KEY\")`.',\n ],\n },\n rateLimit:\n 'Klaviyo enforces per-endpoint burst and steady rate limits and signals them via the RateLimit-Remaining and RateLimit-Reset response headers. The shared HTTP client backs off on 429 and honors Retry-After.',\n limitations: [\n 'Campaign and flow statistics (campaign-values-reports / flow-values-reports) are not synced; the reports endpoints require a per-account conversion metric id and are deferred to a follow-up.',\n 'Profile, event, catalog, and coupon objects are out of scope (niche for dashboard use).',\n 'Only one campaign channel per sync (email, sms, or mobile_push) - the Klaviyo campaigns endpoint requires the filter and does not allow OR across channels.',\n ],\n});\n\n// ---------------------------------------------------------------------------\n// Settings / credentials\n// ---------------------------------------------------------------------------\n\nexport type KlaviyoChannel = 'email' | 'sms' | 'mobile_push';\n\nexport interface KlaviyoSettings {\n apiRevision: string;\n channel: KlaviyoChannel;\n resources?: readonly KlaviyoResource[];\n}\n\nconst klaviyoCredentials = {\n apiKey: {\n description: 'Klaviyo Private API Key',\n auth: 'required' as const,\n },\n} satisfies CredentialsSchema;\n\ntype KlaviyoCredentials = typeof klaviyoCredentials;\n\n// ---------------------------------------------------------------------------\n// Sync phases + cursor\n// ---------------------------------------------------------------------------\n\nconst PHASE_ORDER = ['lists', 'segments', 'campaigns', 'flows'] as const;\n\ntype KlaviyoPhase = (typeof PHASE_ORDER)[number];\n\nexport type KlaviyoResource = KlaviyoPhase;\n\ntype KlaviyoSyncCursor = ChunkedSyncCursor<KlaviyoPhase, string>;\n\nconst isKlaviyoSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);\n\nconst KLAVIYO_API_HOST = 'a.klaviyo.com';\nconst KLAVIYO_API_BASE = `https://${KLAVIYO_API_HOST}/api`;\nconst PAGE_SIZE = 100;\n\nconst LIST_ENTITY = 'klaviyo_list';\nconst SEGMENT_ENTITY = 'klaviyo_segment';\nconst CAMPAIGN_ENTITY = 'klaviyo_campaign';\nconst FLOW_ENTITY = 'klaviyo_flow';\n\nconst ENTITY_TYPE_BY_PHASE: Record<KlaviyoPhase, string> = {\n lists: LIST_ENTITY,\n segments: SEGMENT_ENTITY,\n campaigns: CAMPAIGN_ENTITY,\n flows: FLOW_ENTITY,\n};\n\n// Klaviyo's `updated` (lists/segments/flows) and `updated_at` (campaigns)\n// filter fields differ per endpoint.\nconst UPDATED_FIELD_BY_PHASE: Record<KlaviyoPhase, string> = {\n lists: 'updated',\n segments: 'updated',\n campaigns: 'updated_at',\n flows: 'updated',\n};\n\n// ---------------------------------------------------------------------------\n// API response types (JSON:API)\n// ---------------------------------------------------------------------------\n\ninterface JsonApiResource<TAttrs> {\n type: string;\n id: string;\n attributes: TAttrs;\n}\n\ninterface JsonApiList<TAttrs> {\n data: Array<JsonApiResource<TAttrs>>;\n links?: { next?: string | null } | null;\n}\n\ninterface ListAttributes {\n name?: string | null;\n created?: string | null;\n updated?: string | null;\n opt_in_process?: string | null;\n}\n\ninterface SegmentAttributes {\n name?: string | null;\n created?: string | null;\n updated?: string | null;\n is_active?: boolean | null;\n is_starred?: boolean | null;\n is_processing?: boolean | null;\n}\n\ninterface CampaignAttributes {\n name?: string | null;\n status?: string | null;\n archived?: boolean | null;\n channel?: string | null;\n send_time?: string | null;\n scheduled_at?: string | null;\n send_strategy?: { method?: string | null } | null;\n created_at?: string | null;\n updated_at?: string | null;\n}\n\ninterface FlowAttributes {\n name?: string | null;\n status?: string | null;\n archived?: boolean | null;\n trigger_type?: string | null;\n created?: string | null;\n updated?: string | null;\n}\n\n// ---------------------------------------------------------------------------\n// Schemas\n// ---------------------------------------------------------------------------\n\nconst idString = z.string().min(1);\n\nfunction jsonApiList<T extends z.ZodTypeAny>(attributes: T) {\n return z.object({\n data: z.array(\n z.object({\n type: z.string(),\n id: idString,\n attributes,\n }),\n ),\n links: z.object({ next: z.string().nullish() }).nullish(),\n });\n}\n\nconst listsResponseSchema = jsonApiList(\n z.object({\n name: z.string().nullish(),\n created: z.string().nullish(),\n updated: z.string().nullish(),\n opt_in_process: z.string().nullish(),\n }),\n);\n\nconst segmentsResponseSchema = jsonApiList(\n z.object({\n name: z.string().nullish(),\n created: z.string().nullish(),\n updated: z.string().nullish(),\n is_active: z.boolean().nullish(),\n is_starred: z.boolean().nullish(),\n is_processing: z.boolean().nullish(),\n }),\n);\n\nconst campaignsResponseSchema = jsonApiList(\n z.object({\n name: z.string().nullish(),\n status: z.string().nullish(),\n archived: z.boolean().nullish(),\n channel: z.string().nullish(),\n send_time: z.string().nullish(),\n scheduled_at: z.string().nullish(),\n send_strategy: z.object({ method: z.string().nullish() }).nullish(),\n created_at: z.string().nullish(),\n updated_at: z.string().nullish(),\n }),\n);\n\nconst flowsResponseSchema = jsonApiList(\n z.object({\n name: z.string().nullish(),\n status: z.string().nullish(),\n archived: z.boolean().nullish(),\n trigger_type: z.string().nullish(),\n created: z.string().nullish(),\n updated: z.string().nullish(),\n }),\n);\n\n// ---------------------------------------------------------------------------\n// Resources\n// ---------------------------------------------------------------------------\n\nexport const klaviyoResources = defineResources({\n [LIST_ENTITY]: {\n shape: 'entity',\n description:\n 'Klaviyo lists (manually managed subscriber collections) with opt-in process and created/updated timestamps.',\n endpoint: 'GET /api/lists',\n fields: [\n { name: 'name', description: 'List display name.' },\n {\n name: 'optInProcess',\n description: 'Opt-in process (e.g. single_opt_in, double_opt_in).',\n },\n {\n name: 'createdAt',\n description: 'When the list was created (Unix ms).',\n },\n ],\n responses: { lists: listsResponseSchema },\n },\n [SEGMENT_ENTITY]: {\n shape: 'entity',\n description:\n 'Klaviyo segments (rule-based dynamic groups) with active, starred, and processing flags.',\n endpoint: 'GET /api/segments',\n fields: [\n { name: 'name', description: 'Segment display name.' },\n { name: 'isActive', description: 'Whether the segment is active.' },\n { name: 'isStarred', description: 'Whether the segment is starred.' },\n {\n name: 'isProcessing',\n description: 'Whether the segment is currently recomputing.',\n },\n {\n name: 'createdAt',\n description: 'When the segment was created (Unix ms).',\n },\n ],\n responses: { segments: segmentsResponseSchema },\n },\n [CAMPAIGN_ENTITY]: {\n shape: 'entity',\n description:\n 'Klaviyo campaigns for the configured channel, with status, archived flag, send strategy, and send time.',\n endpoint: 'GET /api/campaigns',\n notes:\n 'Klaviyo requires a channel filter on /campaigns; this connector syncs one channel per instance (the configured `channel` setting).',\n fields: [\n { name: 'name', description: 'Campaign name.' },\n { name: 'status', description: 'Campaign status (Draft, Sent, etc.).' },\n { name: 'archived', description: 'Whether the campaign is archived.' },\n {\n name: 'channel',\n description: 'Campaign channel (email, sms, mobile_push).',\n },\n {\n name: 'sendStrategy',\n description: 'Send strategy method (static, smart_send_time, etc.).',\n },\n {\n name: 'sendTime',\n description: 'Scheduled or actual send time (Unix ms).',\n },\n {\n name: 'createdAt',\n description: 'When the campaign was created (Unix ms).',\n },\n ],\n responses: { campaigns: campaignsResponseSchema },\n },\n [FLOW_ENTITY]: {\n shape: 'entity',\n description:\n 'Klaviyo flows (automation series) with status, trigger type, and archived flag.',\n endpoint: 'GET /api/flows',\n fields: [\n { name: 'name', description: 'Flow name.' },\n { name: 'status', description: 'Flow status (live, draft, manual).' },\n { name: 'archived', description: 'Whether the flow is archived.' },\n {\n name: 'triggerType',\n description: 'Flow trigger type (e.g. list, segment, metric).',\n },\n {\n name: 'createdAt',\n description: 'When the flow was created (Unix ms).',\n },\n ],\n responses: { flows: flowsResponseSchema },\n },\n});\n\n// ---------------------------------------------------------------------------\n// KlaviyoConnector\n// ---------------------------------------------------------------------------\n\nexport const id = 'klaviyo';\n\nexport class KlaviyoConnector extends BaseConnector<\n KlaviyoSettings,\n KlaviyoCredentials\n> {\n static readonly id = id;\n\n static readonly resources = klaviyoResources;\n\n static readonly schemas = schemasFromResources(klaviyoResources);\n\n static create(input: unknown, ctx?: ConnectorContext): KlaviyoConnector {\n const parsed = configFields.parse(input);\n return new KlaviyoConnector(\n {\n apiRevision: parsed.apiRevision,\n channel: parsed.channel,\n resources: parsed.resources,\n },\n { apiKey: parsed.apiKey },\n ctx,\n );\n }\n\n readonly id = id;\n override readonly credentials = klaviyoCredentials;\n\n private buildHeaders(): Record<string, string> {\n return {\n Authorization: `Klaviyo-API-Key ${this.creds.apiKey}`,\n revision: this.settings.apiRevision,\n Accept: 'application/vnd.api+json',\n 'User-Agent': connectorUserAgent('klaviyo'),\n };\n }\n\n private apiGet<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 // -------------------------------------------------------------------------\n // URL building + sanitization\n // -------------------------------------------------------------------------\n\n private allowedPagePath(phase: KlaviyoPhase): string {\n switch (phase) {\n case 'lists':\n return '/api/lists';\n case 'segments':\n return '/api/segments';\n case 'campaigns':\n return '/api/campaigns';\n case 'flows':\n return '/api/flows';\n }\n }\n\n private sanitizePageUrl(\n phase: KlaviyoPhase,\n pageUrl: string | null,\n ): string | null {\n return sanitizeAllowedUrl({\n url: pageUrl,\n host: KLAVIYO_API_HOST,\n pathname: this.allowedPagePath(phase),\n });\n }\n\n private resolveCursor(cursor: unknown): KlaviyoSyncCursor | undefined {\n if (!isKlaviyoSyncCursor(cursor)) {\n return undefined;\n }\n return {\n phase: cursor.phase,\n page: this.sanitizePageUrl(cursor.phase, cursor.page),\n };\n }\n\n private buildInitialUrl(phase: KlaviyoPhase, options: SyncOptions): string {\n const u = new URL(`${KLAVIYO_API_BASE}${this.allowedPagePath(phase)}`);\n u.searchParams.set('page[size]', String(PAGE_SIZE));\n u.searchParams.set('sort', UPDATED_FIELD_BY_PHASE[phase]);\n const filters: string[] = [];\n if (phase === 'campaigns') {\n filters.push(`equals(messages.channel,'${this.settings.channel}')`);\n }\n if (options.since) {\n const date = new Date(options.since);\n if (Number.isFinite(date.getTime())) {\n filters.push(\n `greater-than(${UPDATED_FIELD_BY_PHASE[phase]},${date.toISOString()})`,\n );\n }\n }\n if (filters.length > 0) {\n u.searchParams.set('filter', filters.join(','));\n }\n return u.toString();\n }\n\n // -------------------------------------------------------------------------\n // Fetchers\n // -------------------------------------------------------------------------\n\n private async fetchPhasePage<TAttrs>(\n phase: KlaviyoPhase,\n page: string | null,\n options: SyncOptions,\n signal?: AbortSignal,\n ): Promise<{\n items: Array<JsonApiResource<TAttrs>>;\n next: string | null;\n }> {\n const url = page ?? this.buildInitialUrl(phase, options);\n const res = await this.apiGet<JsonApiList<TAttrs>>(url, phase, signal);\n const nextRaw = res.body.links?.next ?? null;\n const next = nextRaw ? this.sanitizePageUrl(phase, nextRaw) : null;\n return { items: res.body.data ?? [], next };\n }\n\n // -------------------------------------------------------------------------\n // Writers\n // -------------------------------------------------------------------------\n\n private async writeLists(\n storage: StorageHandle,\n items: Array<JsonApiResource<ListAttributes>>,\n ): Promise<void> {\n for (const item of items) {\n const attrs = item.attributes ?? ({} as ListAttributes);\n const createdMs = parseEpoch(attrs.created ?? null, 'iso');\n const updatedMs = parseEpoch(attrs.updated ?? null, 'iso');\n await storage.entity({\n type: LIST_ENTITY,\n id: item.id,\n attributes: {\n name: attrs.name ?? null,\n optInProcess: attrs.opt_in_process ?? null,\n createdAt: createdMs,\n },\n updated_at: updatedMs ?? createdMs ?? 0,\n });\n }\n }\n\n private async writeSegments(\n storage: StorageHandle,\n items: Array<JsonApiResource<SegmentAttributes>>,\n ): Promise<void> {\n for (const item of items) {\n const attrs = item.attributes ?? ({} as SegmentAttributes);\n const createdMs = parseEpoch(attrs.created ?? null, 'iso');\n const updatedMs = parseEpoch(attrs.updated ?? null, 'iso');\n await storage.entity({\n type: SEGMENT_ENTITY,\n id: item.id,\n attributes: {\n name: attrs.name ?? null,\n isActive: attrs.is_active ?? null,\n isStarred: attrs.is_starred ?? null,\n isProcessing: attrs.is_processing ?? null,\n createdAt: createdMs,\n },\n updated_at: updatedMs ?? createdMs ?? 0,\n });\n }\n }\n\n private async writeCampaigns(\n storage: StorageHandle,\n items: Array<JsonApiResource<CampaignAttributes>>,\n ): Promise<void> {\n for (const item of items) {\n const attrs = item.attributes ?? ({} as CampaignAttributes);\n const createdMs = parseEpoch(attrs.created_at ?? null, 'iso');\n const updatedMs = parseEpoch(attrs.updated_at ?? null, 'iso');\n const sendTimeMs = parseEpoch(\n attrs.send_time ?? attrs.scheduled_at ?? null,\n 'iso',\n );\n await storage.entity({\n type: CAMPAIGN_ENTITY,\n id: item.id,\n attributes: {\n name: attrs.name ?? null,\n status: attrs.status ?? null,\n archived: attrs.archived ?? null,\n channel: attrs.channel ?? this.settings.channel,\n sendStrategy: attrs.send_strategy?.method ?? null,\n sendTime: sendTimeMs,\n createdAt: createdMs,\n },\n updated_at: updatedMs ?? createdMs ?? 0,\n });\n }\n }\n\n private async writeFlows(\n storage: StorageHandle,\n items: Array<JsonApiResource<FlowAttributes>>,\n ): Promise<void> {\n for (const item of items) {\n const attrs = item.attributes ?? ({} as FlowAttributes);\n const createdMs = parseEpoch(attrs.created ?? null, 'iso');\n const updatedMs = parseEpoch(attrs.updated ?? null, 'iso');\n await storage.entity({\n type: FLOW_ENTITY,\n id: item.id,\n attributes: {\n name: attrs.name ?? null,\n status: attrs.status ?? null,\n archived: attrs.archived ?? null,\n triggerType: attrs.trigger_type ?? null,\n createdAt: createdMs,\n },\n updated_at: updatedMs ?? createdMs ?? 0,\n });\n }\n }\n\n private async writePhase(\n storage: StorageHandle,\n phase: KlaviyoPhase,\n items: unknown[],\n ): Promise<void> {\n switch (phase) {\n case 'lists':\n return this.writeLists(\n storage,\n items as Array<JsonApiResource<ListAttributes>>,\n );\n case 'segments':\n return this.writeSegments(\n storage,\n items as Array<JsonApiResource<SegmentAttributes>>,\n );\n case 'campaigns':\n return this.writeCampaigns(\n storage,\n items as Array<JsonApiResource<CampaignAttributes>>,\n );\n case 'flows':\n return this.writeFlows(\n storage,\n items as Array<JsonApiResource<FlowAttributes>>,\n );\n }\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const cursor = this.resolveCursor(options.cursor);\n const isFull = options.mode === 'full';\n\n const phases = selectActivePhases<KlaviyoResource, KlaviyoPhase>(\n (r) => r,\n PHASE_ORDER,\n this.settings.resources,\n );\n\n return paginateChunked<KlaviyoPhase, string>({\n phases,\n cursor,\n signal,\n logger: this.logger,\n fetchPage: async (phase, page, sig) =>\n this.fetchPhasePage(phase, page, options, sig),\n writeBatch: async (phase, items, page) => {\n if (isFull && page === null) {\n await storage.entities([], { types: [ENTITY_TYPE_BY_PHASE[phase]] });\n }\n await this.writePhase(storage, phase, items);\n },\n });\n }\n}\n","import { KlaviyoConnector } from './klaviyo';\n\nexport {\n configFields,\n doc,\n KlaviyoConnector,\n klaviyoResources as resources,\n id,\n} from './klaviyo';\nexport type {\n KlaviyoSettings,\n KlaviyoResource,\n KlaviyoChannel,\n} from './klaviyo';\nexport default KlaviyoConnector;\n"],"mappings":";AEAO,IAAM,sBAAsB;AAE5B,IAAM,qBAAqB,qBAAqB,mB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SAAS;AAAA,IAChB;AAEA,WAAO,gBAAsC;AAAA,MAC3C;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ,KAAK;AAAA,MACb,WAAW,OAAO,OAAO,MAAM,QAC7B,KAAK,eAAe,OAAO,MAAM,SAAS,GAAG;AAAA,MAC/C,YAAY,OAAO,OAAO,OAAO,SAAS;AACxC,YAAI,UAAU,SAAS,MAAM;AAC3B,gBAAM,QAAQ,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,qBAAqB,KAAK,CAAC,EAAE,CAAC;AAAA,QACrE;AACA,cAAM,KAAK,WAAW,SAAS,OAAO,KAAK;AAAA,MAC7C;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AC3oBA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rawdash/connector-klaviyo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Rawdash connector for Klaviyo — syncs campaigns, flows, lists, and segments from the Klaviyo REST API into the six-shape storage model",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/rawdash/rawdash.git",
|
|
11
|
+
"directory": "packages/connectors/klaviyo"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"@rawdash/source": "./src/index.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rawdash/core": "workspace:*",
|
|
33
|
+
"zod": "^4.4.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rawdash/connector-shared": "workspace:*",
|
|
37
|
+
"@rawdash/connector-test-utils": "workspace:*",
|
|
38
|
+
"fast-check": "^4.8.0",
|
|
39
|
+
"tsup": "^8.0.0",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"vitest": "^4.1.4"
|
|
42
|
+
}
|
|
43
|
+
}
|