@project-ajax/sdk 0.0.33 → 0.0.35

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/builder.d.ts CHANGED
@@ -1,12 +1,75 @@
1
1
  import type { TextValue } from "./types.js";
2
+ /**
3
+ * Creates a rich text value.
4
+ */
2
5
  export declare function richText(content: string): TextValue;
6
+ /**
7
+ * Creates a URL value.
8
+ */
3
9
  export declare function url(url: string): TextValue;
10
+ /**
11
+ * Creates a title value.
12
+ */
4
13
  export declare function title(content: string): TextValue;
14
+ /**
15
+ * Creates a text value.
16
+ */
5
17
  export declare function text(content: string): TextValue;
6
18
  /**
7
- * Creates a link with custom display text
19
+ * Creates an email value.
20
+ */
21
+ export declare function email(email: string): TextValue;
22
+ /**
23
+ * Creates a phone number value.
24
+ */
25
+ export declare function phoneNumber(phone: string): TextValue;
26
+ /**
27
+ * Creates a checkbox value.
28
+ */
29
+ export declare function checkbox(checked: boolean): TextValue;
30
+ /**
31
+ * Creates a file URL value.
32
+ * @param fileUrl - The URL of the file
33
+ * @param fileName - Optional display name for the file (defaults to URL)
34
+ */
35
+ export declare function file(fileUrl: string, fileName?: string): TextValue;
36
+ /**
37
+ * Creates a number value.
38
+ */
39
+ export declare function number(value: number): TextValue;
40
+ /**
41
+ * Creates a date value from a date string (YYYY-MM-DD).
42
+ */
43
+ export declare function date(dateString: string): TextValue;
44
+ /**
45
+ * Creates a datetime value from a Date object.
46
+ */
47
+ export declare function dateTime(date: Date, timeZone?: string): TextValue;
48
+ /**
49
+ * Creates a date range value from date strings.
50
+ */
51
+ export declare function dateRange(startDate: string, endDate: string): TextValue;
52
+ /**
53
+ * Creates a datetime range value from Date objects.
54
+ */
55
+ export declare function dateTimeRange(startDate: Date, endDate: Date, timeZone?: string): TextValue;
56
+ /**
57
+ * Creates a link with custom display text.
8
58
  * @param displayText - The text to display
9
59
  * @param url - The URL to link to
10
60
  */
11
61
  export declare function link(displayText: string, url: string): TextValue;
