@notionhq/workers 0.0.82

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 (73) hide show
  1. package/README.md +22 -0
  2. package/dist/block.d.ts +321 -0
  3. package/dist/block.d.ts.map +1 -0
  4. package/dist/block.js +0 -0
  5. package/dist/builder.d.ts +117 -0
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +168 -0
  8. package/dist/capabilities/automation.d.ts +91 -0
  9. package/dist/capabilities/automation.d.ts.map +1 -0
  10. package/dist/capabilities/automation.js +40 -0
  11. package/dist/capabilities/automation.test.d.ts +2 -0
  12. package/dist/capabilities/automation.test.d.ts.map +1 -0
  13. package/dist/capabilities/context.d.ts +7 -0
  14. package/dist/capabilities/context.d.ts.map +1 -0
  15. package/dist/capabilities/context.js +15 -0
  16. package/dist/capabilities/oauth.d.ts +120 -0
  17. package/dist/capabilities/oauth.d.ts.map +1 -0
  18. package/dist/capabilities/oauth.js +55 -0
  19. package/dist/capabilities/oauth.test.d.ts +2 -0
  20. package/dist/capabilities/oauth.test.d.ts.map +1 -0
  21. package/dist/capabilities/sync.d.ts +180 -0
  22. package/dist/capabilities/sync.d.ts.map +1 -0
  23. package/dist/capabilities/sync.js +84 -0
  24. package/dist/capabilities/sync.test.d.ts +2 -0
  25. package/dist/capabilities/sync.test.d.ts.map +1 -0
  26. package/dist/capabilities/tool.d.ts +68 -0
  27. package/dist/capabilities/tool.d.ts.map +1 -0
  28. package/dist/capabilities/tool.js +174 -0
  29. package/dist/capabilities/tool.test.d.ts +2 -0
  30. package/dist/capabilities/tool.test.d.ts.map +1 -0
  31. package/dist/error.d.ts +12 -0
  32. package/dist/error.d.ts.map +1 -0
  33. package/dist/error.js +15 -0
  34. package/dist/icon-names.d.ts +6 -0
  35. package/dist/icon-names.d.ts.map +1 -0
  36. package/dist/icon-names.js +0 -0
  37. package/dist/index.d.ts +10 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +9 -0
  40. package/dist/json-schema.d.ts +117 -0
  41. package/dist/json-schema.d.ts.map +1 -0
  42. package/dist/json-schema.js +0 -0
  43. package/dist/json-schema.test.d.ts +2 -0
  44. package/dist/json-schema.test.d.ts.map +1 -0
  45. package/dist/schema.d.ts +178 -0
  46. package/dist/schema.d.ts.map +1 -0
  47. package/dist/schema.js +66 -0
  48. package/dist/types.d.ts +206 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +0 -0
  51. package/dist/worker.d.ts +177 -0
  52. package/dist/worker.d.ts.map +1 -0
  53. package/dist/worker.js +219 -0
  54. package/package.json +68 -0
  55. package/src/block.ts +529 -0
  56. package/src/builder.ts +299 -0
  57. package/src/capabilities/automation.test.ts +152 -0
  58. package/src/capabilities/automation.ts +130 -0
  59. package/src/capabilities/context.ts +23 -0
  60. package/src/capabilities/oauth.test.ts +52 -0
  61. package/src/capabilities/oauth.ts +157 -0
  62. package/src/capabilities/sync.test.ts +104 -0
  63. package/src/capabilities/sync.ts +311 -0
  64. package/src/capabilities/tool.test.ts +351 -0
  65. package/src/capabilities/tool.ts +279 -0
  66. package/src/error.ts +19 -0
  67. package/src/icon-names.ts +890 -0
  68. package/src/index.ts +34 -0
  69. package/src/json-schema.test.ts +719 -0
  70. package/src/json-schema.ts +179 -0
  71. package/src/schema.ts +241 -0
  72. package/src/types.ts +272 -0
  73. package/src/worker.ts +285 -0
