@tryghost/mg-beehiiv-api 0.7.8-0 → 0.8.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.
Files changed (40) hide show
  1. package/README.md +69 -7
  2. package/build/index.d.ts +8 -9
  3. package/build/index.js +4 -8
  4. package/build/index.js.map +1 -1
  5. package/build/lib/fetch.d.ts +30 -5
  6. package/build/lib/fetch.js +58 -51
  7. package/build/lib/fetch.js.map +1 -1
  8. package/build/lib/ingest.d.ts +21 -0
  9. package/build/lib/ingest.js +31 -0
  10. package/build/lib/ingest.js.map +1 -0
  11. package/build/lib/map.d.ts +16 -0
  12. package/build/lib/map.js +128 -0
  13. package/build/lib/map.js.map +1 -0
  14. package/build/lib/types.d.ts +42 -0
  15. package/build/lib/types.js +3 -0
  16. package/build/lib/types.js.map +1 -0
  17. package/build/test/fetch.test.js +70 -285
  18. package/build/test/fetch.test.js.map +1 -1
  19. package/build/test/helpers.d.ts +24 -0
  20. package/build/test/helpers.js +72 -0
  21. package/build/test/helpers.js.map +1 -0
  22. package/build/test/index.test.js +7 -9
  23. package/build/test/index.test.js.map +1 -1
  24. package/build/test/ingest.test.js +79 -0
  25. package/build/test/ingest.test.js.map +1 -0
  26. package/build/test/map.test.js +199 -0
  27. package/build/test/map.test.js.map +1 -0
  28. package/package.json +9 -6
  29. package/build/lib/mapper.d.ts +0 -6
  30. package/build/lib/mapper.js +0 -120
  31. package/build/lib/mapper.js.map +0 -1
  32. package/build/lib/process.d.ts +0 -11
  33. package/build/lib/process.js +0 -279
  34. package/build/lib/process.js.map +0 -1
  35. package/build/test/mapper.test.js +0 -295
  36. package/build/test/mapper.test.js.map +0 -1
  37. package/build/test/process.test.js +0 -311
  38. package/build/test/process.test.js.map +0 -1
  39. /package/build/test/{mapper.test.d.ts → ingest.test.d.ts} +0 -0
  40. /package/build/test/{process.test.d.ts → map.test.d.ts} +0 -0
package/README.md CHANGED
@@ -57,10 +57,8 @@ It's possible to pass more options, in order to achieve a better migration file
57
57
  - Configure scraping tasks
58
58
  - string - default: `all`
59
59
  - Choices: `all`, `web`, `assets`, `none`
60
- - `all`: Scrape web metadata and download assets
61
- - `web`: Only scrape metadata from web pages
62
- - `assets`: Only download assets (images, media, files)
63
- - `none`: Skip all scraping tasks
60
+ - `all`, `assets`: Download assets (images, media, files)
61
+ - `web`, `none`: Skip downloading assets; this source does not scrape web pages
64
62
  - **`--subscribeLink`**
65
63
  - Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
66
64
  - string - default: `#/portal/signup`
@@ -73,6 +71,12 @@ It's possible to pass more options, in order to achieve a better migration file
73
71
  - **`--addTag`**
74
72
  - Provide a tag name which should be added to every post in this migration (wrap in single quotes if the name has spaces, e.g. `'From beehiiv'`)
75
73
  - string - default: `null`
74
+ - **`--rereadSource`**
75
+ - Fetch every post from the API again, replacing the stored source while preserving downloaded assets
76
+ - bool - default: `false`
77
+ - **`--postsPerFile`**
78
+ - Maximum posts written per Ghost import JSON file
79
+ - number - default: `2000`
76
80
  - **`--cache`**
77
81
  - Persist local cache after migration is complete (Only if `--zip` is `true`)
78
82
  - bool - default: `true`
@@ -83,14 +87,20 @@ It's possible to pass more options, in order to achieve a better migration file
83
87
  - Specify the full path where the final zip file will be saved to (Defaults to CWD)
84
88
  - string - default: `null`
85
89
  - **`--cacheName`**
86
- - Provide a unique name for the cache directory (defaults to a UUID)
87
- - string - default: `null`
90
+ - Provide a unique name for the cache directory
91
+ - string - default: one based on the publication ID
88
92
  - **`-V` `--verbose`**
