@notionhq/apps 0.0.4 → 0.0.7

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 (71) hide show
  1. package/README.md +53 -2
  2. package/dist/builder.d.ts +29 -0
  3. package/dist/builder.d.ts.map +1 -0
  4. package/dist/builder.js +86 -0
  5. package/dist/builder.test.d.ts +2 -0
  6. package/dist/builder.test.d.ts.map +1 -0
  7. package/dist/cli/build.js +1 -1
  8. package/dist/cli/discover.d.ts +2 -2
  9. package/dist/cli/discover.d.ts.map +1 -1
  10. package/dist/cli/discover.js +2 -1
  11. package/dist/cli/emit-manifest.d.ts +2 -2
  12. package/dist/cli/emit-manifest.d.ts.map +1 -1
  13. package/dist/cli/emit-manifest.js +177 -27
  14. package/dist/context.js +2 -2
  15. package/dist/database.d.ts +13 -0
  16. package/dist/database.d.ts.map +1 -0
  17. package/dist/database.js +9 -0
  18. package/dist/error.d.ts +7 -0
  19. package/dist/error.d.ts.map +1 -1
  20. package/dist/error.js +10 -1
  21. package/dist/manifest.d.ts +30 -5
  22. package/dist/manifest.d.ts.map +1 -1
  23. package/dist/manifest.js +4 -0
  24. package/dist/pacer.d.ts +15 -0
  25. package/dist/pacer.d.ts.map +1 -0
  26. package/dist/pacer.js +63 -0
  27. package/dist/runtime-input.d.ts +2 -0
  28. package/dist/runtime-input.d.ts.map +1 -0
  29. package/dist/runtime-input.js +20 -0
  30. package/dist/runtime-input.test.d.ts +2 -0
  31. package/dist/runtime-input.test.d.ts.map +1 -0
  32. package/dist/schedule.d.ts +3 -0
  33. package/dist/schedule.d.ts.map +1 -0
  34. package/dist/schedule.js +23 -0
  35. package/dist/schema.d.ts +111 -0
  36. package/dist/schema.d.ts.map +1 -0
  37. package/dist/schema.js +39 -0
  38. package/dist/sync.d.ts +72 -0
  39. package/dist/sync.d.ts.map +1 -0
  40. package/dist/sync.js +75 -0
  41. package/dist/sync.test.d.ts +2 -0
  42. package/dist/sync.test.d.ts.map +1 -0
  43. package/dist/types.d.ts +85 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +0 -0
  46. package/dist/workflow.d.ts.map +1 -1
  47. package/dist/workflow.js +2 -0
  48. package/docs/BUILD.md +1 -0
  49. package/package.json +33 -2
  50. package/src/builder.test.ts +81 -0
  51. package/src/builder.ts +99 -0
  52. package/src/cli/build.test.ts +109 -0
  53. package/src/cli/build.ts +1 -1
  54. package/src/cli/codegen.test.ts +15 -0
  55. package/src/cli/discover.test.ts +13 -2
  56. package/src/cli/discover.ts +3 -2
  57. package/src/cli/emit-manifest.ts +229 -53
  58. package/src/context.ts +6 -6
  59. package/src/database.ts +25 -0
  60. package/src/error.ts +11 -0
  61. package/src/manifest.ts +33 -5
  62. package/src/pacer.ts +82 -0
  63. package/src/runtime-input.test.ts +65 -0
  64. package/src/runtime-input.ts +30 -0
  65. package/src/schedule.ts +25 -0
  66. package/src/schema.ts +73 -0
  67. package/src/sync.test.ts +359 -0
  68. package/src/sync.ts +190 -0
  69. package/src/types.ts +109 -0
  70. package/src/workflow.test.ts +22 -0
  71. package/src/workflow.ts +2 -0
