@tryghost/mg-beehiiv-api-members 0.1.2
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 +108 -0
- package/build/index.d.ts +12 -0
- package/build/index.js +9 -0
- package/build/index.js.map +1 -0
- package/build/lib/fetch.d.ts +14 -0
- package/build/lib/fetch.js +81 -0
- package/build/lib/fetch.js.map +1 -0
- package/build/lib/list-pubs.d.ts +2 -0
- package/build/lib/list-pubs.js +17 -0
- package/build/lib/list-pubs.js.map +1 -0
- package/build/lib/mapper.d.ts +11 -0
- package/build/lib/mapper.js +85 -0
- package/build/lib/mapper.js.map +1 -0
- package/build/test/fetch.test.d.ts +1 -0
- package/build/test/fetch.test.js +340 -0
- package/build/test/fetch.test.js.map +1 -0
- package/build/test/index.test.d.ts +1 -0
- package/build/test/index.test.js +15 -0
- package/build/test/index.test.js.map +1 -0
- package/build/test/mapper.test.d.ts +1 -0
- package/build/test/mapper.test.js +322 -0
- package/build/test/mapper.test.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Migrate beehiiv Members API
|
|
2
|
+
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> This package is a work in progress, and is not ready for production use yet.
|
|
5
|
+
|
|
6
|
+
Migrate members from beehiiv to Ghost using the beehiiv API, and generate CSV files you can import into a Ghost installation.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
To install the CLI, which is required for the Usage commands below:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install --global @tryghost/migrate
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
To use this package in your own project:
|
|
18
|
+
|
|
19
|
+
`npm install @tryghost/mg-beehiiv-api-members --save`
|
|
20
|
+
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
`pnpm add @tryghost/mg-beehiiv-api-members`
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
To run a beehiiv members migration, the required command is:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
migrate beehiiv-api-members --key 1234abcd
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If no `--id` is provided, a list of available publications will be shown. Use the publication ID to run the full migration:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
migrate beehiiv-api-members --key 1234abcd --id pub_abcd1234
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
41
|
+
|
|
42
|
+
- **`--key`** (required)
|
|
43
|
+
- beehiiv API key
|
|
44
|
+
- string - default: `null`
|
|
45
|
+
- **`--id`**
|
|
46
|
+
- beehiiv publication ID
|
|
47
|
+
- string - default: `null`
|
|
48
|
+
- **`--outputSingleCSV`**
|
|
49
|
+
- Choose whether to export a single CSV or one for each type
|
|
50
|
+
- bool - default: `false`
|
|
51
|
+
- **`--writeCSV`**
|
|
52
|
+
- Create a final CSV file
|
|
53
|
+
- bool - default: `false`
|
|
54
|
+
- **`--cache`**
|
|
55
|
+
- Persist local cache after migration is complete (Only if `--zip` is `true`)
|
|
56
|
+
- bool - default: `true`
|
|
57
|
+
- **`--tmpPath`**
|
|
58
|
+
- Specify the full path where the temporary files will be stored (Defaults a hidden tmp dir)
|
|
59
|
+
- string - default: `null`
|
|
60
|
+
- **`--outputPath`**
|
|
61
|
+
- Specify the full path where the final zip file will be saved to (Defaults to CWD)
|
|
62
|
+
- string - default: `null`
|
|
63
|
+
- **`--cacheName`**
|
|
64
|
+
- Provide a unique name for the cache directory (defaults to a UUID)
|
|
65
|
+
- string - default: `null`
|
|
66
|
+
- **`-V` `--verbose`**
|
|
67
|
+
- Show verbose output
|
|
68
|
+
- bool - default: `false`
|
|
69
|
+
- **`--zip`**
|
|
70
|
+
- Create a zip file
|
|
71
|
+
- bool - default: `false`
|
|
72
|
+
|
|
73
|
+
A more complex migration command could look like this:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
migrate beehiiv-api-members --key 1234abcd --id pub_abcd1234 --outputSingleCSV --writeCSV --verbose
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This will export all members into a single CSV file, and show all available output in the console.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## Develop
|
|
83
|
+
|
|
84
|
+
This is a mono repository, managed with [Nx](https://nx.dev/) and pnpm workspaces.
|
|
85
|
+
|
|
86
|
+
Follow the instructions for the top-level repo.
|
|
87
|
+
1. `git clone` this repo & `cd` into it as usual
|
|
88
|
+
2. Run `pnpm install` to install top-level dependencies.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### Run
|
|
92
|
+
|
|
93
|
+
To run a local development copy, `cd` into this directory, and use `pnpm dev` instead of `migrate` like so:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
pnpm dev beehiiv-api-members --key 1234abcd --id pub_abcd1234
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## Test
|
|
101
|
+
|
|
102
|
+
- `pnpm lint` run just eslint
|
|
103
|
+
- `pnpm test` run lint and tests
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# Copyright & License
|
|
107
|
+
|
|
108
|
+
Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
listPublications: (apiKey: string) => Promise<any>;
|
|
3
|
+
fetchTasks: (options: any, ctx: any) => Promise<{
|
|
4
|
+
title: string;
|
|
5
|
+
task: (_: any, task: any) => Promise<void>;
|
|
6
|
+
}[]>;
|
|
7
|
+
mapMembersTasks: (_options: any, ctx: any) => {
|
|
8
|
+
title: string;
|
|
9
|
+
task: (_: any, task: any) => Promise<void>;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { listPublications } from './lib/list-pubs.js';
|
|
2
|
+
import { fetchTasks } from './lib/fetch.js';
|
|
3
|
+
import { mapMembersTasks } from './lib/mapper.js';
|
|
4
|
+
export default {
|
|
5
|
+
listPublications,
|
|
6
|
+
fetchTasks,
|
|
7
|
+
mapMembersTasks
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAEhD,eAAe;IACX,gBAAgB;IAChB,UAAU;IACV,eAAe;CAClB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const authedClient: (apiKey: string, theUrl: URL) => Promise<Response>;
|
|
2
|
+
declare const discover: (key: string, pubId: string) => Promise<number>;
|
|
3
|
+
declare const cachedFetch: ({ fileCache, key, pubId, cursor, cursorIndex }: {
|
|
4
|
+
fileCache: any;
|
|
5
|
+
key: string;
|
|
6
|
+
pubId: string;
|
|
7
|
+
cursor: string | null;
|
|
8
|
+
cursorIndex: number;
|
|
9
|
+
}) => Promise<any>;
|
|
10
|
+
export declare const fetchTasks: (options: any, ctx: any) => Promise<{
|
|
11
|
+
title: string;
|
|
12
|
+
task: (_: any, task: any) => Promise<void>;
|
|
13
|
+
}[]>;
|
|
14
|
+
export { authedClient, discover, cachedFetch };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import errors from '@tryghost/errors';
|
|
2
|
+
const API_LIMIT = 100;
|
|
3
|
+
const authedClient = async (apiKey, theUrl) => {
|
|
4
|
+
return fetch(theUrl, {
|
|
5
|
+
method: 'GET',
|
|
6
|
+
headers: {
|
|
7
|
+
Authorization: `Bearer ${apiKey}`
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const discover = async (key, pubId) => {
|
|
12
|
+
const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}`);
|
|
13
|
+
url.searchParams.append('limit', '1');
|
|
14
|
+
url.searchParams.append('expand[]', 'stats');
|
|
15
|
+
const response = await authedClient(key, url);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
return data.data.stats?.active_subscriptions;
|
|
21
|
+
};
|
|
22
|
+
const cachedFetch = async ({ fileCache, key, pubId, cursor, cursorIndex }) => {
|
|
23
|
+
const filename = `beehiiv_api_members_${cursorIndex}.json`;
|
|
24
|
+
if (fileCache.hasFile(filename, 'tmp')) {
|
|
25
|
+
return await fileCache.readTmpJSONFile(filename);
|
|
26
|
+
}
|
|
27
|
+
const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}/subscriptions`);
|
|
28
|
+
url.searchParams.append('limit', API_LIMIT.toString());
|
|
29
|
+
url.searchParams.append('status', 'active');
|
|
30
|
+
url.searchParams.append('expand[]', 'custom_fields');
|
|
31
|
+
if (cursor) {
|
|
32
|
+
url.searchParams.append('cursor', cursor);
|
|
33
|
+
}
|
|
34
|
+
const response = await authedClient(key, url);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
|
|
37
|
+
}
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
await fileCache.writeTmpFile(data, filename);
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
export const fetchTasks = async (options, ctx) => {
|
|
43
|
+
const totalSubscriptions = await discover(options.key, options.id) ?? 0;
|
|
44
|
+
const estimatedPages = totalSubscriptions > 0 ? Math.ceil(totalSubscriptions / API_LIMIT) : 0;
|
|
45
|
+
const tasks = [
|
|
46
|
+
{
|
|
47
|
+
title: `Fetching subscriptions (estimated ${estimatedPages} pages)`,
|
|
48
|
+
task: async (_, task) => {
|
|
49
|
+
let cursor = null;
|
|
50
|
+
let hasMore = true;
|
|
51
|
+
let cursorIndex = 0;
|
|
52
|
+
ctx.result.subscriptions = [];
|
|
53
|
+
while (hasMore) {
|
|
54
|
+
try {
|
|
55
|
+
const response = await cachedFetch({
|
|
56
|
+
fileCache: ctx.fileCache,
|
|
57
|
+
key: options.key,
|
|
58
|
+
pubId: options.id,
|
|
59
|
+
cursor,
|
|
60
|
+
cursorIndex
|
|
61
|
+
});
|
|
62
|
+
ctx.result.subscriptions = ctx.result.subscriptions.concat(response.data);
|
|
63
|
+
hasMore = response.has_more;
|
|
64
|
+
cursor = response.next_cursor;
|
|
65
|
+
cursorIndex += 1;
|
|
66
|
+
task.output = `Fetched ${ctx.result.subscriptions.length} of ${totalSubscriptions} subscriptions`;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
70
|
+
task.output = errorMessage;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
task.output = `Fetched ${ctx.result.subscriptions.length} subscriptions`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
return tasks;
|
|
79
|
+
};
|
|
80
|
+
export { authedClient, discover, cachedFetch };
|
|
81
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lib/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,YAAY,GAAG,KAAK,EAAE,MAAc,EAAE,MAAW,EAAE,EAAE;IACvD,OAAO,KAAK,CAAC,MAAM,EAA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OAAO,EACH,YAAY,EACZ,QAAQ,EACR,WAAW,EACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import errors from '@tryghost/errors';
|
|
2
|
+
import { authedClient } from './fetch.js';
|
|
3
|
+
const listPublications = async (apiKey) => {
|
|
4
|
+
const url = new URL(`https://api.beehiiv.com/v2/publications`);
|
|
5
|
+
url.searchParams.append('expand[]', 'stats');
|
|
6
|
+
const response = await authedClient(apiKey, url);
|
|
7
|
+
if (!response.ok) {
|
|
8
|
+
throw new errors.InternalServerError({
|
|
9
|
+
message: `Request failed: ${response.status} ${response.statusText}`,
|
|
10
|
+
context: `GET ${new URL(response.url).pathname}`
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const data = await response.json();
|
|
14
|
+
return data.data;
|
|
15
|
+
};
|
|
16
|
+
export { listPublications };
|
|
17
|
+
//# sourceMappingURL=list-pubs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-pubs.js","sourceRoot":"","sources":["../../src/lib/list-pubs.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAExC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IAC9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,yCAAyC,CAAC,CAAC;IAC/D,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC;YACjC,OAAO,EAAE,mBAAmB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE;YACpE,OAAO,EAAE,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;SACnD,CAAC,CAAC;IACP,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,OAAO,IAAI,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EACH,gBAAgB,EACnB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const extractName: (customFields: Array<{
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}>) => string | null;
|
|
5
|
+
declare const mapSubscription: (subscription: BeehiivSubscription) => GhostMemberObject;
|
|
6
|
+
declare const mapSubscriptions: (subscriptions: BeehiivSubscription[]) => MappedMembers;
|
|
7
|
+
export declare const mapMembersTasks: (_options: any, ctx: any) => {
|
|
8
|
+
title: string;
|
|
9
|
+
task: (_: any, task: any) => Promise<void>;
|
|
10
|
+
}[];
|
|
11
|
+
export { extractName, mapSubscription, mapSubscriptions };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { slugify } from '@tryghost/string';
|
|
2
|
+
const extractName = (customFields) => {
|
|
3
|
+
const firstNameField = customFields.find(f => f.name.toLowerCase() === 'first_name' || f.name.toLowerCase() === 'firstname');
|
|
4
|
+
const lastNameField = customFields.find(f => f.name.toLowerCase() === 'last_name' || f.name.toLowerCase() === 'lastname');
|
|
5
|
+
const firstName = firstNameField?.value?.trim() || '';
|
|
6
|
+
const lastName = lastNameField?.value?.trim() || '';
|
|
7
|
+
const combinedName = [firstName, lastName].filter(name => name.length > 0).join(' ');
|
|
8
|
+
return combinedName.length > 0 ? combinedName : null;
|
|
9
|
+
};
|
|
10
|
+
const mapSubscription = (subscription) => {
|
|
11
|
+
const labels = [];
|
|
12
|
+
// Add status label
|
|
13
|
+
labels.push(`beehiiv-status-${subscription.status}`);
|
|
14
|
+
// Add tier label
|
|
15
|
+
labels.push(`beehiiv-tier-${subscription.subscription_tier}`);
|
|
16
|
+
// Add premium tier names as labels
|
|
17
|
+
if (subscription.subscription_premium_tier_names && subscription.subscription_premium_tier_names.length > 0) {
|
|
18
|
+
subscription.subscription_premium_tier_names.forEach((tierName) => {
|
|
19
|
+
const slugifiedTier = slugify(tierName);
|
|
20
|
+
labels.push(`beehiiv-premium-${slugifiedTier}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Add tags as labels
|
|
24
|
+
if (subscription.tags && subscription.tags.length > 0) {
|
|
25
|
+
subscription.tags.forEach((tag) => {
|
|
26
|
+
const slugifiedTag = slugify(tag);
|
|
27
|
+
labels.push(`beehiiv-tag-${slugifiedTag}`);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// Determine if this is a complimentary plan
|
|
31
|
+
// A member is on a complimentary plan if they have premium access but no Stripe customer ID
|
|
32
|
+
const isPremium = subscription.subscription_tier === 'premium';
|
|
33
|
+
const hasStripeId = Boolean(subscription.stripe_customer_id);
|
|
34
|
+
const complimentaryPlan = isPremium && !hasStripeId;
|
|
35
|
+
return {
|
|
36
|
+
email: subscription.email,
|
|
37
|
+
name: extractName(subscription.custom_fields || []),
|
|
38
|
+
note: null,
|
|
39
|
+
subscribed_to_emails: subscription.status === 'active',
|
|
40
|
+
stripe_customer_id: subscription.stripe_customer_id || '',
|
|
41
|
+
complimentary_plan: complimentaryPlan,
|
|
42
|
+
labels,
|
|
43
|
+
created_at: new Date(subscription.created * 1000)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const mapSubscriptions = (subscriptions) => {
|
|
47
|
+
const result = {
|
|
48
|
+
free: [],
|
|
49
|
+
paid: []
|
|
50
|
+
};
|
|
51
|
+
subscriptions.forEach((subscription) => {
|
|
52
|
+
const member = mapSubscription(subscription);
|
|
53
|
+
if (member.stripe_customer_id) {
|
|
54
|
+
result.paid.push(member);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
result.free.push(member);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
export const mapMembersTasks = (_options, ctx) => {
|
|
63
|
+
const tasks = [
|
|
64
|
+
{
|
|
65
|
+
title: 'Mapping subscriptions to Ghost member format',
|
|
66
|
+
task: async (_, task) => {
|
|
67
|
+
try {
|
|
68
|
+
const subscriptions = ctx.result.subscriptions || [];
|
|
69
|
+
ctx.result.members = mapSubscriptions(subscriptions);
|
|
70
|
+
const freeCount = ctx.result.members.free.length;
|
|
71
|
+
const paidCount = ctx.result.members.paid.length;
|
|
72
|
+
task.output = `Mapped ${freeCount} free and ${paidCount} paid members`;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
76
|
+
task.output = errorMessage;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
return tasks;
|
|
83
|
+
};
|
|
84
|
+
export { extractName, mapSubscription, mapSubscriptions };
|
|
85
|
+
//# sourceMappingURL=mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.js","sourceRoot":"","sources":["../../src/lib/mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAEzC,MAAM,WAAW,GAAG,CAAC,YAAkD,EAAiB,EAAE;IACtF,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,CAAC;IAC7H,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU,CAA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O,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAa,EAAE,GAAQ,EAAE,EAAE;IACvD,MAAM,KAAK,GAAG;QACV;YACI,KAAK,EAAE,8CAA8C;YACrD,IAAI,EAAE,KAAK,EAAE,CAAM,EAAE,IAAS,EAAE,EAAE;gBAC9B,IAAI,CAAC;oBACD,MAAM,aAAa,GAA0B,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC;oBAC5E,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;oBAErD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;oBACjD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;oBAEjD,IAAI,CAAC,MAAM,GAAG,UAAU,SAAS,aAAa,SAAS,eAAe,CAAC;gBAC3E,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;oBAC3B,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC;SACJ;KACJ,CAAC;IAEF,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EACH,WAAW,EACX,eAAe,EACf,gBAAgB,EACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { describe, it, beforeEach, afterEach, mock } from 'node:test';
|
|
3
|
+
import { listPublications } from '../lib/list-pubs.js';
|
|
4
|
+
import { fetchTasks, authedClient, discover, cachedFetch } from '../lib/fetch.js';
|
|
5
|
+
describe('beehiiv API Members Fetch', () => {
|
|
6
|
+
let fetchMock;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
fetchMock = mock.method(global, 'fetch', () => Promise.resolve());
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
mock.restoreAll();
|
|
12
|
+
});
|
|
13
|
+
describe('authedClient', () => {
|
|
14
|
+
it('makes authenticated GET request', async () => {
|
|
15
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ data: [] }) }));
|
|
16
|
+
const url = new URL('https://api.beehiiv.com/v2/publications');
|
|
17
|
+
await authedClient('test-api-key', url);
|
|
18
|
+
assert.equal(fetchMock.mock.callCount(), 1);
|
|
19
|
+
const [calledUrl, options] = fetchMock.mock.calls[0].arguments;
|
|
20
|
+
assert.equal(calledUrl.toString(), 'https://api.beehiiv.com/v2/publications');
|
|
21
|
+
assert.equal(options.method, 'GET');
|
|
22
|
+
assert.equal(options.headers.Authorization, 'Bearer test-api-key');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('listPublications', () => {
|
|
26
|
+
it('fetches and returns publications', async () => {
|
|
27
|
+
const mockPubs = [{ id: 'pub-1', name: 'Test Pub' }];
|
|
28
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
29
|
+
ok: true,
|
|
30
|
+
json: () => Promise.resolve({ data: mockPubs })
|
|
31
|
+
}));
|
|
32
|
+
const result = await listPublications('test-key');
|
|
33
|
+
assert.deepEqual(result, mockPubs);
|
|
34
|
+
});
|
|
35
|
+
it('throws on API error with context', async () => {
|
|
36
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
37
|
+
ok: false,
|
|
38
|
+
status: 401,
|
|
39
|
+
statusText: 'Unauthorized',
|
|
40
|
+
url: 'https://api.beehiiv.com/v2/publications?expand%5B%5D=stats'
|
|
41
|
+
}));
|
|
42
|
+
await assert.rejects(async () => {
|
|
43
|
+
await listPublications('invalid-key');
|
|
44
|
+
}, (err) => {
|
|
45
|
+
assert.equal(err.message, 'Request failed: 401 Unauthorized');
|
|
46
|
+
assert.equal(err.context, 'GET /v2/publications');
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('discover', () => {
|
|
52
|
+
it('returns total subscription count', async () => {
|
|
53
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
54
|
+
ok: true,
|
|
55
|
+
json: () => Promise.resolve({ data: { stats: { active_subscriptions: 1500 } } })
|
|
56
|
+
}));
|
|
57
|
+
const result = await discover('test-key', 'pub-123');
|
|
58
|
+
assert.equal(result, 1500);
|
|
59
|
+
});
|
|
60
|
+
it('returns undefined when stats are missing', async () => {
|
|
61
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
62
|
+
ok: true,
|
|
63
|
+
json: () => Promise.resolve({ data: {} })
|
|
64
|
+
}));
|
|
65
|
+
const result = await discover('test-key', 'pub-123');
|
|
66
|
+
assert.equal(result, undefined);
|
|
67
|
+
});
|
|
68
|
+
it('throws on API error', async () => {
|
|
69
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
70
|
+
ok: false,
|
|
71
|
+
status: 403,
|
|
72
|
+
statusText: 'Forbidden'
|
|
73
|
+
}));
|
|
74
|
+
await assert.rejects(async () => {
|
|
75
|
+
await discover('test-key', 'pub-123');
|
|
76
|
+
}, /Request failed: 403 Forbidden/);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('cachedFetch', () => {
|
|
80
|
+
it('returns cached data when available', async () => {
|
|
81
|
+
const cachedData = { data: [{ id: 'sub-1', email: 'test@example.com' }], has_more: false };
|
|
82
|
+
const fileCache = {
|
|
83
|
+
hasFile: () => true,
|
|
84
|
+
readTmpJSONFile: () => Promise.resolve(cachedData)
|
|
85
|
+
};
|
|
86
|
+
const result = await cachedFetch({
|
|
87
|
+
fileCache,
|
|
88
|
+
key: 'test-key',
|
|
89
|
+
pubId: 'pub-123',
|
|
90
|
+
cursor: null,
|
|
91
|
+
cursorIndex: 0
|
|
92
|
+
});
|
|
93
|
+
assert.deepEqual(result, cachedData);
|
|
94
|
+
assert.equal(fetchMock.mock.callCount(), 0);
|
|
95
|
+
});
|
|
96
|
+
it('fetches from API when not cached', async () => {
|
|
97
|
+
const apiData = { data: [{ id: 'sub-1', email: 'test@example.com' }], has_more: false, next_cursor: null };
|
|
98
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
99
|
+
ok: true,
|
|
100
|
+
json: () => Promise.resolve(apiData)
|
|
101
|
+
}));
|
|
102
|
+
const writeTmpFileMock = mock.fn(() => Promise.resolve());
|
|
103
|
+
const fileCache = {
|
|
104
|
+
hasFile: () => false,
|
|
105
|
+
writeTmpFile: writeTmpFileMock
|
|
106
|
+
};
|
|
107
|
+
const result = await cachedFetch({
|
|
108
|
+
fileCache,
|
|
109
|
+
key: 'test-key',
|
|
110
|
+
pubId: 'pub-123',
|
|
111
|
+
cursor: null,
|
|
112
|
+
cursorIndex: 0
|
|
113
|
+
});
|
|
114
|
+
assert.deepEqual(result, apiData);
|
|
115
|
+
assert.equal(writeTmpFileMock.mock.callCount(), 1);
|
|
116
|
+
});
|
|
117
|
+
it('includes cursor when provided', async () => {
|
|
118
|
+
const apiData = { data: [], has_more: false, next_cursor: null };
|
|
119
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
120
|
+
ok: true,
|
|
121
|
+
json: () => Promise.resolve(apiData)
|
|
122
|
+
}));
|
|
123
|
+
const fileCache = {
|
|
124
|
+
hasFile: () => false,
|
|
125
|
+
writeTmpFile: mock.fn(() => Promise.resolve())
|
|
126
|
+
};
|
|
127
|
+
await cachedFetch({
|
|
128
|
+
fileCache,
|
|
129
|
+
key: 'test-key',
|
|
130
|
+
pubId: 'pub-123',
|
|
131
|
+
cursor: 'cursor-abc',
|
|
132
|
+
cursorIndex: 1
|
|
133
|
+
});
|
|
134
|
+
const [calledUrl] = fetchMock.mock.calls[0].arguments;
|
|
135
|
+
assert.ok(calledUrl.toString().includes('cursor=cursor-abc'));
|
|
136
|
+
});
|
|
137
|
+
it('throws on API error', async () => {
|
|
138
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
139
|
+
ok: false,
|
|
140
|
+
status: 500,
|
|
141
|
+
statusText: 'Internal Server Error'
|
|
142
|
+
}));
|
|
143
|
+
const fileCache = {
|
|
144
|
+
hasFile: () => false,
|
|
145
|
+
writeTmpFile: mock.fn(() => Promise.resolve())
|
|
146
|
+
};
|
|
147
|
+
await assert.rejects(async () => {
|
|
148
|
+
await cachedFetch({
|
|
149
|
+
fileCache,
|
|
150
|
+
key: 'test-key',
|
|
151
|
+
pubId: 'pub-123',
|
|
152
|
+
cursor: null,
|
|
153
|
+
cursorIndex: 0
|
|
154
|
+
});
|
|
155
|
+
}, /Request failed: 500 Internal Server Error/);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('fetchTasks', () => {
|
|
159
|
+
it('creates a single task that fetches all subscriptions', async () => {
|
|
160
|
+
// Mock the discover call
|
|
161
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
162
|
+
ok: true,
|
|
163
|
+
json: () => Promise.resolve({ data: { stats: { active_subscriptions: 150 } } })
|
|
164
|
+
}), 0);
|
|
165
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
166
|
+
const ctx = {
|
|
167
|
+
fileCache: {
|
|
168
|
+
hasFile: () => false,
|
|
169
|
+
writeTmpFile: () => Promise.resolve()
|
|
170
|
+
},
|
|
171
|
+
result: {}
|
|
172
|
+
};
|
|
173
|
+
const tasks = await fetchTasks(options, ctx);
|
|
174
|
+
assert.equal(tasks.length, 1);
|
|
175
|
+
assert.ok(tasks[0].title.includes('Fetching subscriptions'));
|
|
176
|
+
});
|
|
177
|
+
it('task fetches all pages using cursor pagination', async () => {
|
|
178
|
+
// Mock the discover call
|
|
179
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
180
|
+
ok: true,
|
|
181
|
+
json: () => Promise.resolve({ total_results: 3, data: [], has_more: true })
|
|
182
|
+
}), 0);
|
|
183
|
+
// Mock first page
|
|
184
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
185
|
+
ok: true,
|
|
186
|
+
json: () => Promise.resolve({
|
|
187
|
+
data: [{ id: 'sub-1', email: 'a@test.com' }],
|
|
188
|
+
has_more: true,
|
|
189
|
+
next_cursor: 'cursor-1'
|
|
190
|
+
})
|
|
191
|
+
}), 1);
|
|
192
|
+
// Mock second page
|
|
193
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
194
|
+
ok: true,
|
|
195
|
+
json: () => Promise.resolve({
|
|
196
|
+
data: [{ id: 'sub-2', email: 'b@test.com' }],
|
|
197
|
+
has_more: false,
|
|
198
|
+
next_cursor: null
|
|
199
|
+
})
|
|
200
|
+
}), 2);
|
|
201
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
202
|
+
const ctx = {
|
|
203
|
+
fileCache: {
|
|
204
|
+
hasFile: () => false,
|
|
205
|
+
writeTmpFile: () => Promise.resolve()
|
|
206
|
+
},
|
|
207
|
+
result: {}
|
|
208
|
+
};
|
|
209
|
+
const tasks = await fetchTasks(options, ctx);
|
|
210
|
+
await tasks[0].task({}, { output: '' });
|
|
211
|
+
assert.equal(ctx.result.subscriptions.length, 2);
|
|
212
|
+
assert.equal(ctx.result.subscriptions[0].id, 'sub-1');
|
|
213
|
+
assert.equal(ctx.result.subscriptions[1].id, 'sub-2');
|
|
214
|
+
});
|
|
215
|
+
it('task uses cached data when available', async () => {
|
|
216
|
+
// Mock the discover call
|
|
217
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
218
|
+
ok: true,
|
|
219
|
+
json: () => Promise.resolve({ total_results: 1, data: [], has_more: false })
|
|
220
|
+
}), 0);
|
|
221
|
+
const cachedData = {
|
|
222
|
+
data: [{ id: 'cached-sub', email: 'cached@test.com' }],
|
|
223
|
+
has_more: false,
|
|
224
|
+
next_cursor: null
|
|
225
|
+
};
|
|
226
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
227
|
+
const ctx = {
|
|
228
|
+
fileCache: {
|
|
229
|
+
hasFile: () => true,
|
|
230
|
+
readTmpJSONFile: () => Promise.resolve(cachedData)
|
|
231
|
+
},
|
|
232
|
+
result: {}
|
|
233
|
+
};
|
|
234
|
+
const tasks = await fetchTasks(options, ctx);
|
|
235
|
+
await tasks[0].task({}, { output: '' });
|
|
236
|
+
assert.equal(ctx.result.subscriptions.length, 1);
|
|
237
|
+
assert.equal(ctx.result.subscriptions[0].id, 'cached-sub');
|
|
238
|
+
// fetch should only be called once (for discover)
|
|
239
|
+
assert.equal(fetchMock.mock.callCount(), 1);
|
|
240
|
+
});
|
|
241
|
+
it('task throws and sets output on fetch error', async () => {
|
|
242
|
+
// Mock the discover call
|
|
243
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
244
|
+
ok: true,
|
|
245
|
+
json: () => Promise.resolve({ total_results: 5, data: [], has_more: true })
|
|
246
|
+
}), 0);
|
|
247
|
+
// Mock a failed fetch
|
|
248
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
249
|
+
ok: false,
|
|
250
|
+
status: 500,
|
|
251
|
+
statusText: 'Internal Server Error'
|
|
252
|
+
}), 1);
|
|
253
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
254
|
+
const ctx = {
|
|
255
|
+
fileCache: {
|
|
256
|
+
hasFile: () => false,
|
|
257
|
+
writeTmpFile: () => Promise.resolve()
|
|
258
|
+
},
|
|
259
|
+
result: {}
|
|
260
|
+
};
|
|
261
|
+
const tasks = await fetchTasks(options, ctx);
|
|
262
|
+
const mockTask = { output: '' };
|
|
263
|
+
await assert.rejects(async () => {
|
|
264
|
+
await tasks[0].task({}, mockTask);
|
|
265
|
+
}, /Request failed: 500 Internal Server Error/);
|
|
266
|
+
assert.ok(mockTask.output.includes('500'));
|
|
267
|
+
});
|
|
268
|
+
it('task handles non-Error thrown objects', async () => {
|
|
269
|
+
// Mock the discover call
|
|
270
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
271
|
+
ok: true,
|
|
272
|
+
json: () => Promise.resolve({ total_results: 5, data: [], has_more: true })
|
|
273
|
+
}), 0);
|
|
274
|
+
// Mock fetch that throws a non-Error value
|
|
275
|
+
fetchMock.mock.mockImplementationOnce(() => {
|
|
276
|
+
// eslint-disable-next-line no-throw-literal
|
|
277
|
+
throw 'Network error string';
|
|
278
|
+
}, 1);
|
|
279
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
280
|
+
const ctx = {
|
|
281
|
+
fileCache: {
|
|
282
|
+
hasFile: () => false,
|
|
283
|
+
writeTmpFile: () => Promise.resolve()
|
|
284
|
+
},
|
|
285
|
+
result: {}
|
|
286
|
+
};
|
|
287
|
+
const tasks = await fetchTasks(options, ctx);
|
|
288
|
+
const mockTask = { output: '' };
|
|
289
|
+
await assert.rejects(async () => {
|
|
290
|
+
await tasks[0].task({}, mockTask);
|
|
291
|
+
});
|
|
292
|
+
assert.equal(mockTask.output, 'Network error string');
|
|
293
|
+
});
|
|
294
|
+
it('handles discover returning undefined stats', async () => {
|
|
295
|
+
// discover returns undefined when stats are missing
|
|
296
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
297
|
+
ok: true,
|
|
298
|
+
json: () => Promise.resolve({ data: {} })
|
|
299
|
+
}), 0);
|
|
300
|
+
// Mock a single page of results
|
|
301
|
+
fetchMock.mock.mockImplementationOnce(() => Promise.resolve({
|
|
302
|
+
ok: true,
|
|
303
|
+
json: () => Promise.resolve({
|
|
304
|
+
data: [{ id: 'sub-1', email: 'a@test.com' }],
|
|
305
|
+
has_more: false,
|
|
306
|
+
next_cursor: null
|
|
307
|
+
})
|
|
308
|
+
}), 1);
|
|
309
|
+
const options = { key: 'test-key', id: 'pub-123' };
|
|
310
|
+
const ctx = {
|
|
311
|
+
fileCache: {
|
|
312
|
+
hasFile: () => false,
|
|
313
|
+
writeTmpFile: () => Promise.resolve()
|
|
314
|
+
},
|
|
315
|
+
result: {}
|
|
316
|
+
};
|
|
317
|
+
const tasks = await fetchTasks(options, ctx);
|
|
318
|
+
assert.equal(tasks.length, 1);
|
|
319
|
+
assert.ok(tasks[0].title.includes('estimated 0 pages'));
|
|
320
|
+
await tasks[0].task({}, { output: '' });
|
|
321
|
+
assert.equal(ctx.result.subscriptions.length, 1);
|
|
322
|
+
});
|
|
323
|
+
it('handles discover error', async () => {
|
|
324
|
+
fetchMock.mock.mockImplementation(() => Promise.resolve({
|
|
325
|
+
ok: false,
|
|
326
|
+
status: 401,
|
|
327
|
+
statusText: 'Unauthorized'
|
|
328
|
+
}));
|
|
329
|
+
const options = { key: 'invalid-key', id: 'pub-123' };
|
|
330
|
+
const ctx = {
|
|
331
|
+
fileCache: {},
|
|
332
|
+
result: {}
|
|
333
|
+
};
|
|
334
|
+
await assert.rejects(async () => {
|
|
335
|
+
await fetchTasks(options, ctx);
|
|
336
|
+
}, /Request failed: 401 Unauthorized/);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
//# sourceMappingURL=fetch.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.test.js","sourceRoot":"","sources":["../../src/test/fetch.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAC,MAAM,WAAW,CAAC;AACpE,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAEhF,QAAQ,CAAC,2BAA2B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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
import beehiivApiMembers from '../index.js';
|
|
4
|
+
describe('beehiiv API Members Package', () => {
|
|
5
|
+
it('exports listPublications', () => {
|
|
6
|
+
assert.ok(typeof beehiivApiMembers.listPublications === 'function');
|
|
7
|
+
});
|
|
8
|
+
it('exports fetchTasks', () => {
|
|
9
|
+
assert.ok(typeof beehiivApiMembers.fetchTasks === 'function');
|
|
10
|
+
});
|
|
11
|
+
it('exports mapMembersTasks', () => {
|
|
12
|
+
assert.ok(typeof beehiivApiMembers.mapMembersTasks === 'function');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/test/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,iBAAiB,MAAM,aAAa,CAAC;AAE5C,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAChC,MAAM,CAAC,EAAE,CAAC,OAAO,iBAAiB,CAAC,gBAAgB,KAAK,UAAU,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAC1B,MAAM,CAAC,EAAE,CAAC,OAAO,iBAAiB,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,EAAE,CAAC,OAAO,iBAAiB,CAAC,eAAe,KAAK,UAAU,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
import { extractName, mapSubscription, mapSubscriptions, mapMembersTasks } from '../lib/mapper.js';
|
|
4
|
+
describe('beehiiv API Members Mapper', () => {
|
|
5
|
+
describe('extractName', () => {
|
|
6
|
+
it('combines first and last name', () => {
|
|
7
|
+
const customFields = [
|
|
8
|
+
{ name: 'first_name', value: 'John' },
|
|
9
|
+
{ name: 'last_name', value: 'Doe' }
|
|
10
|
+
];
|
|
11
|
+
assert.equal(extractName(customFields), 'John Doe');
|
|
12
|
+
});
|
|
13
|
+
it('handles only first name', () => {
|
|
14
|
+
const customFields = [{ name: 'first_name', value: 'Jane' }];
|
|
15
|
+
assert.equal(extractName(customFields), 'Jane');
|
|
16
|
+
});
|
|
17
|
+
it('handles only last name', () => {
|
|
18
|
+
const customFields = [{ name: 'last_name', value: 'Smith' }];
|
|
19
|
+
assert.equal(extractName(customFields), 'Smith');
|
|
20
|
+
});
|
|
21
|
+
it('returns null for empty custom fields', () => {
|
|
22
|
+
assert.equal(extractName([]), null);
|
|
23
|
+
});
|
|
24
|
+
it('returns null when name fields are empty strings', () => {
|
|
25
|
+
const customFields = [
|
|
26
|
+
{ name: 'first_name', value: '' },
|
|
27
|
+
{ name: 'last_name', value: '' }
|
|
28
|
+
];
|
|
29
|
+
assert.equal(extractName(customFields), null);
|
|
30
|
+
});
|
|
31
|
+
it('trims whitespace from names', () => {
|
|
32
|
+
const customFields = [
|
|
33
|
+
{ name: 'first_name', value: ' John ' },
|
|
34
|
+
{ name: 'last_name', value: ' Doe ' }
|
|
35
|
+
];
|
|
36
|
+
assert.equal(extractName(customFields), 'John Doe');
|
|
37
|
+
});
|
|
38
|
+
it('handles alternate field names (firstname/lastname)', () => {
|
|
39
|
+
const customFields = [
|
|
40
|
+
{ name: 'firstname', value: 'Jane' },
|
|
41
|
+
{ name: 'lastname', value: 'Doe' }
|
|
42
|
+
];
|
|
43
|
+
assert.equal(extractName(customFields), 'Jane Doe');
|
|
44
|
+
});
|
|
45
|
+
it('handles case-insensitive field names', () => {
|
|
46
|
+
const customFields = [
|
|
47
|
+
{ name: 'First_Name', value: 'Jane' },
|
|
48
|
+
{ name: 'Last_Name', value: 'Doe' }
|
|
49
|
+
];
|
|
50
|
+
assert.equal(extractName(customFields), 'Jane Doe');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('mapSubscription', () => {
|
|
54
|
+
const baseSubscription = {
|
|
55
|
+
id: 'sub-123',
|
|
56
|
+
email: 'test@example.com',
|
|
57
|
+
status: 'active',
|
|
58
|
+
created: 1704067200, // 2024-01-01 00:00:00 UTC
|
|
59
|
+
subscription_tier: 'free',
|
|
60
|
+
subscription_premium_tier_names: [],
|
|
61
|
+
stripe_customer_id: null,
|
|
62
|
+
custom_fields: [],
|
|
63
|
+
tags: []
|
|
64
|
+
};
|
|
65
|
+
it('maps basic subscription fields', () => {
|
|
66
|
+
const result = mapSubscription(baseSubscription);
|
|
67
|
+
assert.equal(result.email, 'test@example.com');
|
|
68
|
+
assert.equal(result.name, null);
|
|
69
|
+
assert.equal(result.note, null);
|
|
70
|
+
assert.equal(result.subscribed_to_emails, true);
|
|
71
|
+
assert.equal(result.stripe_customer_id, '');
|
|
72
|
+
assert.equal(result.complimentary_plan, false);
|
|
73
|
+
assert.deepEqual(result.created_at, new Date(1704067200 * 1000));
|
|
74
|
+
});
|
|
75
|
+
it('sets subscribed_to_emails true for active status', () => {
|
|
76
|
+
const subscription = { ...baseSubscription, status: 'active' };
|
|
77
|
+
const result = mapSubscription(subscription);
|
|
78
|
+
assert.equal(result.subscribed_to_emails, true);
|
|
79
|
+
});
|
|
80
|
+
it('sets subscribed_to_emails false for inactive status', () => {
|
|
81
|
+
const subscription = { ...baseSubscription, status: 'inactive' };
|
|
82
|
+
const result = mapSubscription(subscription);
|
|
83
|
+
assert.equal(result.subscribed_to_emails, false);
|
|
84
|
+
});
|
|
85
|
+
it('sets subscribed_to_emails false for validating status', () => {
|
|
86
|
+
const subscription = { ...baseSubscription, status: 'validating' };
|
|
87
|
+
const result = mapSubscription(subscription);
|
|
88
|
+
assert.equal(result.subscribed_to_emails, false);
|
|
89
|
+
});
|
|
90
|
+
it('sets subscribed_to_emails false for pending status', () => {
|
|
91
|
+
const subscription = { ...baseSubscription, status: 'pending' };
|
|
92
|
+
const result = mapSubscription(subscription);
|
|
93
|
+
assert.equal(result.subscribed_to_emails, false);
|
|
94
|
+
});
|
|
95
|
+
it('maps stripe_customer_id when present', () => {
|
|
96
|
+
const subscription = { ...baseSubscription, stripe_customer_id: 'cus_abc123' };
|
|
97
|
+
const result = mapSubscription(subscription);
|
|
98
|
+
assert.equal(result.stripe_customer_id, 'cus_abc123');
|
|
99
|
+
});
|
|
100
|
+
it('sets complimentary_plan true for premium without stripe_customer_id', () => {
|
|
101
|
+
const subscription = {
|
|
102
|
+
...baseSubscription,
|
|
103
|
+
subscription_tier: 'premium',
|
|
104
|
+
stripe_customer_id: null
|
|
105
|
+
};
|
|
106
|
+
const result = mapSubscription(subscription);
|
|
107
|
+
assert.equal(result.complimentary_plan, true);
|
|
108
|
+
});
|
|
109
|
+
it('sets complimentary_plan false for premium with stripe_customer_id', () => {
|
|
110
|
+
const subscription = {
|
|
111
|
+
...baseSubscription,
|
|
112
|
+
subscription_tier: 'premium',
|
|
113
|
+
stripe_customer_id: 'cus_abc123'
|
|
114
|
+
};
|
|
115
|
+
const result = mapSubscription(subscription);
|
|
116
|
+
assert.equal(result.complimentary_plan, false);
|
|
117
|
+
});
|
|
118
|
+
it('sets complimentary_plan false for free tier', () => {
|
|
119
|
+
const subscription = { ...baseSubscription, subscription_tier: 'free' };
|
|
120
|
+
const result = mapSubscription(subscription);
|
|
121
|
+
assert.equal(result.complimentary_plan, false);
|
|
122
|
+
});
|
|
123
|
+
it('extracts name from custom_fields', () => {
|
|
124
|
+
const subscription = {
|
|
125
|
+
...baseSubscription,
|
|
126
|
+
custom_fields: [
|
|
127
|
+
{ name: 'first_name', value: 'John' },
|
|
128
|
+
{ name: 'last_name', value: 'Doe' }
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
const result = mapSubscription(subscription);
|
|
132
|
+
assert.equal(result.name, 'John Doe');
|
|
133
|
+
});
|
|
134
|
+
it('adds status label', () => {
|
|
135
|
+
const result = mapSubscription(baseSubscription);
|
|
136
|
+
assert.ok(result.labels.includes('beehiiv-status-active'));
|
|
137
|
+
});
|
|
138
|
+
it('adds tier label', () => {
|
|
139
|
+
const result = mapSubscription(baseSubscription);
|
|
140
|
+
assert.ok(result.labels.includes('beehiiv-tier-free'));
|
|
141
|
+
});
|
|
142
|
+
it('adds premium tier names as labels', () => {
|
|
143
|
+
const subscription = {
|
|
144
|
+
...baseSubscription,
|
|
145
|
+
subscription_tier: 'premium',
|
|
146
|
+
subscription_premium_tier_names: ['Gold Plan', 'VIP Access']
|
|
147
|
+
};
|
|
148
|
+
const result = mapSubscription(subscription);
|
|
149
|
+
assert.ok(result.labels.includes('beehiiv-premium-gold-plan'));
|
|
150
|
+
assert.ok(result.labels.includes('beehiiv-premium-vip-access'));
|
|
151
|
+
});
|
|
152
|
+
it('adds tags as labels', () => {
|
|
153
|
+
const subscription = {
|
|
154
|
+
...baseSubscription,
|
|
155
|
+
tags: ['Newsletter', 'Tech Updates']
|
|
156
|
+
};
|
|
157
|
+
const result = mapSubscription(subscription);
|
|
158
|
+
assert.ok(result.labels.includes('beehiiv-tag-newsletter'));
|
|
159
|
+
assert.ok(result.labels.includes('beehiiv-tag-tech-updates'));
|
|
160
|
+
});
|
|
161
|
+
it('handles empty premium tier names array', () => {
|
|
162
|
+
const subscription = {
|
|
163
|
+
...baseSubscription,
|
|
164
|
+
subscription_premium_tier_names: []
|
|
165
|
+
};
|
|
166
|
+
const result = mapSubscription(subscription);
|
|
167
|
+
assert.ok(!result.labels.some(l => l.startsWith('beehiiv-premium-')));
|
|
168
|
+
});
|
|
169
|
+
it('handles empty tags array', () => {
|
|
170
|
+
const subscription = {
|
|
171
|
+
...baseSubscription,
|
|
172
|
+
tags: []
|
|
173
|
+
};
|
|
174
|
+
const result = mapSubscription(subscription);
|
|
175
|
+
assert.ok(!result.labels.some(l => l.startsWith('beehiiv-tag-')));
|
|
176
|
+
});
|
|
177
|
+
it('handles undefined custom_fields', () => {
|
|
178
|
+
const subscription = {
|
|
179
|
+
...baseSubscription,
|
|
180
|
+
custom_fields: undefined
|
|
181
|
+
};
|
|
182
|
+
const result = mapSubscription(subscription);
|
|
183
|
+
assert.equal(result.name, null);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe('mapSubscriptions', () => {
|
|
187
|
+
it('splits subscriptions into free and paid based on stripe_customer_id', () => {
|
|
188
|
+
const subscriptions = [
|
|
189
|
+
{
|
|
190
|
+
id: 'sub-1',
|
|
191
|
+
email: 'free@test.com',
|
|
192
|
+
status: 'active',
|
|
193
|
+
created: 1704067200,
|
|
194
|
+
subscription_tier: 'free',
|
|
195
|
+
subscription_premium_tier_names: [],
|
|
196
|
+
stripe_customer_id: null,
|
|
197
|
+
custom_fields: [],
|
|
198
|
+
tags: []
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'sub-2',
|
|
202
|
+
email: 'paid@test.com',
|
|
203
|
+
status: 'active',
|
|
204
|
+
created: 1704067200,
|
|
205
|
+
subscription_tier: 'premium',
|
|
206
|
+
subscription_premium_tier_names: [],
|
|
207
|
+
stripe_customer_id: 'cus_paid123',
|
|
208
|
+
custom_fields: [],
|
|
209
|
+
tags: []
|
|
210
|
+
}
|
|
211
|
+
];
|
|
212
|
+
const result = mapSubscriptions(subscriptions);
|
|
213
|
+
assert.equal(result.free.length, 1);
|
|
214
|
+
assert.equal(result.paid.length, 1);
|
|
215
|
+
assert.equal(result.free[0].email, 'free@test.com');
|
|
216
|
+
assert.equal(result.paid[0].email, 'paid@test.com');
|
|
217
|
+
});
|
|
218
|
+
it('returns empty arrays for empty input', () => {
|
|
219
|
+
const result = mapSubscriptions([]);
|
|
220
|
+
assert.deepEqual(result, { free: [], paid: [] });
|
|
221
|
+
});
|
|
222
|
+
it('categorizes complimentary premium as free', () => {
|
|
223
|
+
const subscriptions = [
|
|
224
|
+
{
|
|
225
|
+
id: 'sub-1',
|
|
226
|
+
email: 'comp@test.com',
|
|
227
|
+
status: 'active',
|
|
228
|
+
created: 1704067200,
|
|
229
|
+
subscription_tier: 'premium',
|
|
230
|
+
subscription_premium_tier_names: [],
|
|
231
|
+
stripe_customer_id: null, // No stripe ID means complimentary
|
|
232
|
+
custom_fields: [],
|
|
233
|
+
tags: []
|
|
234
|
+
}
|
|
235
|
+
];
|
|
236
|
+
const result = mapSubscriptions(subscriptions);
|
|
237
|
+
assert.equal(result.free.length, 1);
|
|
238
|
+
assert.equal(result.paid.length, 0);
|
|
239
|
+
assert.equal(result.free[0].complimentary_plan, true);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
describe('mapMembersTasks', () => {
|
|
243
|
+
it('creates a single mapping task', () => {
|
|
244
|
+
const ctx = { result: { subscriptions: [] } };
|
|
245
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
246
|
+
assert.equal(tasks.length, 1);
|
|
247
|
+
assert.equal(tasks[0].title, 'Mapping subscriptions to Ghost member format');
|
|
248
|
+
});
|
|
249
|
+
it('task maps subscriptions and stores result', async () => {
|
|
250
|
+
const ctx = {
|
|
251
|
+
result: {
|
|
252
|
+
subscriptions: [
|
|
253
|
+
{
|
|
254
|
+
id: 'sub-1',
|
|
255
|
+
email: 'test@test.com',
|
|
256
|
+
status: 'active',
|
|
257
|
+
created: 1704067200,
|
|
258
|
+
subscription_tier: 'free',
|
|
259
|
+
subscription_premium_tier_names: [],
|
|
260
|
+
stripe_customer_id: null,
|
|
261
|
+
custom_fields: [],
|
|
262
|
+
tags: []
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
268
|
+
const mockTask = { output: '' };
|
|
269
|
+
await tasks[0].task({}, mockTask);
|
|
270
|
+
assert.ok(ctx.result.members);
|
|
271
|
+
assert.equal(ctx.result.members.free.length, 1);
|
|
272
|
+
assert.equal(ctx.result.members.paid.length, 0);
|
|
273
|
+
assert.ok(mockTask.output.includes('1 free'));
|
|
274
|
+
assert.ok(mockTask.output.includes('0 paid'));
|
|
275
|
+
});
|
|
276
|
+
it('task handles empty subscriptions', async () => {
|
|
277
|
+
const ctx = { result: { subscriptions: [] } };
|
|
278
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
279
|
+
const mockTask = { output: '' };
|
|
280
|
+
await tasks[0].task({}, mockTask);
|
|
281
|
+
assert.deepEqual(ctx.result.members, { free: [], paid: [] });
|
|
282
|
+
});
|
|
283
|
+
it('task handles undefined subscriptions', async () => {
|
|
284
|
+
const ctx = { result: {} };
|
|
285
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
286
|
+
const mockTask = { output: '' };
|
|
287
|
+
await tasks[0].task({}, mockTask);
|
|
288
|
+
assert.deepEqual(ctx.result.members, { free: [], paid: [] });
|
|
289
|
+
});
|
|
290
|
+
it('task sets error output on failure with Error instance', async () => {
|
|
291
|
+
const ctx = {
|
|
292
|
+
result: {
|
|
293
|
+
subscriptions: 'not an array' // Invalid data
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
297
|
+
const mockTask = { output: '' };
|
|
298
|
+
await assert.rejects(async () => {
|
|
299
|
+
await tasks[0].task({}, mockTask);
|
|
300
|
+
});
|
|
301
|
+
assert.ok(mockTask.output.length > 0);
|
|
302
|
+
});
|
|
303
|
+
it('task sets error output on failure with non-Error thrown', async () => {
|
|
304
|
+
// Create a context that will trigger an error through a getter that throws a string
|
|
305
|
+
const ctx = {
|
|
306
|
+
result: {
|
|
307
|
+
get subscriptions() {
|
|
308
|
+
// eslint-disable-next-line no-throw-literal
|
|
309
|
+
throw 'Custom string error';
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const tasks = mapMembersTasks({}, ctx);
|
|
314
|
+
const mockTask = { output: '' };
|
|
315
|
+
await assert.rejects(async () => {
|
|
316
|
+
await tasks[0].task({}, mockTask);
|
|
317
|
+
});
|
|
318
|
+
assert.equal(mockTask.output, 'Custom string error');
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
//# sourceMappingURL=mapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.test.js","sourceRoot":"","sources":["../../src/test/mapper.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,EAAC,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjG,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IACxC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACpC,MAAM,YAAY,GAAG;gBACjB,EAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAC;gBACnC,EAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAC;aACpC,CAAC;YACF,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;YAC/B,MAAM,YAAY,GAAG,CAAC,EAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAA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AC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tryghost/mg-beehiiv-api-members",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-beehiiv-api-members",
|
|
5
|
+
"author": "Ghost Foundation",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "build/index.js",
|
|
9
|
+
"types": "build/types.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"development": "./src/index.ts",
|
|
13
|
+
"default": "./build/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "echo \"Implement me!\"",
|
|
18
|
+
"build:watch": "tsc --watch --preserveWatchOutput --sourceMap",
|
|
19
|
+
"build": "rm -rf build && rm -rf tsconfig.tsbuildinfo && tsc --build --sourceMap",
|
|
20
|
+
"lint": "eslint src/ --ext .ts --cache",
|
|
21
|
+
"posttest": "pnpm lint",
|
|
22
|
+
"test": "rm -rf build && pnpm build --force && c8 --src src --all --check-coverage --100 --reporter text --reporter cobertura node --test build/test/*.test.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"build"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "24.12.2",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "8.0.0",
|
|
33
|
+
"@typescript-eslint/parser": "8.0.0",
|
|
34
|
+
"c8": "10.1.3",
|
|
35
|
+
"eslint": "8.57.0",
|
|
36
|
+
"typescript": "5.9.3"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@tryghost/errors": "1.3.8",
|
|
40
|
+
"@tryghost/mg-fs-utils": "workspace:*",
|
|
41
|
+
"@tryghost/string": "0.2.21"
|
|
42
|
+
}
|
|
43
|
+
}
|