89
93
  - Show verbose output
90
94
  - bool - default: `false`
91
95
  - **`--zip`**
92
96
  - Create a zip file (set to false to skip)
93
97
  - bool - default: `true`
98
+ - **`--report`**
99
+ - Write a `.report.json` migration report beside the import, or a `.failed-report.json` if the run fails
100
+ - bool - default: `false`
101
+ - **`--ghostApiUrl`**, **`--ghostAdminKey`**
102
+ - Match authors to existing Ghost users by email
103
+ - string - default: `null`
94
104
 
95
105
  A more complex migration command could look like this:
96
106
 
@@ -101,9 +111,61 @@ migrate beehiiv-api --key 1234abcd --id pub_abcd1234 --postsAfter 2024-01-01 --p
101
111
  This will migrate only posts published in 2024, and show all available output in the console.
102
112
 
103
113
 
114
+ ## Output
115
+
116
+ The import contains HTML; Ghost's importer converts it. A small migration writes `ghost-import.json`, and larger ones write `ghost-import-1.json`, `ghost-import-2.json` and so on, `--postsPerFile` posts each. With `--report`, a `.report.json` beside the ZIP (or in the workspace when `--zip false`) lists imported and skipped counts with diagnostics for repeated posts, skipped posts, field changes and slug changes. Posts without an ID, without any valid date, or with more than 500 authors or tags are skipped and reported. When every selected post is invalid, or the run fails, `--report` writes a `.failed-report.json` instead. An intentionally empty selection succeeds.
117
+
118
+ Each post gets its content tags, `--addTag` and `#beehiiv`, with internal `#` tags last, and its beehiiv authors, identified by name with a `<slug>@example.com` email that `--ghostApiUrl`/`--ghostAdminKey` can match to an existing Ghost user. Posts that were never published are dated when they were created.
119
+
120
+
121
+ ## Source storage
122
+
123
+ The first run fetches every post of the publication, ten per page with their free and premium web content, and stores them in an `mg-context` SQLite database in the workspace; later runs map the stored posts again without calling the API. Use `--rereadSource` to fetch them again. Without `--cacheName`, the workspace is keyed by the publication ID. The API key is never stored.
124
+
125
+ Each post is stored as a `post` record keyed by its ID. A post returned twice while paging keeps its first copy and reports a `source:conflict`.
126
+
127
+ `--postsAfter`, `--postsBefore`, `--addTag` and the content options apply when the stored posts are mapped, so changing them needs no new fetch. Ghost IDs derive from the publication ID and the post ID, tag slug or author slug, so they stay the same across runs.
128
+
129
+
130
+ ## Programmatic API
131
+
132
+ The package exports `parse`, `ingest` and `map` for use with `@tryghost/mg-context`, and `listPublications`. The caller owns the context, export and closure:
133
+
134
+ ```js
135
+ import {MigrateContext} from '@tryghost/mg-context';
136
+ import {ingest, map} from '@tryghost/mg-beehiiv-api';
137
+
138
+ const context = new MigrateContext({dbPath: './migration.sqlite'});
139
+ const rereadSource = process.argv.includes('--rereadSource');
140
+ await context.init();
141
+ try {
142
+ if (!context.sources.hasCompletedIngestion || rereadSource) {
143
+ await ingest('pub_abcd1234', context, {key: process.env.BEEHIIV_API_KEY, replace: rereadSource});
144
+ }
145
+ const summary = await map({postsAfter: '2024-01-01', addTag: 'From beehiiv'}, context);
146
+ for await (const file of context.writeGhostJsonStream('./output', {filename: 'ghost-import'})) {
147
+ // Consume one file descriptor at a time.
148
+ }
149
+ await context.writeMigrationReport('./migration.report.json', summary);
150
+ } finally {
151
+ await context.close();
152
+ }
153
+ ```
154
+
155
+ - `ingest(id, context, {key, replace, onProgress})` fetches the publication's posts into `context.sources` inside `context.sources.ingest()`, calling `onProgress(title)` before each page. Explicit `replace: true` is required when completed source data exists; a failed fetch keeps the previous data.
156
+ - `parse(id, {key, onProgress})` yields the same records as `SourceRecordInput` values, one page at a time, without storing them.
157
+ - `tasks({key, id})` returns one task per page; each task's `task(ctx)` writes its page into `ctx.sourceIngestion`, and `records()` fetches it without storing. `discover({key, id})` returns the post and page counts.
158
+ - `map(options, context, {ghostUsers?})` rebuilds mapped content and returns `{selected, imported, skipped}`. `options` takes `postsAfter`, `postsBefore`, `addTag`, `subscribeLink`, `comments` and `commentLink`, without the CLI's defaults. `ghostUsers` may be an iterable or async iterable of existing Ghost users; an author whose email matches keeps that user's Ghost ID.
159
+ - `listPublications(key)` lists the publications the key can read.
160
+
161
+ The previous default export (`fetchTasks` and `mapPostsTasks`, which built an array of posts in memory, and cached each page as a JSON file in the workspace) has been removed.
162
+
163
+ The CLI's programmatic `outputStorage.upload({body, fileName, size})` receives a Node readable stream as `body`, for the ZIP and, with `--report`, the report, and must consume it before resolving to the remote path. The uploaded ZIP is named like the local one, such as `gh-beehiiv-api-pub-abcd1234-1700000000000.zip`.
164
+
165
+
104
166
  ## HTML Processing