@@ -1,5 +1,29 @@
1
- /** The only capability type supported by this SDK. */
2
- export type CapabilityType = "workflow";
1
+ import type { NormalizedSchedule } from "./types.js";
2
+ /** Identifies the schema used to validate this manifest independently of the SDK package version. */
3
+ export declare const APPS_MANIFEST_SCHEMA: "notion:apps-manifest:v1";
4
+ /** Capability types supported by this SDK. */
5
+ export type CapabilityType = "workflow" | "sync";
6
+ export type DatabaseManifestConfig = {
7
+ initialTitle?: string;
8
+ schema: unknown;
9
+ };
10
+ export type DatabaseManifestEntry = {
11
+ key: string;
12
+ config: DatabaseManifestConfig;
13
+ };
14
+ export type PacerManifestEntry = {
15
+ key: string;
16
+ config: {
17
+ allowedRequests: number;
18
+ intervalMs: number;
19
+ };
20
+ };
21
+ export type SyncManifestConfig = {
22
+ databaseKey: string;
23
+ primaryKeyProperty: string;
24
+ mode?: "replace" | "incremental";
25
+ schedule?: NormalizedSchedule;
26
+ };
3
27
  /**
4
28
  * One capability in the manifest: its type, its key (derived from its
5
29
  * filename), and its handler-free configuration.
@@ -15,11 +39,12 @@ export type CapabilityManifestEntry = {
15
39
  * complete, static description of the app.
16
40
  */
17
41
  export type AppManifest = {
42
+ $schema: typeof APPS_MANIFEST_SCHEMA;
18
43
  sdkVersion: string;
19
- /** Reserved platform fields; workflow-only apps always emit empty arrays. */
20
- databases: never[];
44
+ databases: DatabaseManifestEntry[];
45
+ /** Reserved platform field; the Apps SDK does not support XLDB. */
21
46
  xldbs: never[];
22
- pacers: never[];
47
+ pacers: PacerManifestEntry[];
23
48
  capabilities: CapabilityManifestEntry[];
24
49
  };
