@notionx/core 0.1.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 (208) hide show
  1. package/dist/admin/index.d.ts +137 -0
  2. package/dist/admin/index.js +206 -0
  3. package/dist/admin/index.js.map +1 -0
  4. package/dist/admin/pages/index.d.ts +324 -0
  5. package/dist/admin/pages/index.js +827 -0
  6. package/dist/admin/pages/index.js.map +1 -0
  7. package/dist/auth/auth-pages/forgot-password.d.ts +20 -0
  8. package/dist/auth/auth-pages/forgot-password.js +70 -0
  9. package/dist/auth/auth-pages/forgot-password.js.map +1 -0
  10. package/dist/auth/auth-pages/index.d.ts +6 -0
  11. package/dist/auth/auth-pages/index.js +342 -0
  12. package/dist/auth/auth-pages/index.js.map +1 -0
  13. package/dist/auth/auth-pages/login.d.ts +30 -0
  14. package/dist/auth/auth-pages/login.js +125 -0
  15. package/dist/auth/auth-pages/login.js.map +1 -0
  16. package/dist/auth/auth-pages/register.d.ts +17 -0
  17. package/dist/auth/auth-pages/register.js +81 -0
  18. package/dist/auth/auth-pages/register.js.map +1 -0
  19. package/dist/auth/auth-pages/reset-password.d.ts +18 -0
  20. package/dist/auth/auth-pages/reset-password.js +72 -0
  21. package/dist/auth/auth-pages/reset-password.js.map +1 -0
  22. package/dist/auth/index.d.ts +72 -0
  23. package/dist/auth/index.js +1011 -0
  24. package/dist/auth/index.js.map +1 -0
  25. package/dist/auth/passwords.d.ts +6 -0
  26. package/dist/auth/passwords.js +79 -0
  27. package/dist/auth/passwords.js.map +1 -0
  28. package/dist/auth/rate-limit.d.ts +28 -0
  29. package/dist/auth/rate-limit.js +245 -0
  30. package/dist/auth/rate-limit.js.map +1 -0
  31. package/dist/auth/routes/google-callback.d.ts +6 -0
  32. package/dist/auth/routes/google-callback.js +404 -0
  33. package/dist/auth/routes/google-callback.js.map +1 -0
  34. package/dist/auth/routes/google.d.ts +6 -0
  35. package/dist/auth/routes/google.js +250 -0
  36. package/dist/auth/routes/google.js.map +1 -0
  37. package/dist/auth/routes/index.d.ts +22 -0
  38. package/dist/auth/routes/index.js +619 -0
  39. package/dist/auth/routes/index.js.map +1 -0
  40. package/dist/auth/routes/verify-email.d.ts +6 -0
  41. package/dist/auth/routes/verify-email.js +317 -0
  42. package/dist/auth/routes/verify-email.js.map +1 -0
  43. package/dist/auth/routes/viewer.d.ts +6 -0
  44. package/dist/auth/routes/viewer.js +372 -0
  45. package/dist/auth/routes/viewer.js.map +1 -0
  46. package/dist/auth/session.d.ts +9 -0
  47. package/dist/auth/session.js +1 -0
  48. package/dist/auth/session.js.map +1 -0
  49. package/dist/auth/turnstile.d.ts +20 -0
  50. package/dist/auth/turnstile.js +301 -0
  51. package/dist/auth/turnstile.js.map +1 -0
  52. package/dist/auth/user-session.d.ts +42 -0
  53. package/dist/auth/user-session.js +419 -0
  54. package/dist/auth/user-session.js.map +1 -0
  55. package/dist/auth/users.d.ts +112 -0
  56. package/dist/auth/users.js +558 -0
  57. package/dist/auth/users.js.map +1 -0
  58. package/dist/bootstrap-CN2g76M6.d.ts +67 -0
  59. package/dist/cache/index.d.ts +6 -0
  60. package/dist/cache/index.js +47 -0
  61. package/dist/cache/index.js.map +1 -0
  62. package/dist/content/admin-summary.d.ts +24 -0
  63. package/dist/content/admin-summary.js +36 -0
  64. package/dist/content/admin-summary.js.map +1 -0
  65. package/dist/content/index.d.ts +9 -0
  66. package/dist/content/index.js +473 -0
  67. package/dist/content/index.js.map +1 -0
  68. package/dist/content/models.d.ts +69 -0
  69. package/dist/content/models.js +24 -0
  70. package/dist/content/models.js.map +1 -0
  71. package/dist/content/prewarm.d.ts +28 -0
  72. package/dist/content/prewarm.js +56 -0
  73. package/dist/content/prewarm.js.map +1 -0
  74. package/dist/content/revalidate.d.ts +37 -0
  75. package/dist/content/revalidate.js +170 -0
  76. package/dist/content/revalidate.js.map +1 -0
  77. package/dist/content/search-index.d.ts +54 -0
  78. package/dist/content/search-index.js +172 -0
  79. package/dist/content/search-index.js.map +1 -0
  80. package/dist/content/search.d.ts +8 -0
  81. package/dist/content/search.js +57 -0
  82. package/dist/content/search.js.map +1 -0
  83. package/dist/doctor/cli.d.ts +1 -0
  84. package/dist/doctor/cli.js +360 -0
  85. package/dist/doctor/cli.js.map +1 -0
  86. package/dist/doctor/index.d.ts +139 -0
  87. package/dist/doctor/index.js +289 -0
  88. package/dist/doctor/index.js.map +1 -0
  89. package/dist/email/index.d.ts +38 -0
  90. package/dist/email/index.js +126 -0
  91. package/dist/email/index.js.map +1 -0
  92. package/dist/env-C5qu-0R-.d.ts +35 -0
  93. package/dist/hooks/index.d.ts +2 -0
  94. package/dist/hooks/index.js +1 -0
  95. package/dist/hooks/index.js.map +1 -0
  96. package/dist/i18n/index.d.ts +26 -0
  97. package/dist/i18n/index.js +73 -0
  98. package/dist/i18n/index.js.map +1 -0
  99. package/dist/index.d.ts +8 -0
  100. package/dist/index.js +1281 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/internal/admin/index.d.ts +75 -0
  103. package/dist/internal/admin/index.js +365 -0
  104. package/dist/internal/admin/index.js.map +1 -0
  105. package/dist/media/index.d.ts +24 -0
  106. package/dist/media/index.js +86 -0
  107. package/dist/media/index.js.map +1 -0
  108. package/dist/media/routes/index.d.ts +1 -0
  109. package/dist/media/routes/index.js +585 -0
  110. package/dist/media/routes/index.js.map +1 -0
  111. package/dist/media/routes/notion-media.d.ts +19 -0
  112. package/dist/media/routes/notion-media.js +588 -0
  113. package/dist/media/routes/notion-media.js.map +1 -0
  114. package/dist/middleware.d.ts +95 -0
  115. package/dist/middleware.js +79 -0
  116. package/dist/middleware.js.map +1 -0
  117. package/dist/notion/block-text.d.ts +5 -0
  118. package/dist/notion/block-text.js +37 -0
  119. package/dist/notion/block-text.js.map +1 -0
  120. package/dist/notion/blocks.d.ts +24 -0
  121. package/dist/notion/blocks.js +46 -0
  122. package/dist/notion/blocks.js.map +1 -0
  123. package/dist/notion/client.d.ts +7 -0
  124. package/dist/notion/client.js +13 -0
  125. package/dist/notion/client.js.map +1 -0
  126. package/dist/notion/config.d.ts +25 -0
  127. package/dist/notion/config.js +147 -0
  128. package/dist/notion/config.js.map +1 -0
  129. package/dist/notion/content-cache.d.ts +45 -0
  130. package/dist/notion/content-cache.js +166 -0
  131. package/dist/notion/content-cache.js.map +1 -0
  132. package/dist/notion/generic-source.d.ts +61 -0
  133. package/dist/notion/generic-source.js +408 -0
  134. package/dist/notion/generic-source.js.map +1 -0
  135. package/dist/notion/index.d.ts +13 -0
  136. package/dist/notion/index.js +1278 -0
  137. package/dist/notion/index.js.map +1 -0
  138. package/dist/notion/mappers.d.ts +1 -0
  139. package/dist/notion/mappers.js +152 -0
  140. package/dist/notion/mappers.js.map +1 -0
  141. package/dist/notion/media.d.ts +22 -0
  142. package/dist/notion/media.js +209 -0
  143. package/dist/notion/media.js.map +1 -0
  144. package/dist/notion/property-mappers.d.ts +24 -0
  145. package/dist/notion/property-mappers.js +152 -0
  146. package/dist/notion/property-mappers.js.map +1 -0
  147. package/dist/notion/routes/index.d.ts +8 -0
  148. package/dist/notion/routes/index.js +428 -0
  149. package/dist/notion/routes/index.js.map +1 -0
  150. package/dist/notion/routes/webhook.d.ts +98 -0
  151. package/dist/notion/routes/webhook.js +428 -0
  152. package/dist/notion/routes/webhook.js.map +1 -0
  153. package/dist/notion/types.d.ts +152 -0
  154. package/dist/notion/types.js +1 -0
  155. package/dist/notion/types.js.map +1 -0
  156. package/dist/notion/webhook.d.ts +83 -0
  157. package/dist/notion/webhook.js +490 -0
  158. package/dist/notion/webhook.js.map +1 -0
  159. package/dist/platform/capabilities.d.ts +34 -0
  160. package/dist/platform/capabilities.js +42 -0
  161. package/dist/platform/capabilities.js.map +1 -0
  162. package/dist/platform/current.d.ts +13 -0
  163. package/dist/platform/current.js +181 -0
  164. package/dist/platform/current.js.map +1 -0
  165. package/dist/platform/index.d.ts +5 -0
  166. package/dist/platform/index.js +269 -0
  167. package/dist/platform/index.js.map +1 -0
  168. package/dist/platform/runtime.d.ts +118 -0
  169. package/dist/platform/runtime.js +160 -0
  170. package/dist/platform/runtime.js.map +1 -0
  171. package/dist/platform/selection.d.ts +10 -0
  172. package/dist/platform/selection.js +22 -0
  173. package/dist/platform/selection.js.map +1 -0
  174. package/dist/storage/index.d.ts +17 -0
  175. package/dist/storage/index.js +218 -0
  176. package/dist/storage/index.js.map +1 -0
  177. package/dist/storage/routes/cdn.d.ts +19 -0
  178. package/dist/storage/routes/cdn.js +289 -0
  179. package/dist/storage/routes/cdn.js.map +1 -0
  180. package/dist/storage/routes/files.d.ts +27 -0
  181. package/dist/storage/routes/files.js +216 -0
  182. package/dist/storage/routes/files.js.map +1 -0
  183. package/dist/storage/routes/index.d.ts +2 -0
  184. package/dist/storage/routes/index.js +352 -0
  185. package/dist/storage/routes/index.js.map +1 -0
  186. package/dist/types-BsAcZSNX.d.ts +94 -0
  187. package/dist/types.d.ts +78 -0
  188. package/dist/types.js +1 -0
  189. package/dist/types.js.map +1 -0
  190. package/dist/util/index.d.ts +18 -0
  191. package/dist/util/index.js +48 -0
  192. package/dist/util/index.js.map +1 -0
  193. package/dist/worker/index.d.ts +6 -0
  194. package/dist/worker/index.js +1026 -0
  195. package/dist/worker/index.js.map +1 -0
  196. package/dist/worker/routes/content-prewarm.d.ts +34 -0
  197. package/dist/worker/routes/content-prewarm.js +38 -0
  198. package/dist/worker/routes/content-prewarm.js.map +1 -0
  199. package/dist/worker/routes/content-revalidate.d.ts +81 -0
  200. package/dist/worker/routes/content-revalidate.js +64 -0
  201. package/dist/worker/routes/content-revalidate.js.map +1 -0
  202. package/dist/worker/routes/health.d.ts +14 -0
  203. package/dist/worker/routes/health.js +278 -0
  204. package/dist/worker/routes/health.js.map +1 -0
  205. package/dist/worker/routes/index.d.ts +6 -0
  206. package/dist/worker/routes/index.js +373 -0
  207. package/dist/worker/routes/index.js.map +1 -0
  208. package/package.json +124 -0