105
167
 
106
- The `processHTML` function transforms beehiiv email HTML into clean, Ghost-compatible HTML. It applies the following transformations in order:
168
+ Post content is converted with `processWebHTML` from `@tryghost/mg-beehiiv`, which shares it with the CSV migration's `processHTML` and `removeDuplicateFeatureImage`. It transforms beehiiv's web HTML into clean, Ghost-compatible HTML, applying the following transformations in order:
107
169
 
108
170
  1. **Variable replacement** — Removes beehiiv template variables (`{{subscriber_id}}`, `{{rp_refer_url}}`, etc.)
109
171
  2. **Content extraction** — Extracts content from `#content-blocks`
package/build/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { listPublications } from './lib/list-pubs.js';
2
- import { mapPostsTasks } from './lib/mapper.js';
3
- import { fetchTasks } from './lib/fetch.js';
4
- declare const _default: {
5
- listPublications: typeof listPublications;
6
- fetchTasks: typeof fetchTasks;
7
- mapPostsTasks: typeof mapPostsTasks;
8
- };
9
- export default _default;
1
+ export { listPublications } from './lib/list-pubs.js';
2
+ export { authedClient, discover, tasks } from './lib/fetch.js';
3
+ export type { FetchOptions, FetchTask, TaskContext } from './lib/fetch.js';
4
+ export { ingest, parse, sourcePublication } from './lib/ingest.js';
5
+ export type { IngestOptions, ParseOptions } from './lib/ingest.js';
6
+ export { ghostId, map } from './lib/map.js';
7
+ export type { MappingServices, MappingSummary } from './lib/map.js';
8
+ export type { BeehiivApiOptions, BeehiivApiPost } from './lib/types.js';
package/build/index.js CHANGED
@@ -1,9 +1,5 @@
1
- import { listPublications } from './lib/list-pubs.js';
2
- import { mapPostsTasks } from './lib/mapper.js';
3
- import { fetchTasks } from './lib/fetch.js';
4
- export default {
5
- listPublications,
6
- fetchTasks,
7
- mapPostsTasks
8
- };
1
+ export { listPublications } from './lib/list-pubs.js';
2
+ export { authedClient, discover, tasks } from './lib/fetch.js';
3
+ export { ingest, parse, sourcePublication } from './lib/ingest.js';
4
+ export { ghostId, map } from './lib/map.js';
9
5
  //# sourceMappingURL=index.js.map
