@zerodot/convertkit 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/convertkit.svg +4 -0
- package/dist/index.cjs +689 -0
- package/package.json +52 -3
- package/README.md +0 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
let _zerodot_node_sdk = require("@zerodot/node-sdk");
|
|
4
|
+
// src/api.ts
|
|
5
|
+
const CONVERTKIT_CREDENTIAL = "convertkit.apiKey";
|
|
6
|
+
const BASE_URL = "https://api.kit.com";
|
|
7
|
+
/** The most items that "return all" collects. A node output has a size limit too. */
|
|
8
|
+
const MAX_ITEMS = 5e3;
|
|
9
|
+
/** Kit allows at most 1000 items for each page. */
|
|
10
|
+
const PAGE_SIZE = 1e3;
|
|
11
|
+
/** The API key of a credential. */
|
|
12
|
+
function convertkitAccess(credential) {
|
|
13
|
+
if (!credential || credential.type !== "convertkit.apiKey") throw new Error("The node needs a ConvertKit credential");
|
|
14
|
+
const apiKey = credential.data.apiKey;
|
|
15
|
+
if (typeof apiKey !== "string" || apiKey.trim() === "") throw new Error("The credential has no \"apiKey\"");
|
|
16
|
+
return { apiKey: apiKey.trim() };
|
|
17
|
+
}
|
|
18
|
+
/** An error that Kit gave. */
|
|
19
|
+
var ConvertkitError = class extends Error {
|
|
20
|
+
status;
|
|
21
|
+
constructor(message, status) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "ConvertkitError";
|
|
24
|
+
this.status = status;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Short help for the statuses that people see most. */
|
|
28
|
+
const HINTS = {
|
|
29
|
+
401: "Kit did not accept the API key",
|
|
30
|
+
403: "The API key cannot use this resource",
|
|
31
|
+
404: "Kit did not find the resource. Check the IDs",
|
|
32
|
+
429: "Kit limits the requests. Try again later"
|
|
33
|
+
};
|
|
34
|
+
/** The error for an answer with an error status. The text never has the API key. */
|
|
35
|
+
function convertkitErrorOf(label, status, answer, textBody) {
|
|
36
|
+
const parts = [`Kit ${label} failed (${status})`];
|
|
37
|
+
if (typeof answer?.message === "string" && answer.message) parts.push(answer.message);
|
|
38
|
+
if (Array.isArray(answer?.errors)) {
|
|
39
|
+
for (const item of answer.errors) if (typeof item === "string" && item) parts.push(item);
|
|
40
|
+
else if (item && typeof item === "object") {
|
|
41
|
+
const msg = item.message;
|
|
42
|
+
if (typeof msg === "string" && msg) parts.push(msg);
|
|
43
|
+
}
|
|
44
|
+
} else if (answer?.errors && typeof answer.errors === "object") {
|
|
45
|
+
for (const [field, value] of Object.entries(answer.errors)) if (Array.isArray(value)) {
|
|
46
|
+
for (const msg of value) if (typeof msg === "string" && msg) parts.push(`${field}: ${msg}`);
|
|
47
|
+
} else if (typeof value === "string" && value) parts.push(`${field}: ${value}`);
|
|
48
|
+
} else if (typeof textBody === "string" && textBody.trim() && !answer) parts.push(textBody.trim());
|
|
49
|
+
const hint = HINTS[status];
|
|
50
|
+
if (hint) parts.push(hint);
|
|
51
|
+
return new ConvertkitError(parts.join(". "), status);
|
|
52
|
+
}
|
|
53
|
+
function requestSignal(options) {
|
|
54
|
+
return AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)]);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One call. Kit answers 204 without a body for some deletes.
|
|
58
|
+
* HTTP 429 returns plain text "Retry later" with no Retry-After header.
|
|
59
|
+
*/
|
|
60
|
+
async function callConvertkit(access, call, options) {
|
|
61
|
+
const url = new URL(`${BASE_URL}${call.path}`);
|
|
62
|
+
for (const [key, value] of Object.entries(call.query ?? {})) {
|
|
63
|
+
if (value === void 0 || value === "") continue;
|
|
64
|
+
url.searchParams.set(key, String(value));
|
|
65
|
+
}
|
|
66
|
+
const label = `${call.method} ${call.path.replace(/^\/+/, "").split("/").slice(0, 2).join("/")}`;
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
method: call.method,
|
|
69
|
+
headers: {
|
|
70
|
+
"X-Kit-Api-Key": access.apiKey,
|
|
71
|
+
accept: "application/json",
|
|
72
|
+
...call.body ? { "content-type": "application/json" } : {}
|
|
73
|
+
},
|
|
74
|
+
body: call.body ? JSON.stringify(call.body) : void 0,
|
|
75
|
+
redirect: "error",
|
|
76
|
+
signal: requestSignal(options)
|
|
77
|
+
});
|
|
78
|
+
if (response.status === 429) throw new ConvertkitError(`Kit ${label} failed (429). ${(await response.text().catch(() => "")).trim() || "Retry later"}. ${HINTS[429]}`, 429);
|
|
79
|
+
if (response.status === 204) return {};
|
|
80
|
+
const text = await response.text();
|
|
81
|
+
let answer = null;
|
|
82
|
+
if (text) try {
|
|
83
|
+
answer = JSON.parse(text);
|
|
84
|
+
} catch {
|
|
85
|
+
answer = null;
|
|
86
|
+
}
|
|
87
|
+
if (!response.ok) throw convertkitErrorOf(label, response.status, answer, text);
|
|
88
|
+
return answer ?? {};
|
|
89
|
+
}
|
|
90
|
+
function pageInfo(page) {
|
|
91
|
+
const pagination = page.pagination;
|
|
92
|
+
const source = pagination && typeof pagination === "object" ? pagination : page;
|
|
93
|
+
return {
|
|
94
|
+
hasNext: source.has_next_page === true,
|
|
95
|
+
endCursor: typeof source.end_cursor === "string" && source.end_cursor ? source.end_cursor : void 0
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A list. Reads pages with `per_page` and `after` until it has `limit` items, or all items when
|
|
100
|
+
* `limit` is null. The items are in `itemsKey` of each page.
|
|
101
|
+
*/
|
|
102
|
+
async function callConvertkitList(access, call, itemsKey, limit, options) {
|
|
103
|
+
const wanted = Math.min(limit ?? 5e3, MAX_ITEMS);
|
|
104
|
+
const items = [];
|
|
105
|
+
let after;
|
|
106
|
+
while (items.length < wanted) {
|
|
107
|
+
const perPage = Math.min(PAGE_SIZE, wanted - items.length);
|
|
108
|
+
const page = await callConvertkit(access, {
|
|
109
|
+
...call,
|
|
110
|
+
query: {
|
|
111
|
+
...call.query,
|
|
112
|
+
per_page: perPage,
|
|
113
|
+
after
|
|
114
|
+
}
|
|
115
|
+
}, options);
|
|
116
|
+
const found = page[itemsKey];
|
|
117
|
+
if (!Array.isArray(found) || found.length === 0) break;
|
|
118
|
+
items.push(...found);
|
|
119
|
+
const { hasNext, endCursor } = pageInfo(page);
|
|
120
|
+
if (!hasNext || !endCursor) break;
|
|
121
|
+
after = endCursor;
|
|
122
|
+
}
|
|
123
|
+
return items.slice(0, wanted);
|
|
124
|
+
}
|
|
125
|
+
// src/icon.ts
|
|
126
|
+
const CONVERTKIT_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../convertkit.svg");
|
|
127
|
+
// src/credential.ts
|
|
128
|
+
const TIMEOUT_MS = 1e4;
|
|
129
|
+
const convertkitCredential = {
|
|
130
|
+
type: CONVERTKIT_CREDENTIAL,
|
|
131
|
+
label: "ConvertKit API key",
|
|
132
|
+
fields: zod.z.object({
|
|
133
|
+
/** From Kit: Settings, Developer, V4 API key. */
|
|
134
|
+
apiKey: zod.z.string().min(1).meta({ placeholder: "Your Kit V4 API key" }) }),
|
|
135
|
+
secretFields: ["apiKey"],
|
|
136
|
+
icon: "Mail01Icon",
|
|
137
|
+
iconUrl: CONVERTKIT_ICON,
|
|
138
|
+
async test(credential) {
|
|
139
|
+
await callConvertkit(convertkitAccess(credential), {
|
|
140
|
+
method: "GET",
|
|
141
|
+
path: "/v4/account"
|
|
142
|
+
}, {
|
|
143
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
144
|
+
timeoutMs: TIMEOUT_MS
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
// src/config.ts
|
|
149
|
+
const RESOURCES = [
|
|
150
|
+
"subscriber",
|
|
151
|
+
"tag",
|
|
152
|
+
"form",
|
|
153
|
+
"customField",
|
|
154
|
+
"broadcast"
|
|
155
|
+
];
|
|
156
|
+
const OPERATIONS_OF = {
|
|
157
|
+
subscriber: [
|
|
158
|
+
"getAll",
|
|
159
|
+
"get",
|
|
160
|
+
"create",
|
|
161
|
+
"update"
|
|
162
|
+
],
|
|
163
|
+
tag: [
|
|
164
|
+
"getAll",
|
|
165
|
+
"create",
|
|
166
|
+
"tagSubscriber"
|
|
167
|
+
],
|
|
168
|
+
form: ["getAll", "addSubscriber"],
|
|
169
|
+
customField: ["getAll", "create"],
|
|
170
|
+
broadcast: [
|
|
171
|
+
"getAll",
|
|
172
|
+
"get",
|
|
173
|
+
"create"
|
|
174
|
+
]
|
|
175
|
+
};
|
|
176
|
+
const ALL_OPERATIONS = [...new Set(Object.values(OPERATIONS_OF).flat())];
|
|
177
|
+
const SUBSCRIBER_STATES = [
|
|
178
|
+
"active",
|
|
179
|
+
"inactive",
|
|
180
|
+
"bounced",
|
|
181
|
+
"complained",
|
|
182
|
+
"cancelled"
|
|
183
|
+
];
|
|
184
|
+
/** Show a field for these operations of these resources. */
|
|
185
|
+
const on = (operations) => ({ showWhen: Object.entries(operations).map(([resource, ops]) => ({
|
|
186
|
+
resource: [resource],
|
|
187
|
+
operation: [...ops ?? []]
|
|
188
|
+
})) });
|
|
189
|
+
const isList = on({
|
|
190
|
+
subscriber: ["getAll"],
|
|
191
|
+
tag: ["getAll"],
|
|
192
|
+
form: ["getAll"],
|
|
193
|
+
customField: ["getAll"],
|
|
194
|
+
broadcast: ["getAll"]
|
|
195
|
+
});
|
|
196
|
+
const convertkitConfig = zod.z.object({
|
|
197
|
+
resource: zod.z.enum(RESOURCES).default("subscriber").meta({
|
|
198
|
+
labels: {
|
|
199
|
+
subscriber: "Subscriber",
|
|
200
|
+
tag: "Tag",
|
|
201
|
+
form: "Form",
|
|
202
|
+
customField: "Custom Field",
|
|
203
|
+
broadcast: "Broadcast"
|
|
204
|
+
},
|
|
205
|
+
hints: {
|
|
206
|
+
subscriber: "A person in Kit",
|
|
207
|
+
tag: "A label you can put on subscribers",
|
|
208
|
+
form: "A form that can add subscribers",
|
|
209
|
+
customField: "A custom data field for subscribers",
|
|
210
|
+
broadcast: "An email broadcast"
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
operation: zod.z.enum(ALL_OPERATIONS).default("getAll").meta({
|
|
214
|
+
labels: {
|
|
215
|
+
getAll: "Get Many",
|
|
216
|
+
get: "Get",
|
|
217
|
+
create: "Create",
|
|
218
|
+
update: "Update",
|
|
219
|
+
tagSubscriber: "Tag Subscriber",
|
|
220
|
+
addSubscriber: "Add Subscriber"
|
|
221
|
+
},
|
|
222
|
+
hints: {
|
|
223
|
+
getAll: "Get many items",
|
|
224
|
+
get: "Get one item",
|
|
225
|
+
create: "Create an item",
|
|
226
|
+
update: "Change an item",
|
|
227
|
+
tagSubscriber: "Add a tag to a subscriber",
|
|
228
|
+
addSubscriber: "Add a subscriber to a form"
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
subscriberId: zod.z.string().optional().meta({
|
|
232
|
+
...on({ subscriber: ["get", "update"] }),
|
|
233
|
+
title: "Subscriber ID",
|
|
234
|
+
description: "The ID of the subscriber"
|
|
235
|
+
}),
|
|
236
|
+
tagId: zod.z.string().optional().meta({
|
|
237
|
+
...on({ tag: ["tagSubscriber"] }),
|
|
238
|
+
title: "Tag ID",
|
|
239
|
+
description: "The ID of the tag"
|
|
240
|
+
}),
|
|
241
|
+
formId: zod.z.string().optional().meta({
|
|
242
|
+
...on({ form: ["addSubscriber"] }),
|
|
243
|
+
title: "Form ID",
|
|
244
|
+
description: "The ID of the form"
|
|
245
|
+
}),
|
|
246
|
+
broadcastId: zod.z.string().optional().meta({
|
|
247
|
+
...on({ broadcast: ["get"] }),
|
|
248
|
+
title: "Broadcast ID",
|
|
249
|
+
description: "The ID of the broadcast"
|
|
250
|
+
}),
|
|
251
|
+
email: zod.z.string().optional().meta({
|
|
252
|
+
...on({
|
|
253
|
+
subscriber: ["create"],
|
|
254
|
+
tag: ["tagSubscriber"],
|
|
255
|
+
form: ["addSubscriber"]
|
|
256
|
+
}),
|
|
257
|
+
description: "The email address of the subscriber"
|
|
258
|
+
}),
|
|
259
|
+
firstName: zod.z.string().optional().meta({
|
|
260
|
+
...on({
|
|
261
|
+
subscriber: ["create", "update"],
|
|
262
|
+
tag: ["tagSubscriber"],
|
|
263
|
+
form: ["addSubscriber"]
|
|
264
|
+
}),
|
|
265
|
+
title: "First Name",
|
|
266
|
+
description: "The first name of the subscriber"
|
|
267
|
+
}),
|
|
268
|
+
subscriberState: zod.z.enum(SUBSCRIBER_STATES).optional().meta({
|
|
269
|
+
...on({ subscriber: ["update"] }),
|
|
270
|
+
title: "State",
|
|
271
|
+
labels: {
|
|
272
|
+
active: "Active",
|
|
273
|
+
inactive: "Inactive",
|
|
274
|
+
bounced: "Bounced",
|
|
275
|
+
complained: "Complained",
|
|
276
|
+
cancelled: "Cancelled"
|
|
277
|
+
},
|
|
278
|
+
description: "The state of the subscriber"
|
|
279
|
+
}),
|
|
280
|
+
fields: zod.z.record(zod.z.string(), zod.z.unknown()).optional().meta({
|
|
281
|
+
...on({
|
|
282
|
+
subscriber: ["create", "update"],
|
|
283
|
+
tag: ["tagSubscriber"],
|
|
284
|
+
form: ["addSubscriber"]
|
|
285
|
+
}),
|
|
286
|
+
ui: "fields",
|
|
287
|
+
title: "Custom Fields",
|
|
288
|
+
description: "Custom field values. The name is the field label or key"
|
|
289
|
+
}),
|
|
290
|
+
name: zod.z.string().optional().meta({
|
|
291
|
+
...on({
|
|
292
|
+
tag: ["create"],
|
|
293
|
+
customField: ["create"]
|
|
294
|
+
}),
|
|
295
|
+
description: "The name of the item"
|
|
296
|
+
}),
|
|
297
|
+
label: zod.z.string().optional().meta({
|
|
298
|
+
...on({ customField: ["create"] }),
|
|
299
|
+
description: "The label shown for the custom field"
|
|
300
|
+
}),
|
|
301
|
+
key: zod.z.string().optional().meta({
|
|
302
|
+
...on({ customField: ["create"] }),
|
|
303
|
+
description: "The key of the custom field. Leave empty to let Kit create it from the label"
|
|
304
|
+
}),
|
|
305
|
+
subject: zod.z.string().optional().meta({
|
|
306
|
+
...on({ broadcast: ["create"] }),
|
|
307
|
+
description: "The subject of the broadcast"
|
|
308
|
+
}),
|
|
309
|
+
content: zod.z.string().optional().meta({
|
|
310
|
+
...on({ broadcast: ["create"] }),
|
|
311
|
+
description: "The HTML content of the broadcast"
|
|
312
|
+
}),
|
|
313
|
+
description: zod.z.string().optional().meta({
|
|
314
|
+
...on({ broadcast: ["create"] }),
|
|
315
|
+
description: "An internal description of the broadcast"
|
|
316
|
+
}),
|
|
317
|
+
emailAddress: zod.z.string().optional().meta({
|
|
318
|
+
...on({ broadcast: ["create"] }),
|
|
319
|
+
title: "Email Address",
|
|
320
|
+
description: "The sender email address to use for the broadcast"
|
|
321
|
+
}),
|
|
322
|
+
emailTemplateId: zod.z.string().optional().meta({
|
|
323
|
+
...on({ broadcast: ["create"] }),
|
|
324
|
+
title: "Email Template ID",
|
|
325
|
+
description: "The ID of the email template to use"
|
|
326
|
+
}),
|
|
327
|
+
public: zod.z.boolean().optional().meta({
|
|
328
|
+
...on({ broadcast: ["create"] }),
|
|
329
|
+
description: "Whether the broadcast is public in the web archive"
|
|
330
|
+
}),
|
|
331
|
+
publishedAt: zod.z.string().optional().meta({
|
|
332
|
+
...on({ broadcast: ["create"] }),
|
|
333
|
+
title: "Published At",
|
|
334
|
+
description: "When to publish the broadcast. A date and time as ISO 8601"
|
|
335
|
+
}),
|
|
336
|
+
sendAt: zod.z.string().optional().meta({
|
|
337
|
+
...on({ broadcast: ["create"] }),
|
|
338
|
+
title: "Send At",
|
|
339
|
+
description: "When to send the broadcast. A date and time as ISO 8601. Null or empty to send as draft"
|
|
340
|
+
}),
|
|
341
|
+
previewText: zod.z.string().optional().meta({
|
|
342
|
+
...on({ broadcast: ["create"] }),
|
|
343
|
+
title: "Preview Text",
|
|
344
|
+
description: "The preview text shown in email clients"
|
|
345
|
+
}),
|
|
346
|
+
subscriberFilters: zod.z.object({
|
|
347
|
+
emailAddress: zod.z.string().meta({
|
|
348
|
+
title: "Email Address",
|
|
349
|
+
description: "Only subscribers with this email address"
|
|
350
|
+
}),
|
|
351
|
+
state: zod.z.enum(SUBSCRIBER_STATES).meta({ labels: {
|
|
352
|
+
active: "Active",
|
|
353
|
+
inactive: "Inactive",
|
|
354
|
+
bounced: "Bounced",
|
|
355
|
+
complained: "Complained",
|
|
356
|
+
cancelled: "Cancelled"
|
|
357
|
+
} })
|
|
358
|
+
}).partial().default({}).meta({
|
|
359
|
+
showWhen: {
|
|
360
|
+
resource: ["subscriber"],
|
|
361
|
+
operation: ["getAll"]
|
|
362
|
+
},
|
|
363
|
+
title: "Filters"
|
|
364
|
+
}),
|
|
365
|
+
returnAll: zod.z.boolean().default(false).meta(isList),
|
|
366
|
+
limit: zod.z.number().int().min(1).max(5e3).default(50).meta({ showWhen: [
|
|
367
|
+
{
|
|
368
|
+
resource: ["subscriber"],
|
|
369
|
+
operation: ["getAll"],
|
|
370
|
+
returnAll: [false]
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
resource: ["tag"],
|
|
374
|
+
operation: ["getAll"],
|
|
375
|
+
returnAll: [false]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
resource: ["form"],
|
|
379
|
+
operation: ["getAll"],
|
|
380
|
+
returnAll: [false]
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
resource: ["customField"],
|
|
384
|
+
operation: ["getAll"],
|
|
385
|
+
returnAll: [false]
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
resource: ["broadcast"],
|
|
389
|
+
operation: ["getAll"],
|
|
390
|
+
returnAll: [false]
|
|
391
|
+
}
|
|
392
|
+
] }),
|
|
393
|
+
timeoutMs: zod.z.number().int().min(1).max(3e5).default(3e4)
|
|
394
|
+
}).superRefine((config, context) => {
|
|
395
|
+
if (!OPERATIONS_OF[config.resource].includes(config.operation)) context.addIssue({
|
|
396
|
+
code: "custom",
|
|
397
|
+
path: ["operation"],
|
|
398
|
+
message: `"${config.operation}" is not an operation of "${config.resource}"`
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
// src/request.ts
|
|
402
|
+
const need = (value, name, operation) => {
|
|
403
|
+
if (value === void 0 || typeof value === "string" && value.trim() === "") throw new Error(`Kit ${operation} needs "${name}"`);
|
|
404
|
+
return value;
|
|
405
|
+
};
|
|
406
|
+
/** An ID goes in a path, so it must be letters, digits, `_`, or `-` only. */
|
|
407
|
+
const id = (value, name, operation) => {
|
|
408
|
+
const text = need(value, name, operation).trim();
|
|
409
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/.test(text)) throw new Error(`Kit ${operation}: "${name}" is not a valid ID`);
|
|
410
|
+
return text;
|
|
411
|
+
};
|
|
412
|
+
const emailOf = (value, operation) => {
|
|
413
|
+
const text = need(value, "email", operation).trim();
|
|
414
|
+
if (!/^[^\s@]+@[^\s@]+$/.test(text)) throw new Error(`Kit ${operation}: "email" is not an email address`);
|
|
415
|
+
return text;
|
|
416
|
+
};
|
|
417
|
+
const clean = (body) => Object.fromEntries(Object.entries(body).filter(([, value]) => value !== void 0 && value !== ""));
|
|
418
|
+
const fieldsOf = (fields) => {
|
|
419
|
+
if (!fields) return void 0;
|
|
420
|
+
const entries = Object.entries(fields);
|
|
421
|
+
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
422
|
+
};
|
|
423
|
+
/** The Kit call for one operation, without the network. */
|
|
424
|
+
function buildRequest(c) {
|
|
425
|
+
const op = `${c.resource}.${c.operation}`;
|
|
426
|
+
switch (op) {
|
|
427
|
+
case "subscriber.getAll": {
|
|
428
|
+
const f = c.subscriberFilters;
|
|
429
|
+
return {
|
|
430
|
+
itemsKey: "subscribers",
|
|
431
|
+
call: {
|
|
432
|
+
method: "GET",
|
|
433
|
+
path: "/v4/subscribers",
|
|
434
|
+
query: {
|
|
435
|
+
email_address: f.emailAddress?.trim(),
|
|
436
|
+
status: f.state
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
case "subscriber.get": return { call: {
|
|
442
|
+
method: "GET",
|
|
443
|
+
path: `/v4/subscribers/${id(c.subscriberId, "subscriberId", op)}`
|
|
444
|
+
} };
|
|
445
|
+
case "subscriber.create": return { call: {
|
|
446
|
+
method: "POST",
|
|
447
|
+
path: "/v4/subscribers",
|
|
448
|
+
body: clean({
|
|
449
|
+
email_address: emailOf(c.email, op),
|
|
450
|
+
first_name: c.firstName?.trim() || void 0,
|
|
451
|
+
fields: fieldsOf(c.fields)
|
|
452
|
+
})
|
|
453
|
+
} };
|
|
454
|
+
case "subscriber.update": return { call: {
|
|
455
|
+
method: "PUT",
|
|
456
|
+
path: `/v4/subscribers/${id(c.subscriberId, "subscriberId", op)}`,
|
|
457
|
+
body: clean({
|
|
458
|
+
email_address: c.email?.trim() || void 0,
|
|
459
|
+
first_name: c.firstName?.trim() || void 0,
|
|
460
|
+
state: c.subscriberState,
|
|
461
|
+
fields: fieldsOf(c.fields)
|
|
462
|
+
})
|
|
463
|
+
} };
|
|
464
|
+
case "tag.getAll": return {
|
|
465
|
+
itemsKey: "tags",
|
|
466
|
+
call: {
|
|
467
|
+
method: "GET",
|
|
468
|
+
path: "/v4/tags"
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
case "tag.create": return { call: {
|
|
472
|
+
method: "POST",
|
|
473
|
+
path: "/v4/tags",
|
|
474
|
+
body: { name: need(c.name?.trim(), "name", op) }
|
|
475
|
+
} };
|
|
476
|
+
case "tag.tagSubscriber": return { call: {
|
|
477
|
+
method: "POST",
|
|
478
|
+
path: `/v4/tags/${id(c.tagId, "tagId", op)}/subscribers`,
|
|
479
|
+
body: clean({
|
|
480
|
+
email_address: emailOf(c.email, op),
|
|
481
|
+
first_name: c.firstName?.trim() || void 0,
|
|
482
|
+
fields: fieldsOf(c.fields)
|
|
483
|
+
})
|
|
484
|
+
} };
|
|
485
|
+
case "form.getAll": return {
|
|
486
|
+
itemsKey: "forms",
|
|
487
|
+
call: {
|
|
488
|
+
method: "GET",
|
|
489
|
+
path: "/v4/forms"
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
case "form.addSubscriber": return { call: {
|
|
493
|
+
method: "POST",
|
|
494
|
+
path: `/v4/forms/${id(c.formId, "formId", op)}/subscribers`,
|
|
495
|
+
body: clean({
|
|
496
|
+
email_address: emailOf(c.email, op),
|
|
497
|
+
first_name: c.firstName?.trim() || void 0,
|
|
498
|
+
fields: fieldsOf(c.fields)
|
|
499
|
+
})
|
|
500
|
+
} };
|
|
501
|
+
case "customField.getAll": return {
|
|
502
|
+
itemsKey: "custom_fields",
|
|
503
|
+
call: {
|
|
504
|
+
method: "GET",
|
|
505
|
+
path: "/v4/custom_fields"
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
case "customField.create": return { call: {
|
|
509
|
+
method: "POST",
|
|
510
|
+
path: "/v4/custom_fields",
|
|
511
|
+
body: clean({
|
|
512
|
+
label: c.label?.trim() || need(c.name?.trim(), "name", op),
|
|
513
|
+
key: c.key?.trim() || void 0
|
|
514
|
+
})
|
|
515
|
+
} };
|
|
516
|
+
case "broadcast.getAll": return {
|
|
517
|
+
itemsKey: "broadcasts",
|
|
518
|
+
call: {
|
|
519
|
+
method: "GET",
|
|
520
|
+
path: "/v4/broadcasts"
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
case "broadcast.get": return { call: {
|
|
524
|
+
method: "GET",
|
|
525
|
+
path: `/v4/broadcasts/${id(c.broadcastId, "broadcastId", op)}`
|
|
526
|
+
} };
|
|
527
|
+
case "broadcast.create": return { call: {
|
|
528
|
+
method: "POST",
|
|
529
|
+
path: "/v4/broadcasts",
|
|
530
|
+
body: clean({
|
|
531
|
+
subject: c.subject?.trim() || void 0,
|
|
532
|
+
content: c.content || void 0,
|
|
533
|
+
description: c.description?.trim() || void 0,
|
|
534
|
+
email_address: c.emailAddress?.trim() || void 0,
|
|
535
|
+
email_template_id: c.emailTemplateId?.trim() || void 0,
|
|
536
|
+
public: c.public,
|
|
537
|
+
published_at: c.publishedAt?.trim() || void 0,
|
|
538
|
+
send_at: c.sendAt?.trim() || void 0,
|
|
539
|
+
preview_text: c.previewText?.trim() || void 0
|
|
540
|
+
})
|
|
541
|
+
} };
|
|
542
|
+
default: throw new Error(`Kit does not know the operation "${op}"`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
// src/index.ts
|
|
546
|
+
const nodes = [(0, _zerodot_node_sdk.defineNode)({
|
|
547
|
+
type: "convertkit.api",
|
|
548
|
+
label: "ConvertKit",
|
|
549
|
+
description: "Manage subscribers, tags, forms, and broadcasts in Kit",
|
|
550
|
+
category: "integration",
|
|
551
|
+
app: "ConvertKit",
|
|
552
|
+
actions: [
|
|
553
|
+
{
|
|
554
|
+
label: "Get many subscribers",
|
|
555
|
+
config: {
|
|
556
|
+
resource: "subscriber",
|
|
557
|
+
operation: "getAll"
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
label: "Get a subscriber",
|
|
562
|
+
config: {
|
|
563
|
+
resource: "subscriber",
|
|
564
|
+
operation: "get"
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
label: "Create a subscriber",
|
|
569
|
+
config: {
|
|
570
|
+
resource: "subscriber",
|
|
571
|
+
operation: "create"
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
label: "Update a subscriber",
|
|
576
|
+
config: {
|
|
577
|
+
resource: "subscriber",
|
|
578
|
+
operation: "update"
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
label: "Get many tags",
|
|
583
|
+
config: {
|
|
584
|
+
resource: "tag",
|
|
585
|
+
operation: "getAll"
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
label: "Create a tag",
|
|
590
|
+
config: {
|
|
591
|
+
resource: "tag",
|
|
592
|
+
operation: "create"
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
label: "Tag a subscriber",
|
|
597
|
+
config: {
|
|
598
|
+
resource: "tag",
|
|
599
|
+
operation: "tagSubscriber"
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
label: "Get many forms",
|
|
604
|
+
config: {
|
|
605
|
+
resource: "form",
|
|
606
|
+
operation: "getAll"
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
label: "Add a subscriber to a form",
|
|
611
|
+
config: {
|
|
612
|
+
resource: "form",
|
|
613
|
+
operation: "addSubscriber"
|
|
614
|
+
}
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
label: "Get many custom fields",
|
|
618
|
+
config: {
|
|
619
|
+
resource: "customField",
|
|
620
|
+
operation: "getAll"
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
label: "Create a custom field",
|
|
625
|
+
config: {
|
|
626
|
+
resource: "customField",
|
|
627
|
+
operation: "create"
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
label: "Get many broadcasts",
|
|
632
|
+
config: {
|
|
633
|
+
resource: "broadcast",
|
|
634
|
+
operation: "getAll"
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
label: "Get a broadcast",
|
|
639
|
+
config: {
|
|
640
|
+
resource: "broadcast",
|
|
641
|
+
operation: "get"
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
label: "Create a broadcast",
|
|
646
|
+
config: {
|
|
647
|
+
resource: "broadcast",
|
|
648
|
+
operation: "create"
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
],
|
|
652
|
+
icon: "Mail01Icon",
|
|
653
|
+
iconUrl: CONVERTKIT_ICON,
|
|
654
|
+
config: convertkitConfig,
|
|
655
|
+
defaultConfig: {
|
|
656
|
+
resource: "subscriber",
|
|
657
|
+
operation: "getAll",
|
|
658
|
+
subscriberFilters: {},
|
|
659
|
+
returnAll: false,
|
|
660
|
+
limit: 50,
|
|
661
|
+
timeoutMs: 3e4
|
|
662
|
+
},
|
|
663
|
+
credentialTypes: [CONVERTKIT_CREDENTIAL],
|
|
664
|
+
ports: {
|
|
665
|
+
in: ["in"],
|
|
666
|
+
out: ["out"]
|
|
667
|
+
},
|
|
668
|
+
subtitle: (config) => typeof config.operation === "string" ? `${String(config.resource ?? "subscriber")}: ${config.operation}` : void 0,
|
|
669
|
+
async run({ config, credential, signal }) {
|
|
670
|
+
const access = convertkitAccess(credential);
|
|
671
|
+
const options = {
|
|
672
|
+
signal,
|
|
673
|
+
timeoutMs: config.timeoutMs
|
|
674
|
+
};
|
|
675
|
+
const request = buildRequest(config);
|
|
676
|
+
if (request.itemsKey) return {
|
|
677
|
+
port: "out",
|
|
678
|
+
data: await callConvertkitList(access, request.call, request.itemsKey, config.returnAll ? null : config.limit, options)
|
|
679
|
+
};
|
|
680
|
+
const data = await callConvertkit(access, request.call, options);
|
|
681
|
+
return {
|
|
682
|
+
port: "out",
|
|
683
|
+
data: Object.keys(data).length > 0 ? data : { success: true }
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
})];
|
|
687
|
+
const credentialTypes = [convertkitCredential];
|
|
688
|
+
exports.credentialTypes = credentialTypes;
|
|
689
|
+
exports.nodes = nodes;
|