@stoneforge/quarry 1.12.0 → 1.14.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 (199) hide show
  1. package/README.md +2 -0
  2. package/dist/api/quarry-api.d.ts +9 -1
  3. package/dist/api/quarry-api.d.ts.map +1 -1
  4. package/dist/api/quarry-api.js +21 -2
  5. package/dist/api/quarry-api.js.map +1 -1
  6. package/dist/api/types.d.ts +8 -1
  7. package/dist/api/types.d.ts.map +1 -1
  8. package/dist/api/types.js.map +1 -1
  9. package/dist/cli/commands/auto-link-helper.d.ts +33 -0
  10. package/dist/cli/commands/auto-link-helper.d.ts.map +1 -0
  11. package/dist/cli/commands/auto-link-helper.js +74 -0
  12. package/dist/cli/commands/auto-link-helper.js.map +1 -0
  13. package/dist/cli/commands/crud.d.ts +3 -0
  14. package/dist/cli/commands/crud.d.ts.map +1 -1
  15. package/dist/cli/commands/crud.js +144 -15
  16. package/dist/cli/commands/crud.js.map +1 -1
  17. package/dist/cli/commands/docs.js +2 -2
  18. package/dist/cli/commands/docs.js.map +1 -1
  19. package/dist/cli/commands/document.js +1 -1
  20. package/dist/cli/commands/document.js.map +1 -1
  21. package/dist/cli/commands/entity.js +1 -1
  22. package/dist/cli/commands/entity.js.map +1 -1
  23. package/dist/cli/commands/external-sync.d.ts +18 -0
  24. package/dist/cli/commands/external-sync.d.ts.map +1 -0
  25. package/dist/cli/commands/external-sync.js +2499 -0
  26. package/dist/cli/commands/external-sync.js.map +1 -0
  27. package/dist/cli/commands/library.js +1 -1
  28. package/dist/cli/commands/library.js.map +1 -1
  29. package/dist/cli/commands/message.js +2 -2
  30. package/dist/cli/commands/message.js.map +1 -1
  31. package/dist/cli/commands/serve.d.ts.map +1 -1
  32. package/dist/cli/commands/serve.js +2 -0
  33. package/dist/cli/commands/serve.js.map +1 -1
  34. package/dist/cli/commands/task.d.ts.map +1 -1
  35. package/dist/cli/commands/task.js +7 -4
  36. package/dist/cli/commands/task.js.map +1 -1
  37. package/dist/cli/commands/team.js +1 -1
  38. package/dist/cli/commands/team.js.map +1 -1
  39. package/dist/cli/commands/workflow.js +1 -1
  40. package/dist/cli/commands/workflow.js.map +1 -1
  41. package/dist/cli/runner.d.ts.map +1 -1
  42. package/dist/cli/runner.js +3 -0
  43. package/dist/cli/runner.js.map +1 -1
  44. package/dist/cli/utils/progress.d.ts +30 -0
  45. package/dist/cli/utils/progress.d.ts.map +1 -0
  46. package/dist/cli/utils/progress.js +47 -0
  47. package/dist/cli/utils/progress.js.map +1 -0
  48. package/dist/config/config.d.ts.map +1 -1
  49. package/dist/config/config.js +34 -0
  50. package/dist/config/config.js.map +1 -1
  51. package/dist/config/defaults.d.ts +13 -1
  52. package/dist/config/defaults.d.ts.map +1 -1
  53. package/dist/config/defaults.js +22 -0
  54. package/dist/config/defaults.js.map +1 -1
  55. package/dist/config/file.d.ts.map +1 -1
  56. package/dist/config/file.js +71 -0
  57. package/dist/config/file.js.map +1 -1
  58. package/dist/config/index.d.ts +3 -3
  59. package/dist/config/index.d.ts.map +1 -1
  60. package/dist/config/index.js +2 -2
  61. package/dist/config/index.js.map +1 -1
  62. package/dist/config/merge.d.ts.map +1 -1
  63. package/dist/config/merge.js +52 -1
  64. package/dist/config/merge.js.map +1 -1
  65. package/dist/config/types.d.ts +68 -1
  66. package/dist/config/types.d.ts.map +1 -1
  67. package/dist/config/types.js +33 -0
  68. package/dist/config/types.js.map +1 -1
  69. package/dist/config/validation.d.ts.map +1 -1
  70. package/dist/config/validation.js +64 -1
  71. package/dist/config/validation.js.map +1 -1
  72. package/dist/external-sync/adapters/document-sync-adapter.d.ts +150 -0
  73. package/dist/external-sync/adapters/document-sync-adapter.d.ts.map +1 -0
  74. package/dist/external-sync/adapters/document-sync-adapter.js +325 -0
  75. package/dist/external-sync/adapters/document-sync-adapter.js.map +1 -0
  76. package/dist/external-sync/adapters/task-sync-adapter.d.ts +177 -0
  77. package/dist/external-sync/adapters/task-sync-adapter.d.ts.map +1 -0
  78. package/dist/external-sync/adapters/task-sync-adapter.js +353 -0
  79. package/dist/external-sync/adapters/task-sync-adapter.js.map +1 -0
  80. package/dist/external-sync/auto-link.d.ts +66 -0
  81. package/dist/external-sync/auto-link.d.ts.map +1 -0
  82. package/dist/external-sync/auto-link.js +98 -0
  83. package/dist/external-sync/auto-link.js.map +1 -0
  84. package/dist/external-sync/conflict-resolver.d.ts +170 -0
  85. package/dist/external-sync/conflict-resolver.d.ts.map +1 -0
  86. package/dist/external-sync/conflict-resolver.js +580 -0
  87. package/dist/external-sync/conflict-resolver.js.map +1 -0
  88. package/dist/external-sync/index.d.ts +23 -0
  89. package/dist/external-sync/index.d.ts.map +1 -0
  90. package/dist/external-sync/index.js +24 -0
  91. package/dist/external-sync/index.js.map +1 -0
  92. package/dist/external-sync/provider-registry.d.ts +113 -0
  93. package/dist/external-sync/provider-registry.d.ts.map +1 -0
  94. package/dist/external-sync/provider-registry.js +205 -0
  95. package/dist/external-sync/provider-registry.js.map +1 -0
  96. package/dist/external-sync/providers/folder/folder-document-adapter.d.ts +97 -0
  97. package/dist/external-sync/providers/folder/folder-document-adapter.d.ts.map +1 -0
  98. package/dist/external-sync/providers/folder/folder-document-adapter.js +261 -0
  99. package/dist/external-sync/providers/folder/folder-document-adapter.js.map +1 -0
  100. package/dist/external-sync/providers/folder/folder-fs.d.ts +146 -0
  101. package/dist/external-sync/providers/folder/folder-fs.d.ts.map +1 -0
  102. package/dist/external-sync/providers/folder/folder-fs.js +300 -0
  103. package/dist/external-sync/providers/folder/folder-fs.js.map +1 -0
  104. package/dist/external-sync/providers/folder/folder-provider.d.ts +28 -0
  105. package/dist/external-sync/providers/folder/folder-provider.d.ts.map +1 -0
  106. package/dist/external-sync/providers/folder/folder-provider.js +87 -0
  107. package/dist/external-sync/providers/folder/folder-provider.js.map +1 -0
  108. package/dist/external-sync/providers/folder/index.d.ts +11 -0
  109. package/dist/external-sync/providers/folder/index.d.ts.map +1 -0
  110. package/dist/external-sync/providers/folder/index.js +13 -0
  111. package/dist/external-sync/providers/folder/index.js.map +1 -0
  112. package/dist/external-sync/providers/github/github-api.d.ts +271 -0
  113. package/dist/external-sync/providers/github/github-api.d.ts.map +1 -0
  114. package/dist/external-sync/providers/github/github-api.js +366 -0
  115. package/dist/external-sync/providers/github/github-api.js.map +1 -0
  116. package/dist/external-sync/providers/github/github-field-map.d.ts +76 -0
  117. package/dist/external-sync/providers/github/github-field-map.d.ts.map +1 -0
  118. package/dist/external-sync/providers/github/github-field-map.js +157 -0
  119. package/dist/external-sync/providers/github/github-field-map.js.map +1 -0
  120. package/dist/external-sync/providers/github/github-provider.d.ts +36 -0
  121. package/dist/external-sync/providers/github/github-provider.d.ts.map +1 -0
  122. package/dist/external-sync/providers/github/github-provider.js +212 -0
  123. package/dist/external-sync/providers/github/github-provider.js.map +1 -0
  124. package/dist/external-sync/providers/github/github-task-adapter.d.ts +135 -0
  125. package/dist/external-sync/providers/github/github-task-adapter.d.ts.map +1 -0
  126. package/dist/external-sync/providers/github/github-task-adapter.js +374 -0
  127. package/dist/external-sync/providers/github/github-task-adapter.js.map +1 -0
  128. package/dist/external-sync/providers/github/index.d.ts +12 -0
  129. package/dist/external-sync/providers/github/index.d.ts.map +1 -0
  130. package/dist/external-sync/providers/github/index.js +15 -0
  131. package/dist/external-sync/providers/github/index.js.map +1 -0
  132. package/dist/external-sync/providers/index.d.ts +13 -0
  133. package/dist/external-sync/providers/index.d.ts.map +1 -0
  134. package/dist/external-sync/providers/index.js +15 -0
  135. package/dist/external-sync/providers/index.js.map +1 -0
  136. package/dist/external-sync/providers/linear/index.d.ts +19 -0
  137. package/dist/external-sync/providers/linear/index.d.ts.map +1 -0
  138. package/dist/external-sync/providers/linear/index.js +19 -0
  139. package/dist/external-sync/providers/linear/index.js.map +1 -0
  140. package/dist/external-sync/providers/linear/linear-api.d.ts +252 -0
  141. package/dist/external-sync/providers/linear/linear-api.d.ts.map +1 -0
  142. package/dist/external-sync/providers/linear/linear-api.js +522 -0
  143. package/dist/external-sync/providers/linear/linear-api.js.map +1 -0
  144. package/dist/external-sync/providers/linear/linear-field-map.d.ts +135 -0
  145. package/dist/external-sync/providers/linear/linear-field-map.d.ts.map +1 -0
  146. package/dist/external-sync/providers/linear/linear-field-map.js +338 -0
  147. package/dist/external-sync/providers/linear/linear-field-map.js.map +1 -0
  148. package/dist/external-sync/providers/linear/linear-provider.d.ts +52 -0
  149. package/dist/external-sync/providers/linear/linear-provider.d.ts.map +1 -0
  150. package/dist/external-sync/providers/linear/linear-provider.js +169 -0
  151. package/dist/external-sync/providers/linear/linear-provider.js.map +1 -0
  152. package/dist/external-sync/providers/linear/linear-task-adapter.d.ts +190 -0
  153. package/dist/external-sync/providers/linear/linear-task-adapter.d.ts.map +1 -0
  154. package/dist/external-sync/providers/linear/linear-task-adapter.js +521 -0
  155. package/dist/external-sync/providers/linear/linear-task-adapter.js.map +1 -0
  156. package/dist/external-sync/providers/linear/linear-types.d.ts +114 -0
  157. package/dist/external-sync/providers/linear/linear-types.d.ts.map +1 -0
  158. package/dist/external-sync/providers/linear/linear-types.js +10 -0
  159. package/dist/external-sync/providers/linear/linear-types.js.map +1 -0
  160. package/dist/external-sync/providers/notion/index.d.ts +19 -0
  161. package/dist/external-sync/providers/notion/index.d.ts.map +1 -0
  162. package/dist/external-sync/providers/notion/index.js +20 -0
  163. package/dist/external-sync/providers/notion/index.js.map +1 -0
  164. package/dist/external-sync/providers/notion/notion-api.d.ts +253 -0
  165. package/dist/external-sync/providers/notion/notion-api.d.ts.map +1 -0
  166. package/dist/external-sync/providers/notion/notion-api.js +492 -0
  167. package/dist/external-sync/providers/notion/notion-api.js.map +1 -0
  168. package/dist/external-sync/providers/notion/notion-blocks.d.ts +93 -0
  169. package/dist/external-sync/providers/notion/notion-blocks.d.ts.map +1 -0
  170. package/dist/external-sync/providers/notion/notion-blocks.js +773 -0
  171. package/dist/external-sync/providers/notion/notion-blocks.js.map +1 -0
  172. package/dist/external-sync/providers/notion/notion-document-adapter.d.ts +176 -0
  173. package/dist/external-sync/providers/notion/notion-document-adapter.d.ts.map +1 -0
  174. package/dist/external-sync/providers/notion/notion-document-adapter.js +413 -0
  175. package/dist/external-sync/providers/notion/notion-document-adapter.js.map +1 -0
  176. package/dist/external-sync/providers/notion/notion-provider.d.ts +57 -0
  177. package/dist/external-sync/providers/notion/notion-provider.d.ts.map +1 -0
  178. package/dist/external-sync/providers/notion/notion-provider.js +159 -0
  179. package/dist/external-sync/providers/notion/notion-provider.js.map +1 -0
  180. package/dist/external-sync/providers/notion/notion-types.d.ts +388 -0
  181. package/dist/external-sync/providers/notion/notion-types.d.ts.map +1 -0
  182. package/dist/external-sync/providers/notion/notion-types.js +47 -0
  183. package/dist/external-sync/providers/notion/notion-types.js.map +1 -0
  184. package/dist/external-sync/sync-engine.d.ts +364 -0
  185. package/dist/external-sync/sync-engine.d.ts.map +1 -0
  186. package/dist/external-sync/sync-engine.js +1154 -0
  187. package/dist/external-sync/sync-engine.js.map +1 -0
  188. package/dist/index.d.ts +1 -0
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +2 -0
  191. package/dist/index.js.map +1 -1
  192. package/dist/server/index.js +8 -8
  193. package/dist/server/index.js.map +1 -1
  194. package/dist/services/inbox.js +1 -1
  195. package/dist/sync/hash.d.ts +5 -0
  196. package/dist/sync/hash.d.ts.map +1 -1
  197. package/dist/sync/hash.js +21 -2
  198. package/dist/sync/hash.js.map +1 -1
  199. package/package.json +10 -12
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Notion Provider — exports for the Notion external sync provider
3
+ *
4
+ * Provides:
5
+ * - NotionApiClient: REST API client for Notion pages and blocks
6
+ * - NotionDocumentAdapter: DocumentSyncAdapter implementation for Notion pages
7
+ * - NotionProvider: ExternalProvider implementation (via factory functions)
8
+ * - Block/markdown conversion utilities
9
+ * - Notion API types
10
+ */
11
+ export { createNotionProvider, createNotionPlaceholderProvider, } from './notion-provider.js';
12
+ export type { CreateNotionProviderOptions } from './notion-provider.js';
13
+ export { NotionDocumentAdapter, createNotionDocumentAdapter, extractTitleFromProperties, buildPageProperties, } from './notion-document-adapter.js';
14
+ export { markdownToNotionBlocks, notionBlocksToMarkdown, parseInlineMarkdown, richTextToMarkdown, chunkRichText, NOTION_MAX_TEXT_LENGTH, NOTION_MAX_RICH_TEXT_ARRAY_LENGTH, } from './notion-blocks.js';
15
+ export { NotionApiClient, NotionApiError, isNotionApiError, } from './notion-api.js';
16
+ export type { NotionApiClientOptions, RateLimitState, } from './notion-api.js';
17
+ export type { NotionPage, NotionBlock, NotionBlockInput, NotionRichText, NotionAnnotations, NotionProperty, NotionCreatePageInput, NotionUpdatePageInput, NotionDatabase, NotionDatabaseProperty, NotionDatabaseSchema, NotionUpdateDatabaseInput, NotionDatabaseQueryResponse, NotionBlockChildrenResponse, NotionErrorResponse, } from './notion-types.js';
18
+ export { DEFAULT_ANNOTATIONS, SUPPORTED_BLOCK_TYPES, isSupportedBlockType, } from './notion-types.js';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/external-sync/providers/notion/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACL,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGxE,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,sBAAsB,EACtB,iCAAiC,GAClC,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,sBAAsB,EACtB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Notion Provider — exports for the Notion external sync provider
3
+ *
4
+ * Provides:
5
+ * - NotionApiClient: REST API client for Notion pages and blocks
6
+ * - NotionDocumentAdapter: DocumentSyncAdapter implementation for Notion pages
7
+ * - NotionProvider: ExternalProvider implementation (via factory functions)
8
+ * - Block/markdown conversion utilities
9
+ * - Notion API types
10
+ */
11
+ // Provider factory functions
12
+ export { createNotionProvider, createNotionPlaceholderProvider, } from './notion-provider.js';
13
+ // Document adapter
14
+ export { NotionDocumentAdapter, createNotionDocumentAdapter, extractTitleFromProperties, buildPageProperties, } from './notion-document-adapter.js';
15
+ // Block/markdown conversion
16
+ export { markdownToNotionBlocks, notionBlocksToMarkdown, parseInlineMarkdown, richTextToMarkdown, chunkRichText, NOTION_MAX_TEXT_LENGTH, NOTION_MAX_RICH_TEXT_ARRAY_LENGTH, } from './notion-blocks.js';
17
+ // API client
18
+ export { NotionApiClient, NotionApiError, isNotionApiError, } from './notion-api.js';
19
+ export { DEFAULT_ANNOTATIONS, SUPPORTED_BLOCK_TYPES, isSupportedBlockType, } from './notion-types.js';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/external-sync/providers/notion/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6BAA6B;AAC7B,OAAO,EACL,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAG9B,mBAAmB;AACnB,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,4BAA4B;AAC5B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,sBAAsB,EACtB,iCAAiC,GAClC,MAAM,oBAAoB,CAAC;AAE5B,aAAa;AACb,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAwBzB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Notion REST API Client
3
+ *
4
+ * Pure fetch-based client for Notion page and block operations.
5
+ * Supports Bearer token authentication, rate limit handling with Retry-After,
6
+ * automatic retry on transient server errors (502/503/504) with exponential backoff,
7
+ * cursor-based pagination, and typed error responses.
8
+ *
9
+ * No external dependencies — uses only the standard fetch API.
10
+ *
11
+ * @see https://developers.notion.com/reference
12
+ */
13
+ import type { NotionPage, NotionBlock, NotionBlockInput, NotionDatabaseQueryResponse, NotionErrorResponse, NotionDatabase, NotionUpdateDatabaseInput } from './notion-types.js';
14
+ /**
15
+ * Configuration for creating a NotionApiClient.
16
+ */
17
+ export interface NotionApiClientOptions {
18
+ /** Notion integration token (internal integration or OAuth token) */
19
+ token: string;
20
+ /** Notion API version header (default: "2022-06-28") */
21
+ notionVersion?: string;
22
+ /** Maximum number of automatic retries on retryable responses: 429, 502, 503, 504 (default: 3) */
23
+ maxRetries?: number;
24
+ /** Rate limit warning threshold — log a warning after a 429 (default: true) */
25
+ warnOnRateLimit?: boolean;
26
+ }
27
+ /**
28
+ * Rate limit state tracked from 429 responses.
29
+ */
30
+ export interface RateLimitState {
31
+ /** Whether the client has been rate limited at least once */
32
+ readonly wasRateLimited: boolean;
33
+ /** The most recent Retry-After value in seconds (from last 429 response) */
34
+ readonly lastRetryAfterSeconds: number | null;
35
+ /** Total number of 429 responses received */
36
+ readonly totalRateLimitHits: number;
37
+ }
38
+ /**
39
+ * Typed error for Notion API failures.
40
+ * Wraps fetch errors with status code, Notion error code, and message.
41
+ */
42
+ export declare class NotionApiError extends Error {
43
+ /** HTTP status code from Notion's response */
44
+ readonly status: number;
45
+ /** Notion-specific error code (e.g., "validation_error", "object_not_found") */
46
+ readonly code: string;
47
+ /** Parsed error body from Notion (if available) */
48
+ readonly responseBody: NotionErrorResponse | null;
49
+ constructor(message: string, status: number, code?: string, responseBody?: NotionErrorResponse | null, cause?: Error);
50
+ /**
51
+ * Whether this error is due to rate limiting (429 Too Many Requests).
52
+ */
53
+ get isRateLimited(): boolean;
54
+ /**
55
+ * Whether this error is transient and can be retried.
56
+ * Includes rate limiting (429) and server errors (502, 503, 504).
57
+ */
58
+ get isRetryable(): boolean;
59
+ /**
60
+ * Whether this error is due to authentication failure.
61
+ */
62
+ get isAuthError(): boolean;
63
+ /**
64
+ * Whether this error is a not-found response.
65
+ */
66
+ get isNotFound(): boolean;
67
+ /**
68
+ * Whether this is a validation error.
69
+ */
70
+ get isValidationError(): boolean;
71
+ /**
72
+ * Returns a JSON-serializable representation of the error.
73
+ */
74
+ toJSON(): {
75
+ name: string;
76
+ message: string;
77
+ status: number;
78
+ code: string;
79
+ responseBody: NotionErrorResponse | null;
80
+ };
81
+ }
82
+ /**
83
+ * Type guard for NotionApiError.
84
+ */
85
+ export declare function isNotionApiError(error: unknown): error is NotionApiError;
86
+ /** Maximum number of blocks per Notion API request (POST /pages or PATCH /blocks/{id}/children) */
87
+ declare const NOTION_BLOCK_BATCH_SIZE = 100;
88
+ /** Number of concurrent block delete requests (kept under Notion's 3 req/s rate limit with headroom) */
89
+ declare const CONCURRENT_BLOCK_DELETES = 8;
90
+ /**
91
+ * Fetch-based Notion REST API client for page and block operations.
92
+ *
93
+ * Features:
94
+ * - Bearer token authentication (internal integrations or OAuth)
95
+ * - Notion-Version header for API versioning
96
+ * - Automatic retry on 429 (Too Many Requests) with Retry-After
97
+ * - Automatic retry on 502/503/504 (server errors) with exponential backoff
98
+ * - Cursor-based pagination for list endpoints
99
+ * - Typed errors with Notion error codes
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const client = new NotionApiClient({ token: 'ntn_...' });
104
+ * const page = await client.getPage('page-uuid');
105
+ * const blocks = await client.getBlocks('page-uuid');
106
+ * ```
107
+ */
108
+ export declare class NotionApiClient {
109
+ private readonly token;
110
+ private readonly notionVersion;
111
+ private readonly maxRetries;
112
+ private readonly warnOnRateLimit;
113
+ /** Rate limit state tracked from 429 responses */
114
+ private rateLimitState;
115
+ constructor(options: NotionApiClientOptions);
116
+ /**
117
+ * Returns the current rate limit state.
118
+ */
119
+ getRateLimitState(): RateLimitState;
120
+ /**
121
+ * Retrieve a page by ID.
122
+ *
123
+ * GET /pages/{page_id}
124
+ *
125
+ * @see https://developers.notion.com/reference/retrieve-a-page
126
+ */
127
+ getPage(pageId: string): Promise<NotionPage>;
128
+ /**
129
+ * Retrieve a database by ID.
130
+ *
131
+ * GET /databases/{database_id}
132
+ *
133
+ * Returns the database schema including all property definitions.
134
+ * Used for discovering the title property name and checking which
135
+ * properties (Category, Tags) exist before creating pages.
136
+ *
137
+ * @see https://developers.notion.com/reference/retrieve-a-database
138
+ */
139
+ getDatabase(databaseId: string): Promise<NotionDatabase>;
140
+ /**
141
+ * Update a database schema (add or modify properties).
142
+ *
143
+ * PATCH /databases/{database_id}
144
+ *
145
+ * Used to auto-create missing properties (e.g., Category as select,
146
+ * Tags as multi_select) when they don't exist in the database schema.
147
+ *
148
+ * @see https://developers.notion.com/reference/update-a-database
149
+ */
150
+ updateDatabase(databaseId: string, updates: NotionUpdateDatabaseInput): Promise<NotionDatabase>;
151
+ /**
152
+ * Retrieve all block children for a given block (or page).
153
+ * Automatically paginates through all results.
154
+ *
155
+ * GET /blocks/{block_id}/children
156
+ *
157
+ * @see https://developers.notion.com/reference/get-block-children
158
+ */
159
+ getBlocks(blockId: string): Promise<NotionBlock[]>;
160
+ /**
161
+ * Create a new page in a database or as a child of another page.
162
+ *
163
+ * POST /pages
164
+ *
165
+ * @see https://developers.notion.com/reference/post-page
166
+ */
167
+ createPage(databaseId: string, properties: Record<string, unknown>, children?: readonly NotionBlockInput[]): Promise<NotionPage>;
168
+ /**
169
+ * Update page properties.
170
+ *
171
+ * PATCH /pages/{page_id}
172
+ *
173
+ * @see https://developers.notion.com/reference/patch-page
174
+ */
175
+ updatePage(pageId: string, properties: Record<string, unknown>): Promise<NotionPage>;
176
+ /**
177
+ * Replace all content blocks of a page.
178
+ *
179
+ * This is a two-step operation:
180
+ * 1. Delete all existing top-level block children
181
+ * 2. Append new block children in batches of 100 (Notion's per-request limit)
182
+ *
183
+ * CAUTION: This is not atomic. If step 2 fails, the page may have partial content.
184
+ *
185
+ * @see https://developers.notion.com/reference/delete-a-block
186
+ * @see https://developers.notion.com/reference/patch-block-children
187
+ */
188
+ updatePageContent(pageId: string, blocks: readonly NotionBlockInput[]): Promise<NotionBlock[]>;
189
+ /**
190
+ * Append block children to a page or block.
191
+ *
192
+ * Respects Notion's 100-block-per-request limit by batching automatically.
193
+ * Block order is preserved across batches.
194
+ *
195
+ * PATCH /blocks/{block_id}/children
196
+ *
197
+ * @param blockId - The page or block ID to append children to
198
+ * @param blocks - The blocks to append
199
+ * @returns All appended blocks
200
+ *
201
+ * @see https://developers.notion.com/reference/patch-block-children
202
+ */
203
+ appendBlocks(blockId: string, blocks: readonly NotionBlockInput[]): Promise<NotionBlock[]>;
204
+ /**
205
+ * Query a database with optional filter and cursor-based pagination.
206
+ *
207
+ * POST /databases/{database_id}/query
208
+ *
209
+ * When no cursor is provided and the result has more pages, this method
210
+ * returns only the first page. Callers can use `next_cursor` to fetch
211
+ * additional pages, or use `queryDatabaseAll()` to auto-paginate.
212
+ *
213
+ * @see https://developers.notion.com/reference/post-database-query
214
+ */
215
+ queryDatabase(databaseId: string, filter?: Record<string, unknown>, cursor?: string): Promise<NotionDatabaseQueryResponse>;
216
+ /**
217
+ * Query a database and automatically paginate through all results.
218
+ *
219
+ * This is a convenience wrapper around `queryDatabase()` that follows
220
+ * `next_cursor` until all pages have been fetched.
221
+ *
222
+ * @param databaseId - The database to query.
223
+ * @param filter - Optional Notion filter object.
224
+ * @returns All pages matching the query.
225
+ */
226
+ queryDatabaseAll(databaseId: string, filter?: Record<string, unknown>): Promise<NotionPage[]>;
227
+ /**
228
+ * Performs an HTTP request to the Notion API with automatic retry on retryable errors.
229
+ *
230
+ * Retry strategy:
231
+ * - 429 (rate limited): Uses Retry-After header value (existing behavior)
232
+ * - 502/503/504 (server errors): Uses exponential backoff starting at 1s (1s, 2s, 4s, ...)
233
+ */
234
+ private request;
235
+ /**
236
+ * Executes a single HTTP request to the Notion API (no retry logic).
237
+ */
238
+ private executeRequest;
239
+ /**
240
+ * Handles non-OK responses by throwing a NotionApiError.
241
+ */
242
+ private handleErrorResponse;
243
+ }
244
+ /**
245
+ * Parses the Retry-After value from a NotionApiError's response body or falls back to default.
246
+ */
247
+ declare function parseRetryAfterFromError(err: NotionApiError): number;
248
+ /**
249
+ * Promise-based sleep utility.
250
+ */
251
+ declare function sleep(ms: number): Promise<void>;
252
+ export { sleep, parseRetryAfterFromError, NOTION_BLOCK_BATCH_SIZE, CONCURRENT_BLOCK_DELETES };
253
+ //# sourceMappingURL=notion-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notion-api.d.ts","sourceRoot":"","sources":["../../../../src/external-sync/providers/notion/notion-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,EAGhB,2BAA2B,EAE3B,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAM3B;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,KAAK,E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