@@ -1 +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,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAE1C,eAAe;IACX,gBAAgB;IAChB,UAAU;IACV,aAAa;CAChB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAC,OAAO,EAAE,GAAG,EAAC,MAAM,cAAc,CAAC"}
@@ -1,6 +1,31 @@
1
- declare const authedClient: (apiKey: string, theUrl: URL) => Promise<Response>;
2
- export declare const fetchTasks: (options: any, ctx: any) => Promise<{
1
+ import type { SourceIngestion, SourceRecordInput } from '@tryghost/mg-context';
2
+ /** The publication to fetch and the API key to fetch it with. */
3
+ export interface FetchOptions {
4
+ key: string;
5
+ id: string;
6
+ }
7
+ export interface TaskContext {
8
+ sourceIngestion?: SourceIngestion;
9
+ }
10
+ export interface FetchTask {
3
11
  title: string;
4
- task: (_: any, task: any) => Promise<void>;
5
- }[]>;
6
- export { authedClient };
12
+ page: number;
13
+ /** Fetch this page's records without storing them. */
14
+ records: () => Promise<SourceRecordInput[]>;
15
+ /** Fetch this page and write its records into `ctx.sourceIngestion`. */
16
+ task: (ctx: TaskContext) => Promise<void>;
17
+ }
18
+ declare const authedClient: (apiKey: string, theUrl: URL) => Promise<Response>;
19
+ /** The number of posts in a publication, and of pages to fetch them in. */
20
+ declare const discover: ({ key, id }: FetchOptions) => Promise<{
21
+ total: number;
22
+ pages: number;
23
+ }>;
24
+ /** Source records for one page of posts, keyed by post ID. */
25
+ declare const pageRecords: (posts: any[], page: number) => SourceRecordInput[];
26
+ /**
27
+ * One task per page of the publication's posts, in page order. Each task writes its page into
28
+ * `ctx.sourceIngestion` as `post` records; a post returned twice while paging keeps its first version.
29
+ */
30
+ declare const tasks: (options: FetchOptions) => Promise<FetchTask[]>;
31
+ export { authedClient, discover, tasks, pageRecords };
@@ -8,68 +8,75 @@ const authedClient = async (apiKey, theUrl) => {
8
8
  }
9
9
  });
10
10
  };
11
- const discover = async (key, pubId) => {
12
- const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}/posts`);
13
- url.searchParams.append('limit', '1');
11
+ const getJSON = async (key, url) => {
14
12
  const response = await authedClient(key, url);
15
13
  if (!response.ok) {
16
14
  throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
17
15
  }
18
- const data = await response.json();
19
- return data.total_results;
16
+ return response.json();
20
17
  };
21
- const cachedFetch = async ({ fileCache, key, pubId, limit = API_LIMIT, page }) => {
22
- let filename = `beehiiv_api_${limit}_${page}.json`;
23
- if (fileCache.hasFile(filename, 'tmp')) {
24
- return await fileCache.readTmpJSONFile(filename);
18
+ const postsURL = (id, params) => {
19
+ const url = new URL(`https://api.beehiiv.com/v2/publications/${id}/posts`);
20
+ for (const [name, value] of params) {
21
+ url.searchParams.append(name, value);
25
22
  }
