@keystrokehq/notion 0.0.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.
package/dist/pages.mjs ADDED
@@ -0,0 +1,208 @@
1
+ import { NOTION_MAX_BLOCK_CHILDREN_PER_REQUEST, appendBlockChildrenAndReturnResults, chunkArray, createNotionClient, listAllPaginatedResults, withRateLimitRetry } from "./client.mjs";
2
+ import { normalizePage, normalizePagePropertyItem, notionPagePropertyItemSchema, notionPageSchema, notionSuccessResponseSchema } from "./schemas.mjs";
3
+ import { t as notionOperation } from "./factory-BttZ5eEq.mjs";
4
+ import { i as buildPlainTextRichText, n as buildPageParent, r as buildPaginationInput } from "./shared-C6A6JPl3.mjs";
5
+ import { z } from "zod";
6
+
7
+ //#region src/pages.ts
8
+ const pageParentInputSchema = z.object({
9
+ pageId: z.string().optional(),
10
+ databaseId: z.string().optional(),
11
+ dataSourceId: z.string().optional()
12
+ }).refine((value) => [
13
+ value.pageId,
14
+ value.databaseId,
15
+ value.dataSourceId
16
+ ].filter((entry) => Boolean(entry)).length === 1, { error: "Provide exactly one of pageId, databaseId, or dataSourceId." });
17
+ const unsupportedCopyBlockTypes = new Set([
18
+ "child_page",
19
+ "child_database",
20
+ "link_preview",
21
+ "meeting_notes",
22
+ "template",
23
+ "unsupported"
24
+ ]);
25
+ function asRecord(value) {
26
+ return typeof value === "object" && value !== null ? value : {};
27
+ }
28
+ function asString(value) {
29
+ return typeof value === "string" && value.length > 0 ? value : void 0;
30
+ }
31
+ function sanitizeBlockValueForCreate(value) {
32
+ if (Array.isArray(value)) return value.map((entry) => sanitizeBlockValueForCreate(entry));
33
+ if (typeof value !== "object" || value === null) return value;
34
+ const sanitized = {};
35
+ for (const [key, nestedValue] of Object.entries(value)) {
36
+ if (key === "children" || key === "plain_text" || key === "href") continue;
37
+ if (nestedValue === null) continue;
38
+ sanitized[key] = sanitizeBlockValueForCreate(nestedValue);
39
+ }
40
+ return sanitized;
41
+ }
42
+ async function buildCopyableBlockNode(client, block) {
43
+ const record = asRecord(block);
44
+ const blockId = asString(record.id);
45
+ if (!blockId) throw new Error("Cannot copy a Notion block without an ID.");
46
+ const type = asString(record.type);
47
+ if (!type) throw new Error("Cannot copy a Notion block without a type.");
48
+ if (unsupportedCopyBlockTypes.has(type)) throw new Error(`Notion block type \`${type}\` cannot be copied through the API. Use a template or a more specific page-creation flow instead.`);
49
+ const requestValue = sanitizeBlockValueForCreate(record[type]);
50
+ return {
51
+ request: {
52
+ object: "block",
53
+ type,
54
+ [type]: typeof requestValue === "object" && requestValue !== null ? requestValue : {}
55
+ },
56
+ children: record.has_children === true ? await listCopyableBlockTree(client, blockId) : []
57
+ };
58
+ }
59
+ async function listCopyableBlockTree(client, blockId) {
60
+ const blocks = await listAllPaginatedResults((cursor) => client.blocks.children.list({
61
+ block_id: blockId,
62
+ ...buildPaginationInput(void 0, cursor)
63
+ }));
64
+ return Promise.all(blocks.map((block) => buildCopyableBlockNode(client, block)));
65
+ }
66
+ function getCreatedBlockId(value) {
67
+ const id = asString(asRecord(value).id);
68
+ if (!id) throw new Error("Notion append block children response did not include a created block ID.");
69
+ return id;
70
+ }
71
+ async function appendCopyableBlockTree(client, targetBlockId, nodes) {
72
+ for (const chunk of chunkArray(nodes, NOTION_MAX_BLOCK_CHILDREN_PER_REQUEST)) {
73
+ const createdBlocks = await appendBlockChildrenAndReturnResults(client, targetBlockId, chunk.map((node) => node.request));
74
+ for (const [index, node] of chunk.entries()) {
75
+ if (node.children.length === 0) continue;
76
+ await appendCopyableBlockTree(client, getCreatedBlockId(createdBlocks[index]), node.children);
77
+ }
78
+ }
79
+ }
80
+ const getPage = notionOperation({
81
+ id: "get_notion_page",
82
+ name: "Get Notion Page",
83
+ description: "Retrieve a Notion page by ID",
84
+ input: z.object({ pageId: z.string().min(1) }),
85
+ output: notionPageSchema,
86
+ run: async (input, credentials) => {
87
+ const client = createNotionClient(credentials);
88
+ return normalizePage(await withRateLimitRetry(() => client.pages.retrieve({ page_id: input.pageId })));
89
+ }
90
+ });
91
+ const createPage = notionOperation({
92
+ id: "create_notion_page",
93
+ name: "Create Notion Page",
94
+ description: "Create a Notion page in a page, database, or data source parent",
95
+ input: z.object({
96
+ parent: pageParentInputSchema,
97
+ title: z.string().min(1).optional(),
98
+ properties: z.record(z.string(), z.unknown()).optional(),
99
+ children: z.array(z.record(z.string(), z.unknown())).max(100).optional()
100
+ }),
101
+ output: notionPageSchema,
102
+ needsApproval: true,
103
+ run: async (input, credentials) => {
104
+ const client = createNotionClient(credentials);
105
+ const properties = input.properties ?? (input.title ? { title: { title: buildPlainTextRichText(input.title) } } : void 0);
106
+ return normalizePage(await withRateLimitRetry(() => client.pages.create({
107
+ parent: buildPageParent(input.parent),
108
+ ...properties ? { properties } : {},
109
+ ...input.children ? { children: input.children } : {}
110
+ })));
111
+ }
112
+ });
113
+ const updatePage = notionOperation({
114
+ id: "update_notion_page",
115
+ name: "Update Notion Page",
116
+ description: "Update Notion page properties or presentation metadata",
117
+ input: z.object({
118
+ pageId: z.string().min(1),
119
+ properties: z.record(z.string(), z.unknown()).optional(),
120
+ icon: z.record(z.string(), z.unknown()).nullable().optional(),
121
+ cover: z.record(z.string(), z.unknown()).nullable().optional(),
122
+ isLocked: z.boolean().optional(),
123
+ inTrash: z.boolean().optional()
124
+ }),
125
+ output: notionPageSchema,
126
+ needsApproval: true,
127
+ run: async (input, credentials) => {
128
+ const client = createNotionClient(credentials);
129
+ return normalizePage(await withRateLimitRetry(() => client.pages.update({
130
+ page_id: input.pageId,
131
+ ...input.properties ? { properties: input.properties } : {},
132
+ ...input.icon !== void 0 ? { icon: input.icon } : {},
133
+ ...input.cover !== void 0 ? { cover: input.cover } : {},
134
+ ...input.isLocked !== void 0 ? { is_locked: input.isLocked } : {},
135
+ ...input.inTrash !== void 0 ? { in_trash: input.inTrash } : {}
136
+ })));
137
+ }
138
+ });
139
+ const copyPageContent = notionOperation({
140
+ id: "copy_notion_page_content",
141
+ name: "Copy Notion Page Content",
142
+ description: "Copy block content from one Notion page into another page",
143
+ input: z.object({
144
+ sourcePageId: z.string().min(1),
145
+ targetPageId: z.string().min(1)
146
+ }).refine((value) => value.sourcePageId !== value.targetPageId, { error: "Source and target pages must be different." }),
147
+ output: notionSuccessResponseSchema,
148
+ needsApproval: true,
149
+ run: async (input, credentials) => {
150
+ const client = createNotionClient(credentials);
151
+ const sourceBlocks = await listCopyableBlockTree(client, input.sourcePageId);
152
+ if (sourceBlocks.length > 0) await appendCopyableBlockTree(client, input.targetPageId, sourceBlocks);
153
+ return { success: true };
154
+ }
155
+ });
156
+ const trashPage = notionOperation({
157
+ id: "trash_notion_page",
158
+ name: "Trash Notion Page",
159
+ description: "Move a Notion page to the trash",
160
+ input: z.object({ pageId: z.string().min(1) }),
161
+ output: notionPageSchema,
162
+ needsApproval: true,
163
+ run: async (input, credentials) => {
164
+ const client = createNotionClient(credentials);
165
+ return normalizePage(await withRateLimitRetry(() => client.pages.update({
166
+ page_id: input.pageId,
167
+ in_trash: true
168
+ })));
169
+ }
170
+ });
171
+ const getPageProperty = notionOperation({
172
+ id: "get_notion_page_property",
173
+ name: "Get Notion Page Property",
174
+ description: "Retrieve a single Notion page property item by property ID",
175
+ input: z.object({
176
+ pageId: z.string().min(1),
177
+ propertyId: z.string().min(1),
178
+ limit: z.number().int().positive().max(100).optional(),
179
+ startCursor: z.string().optional()
180
+ }),
181
+ output: notionPagePropertyItemSchema,
182
+ run: async (input, credentials) => {
183
+ const client = createNotionClient(credentials);
184
+ return normalizePagePropertyItem(await withRateLimitRetry(() => client.pages.properties.retrieve({
185
+ page_id: input.pageId,
186
+ property_id: input.propertyId,
187
+ ...buildPaginationInput(input.limit, input.startCursor)
188
+ })));
189
+ }
190
+ });
191
+ const restorePage = notionOperation({
192
+ id: "restore_notion_page",
193
+ name: "Restore Notion Page",
194
+ description: "Restore a trashed Notion page",
195
+ input: z.object({ pageId: z.string().min(1) }),
196
+ output: notionPageSchema,
197
+ needsApproval: true,
198
+ run: async (input, credentials) => {
199
+ const client = createNotionClient(credentials);
200
+ return normalizePage(await withRateLimitRetry(() => client.pages.update({
201
+ page_id: input.pageId,
202
+ in_trash: false
203
+ })));
204
+ }
205
+ });
206
+
207
+ //#endregion
208
+ export { copyPageContent, createPage, getPage, getPageProperty, restorePage, trashPage, updatePage };
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { CredentialSet } from "@keystrokehq/core";
3
+ import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
4
+ import { InferCredentialSetAuth } from "@keystrokehq/core/credential-set";
5
+
6
+ //#region src/_official/provider-app.d.ts
7
+ declare const notionAppCredentialSet: CredentialSet<"notion-app", z.ZodObject<{
8
+ clientId: z.ZodString;
9
+ clientSecret: z.ZodString;
10
+ }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
11
+ clientId: z.ZodString;
12
+ clientSecret: z.ZodString;
13
+ }, z.core.$strip>>[] | undefined>;
14
+ declare const notionPlatformProviderSeed: {
15
+ readonly provider: "notion";
16
+ readonly appRef: "notion-platform";
17
+ readonly displayName: "Notion Platform";
18
+ readonly credentialSetName: "Keystroke Notion Platform App";
19
+ readonly envShape: {
20
+ readonly KEYSTROKE_PLATFORM_NOTION_CLIENT_ID: z.ZodOptional<z.ZodString>;
21
+ readonly KEYSTROKE_PLATFORM_NOTION_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
22
+ };
23
+ readonly requiredEnvKeys: readonly ["KEYSTROKE_PLATFORM_NOTION_CLIENT_ID", "KEYSTROKE_PLATFORM_NOTION_CLIENT_SECRET"];
24
+ readonly externalAppIdEnvKey: "KEYSTROKE_PLATFORM_NOTION_CLIENT_ID";
25
+ readonly buildCredentials: (env: Record<string, string | undefined>) => {
26
+ clientId: string | undefined;
27
+ clientSecret: string | undefined;
28
+ };
29
+ };
30
+ type NotionAppCredentials = InferCredentialSetAuth<typeof notionAppCredentialSet>;
31
+ declare const notionWebhookCredentialSet: CredentialSet<"notion-webhook", z.ZodObject<{
32
+ verificationToken: z.ZodString;
33
+ }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
34
+ verificationToken: z.ZodString;
35
+ }, z.core.$strip>>[] | undefined>;
36
+ type NotionWebhookCredentials = InferCredentialSetAuth<typeof notionWebhookCredentialSet>;
37
+ //#endregion
38
+ export { notionWebhookCredentialSet as a, notionPlatformProviderSeed as i, NotionWebhookCredentials as n, notionAppCredentialSet as r, NotionAppCredentials as t };
@@ -0,0 +1,156 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas.d.ts
4
+ declare const notionParentSchema: z.ZodObject<{
5
+ type: z.ZodString;
6
+ pageId: z.ZodOptional<z.ZodString>;
7
+ blockId: z.ZodOptional<z.ZodString>;
8
+ dataSourceId: z.ZodOptional<z.ZodString>;
9
+ databaseId: z.ZodOptional<z.ZodString>;
10
+ workspace: z.ZodOptional<z.ZodBoolean>;
11
+ }, z.core.$strip>;
12
+ type NotionParent = z.infer<typeof notionParentSchema>;
13
+ declare function normalizeParent(parent: unknown): NotionParent | undefined;
14
+ declare const notionUserSchema: z.ZodObject<{
15
+ id: z.ZodString;
16
+ object: z.ZodLiteral<"user">;
17
+ type: z.ZodString;
18
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
21
+ }, z.core.$strip>;
22
+ type NotionUser = z.infer<typeof notionUserSchema>;
23
+ declare function normalizeUser(user: unknown): NotionUser;
24
+ declare const notionPageSchema: z.ZodObject<{
25
+ id: z.ZodString;
26
+ object: z.ZodLiteral<"page">;
27
+ url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
+ createdTime: z.ZodString;
30
+ lastEditedTime: z.ZodString;
31
+ archived: z.ZodOptional<z.ZodBoolean>;
32
+ inTrash: z.ZodOptional<z.ZodBoolean>;
33
+ parent: z.ZodOptional<z.ZodObject<{
34
+ type: z.ZodString;
35
+ pageId: z.ZodOptional<z.ZodString>;
36
+ blockId: z.ZodOptional<z.ZodString>;
37
+ dataSourceId: z.ZodOptional<z.ZodString>;
38
+ databaseId: z.ZodOptional<z.ZodString>;
39
+ workspace: z.ZodOptional<z.ZodBoolean>;
40
+ }, z.core.$strip>>;
41
+ properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
42
+ }, z.core.$strip>;
43
+ type NotionPage = z.infer<typeof notionPageSchema>;
44
+ declare function normalizePage(page: unknown): NotionPage;
45
+ declare const notionBlockSchema: z.ZodObject<{
46
+ id: z.ZodString;
47
+ object: z.ZodLiteral<"block">;
48
+ type: z.ZodString;
49
+ hasChildren: z.ZodBoolean;
50
+ createdTime: z.ZodString;
51
+ lastEditedTime: z.ZodString;
52
+ archived: z.ZodOptional<z.ZodBoolean>;
53
+ inTrash: z.ZodOptional<z.ZodBoolean>;
54
+ parent: z.ZodOptional<z.ZodObject<{
55
+ type: z.ZodString;
56
+ pageId: z.ZodOptional<z.ZodString>;
57
+ blockId: z.ZodOptional<z.ZodString>;
58
+ dataSourceId: z.ZodOptional<z.ZodString>;
59
+ databaseId: z.ZodOptional<z.ZodString>;
60
+ workspace: z.ZodOptional<z.ZodBoolean>;
61
+ }, z.core.$strip>>;
62
+ value: z.ZodOptional<z.ZodUnknown>;
63
+ }, z.core.$strip>;
64
+ type NotionBlock = z.infer<typeof notionBlockSchema>;
65
+ declare function normalizeBlock(block: unknown): NotionBlock;
66
+ declare const notionPagePropertyItemSchema: z.ZodObject<{
67
+ object: z.ZodString;
68
+ id: z.ZodOptional<z.ZodString>;
69
+ type: z.ZodOptional<z.ZodString>;
70
+ value: z.ZodUnknown;
71
+ nextCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
72
+ hasMore: z.ZodOptional<z.ZodBoolean>;
73
+ }, z.core.$strip>;
74
+ type NotionPagePropertyItem = z.infer<typeof notionPagePropertyItemSchema>;
75
+ declare function normalizePagePropertyItem(item: unknown): NotionPagePropertyItem;
76
+ declare const notionCommentSchema: z.ZodObject<{
77
+ id: z.ZodString;
78
+ object: z.ZodLiteral<"comment">;
79
+ discussionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
80
+ createdTime: z.ZodString;
81
+ lastEditedTime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
82
+ richText: z.ZodArray<z.ZodUnknown>;
83
+ parent: z.ZodOptional<z.ZodObject<{
84
+ type: z.ZodString;
85
+ pageId: z.ZodOptional<z.ZodString>;
86
+ blockId: z.ZodOptional<z.ZodString>;
87
+ dataSourceId: z.ZodOptional<z.ZodString>;
88
+ databaseId: z.ZodOptional<z.ZodString>;
89
+ workspace: z.ZodOptional<z.ZodBoolean>;
90
+ }, z.core.$strip>>;
91
+ createdBy: z.ZodOptional<z.ZodObject<{
92
+ id: z.ZodString;
93
+ object: z.ZodLiteral<"user">;
94
+ type: z.ZodString;
95
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
96
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
97
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
98
+ }, z.core.$strip>>;
99
+ }, z.core.$strip>;
100
+ type NotionComment = z.infer<typeof notionCommentSchema>;
101
+ declare function normalizeComment(comment: unknown): NotionComment;
102
+ declare const notionDataSourceSchema: z.ZodObject<{
103
+ id: z.ZodString;
104
+ object: z.ZodLiteral<"data_source">;
105
+ url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
106
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
107
+ createdTime: z.ZodOptional<z.ZodString>;
108
+ lastEditedTime: z.ZodOptional<z.ZodString>;
109
+ parent: z.ZodOptional<z.ZodObject<{
110
+ type: z.ZodString;
111
+ pageId: z.ZodOptional<z.ZodString>;
112
+ blockId: z.ZodOptional<z.ZodString>;
113
+ dataSourceId: z.ZodOptional<z.ZodString>;
114
+ databaseId: z.ZodOptional<z.ZodString>;
115
+ workspace: z.ZodOptional<z.ZodBoolean>;
116
+ }, z.core.$strip>>;
117
+ properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
118
+ }, z.core.$strip>;
119
+ type NotionDataSource = z.infer<typeof notionDataSourceSchema>;
120
+ declare function normalizeDataSource(dataSource: unknown): NotionDataSource;
121
+ declare const notionSearchResultSchema: z.ZodObject<{
122
+ id: z.ZodString;
123
+ object: z.ZodEnum<{
124
+ page: "page";
125
+ data_source: "data_source";
126
+ }>;
127
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
128
+ url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
129
+ lastEditedTime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
130
+ parent: z.ZodOptional<z.ZodObject<{
131
+ type: z.ZodString;
132
+ pageId: z.ZodOptional<z.ZodString>;
133
+ blockId: z.ZodOptional<z.ZodString>;
134
+ dataSourceId: z.ZodOptional<z.ZodString>;
135
+ databaseId: z.ZodOptional<z.ZodString>;
136
+ workspace: z.ZodOptional<z.ZodBoolean>;
137
+ }, z.core.$strip>>;
138
+ }, z.core.$strip>;
139
+ type NotionSearchResult = z.infer<typeof notionSearchResultSchema>;
140
+ declare function normalizeSearchResult(result: unknown): NotionSearchResult;
141
+ declare const notionListMetaSchema: z.ZodObject<{
142
+ hasMore: z.ZodBoolean;
143
+ nextCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
144
+ }, z.core.$strip>;
145
+ type NotionListMeta = z.infer<typeof notionListMetaSchema>;
146
+ declare function notionListResponseSchema<TItem extends z.ZodTypeAny>(itemSchema: TItem): z.ZodObject<{
147
+ results: z.ZodArray<TItem>;
148
+ hasMore: z.ZodBoolean;
149
+ nextCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
150
+ }, z.core.$strip>;
151
+ declare const notionSuccessResponseSchema: z.ZodObject<{
152
+ success: z.ZodLiteral<true>;
153
+ }, z.core.$strip>;
154
+ declare function normalizeListMeta(value: unknown): NotionListMeta;
155
+ //#endregion
156
+ export { NotionBlock, NotionComment, NotionDataSource, NotionListMeta, NotionPage, NotionPagePropertyItem, NotionParent, NotionSearchResult, NotionUser, normalizeBlock, normalizeComment, normalizeDataSource, normalizeListMeta, normalizePage, normalizePagePropertyItem, normalizeParent, normalizeSearchResult, normalizeUser, notionBlockSchema, notionCommentSchema, notionDataSourceSchema, notionListMetaSchema, notionListResponseSchema, notionPagePropertyItemSchema, notionPageSchema, notionParentSchema, notionSearchResultSchema, notionSuccessResponseSchema, notionUserSchema };
@@ -0,0 +1,234 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas.ts
4
+ function asRecord(value) {
5
+ return typeof value === "object" && value !== null ? value : {};
6
+ }
7
+ function asString(value) {
8
+ return typeof value === "string" && value.length > 0 ? value : void 0;
9
+ }
10
+ function asBoolean(value) {
11
+ return typeof value === "boolean" ? value : void 0;
12
+ }
13
+ function extractTextContent(value) {
14
+ if (!Array.isArray(value)) return void 0;
15
+ return value.map((entry) => {
16
+ return asString(asRecord(entry).plain_text);
17
+ }).filter((entry) => Boolean(entry)).join("") || void 0;
18
+ }
19
+ function firstPropertyText(properties) {
20
+ for (const value of Object.values(properties)) {
21
+ const property = asRecord(value);
22
+ const title = extractTextContent(property.title);
23
+ if (title) return title;
24
+ const richText = extractTextContent(property.rich_text);
25
+ if (richText) return richText;
26
+ }
27
+ }
28
+ const notionParentSchema = z.object({
29
+ type: z.string(),
30
+ pageId: z.string().optional(),
31
+ blockId: z.string().optional(),
32
+ dataSourceId: z.string().optional(),
33
+ databaseId: z.string().optional(),
34
+ workspace: z.boolean().optional()
35
+ });
36
+ function normalizeParent(parent) {
37
+ const record = asRecord(parent);
38
+ const type = asString(record.type);
39
+ if (!type) return void 0;
40
+ return notionParentSchema.parse({
41
+ type,
42
+ pageId: asString(record.page_id),
43
+ blockId: asString(record.block_id),
44
+ dataSourceId: asString(record.data_source_id),
45
+ databaseId: asString(record.database_id),
46
+ workspace: asBoolean(record.workspace)
47
+ });
48
+ }
49
+ const notionUserSchema = z.object({
50
+ id: z.string(),
51
+ object: z.literal("user"),
52
+ type: z.string(),
53
+ name: z.string().nullish(),
54
+ avatarUrl: z.string().nullish(),
55
+ email: z.string().nullish()
56
+ });
57
+ function normalizeUser(user) {
58
+ const record = asRecord(user);
59
+ const person = asRecord(record.person);
60
+ return notionUserSchema.parse({
61
+ id: asString(record.id) ?? "",
62
+ object: "user",
63
+ type: asString(record.type) ?? "unknown",
64
+ name: asString(record.name) ?? null,
65
+ avatarUrl: asString(record.avatar_url) ?? null,
66
+ email: asString(person.email) ?? null
67
+ });
68
+ }
69
+ const notionPageSchema = z.object({
70
+ id: z.string(),
71
+ object: z.literal("page"),
72
+ url: z.string().nullish(),
73
+ title: z.string().nullish(),
74
+ createdTime: z.string(),
75
+ lastEditedTime: z.string(),
76
+ archived: z.boolean().optional(),
77
+ inTrash: z.boolean().optional(),
78
+ parent: notionParentSchema.optional(),
79
+ properties: z.record(z.string(), z.unknown())
80
+ });
81
+ function normalizePage(page) {
82
+ const record = asRecord(page);
83
+ const properties = asRecord(record.properties);
84
+ return notionPageSchema.parse({
85
+ id: asString(record.id) ?? "",
86
+ object: "page",
87
+ url: asString(record.url) ?? null,
88
+ title: firstPropertyText(properties) ?? null,
89
+ createdTime: asString(record.created_time) ?? "",
90
+ lastEditedTime: asString(record.last_edited_time) ?? "",
91
+ archived: asBoolean(record.archived),
92
+ inTrash: asBoolean(record.in_trash),
93
+ parent: normalizeParent(record.parent),
94
+ properties
95
+ });
96
+ }
97
+ const notionBlockSchema = z.object({
98
+ id: z.string(),
99
+ object: z.literal("block"),
100
+ type: z.string(),
101
+ hasChildren: z.boolean(),
102
+ createdTime: z.string(),
103
+ lastEditedTime: z.string(),
104
+ archived: z.boolean().optional(),
105
+ inTrash: z.boolean().optional(),
106
+ parent: notionParentSchema.optional(),
107
+ value: z.unknown().optional()
108
+ });
109
+ function normalizeBlock(block) {
110
+ const record = asRecord(block);
111
+ const type = asString(record.type) ?? "unknown";
112
+ return notionBlockSchema.parse({
113
+ id: asString(record.id) ?? "",
114
+ object: "block",
115
+ type,
116
+ hasChildren: asBoolean(record.has_children) ?? false,
117
+ createdTime: asString(record.created_time) ?? "",
118
+ lastEditedTime: asString(record.last_edited_time) ?? "",
119
+ archived: asBoolean(record.archived),
120
+ inTrash: asBoolean(record.in_trash),
121
+ parent: normalizeParent(record.parent),
122
+ value: record[type]
123
+ });
124
+ }
125
+ const notionPagePropertyItemSchema = z.object({
126
+ object: z.string(),
127
+ id: z.string().optional(),
128
+ type: z.string().optional(),
129
+ value: z.unknown(),
130
+ nextCursor: z.string().nullish(),
131
+ hasMore: z.boolean().optional()
132
+ });
133
+ function normalizePagePropertyItem(item) {
134
+ const record = asRecord(item);
135
+ const type = asString(record.type);
136
+ return notionPagePropertyItemSchema.parse({
137
+ object: asString(record.object) ?? "property_item",
138
+ id: asString(record.id),
139
+ type,
140
+ value: (type && type in record ? record[type] : void 0) ?? (Array.isArray(record.results) ? record.results : record),
141
+ nextCursor: asString(record.next_cursor) ?? null,
142
+ hasMore: asBoolean(record.has_more)
143
+ });
144
+ }
145
+ const notionCommentSchema = z.object({
146
+ id: z.string(),
147
+ object: z.literal("comment"),
148
+ discussionId: z.string().nullish(),
149
+ createdTime: z.string(),
150
+ lastEditedTime: z.string().nullish(),
151
+ richText: z.array(z.unknown()),
152
+ parent: notionParentSchema.optional(),
153
+ createdBy: notionUserSchema.optional()
154
+ });
155
+ function normalizeComment(comment) {
156
+ const record = asRecord(comment);
157
+ return notionCommentSchema.parse({
158
+ id: asString(record.id) ?? "",
159
+ object: "comment",
160
+ discussionId: asString(record.discussion_id) ?? null,
161
+ createdTime: asString(record.created_time) ?? "",
162
+ lastEditedTime: asString(record.last_edited_time) ?? null,
163
+ richText: Array.isArray(record.rich_text) ? record.rich_text : [],
164
+ parent: normalizeParent(record.parent),
165
+ createdBy: record.created_by ? normalizeUser(record.created_by) : void 0
166
+ });
167
+ }
168
+ const notionDataSourceSchema = z.object({
169
+ id: z.string(),
170
+ object: z.literal("data_source"),
171
+ url: z.string().nullish(),
172
+ title: z.string().nullish(),
173
+ createdTime: z.string().optional(),
174
+ lastEditedTime: z.string().optional(),
175
+ parent: notionParentSchema.optional(),
176
+ properties: z.record(z.string(), z.unknown())
177
+ });
178
+ function normalizeDataSource(dataSource) {
179
+ const record = asRecord(dataSource);
180
+ const properties = asRecord(record.properties);
181
+ return notionDataSourceSchema.parse({
182
+ id: asString(record.id) ?? "",
183
+ object: "data_source",
184
+ url: asString(record.url) ?? null,
185
+ title: extractTextContent(record.title) ?? extractTextContent(record.name) ?? firstPropertyText(properties) ?? null,
186
+ createdTime: asString(record.created_time),
187
+ lastEditedTime: asString(record.last_edited_time),
188
+ parent: normalizeParent(record.parent),
189
+ properties
190
+ });
191
+ }
192
+ const notionSearchResultSchema = z.object({
193
+ id: z.string(),
194
+ object: z.enum(["page", "data_source"]),
195
+ title: z.string().nullish(),
196
+ url: z.string().nullish(),
197
+ lastEditedTime: z.string().nullish(),
198
+ parent: notionParentSchema.optional()
199
+ });
200
+ function normalizeSearchResult(result) {
201
+ const record = asRecord(result);
202
+ const object = asString(record.object) === "data_source" ? "data_source" : "page";
203
+ const properties = asRecord(record.properties);
204
+ return notionSearchResultSchema.parse({
205
+ id: asString(record.id) ?? "",
206
+ object,
207
+ title: firstPropertyText(properties) ?? extractTextContent(record.title) ?? null,
208
+ url: asString(record.url) ?? null,
209
+ lastEditedTime: asString(record.last_edited_time) ?? null,
210
+ parent: normalizeParent(record.parent)
211
+ });
212
+ }
213
+ const notionListMetaSchema = z.object({
214
+ hasMore: z.boolean(),
215
+ nextCursor: z.string().nullish()
216
+ });
217
+ function notionListResponseSchema(itemSchema) {
218
+ return z.object({
219
+ results: z.array(itemSchema),
220
+ hasMore: z.boolean(),
221
+ nextCursor: z.string().nullish()
222
+ });
223
+ }
224
+ const notionSuccessResponseSchema = z.object({ success: z.literal(true) });
225
+ function normalizeListMeta(value) {
226
+ const record = asRecord(value);
227
+ return notionListMetaSchema.parse({
228
+ hasMore: asBoolean(record.has_more) ?? false,
229
+ nextCursor: asString(record.next_cursor) ?? null
230
+ });
231
+ }
232
+
233
+ //#endregion
234
+ export { normalizeBlock, normalizeComment, normalizeDataSource, normalizeListMeta, normalizePage, normalizePagePropertyItem, normalizeParent, normalizeSearchResult, normalizeUser, notionBlockSchema, notionCommentSchema, notionDataSourceSchema, notionListMetaSchema, notionListResponseSchema, notionPagePropertyItemSchema, notionPageSchema, notionParentSchema, notionSearchResultSchema, notionSuccessResponseSchema, notionUserSchema };
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ import * as _keystrokehq_core0 from "@keystrokehq/core";
3
+ import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
4
+
5
+ //#region src/search.d.ts
6
+ declare const searchWorkspace: _keystrokehq_core0.Operation<z.ZodObject<{
7
+ query: z.ZodOptional<z.ZodString>;
8
+ object: z.ZodOptional<z.ZodEnum<{
9
+ page: "page";
10
+ data_source: "data_source";
11
+ }>>;
12
+ sortDirection: z.ZodOptional<z.ZodEnum<{
13
+ ascending: "ascending";
14
+ descending: "descending";
15
+ }>>;
16
+ startCursor: z.ZodOptional<z.ZodString>;
17
+ pageSize: z.ZodOptional<z.ZodNumber>;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ results: z.ZodArray<z.ZodObject<{
20
+ id: z.ZodString;
21
+ object: z.ZodEnum<{
22
+ page: "page";
23
+ data_source: "data_source";
24
+ }>;
25
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
+ url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
+ lastEditedTime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ parent: z.ZodOptional<z.ZodObject<{
29
+ type: z.ZodString;
30
+ pageId: z.ZodOptional<z.ZodString>;
31
+ blockId: z.ZodOptional<z.ZodString>;
32
+ dataSourceId: z.ZodOptional<z.ZodString>;
33
+ databaseId: z.ZodOptional<z.ZodString>;
34
+ workspace: z.ZodOptional<z.ZodBoolean>;
35
+ }, z.core.$strip>>;
36
+ }, z.core.$strip>>;
37
+ hasMore: z.ZodBoolean;
38
+ nextCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
39
+ }, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"notion", z.ZodObject<{
40
+ NOTION_ACCESS_TOKEN: z.ZodString;
41
+ }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
42
+ NOTION_ACCESS_TOKEN: z.ZodString;
43
+ }, z.core.$strip>>[] | undefined>], undefined>;
44
+ //#endregion
45
+ export { searchWorkspace };