@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.
Files changed (75) hide show
  1. package/README.md +47 -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 +1 -1
  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/triggers.generated.d.ts +1 -1
  44. package/dist/triggers.generated.d.ts.map +1 -1
  45. package/dist/triggers.generated.js +1 -1
  46. package/dist/types.d.ts +85 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +0 -0
  49. package/dist/workflow.d.ts.map +1 -1
  50. package/dist/workflow.js +2 -0
  51. package/docs/BUILD.md +1 -0
  52. package/package.json +33 -2
  53. package/src/builder.test.ts +81 -0
  54. package/src/builder.ts +99 -0
  55. package/src/cli/build.test.ts +109 -0
  56. package/src/cli/build.ts +1 -1
  57. package/src/cli/codegen.test.ts +15 -0
  58. package/src/cli/discover.test.ts +13 -2
  59. package/src/cli/discover.ts +3 -2
  60. package/src/cli/emit-manifest.ts +229 -53
  61. package/src/context.ts +1 -1
  62. package/src/database.ts +25 -0
  63. package/src/error.ts +11 -0
  64. package/src/manifest.ts +33 -5
  65. package/src/pacer.ts +82 -0
  66. package/src/runtime-input.test.ts +65 -0
  67. package/src/runtime-input.ts +30 -0
  68. package/src/schedule.ts +25 -0
  69. package/src/schema.ts +73 -0
  70. package/src/sync.test.ts +359 -0
  71. package/src/sync.ts +190 -0
  72. package/src/triggers.generated.ts +1 -1
  73. package/src/types.ts +109 -0
  74. package/src/workflow.test.ts +22 -0
  75. 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
+ };
@@ -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(),