25
50
  //# sourceMappingURL=manifest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,SAAS,EAAE,KAAK,EAAE,CAAC;IACnB,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,YAAY,EAAE,uBAAuB,EAAE,CAAC;CACxC,CAAC"}
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,qGAAqG;AACrG,eAAO,MAAM,oBAAoB,EAAG,yBAAkC,CAAC;AAEvE,8CAA8C;AAC9C,MAAM,MAAM,cA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ests: number;
3
+ intervalMs: number;
4
+ };
5
+ export type PacerEntry = PacerConfig & {
6
+ lastScheduledAtMs: number;
7
+ };
8
+ export type Pacer = {
9
+ _tag: "pacer";
10
+ name: string;
11
+ config: PacerConfig;
12
+ wait(): Promise<void>;
13
+ };
14
+ export declare function createPacer(name: string, config: PacerConfig): Pacer;
15
+ //# sourceMappingURL=pacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.d.ts","sourceRoot":"","sources":["../src/pacer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB,CAAC;AAiBF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,KAAK,CA+BpE"}
package/dist/pacer.js ADDED
@@ -0,0 +1,63 @@
1
+ const REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@notionhq/apps/pacer-registry");
2
+ const STATE_KEY = /* @__PURE__ */ Symbol.for("@notionhq/apps/pacer-state");
3
+ function registry() {
4
+ const holder = globalThis;
5
+ holder[REGISTRY_KEY] ??= /* @__PURE__ */ new Map();
6
+ return holder[REGISTRY_KEY];
7
+ }
8
+ function state() {
9
+ const holder = globalThis;
10
+ holder[STATE_KEY] ??= /* @__PURE__ */ new Map();
11
+ return holder[STATE_KEY];
12
+ }
13
+ function createPacer(name, config) {
14
+ if (typeof name !== "string" || name.length === 0) {
15
+ throw new Error("Pacer name must be a non-empty string");
16
+ }
17
+ if (!Number.isFinite(config.allowedRequests) || config.allowedRequests <= 0) {
18
+ throw new Error("Pacer allowedRequests must be greater than zero");
19
+ }
20
+ if (!Number.isFinite(config.intervalMs) || config.intervalMs <= 0) {
21
+ throw new Error("Pacer intervalMs must be greater than zero");
22
+ }
23
+ if (registry().has(name)) {
24
+ throw new Error(`Two distinct pacers are named "${name}"`);
25
+ }
26
+ const pacer = {
27
+ _tag: "pacer",
28
+ name,
29
+ config,
30
+ async wait() {
31
+ const entry = state().get(name) ?? { ...config, lastScheduledAtMs: 0 };
32
+ const stepMs = Math.ceil(entry.intervalMs / entry.allowedRequests);
33
+ const now = Date.now();
34
+ const scheduledAtMs = Math.max(entry.lastScheduledAtMs + stepMs, now);
35
+ state().set(name, { ...entry, lastScheduledAtMs: scheduledAtMs });
36
+ if (scheduledAtMs > now) {
37
+ await new Promise((resolve) => setTimeout(resolve, scheduledAtMs - now));
38
+ }
39
+ }
40
+ };
41
+ registry().set(name, pacer);
42
+ return pacer;
43
+ }
44
+ function initPacerState(entries) {
45
+ state().clear();
46
+ for (const [name, entry] of Object.entries(entries ?? {})) state().set(name, entry);
47
+ }
48
+ function pacerStates() {
49
+ return Object.fromEntries(state());
50
+ }
51
+ function registeredPacers() {
52
+ return [...registry().values()];
53
+ }
54
+ function clearRegisteredPacers() {
55
+ registry().clear();
56
+ }
57
+ export {
58
+ clearRegisteredPacers,
59
+ createPacer,
60
+ initPacerState,
61
+ pacerStates,
62
+ registeredPacers
63
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-input.d.ts","sourceRoot":"","sources":["../src/runtime-input.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { readFile } from "node:fs/promises";
2
+ async function resolveRuntimeInput(fallback) {
3
+ const inputPayloadPath = process.env.NOTION_INPUT_PAYLOAD_PATH;
4
+ if (inputPayloadPath === void 0) {
5
+ return fallback;
6
+ }
7
+ let serializedInput;
8
+ try {
9
+ serializedInput = await readFile(inputPayloadPath, "utf8");
10
+ } catch (error) {
11
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
12
+ return fallback;
13
+ }
14
+ throw error;
15
+ }
16
+ return JSON.parse(serializedInput);
17
+ }
18
+ export {
19
+ resolveRuntimeInput
20
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime-input.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-input.test.d.ts","sourceRoot":"","sources":["../src/runtime-input.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { NormalizedSchedule, Schedule } from "./types.js";
2
+ export declare function parseSchedule(schedule: Schedule): NormalizedSchedule;
3
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAKzE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,kBAAkB,CAmBpE"}
@@ -0,0 +1,23 @@
1
+ const MIN_INTERVAL_MS = 6e4;
2
+ const MAX_INTERVAL_MS = 7 * 24 * 60 * 6e4;
3
+ function parseSchedule(schedule) {
4
+ if (schedule === "continuous" || schedule === "manual") return { type: schedule };
5
+ const match = schedule.match(/^(\d+)(m|h|d)$/);
6
+ if (!match?.[1] || !match[2]) {
7
+ throw new Error(`Invalid schedule format: "${schedule}"`);
8
+ }
9
+ const value = Number.parseInt(match[1], 10);
10
+ const multipliers = {
11
+ m: 6e4,
12
+ h: 60 * 6e4,
13
+ d: 24 * 60 * 6e4
14
+ };
15
+ const intervalMs = value * multipliers[match[2]];
16
+ if (intervalMs < MIN_INTERVAL_MS)
17
+ throw new Error("Schedule interval must be at least 1 minute");
18
+ if (intervalMs > MAX_INTERVAL_MS) throw new Error("Schedule interval must be at most 7 days");
19
+ return { type: "interval", intervalMs };
20
+ }
21
+ export {
22
+ parseSchedule
23
+ };
@@ -0,0 +1,111 @@
1
+ import type { Database } from "./database.js";
2
+ import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "./types.js";
3
+ export type TitleProperty = {
4
+ type: "title";
5
+ };
6
+ export type TextProperty = {
7
+ type: "text";
8
+ };
9
+ export type PropertyConfiguration = TitleProperty | TextProperty | {
10
+ type: "url";
11
+ } | {
12
+ type: "email";
13
+ } | {
14
+ type: "phone_number";
15
+ } | {
16
+ type: "checkbox";
17
+ } | {
18
+ type: "file";
19
+ } | {
20
+ type: "number";
21
+ format?: NumberFormat;
22
+ } | {
23
+ type: "date";
24
+ date_format?: DateFormat;
25
+ } | {
26
+ type: "select";
27
+ options: SelectOption[];
28
+ } | {
29
+ type: "multi_select";
30
+ options: SelectOption[];
31
+ } | {
32
+ type: "status";
33
+ groups: StatusGroup[];
34
+ } | {
35
+ type: "people";
36
+ } | {
37
+ type: "place";
38
+ } | {
39
+ type: "relation";
40
+ database: Database;
41
+ config: {
42
+ twoWay: false;
43
+ } | {
44
+ twoWay: true;
45
+ relatedPropertyName: string;
46
+ };
47
+ };
48
+ export type DatabaseSchema = Record<string, PropertyConfiguration>;
49
+ export type DatabaseSchemaOptions = {
50
+ databaseIcon?: Icon;
51
+ subItems?: {
52
+ parentPropertyName: string;
53
+ childPropertyName: string;
54
+ };
55
+ };
56
+ export declare const Schema: {
57
+ title: () => TitleProperty;
58
+ richText: () => TextProperty;
59
+ url: () => {
60
+ type: "url";
61
+ };
62
+ email: () => {
63
+ type: "email";
64
+ };
65
+ phoneNumber: () => {
66
+ type: "phone_number";
67
+ };
68
+ checkbox: () => {
69
+ type: "checkbox";
70
+ };
71
+ file: () => {
72
+ type: "file";
73
+ };
74
+ number: (format?: NumberFormat) => {
75
+ type: "number";
76
+ format?: NumberFormat;
77
+ };
78
+ date: (date_format?: DateFormat) => {
79
+ type: "date";
80
+ date_format?: DateFormat;
81
+ };
82
+ select: (options: SelectOption[]) => {
83
+ type: "select";
84
+ options: SelectOption[];
85
+ };
86
+ multiSelect: (options: SelectOption[]) => {
87
+ type: "multi_select";
88
+ options: SelectOption[];
89
+ };
90
+ status: (config: {
91
+ groups: StatusGroup[];
92
+ }) => {
93
+ type: "status";
94
+ groups: StatusGroup[];
95
+ };
96
+ people: () => {
97
+ type: "people";
98
+ };
99
+ place: () => {
100
+ type: "place";
101
+ };
102
+ relation: (database: Database, config?: {
103
+ twoWay: false;
104
+ } | {
105
+ twoWay: true;
106
+ relatedPropertyName: string;
107
+ }) => Extract<PropertyConfiguration, {
108
+ type: "relation";
109
+ }>;
110
+ };
111
+ //# 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,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5F,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAC9C,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,qBAAqB,GAC9B,aAAa,GACb,YAAY,GACZ;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;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,YAAY,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,MA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AI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,UAAU,CAAA;KAAE;sBAI1D,YAAY,EAAE,KAAG;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,OAAO,EAAE,YAAY,EAAE,CAAA;KAAE;2BAIvD,YAAY,EAAE,KAAG;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,YAAY,EAAE,CAAA;KAAE;qBAIxE;QAAE,MAAM,EAAE,WAAW,EAAE,CAAA;KAAE,KAAG;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,WAAW,EAAE,CAAA;KAAE;kBAI1E;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE;iBACnB;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE;yBAEjB,QAAQ,WACT;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE,GAAG;QAAE,MAAM,EAAE,IAAI,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE,KACxE,OAAO,CAAC,qBAAqB,EAAE;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;CAKvD,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,39 @@
1
+ const Schema = {
2
+ title: () => ({ type: "title" }),
3
+ richText: () => ({ type: "text" }),
4
+ url: () => ({ type: "url" }),
5
+ email: () => ({ type: "email" }),
6
+ phoneNumber: () => ({ type: "phone_number" }),
7
+ checkbox: () => ({ type: "checkbox" }),
8
+ file: () => ({ type: "file" }),
9
+ number: (format) => ({
10
+ type: "number",
11
+ ...format === void 0 ? {} : { format }
12
+ }),
13
+ date: (date_format) => ({
14
+ type: "date",
15
+ ...date_format === void 0 ? {} : { date_format }
16
+ }),
17
+ select: (options) => ({
18
+ type: "select",
19
+ options
20
+ }),
21
+ multiSelect: (options) => ({
22
+ type: "multi_select",
23
+ options
24
+ }),
25
+ status: (config) => ({
26
+ type: "status",
27
+ groups: config.groups
28
+ }),
29
+ people: () => ({ type: "people" }),
30
+ place: () => ({ type: "place" }),
31
+ relation: (database, config) => ({
32
+ type: "relation",
33
+ database,
34
+ config: config ?? { twoWay: false }
35
+ })
36
+ };
37
+ export {
38
+ Schema
39
+ };
package/dist/sync.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type { CapabilityContext } from "./context.js";
2
+ import type { Database } from "./database.js";
3
+ import { type PacerEntry } from "./pacer.js";
4
+ import type { DatabaseSchema, PropertyConfiguration, TextProperty, TitleProperty } from "./schema.js";
5
+ import type { Cover, HandlerOptions, Icon, NormalizedSchedule, PeopleValue, PlaceValue, RelationValue, Schedule, TextValue } from "./types.js";
6
+ type KeyProperty = TitleProperty | TextProperty;
7
+ /** Names of title or rich-text properties in a database schema. */
8
+ export type KeyPropertyName<S extends DatabaseSchema> = Extract<{
9
+ [P in keyof S]: S[P] extends KeyProperty ? P : never;
10
+ }[keyof S], string>;
11
+ type PropertyValue<T extends PropertyConfiguration> = T extends {
12
+ type: "people";
13
+ } ? PeopleValue : T extends {
14
+ type: "place";
15
+ } ? PlaceValue : T extends {
16
+ type: "relation";
17
+ } ? RelationValue : TextValue;
18
+ export type SyncMode = "replace" | "incremental";
19
+ export type SyncChangeUpsert<S extends DatabaseSchema, PrimaryKey extends KeyPropertyName<S>> = {
20
+ type: "upsert";
21
+ key: string;
22
+ properties: Omit<{
23
+ [P in keyof S]: PropertyValue<S[P]>;
24
+ }, PrimaryKey>;
25
+ upstreamUpdatedAt?: string;
26
+ icon?: Icon;
27
+ cover?: Cover;
28
+ pageContentMarkdown?: string;
29
+ };
30
+ export type SyncChangeDelete = {
31
+ type: "delete";
32
+ key: string;
33
+ };
34
+ export type SyncChange<S extends DatabaseSchema, PrimaryKey extends KeyPropertyName<S>> = SyncChangeUpsert<S, PrimaryKey> | SyncChangeDelete;
35
+ export type SyncHandlerResult<S extends DatabaseSchema, PrimaryKey extends KeyPropertyName<S>, State> = {
36
+ changes: SyncChange<S, PrimaryKey>[];
37
+ hasMore?: boolean;
38
+ nextState?: State;
39
+ };
40
+ export type SyncConfiguration<S extends DatabaseSchema, PrimaryKey extends KeyPropertyName<S>, State> = {
41
+ database: Database<S>;
42
+ primaryKey: PrimaryKey;
43
+ mode?: SyncMode;
44
+ schedule?: Schedule;
45
+ handler: (state: State | undefined, context: CapabilityContext) => Promise<SyncHandlerResult<S, PrimaryKey, State>>;
46
+ };
47
+ export type SyncRuntimeContext = {
48
+ state?: unknown;
49
+ userContext?: unknown;
50
+ pacers?: Record<string, PacerEntry>;
51
+ };
52
+ type SyncDefinitionConfig = {
53
+ database: Database;
54
+ primaryKeyProperty: string;
55
+ mode?: SyncMode;
56
+ schedule?: NormalizedSchedule;
57
+ };
58
+ export type SyncRunResult = {
59
+ changes: unknown[];
60
+ hasMore: boolean;
61
+ nextUserContext?: unknown;
62
+ nextPacerStates: Record<string, PacerEntry>;
63
+ };
64
+ export type Sync = {
65
+ _tag: "sync";
66
+ config: SyncDefinitionConfig;
67
+ handler: (context?: SyncRuntimeContext, options?: HandlerOptions) => Promise<SyncRunResult>;
68
+ };
69
+ /** Create a database sync. Default-export it from a file in `src/syncs/`. */
70
+ export declare function createSync<const S extends DatabaseSchema, const PrimaryKey extends KeyPropertyName<S>, State = unknown>(configuration: SyncConfiguration<S, PrimaryKey, State>): Sync;
71
+ export {};
72
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAG1E,OAAO,KAAK,EACX,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,KAAK,EACL,cAAc,EACd,IAAI,EACJ,kBAAkB,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AC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,CAAC;IAC7B,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CAC5F,CAAC;AAEF,6EAA6E;AAC7E,wBAAgB,UAAU,CACzB,KAAK,CAAC,CAAC,SAAS,cAAc,EAC9B,KAAK,CAAC,UAAU,SAAS,eAAe,CAAC,CAAC,CAAC,EAC3C,KAAK,GAAG,OAAO,EACd,aAAa,EAAE,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,IAAI,CAuE9D"}
package/dist/sync.js ADDED
@@ -0,0 +1,75 @@
1
+ import { createCapabilityContext } from "./context.js";
2
+ import { ExecutionError, RateLimitError } from "./error.js";
3
+ import { writeOutput } from "./output.js";
4
+ import { initPacerState, pacerStates } from "./pacer.js";
5
+ import { resolveRuntimeInput } from "./runtime-input.js";
6
+ import { parseSchedule } from "./schedule.js";
7
+ function createSync(configuration) {
8
+ const schedule = configuration.schedule === void 0 ? void 0 : parseSchedule(configuration.schedule);
9
+ const config = {
10
+ database: configuration.database,
11
+ primaryKeyProperty: configuration.primaryKey,
12
+ ...configuration.mode === void 0 ? {} : { mode: configuration.mode },
13
+ ...schedule === void 0 ? {} : { schedule }
14
+ };
15
+ return {
16
+ _tag: "sync",
17
+ config,
18
+ async handler(runtimeContext, options) {
19
+ try {
20
+ runtimeContext = await resolveRuntimeInput(runtimeContext);
21
+ initPacerState(runtimeContext?.pacers);
22
+ const state = runtimeContext?.state ?? runtimeContext?.userContext;
23
+ const handlerResult = await configuration.handler(state, createCapabilityContext());
24
+ const changes = handlerResult.changes.map((change) => {
25
+ if (change.type === "delete") {
26
+ return { ...change, targetDatabaseKey: configuration.database.key };
27
+ }
28
+ return {
29
+ ...change,
30
+ properties: {
31
+ ...change.properties,
32
+ [configuration.primaryKey]: [[change.key]]
33
+ },
34
+ targetDatabaseKey: configuration.database.key
35
+ };
36
+ });
37
+ const result = {
38
+ changes,
39
+ hasMore: handlerResult.hasMore ?? false,
40
+ nextUserContext: handlerResult.nextState,
41
+ nextPacerStates: pacerStates()
42
+ };
43
+ if (options?.concreteOutput) return result;
44
+ writeOutput({ _tag: "success", value: result });
45
+ return result;
46
+ } catch (cause) {
47
+ if (cause instanceof RateLimitError) {
48
+ if (!options?.concreteOutput) {
49
+ writeOutput({
50
+ _tag: "error",
51
+ error: {
52
+ _tag: "rate_limit",
53
+ name: cause.name,
54
+ message: cause.message,
55
+ retryAfter: cause.retryAfter
56
+ }
57
+ });
58
+ }
59
+ throw cause;
60
+ }
61
+ const error = new ExecutionError(cause);
62
+ if (!options?.concreteOutput) {
63
+ writeOutput({
64
+ _tag: "error",
65
+ error: { _tag: "generic", name: error.name, message: error.message }
66
+ });
67
+ }
68
+ throw error;
69
+ }
70
+ }
71
+ };
72
+ }
73
+ export {
74
+ createSync
75
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sync.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.test.d.ts","sourceRoot":"","sources":["../src/sync.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,85 @@
1
+ export type TextToken = [string, ...unknown[]];
2
+ export type TextValue = TextToken[];
3
+ export type PeopleValue = Array<{
4
+ email: string;
5
+ }>;
6
+ export type PlaceValue = {
7
+ lat: number;
8
+ lon: number;
9
+ name?: string;
10
+ address?: string;
11
+ googlePlaceId?: string;
12
+ };
13
+ export type RelationReference = {
14
+ type: "primaryKey";
15
+ value: string;
16
+ };
17
+ export type RelationValue = RelationReference[];
18
+ export type NotionDate = {
19
+ type: "date";
20
+ start_date: string;
21
+ };
22
+ export type NotionDateTime = {
23
+ type: "datetime";
24
+ start_date: string;
25
+ start_time: string;
26
+ time_zone?: string;
27
+ };
28
+ export type DateRange = {
29
+ type: "daterange";
30
+ start_date: string;
31
+ end_date: string;
32
+ };
33
+ export type DateTimeRange = {
34
+ type: "datetimerange";
35
+ start_date: string;
36
+ start_time: string;
37
+ end_date: string;
38
+ end_time: string;
39
+ time_zone?: string;
40
+ };
41
+ export type DateValue = NotionDate | NotionDateTime | DateRange | DateTimeRange;
42
+ export type SelectColor = "default" | "gray" | "brown" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "red";
43
+ export type SelectOption = {
44
+ name: string;
45
+ color?: SelectColor;
46
+ };
47
+ export type StatusGroupType = "To-do" | "In progress" | "Complete";
48
+ export type StatusGroup = {
49
+ name: StatusGroupType;
50
+ options: SelectOption[];
51
+ };
52
+ export type NumberFormat = "number" | "number_with_commas" | "percent" | "dollar" | "euro" | "pound" | "yen" | "rupee" | "won" | "yuan";
53
+ export type DateFormat = "relative" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY/MM/DD" | "ll" | "MMM d";
54
+ export type NoticonColor = "gray" | "lightgray" | "brown" | "yellow" | "orange" | "green" | "blue" | "purple" | "pink" | "red";
55
+ export type Icon = {
56
+ type: "emoji";
57
+ value: string;
58
+ } | {
59
+ type: "notion";
60
+ icon: string;
61
+ color: NoticonColor;
62
+ } | {
63
+ type: "image";
64
+ url: string;
65
+ };
66
+ export type Cover = {
67
+ type: "image";
68
+ url: string;
69
+ position?: number;
70
+ };
71
+ export type TimeUnit = "m" | "h" | "d";
72
+ export type IntervalString = `${number}${TimeUnit}`;
73
+ export type Schedule = "continuous" | "manual" | IntervalString;
74
+ export type NormalizedSchedule = {
75
+ type: "continuous";
76
+ } | {
77
+ type: "manual";
78
+ } | {
79
+ type: "interval";
80
+ intervalMs: number;
81
+ };
82
+ export type HandlerOptions = {
83
+ concreteOutput?: true;
84
+ };
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAC/C,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAEpC,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEnD,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe,CA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;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAC7B,KAAK,CAAC,SAAS,SAAS,SAAS,CAAC,eAAe,EAAE,GAAG,eAAe,EAAE,CAAC,EACvE,aAAa,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CA6CtE;AAED,yCAAyC;AACzC,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;AAEvD,mCAAmC;AACnC,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;OAIG;IACH,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,KAAK,YAAY,GAAG;IACnB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAChG,CAAC,CAAC,EACD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,mBAAmB,EAC5B,EAAE,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAC9C,WAAW,GAAG;IACb;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,EAAE,YAAY,CAAC;CACnB,CAAC"}
package/dist/workflow.js CHANGED
@@ -4,6 +4,7 @@ import { join } from "node:path";
4
4
  import { createCapabilityContext } from "./context.js";
5
5
  import { ExecutionError } from "./error.js";
6
6
  import { writeOutput } from "./output.js";
7
+ import { resolveRuntimeInput } from "./runtime-input.js";
7
8
  import { readRunMetadata } from "./runtime-metadata.js";
8
9
  function createWorkflow(configuration) {
9
10
  return {
@@ -15,6 +16,7 @@ function createWorkflow(configuration) {
15
16
  },
16
17
  async handler(event, options) {
17
18
  try {
19
+ event = await resolveRuntimeInput(event);
18
20
  const runMetadata = readRunMetadata();
19
21
  const capabilityContext = {
20
22
  ...createCapabilityContext(),