@@ -0,0 +1,147 @@
1
+ // src/notion/config.ts
2
+ var DEFAULT_NOTION_MOVIES_DATA_SOURCE_ID = "371dc62d-0738-8015-a601-000bc3944fcb";
3
+ function readProcessEnv() {
4
+ const env = {
5
+ NOTION_TOKEN: process.env.NOTION_TOKEN,
6
+ NOTION_DATA_SOURCE_ID: process.env.NOTION_DATA_SOURCE_ID,
7
+ NOTION_MOVIES_DATA_SOURCE_ID: process.env.NOTION_MOVIES_DATA_SOURCE_ID,
8
+ NOTION_API_BASE_URL: process.env.NOTION_API_BASE_URL,
9
+ NOTION_EDIT_BASE_URL: process.env.NOTION_EDIT_BASE_URL,
10
+ NOTION_WEBHOOK_VERIFICATION_TOKEN: process.env.NOTION_WEBHOOK_VERIFICATION_TOKEN
11
+ };
12
+ for (const [key, value] of Object.entries(process.env)) {
13
+ if (key.startsWith("NOTION_") && typeof value === "string") {
14
+ env[key] = value;
15
+ }
16
+ }
17
+ return env;
18
+ }
19
+ async function readWorkerEnv() {
20
+ try {
21
+ const mod = await import(
22
+ /* webpackIgnore: true */
23
+ "cloudflare:workers"
24
+ );
25
+ const env = {};
26
+ for (const [key, value] of Object.entries(mod.env ?? {})) {
27
+ if (key.startsWith("NOTION_") && typeof value === "string") {
28
+ env[key] = value;
29
+ }
30
+ }
31
+ return env;
32
+ } catch {
33
+ return {};
34
+ }
35
+ }
36
+ function readString(source, name) {
37
+ const value = String(source[name] ?? "").trim();
38
+ return value || void 0;
39
+ }
40
+ function mergeEnv(...sources) {
41
+ const merged = {};
42
+ for (const source of sources) {
43
+ for (const name of Object.keys(source)) {
44
+ if (!name.startsWith("NOTION_")) continue;
45
+ const value = readString(source, name);
46
+ if (value) merged[name] = value;
47
+ }
48
+ }
49
+ return merged;
50
+ }
51
+ async function readEnv() {
52
+ const processEnv = readProcessEnv();
53
+ return mergeEnv(await readWorkerEnv(), processEnv);
54
+ }
55
+ function readRequired(source, name) {
56
+ const value = readString(source, name);
57
+ if (!value) {
58
+ throw new Error(`Missing required Notion env: ${name}`);
59
+ }
60
+ return value;
61
+ }
62
+ function getNotionEditBaseUrl() {
63
+ return readString(readProcessEnv(), "NOTION_EDIT_BASE_URL") ?? "https://www.notion.so";
64
+ }
65
+ async function hasNotionConfig() {
66
+ const env = await readEnv();
67
+ return Boolean(
68
+ readString(env, "NOTION_TOKEN") && readString(env, "NOTION_DATA_SOURCE_ID")
69
+ );
70
+ }
71
+ async function hasNotionMovieConfig() {
72
+ const env = await readEnv();
73
+ return Boolean(readString(env, "NOTION_TOKEN"));
74
+ }
75
+ async function hasNotionModelConfig(model) {
76
+ const env = await readEnv();
77
+ return Boolean(
78
+ readString(env, "NOTION_TOKEN") && (readString(env, model.source.dataSourceEnv) || model.source.defaultDataSourceId)
79
+ );
80
+ }
81
+ async function getNotionClientConfig() {
82
+ const env = await readEnv();
83
+ return {
84
+ token: readRequired(env, "NOTION_TOKEN"),
85
+ apiBaseUrl: readString(env, "NOTION_API_BASE_URL")
86
+ };
87
+ }
88
+ async function getNotionConfig() {
89
+ const env = await readEnv();
90
+ return {
91
+ token: readRequired(env, "NOTION_TOKEN"),
92
+ dataSourceId: readRequired(env, "NOTION_DATA_SOURCE_ID"),
93
+ apiBaseUrl: readString(env, "NOTION_API_BASE_URL"),
94
+ editBaseUrl: readString(env, "NOTION_EDIT_BASE_URL"),
95
+ webhookVerificationToken: readString(
96
+ env,
97
+ "NOTION_WEBHOOK_VERIFICATION_TOKEN"
98
+ )
99
+ };
100
+ }
101
+ async function getNotionWebhookVerificationToken() {
102
+ const env = await readEnv();
103
+ return readString(env, "NOTION_WEBHOOK_VERIFICATION_TOKEN");
104
+ }
105
+ async function getNotionMovieConfig() {
106
+ const env = await readEnv();
107
+ return {
108
+ token: readRequired(env, "NOTION_TOKEN"),
109
+ dataSourceId: readString(env, "NOTION_MOVIES_DATA_SOURCE_ID") ?? DEFAULT_NOTION_MOVIES_DATA_SOURCE_ID,
110
+ apiBaseUrl: readString(env, "NOTION_API_BASE_URL"),
111
+ editBaseUrl: readString(env, "NOTION_EDIT_BASE_URL"),
112
+ webhookVerificationToken: readString(
113
+ env,
114
+ "NOTION_WEBHOOK_VERIFICATION_TOKEN"
115
+ )
116
+ };
117
+ }
118
+ async function getNotionConfigForModel(model) {
119
+ const env = await readEnv();
120
+ const dataSourceId = readString(env, model.source.dataSourceEnv) ?? model.source.defaultDataSourceId;
121
+ if (!dataSourceId) {
122
+ throw new Error(`Missing required Notion env: ${model.source.dataSourceEnv}`);
123
+ }
124
+ return {
125
+ token: readRequired(env, model.source.tokenEnv),
126
+ dataSourceId,
127
+ apiBaseUrl: readString(env, "NOTION_API_BASE_URL"),
128
+ editBaseUrl: readString(env, "NOTION_EDIT_BASE_URL"),
129
+ webhookVerificationToken: readString(
130
+ env,
131
+ "NOTION_WEBHOOK_VERIFICATION_TOKEN"
132
+ )
133
+ };
134
+ }
135
+ export {
136
+ DEFAULT_NOTION_MOVIES_DATA_SOURCE_ID,
137
+ getNotionClientConfig,
138
+ getNotionConfig,
139
+ getNotionConfigForModel,
140
+ getNotionEditBaseUrl,
141
+ getNotionMovieConfig,
142
+ getNotionWebhookVerificationToken,
143
+ hasNotionConfig,
144
+ hasNotionModelConfig,
145
+ hasNotionMovieConfig
146
+ };
147
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/notion/config.ts"],"sourcesContent":["import type { NotionContentModelLike } from \"./types\";\n\ntype NotionEnv = {\n NOTION_TOKEN?: string;\n NOTION_DATA_SOURCE_ID?: string;\n NOTION_MOVIES_DATA_SOURCE_ID?: string;\n NOTION_API_BASE_URL?: string;\n NOTION_EDIT_BASE_URL?: string;\n NOTION_WEBHOOK_VERIFICATION_TOKEN?: string;\n [key: string]: string | undefined;\n};\n\nexport const DEFAULT_NOTION_MOVIES_DATA_SOURCE_ID =\n \"371dc62d-0738-8015-a601-000bc3944fcb\";\n\nexport type NotionClientConfig = {\n token: string;\n apiBaseUrl?: string;\n};\n\nexport type NotionConfig = {\n token: string;\n dataSourceId: string;\n apiBaseUrl?: string;\n editBaseUrl?: string;\n webhookVerificationToken?: string;\n};\n\nfunction readProcessEnv(): NotionEnv {\n const env: NotionEnv = {\n NOTION_TOKEN: process.env.NOTION_TOKEN,\n NOTION_DATA_SOURCE_ID: process.env.NOTION_DATA_SOURCE_ID,\n NOTION_MOVIES_DATA_SOURCE_ID: process.env.NOTION_MOVIES_DATA_SOURCE_ID,\n NOTION_API_BASE_URL: process.env.NOTION_API_BASE_URL,\n NOTION_EDIT_BASE_URL: process.env.NOTION_EDIT_BASE_URL,\n NOTION_WEBHOOK_VERIFICATION_TOKEN:\n process.env.NOTION_WEBHOOK_VERIFICATION_TOKEN,\n };\n\n for (const [key, value] of Object.entries(process.env)) {\n if (key.startsWith(\"NOTION_\") && typeof value === \"string\") {\n env[key] = value;\n }\n }\n\n return env;\n}\n\nasync function readWorkerEnv(): Promise<NotionEnv> {\n try {\n const mod = (await import(\n /* webpackIgnore: true */ \"cloudflare:workers\"\n )) as unknown as { env?: Record<string, unknown> };\n const env: NotionEnv = {};\n for (const [key, value] of Object.entries(mod.env ?? {})) {\n if (key.startsWith(\"NOTION_\") && typeof value === \"string\") {\n env[key] = value;\n }\n }\n return env;\n } catch {\n return {};\n }\n}\n\nfunction readString(source: NotionEnv, name: string): string | undefined {\n const value = String(source[name] ?? \"\").trim();\n return value || undefined;\n}\n\nfunction mergeEnv(...sources: NotionEnv[]): NotionEnv {\n const merged: NotionEnv = {};\n\n for (const source of sources) {\n for (const name of Object.keys(source)) {\n if (!name.startsWith(\"NOTION_\")) continue;\n const value = readString(source, name);\n if (value) merged[name] = value;\n }\n }\n\n return merged;\n}\n\nasync function readEnv(): Promise<NotionEnv> {\n const processEnv = readProcessEnv();\n return mergeEnv(await readWorkerEnv(), processEnv);\n}\n\nfunction readRequired(\n source: NotionEnv,\n name: string\n): string {\n const value = readString(source, name);\n if (!value) {\n throw new Error(`Missing required Notion env: ${name}`);\n }\n return value;\n}\n\nexport function getNotionEditBaseUrl(): string {\n return readString(readProcessEnv(), \"NOTION_EDIT_BASE_URL\") ?? \"https://www.notion.so\";\n}\n\nexport async function hasNotionConfig(): Promise<boolean> {\n const env = await readEnv();\n return Boolean(\n readString(env, \"NOTION_TOKEN\") && readString(env, \"NOTION_DATA_SOURCE_ID\")\n );\n}\n\nexport async function hasNotionMovieConfig(): Promise<boolean> {\n const env = await readEnv();\n return Boolean(readString(env, \"NOTION_TOKEN\"));\n}\n\nexport async function hasNotionModelConfig(\n model: NotionContentModelLike\n): Promise<boolean> {\n const env = await readEnv();\n return Boolean(\n readString(env, \"NOTION_TOKEN\") &&\n (readString(env, model.source.dataSourceEnv) ||\n model.source.defaultDataSourceId)\n );\n}\n\nexport async function getNotionClientConfig(): Promise<NotionClientConfig> {\n const env = await readEnv();\n return {\n token: readRequired(env, \"NOTION_TOKEN\"),\n apiBaseUrl: readString(env, \"NOTION_API_BASE_URL\"),\n };\n}\n\nexport async function getNotionConfig(): Promise<NotionConfig> {\n const env = await readEnv();\n return {\n token: readRequired(env, \"NOTION_TOKEN\"),\n dataSourceId: readRequired(env, \"NOTION_DATA_SOURCE_ID\"),\n apiBaseUrl: readString(env, \"NOTION_API_BASE_URL\"),\n editBaseUrl: readString(env, \"NOTION_EDIT_BASE_URL\"),\n webhookVerificationToken: readString(\n env,\n \"NOTION_WEBHOOK_VERIFICATION_TOKEN\"\n ),\n };\n}\n\nexport async function getNotionWebhookVerificationToken(): Promise<\n string | undefined\n> {\n const env = await readEnv();\n return readString(env, \"NOTION_WEBHOOK_VERIFICATION_TOKEN\");\n}\n\nexport async function getNotionMovieConfig(): Promise<NotionConfig> {\n const env = await readEnv();\n return {\n token: readRequired(env, \"NOTION_TOKEN\"),\n dataSourceId:\n readString(env, \"NOTION_MOVIES_DATA_SOURCE_ID\") ??\n DEFAULT_NOTION_MOVIES_DATA_SOURCE_ID,\n apiBaseUrl: readString(env, \"NOTION_API_BASE_URL\"),\n editBaseUrl: readString(env, \"NOTION_EDIT_BASE_URL\"),\n webhookVerificationToken: readString(\n env,\n \"NOTION_WEBHOOK_VERIFICATION_TOKEN\"\n ),\n };\n}\n\nexport async function getNotionConfigForModel(\n model: NotionContentModelLike\n): Promise<NotionConfig> {\n const env = await readEnv();\n const dataSourceId =\n readString(env, model.source.dataSourceEnv) ??\n model.source.defaultDataSourceId;\n if (!dataSourceId) {\n throw new Error(`Missing required Notion env: ${model.source.dataSourceEnv}`);\n }\n\n return {\n token: readRequired(env, model.source.tokenEnv),\n dataSourceId,\n apiBaseUrl: readString(env, \"NOTION_API_BASE_URL\"),\n editBaseUrl: readString(env, \"NOTION_EDIT_BASE_URL\"),\n webhookVerificationToken: readString(\n env,\n \"NOTION_WEBHOOK_VERIFICATION_TOKEN\"\n ),\n };\n}\n"],"mappings":";AAYO,IAAM,uCACX;AAeF,SAAS,iBAA4B;AACnC,QAAM,MAAiB;AAAA,IACrB,cAAc,QAAQ,IAAI;AAAA,IAC1B,uBAAuB,QAAQ,IAAI;AAAA,IACnC,8BAA8B,QAAQ,IAAI;AAAA,IAC1C,qBAAqB,QAAQ,IAAI;AAAA,IACjC,sBAAsB,QAAQ,IAAI;AAAA,IAClC,mCACE,QAAQ,IAAI;AAAA,EAChB;AAEA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG,GAAG;AACtD,QAAI,IAAI,WAAW,SAAS,KAAK,OAAO,UAAU,UAAU;AAC1D,UAAI,GAAG,IAAI;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AACT;AAEA,eAAe,gBAAoC;AACjD,MAAI;AACF,UAAM,MAAO,MAAM;AAAA;AAAA,MACS;AAAA,IAC5B;AACA,UAAM,MAAiB,CAAC;AACxB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,OAAO,CAAC,CAAC,GAAG;AACxD,UAAI,IAAI,WAAW,SAAS,KAAK,OAAO,UAAU,UAAU;AAC1D,YAAI,GAAG,IAAI;AAAA,MACb;AAAA,IACF;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEA,S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
+ import { NotionBlock } from './types.js';
3
+ import '../env-C5qu-0R-.js';
4
+
5
+ declare const NOTION_LIST_CACHE_TTL_SECONDS = 300;
6
+ declare const NOTION_BLOCKS_CACHE_TTL_SECONDS: number;
7
+ type NotionContentCacheDeleteResult = {
8
+ ok: boolean;
9
+ skipped: boolean;
10
+ deleted: string[];
11
+ failed: Array<{
12
+ key?: string;
13
+ error: string;
14
+ }>;
15
+ };
16
+ type CacheableValue = Record<string, unknown> | unknown[] | null;
17
+ declare function notionModelListCacheKey(modelId: string): string;
18
+ declare function notionPageBlocksCacheKey(modelId: string, pageId: string, cacheVersion?: string): string;
19
+ declare function notionModelCachePrefix(modelId: string): string;
20
+ declare function notionPageCachePrefix(modelId: string, pageId: string): string;
21
+ declare function getCachedNotionValue<T extends CacheableValue>(cache: KeyValueCacheAdapter | null | undefined, key: string): Promise<T | null>;
22
+ declare function putCachedNotionValue<T extends CacheableValue>(cache: KeyValueCacheAdapter | null | undefined, key: string, value: T, options?: {
23
+ expirationTtl?: number;
24
+ }): Promise<void>;
25
+ declare function getCachedNotionBlocks(cache: KeyValueCacheAdapter | null | undefined, input: {
26
+ modelId: string;
27
+ pageId: string;
28
+ cacheVersion?: string;
29
+ }): Promise<NotionBlock[] | null>;
30
+ declare function putCachedNotionBlocks(cache: KeyValueCacheAdapter | null | undefined, input: {
31
+ modelId: string;
32
+ pageId: string;
33
+ cacheVersion?: string;
34
+ blocks: NotionBlock[];
35
+ }): Promise<void>;
36
+ declare function deleteNotionContentCache(input: {
37
+ modelId: string;
38
+ pageId?: string;
39
+ routeId?: string;
40
+ previousRouteId?: string;
41
+ cache?: KeyValueCacheAdapter | null;
42
+ getCache?: () => KeyValueCacheAdapter | null;
43
+ }): Promise<NotionContentCacheDeleteResult>;
44
+
45
+ export { NOTION_BLOCKS_CACHE_TTL_SECONDS, NOTION_LIST_CACHE_TTL_SECONDS, type NotionContentCacheDeleteResult, deleteNotionContentCache, getCachedNotionBlocks, getCachedNotionValue, notionModelCachePrefix, notionModelListCacheKey, notionPageBlocksCacheKey, notionPageCachePrefix, putCachedNotionBlocks, putCachedNotionValue };
@@ -0,0 +1,166 @@
1
+ // src/notion/content-cache.ts
2
+ var CACHE_VERSION = "v2";
3
+ var NOTION_LIST_CACHE_TTL_SECONDS = 300;
4
+ var NOTION_BLOCKS_CACHE_TTL_SECONDS = 60 * 60 * 24;
5
+ var CONTENT_CACHE_READ_TTL_SECONDS = 60;
6
+ function modelPrefix(modelId) {
7
+ return `notion:${CACHE_VERSION}:${modelId}`;
8
+ }
9
+ function notionModelListCacheKey(modelId) {
10
+ return `${modelPrefix(modelId)}:list`;
11
+ }
12
+ function versionSegment(value) {
13
+ const version = String(value ?? "").trim();
14
+ return version ? `:v:${encodeURIComponent(version)}` : "";
15
+ }
16
+ function notionPageBlocksCacheKey(modelId, pageId, cacheVersion) {
17
+ return `${modelPrefix(modelId)}:page:${pageId}:blocks${versionSegment(cacheVersion)}`;
18
+ }
19
+ function notionModelCachePrefix(modelId) {
20
+ return `${modelPrefix(modelId)}:`;
21
+ }
22
+ function notionPageCachePrefix(modelId, pageId) {
23
+ return `${modelPrefix(modelId)}:page:${pageId}:`;
24
+ }
25
+ function logNotionContentCache(fields) {
26
+ try {
27
+ console.log(JSON.stringify({ tag: "notion_content_cache", ...fields }));
28
+ } catch {
29
+ }
30
+ }
31
+ async function getCachedNotionValue(cache, key) {
32
+ if (!cache) return null;
33
+ try {
34
+ const value = await cache.get(key, {
35
+ cacheTtl: CONTENT_CACHE_READ_TTL_SECONDS
36
+ });
37
+ logNotionContentCache({
38
+ op: "get",
39
+ key,
40
+ hit: value !== null,
41
+ cache: cache.kind
42
+ });
43
+ return value;
44
+ } catch (error) {
45
+ logNotionContentCache({
46
+ op: "get_error",
47
+ key,
48
+ cache: cache.kind,
49
+ message: error instanceof Error ? error.message : String(error)
50
+ });
51
+ return null;
52
+ }
53
+ }
54
+ async function putCachedNotionValue(cache, key, value, options) {
55
+ if (!cache) return;
56
+ try {
57
+ await cache.put(key, value, {
58
+ expirationTtl: options?.expirationTtl ?? NOTION_BLOCKS_CACHE_TTL_SECONDS,
59
+ metadata: {
60
+ source: "notion",
61
+ cachedAt: (/* @__PURE__ */ new Date()).toISOString()
62
+ }
63
+ });
64
+ logNotionContentCache({
65
+ op: "put",
66
+ key,
67
+ cache: cache.kind
68
+ });
69
+ } catch (error) {
70
+ logNotionContentCache({
71
+ op: "put_error",
72
+ key,
73
+ cache: cache.kind,
74
+ message: error instanceof Error ? error.message : String(error)
75
+ });
76
+ }
77
+ }
78
+ async function getCachedNotionBlocks(cache, input) {
79
+ return getCachedNotionValue(
80
+ cache,
81
+ notionPageBlocksCacheKey(input.modelId, input.pageId, input.cacheVersion)
82
+ );
83
+ }
84
+ async function putCachedNotionBlocks(cache, input) {
85
+ await putCachedNotionValue(
86
+ cache,
87
+ notionPageBlocksCacheKey(input.modelId, input.pageId, input.cacheVersion),
88
+ input.blocks,
89
+ { expirationTtl: NOTION_BLOCKS_CACHE_TTL_SECONDS }
90
+ );
91
+ }
92
+ async function deleteNotionContentCache(input) {
93
+ let cache;
94
+ try {
95
+ cache = input.cache ?? input.getCache?.() ?? null;
96
+ } catch (error) {
97
+ return {
98
+ ok: false,
99
+ skipped: true,
100
+ deleted: [],
101
+ failed: [
102
+ {
103
+ error: error instanceof Error ? error.message : String(error)
104
+ }
105
+ ]
106
+ };
107
+ }
108
+ if (!cache) {
109
+ return { ok: true, skipped: true, deleted: [], failed: [] };
110
+ }
111
+ const prefixes = /* @__PURE__ */ new Set();
112
+ if (input.pageId) {
113
+ prefixes.add(notionPageCachePrefix(input.modelId, input.pageId));
114
+ } else {
115
+ prefixes.add(notionModelCachePrefix(input.modelId));
116
+ }
117
+ prefixes.add(notionModelListCacheKey(input.modelId));
118
+ const deleted = [];
119
+ const failed = [];
120
+ for (const prefix of prefixes) {
121
+ let cursor;
122
+ do {
123
+ try {
124
+ const result = await cache.list({ prefix, cursor, limit: 100 });
125
+ for (const { name } of result.keys) {
126
+ try {
127
+ await cache.delete(name);
128
+ deleted.push(name);
129
+ } catch (error) {
130
+ failed.push({
131
+ key: name,
132
+ error: error instanceof Error ? error.message : String(error)
133
+ });
134
+ }
135
+ }
136
+ cursor = result.listComplete ? void 0 : result.cursor;
137
+ } catch (error) {
138
+ failed.push({
139
+ key: prefix,
140
+ error: error instanceof Error ? error.message : String(error)
141
+ });
142
+ cursor = void 0;
143
+ }
144
+ } while (cursor);
145
+ }
146
+ return {
147
+ ok: failed.length === 0,
148
+ skipped: false,
149
+ deleted,
150
+ failed
151
+ };
152
+ }
153
+ export {
154
+ NOTION_BLOCKS_CACHE_TTL_SECONDS,
155
+ NOTION_LIST_CACHE_TTL_SECONDS,
156
+ deleteNotionContentCache,
157
+ getCachedNotionBlocks,
158
+ getCachedNotionValue,
159
+ notionModelCachePrefix,
160
+ notionModelListCacheKey,
161
+ notionPageBlocksCacheKey,
162
+ notionPageCachePrefix,
163
+ putCachedNotionBlocks,
164
+ putCachedNotionValue
165
+ };
166
+ //# sourceMappingURL=content-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/notion/content-cache.ts"],"sourcesContent":["import type { KeyValueCacheAdapter } from \"../platform/runtime\";\nimport type { NotionBlock } from \"./types\";\n\nconst CACHE_VERSION = \"v2\";\nexport const NOTION_LIST_CACHE_TTL_SECONDS = 300;\nexport const NOTION_BLOCKS_CACHE_TTL_SECONDS = 60 * 60 * 24;\nconst CONTENT_CACHE_READ_TTL_SECONDS = 60;\n\nexport type NotionContentCacheDeleteResult = {\n ok: boolean;\n skipped: boolean;\n deleted: string[];\n failed: Array<{ key?: string; error: string }>;\n};\n\ntype CacheableValue = Record<string, unknown> | unknown[] | null;\n\nfunction modelPrefix(modelId: string) {\n return `notion:${CACHE_VERSION}:${modelId}`;\n}\n\nexport function notionModelListCacheKey(modelId: string) {\n return `${modelPrefix(modelId)}:list`;\n}\n\nfunction versionSegment(value?: string) {\n const version = String(value ?? \"\").trim();\n return version ? `:v:${encodeURIComponent(version)}` : \"\";\n}\n\nexport function notionPageBlocksCacheKey(\n modelId: string,\n pageId: string,\n cacheVersion?: string\n) {\n return `${modelPrefix(modelId)}:page:${pageId}:blocks${versionSegment(cacheVersion)}`;\n}\n\nexport function notionModelCachePrefix(modelId: string) {\n return `${modelPrefix(modelId)}:`;\n}\n\nexport function notionPageCachePrefix(modelId: string, pageId: string) {\n return `${modelPrefix(modelId)}:page:${pageId}:`;\n}\n\nfunction logNotionContentCache(fields: Record<string, unknown>) {\n try {\n console.log(JSON.stringify({ tag: \"notion_content_cache\", ...fields }));\n } catch {\n // Ignore logging serialization errors.\n }\n}\n\nexport async function getCachedNotionValue<T extends CacheableValue>(\n cache: KeyValueCacheAdapter | null | undefined,\n key: string\n): Promise<T | null> {\n if (!cache) return null;\n try {\n const value = await cache.get<T>(key, {\n cacheTtl: CONTENT_CACHE_READ_TTL_SECONDS,\n });\n logNotionContentCache({\n op: \"get\",\n key,\n hit: value !== null,\n cache: cache.kind,\n });\n return value;\n } catch (error) {\n logNotionContentCache({\n op: \"get_error\",\n key,\n cache: cache.kind,\n message: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n}\n\nexport async function putCachedNotionValue<T extends CacheableValue>(\n cache: KeyValueCacheAdapter | null | undefined,\n key: string,\n value: T,\n options?: { expirationTtl?: number }\n) {\n if (!cache) return;\n try {\n await cache.put(key, value, {\n expirationTtl: options?.expirationTtl ?? NOTION_BLOCKS_CACHE_TTL_SECONDS,\n metadata: {\n source: \"notion\",\n cachedAt: new Date().toISOString(),\n },\n });\n logNotionContentCache({\n op: \"put\",\n key,\n cache: cache.kind,\n });\n } catch (error) {\n logNotionContentCache({\n op: \"put_error\",\n key,\n cache: cache.kind,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\n\nexport async function getCachedNotionBlocks(\n cache: KeyValueCacheAdapter | null | undefined,\n input: { modelId: string; pageId: string; cacheVersion?: string }\n) {\n return getCachedNotionValue<NotionBlock[]>(\n cache,\n notionPageBlocksCacheKey(input.modelId, input.pageId, input.cacheVersion)\n );\n}\n\nexport async function putCachedNotionBlocks(\n cache: KeyValueCacheAdapter | null | undefined,\n input: {\n modelId: string;\n pageId: string;\n cacheVersion?: string;\n blocks: NotionBlock[];\n }\n) {\n await putCachedNotionValue(\n cache,\n notionPageBlocksCacheKey(input.modelId, input.pageId, input.cacheVersion),\n input.blocks,\n { expirationTtl: NOTION_BLOCKS_CACHE_TTL_SECONDS }\n );\n}\n\nexport async function deleteNotionContentCache(input: {\n modelId: string;\n pageId?: string;\n routeId?: string;\n previousRouteId?: string;\n cache?: KeyValueCacheAdapter | null;\n getCache?: () => KeyValueCacheAdapter | null;\n}): Promise<NotionContentCacheDeleteResult> {\n let cache: KeyValueCacheAdapter | null;\n try {\n cache = input.cache ?? input.getCache?.() ?? null;\n } catch (error) {\n return {\n ok: false,\n skipped: true,\n deleted: [],\n failed: [\n {\n error: error instanceof Error ? error.message : String(error),\n },\n ],\n };\n }\n\n if (!cache) {\n return { ok: true, skipped: true, deleted: [], failed: [] };\n }\n\n const prefixes = new Set<string>();\n if (input.pageId) {\n prefixes.add(notionPageCachePrefix(input.modelId, input.pageId));\n } else {\n prefixes.add(notionModelCachePrefix(input.modelId));\n }\n\n prefixes.add(notionModelListCacheKey(input.modelId));\n\n const deleted: string[] = [];\n const failed: Array<{ key?: string; error: string }> = [];\n\n for (const prefix of prefixes) {\n let cursor: string | undefined;\n do {\n try {\n const result = await cache.list({ prefix, cursor, limit: 100 });\n for (const { name } of result.keys) {\n try {\n await cache.delete(name);\n deleted.push(name);\n } catch (error) {\n failed.push({\n key: name,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n cursor = result.listComplete ? undefined : result.cursor;\n } catch (error) {\n failed.push({\n key: prefix,\n error: error instanceof Error ? error.message : String(error),\n });\n cursor = undefined;\n }\n } while (cursor);\n }\n\n return {\n ok: failed.length === 0,\n skipped: false,\n deleted,\n failed,\n };\n}\n"],"mappings":";AAGA,IAAM,gBAAgB;A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AC5D;AAEA,QAAM,WAAW,oBAAI,IAAY;AACjC,MAAI,MAAM,QAAQ;AAChB,aAAS,IAAI,sBAAsB,MAAM,SAAS,MAAM,MAAM,CAAC;AAAA,EACjE,OAAO;AACL,aAAS,IAAI,uBAAuB,MAAM,OAAO,CAAC;AAAA,EACpD;AAEA,WAAS,IAAI,wBAAwB,MAAM,OAAO,CAAC;AAEnD,QAAM,UAAoB,CAAC;AAC3B,QAAM,SAAiD,CAAC;AAExD,aAAW,UAAU,UAAU;AAC7B,QAAI;AACJ,OAAG;AACD,UAAI;AACF,cAAM,SAAS,MAAM,MAAM,KAAK,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;AAC9D,mBAAW,EAAE,KAAK,KAAK,OAAO,MAAM;AAClC,cAAI;AACF,kBAAM,MAAM,OAAO,IAAI;AACvB,oBAAQ,KAAK,IAAI;AAAA,UACnB,SAAS,OAAO;AACd,mBAAO,KAAK;AAAA,cACV,KAAK;AAAA,cACL,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,YAC9D,CAAC;AAAA,UACH;AAAA,QACF;AACA,iBAAS,OAAO,eAAe,SAAY,OAAO;AAAA,MACpD,SAAS,OAAO;AACd,eAAO,KAAK;AAAA,UACV,KAAK;AAAA,UACL,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,QAC9D,CAAC;AACD,iBAAS;AAAA,MACX;AAAA,IACF,SAAS;AAAA,EACX;AAEA,SAAO;AAAA,IACL,IAAI,OAAO,WAAW;AAAA,IACtB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,61 @@
1
+ import { NotionBlock, NotionFieldMap, NotionGenericContentModel, NotionPageLike } from './types.js';
2
+
3
+ type DataSourceQueryResponse = {
4
+ results?: unknown[];
5
+ has_more?: boolean;
6
+ next_cursor?: string | null;
7
+ };
8
+ type QueryDataSourceInput = {
9
+ startCursor?: string;
10
+ };
11
+ type GenericContentListItem = {
12
+ pageId: string;
13
+ slug: string;
14
+ title: string;
15
+ description: string;
16
+ date: string;
17
+ tags: string[];
18
+ coverImage: string | null;
19
+ published: boolean;
20
+ editUrl: string | null;
21
+ properties: Record<string, string | string[]>;
22
+ };
23
+ type GenericContentDetail = GenericContentListItem & {
24
+ blocks: NotionBlock[];
25
+ };
26
+ type GenericContentSourceDeps<TFields extends NotionFieldMap = NotionFieldMap> = {
27
+ model: NotionGenericContentModel & {
28
+ source: {
29
+ fields: TFields;
30
+ };
31
+ };
32
+ dataSourceId: string;
33
+ queryDataSource: (input?: QueryDataSourceInput) => Promise<DataSourceQueryResponse>;
34
+ getPageBlocks: (pageId: string) => Promise<NotionBlock[]>;
35
+ editBaseUrl?: string;
36
+ };
37
+ declare function mapNotionPageToGenericContentItem<TFields extends NotionFieldMap>(model: {
38
+ id: string;
39
+ source: {
40
+ fields: TFields;
41
+ };
42
+ }, page: NotionPageLike, options?: {
43
+ editBaseUrl?: string;
44
+ }): GenericContentListItem;
45
+ declare function isRenderableGenericContentItem(item: GenericContentListItem): boolean;
46
+ declare function createGenericNotionContentSource<TFields extends NotionFieldMap>(deps: GenericContentSourceDeps<TFields>): {
47
+ listItems(): Promise<GenericContentListItem[]>;
48
+ getItemBySlug(slug: string): Promise<GenericContentDetail | null>;
49
+ };
50
+ declare function listGenericNotionContent<TFields extends NotionFieldMap>(model: NotionGenericContentModel & {
51
+ source: {
52
+ fields: TFields;
53
+ };
54
+ }): Promise<GenericContentListItem[]>;
55
+ declare function getGenericNotionContentBySlug<TFields extends NotionFieldMap>(model: NotionGenericContentModel & {
56
+ source: {
57
+ fields: TFields;
58
+ };
59
+ }, slug: string): Promise<GenericContentDetail | null>;
60
+
61
+ export { type GenericContentDetail, type GenericContentListItem, type GenericContentSourceDeps, createGenericNotionContentSource, getGenericNotionContentBySlug, isRenderableGenericContentItem, listGenericNotionContent, mapNotionPageToGenericContentItem };