26
- const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}/posts`);
27
- url.searchParams.append('limit', limit.toString());
28
- url.searchParams.append('expand', 'free_web_content');
29
- url.searchParams.append('expand', 'premium_web_content');
30
- url.searchParams.append('page', page.toString());
31
- const response = await authedClient(key, url);
32
- if (!response.ok) {
33
- throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
23
+ return url;
24
+ };
25
+ /** The number of posts in a publication, and of pages to fetch them in. */
26
+ const discover = async ({ key, id }) => {
27
+ const data = await getJSON(key, postsURL(id, [['limit', '1']]));
28
+ const total = Number(data.total_results) || 0;
29
+ return { total, pages: Math.ceil(total / API_LIMIT) };
30
+ };
31
+ /** One page of posts with their free and premium web content. */
32
+ const fetchPage = async ({ key, id }, page) => {
33
+ const url = postsURL(id, [
34
+ ['limit', String(API_LIMIT)],
35
+ ['expand', 'free_web_content'],
36
+ ['expand', 'premium_web_content'],
37
+ ['page', String(page)]
38
+ ]);
39
+ const data = await getJSON(key, url);
40
+ return data.data ?? [];
41
+ };
42
+ /** Source records for one page of posts, keyed by post ID. */
43
+ const pageRecords = (posts, page) => posts.map(post => ({
44
+ kind: 'post',
45
+ key: post.id || null,
46
+ content: JSON.stringify(post),
47
+ format: 'json',
48
+ metadata: { page }
49
+ }));
50
+ const stageFor = (ctx) => {
51
+ if (!ctx.sourceIngestion) {
52
+ throw new errors.IncorrectUsageError({
53
+ message: 'mg-beehiiv-api fetch tasks write into ctx.sourceIngestion; run them inside context.sources.ingest()'
54
+ });
34
55
  }
35
- const data = await response.json();
36
- await fileCache.writeTmpFile(data, filename);
37
- return data;
56
+ return ctx.sourceIngestion;
38
57
  };
39
- export const fetchTasks = async (options, ctx) => {
40
- const numberOfPosts = await discover(options.key, options.id);
41
- const totalPages = Math.ceil(numberOfPosts / API_LIMIT);
42
- let tasks = [];
43
- for (let page = 1; page <= totalPages; page++) {
44
- tasks.push({
45
- title: `Fetching posts page ${page} of ${totalPages}`,
46
- task: async (_, task) => {
47
- try {
48
- let response = await cachedFetch({
49
- fileCache: ctx.fileCache,
50
- key: options.key,
51
- pubId: options.id,
52
- page: page
53
- });
54
- ctx.result.posts = ctx.result.posts.concat(response.data);
55
- if (options.postsAfter) {
56
- const afterTimestamp = new Date(options.postsAfter).getTime() / 1000;
57
- ctx.result.posts = ctx.result.posts.filter((post) => post.publish_date >= afterTimestamp);
58
- }
59
- if (options.postsBefore) {
60
- const beforeTimestamp = new Date(options.postsBefore).getTime() / 1000;
61
- ctx.result.posts = ctx.result.posts.filter((post) => post.publish_date <= beforeTimestamp);
62
- }
63
- }
64
- catch (error) {
65
- const errorMessage = error instanceof Error ? error.message : String(error);
66
- task.output = errorMessage;
67
- throw error;
58
+ /**
59
+ * One task per page of the publication's posts, in page order. Each task writes its page into
60
+ * `ctx.sourceIngestion` as `post` records; a post returned twice while paging keeps its first version.
61
+ */
62
+ const tasks = async (options) => {
63
+ const { pages } = await discover(options);
64
+ const list = [];
65
+ for (let page = 1; page <= pages; page++) {
66
+ const records = async () => pageRecords(await fetchPage(options, page), page);
67
+ list.push({
68
+ title: `Fetching posts page ${page} of ${pages}`,
69
+ page,
70
+ records,
71
+ task: async (ctx) => {
72
+ const stage = stageFor(ctx);
73
+ for (const record of await records()) {
74
+ stage.reconcile(record);
68
75
  }
69
76
  }
70
77
  });
71
78
  }
72
- return tasks;
79
+ return list;
73
80
  };
74
- export { authedClient };
81
+ export { authedClient, discover, tasks, pageRecords };
75
82
  //# sourceMappingURL=fetch.js.map
@@ -1 +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,EAAE,CAAC;AAErB,MAAM,YAAY,GAAG,KAAK,EAAE,MAAc,EAAE,MAAW,EAAE,EAAE;IACvD,OAAO,KAAK,CAAC,MAAM,EAAE;QACjB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACL,aAAa,EAAE,UAAU,MAAM,EAAE;SACpC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAW,EAAE,KAAa,EAAE,EAAE;IAClD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,2CAA2C,KAAK,QAAQ,CAAC,CAAC;IAC9E,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE9C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC,EAAC,OAAO,EAAE,mBAAmB,QA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,EAAE,IAAI,EAAE,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,CAAC;YACN,KAAK,EAAE,uBAAuB,IAAI,OAAO,KAAK,EAAE;YAChD,IAAI;YACJ,OAAO;YACP,IAAI,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE;gBACd,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC5B,KAAK,MAAM,MAAM,IAAI,MAAM,OAAO,EAAE,EAAE,CAAC;oBACnC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC5B,CAAC;YACL,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { MigrateContext, SourceRecordInput } from '@tryghost/mg-context';
2
+ export interface ParseOptions {
3
+ /** The beehiiv API key. It is used for requests only and never stored. */
4
+ key: string;
5
+ /** Called with each page's title before it is fetched. */
6
+ onProgress?: (title: string) => void;
7
+ }
8
+ export interface IngestOptions extends ParseOptions {
9
+ /** Replace completed source data. Without it, ingesting into a context that has source data throws. */
10
+ replace?: boolean;
11
+ }
12
+ /** Yield the source records for every page of a publication's posts, one page at a time, without storing them. */
13
+ export declare function parse(id: string, { key, onProgress }: ParseOptions): AsyncGenerator<SourceRecordInput>;
14
+ /**
15
+ * Fetch every post of a beehiiv publication into `context.sources` as `post` records keyed by post ID, with their
16
+ * free and premium web content. Every page is fetched; `map()` applies the date filters. A post returned twice
17
+ * while paging keeps its first version and reports a `source:conflict`.
18
+ */
19
+ export declare function ingest(id: string, context: MigrateContext, { key, replace, onProgress }: IngestOptions): Promise<void>;
20
+ /** The publication ID stored with the completed ingestion. */
21
+ export declare function sourcePublication(context: MigrateContext): string;
@@ -0,0 +1,31 @@
1
+ import { tasks } from './fetch.js';
2
+ /** Yield the source records for every page of a publication's posts, one page at a time, without storing them. */
3
+ export async function* parse(id, { key, onProgress }) {
4
+ for (const task of await tasks({ key, id })) {
5
+ onProgress?.(task.title);
6
+ yield* await task.records();
7
+ }
8
+ }
9
+ /**
10
+ * Fetch every post of a beehiiv publication into `context.sources` as `post` records keyed by post ID, with their
11
+ * free and premium web content. Every page is fetched; `map()` applies the date filters. A post returned twice
12
+ * while paging keeps its first version and reports a `source:conflict`.
13
+ */
14
+ export async function ingest(id, context, { key, replace = false, onProgress }) {
15
+ await context.sources.ingest({ replace, metadata: { adapter: 'beehiiv-api', publication: id } }, async (stage) => {
16
+ const ctx = { sourceIngestion: stage };
17
+ for (const task of await tasks({ key, id })) {
18
+ onProgress?.(task.title);
19
+ await task.task(ctx);
20
+ }
21
+ });
22
+ }
23
+ /** The publication ID stored with the completed ingestion. */
24
+ export function sourcePublication(context) {
25
+ const id = context.sources.currentIngestion?.metadata.publication;
26
+ if (typeof id !== 'string' || !id) {
27
+ throw new Error('Completed beehiiv API source data has no publication ID.');
28
+ }
29
+ return id;
30
+ }
31
+ //# sourceMappingURL=ingest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../src/lib/ingest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAmB,MAAM,YAAY,CAAC;AAcnD,kHAAkH;AAClH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,KAAK,CAAC,EAAU,EAAE,EAAC,GAAG,EAAE,UAAU,EAAe;IACpE,KAAK,MAAM,IAAI,IAAI,MAAM,KAAK,CAAC,EAAC,GAAG,EAAE,EAAE,EAAC,CAAC,EAAE,CAAC;QACxC,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CACxB,EAAU,EACV,OAAuB,EACvB,EAAC,GAAG,EAAE,OAAO,GAAG,KAAK,EAAE,UAAU,EAAgB;IAEjD,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAE,EAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAC,EAAC,EAAE,KAAK,EAAC,KAAK,EAAC,EAAE;QACvG,MAAM,GAAG,GAAgB,EAAC,eAAe,EAAE,KAAK,EAAC,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,MAAM,KAAK,CAAC,EAAC,GAAG,EAAE,EAAE,EAAC,CAAC,EAAE,CAAC;YACxC,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAAC,OAAuB;IACrD,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAAC;IAClE,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { MigrateContext } from '@tryghost/mg-context';
2
+ import type { MappingSummary } from '@tryghost/mg-context';
3
+ import type { GhostUser } from '@tryghost/mg-ghost-authors';
4
+ import type { BeehiivApiOptions } from './types.js';
5
+ export type { MappingSummary };
6
+ export interface MappingServices {
7
+ /** Existing Ghost users; an author whose placeholder email matches one keeps that user's ID. */
8
+ ghostUsers?: Iterable<GhostUser> | AsyncIterable<GhostUser>;
9
+ }
10
+ export declare function ghostId(publication: string, kind: string, key: string): string;
11
+ /**
12
+ * Rebuild posts, tags and authors from the stored API posts. The date filters, `addTag` and the content options
13
+ * apply here, so changing them needs no new fetch. Posts without an ID or any valid date are skipped with a
14
+ * `record:skipped` diagnostic.
15
+ */
16
+ export declare function map(options: BeehiivApiOptions, context: MigrateContext, services?: MappingServices): Promise<MappingSummary>;
@@ -0,0 +1,128 @@
1
+ import { PostContext, MappingState, RecordDataError, ghostId as coreGhostId } from '@tryghost/mg-context';
2
+ import { namedAuthor, namedTag, processWebHTML, publicFirst, rememberGhostUsers, removeDuplicateFeatureImage } from '@tryghost/mg-beehiiv';
3
+ import { slugify } from '@tryghost/string';
4
+ import { stringUtils } from '@tryghost/mg-utils';
5
+ import { sourcePublication } from './ingest.js';
6
+ /** Ghost relationship limits for one post. */
7
+ const MAX_RELATIONS = 500;
8
+ export function ghostId(publication, kind, key) {
9
+ return coreGhostId('mg-beehiiv-api:1', publication, kind, key);
10
+ }
11
+ function visibility(webTargets = []) {
12
+ const tiers = new Set(webTargets.map(target => target.tier));
13
+ if (tiers.has('free') && tiers.has('premium')) {
14
+ return 'members';
15
+ }
16
+ return tiers.has('premium') ? 'paid' : 'public';
17
+ }
18
+ function status(item) {
19
+ return item.platform !== 'email' && item.status === 'confirmed' ? 'published' : 'draft';
20
+ }
21
+ /** A Unix time in seconds as a date, or `null` when there is none. */
22
+ function unixDate(value) {
23
+ return typeof value === 'number' && Number.isFinite(value) ? new Date(value * 1000) : null;
24
+ }
25
+ /**
26
+ * `--postsAfter` and `--postsBefore` compare the publish date with the start of each day, as they always have.
27
+ * Posts never published have no publish date: `--postsAfter` leaves them out and `--postsBefore` keeps them.
28
+ */
29
+ function inDateRange(item, after, before) {
30
+ const published = item.publish_date;
31
+ return !((after !== null && !(published >= after)) || (before !== null && !(published <= before)));
32
+ }
33
+ /** A date option as Unix seconds, or `null` when it is not set. */
34
+ function dayStart(name, value) {
35
+ if (!value) {
36
+ return null;
37
+ }
38
+ const time = Date.parse(value);
39
+ if (!Number.isFinite(time)) {
40
+ throw new Error(`Invalid ${name} date: ${value}`);
41
+ }
42
+ return time / 1000;
43
+ }
44
+ /**
45
+ * Rebuild posts, tags and authors from the stored API posts. The date filters, `addTag` and the content options
46
+ * apply here, so changing them needs no new fetch. Posts without an ID or any valid date are skipped with a
47
+ * `record:skipped` diagnostic.
48
+ */
49
+ export async function map(options, context, services = {}) {
50
+ if (!context.sources.hasCompletedIngestion) {
51
+ throw new Error('Ingest complete beehiiv API source data before mapping.');
52
+ }
53
+ const publication = sourcePublication(context);
54
+ const after = dayStart('postsAfter', options.postsAfter);
55
+ const before = dayStart('postsBefore', options.postsBefore);
56
+ const addTag = options.addTag?.trim();
57
+ const idFor = (kind, key) => ghostId(publication, kind, key);
58
+ const state = new MappingState(context, 'mg-beehiiv-api');
59
+ return context.rebuildMappedContent(async () => {
60
+ await rememberGhostUsers(state, services.ghostUsers);
61
+ return context.mapRecords(context.sources.records({ kind: 'post' }), async (record) => {
62
+ const item = JSON.parse(record.content);
63
+ if (!inDateRange(item, after, before)) {
64
+ return false;
65
+ }
66
+ if (!record.key) {
67
+ throw new RecordDataError('Post has no ID');
68
+ }
69
+ const published = unixDate(item.publish_date);
70
+ const created = unixDate(item.created) ?? published;
71
+ if (!created) {
72
+ throw new RecordDataError('Invalid beehiiv post dates');
73
+ }
74
+ const authors = (item.authors ?? []).filter(name => typeof name === 'string' && name.trim());
75
+ const tags = (item.content_tags ?? [])
76
+ .filter(name => typeof name === 'string' && name.trim())
77
+ .map(name => namedTag(name.trim(), idFor));
78
+ tags.push(namedTag('#beehiiv', idFor, 'hash-beehiiv'));
79
+ if (addTag) {
80
+ tags.push(namedTag(addTag, idFor));
81
+ }
82
+ if (authors.length > MAX_RELATIONS || tags.length > MAX_RELATIONS) {
83
+ throw new RecordDataError('Post exceeds Ghost author/tag relationship limits');
84
+ }
85
+ const post = new PostContext({ lookupKey: record.key });
86
+ post.ghostId = idFor('post', record.key);
87
+ post.set('title', item.title ?? '');
88
+ post.set('slug', item.slug || slugify(item.title) || slugify(record.key));
89
+ post.set('comment_id', record.key);
90
+ post.set('created_at', created);
91
+ // Posts never published are dated when they were created.
92
+ post.set('published_at', published ?? created);
93
+ post.set('updated_at', published ?? created);
94
+ post.set('type', 'post');
95
+ post.set('status', status(item));
96
+ post.set('custom_excerpt', item.subtitle || null);
97
+ post.set('visibility', visibility(item.web_targets));
98
+ post.set('feature_image', item.thumbnail_url || null);
99
+ post.set('og_title', item.meta_default_title || null);
100
+ post.set('og_description', item.meta_default_description || null);
101
+ let html = processWebHTML({
102
+ html: item.content?.premium?.web ?? item.content?.free?.web,
103
+ url: item.web_url,
104
+ options
105
+ });
106
+ if (item.thumbnail_url) {
107
+ html = removeDuplicateFeatureImage({ html, featureSrc: item.thumbnail_url });
108
+ }
109
+ post.set('html', html);
110
+ for (const name of authors) {
111
+ const author = namedAuthor(state, name, idFor);
112
+ post.addAuthor(author);
113
+ context.sources.link(record.id, { type: 'author', id: author.dbId });
114
+ }
115
+ for (const tag of publicFirst(tags)) {
116
+ tag.save(context.db);
117
+ post.addTag(tag);
118
+ context.sources.link(record.id, { type: 'tag', id: tag.dbId });
119
+ }
120
+ post.save(context.db);
121
+ context.sources.link(record.id, { type: 'post', id: post.dbId });
122
+ if (item.web_url && URL.canParse(item.web_url)) {
123
+ context.addLink(stringUtils.cleanURL(item.web_url), `/${post.get('slug')}/`);
124
+ }
125
+ });
126
+ });
127
+ }
128
+ //# sourceMappingURL=map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/lib/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,IAAI,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAGxH,OAAO,EACH,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,kBAA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BAC/C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACvB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,IAAK,EAAC,CAAC,CAAC;YACxE,CAAC;YACD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,IAAK,EAAC,CAAC,CAAC;YAClE,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,IAAK,EAAC,CAAC,CAAC;YAChE,IAAI,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7C,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjF,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { ContentOptions } from '@tryghost/mg-beehiiv';
2
+ /** A post from beehiiv's `GET /v2/publications/:id/posts`, with expanded web content. */
3
+ export interface BeehiivApiPost {
4
+ id: string;
5
+ title: string;
6
+ subtitle?: string | null;
7
+ authors?: string[];
8
+ /** Unix time in seconds. */
9
+ created?: number | null;
10
+ status?: 'archived' | 'confirmed' | 'draft';
11
+ /** Unix time in seconds; `null` for posts never published. */
12
+ publish_date?: number | null;
13
+ slug?: string;
14
+ thumbnail_url?: string;
15
+ web_url?: string;
16
+ platform?: 'web' | 'email' | 'both';
17
+ content_tags?: string[];
18
+ meta_default_description?: string | null;
19
+ meta_default_title?: string | null;
20
+ web_targets?: {
21
+ tier: 'free' | 'premium';
22
+ [key: string]: unknown;
23
+ }[];
24
+ content?: {
25
+ free?: {
26
+ web?: string;
27
+ };
28
+ premium?: {
29
+ web?: string;
30
+ };
31
+ };
32
+ [key: string]: unknown;
33
+ }
34
+ export interface BeehiivApiOptions extends Omit<ContentOptions, 'url'> {
35
+ /** Only posts published on or after this date. */
36
+ postsAfter?: string | null;
37
+ /** Only posts published on or before this date. */
38
+ postsBefore?: string | null;
39
+ /** A tag added to every post. */
40
+ addTag?: string | null;
41
+ [key: string]: any;
42
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+ /* c8 ignore stop */
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":";AAsCA,oBAAoB"}