@notionhq/apps 0.0.3 → 0.0.6
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/README.md +47 -2
- package/dist/builder.d.ts +29 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +86 -0
- package/dist/builder.test.d.ts +2 -0
- package/dist/builder.test.d.ts.map +1 -0
- package/dist/cli/build.js +1 -1
- package/dist/cli/discover.d.ts +2 -2
- package/dist/cli/discover.d.ts.map +1 -1
- package/dist/cli/discover.js +2 -1
- package/dist/cli/emit-manifest.d.ts +2 -2
- package/dist/cli/emit-manifest.d.ts.map +1 -1
- package/dist/cli/emit-manifest.js +177 -27
- package/dist/context.js +1 -1
- package/dist/database.d.ts +13 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +9 -0
- package/dist/error.d.ts +7 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +10 -1
- package/dist/manifest.d.ts +30 -5
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +4 -0
- package/dist/pacer.d.ts +15 -0
- package/dist/pacer.d.ts.map +1 -0
- package/dist/pacer.js +63 -0
- package/dist/runtime-input.d.ts +2 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +20 -0
- package/dist/runtime-input.test.d.ts +2 -0
- package/dist/runtime-input.test.d.ts.map +1 -0
- package/dist/schedule.d.ts +3 -0
- package/dist/schedule.d.ts.map +1 -0
- package/dist/schedule.js +23 -0
- package/dist/schema.d.ts +111 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +39 -0
- package/dist/sync.d.ts +72 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +75 -0
- package/dist/sync.test.d.ts +2 -0
- package/dist/sync.test.d.ts.map +1 -0
- package/dist/triggers.generated.d.ts +1 -1
- package/dist/triggers.generated.d.ts.map +1 -1
- package/dist/triggers.generated.js +1 -1
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +2 -0
- package/docs/BUILD.md +1 -0
- package/package.json +33 -2
- package/src/builder.test.ts +81 -0
- package/src/builder.ts +99 -0
- package/src/cli/build.test.ts +109 -0
- package/src/cli/build.ts +1 -1
- package/src/cli/codegen.test.ts +15 -0
- package/src/cli/discover.test.ts +13 -2
- package/src/cli/discover.ts +3 -2
- package/src/cli/emit-manifest.ts +229 -53
- package/src/context.ts +1 -1
- package/src/database.ts +25 -0
- package/src/error.ts +11 -0
- package/src/manifest.ts +33 -5
- package/src/pacer.ts +82 -0
- package/src/runtime-input.test.ts +65 -0
- package/src/runtime-input.ts +30 -0
- package/src/schedule.ts +25 -0
- package/src/schema.ts +73 -0
- package/src/sync.test.ts +359 -0
- package/src/sync.ts +190 -0
- package/src/triggers.generated.ts +1 -1
- package/src/types.ts +109 -0
- package/src/workflow.test.ts +22 -0
- package/src/workflow.ts +2 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export type TextToken = [string, ...unknown[]];
|
|
2
|
+
export type TextValue = TextToken[];
|
|
3
|
+
|
|
4
|
+
export type PeopleValue = Array<{ email: string }>;
|
|
5
|
+
|
|
6
|
+
export type PlaceValue = {
|
|
7
|
+
lat: number;
|
|
8
|
+
lon: number;
|
|
9
|
+
name?: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
googlePlaceId?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type RelationReference = {
|
|
15
|
+
type: "primaryKey";
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type RelationValue = RelationReference[];
|
|
20
|
+
|
|
21
|
+
export type NotionDate = {
|
|
22
|
+
type: "date";
|
|
23
|
+
start_date: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type NotionDateTime = {
|
|
27
|
+
type: "datetime";
|
|
28
|
+
start_date: string;
|
|
29
|
+
start_time: string;
|
|
30
|
+
time_zone?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type DateRange = {
|
|
34
|
+
type: "daterange";
|
|
35
|
+
start_date: string;
|
|
36
|
+
end_date: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type DateTimeRange = {
|
|
40
|
+
type: "datetimerange";
|
|
41
|
+
start_date: string;
|
|
42
|
+
start_time: string;
|
|
43
|
+
end_date: string;
|
|
44
|
+
end_time: string;
|
|
45
|
+
time_zone?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type DateValue = NotionDate | NotionDateTime | DateRange | DateTimeRange;
|
|
49
|
+
|
|
50
|
+
export type SelectColor =
|
|
51
|
+
| "default"
|
|
52
|
+
| "gray"
|
|
53
|
+
| "brown"
|
|
54
|
+
| "orange"
|
|
55
|
+
| "yellow"
|
|
56
|
+
| "green"
|
|
57
|
+
| "blue"
|
|
58
|
+
| "purple"
|
|
59
|
+
| "pink"
|
|
60
|
+
| "red";
|
|
61
|
+
|
|
62
|
+
export type SelectOption = { name: string; color?: SelectColor };
|
|
63
|
+
export type StatusGroupType = "To-do" | "In progress" | "Complete";
|
|
64
|
+
export type StatusGroup = { name: StatusGroupType; options: SelectOption[] };
|
|
65
|
+
|
|
66
|
+
export type NumberFormat =
|
|
67
|
+
| "number"
|
|
68
|
+
| "number_with_commas"
|
|
69
|
+
| "percent"
|
|
70
|
+
| "dollar"
|
|
71
|
+
| "euro"
|
|
72
|
+
| "pound"
|
|
73
|
+
| "yen"
|
|
74
|
+
| "rupee"
|
|
75
|
+
| "won"
|
|
76
|
+
| "yuan";
|
|
77
|
+
|
|
78
|
+
export type DateFormat = "relative" | "MM/DD/YYYY" | "DD/MM/YYYY" | "YYYY/MM/DD" | "ll" | "MMM d";
|
|
79
|
+
|
|
80
|
+
export type NoticonColor =
|
|
81
|
+
| "gray"
|
|
82
|
+
| "lightgray"
|
|
83
|
+
| "brown"
|
|
84
|
+
| "yellow"
|
|
85
|
+
| "orange"
|
|
86
|
+
| "green"
|
|
87
|
+
| "blue"
|
|
88
|
+
| "purple"
|
|
89
|
+
| "pink"
|
|
90
|
+
| "red";
|
|
91
|
+
|
|
92
|
+
export type Icon =
|
|
93
|
+
| { type: "emoji"; value: string }
|
|
94
|
+
| { type: "notion"; icon: string; color: NoticonColor }
|
|
95
|
+
| { type: "image"; url: string };
|
|
96
|
+
|
|
97
|
+
export type Cover = { type: "image"; url: string; position?: number };
|
|
98
|
+
|
|
99
|
+
export type TimeUnit = "m" | "h" | "d";
|
|
100
|
+
export type IntervalString = `${number}${TimeUnit}`;
|
|
101
|
+
export type Schedule = "continuous" | "manual" | IntervalString;
|
|
102
|
+
export type NormalizedSchedule =
|
|
103
|
+
| { type: "continuous" }
|
|
104
|
+
| { type: "manual" }
|
|
105
|
+
| { type: "interval"; intervalMs: number };
|
|
106
|
+
|
|
107
|
+
export type HandlerOptions = {
|
|
108
|
+
concreteOutput?: true;
|
|
109
|
+
};
|
package/src/workflow.test.ts
CHANGED
|
@@ -25,6 +25,7 @@ beforeEach(async () => {
|
|
|
25
25
|
afterEach(async () => {
|
|
26
26
|
stdoutSpy.mockRestore();
|
|
27
27
|
delete process.env.NOTION_WORKFLOW_STEP_DIRECTORY;
|
|
28
|
+
delete process.env.NOTION_INPUT_PAYLOAD_PATH;
|
|
28
29
|
delete process.env.NOTION_RUN_METADATA_PATH;
|
|
29
30
|
if (checkpointDirectory) {
|
|
30
31
|
await rm(checkpointDirectory, { recursive: true, force: true });
|
|
@@ -754,6 +755,27 @@ describe("createWorkflow", () => {
|
|
|
754
755
|
);
|
|
755
756
|
});
|
|
756
757
|
|
|
758
|
+
it("uses a file-backed event instead of the inline event", async () => {
|
|
759
|
+
if (!metadataDirectory) {
|
|
760
|
+
throw new Error("Metadata directory was not created");
|
|
761
|
+
}
|
|
762
|
+
const handler = vi.fn();
|
|
763
|
+
const workflow = createWorkflow({
|
|
764
|
+
name: "Log Pages",
|
|
765
|
+
description: "Logs created pages",
|
|
766
|
+
triggers: [triggers.notionPageCreated()],
|
|
767
|
+
handler,
|
|
768
|
+
});
|
|
769
|
+
const fileEvent = { ...event, message: "File event" };
|
|
770
|
+
const inputPath = join(metadataDirectory, "input.json");
|
|
771
|
+
await writeFile(inputPath, JSON.stringify(fileEvent));
|
|
772
|
+
process.env.NOTION_INPUT_PAYLOAD_PATH = inputPath;
|
|
773
|
+
|
|
774
|
+
await workflow.handler(event, { concreteOutput: true });
|
|
775
|
+
|
|
776
|
+
expect(handler).toHaveBeenCalledWith(fileEvent, expect.anything());
|
|
777
|
+
});
|
|
778
|
+
|
|
757
779
|
it("returns the status without an envelope under concreteOutput", async () => {
|
|
758
780
|
const workflow = createWorkflow({
|
|
759
781
|
name: "Log Pages",
|
package/src/workflow.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { CapabilityContext } from "./context.js";
|
|
|
6
6
|
import { createCapabilityContext } from "./context.js";
|
|
7
7
|
import { ExecutionError } from "./error.js";
|
|
8
8
|
import { writeOutput } from "./output.js";
|
|
9
|
+
import { resolveRuntimeInput } from "./runtime-input.js";
|
|
9
10
|
import { readRunMetadata, type RunMetadata } from "./runtime-metadata.js";
|
|
10
11
|
import type { WorkflowEventMap, WorkflowTrigger } from "./triggers.generated.js";
|
|
11
12
|
|
|
@@ -115,6 +116,7 @@ export function createWorkflow<
|
|
|
115
116
|
options?: HandlerOptions,
|
|
116
117
|
): Promise<{ status: "success" } | undefined> {
|
|
117
118
|
try {
|
|
119
|
+
event = await resolveRuntimeInput(event);
|
|
118
120
|
const runMetadata = readRunMetadata();
|
|
119
121
|
const capabilityContext: WorkflowContext = {
|
|
120
122
|
...createCapabilityContext(),
|