62
+ /**
63
+ * Creates a select value from a single option.
64
+ */
65
+ export declare function select(value: string): TextValue;
66
+ /**
67
+ * Creates a multi-select value from multiple options.
68
+ * @param values - Array of option names to select
69
+ */
70
+ export declare function multiSelect(...values: string[]): TextValue;
71
+ /**
72
+ * Creates a status value from a status option name.
73
+ */
74
+ export declare function status(value: string): TextValue;
12
75
  //# sourceMappingURL=builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEnD;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAE1C;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEhD;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAEhE"}
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEnD;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAE1C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAEhD;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAK/C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CASlD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAYjE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAWvE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,QAAQ,CAAC,EAAE,MAAM,GACf,SAAS,CAcX;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAEhE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAK1D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAE/C"}
package/dist/builder.js CHANGED
@@ -10,12 +10,121 @@ function title(content) {
10
10
  function text(content) {
11
11
  return [[content]];
12
12
  }
13
+ function email(email2) {
14
+ return [[email2]];
15
+ }
16
+ function phoneNumber(phone) {
17
+ return [[phone]];
18
+ }
19
+ function checkbox(checked) {
20
+ return checked ? [["Yes"]] : [["No"]];
21
+ }
22
+ function file(fileUrl, fileName) {
23
+ return [[fileName ?? fileUrl, [["a", fileUrl]]]];
24
+ }
25
+ function number(value) {
26
+ if (Number.isNaN(value)) {
27
+ return [];
28
+ }
29
+ return [[value.toString()]];
30
+ }
31
+ function date(dateString) {
32
+ validateDateString(dateString);
33
+ const dateValue = {
34
+ type: "date",
35
+ start_date: dateString
36
+ };
37
+ return createDateToken(dateValue);
38
+ }
39
+ function dateTime(date2, timeZone) {
40
+ const dateValue = {
41
+ type: "datetime",
42
+ start_date: formatDate(date2),
43
+ start_time: formatTime(date2)
44
+ };
45
+ if (timeZone) {
46
+ dateValue.time_zone = timeZone;
47
+ }
48
+ return createDateToken(dateValue);
49
+ }
50
+ function dateRange(startDate, endDate) {
51
+ validateDateString(startDate);
52
+ validateDateString(endDate);
53
+ const dateValue = {
54
+ type: "daterange",
55
+ start_date: startDate,
56
+ end_date: endDate
57
+ };
58
+ return createDateToken(dateValue);
59
+ }
60
+ function dateTimeRange(startDate, endDate, timeZone) {
61
+ const dateValue = {
62
+ type: "datetimerange",
63
+ start_date: formatDate(startDate),
64
+ start_time: formatTime(startDate),
65
+ end_date: formatDate(endDate),
66
+ end_time: formatTime(endDate)
67
+ };
68
+ if (timeZone) {
69
+ dateValue.time_zone = timeZone;
70
+ }
71
+ return createDateToken(dateValue);
72
+ }
13
73
  function link(displayText, url2) {
14
74
  return [[displayText, [["a", url2]]]];
15
75
  }
76
+ function select(value) {
77
+ return [[value]];
78
+ }
79
+ function multiSelect(...values) {
80
+ if (values.length === 0) {
81
+ return [];
82
+ }
83
+ return [[values.join(",")]];
84
+ }
85
+ function status(value) {
86
+ return [[value]];
87
+ }
88
+ function validateDateString(dateString) {
89
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
90
+ throw new Error(
91
+ `Invalid date format: ${dateString}. Expected YYYY-MM-DD format.`
92
+ );
93
+ }
94
+ const date2 = new Date(dateString);
95
+ if (Number.isNaN(date2.getTime())) {
96
+ throw new Error(`Invalid date: ${dateString}`);
97
+ }
98
+ }
99
+ function createDateToken(dateValue) {
100
+ return [["\u2023", [["d", dateValue]]]];
101
+ }
102
+ function formatDate(date2) {
103
+ const year = date2.getFullYear();
104
+ const month = String(date2.getMonth() + 1).padStart(2, "0");
105
+ const day = String(date2.getDate()).padStart(2, "0");
106
+ return `${year}-${month}-${day}`;
107
+ }
108
+ function formatTime(date2) {
109
+ const hours = String(date2.getHours()).padStart(2, "0");
110
+ const minutes = String(date2.getMinutes()).padStart(2, "0");
111
+ return `${hours}:${minutes}`;
112
+ }
16
113
  export {
114
+ checkbox,
115
+ date,
116
+ dateRange,
117
+ dateTime,
118
+ dateTimeRange,
119
+ email,
120
+ file,
17
121
  link,
122
+ multiSelect,
123
+ number,
124
+ phoneNumber,
18
125
  richText,
126
+ select,
127
+ status,
19
128
  text,
20
129
  title,
21
130
  url
package/dist/schema.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import type { DateFormat, NumberFormat, SelectOption, StatusGroup } from "./types.js";
1
2
  /**
2
3
  * Supported property types for sync schemas.
3
4
  */
4
- export type PropertyType = "title" | "rich_text" | "url";
5
+ export type PropertyType = "title" | "rich_text" | "url" | "email" | "phone_number" | "checkbox" | "file" | "number" | "date" | "select" | "multi_select" | "status";
5
6
  /**
6
7
  * Definition of a single property in a sync schema.
7
8
  */
@@ -17,6 +18,29 @@ export type PropertyConfiguration = {
17
18
  type: "text";
18
19
  } | {
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[];
20
44
  };
21
45
  export type Schema<PK extends string> = {
22
46
  dataSourceTitle: string;
@@ -42,4 +66,42 @@ export declare function richText(): PropertyConfiguration;
42
66
  * Creates a URL property definition.
43
67
  */
44
68
  export declare function url(): PropertyConfiguration;
69
+ /**
70
+ * Creates an email property definition.
71
+ */
72
+ export declare function email(): PropertyConfiguration;
73
+ /**
74
+ * Creates a phone number property definition.
75
+ */
76
+ export declare function phoneNumber(): PropertyConfiguration;
77
+ /**
78
+ * Creates a checkbox property definition.
79
+ */
80
+ export declare function checkbox(): PropertyConfiguration;
81
+ /**
82
+ * Creates a file property definition.
83
+ */
84
+ export declare function file(): PropertyConfiguration;
85
+ /**
86
+ * Creates a number property definition with optional formatting.
87
+ */
88
+ export declare function number(format?: NumberFormat): PropertyConfiguration;
89
+ /**
90
+ * Creates a date property definition with optional formatting.
91
+ */
92
+ export declare function date(date_format?: DateFormat): PropertyConfiguration;
93
+ /**
94
+ * Creates a select property definition with predefined options.
95
+ */
96
+ export declare function select(options: SelectOption[]): PropertyConfiguration;
97
+ /**
98
+ * Creates a multi-select property definition with predefined options.
99
+ */
100
+ export declare function multiSelect(options: SelectOption[]): PropertyConfiguration;
101
+ /**
102
+ * Creates a status property definition with groups.
103
+ */
104
+ export declare function status(config: {
105
+ groups: StatusGroup[];
106
+ }): PropertyConfiguration;
45
107
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,GAAG,KAAK,CAAC;AAEzD;;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,EA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G,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"}
package/dist/schema.js CHANGED
@@ -7,8 +7,44 @@ function richText() {
7
7
  function url() {
8
8
  return { type: "url" };
9
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
+ }
10
37
  export {
38
+ checkbox,
39
+ date,
40
+ email,
41
+ file,
42
+ multiSelect,
43
+ number,
44
+ phoneNumber,
11
45
  richText,
46
+ select,
47
+ status,
12
48
  title,
13
49
  url
14
50
  };
package/dist/types.d.ts CHANGED
@@ -7,5 +7,74 @@ type TextToken = [string, ...unknown[]];
7
7
  * A TextValue is an array of text tokens, representing rich text content.
8
8
  */
9
9
  export type TextValue = Array<TextToken>;
10
+ /**
11
+ * Select option color types supported by Notion
12
+ */
13
+ export type SelectColor = "default" | "gray" | "brown" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "red";
14
+ /**
15
+ * A select option with an optional color
16
+ */
17
+ export interface SelectOption {
18
+ name: string;
19
+ color?: SelectColor;
20
+ }
21
+ /**
22
+ * Status group types in Notion
23
+ */
24
+ export type StatusGroupType = "To-do" | "In progress" | "Complete";
25
+ /**
26
+ * Status group configuration
27
+ */
28
+ export interface StatusGroup {
29
+ name: StatusGroupType;
30
+ options: SelectOption[];
31
+ }
32
+ /**
33
+ * Date object representing a single date without time
34
+ */
35
+ export interface NotionDate {
36
+ type: "date";
37
+ start_date: string;
38
+ }
39
+ /**
40
+ * Date object representing a date with time
41
+ */
42
+ export interface NotionDateTime {
43
+ type: "datetime";
44
+ start_date: string;
45
+ start_time: string;
46
+ time_zone?: string;
47
+ }
48
+ /**
49
+ * Date object representing a date range
50
+ */
51
+ export interface DateRange {
52
+ type: "daterange";
53
+ start_date: string;
54
+ end_date: string;
55
+ }
56
+ /**
57
+ * Date object representing a date-time range
58
+ */
59
+ export interface DateTimeRange {
60
+ type: "datetimerange";
61
+ start_date: string;
62
+ start_time: string;
63
+ end_date: string;
64
+ end_time: string;
65
+ time_zone?: string;
66
+ }
67
+ /**
68
+ * All possible date value types
69
+ */
70
+ export type DateValue = NotionDate | NotionDateTime | DateRange | DateTimeRange;
71
+ /**
72
+ * Number format types
73
+ */
74
+ export type NumberFormat = "number" | "number_with_commas" | "percent" | "dollar" | "euro" | "pound" | "yen" | "rupee" | "won" | "yuan";
75
+ /**
76
+ * Date format types
77
+ */
78
+ export type DateFormat = "relative" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY/MM/DD" | "ll" | "MMM d";
10
79
  export {};
11
80
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,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B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,GAAG,aAAa,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB,QAAQ,GACR,oBAAoB,GACpB,SAAS,GACT,QAAQ,GACR,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,KAAK,GACL,MAAM,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,UAAU,GACnB,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,IAAI,GACJ,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/sdk",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "An SDK for building workers for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/src/builder.ts CHANGED
@@ -1,26 +1,215 @@
1
- import type { TextValue } from "./types.js";
1
+ import type { DateValue, TextValue } from "./types.js";
2
2
 
3
+ /**
4
+ * Creates a rich text value.
5
+ */
3
6
  export function richText(content: string): TextValue {
4
7
  return [[content]];
5
8
  }
6
9
 
10
+ /**
11
+ * Creates a URL value.
12
+ */
7
13
  export function url(url: string): TextValue {
8
14
  return [[url]];
9
15
  }
10
16
 
17
+ /**
18
+ * Creates a title value.
19
+ */
11
20
  export function title(content: string): TextValue {
12
21
  return [[content]];
13
22
  }
14
23
 
24
+ /**
25
+ * Creates a text value.
26
+ */
15
27
  export function text(content: string): TextValue {
16
28
  return [[content]];
17
29
  }
18
30
 
19
31
  /**
20
- * Creates a link with custom display text
32
+ * Creates an email value.
33
+ */
34
+ export function email(email: string): TextValue {
35
+ return [[email]];
36
+ }
37
+
38
+ /**
39
+ * Creates a phone number value.
40
+ */
41
+ export function phoneNumber(phone: string): TextValue {
42
+ return [[phone]];
43
+ }
44
+
45
+ /**
46
+ * Creates a checkbox value.
47
+ */
48
+ export function checkbox(checked: boolean): TextValue {
49
+ return checked ? [["Yes"]] : [["No"]];
50
+ }
51
+
52
+ /**
53
+ * Creates a file URL value.
54
+ * @param fileUrl - The URL of the file
55
+ * @param fileName - Optional display name for the file (defaults to URL)
56
+ */
57
+ export function file(fileUrl: string, fileName?: string): TextValue {
58
+ return [[fileName ?? fileUrl, [["a", fileUrl]]]];
59
+ }
60
+
61
+ /**
62
+ * Creates a number value.
63
+ */
64
+ export function number(value: number): TextValue {
65
+ if (Number.isNaN(value)) {
66
+ return [];
67
+ }
68
+ return [[value.toString()]];
69
+ }
70
+
71
+ /**
72
+ * Creates a date value from a date string (YYYY-MM-DD).
73
+ */
74
+ export function date(dateString: string): TextValue {
75
+ validateDateString(dateString);
76
+
77
+ const dateValue: DateValue = {
78
+ type: "date",
79
+ start_date: dateString,
80
+ };
81
+
82
+ return createDateToken(dateValue);
83
+ }
84
+
85
+ /**
86
+ * Creates a datetime value from a Date object.
87
+ */
88
+ export function dateTime(date: Date, timeZone?: string): TextValue {
89
+ const dateValue: DateValue = {
90
+ type: "datetime",
91
+ start_date: formatDate(date),
92
+ start_time: formatTime(date),
93
+ };
94
+
95
+ if (timeZone) {
96
+ dateValue.time_zone = timeZone;
97
+ }
98
+
99
+ return createDateToken(dateValue);
100
+ }
101
+
102
+ /**
103
+ * Creates a date range value from date strings.
104
+ */
105
+ export function dateRange(startDate: string, endDate: string): TextValue {
106
+ validateDateString(startDate);
107
+ validateDateString(endDate);
108
+
109
+ const dateValue: DateValue = {
110
+ type: "daterange",
111
+ start_date: startDate,
112
+ end_date: endDate,
113
+ };
114
+
115
+ return createDateToken(dateValue);
116
+ }
117
+
118
+ /**
119
+ * Creates a datetime range value from Date objects.
120
+ */
121
+ export function dateTimeRange(
122
+ startDate: Date,
123
+ endDate: Date,
124
+ timeZone?: string,
125
+ ): TextValue {
126
+ const dateValue: DateValue = {
127
+ type: "datetimerange",
128
+ start_date: formatDate(startDate),
129
+ start_time: formatTime(startDate),
130
+ end_date: formatDate(endDate),
131
+ end_time: formatTime(endDate),
132
+ };
133
+
134
+ if (timeZone) {
135
+ dateValue.time_zone = timeZone;
136
+ }
137
+
138
+ return createDateToken(dateValue);
139
+ }
140
+
141
+ /**
142
+ * Creates a link with custom display text.
21
143
  * @param displayText - The text to display
22
144
  * @param url - The URL to link to
23
145
  */
24
146
  export function link(displayText: string, url: string): TextValue {
25
147
  return [[displayText, [["a", url]]]];
26
148
  }
149
+
150
+ /**
151
+ * Creates a select value from a single option.
152
+ */
153
+ export function select(value: string): TextValue {
154
+ return [[value]];
155
+ }
156
+
157
+ /**
158
+ * Creates a multi-select value from multiple options.
159
+ * @param values - Array of option names to select
160
+ */
161
+ export function multiSelect(...values: string[]): TextValue {
162
+ if (values.length === 0) {
163
+ return [];
164
+ }
165
+ return [[values.join(",")]];
166
+ }
167
+
168
+ /**
169
+ * Creates a status value from a status option name.
170
+ */
171
+ export function status(value: string): TextValue {
172
+ return [[value]];
173
+ }
174
+
175
+ /**
176
+ * Validates a date string is in YYYY-MM-DD format and represents a valid date.
177
+ */
178
+ function validateDateString(dateString: string): void {
179
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
180
+ throw new Error(
181
+ `Invalid date format: ${dateString}. Expected YYYY-MM-DD format.`,
182
+ );
183
+ }
184
+
185
+ const date = new Date(dateString);
186
+ if (Number.isNaN(date.getTime())) {
187
+ throw new Error(`Invalid date: ${dateString}`);
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Internal helper to create a date mention token from a DateValue object.
193
+ */
194
+ function createDateToken(dateValue: DateValue): TextValue {
195
+ return [["\u2023", [["d", dateValue]]]];
196
+ }
197
+
198
+ /**
199
+ * Formats a Date object to YYYY-MM-DD string.
200
+ */
201
+ function formatDate(date: Date): string {
202
+ const year = date.getFullYear();
203
+ const month = String(date.getMonth() + 1).padStart(2, "0");
204
+ const day = String(date.getDate()).padStart(2, "0");
205
+ return `${year}-${month}-${day}`;
206
+ }
207
+
208
+ /**
209
+ * Formats a Date object to HH:mm string.
210
+ */
211
+ function formatTime(date: Date): string {
212
+ const hours = String(date.getHours()).padStart(2, "0");
213
+ const minutes = String(date.getMinutes()).padStart(2, "0");
214
+ return `${hours}:${minutes}`;
215
+ }
package/src/schema.ts CHANGED
@@ -1,7 +1,26 @@
1
+ import type {
2
+ DateFormat,
3
+ NumberFormat,
4
+ SelectOption,
5
+ StatusGroup,
6
+ } from "./types.js";
7
+
1
8
  /**
2
9
  * Supported property types for sync schemas.
3
10
  */
4
- export type PropertyType = "title" | "rich_text" | "url";
11
+ export type PropertyType =
12
+ | "title"
13
+ | "rich_text"
14
+ | "url"
15
+ | "email"
16
+ | "phone_number"
17
+ | "checkbox"
18
+ | "file"
19
+ | "number"
20
+ | "date"
21
+ | "select"
22
+ | "multi_select"
23
+ | "status";
5
24
 
6
25
  /**
7
26
  * Definition of a single property in a sync schema.
@@ -16,7 +35,31 @@ export type PropertyDefinition = {
16
35
  export type PropertyConfiguration =
17
36
  | { type: "title" }
18
37
  | { type: "text" }
19
- | { type: "url" };
38
+ | { type: "url" }
39
+ | { type: "email" }
40
+ | { type: "phone_number" }
41
+ | { type: "checkbox" }
42
+ | { type: "file" }
43
+ | {
44
+ type: "number";
45
+ format?: NumberFormat;
46
+ }
47
+ | {
48
+ type: "date";
49
+ date_format?: DateFormat;
50
+ }
51
+ | {
52
+ type: "select";
53
+ options: SelectOption[];
54
+ }
55
+ | {
56
+ type: "multi_select";
57
+ options: SelectOption[];
58
+ }
59
+ | {
60
+ type: "status";
61
+ groups: StatusGroup[];
62
+ };
20
63
 
21
64
  export type Schema<PK extends string> = {
22
65
  dataSourceTitle: string;
@@ -52,3 +95,68 @@ export function richText(): PropertyConfiguration {
52
95
  export function url(): PropertyConfiguration {
53
96
  return { type: "url" };
54
97
  }
98
+
99
+ /**
100
+ * Creates an email property definition.
101
+ */
102
+ export function email(): PropertyConfiguration {
103
+ return { type: "email" };
104
+ }
105
+
106
+ /**
107
+ * Creates a phone number property definition.
108
+ */
109
+ export function phoneNumber(): PropertyConfiguration {
110
+ return { type: "phone_number" };
111
+ }
112
+
113
+ /**
114
+ * Creates a checkbox property definition.
115
+ */
116
+ export function checkbox(): PropertyConfiguration {
117
+ return { type: "checkbox" };
118
+ }
119
+
120
+ /**
121
+ * Creates a file property definition.
122
+ */
123
+ export function file(): PropertyConfiguration {
124
+ return { type: "file" };
125
+ }
126
+
127
+ /**
128
+ * Creates a number property definition with optional formatting.
129
+ */
130
+ export function number(format?: NumberFormat): PropertyConfiguration {
131
+ return format ? { type: "number", format } : { type: "number" };
132
+ }
133
+
134
+ /**
135
+ * Creates a date property definition with optional formatting.
136
+ */
137
+ export function date(date_format?: DateFormat): PropertyConfiguration {
138
+ return date_format ? { type: "date", date_format } : { type: "date" };
139
+ }
140
+
141
+ /**
142
+ * Creates a select property definition with predefined options.
143
+ */
144
+ export function select(options: SelectOption[]): PropertyConfiguration {
145
+ return { type: "select", options };
146
+ }
147
+
148
+ /**
149
+ * Creates a multi-select property definition with predefined options.
150
+ */
151
+ export function multiSelect(options: SelectOption[]): PropertyConfiguration {
152
+ return { type: "multi_select", options };
153
+ }
154
+
155
+ /**
156
+ * Creates a status property definition with groups.
157
+ */
158
+ export function status(config: {
159
+ groups: StatusGroup[];
160
+ }): PropertyConfiguration {
161
+ return { type: "status", groups: config.groups };
162
+ }
package/src/types.ts CHANGED
@@ -8,3 +8,109 @@ type TextToken = [string, ...unknown[]];
8
8
  * A TextValue is an array of text tokens, representing rich text content.
9
9
  */
10
10
  export type TextValue = Array<TextToken>;
11
+
12
+ /**
13
+ * Select option color types supported by Notion
14
+ */
15
+ export type SelectColor =
16
+ | "default"
17
+ | "gray"
18
+ | "brown"
19
+ | "orange"
20
+ | "yellow"
21
+ | "green"
22
+ | "blue"
23
+ | "purple"
24
+ | "pink"
25
+ | "red";
26
+
27
+ /**
28
+ * A select option with an optional color
29
+ */
30
+ export interface SelectOption {
31
+ name: string;
32
+ color?: SelectColor;
33
+ }
34
+
35
+ /**
36
+ * Status group types in Notion
37
+ */
38
+ export type StatusGroupType = "To-do" | "In progress" | "Complete";
39
+
40
+ /**
41
+ * Status group configuration
42
+ */
43
+ export interface StatusGroup {
44
+ name: StatusGroupType;
45
+ options: SelectOption[];
46
+ }
47
+
48
+ /**
49
+ * Date object representing a single date without time
50
+ */
51
+ export interface NotionDate {
52
+ type: "date";
53
+ start_date: string; // Format: "YYYY-MM-DD"
54
+ }
55
+
56
+ /**
57
+ * Date object representing a date with time
58
+ */
59
+ export interface NotionDateTime {
60
+ type: "datetime";
61
+ start_date: string; // Format: "YYYY-MM-DD"
62
+ start_time: string; // Format: "HH:mm"
63
+ time_zone?: string; // e.g., "America/Los_Angeles"
64
+ }
65
+
66
+ /**
67
+ * Date object representing a date range
68
+ */
69
+ export interface DateRange {
70
+ type: "daterange";
71
+ start_date: string; // Format: "YYYY-MM-DD"
72
+ end_date: string; // Format: "YYYY-MM-DD"
73
+ }
74
+
75
+ /**
76
+ * Date object representing a date-time range
77
+ */
78
+ export interface DateTimeRange {
79
+ type: "datetimerange";
80
+ start_date: string; // Format: "YYYY-MM-DD"
81
+ start_time: string; // Format: "HH:mm"
82
+ end_date: string; // Format: "YYYY-MM-DD"
83
+ end_time: string; // Format: "HH:mm"
84
+ time_zone?: string;
85
+ }
86
+
87
+ /**
88
+ * All possible date value types
89
+ */
90
+ export type DateValue = NotionDate | NotionDateTime | DateRange | DateTimeRange;
91
+
92
+ /**
93
+ * Number format types
94
+ */
95
+ export type NumberFormat =
96
+ | "number"
97
+ | "number_with_commas"
98
+ | "percent"
99
+ | "dollar"
100
+ | "euro"
101
+ | "pound"
102
+ | "yen"
103
+ | "rupee"
104
+ | "won"
105
+ | "yuan";
106
+
107
+ /**
108
+ * Date format types
109
+ */
110
+ export type DateFormat =
111
+ | "relative"
112
+ | "MM/DD/YYYY"
113
+ | "DD/MM/YYYY"
114
+ | "YYYY/MM/DD"
115
+ | "ll"
116
+ | "MMM d";