@notionhq/apps 0.0.14 → 0.0.16
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/AGENTS.md +13 -0
- package/README.md +126 -27
- package/dist/cli/emit-manifest.d.ts.map +1 -1
- package/dist/cli/emit-manifest.js +1 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -0
- package/dist/context.test.d.ts +2 -0
- package/dist/context.test.d.ts.map +1 -0
- package/dist/custom-block.d.ts +1 -1
- package/dist/custom-block.d.ts.map +1 -1
- package/dist/custom-block.js +3 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/notion-as-code/database.d.ts +23 -1
- package/dist/notion-as-code/database.d.ts.map +1 -1
- package/dist/notion-as-code/database.js +27 -0
- package/dist/notion-as-code/index.d.ts +1 -1
- package/dist/notion-as-code/index.d.ts.map +1 -1
- package/dist/notion-as-code/page.d.ts +3 -3
- package/dist/notion-as-code/page.d.ts.map +1 -1
- package/dist/notion-as-code/page.js +2 -7
- package/dist/notion-as-code/teamspace.d.ts +3 -3
- package/dist/notion-as-code/teamspace.d.ts.map +1 -1
- package/dist/notion-as-code/teamspace.js +2 -7
- package/dist/sync.d.ts +2 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +3 -3
- package/dist/workflow.d.ts +6 -6
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +2 -2
- package/docs/BUILD.md +5 -5
- package/docs/CONNECTIONS.md +5 -4
- package/package.json +7 -1
- package/skills/connections/SKILL.md +86 -0
- package/skills/custom-blocks/SKILL.md +45 -0
- package/skills/notion-as-code/SKILL.md +189 -0
- package/skills/sync/SKILL.md +98 -0
- package/skills/workflow/SKILL.md +123 -0
- package/src/cli/build.test.ts +97 -7
- package/src/cli/emit-manifest.ts +1 -5
- package/src/context.test.ts +26 -0
- package/src/context.ts +8 -0
- package/src/custom-block.test.ts +4 -4
- package/src/custom-block.ts +2 -2
- package/src/index.ts +7 -0
- package/src/notion-as-code/database.ts +72 -2
- package/src/notion-as-code/index.ts +4 -0
- package/src/notion-as-code/page.ts +3 -11
- package/src/notion-as-code/teamspace.ts +3 -11
- package/src/sync.ts +2 -2
- package/src/workflow-connections-types.test.ts +6 -6
- package/src/workflow-types.test.ts +2 -2
- package/src/workflow.test.ts +31 -31
- package/src/workflow.ts +7 -7
package/src/workflow.test.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi, type Moc
|
|
|
8
8
|
import { ExecutionError } from "./error.js";
|
|
9
9
|
import type { RunMetadata } from "./runtime-metadata.js";
|
|
10
10
|
import { triggers, type NotionPageCreatedEvent } from "./triggers.generated.js";
|
|
11
|
-
import { connections,
|
|
11
|
+
import { connections, workflow, type StepContext, type WorkflowContext } from "./workflow.js";
|
|
12
12
|
|
|
13
13
|
let stdoutSpy: Mock<typeof process.stdout.write>;
|
|
14
14
|
let checkpointDirectory: string | undefined;
|
|
@@ -39,7 +39,7 @@ const event = { type: "notion.page.created" } as NotionPageCreatedEvent;
|
|
|
39
39
|
|
|
40
40
|
async function createWorkflowContext(): Promise<WorkflowContext<readonly []>> {
|
|
41
41
|
let context: WorkflowContext<readonly []> | undefined;
|
|
42
|
-
const
|
|
42
|
+
const definition = workflow({
|
|
43
43
|
name: "Test workflow",
|
|
44
44
|
description: "Captures its workflow context",
|
|
45
45
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -48,7 +48,7 @@ async function createWorkflowContext(): Promise<WorkflowContext<readonly []>> {
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
await
|
|
51
|
+
await definition.handler(event, { concreteOutput: true });
|
|
52
52
|
|
|
53
53
|
if (!context) {
|
|
54
54
|
throw new Error("Workflow context was not created");
|
|
@@ -638,7 +638,7 @@ describe("step", () => {
|
|
|
638
638
|
|
|
639
639
|
it("resets duplicate key tracking for each workflow call", async () => {
|
|
640
640
|
const keys: string[] = [];
|
|
641
|
-
const
|
|
641
|
+
const definition = workflow({
|
|
642
642
|
name: "Reuse step key",
|
|
643
643
|
description: "Checks that a key can be reused in a new invocation",
|
|
644
644
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -654,14 +654,14 @@ describe("step", () => {
|
|
|
654
654
|
},
|
|
655
655
|
});
|
|
656
656
|
|
|
657
|
-
await
|
|
658
|
-
await
|
|
657
|
+
await definition.handler(event, { concreteOutput: true });
|
|
658
|
+
await definition.handler(event, { concreteOutput: true });
|
|
659
659
|
|
|
660
660
|
expect(keys).toEqual([workflowStepKey(["First"]), workflowStepKey(["First"])]);
|
|
661
661
|
});
|
|
662
662
|
|
|
663
663
|
it("writes step events under concreteOutput", async () => {
|
|
664
|
-
const
|
|
664
|
+
const definition = workflow({
|
|
665
665
|
name: "Log Pages",
|
|
666
666
|
description: "Logs created pages",
|
|
667
667
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -670,7 +670,7 @@ describe("step", () => {
|
|
|
670
670
|
},
|
|
671
671
|
});
|
|
672
672
|
|
|
673
|
-
await
|
|
673
|
+
await definition.handler(event, { concreteOutput: true });
|
|
674
674
|
|
|
675
675
|
expect(stdoutSpy).toHaveBeenCalledTimes(3);
|
|
676
676
|
expect(stdoutSpy.mock.calls[0]?.[0]).toEqual(
|
|
@@ -721,17 +721,17 @@ async function writeRunMetadata(overrides: Partial<RunMetadata> = {}): Promise<v
|
|
|
721
721
|
process.env.NOTION_RUN_METADATA_PATH = metadataPath;
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
-
describe("
|
|
724
|
+
describe("workflow", () => {
|
|
725
725
|
it("is tagged and exposes triggers in config", () => {
|
|
726
|
-
const
|
|
726
|
+
const definition = workflow({
|
|
727
727
|
name: "Log Pages",
|
|
728
728
|
description: "Logs created pages",
|
|
729
729
|
triggers: [triggers.notionPageCreated()],
|
|
730
730
|
handler: () => {},
|
|
731
731
|
});
|
|
732
732
|
|
|
733
|
-
expect(
|
|
734
|
-
expect(
|
|
733
|
+
expect(definition._tag).toBe("workflow");
|
|
734
|
+
expect(definition.config).toEqual({
|
|
735
735
|
name: "Log Pages",
|
|
736
736
|
description: "Logs created pages",
|
|
737
737
|
triggers: [{ type: "notion.page.created" }],
|
|
@@ -739,7 +739,7 @@ describe("createWorkflow", () => {
|
|
|
739
739
|
});
|
|
740
740
|
|
|
741
741
|
it("declares a Calendar connection requirement", () => {
|
|
742
|
-
const
|
|
742
|
+
const definition = workflow({
|
|
743
743
|
name: "Schedule Follow-up",
|
|
744
744
|
description: "Schedules a follow-up after a page is created",
|
|
745
745
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -747,12 +747,12 @@ describe("createWorkflow", () => {
|
|
|
747
747
|
handler: () => {},
|
|
748
748
|
});
|
|
749
749
|
|
|
750
|
-
expect(
|
|
750
|
+
expect(definition.config.connections).toEqual([{ type: "calendar" }]);
|
|
751
751
|
});
|
|
752
752
|
|
|
753
753
|
it("rejects duplicate connection requirements", () => {
|
|
754
754
|
expect(() =>
|
|
755
|
-
|
|
755
|
+
workflow({
|
|
756
756
|
name: "Schedule Follow-up",
|
|
757
757
|
description: "Schedules a follow-up after a page is created",
|
|
758
758
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -764,14 +764,14 @@ describe("createWorkflow", () => {
|
|
|
764
764
|
|
|
765
765
|
it("writes a success envelope after the handler runs", async () => {
|
|
766
766
|
const handler = vi.fn();
|
|
767
|
-
const
|
|
767
|
+
const definition = workflow({
|
|
768
768
|
name: "Log Pages",
|
|
769
769
|
description: "Logs created pages",
|
|
770
770
|
triggers: [triggers.notionPageCreated()],
|
|
771
771
|
handler,
|
|
772
772
|
});
|
|
773
773
|
|
|
774
|
-
await
|
|
774
|
+
await definition.handler(event);
|
|
775
775
|
|
|
776
776
|
expect(handler).toHaveBeenCalledWith(event, expect.anything());
|
|
777
777
|
expect(stdoutSpy).toHaveBeenCalledWith(
|
|
@@ -784,7 +784,7 @@ describe("createWorkflow", () => {
|
|
|
784
784
|
throw new Error("Metadata directory was not created");
|
|
785
785
|
}
|
|
786
786
|
const handler = vi.fn();
|
|
787
|
-
const
|
|
787
|
+
const definition = workflow({
|
|
788
788
|
name: "Log Pages",
|
|
789
789
|
description: "Logs created pages",
|
|
790
790
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -795,27 +795,27 @@ describe("createWorkflow", () => {
|
|
|
795
795
|
await writeFile(inputPath, JSON.stringify(fileEvent));
|
|
796
796
|
process.env.NOTION_INPUT_PAYLOAD_PATH = inputPath;
|
|
797
797
|
|
|
798
|
-
await
|
|
798
|
+
await definition.handler(event, { concreteOutput: true });
|
|
799
799
|
|
|
800
800
|
expect(handler).toHaveBeenCalledWith(fileEvent, expect.anything());
|
|
801
801
|
});
|
|
802
802
|
|
|
803
803
|
it("returns the status without an envelope under concreteOutput", async () => {
|
|
804
|
-
const
|
|
804
|
+
const definition = workflow({
|
|
805
805
|
name: "Log Pages",
|
|
806
806
|
description: "Logs created pages",
|
|
807
807
|
triggers: [triggers.notionPageCreated()],
|
|
808
808
|
handler: () => {},
|
|
809
809
|
});
|
|
810
810
|
|
|
811
|
-
await expect(
|
|
811
|
+
await expect(definition.handler(event, { concreteOutput: true })).resolves.toEqual({
|
|
812
812
|
status: "success",
|
|
813
813
|
});
|
|
814
814
|
expect(stdoutSpy).not.toHaveBeenCalled();
|
|
815
815
|
});
|
|
816
816
|
|
|
817
817
|
it("writes an error envelope and throws ExecutionError on failure", async () => {
|
|
818
|
-
const
|
|
818
|
+
const definition = workflow({
|
|
819
819
|
name: "Log Pages",
|
|
820
820
|
description: "Logs created pages",
|
|
821
821
|
triggers: [triggers.notionPageCreated()],
|
|
@@ -824,7 +824,7 @@ describe("createWorkflow", () => {
|
|
|
824
824
|
},
|
|
825
825
|
});
|
|
826
826
|
|
|
827
|
-
await expect(
|
|
827
|
+
await expect(definition.handler(event)).rejects.toBeInstanceOf(ExecutionError);
|
|
828
828
|
expect(stdoutSpy).toHaveBeenCalledWith(
|
|
829
829
|
expect.stringContaining(
|
|
830
830
|
`<__notion_output__>{"_tag":"error","error":{"name":"ExecutionError","message":"Error during app execution: Error: boom"`,
|
|
@@ -836,7 +836,7 @@ describe("createWorkflow", () => {
|
|
|
836
836
|
describe("connection-bound triggers", () => {
|
|
837
837
|
it("resolves typed trigger callbacks once and preserves event inference", () => {
|
|
838
838
|
let calls = 0;
|
|
839
|
-
const
|
|
839
|
+
const definition = workflow({
|
|
840
840
|
name: "Typed triggers",
|
|
841
841
|
description: "Uses only declared provider keys",
|
|
842
842
|
connections: [connections.slack({ key: "support" }), connections.calendar()],
|
|
@@ -866,14 +866,14 @@ describe("connection-bound triggers", () => {
|
|
|
866
866
|
},
|
|
867
867
|
});
|
|
868
868
|
expect(calls).toBe(1);
|
|
869
|
-
expect(
|
|
869
|
+
expect(definition.config.triggers).toEqual([
|
|
870
870
|
{ type: "slack.message", connectionKey: "support" },
|
|
871
871
|
{ type: "calendar.event.created", connectionKey: "calendar" },
|
|
872
872
|
]);
|
|
873
873
|
});
|
|
874
874
|
|
|
875
875
|
it("preserves the binding in the manifest and infers the event", () => {
|
|
876
|
-
const
|
|
876
|
+
const definition = workflow({
|
|
877
877
|
name: "Support",
|
|
878
878
|
description: "Watch support messages",
|
|
879
879
|
connections: [connections.slack({ key: "support" })],
|
|
@@ -882,7 +882,7 @@ describe("connection-bound triggers", () => {
|
|
|
882
882
|
expectTypeOf(event.type).toEqualTypeOf<"slack.message">();
|
|
883
883
|
},
|
|
884
884
|
});
|
|
885
|
-
expect(
|
|
885
|
+
expect(definition.config.triggers).toEqual([
|
|
886
886
|
{ type: "slack.message", connectionKey: "support" },
|
|
887
887
|
]);
|
|
888
888
|
});
|
|
@@ -892,7 +892,7 @@ describe("connection-bound triggers", () => {
|
|
|
892
892
|
{ requirements: [connections.slack({ key: "other" })] },
|
|
893
893
|
])("rejects missing or incompatible declarations: %j", ({ requirements }) => {
|
|
894
894
|
expect(() =>
|
|
895
|
-
|
|
895
|
+
workflow({
|
|
896
896
|
name: "Support",
|
|
897
897
|
description: "",
|
|
898
898
|
connections: requirements,
|
|
@@ -912,7 +912,7 @@ describe("connection-bound triggers", () => {
|
|
|
912
912
|
handler() {},
|
|
913
913
|
};
|
|
914
914
|
expect(() =>
|
|
915
|
-
|
|
915
|
+
workflow({
|
|
916
916
|
...configuration,
|
|
917
917
|
triggers: [
|
|
918
918
|
triggers.slackMessage({ connectionKey: "support" }),
|
|
@@ -921,7 +921,7 @@ describe("connection-bound triggers", () => {
|
|
|
921
921
|
}),
|
|
922
922
|
).toThrow("Duplicate");
|
|
923
923
|
expect(() =>
|
|
924
|
-
|
|
924
|
+
workflow({
|
|
925
925
|
...configuration,
|
|
926
926
|
triggers: [
|
|
927
927
|
triggers.slackMessage({ connectionKey: "support" }),
|
|
@@ -933,7 +933,7 @@ describe("connection-bound triggers", () => {
|
|
|
933
933
|
it("preserves existing unkeyed helpers", () => {
|
|
934
934
|
expect(triggers.slackMessage()).toEqual({ type: "slack.message" });
|
|
935
935
|
expect(() =>
|
|
936
|
-
|
|
936
|
+
workflow({
|
|
937
937
|
name: "Existing",
|
|
938
938
|
description: "",
|
|
939
939
|
triggers: [triggers.slackMessage()],
|
package/src/workflow.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type WorkflowEventForTriggers<T extends readonly WorkflowTrigger[]> =
|
|
|
38
38
|
export { connections, type WorkflowConnection, type WorkflowConnections } from "./connections.js";
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Configuration passed to {@link
|
|
41
|
+
* Configuration passed to {@link workflow}.
|
|
42
42
|
*/
|
|
43
43
|
export type WorkflowConfiguration<
|
|
44
44
|
TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
@@ -81,7 +81,7 @@ export type WorkflowTriggerConfiguration<
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* A workflow capability as returned by {@link
|
|
84
|
+
* A workflow capability as returned by {@link workflow}.
|
|
85
85
|
*
|
|
86
86
|
* Note that a workflow carries no key of its own — the build tool derives
|
|
87
87
|
* the capability key from the file the workflow is default-exported from.
|
|
@@ -115,9 +115,9 @@ export type Workflow<
|
|
|
115
115
|
* ```ts
|
|
116
116
|
* // src/workflows/onPageCreated.ts
|
|
117
117
|
* import { triggers } from "@notionhq/apps/triggers";
|
|
118
|
-
* import {
|
|
118
|
+
* import { workflow } from "@notionhq/apps/workflow";
|
|
119
119
|
*
|
|
120
|
-
* export default
|
|
120
|
+
* export default workflow({
|
|
121
121
|
* name: "Send Welcome Email",
|
|
122
122
|
* description: "Sends a welcome email when a new page is added",
|
|
123
123
|
* triggers: [triggers.notionPageCreated()],
|
|
@@ -131,18 +131,18 @@ export type Workflow<
|
|
|
131
131
|
* });
|
|
132
132
|
* ```
|
|
133
133
|
*/
|
|
134
|
-
export function
|
|
134
|
+
export function workflow<
|
|
135
135
|
const TTriggers extends readonly [
|
|
136
136
|
WorkflowTriggerForConnections<NoInfer<TConnections>>,
|
|
137
137
|
...WorkflowTriggerForConnections<NoInfer<TConnections>>[],
|
|
138
138
|
],
|
|
139
139
|
const TConnections extends readonly WorkflowConnection[] = readonly [],
|
|
140
140
|
>(configuration: WorkflowTriggerConfiguration<TTriggers, TConnections>): Workflow<TTriggers>;
|
|
141
|
-
export function
|
|
141
|
+
export function workflow<
|
|
142
142
|
const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
143
143
|
const TConnections extends readonly WorkflowConnection[] = readonly [],
|
|
144
144
|
>(configuration: WorkflowConfiguration<TTriggers, TConnections>): Workflow<TTriggers>;
|
|
145
|
-
export function
|
|
145
|
+
export function workflow<
|
|
146
146
|
const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
|
|
147
147
|
const TConnections extends readonly WorkflowConnection[] = readonly [],
|
|
148
148
|
>(
|