@sillsdev/docu-notion 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -0
  3. package/dist/FlatGuidLayoutStrategy.d.ts +6 -0
  4. package/dist/FlatGuidLayoutStrategy.js +25 -0
  5. package/dist/HierarchicalNamedLayoutStrategy.d.ts +7 -0
  6. package/dist/HierarchicalNamedLayoutStrategy.js +80 -0
  7. package/dist/LayoutStrategy.d.ts +12 -0
  8. package/dist/LayoutStrategy.js +83 -0
  9. package/dist/MakeImagePersistencePlan.d.ts +2 -0
  10. package/dist/MakeImagePersistencePlan.js +66 -0
  11. package/dist/NotionImage-CaptionReading.spec.d.ts +1 -0
  12. package/dist/NotionImage-CaptionReading.spec.js +233 -0
  13. package/dist/NotionPage.d.ts +45 -0
  14. package/dist/NotionPage.js +229 -0
  15. package/dist/NotionPage.spec.d.ts +1 -0
  16. package/dist/NotionPage.spec.js +143 -0
  17. package/dist/config/configuration.d.ts +5 -0
  18. package/dist/config/configuration.js +86 -0
  19. package/dist/config/default.docunotion.config.d.ts +3 -0
  20. package/dist/config/default.docunotion.config.js +37 -0
  21. package/dist/images.d.ts +24 -0
  22. package/dist/images.js +230 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.js +37 -0
  25. package/dist/log.d.ts +11 -0
  26. package/dist/log.js +61 -0
  27. package/dist/makeImagePersistencePlan.spec.d.ts +1 -0
  28. package/dist/makeImagePersistencePlan.spec.js +35 -0
  29. package/dist/notion-styles.css +58 -0
  30. package/dist/plugins/CalloutTransformer.d.ts +24 -0
  31. package/dist/plugins/CalloutTransformer.js +88 -0
  32. package/dist/plugins/CalloutTransformer.spec.d.ts +1 -0
  33. package/dist/plugins/CalloutTransformer.spec.js +199 -0
  34. package/dist/plugins/ColumnListTransformer.d.ts +2 -0
  35. package/dist/plugins/ColumnListTransformer.js +34 -0
  36. package/dist/plugins/ColumnTransformer.d.ts +2 -0
  37. package/dist/plugins/ColumnTransformer.js +67 -0
  38. package/dist/plugins/EscapeHtmlBlockModifier.d.ts +2 -0
  39. package/dist/plugins/EscapeHtmlBlockModifier.js +41 -0
  40. package/dist/plugins/EscapeHtmlBlockModifier.spec.d.ts +1 -0
  41. package/dist/plugins/EscapeHtmlBlockModifier.spec.js +130 -0
  42. package/dist/plugins/HeadingTranformer.spec.d.ts +1 -0
  43. package/dist/plugins/HeadingTranformer.spec.js +46 -0
  44. package/dist/plugins/HeadingTransformer.d.ts +2 -0
  45. package/dist/plugins/HeadingTransformer.js +63 -0
  46. package/dist/plugins/NumberedListTransformer.d.ts +2 -0
  47. package/dist/plugins/NumberedListTransformer.js +55 -0
  48. package/dist/plugins/NumberedListTransformer.spec.d.ts +1 -0
  49. package/dist/plugins/NumberedListTransformer.spec.js +86 -0
  50. package/dist/plugins/TableTransformer.d.ts +5 -0
  51. package/dist/plugins/TableTransformer.js +70 -0
  52. package/dist/plugins/embedTweaks.d.ts +5 -0
  53. package/dist/plugins/embedTweaks.js +46 -0
  54. package/dist/plugins/embedTweaks.spec.d.ts +1 -0
  55. package/dist/plugins/embedTweaks.spec.js +230 -0
  56. package/dist/plugins/externalLinks.d.ts +2 -0
  57. package/dist/plugins/externalLinks.js +26 -0
  58. package/dist/plugins/externalLinks.spec.d.ts +1 -0
  59. package/dist/plugins/externalLinks.spec.js +132 -0
  60. package/dist/plugins/internalLinks.d.ts +7 -0
  61. package/dist/plugins/internalLinks.js +102 -0
  62. package/dist/plugins/internalLinks.spec.d.ts +1 -0
  63. package/dist/plugins/internalLinks.spec.js +505 -0
  64. package/dist/plugins/mermaidLinkPlugin.spec.d.ts +1 -0
  65. package/dist/plugins/mermaidLinkPlugin.spec.js +77 -0
  66. package/dist/plugins/pluginTestRun.d.ts +10 -0
  67. package/dist/plugins/pluginTestRun.js +252 -0
  68. package/dist/plugins/pluginTypes.d.ts +44 -0
  69. package/dist/plugins/pluginTypes.js +2 -0
  70. package/dist/pull.d.ts +12 -0
  71. package/dist/pull.js +255 -0
  72. package/dist/run.d.ts +1 -0
  73. package/dist/run.js +35 -0
  74. package/dist/transform.d.ts +6 -0
  75. package/dist/transform.js +200 -0
  76. package/dist/types.d.ts +8 -0
  77. package/dist/types.js +2 -0
  78. package/package.json +103 -0
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const images_1 = require("./images");
13
+ const kPrimaryImageUrl = "https://s3.us-west-2.amazonaws.com/primaryImage.png?Blah=foo";
14
+ /* didn't work?
15
+ beforeAll(async () => {
16
+ console.log("before");
17
+ await initImageHandling("", "", []);
18
+ console.log("azfter");
19
+ });
20
+ */
21
+ /* eslint-disable @typescript-eslint/require-await */
22
+ test("finds primary image url", () => __awaiter(void 0, void 0, void 0, function* () {
23
+ yield (0, images_1.initImageHandling)("", "", []);
24
+ const img = (0, images_1.parseImageBlock)(kImageBlockWithTwoLocalizedImages.image);
25
+ expect(img.primaryUrl).toBe(kPrimaryImageUrl);
26
+ }));
27
+ test("primary caption content after image links are removed", () => __awaiter(void 0, void 0, void 0, function* () {
28
+ yield (0, images_1.initImageHandling)("", "", []);
29
+ const img = (0, images_1.parseImageBlock)(kImageBlockWithTwoLocalizedImagesWrappedWithActualCaptionText.image);
30
+ // carriage returns seem to mess up the markdown, so should be removed
31
+ expect(img.caption).toBe("Caption before images. Caption after images.");
32
+ }));
33
+ test("gets localized image links", () => __awaiter(void 0, void 0, void 0, function* () {
34
+ yield (0, images_1.initImageHandling)("", "", []);
35
+ const img = (0, images_1.parseImageBlock)(kImageBlockWithTwoLocalizedImagesWrappedWithActualCaptionText.image);
36
+ expect(img.localizedUrls.length).toBe(2);
37
+ expect(img.localizedUrls[0].iso632Code).toBe("fr");
38
+ expect(img.localizedUrls[1].iso632Code).toBe("es");
39
+ expect(img.localizedUrls[0].url).toBe("https://i.imgur.com/pYmE7OJ.png");
40
+ expect(img.localizedUrls[1].url).toBe("https://i.imgur.com/8paSZ0i.png");
41
+ }));
42
+ const kImageBlockWithTwoLocalizedImagesWrappedWithActualCaptionText = {
43
+ object: "block",
44
+ id: "20b821b4-7c5b-41dc-8e30-92c23c125580",
45
+ parent: { type: "page_id", page_id: "9dd05134-0401-47f6-b159-1e6b76b9aad3" },
46
+ created_time: "2022-07-25T23:05:00.000Z",
47
+ last_edited_time: "2022-07-26T15:31:00.000Z",
48
+ created_by: { object: "user", id: "11fb7f16-0560-4aee-ab88-ed75a850cfc4" },
49
+ last_edited_by: {
50
+ object: "user",
51
+ id: "11fb7f16-0560-4aee-ab88-ed75a850cfc4",
52
+ },
53
+ has_children: false,
54
+ archived: false,
55
+ type: "image",
56
+ image: {
57
+ caption: [
58
+ {
59
+ type: "text",
60
+ text: { content: "Caption before images. fr-", link: null },
61
+ annotations: {
62
+ bold: false,
63
+ italic: false,
64
+ strikethrough: false,
65
+ underline: false,
66
+ code: false,
67
+ color: "default",
68
+ },
69
+ plain_text: "Caption before images.\nfr ",
70
+ href: null,
71
+ },
72
+ {
73
+ type: "text",
74
+ text: {
75
+ content: "https://i.imgur.com/pYmE7OJ.png",
76
+ link: { url: "https://i.imgur.com/pYmE7OJ.png" },
77
+ },
78
+ annotations: {
79
+ bold: false,
80
+ italic: false,
81
+ strikethrough: false,
82
+ underline: false,
83
+ code: false,
84
+ color: "default",
85
+ },
86
+ plain_text: "https://i.imgur.com/pYmE7OJ.png",
87
+ href: "https://i.imgur.com/pYmE7OJ.png",
88
+ },
89
+ {
90
+ type: "text",
91
+ text: { content: " es-", link: null },
92
+ annotations: {
93
+ bold: false,
94
+ italic: false,
95
+ strikethrough: false,
96
+ underline: false,
97
+ code: false,
98
+ color: "default",
99
+ },
100
+ plain_text: "\nES ",
101
+ href: null,
102
+ },
103
+ {
104
+ type: "text",
105
+ text: {
106
+ content: "https://i.imgur.com/8paSZ0i.png",
107
+ link: { url: "https://i.imgur.com/8paSZ0i.png" },
108
+ },
109
+ annotations: {
110
+ bold: false,
111
+ italic: false,
112
+ strikethrough: false,
113
+ underline: false,
114
+ code: false,
115
+ color: "default",
116
+ },
117
+ plain_text: "https://i.imgur.com/8paSZ0i.png",
118
+ href: "https://i.imgur.com/8paSZ0i.png",
119
+ },
120
+ {
121
+ type: "text",
122
+ text: { content: "\nCaption after images", link: null },
123
+ annotations: {
124
+ bold: false,
125
+ italic: false,
126
+ strikethrough: false,
127
+ underline: false,
128
+ code: false,
129
+ color: "default",
130
+ },
131
+ plain_text: "\nCaption after images.",
132
+ href: null,
133
+ },
134
+ ],
135
+ type: "file",
136
+ file: {
137
+ url: kPrimaryImageUrl,
138
+ expiry_time: "2022-07-26T16:35:44.029Z",
139
+ },
140
+ },
141
+ };
142
+ const kImageBlockWithTwoLocalizedImages = {
143
+ object: "block",
144
+ id: "20b821b4-7c5b-41dc-8e30-92c23c125580",
145
+ parent: {
146
+ type: "page_id",
147
+ page_id: "9dd05134-0401-47f6-b159-1e6b76b9aad3",
148
+ },
149
+ created_time: "2022-07-25T23:05:00.000Z",
150
+ last_edited_time: "2022-07-25T23:07:00.000Z",
151
+ created_by: {
152
+ object: "user",
153
+ id: "11fb7f16-0560-4aee-ab88-ed75a850cfc4",
154
+ },
155
+ last_edited_by: {
156
+ object: "user",
157
+ id: "11fb7f16-0560-4aee-ab88-ed75a850cfc4",
158
+ },
159
+ has_children: false,
160
+ archived: false,
161
+ type: "image",
162
+ image: {
163
+ caption: [
164
+ {
165
+ type: "text",
166
+ text: { content: "fr-", link: null },
167
+ annotations: {
168
+ bold: false,
169
+ italic: false,
170
+ strikethrough: false,
171
+ underline: false,
172
+ code: false,
173
+ color: "default",
174
+ },
175
+ plain_text: "fr-",
176
+ href: null,
177
+ },
178
+ {
179
+ type: "text",
180
+ text: {
181
+ content: "https://i.imgur.com/pYmE7OJ.png",
182
+ link: { url: "https://i.imgur.com/pYmE7OJ.png" },
183
+ },
184
+ annotations: {
185
+ bold: false,
186
+ italic: false,
187
+ strikethrough: false,
188
+ underline: false,
189
+ code: false,
190
+ color: "default",
191
+ },
192
+ plain_text: "https://i.imgur.com/pYmE7OJ.png",
193
+ href: "https://i.imgur.com/pYmE7OJ.png",
194
+ },
195
+ {
196
+ type: "text",
197
+ text: { content: " es-", link: null },
198
+ annotations: {
199
+ bold: false,
200
+ italic: false,
201
+ strikethrough: false,
202
+ underline: false,
203
+ code: false,
204
+ color: "default",
205
+ },
206
+ plain_text: " es-",
207
+ href: null,
208
+ },
209
+ {
210
+ type: "text",
211
+ text: {
212
+ content: "https://i.imgur.com/8paSZ0i.png",
213
+ link: { url: "https://i.imgur.com/8paSZ0i.png" },
214
+ },
215
+ annotations: {
216
+ bold: false,
217
+ italic: false,
218
+ strikethrough: false,
219
+ underline: false,
220
+ code: false,
221
+ color: "default",
222
+ },
223
+ plain_text: "https://i.imgur.com/8paSZ0i.png",
224
+ href: "https://i.imgur.com/8paSZ0i.png",
225
+ },
226
+ ],
227
+ type: "file",
228
+ file: {
229
+ url: kPrimaryImageUrl,
230
+ expiry_time: "2022-07-26T00:19:09.096Z",
231
+ },
232
+ },
233
+ };
@@ -0,0 +1,45 @@
1
+ import { GetPageResponse } from "@notionhq/client/build/src/api-endpoints";
2
+ import { ListBlockChildrenResponseResults } from "notion-to-md/build/types";
3
+ export declare enum PageType {
4
+ DatabasePage = 0,
5
+ Simple = 1
6
+ }
7
+ export declare class NotionPage {
8
+ metadata: GetPageResponse;
9
+ pageId: string;
10
+ order: number;
11
+ layoutContext: string;
12
+ foundDirectlyInOutline: boolean;
13
+ constructor(args: {
14
+ layoutContext: string;
15
+ pageId: string;
16
+ order: number;
17
+ metadata: GetPageResponse;
18
+ foundDirectlyInOutline: boolean;
19
+ });
20
+ matchesLinkId(id: string): boolean;
21
+ get type(): PageType;
22
+ get nameOrTitle(): string;
23
+ nameForFile(): string;
24
+ private get title();
25
+ private get name();
26
+ private explicitSlug;
27
+ get slug(): string;
28
+ get hasExplicitSlug(): boolean;
29
+ get keywords(): string | undefined;
30
+ get status(): string | undefined;
31
+ getPlainTextProperty(property: string, defaultIfEmpty: string): string;
32
+ getSelectProperty(property: string): string | undefined;
33
+ getDateProperty(property: string, defaultIfEmpty: string, start?: boolean): string;
34
+ getContentInfo(children: ListBlockChildrenResponseResults): Promise<{
35
+ childPageIdsAndOrder: {
36
+ id: string;
37
+ order: number;
38
+ }[];
39
+ linksPageIdsAndOrder: {
40
+ id: string;
41
+ order: number;
42
+ }[];
43
+ hasParagraphs: boolean;
44
+ }>;
45
+ }
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NotionPage = exports.PageType = void 0;
13
+ const internalLinks_1 = require("./plugins/internalLinks");
14
+ // Notion has 2 kinds of pages: a normal one which is just content, and what I'm calling a "database page", which has whatever properties you put on it.
15
+ // docu-notion supports the later via links from outline pages. That is, you put the database pages in a database, then separately, in the outline, you
16
+ // create pages for each node of the outline and then add links from those to the database pages. In this way, we get the benefits of database
17
+ // pages (metadata, workflow, etc) and also normal pages (order, position in the outline).
18
+ var PageType;
19
+ (function (PageType) {
20
+ PageType[PageType["DatabasePage"] = 0] = "DatabasePage";
21
+ PageType[PageType["Simple"] = 1] = "Simple";
22
+ })(PageType = exports.PageType || (exports.PageType = {}));
23
+ class NotionPage {
24
+ constructor(args) {
25
+ this.layoutContext = args.layoutContext;
26
+ this.pageId = args.pageId;
27
+ this.order = args.order;
28
+ this.metadata = args.metadata;
29
+ this.foundDirectlyInOutline = args.foundDirectlyInOutline;
30
+ // review: this is expensive to learn as it takes another api call... I
31
+ // think? We can tell if it's a database because it has a "Name" instead of a
32
+ // "tile" and "parent": "type": "database_id". But do we need to differentiate
33
+ //this.type = PageType.Unknown;
34
+ }
35
+ matchesLinkId(id) {
36
+ const { baseLinkId } = (0, internalLinks_1.parseLinkId)(id);
37
+ const match = baseLinkId === this.pageId || // from a link_to_page.pageId, which still has the dashes
38
+ baseLinkId === this.pageId.replaceAll("-", ""); // from inline links, which are lacking the dashes
39
+ // logDebug(
40
+ // `matchedLinkId`,
41
+ // `comparing pageId:${this.pageId} to id ${id} --> ${match.toString()}`
42
+ // );
43
+ return match;
44
+ }
45
+ get type() {
46
+ /*
47
+ {
48
+ "object": "page",
49
+ "parent": {
50
+ "type": "page_id",
51
+ or
52
+ "type": "database_id",
53
+ ...
54
+ },
55
+ */
56
+ return this.metadata.parent.type === "database_id"
57
+ ? PageType.DatabasePage
58
+ : PageType.Simple;
59
+ }
60
+ // In Notion, pages from the Database have names and simple pages have titles.
61
+ get nameOrTitle() {
62
+ return this.type === PageType.DatabasePage ? this.name : this.title;
63
+ }
64
+ nameForFile() {
65
+ var _a;
66
+ // In Notion, pages from the Database have names and simple pages have titles.
67
+ return this.type === PageType.Simple
68
+ ? this.title
69
+ : // if it's a Database page, then we'll use the slug unless there is none, then we'd rather have the
70
+ // page name than an ugly id for the file name
71
+ ((_a = this.explicitSlug()) === null || _a === void 0 ? void 0 : _a.replace(/^\//, "")) || this.name;
72
+ }
73
+ // TODO: let's go farther in hiding this separate title vs name stuff. This seems like an implementation detail on the Notion side.
74
+ // In Notion, pages from the Outline have "title"'s.
75
+ get title() {
76
+ return this.getPlainTextProperty("title", "title missing");
77
+ }
78
+ // In Notion, pages from the Database have "Name"s.
79
+ get name() {
80
+ return this.getPlainTextProperty("Name", "name missing");
81
+ }
82
+ explicitSlug() {
83
+ const explicitSlug = this.getPlainTextProperty("Slug", "");
84
+ if (explicitSlug) {
85
+ if (explicitSlug === "/")
86
+ return explicitSlug;
87
+ // the root page
88
+ else
89
+ return ("/" +
90
+ encodeURIComponent(explicitSlug
91
+ .replace(/^\//, "")
92
+ // If for some reason someone types in a slug with special characters,
93
+ //we really don't want to see ugly entities in the URL, so first
94
+ // we replace a bunch of likely suspects with dashes. This will not
95
+ // adequately handle the case where there is one pag with slug:"foo-bar"
96
+ // and another with "foo?bar". Both will come out "foo-bar"
97
+ .replaceAll(" ", "-")
98
+ .replaceAll("?", "-")
99
+ .replaceAll("/", "-")
100
+ .replaceAll("#", "-")
101
+ .replaceAll("&", "-")
102
+ .replaceAll("%", "-")
103
+ // remove consecutive dashes
104
+ .replaceAll("--", "-")));
105
+ return undefined; // this page has no slug property
106
+ }
107
+ }
108
+ get slug() {
109
+ var _a;
110
+ return (_a = this.explicitSlug()) !== null && _a !== void 0 ? _a : "/" + this.pageId;
111
+ }
112
+ get hasExplicitSlug() {
113
+ return this.explicitSlug() !== undefined;
114
+ }
115
+ get keywords() {
116
+ return this.getPlainTextProperty("Keywords", "");
117
+ }
118
+ get status() {
119
+ return this.getSelectProperty("Status");
120
+ }
121
+ getPlainTextProperty(property, defaultIfEmpty) {
122
+ /* Notion strings look like this
123
+ "properties": {
124
+ "slug": {
125
+ "type": "rich_text",
126
+ ...
127
+ "rich_text": [
128
+ {
129
+ ...
130
+ "plain_text": "/",
131
+ }
132
+ ]
133
+ },
134
+ "Name": {
135
+ "type": "title",
136
+ "title": [
137
+ {
138
+ ...
139
+ "plain_text": "Intro",
140
+ },
141
+ {
142
+ ...
143
+ "plain_text": " to Notion",
144
+ }
145
+ ]
146
+ */
147
+ var _a;
148
+ //console.log("metadata:\n" + JSON.stringify(this.metadata, null, 2));
149
+ const p = (_a = this.metadata.properties) === null || _a === void 0 ? void 0 : _a[property];
150
+ //console.log(`prop ${property} = ${JSON.stringify(p)}`);
151
+ if (!p)
152
+ return defaultIfEmpty;
153
+ const textArray = p[p.type];
154
+ //console.log("textarray:" + JSON.stringify(textArray, null, 2));
155
+ return textArray && textArray.length
156
+ ? textArray
157
+ .map((item) => item.plain_text)
158
+ .join("")
159
+ : defaultIfEmpty;
160
+ }
161
+ getSelectProperty(property) {
162
+ /* Notion select values look like this
163
+ "properties": {
164
+ "Status": {
165
+ "id": "oB~%3D",
166
+ "type": "select",
167
+ "select": {
168
+ "id": "1",
169
+ "name": "Ready For Review",
170
+ "color": "red"
171
+ }
172
+ },
173
+ */
174
+ var _a, _b;
175
+ const p = (_a = this.metadata.properties) === null || _a === void 0 ? void 0 : _a[property];
176
+ if (!p) {
177
+ throw new Error(`missing ${property} in ${JSON.stringify(this.metadata, null, 2)}`);
178
+ return undefined;
179
+ }
180
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
181
+ return ((_b = p.select) === null || _b === void 0 ? void 0 : _b.name) || undefined;
182
+ }
183
+ getDateProperty(property, defaultIfEmpty, start = true) {
184
+ /* Notion dates look like this
185
+ "properties": {
186
+ "published_date":
187
+ {
188
+ "id":"a%3Cql",
189
+ "type":"date",
190
+ "date":{
191
+ "start":"2021-10-24",
192
+ "end":null,
193
+ "time_zone":null
194
+ }
195
+ }
196
+ }
197
+ */
198
+ var _a, _b, _c;
199
+ // console.log("metadata:\n" + JSON.stringify(this.metadata, null, 2));
200
+ const p = (_a = this.metadata.properties) === null || _a === void 0 ? void 0 : _a[property];
201
+ // console.log(`prop ${property} = ${JSON.stringify(p)}`);
202
+ if (!p)
203
+ return defaultIfEmpty;
204
+ if (start) {
205
+ return ((_b = p === null || p === void 0 ? void 0 : p.date) === null || _b === void 0 ? void 0 : _b.start) ? p.date.start : defaultIfEmpty;
206
+ }
207
+ else {
208
+ return ((_c = p === null || p === void 0 ? void 0 : p.date) === null || _c === void 0 ? void 0 : _c.end) ? p.date.end : defaultIfEmpty;
209
+ }
210
+ }
211
+ getContentInfo(children) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ for (let i = 0; i < children.length; i++) {
214
+ children[i].order = i;
215
+ }
216
+ return {
217
+ childPageIdsAndOrder: children
218
+ .filter((b) => b.type === "child_page")
219
+ .map((b) => ({ id: b.id, order: b.order })),
220
+ linksPageIdsAndOrder: children
221
+ .filter((b) => b.type === "link_to_page")
222
+ .map((b) => ({ id: b.link_to_page.page_id, order: b.order })),
223
+ hasParagraphs: children.some(b => b.type === "paragraph" &&
224
+ b.paragraph.rich_text.length > 0),
225
+ };
226
+ });
227
+ }
228
+ }
229
+ exports.NotionPage = NotionPage;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const NotionPage_1 = require("./NotionPage");
4
+ describe("NotionPage", () => {
5
+ const mockMetadata = {
6
+ object: "page",
7
+ id: "6e6921b9-b1f5-4614-ab3c-bf1a73358a1f",
8
+ created_time: "2023-04-11T10:17:00.000Z",
9
+ last_edited_time: "2023-04-13T20:24:00.000Z",
10
+ created_by: {
11
+ object: "user",
12
+ id: "USERID",
13
+ },
14
+ last_edited_by: {
15
+ object: "user",
16
+ id: "USERID",
17
+ },
18
+ cover: null,
19
+ icon: {
20
+ type: "file",
21
+ file: {
22
+ url: "https:/dummy_URL",
23
+ expiry_time: "2023-04-15T11:50:20.461Z",
24
+ },
25
+ },
26
+ parent: {
27
+ type: "workspace",
28
+ workspace: true,
29
+ },
30
+ archived: false,
31
+ properties: {
32
+ title: {
33
+ id: "title",
34
+ type: "title",
35
+ title: [
36
+ {
37
+ type: "text",
38
+ text: {
39
+ content: "Foo",
40
+ link: null,
41
+ },
42
+ annotations: {
43
+ bold: false,
44
+ italic: false,
45
+ strikethrough: false,
46
+ underline: false,
47
+ code: false,
48
+ color: "default",
49
+ },
50
+ plain_text: "Foo",
51
+ href: null,
52
+ },
53
+ {
54
+ type: "text",
55
+ text: {
56
+ content: "Bar",
57
+ link: null,
58
+ },
59
+ annotations: {
60
+ bold: false,
61
+ italic: false,
62
+ strikethrough: false,
63
+ underline: false,
64
+ code: false,
65
+ color: "default",
66
+ },
67
+ plain_text: "Bar",
68
+ href: null,
69
+ },
70
+ ],
71
+ },
72
+ date_property: {
73
+ id: "a%3Cql",
74
+ type: "date",
75
+ date: {
76
+ start: "2021-10-24",
77
+ end: "2021-10-28",
78
+ time_zone: null,
79
+ },
80
+ },
81
+ },
82
+ url: "https://www.notion.so/Site-docu-notion-PAGEID",
83
+ };
84
+ describe("getPlainTextProperty", () => {
85
+ it("should return the plain text value of a property", () => {
86
+ const page = new NotionPage_1.NotionPage({
87
+ layoutContext: "Test Context",
88
+ pageId: "123",
89
+ order: 1,
90
+ metadata: mockMetadata,
91
+ foundDirectlyInOutline: true,
92
+ });
93
+ const result = page.getPlainTextProperty("title", "");
94
+ expect(result).toBe("FooBar");
95
+ });
96
+ it("should return the default value if the property is not found", () => {
97
+ const page = new NotionPage_1.NotionPage({
98
+ layoutContext: "Test Context",
99
+ pageId: "123",
100
+ order: 1,
101
+ metadata: mockMetadata,
102
+ foundDirectlyInOutline: true,
103
+ });
104
+ const result = page.getPlainTextProperty("nonexistent", "Default Value");
105
+ expect(result).toBe("Default Value");
106
+ });
107
+ });
108
+ describe("getDateProperty", () => {
109
+ it("should return the start date property by default", () => {
110
+ const page = new NotionPage_1.NotionPage({
111
+ layoutContext: "Test Context",
112
+ pageId: "123",
113
+ order: 1,
114
+ metadata: mockMetadata,
115
+ foundDirectlyInOutline: true,
116
+ });
117
+ const result = page.getDateProperty("date_property", "");
118
+ expect(result).toBe("2021-10-24");
119
+ });
120
+ it("should return the end date if start is false", () => {
121
+ const page = new NotionPage_1.NotionPage({
122
+ layoutContext: "Test Context",
123
+ pageId: "123",
124
+ order: 1,
125
+ metadata: mockMetadata,
126
+ foundDirectlyInOutline: true,
127
+ });
128
+ const result = page.getDateProperty("date_property", "", false);
129
+ expect(result).toBe("2021-10-28");
130
+ });
131
+ it("should return the default value if the property is not found", () => {
132
+ const page = new NotionPage_1.NotionPage({
133
+ layoutContext: "Test Context",
134
+ pageId: "123",
135
+ order: 1,
136
+ metadata: mockMetadata,
137
+ foundDirectlyInOutline: true,
138
+ });
139
+ const result = page.getPlainTextProperty("nonexistent", "Default Value");
140
+ expect(result).toBe("Default Value");
141
+ });
142
+ });
143
+ });
@@ -0,0 +1,5 @@
1
+ import { IPlugin } from "../plugins/pluginTypes";
2
+ export type IDocuNotionConfig = {
3
+ plugins: IPlugin[];
4
+ };
5
+ export declare function loadConfigAsync(): Promise<IDocuNotionConfig>;