@@ -0,0 +1,178 @@
1
+ import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "./types.js";
2
+ /**
3
+ * Supported property types for sync schemas.
4
+ */
5
+ export type PropertyType = "title" | "rich_text" | "url" | "email" | "phone_number" | "checkbox" | "file" | "number" | "date" | "select" | "multi_select" | "status" | "people" | "place";
6
+ /**
7
+ * Definition of a single property in a sync schema.
8
+ */
9
+ export type PropertyDefinition = {
10
+ type: PropertyType;
11
+ };
12
+ /**
13
+ * A schema defining the structure a single property in a data source.
14
+ */
15
+ export type PropertyConfiguration = {
16
+ type: "title";
17
+ } | {
18
+ type: "text";
19
+ } | {
20
+ type: "url";
21
+ } | {
22
+ type: "email";
23
+ } | {
24
+ type: "phone_number";
25
+ } | {
26
+ type: "checkbox";
27
+ } | {
28
+ type: "file";
29
+ } | {
30
+ type: "number";
31
+ format?: NumberFormat;
32
+ } | {
33
+ type: "date";
34
+ date_format?: DateFormat;
35
+ } | {
36
+ type: "select";
37
+ options: SelectOption[];
38
+ } | {
39
+ type: "multi_select";
40
+ options: SelectOption[];
41
+ } | {
42
+ type: "status";
43
+ groups: StatusGroup[];
44
+ } | {
45
+ type: "people";
46
+ } | {
47
+ type: "place";
48
+ } | {
49
+ type: "relation";
50
+ /**
51
+ * The export name of the sync capability that defines the related collection.
52
+ * This must match the export name used when defining the related sync capability.
53
+ */
54
+ relatedSyncKey: string;
55
+ config: {
56
+ twoWay: false;
57
+ } | {
58
+ twoWay: true;
59
+ relatedPropertyName: string;
60
+ };
61
+ };
62
+ export type Schema<PK extends string> = {
63
+ /**
64
+ * The default name for the database when it is first created.
65
+ *
66
+ * Updating this after the database has been created will not change the
67
+ * name of the database.
68
+ */
69
+ defaultName: string;
70
+ /**
71
+ * Optional icon to use as the icon for the database page.
72
+ * If not provided, defaults to 📋.
73
+ * Use the `icon()` builder to create an icon value.
74
+ */
75
+ databaseIcon?: Icon;
76
+ properties: PropertySchema<PK>;
77
+ /**
78
+ * Optional configuration for sub-item relations.
79
+ * If provided, the parent and child properties must be part of a two-way self-relation.
80
+ */
81
+ subItems?: {
82
+ parentPropertyName: string;
83
+ childPropertyName: string;
84
+ };
85
+ };
86
+ /**
87
+ * A schema defining the structure of properties in a data source.
88
+ */
89
+ export type PropertySchema<PK extends string> = {
90
+ [PrimaryKey in PK]: PropertyConfiguration;
91
+ } & {
92
+ [propertyName: string]: PropertyConfiguration;
93
+ };
94
+ /**
95
+ * Creates a title property definition.
96
+ */
97
+ export declare function title(): PropertyConfiguration;
98
+ /**
99
+ * Creates a rich text property definition.
100
+ */
101
+ export declare function richText(): PropertyConfiguration;
102
+ /**
103
+ * Creates a URL property definition.
104
+ */
105
+ export declare function url(): PropertyConfiguration;
106
+ /**
107
+ * Creates an email property definition.
108
+ */
109
+ export declare function email(): PropertyConfiguration;
110
+ /**
111
+ * Creates a phone number property definition.
112
+ */
113
+ export declare function phoneNumber(): PropertyConfiguration;
114
+ /**
115
+ * Creates a checkbox property definition.
116
+ */
117
+ export declare function checkbox(): PropertyConfiguration;
118
+ /**
119
+ * Creates a file property definition.
120
+ */
121
+ export declare function file(): PropertyConfiguration;
122
+ /**
123
+ * Creates a number property definition with optional formatting.
124
+ */
125
+ export declare function number(format?: NumberFormat): PropertyConfiguration;
126
+ /**
127
+ * Creates a date property definition with optional formatting.
128
+ */
129
+ export declare function date(date_format?: DateFormat): PropertyConfiguration;
130
+ /**
131
+ * Creates a select property definition with predefined options.
132
+ */
133
+ export declare function select(options: SelectOption[]): PropertyConfiguration;
134
+ /**
135
+ * Creates a multi-select property definition with predefined options.
136
+ */
137
+ export declare function multiSelect(options: SelectOption[]): PropertyConfiguration;
138
+ /**
139
+ * Creates a status property definition with groups.
140
+ */
141
+ export declare function status(config: {
142
+ groups: StatusGroup[];
143
+ }): PropertyConfiguration;
144
+ /**
145
+ * Creates a people property definition.
146
+ */
147
+ export declare function people(): PropertyConfiguration;
148
+ /**
149
+ * Creates a place property definition for storing geographic locations.
150
+ */
151
+ export declare function place(): PropertyConfiguration;
152
+ /**
153
+ * Creates a relation property definition that references another sync capability.
154
+ * The related collection must be defined by a sync capability in the same worker.
155
+ *
156
+ * @param relatedSyncKey - The export name of the sync capability that defines the related collection.
157
+ * @example
158
+ * ```typescript
159
+ * export const projectsSync = sync({...});
160
+ *
161
+ * export const tasksSync = sync({
162
+ * schema: {
163
+ * properties: {
164
+ * "Task Title": Schema.title(),
165
+ * "Project": Schema.relation("projectsSync"),
166
+ * },
167
+ * },
168
+ * ...
169
+ * });
170
+ * ```
171
+ */
172
+ export declare function relation(relatedSyncKey: string, config?: {
173
+ twoWay: false;
174
+ } | {
175
+ twoWay: true;
176
+ relatedPropertyName: string;
177
+ }): PropertyConfiguration;
178
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,WAAW,GACX,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,QAAQ,GACR,OAAO,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,YAAY,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,CAAC;CACrB,GACD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,UAAU,CAAC;CACxB,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,YAAY,EAAE,CAAC;CACvB,GACD;IACA,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,YAAY,EAAE,CAAC;CACvB,GACD;IACA,IAAI,EA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,qBAAqB,CAE5C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,qBAAqB,CAEnE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU,GAAG,qBAAqB,CAEpE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAErE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAE1E;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE;IAC9B,MAAM,EAAE,WAAW,EAAE,CAAC;CACtB,GAAG,qBAAqB,CAExB;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,qBAAqB,CAE9C;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,qBAAqB,CAE7C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CACvB,cAAc,EAAE,MAAM,EACtB,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,GACxE,qBAAqB,CAMvB"}
package/dist/schema.js ADDED
@@ -0,0 +1,66 @@
1
+ function title() {
2
+ return { type: "title" };
3
+ }
4
+ function richText() {
5
+ return { type: "text" };
6
+ }
7
+ function url() {
8
+ return { type: "url" };
9
+ }
10
+ function email() {
11
+ return { type: "email" };
12
+ }
13
+ function phoneNumber() {
14
+ return { type: "phone_number" };
15
+ }
16
+ function checkbox() {
17
+ return { type: "checkbox" };
18
+ }
19
+ function file() {
20
+ return { type: "file" };
21
+ }
22
+ function number(format) {
23
+ return format ? { type: "number", format } : { type: "number" };
24
+ }
25
+ function date(date_format) {
26
+ return date_format ? { type: "date", date_format } : { type: "date" };
27
+ }
28
+ function select(options) {
29
+ return { type: "select", options };
30
+ }
31
+ function multiSelect(options) {
32
+ return { type: "multi_select", options };
33
+ }
34
+ function status(config) {
35
+ return { type: "status", groups: config.groups };
36
+ }
37
+ function people() {
38
+ return { type: "people" };
39
+ }
40
+ function place() {
41
+ return { type: "place" };
42
+ }
43
+ function relation(relatedSyncKey, config) {
44
+ return {
45
+ type: "relation",
46
+ relatedSyncKey,
47
+ config: config ?? { twoWay: false }
48
+ };
49
+ }
50
+ export {
51
+ checkbox,
52
+ date,
53
+ email,
54
+ file,
55
+ multiSelect,
56
+ number,
57
+ people,
58
+ phoneNumber,
59
+ place,
60
+ relation,
61
+ richText,
62
+ select,
63
+ status,
64
+ title,
65
+ url
66
+ };
@@ -0,0 +1,206 @@
1
+ /**
2
+ * A JSON value is a string, number, boolean, null, array, or object.
3
+ */
4
+ export type JSONValue = string | number | boolean | null | JSONValue[] | {
5
+ [key: string]: JSONValue;
6
+ };
7
+ /**
8
+ * A text token is a tuple where the first element is the text content
9
+ * and optional subsequent elements are formatting annotations.
10
+ */
11
+ type TextToken = [string, ...unknown[]];
12
+ /**
13
+ * A TextValue is an array of text tokens, representing rich text content.
14
+ */
15
+ export type TextValue = Array<TextToken>;
16
+ /**
17
+ * Select option color types supported by Notion
18
+ */
19
+ export type SelectColor = "default" | "gray" | "brown" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "red";
20
+ /**
21
+ * A select option with an optional color
22
+ */
23
+ export interface SelectOption {
24
+ name: string;
25
+ color?: SelectColor;
26
+ }
27
+ /**
28
+ * Status group types in Notion
29
+ */
30
+ export type StatusGroupType = "To-do" | "In progress" | "Complete";
31
+ /**
32
+ * Status group configuration
33
+ */
34
+ export interface StatusGroup {
35
+ name: StatusGroupType;
36
+ options: SelectOption[];
37
+ }
38
+ /**
39
+ * Date object representing a single date without time
40
+ */
41
+ export interface NotionDate {
42
+ type: "date";
43
+ start_date: string;
44
+ }
45
+ /**
46
+ * Date object representing a date with time
47
+ */
48
+ export interface NotionDateTime {
49
+ type: "datetime";
50
+ start_date: string;
51
+ start_time: string;
52
+ time_zone?: string;
53
+ }
54
+ /**
55
+ * Date object representing a date range
56
+ */
57
+ export interface DateRange {
58
+ type: "daterange";
59
+ start_date: string;
60
+ end_date: string;
61
+ }
62
+ /**
63
+ * Date object representing a date-time range
64
+ */
65
+ export interface DateTimeRange {
66
+ type: "datetimerange";
67
+ start_date: string;
68
+ start_time: string;
69
+ end_date: string;
70
+ end_time: string;
71
+ time_zone?: string;
72
+ }
73
+ /**
74
+ * All possible date value types
75
+ */
76
+ export type DateValue = NotionDate | NotionDateTime | DateRange | DateTimeRange;
77
+ /**
78
+ * Number format types
79
+ */
80
+ export type NumberFormat = "number" | "number_with_commas" | "percent" | "dollar" | "euro" | "pound" | "yen" | "rupee" | "won" | "yuan";
81
+ /**
82
+ * Date format types
83
+ */
84
+ export type DateFormat = "relative" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY/MM/DD" | "ll" | "MMM d";
85
+ import type { NoticonName } from "./icon-names.js";
86
+ /**
87
+ * Icon representing an emoji
88
+ */
89
+ export interface EmojiIcon {
90
+ type: "emoji";
91
+ value: string;
92
+ }
93
+ /**
94
+ * Valid colors for Notion icons
95
+ */
96
+ export type NoticonColor = "gray" | "lightgray" | "brown" | "yellow" | "orange" | "green" | "blue" | "purple" | "pink" | "red";
97
+ /**
98
+ * Icon representing a Notion built-in icon
99
+ */
100
+ export interface NoticonIcon {
101
+ type: "notion";
102
+ /**
103
+ * The name of the Notion icon (e.g., "checkmark", "pizza", "rocket")
104
+ */
105
+ icon: NoticonName;
106
+ /**
107
+ * The color variant of the icon
108
+ */
109
+ color: NoticonColor;
110
+ }
111
+ /**
112
+ * Icon representing an external image URL
113
+ */
114
+ export interface ImageIcon {
115
+ type: "image";
116
+ /**
117
+ * The URL of the image (must be a valid http/https URL)
118
+ */
119
+ url: string;
120
+ }
121
+ /**
122
+ * All possible icon types
123
+ */
124
+ export type Icon = EmojiIcon | NoticonIcon | ImageIcon;
125
+ /**
126
+ * Person reference - represents a user in a people property
127
+ */
128
+ export interface PersonReference {
129
+ /**
130
+ * The email address of the user
131
+ */
132
+ email: string;
133
+ }
134
+ /**
135
+ * A PeopleValue is an array of person references
136
+ */
137
+ export type PeopleValue = PersonReference[];
138
+ export type { NoticonName } from "./icon-names.js";
139
+ /**
140
+ * Place value representing a geographic location.
141
+ * Used for place properties in databases.
142
+ */
143
+ export interface PlaceValue {
144
+ /**
145
+ * Latitude coordinate (required)
146
+ */
147
+ lat: number;
148
+ /**
149
+ * Longitude coordinate (required)
150
+ */
151
+ lon: number;
152
+ /**
153
+ * Optional display name for the location
154
+ */
155
+ name?: string;
156
+ /**
157
+ * Optional street address
158
+ */
159
+ address?: string;
160
+ /**
161
+ * Optional Google Place ID for the location
162
+ */
163
+ googlePlaceId?: string;
164
+ }
165
+ /**
166
+ * A reference to a related record by its primary key.
167
+ */
168
+ export type RelationReference = {
169
+ type: "primaryKey";
170
+ value: string;
171
+ };
172
+ /**
173
+ * Relation value representing references to related records.
174
+ * Each reference identifies a record in the target collection.
175
+ */
176
+ export type RelationValue = RelationReference[];
177
+ /**
178
+ * Time units for schedule intervals.
179
+ * - "m": minutes
180
+ * - "h": hours
181
+ * - "d": days
182
+ */
183
+ export type TimeUnit = "m" | "h" | "d";
184
+ /**
185
+ * A string representing an interval, e.g. "30m", "1h", "7d".
186
+ */
187
+ export type IntervalString = `${number}${TimeUnit}`;
188
+ /**
189
+ * Schedule configuration for sync capabilities.
190
+ * - "continuous": Run as frequently as the system allows
191
+ * - IntervalString: Run at specified intervals, e.g. "30m", "1h", "1d"
192
+ */
193
+ export type Schedule = "continuous" | IntervalString;
194
+ /**
195
+ * Normalized schedule representation stored in the backend.
196
+ */
197
+ export type SyncSchedule = {
198
+ type: "continuous";
199
+ } | {
200
+ type: "interval";
201
+ intervalMs: number;
202
+ };
203
+ export type HandlerOptions = {
204
+ concreteOutput?: true;
205
+ };
206
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+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W,GAAG,SAAS,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;AAE5C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,cAAc,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,cAAc,GAAG;IAC5B,cAAc,CAAC,EAAE,IAAI,CAAC;CACtB,CAAC"}
package/dist/types.js ADDED
File without changes
@@ -0,0 +1,177 @@
1
+ import type { AutomationCapability, AutomationConfiguration, AutomationEvent } from "./capabilities/automation.js";
2
+ import type { CapabilityContext } from "./capabilities/context.js";
3
+ import type { NotionManagedOAuthConfiguration, OAuthCapability, OAuthConfiguration, UserManagedOAuthConfiguration } from "./capabilities/oauth.js";
4
+ import type { SyncCapability, SyncConfiguration } from "./capabilities/sync.js";
5
+ import type { ToolCapability, ToolConfiguration } from "./capabilities/tool.js";
6
+ import type { Schema } from "./schema.js";
7
+ import type { HandlerOptions, JSONValue } from "./types.js";
8
+ export type { AutomationConfiguration, AutomationEvent, CapabilityContext, OAuthConfiguration, NotionManagedOAuthConfiguration, UserManagedOAuthConfiguration, SyncConfiguration, ToolConfiguration, };
9
+ type Capability = SyncCapability | ToolCapability<any, any> | AutomationCapability | OAuthCapability;
10
+ export declare class Worker {
11
+ #private;
12
+ /**
13
+ * Register a sync capability.
14
+ *
15
+ * Example:
16
+ *
17
+ * ```ts
18
+ * import { Worker } from "@notionhq/workers-sdk";
19
+ * import * as Builder from "@notionhq/workers-sdk/builder";
20
+ * import * as Schema from "@notionhq/workers-sdk/schema";
21
+ *
22
+ * const worker = new Worker();
23
+ * export default worker;
24
+ *
25
+ * worker.sync("tasksSync", {
26
+ * primaryKeyProperty: "Task ID",
27
+ * schema: {
28
+ * defaultName: "Tasks",
29
+ * properties: {
30
+ * "Task Name": Schema.title(),
31
+ * "Task ID": Schema.richText(),
32
+ * Status: Schema.select([
33
+ * { name: "Open", color: "default" },
34
+ * { name: "Done", color: "green" },
35
+ * ]),
36
+ * },
37
+ * },
38
+ * execute: async () => {
39
+ * const changes = [
40
+ * {
41
+ * key: "task-1",
42
+ * properties: {
43
+ * "Task Name": Builder.title("Write docs"),
44
+ * "Task ID": Builder.richText("task-1"),
45
+ * Status: Builder.select("Open"),
46
+ * },
47
+ * },
48
+ * ];
49
+ *
50
+ * return { changes, hasMore: false };
51
+ * },
52
+ * });
53
+ * ```
54
+ *
55
+ * @param key - The unique key for this capability.
56
+ * @param config - The sync configuration.
57
+ * @returns The capability object.
58
+ */
59
+ sync<PK extends string, S extends Schema<PK>, Context = unknown>(key: string, config: SyncConfiguration<PK, S, Context>): SyncCapability;
60
+ /**
61
+ * Register a tool capability.
62
+ *
63
+ * Example:
64
+ *
65
+ * ```ts
66
+ * worker.tool<{ name: string }, string>("sayHello", {
67
+ * title: "Say Hello",
68
+ * description: "Say hello to the user",
69
+ * schema: {
70
+ * type: "object",
71
+ * properties: {
72
+ * name: { type: "string" },
73
+ * },
74
+ * required: ["name"],
75
+ * },
76
+ * execute: ({ name }, { notion }) => {
77
+ * return `Hello, ${name}!`;
78
+ * },
79
+ * })
80
+ * ```
81
+ *
82
+ *
83
+ * @param key - The unique key for this capability.
84
+ * @param config - The tool configuration.
85
+ * @returns The capability object.
86
+ */
87
+ tool<I extends JSONValue, O extends JSONValue = JSONValue>(key: string, config: ToolConfiguration<I, O>): ToolCapability<I, O>;
88
+ /**
89
+ * Register an automation capability.
90
+ *
91
+ * Example:
92
+ *
93
+ * ```ts
94
+ * const worker = new Worker();
95
+ * export default worker;
96
+ *
97
+ * worker.automation("sendWelcomeEmail", {
98
+ * title: "Send Welcome Email",
99
+ * description: "Sends a welcome email when a new user is added",
100
+ * execute: async (event, { notion }) => {
101
+ * const { pageId, pageData } = event;
102
+ *
103
+ * // Access page properties from the Public API format
104
+ * if (pageData) {
105
+ * const name = pageData.properties.Name; // Access any property
106
+ * const status = pageData.properties.Status;
107
+ * console.log(`Processing: ${name}`);
108
+ * }
109
+ *
110
+ * // Your automation logic here
111
+ * await sendEmail(pageId);
112
+ * },
113
+ * })
114
+ * ```
115
+ *
116
+ * @param key - The unique key for this capability.
117
+ * @param config - The automation configuration.
118
+ * @returns The capability object.
119
+ */
120
+ automation(key: string, config: AutomationConfiguration): AutomationCapability;
121
+ /**
122
+ * Register an OAuth capability.
123
+ *
124
+ * There are two ways to configure OAuth:
125
+ *
126
+ * 1. Notion-managed providers:
127
+ * ```ts
128
+ * const worker = new Worker();
129
+ * export default worker;
130
+ *
131
+ * worker.oauth("googleAuth", {
132
+ * type: "notion_managed",
133
+ * name: "my-google-auth",
134
+ * provider: "google"
135
+ * })
136
+ * ```
137
+ *
138
+ * 2. User-managed OAuth configuration:
139
+ * ```ts
140
+ * const worker = new Worker();
141
+ * export default worker;
142
+ *
143
+ * worker.oauth("myCustomAuth", {
144
+ * type: "user_managed",
145
+ * name: "my-custom-oauth",
146
+ * authorizationEndpoint: "https://provider.com/oauth/authorize",
147
+ * tokenEndpoint: "https://provider.com/oauth/token",
148
+ * scope: "read write",
149
+ * clientId: process.env.CLIENT_ID,
150
+ * clientSecret: process.env.CLIENT_SECRET,
151
+ * authorizationParams: {
152
+ * access_type: "offline",
153
+ * prompt: "consent"
154
+ * }
155
+ * })
156
+ * ```
157
+ *
158
+ * @param key - The unique key used to register this OAuth capability.
159
+ * @param config - The OAuth configuration (Notion-managed or user-managed) for this capability.
160
+ * @returns The registered OAuth capability.
161
+ */
162
+ oauth(key: string, config: OAuthConfiguration): OAuthCapability;
163
+ /**
164
+ * Get all registered capabilities (for discovery) without their handlers.
165
+ */
166
+ get capabilities(): Pick<Capability, "_tag" | "key" | "config">[];
167
+ /**
168
+ * Execute a capability by key.
169
+ *
170
+ * @param key - The key of the capability to execute.
171
+ * @param context - The context to pass to the capability.
172
+ * @param options - Additional options for execution (e.g. for testing).
173
+ * @returns The result of the capability execution.
174
+ */
175
+ run(key: string, context: unknown, options?: HandlerOptions): Promise<unknown>;
176
+ }
177
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,EAC7B,MAAM,yBAAyB,CAAC;AAEjC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