@notionhq/apps 0.0.33 → 0.0.34
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 +59 -5
- package/dist/configured-events.d.ts +45 -0
- package/dist/configured-events.d.ts.map +1 -0
- package/dist/configured-events.js +38 -0
- package/dist/configured-events.test.d.ts +2 -0
- package/dist/configured-events.test.d.ts.map +1 -0
- package/dist/custom-block.d.ts +1 -1
- package/dist/events-types.test.d.ts +2 -0
- package/dist/events-types.test.d.ts.map +1 -0
- package/dist/{triggers.d.ts → events.d.ts} +1 -1
- package/dist/events.d.ts.map +1 -0
- package/dist/{triggers.generated.d.ts → events.generated.d.ts} +20 -38
- package/dist/events.generated.d.ts.map +1 -0
- package/dist/{triggers.generated.js → events.generated.js} +9 -35
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/notion-as-code/custom-agent.d.ts +3 -48
- package/dist/notion-as-code/custom-agent.d.ts.map +1 -1
- package/dist/notion-as-code/database.d.ts +11 -0
- package/dist/notion-as-code/database.d.ts.map +1 -1
- package/dist/notion-as-code/database.js +12 -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/recurrence.d.ts +49 -0
- package/dist/notion-as-code/recurrence.d.ts.map +1 -0
- package/dist/notion-as-code/recurrence.js +0 -0
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +2 -2
- package/package.json +7 -7
- package/skills/connections/SKILL.md +3 -3
- package/skills/workflow/SKILL.md +25 -5
- package/src/cli/build.test.ts +30 -0
- package/src/configured-events.test.ts +90 -0
- package/src/configured-events.ts +101 -0
- package/src/connections.ts +1 -1
- package/src/events-types.test.ts +110 -0
- package/src/{triggers.generated.ts → events.generated.ts} +21 -55
- package/src/index.ts +1 -0
- package/src/notion-as-code/custom-agent.ts +15 -61
- package/src/notion-as-code/database.ts +27 -0
- package/src/notion-as-code/index.ts +2 -0
- package/src/notion-as-code/recurrence.ts +58 -0
- package/src/workflow-access-types.test.ts +4 -4
- package/src/workflow-connections-types.test.ts +7 -7
- package/src/workflow-types.test.ts +23 -23
- package/src/workflow.test.ts +39 -39
- package/src/workflow.ts +7 -7
- package/dist/triggers.d.ts.map +0 -1
- package/dist/triggers.generated.d.ts.map +0 -1
- /package/dist/{triggers.js → events.js} +0 -0
- /package/src/{triggers.ts → events.ts} +0 -0
|
@@ -223,6 +223,7 @@ function recordCustomView(databaseResourceId, view, handles) {
|
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
function createDataSourceHandle(dataSource, schema, databaseDescription) {
|
|
226
|
+
const propertyEntries = [];
|
|
226
227
|
const propertyResourceIds = /* @__PURE__ */ new Set();
|
|
227
228
|
const propertyNames = /* @__PURE__ */ new Set();
|
|
228
229
|
for (const property of dataSource.properties) {
|
|
@@ -239,6 +240,16 @@ function createDataSourceHandle(dataSource, schema, databaseDescription) {
|
|
|
239
240
|
}
|
|
240
241
|
propertyResourceIds.add(property.resourceId);
|
|
241
242
|
propertyNames.add(property.name);
|
|
243
|
+
propertyEntries.push([
|
|
244
|
+
property.name,
|
|
245
|
+
{
|
|
246
|
+
resourceType: "property",
|
|
247
|
+
resourceId: property.resourceId,
|
|
248
|
+
dataSourceResourceId: dataSource.resourceId,
|
|
249
|
+
name: property.name,
|
|
250
|
+
propertyType: property.type
|
|
251
|
+
}
|
|
252
|
+
]);
|
|
242
253
|
}
|
|
243
254
|
const description = dataSource.description ?? databaseDescription;
|
|
244
255
|
return {
|
|
@@ -247,6 +258,7 @@ function createDataSourceHandle(dataSource, schema, databaseDescription) {
|
|
|
247
258
|
name: dataSource.name,
|
|
248
259
|
...description === void 0 ? {} : { description },
|
|
249
260
|
schema,
|
|
261
|
+
properties: Object.fromEntries(propertyEntries),
|
|
250
262
|
database: createAppsDatabase(dataSource.resourceId, dataSource),
|
|
251
263
|
addPage(pageArgs) {
|
|
252
264
|
return createPage(pageArgs, { type: "resourceId", resourceId: dataSource.resourceId });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { APPS_RESERVED_RESOURCE_ID_PREFIX, APPS_WORKSPACE_RESOURCE_ID } from "./intents.js";
|
|
2
2
|
export type { ContentPageLayoutTab, DatabasePageLayout, DatabasePageLayoutTab, DatabaseIntent, DataSourceDefinition, NotionAsCodeIcon, NotionAsCodeProperty, NotionAsCodePropertyConfig, NotionAsCodeSchema, NotionAsCodeSelectOption, NotionAsCodeStatusOption, PageCoverReference, PageLayoutMainModule, PageLayoutNumberAndFormulaStyle, PageLayoutPersonStyle, PageLayoutPropertiesModule, PageLayoutPropertyConfig, PageLayoutPropertyModule, PageLayoutPropertySection, PageLayoutRelationConfig, PageLayoutRelationsGroupModule, PageLayoutSidebarModule, Parent, ResourceId, RollupBaseAggregationType, RollupDateAggregationType, RollupNumberAggregationType, RollupTargetPropertyType, ViewPageLayoutTab, } from "./intents.js";
|
|
3
3
|
export type { CustomAgentAccess, CustomAgentArgs, CustomAgentHandle, CustomAgentPageAddedTrigger, CustomAgentPropertyUpdatedTrigger, CustomAgentRecurrenceSchedule, CustomAgentRecurrenceTrigger, CustomAgentTrustedUrls, CustomAgentTrigger, CustomAgentTriggerBase, DailyRecurrenceSchedule, HourlyRecurrenceSchedule, MonthlyRecurrenceRestriction, MonthlyRecurrenceSchedule, MonthlyWeekdayOccurrence, PropertyTriggerCondition, RecurrenceScheduleEnd, RecurrenceWeekdays, WeeklyRecurrenceSchedule, YearlyRecurrenceSchedule, } from "./custom-agent.js";
|
|
4
|
-
export type { AddCustomViewArgs, ChildDatabaseArgs, ChildDatabaseFactory, ChildMultiSourceDatabaseArgs, ChildSingleSourceDatabaseArgs, DataSourceArgs, DataSourceHandle, DataSourceMap, DatabaseArgs, DatabaseHandle, MultiSourceDatabaseArgs, SingleSourceDatabaseArgs, SingleSourceDatabaseHandle, } from "./database.js";
|
|
4
|
+
export type { AddCustomViewArgs, ChildDatabaseArgs, ChildDatabaseFactory, ChildMultiSourceDatabaseArgs, ChildSingleSourceDatabaseArgs, DataSourceArgs, DataSourceHandle, DataSourceProperties, PropertyHandle, DataSourceMap, DatabaseArgs, DatabaseHandle, MultiSourceDatabaseArgs, SingleSourceDatabaseArgs, SingleSourceDatabaseHandle, } from "./database.js";
|
|
5
5
|
export { toCustomBlockDefaultBinding, toCustomBlockDataSource } from "../translate.js";
|
|
6
6
|
export type { ChildPageArgs, PageArgs, PageHandle, PropertyValue, SimpleTextToken, TextValue, VerificationInput, VerificationPropertyValue, } from "./page.js";
|
|
7
7
|
export type { TeamspaceArgs, TeamspaceHandle } from "./teamspace.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EACX,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,EAC/B,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,EAC9B,uBAAuB,EACvB,MAAM,EACN,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EACX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,E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B,+BAA+B,EAC/B,qBAAqB,EACrB,sCAAsC,EACtC,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;CAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EACX,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,EAC/B,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,EAC9B,uBAAuB,EACvB,MAAM,EACN,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EACX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,iCAAiC,EACjC,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACX,iBAAiB,EACjB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AkB,EAClB,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;CAAiB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type RecurrenceWeekday = "MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU";
|
|
2
|
+
/** A nonempty selection of weekdays for a weekly recurrence. */
|
|
3
|
+
export type RecurrenceWeekdays = {
|
|
4
|
+
[Day in RecurrenceWeekday]?: true;
|
|
5
|
+
} & {
|
|
6
|
+
[Day in RecurrenceWeekday]: Required<Pick<Record<RecurrenceWeekday, true>, Day>>;
|
|
7
|
+
}[RecurrenceWeekday];
|
|
8
|
+
export type MonthlyWeekdayOccurrence = "1st" | "2nd" | "3rd" | "4th" | "last";
|
|
9
|
+
export type MonthlyRecurrenceRestriction = {
|
|
10
|
+
type: "day_of_month";
|
|
11
|
+
day: number;
|
|
12
|
+
} | {
|
|
13
|
+
type: "weekday_of_month";
|
|
14
|
+
weekday: RecurrenceWeekday;
|
|
15
|
+
occurrence: MonthlyWeekdayOccurrence;
|
|
16
|
+
};
|
|
17
|
+
export type RecurrenceScheduleEnd = {
|
|
18
|
+
type: "date";
|
|
19
|
+
endsAt: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "occurrences";
|
|
22
|
+
count: number;
|
|
23
|
+
};
|
|
24
|
+
type RecurrenceScheduleBase = {
|
|
25
|
+
interval: number;
|
|
26
|
+
start: string;
|
|
27
|
+
timeZone: string;
|
|
28
|
+
end?: RecurrenceScheduleEnd;
|
|
29
|
+
};
|
|
30
|
+
export type HourlyRecurrenceSchedule = RecurrenceScheduleBase & {
|
|
31
|
+
frequency: "hour";
|
|
32
|
+
};
|
|
33
|
+
export type DailyRecurrenceSchedule = RecurrenceScheduleBase & {
|
|
34
|
+
frequency: "day";
|
|
35
|
+
};
|
|
36
|
+
export type WeeklyRecurrenceSchedule = RecurrenceScheduleBase & {
|
|
37
|
+
frequency: "week";
|
|
38
|
+
weekdays: RecurrenceWeekdays;
|
|
39
|
+
};
|
|
40
|
+
export type MonthlyRecurrenceSchedule = RecurrenceScheduleBase & {
|
|
41
|
+
frequency: "month";
|
|
42
|
+
monthlyRestriction: MonthlyRecurrenceRestriction;
|
|
43
|
+
};
|
|
44
|
+
export type YearlyRecurrenceSchedule = RecurrenceScheduleBase & {
|
|
45
|
+
frequency: "year";
|
|
46
|
+
};
|
|
47
|
+
export type RecurrenceSchedule = HourlyRecurrenceSchedule | DailyRecurrenceSchedule | WeeklyRecurrenceSchedule | MonthlyRecurrenceSchedule | YearlyRecurrenceSchedule;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=recurrence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurrence.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/recurrence.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExE,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAAG;KAC/B,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE,IAAI;CACjC,GAAG;KACF,GAAG,IAAI,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;CAChF,CAAC,iBAAiB,CAAC,CAAC;AAErB,MAAM,MAAM,wBAAwB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAE9E,MAAM,MAAM,4BAA4B,GACrC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACrC;IACA,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,UAAU,EAAE,wBAAwB,CAAC;CACpC,CAAC;AAEL,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,KAAK,sBAAsB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC/D,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,sBAAsB,GAAG;IAC9D,SAAS,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,GAAG;IAChE,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,4BAA4B,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC/D,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC3B,wBAAwB,GACxB,uBAAuB,GACvB,wBAAwB,GACxB,yBAAyB,GACzB,wBAAwB,CAAC"}
|
|
File without changes
|
package/dist/workflow.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type WorkflowAccess, type WorkflowAccessDeclarations, type WorkflowAcce
|
|
|
3
3
|
import type { CapabilityContext } from "./context.js";
|
|
4
4
|
import { type RunMetadata } from "./runtime-metadata.js";
|
|
5
5
|
import { type WorkflowState } from "./workflow-state.js";
|
|
6
|
-
import type { WorkflowEventMap, WorkflowTrigger,
|
|
6
|
+
import type { WorkflowEventMap, WorkflowTrigger, WorkflowEventCreators, WorkflowTriggerForConnections } from "./events.generated.js";
|
|
7
7
|
type HandlerOptions = {
|
|
8
8
|
/** Return the concrete result instead of writing the output envelope. */
|
|
9
9
|
concreteOutput?: true;
|
|
@@ -131,7 +131,7 @@ export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, .
|
|
|
131
131
|
/** Configuration that checks trigger keys against declared connections. */
|
|
132
132
|
export type WorkflowTriggerConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess>, "triggers"> & {
|
|
133
133
|
triggers: (context: {
|
|
134
|
-
|
|
134
|
+
events: WorkflowEventCreators<NoInfer<TConnections>>;
|
|
135
135
|
}) => TTriggers;
|
|
136
136
|
};
|
|
137
137
|
/**
|
|
@@ -163,13 +163,13 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
|
|
|
163
163
|
* @example
|
|
164
164
|
* ```ts
|
|
165
165
|
* // src/workflows/onPageCreated.ts
|
|
166
|
-
* import {
|
|
166
|
+
* import { events } from "@notionhq/apps/events";
|
|
167
167
|
* import { workflow } from "@notionhq/apps/workflow";
|
|
168
168
|
*
|
|
169
169
|
* export default workflow({
|
|
170
170
|
* name: "Send Welcome Email",
|
|
171
171
|
* description: "Sends a welcome email when a new page is added",
|
|
172
|
-
* triggers: [
|
|
172
|
+
* triggers: [events.notionPageCreated()],
|
|
173
173
|
* handler: async (event, context) => {
|
|
174
174
|
* console.log(event.page);
|
|
175
175
|
* await context.step("Process page", async ({ id }) => {
|
package/dist/workflow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"m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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,KAAK,YAAY,GAAG;IACnB;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,OAAO,SAAS,mBAAmB,EACjD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAC3C,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3C,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,eAAe,CAC1B,YAAY,SAAS,8BAA8B,GAAG,8BAA8B,EACpF,OAAO,SAAS,0BAA0B,GAAG,0BAA0B,IACpE,iBAAiB,GAAG;IACvB,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,WAAW,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC/C,GAAG,WAAW,GAAG;IAChB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,EAAE,YAAY,CAAC;IACnB,iEAAiE;IACjE,IAAI,EAAE,YAAY,CAAC;CACnB,CAAC"}
|
package/dist/workflow.js
CHANGED
|
@@ -15,7 +15,7 @@ import { ExecutionError } from "./error.js";
|
|
|
15
15
|
import { writeOutput } from "./output.js";
|
|
16
16
|
import { resolveRuntimeInput } from "./runtime-input.js";
|
|
17
17
|
import { readRunMetadata } from "./runtime-metadata.js";
|
|
18
|
-
import {
|
|
18
|
+
import { createWorkflowEvents } from "./events.generated.js";
|
|
19
19
|
import { createWorkflowStepState } from "./workflow-state.js";
|
|
20
20
|
const input = {
|
|
21
21
|
text(options) {
|
|
@@ -54,7 +54,7 @@ function workflow(configuration) {
|
|
|
54
54
|
const requirements = normalizeConnectionRequirements(configuration.connections ?? {});
|
|
55
55
|
const accessRequirements = normalizeWorkflowAccess(configuration.access);
|
|
56
56
|
const connectionDeclarations = configuration.connections === void 0 ? void 0 : structuredClone(configuration.connections);
|
|
57
|
-
const triggers = typeof configuration.triggers === "function" ? configuration.triggers({
|
|
57
|
+
const triggers = typeof configuration.triggers === "function" ? configuration.triggers({ events: createWorkflowEvents() }) : configuration.triggers;
|
|
58
58
|
validateTriggerConnections(triggers, requirements);
|
|
59
59
|
return {
|
|
60
60
|
_tag: "workflow",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/apps",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "An SDK for building workflow apps for Notion",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"types": "./dist/manifest.d.ts",
|
|
56
56
|
"default": "./dist/manifest.js"
|
|
57
57
|
},
|
|
58
|
-
"./
|
|
59
|
-
"types": "./dist/
|
|
60
|
-
"default": "./dist/
|
|
58
|
+
"./events": {
|
|
59
|
+
"types": "./dist/events.generated.d.ts",
|
|
60
|
+
"default": "./dist/events.generated.js"
|
|
61
61
|
},
|
|
62
62
|
"./workflow": {
|
|
63
63
|
"types": "./dist/workflow.d.ts",
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"build:watch": "concurrently --group \"pnpm run build:watch:types\" \"pnpm run build:watch:js\"",
|
|
100
100
|
"build:watch:types": "tsc --watch",
|
|
101
101
|
"build:watch:js": "esbuild --watch --format=esm --outdir=dist --target=node26 --packages=external ./src/**.ts ./src/**/*.ts",
|
|
102
|
-
"generate": "tsx scripts/generate-
|
|
103
|
-
"generate:check": "tsx scripts/generate-
|
|
104
|
-
"sync:
|
|
102
|
+
"generate": "tsx scripts/generate-events.ts",
|
|
103
|
+
"generate:check": "tsx scripts/generate-events.ts --check",
|
|
104
|
+
"sync:events": "tsx scripts/sync-events.ts",
|
|
105
105
|
"test": "vitest run",
|
|
106
106
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.scripts.json"
|
|
107
107
|
},
|
|
@@ -41,7 +41,7 @@ capability context with `notion`; do not assume they have provider clients.
|
|
|
41
41
|
|
|
42
42
|
## Bind triggers to connections
|
|
43
43
|
|
|
44
|
-
For provider triggers, use the `triggers: ({
|
|
44
|
+
For provider triggers, use the `triggers: ({ events }) => [...]` callback
|
|
45
45
|
on `workflow`. Its trigger creators infer valid connection keys from
|
|
46
46
|
the workflow's declarations:
|
|
47
47
|
|
|
@@ -53,7 +53,7 @@ export default workflow({
|
|
|
53
53
|
name: "Watch support messages",
|
|
54
54
|
description: "Runs when a message arrives through the support connection.",
|
|
55
55
|
connections: { support: connections.slack() },
|
|
56
|
-
triggers: ({
|
|
56
|
+
triggers: ({ events }) => [events.slackMessage({ connectionKey: "support" })],
|
|
57
57
|
handler: async (_event, context) => {
|
|
58
58
|
await context.step("Record trigger", () => {
|
|
59
59
|
console.log("Support message received");
|
|
@@ -62,7 +62,7 @@ export default workflow({
|
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
Use the callback's `
|
|
65
|
+
Use the callback's `events` argument to get connection-key checking.
|
|
66
66
|
`connectionKey` refers to a declared key for that trigger's provider, not an
|
|
67
67
|
external account ID or a durable step key. Here, a typo or a key belonging to
|
|
68
68
|
a different provider's connection is a type error. For example, `{ slack: connections.slack() }` declares the key `"slack"`.
|
package/skills/workflow/SKILL.md
CHANGED
|
@@ -133,14 +133,14 @@ Import the handle into the workflow and declare the named binding it needs:
|
|
|
133
133
|
|
|
134
134
|
```ts
|
|
135
135
|
import { access, workflow } from "@notionhq/apps";
|
|
136
|
-
import {
|
|
136
|
+
import { events } from "@notionhq/apps/events";
|
|
137
137
|
|
|
138
138
|
import { guide } from "./sayHello/lib/notion.js";
|
|
139
139
|
|
|
140
140
|
export default workflow({
|
|
141
141
|
name: "Read guide",
|
|
142
142
|
description: "Reads the App's guide on a recurring schedule.",
|
|
143
|
-
triggers: [
|
|
143
|
+
triggers: [events.scheduled()],
|
|
144
144
|
access: { guide: access.view(guide) },
|
|
145
145
|
handler: async (_event, context) => {
|
|
146
146
|
await context.step("Read guide", () =>
|
|
@@ -155,7 +155,7 @@ declarations in `access` work too. Importing a declaration alone provisions the
|
|
|
155
155
|
resource but does not create a `context.access` alias. An `access` entry declares
|
|
156
156
|
the needed permission level and a named binding for that NaC resource.
|
|
157
157
|
|
|
158
|
-
For a workflow that uses `
|
|
158
|
+
For a workflow that uses `events.scheduled()`, also declare a "triggers"
|
|
159
159
|
database with a page-added trigger bound to it. This lets the user manually
|
|
160
160
|
trigger a run at any time by adding a page to that database, without waiting
|
|
161
161
|
for the schedule.
|
|
@@ -195,11 +195,31 @@ updates code-managed grants and bindings while preserving manually configured
|
|
|
195
195
|
UI grants. Normal draft/publish and runtime authorization still apply. Missing
|
|
196
196
|
or mismatched required bindings fail before the handler runs.
|
|
197
197
|
|
|
198
|
-
Deploy workflows with nonempty `access` using `ntn apps deploy
|
|
199
|
-
`--local-build`. Local-build deployment rejects them before upload. Runtime API
|
|
198
|
+
Deploy workflows with nonempty `access` using `ntn apps deploy`. Runtime API
|
|
200
199
|
calls still belong in durable steps. For syncs, see the
|
|
201
200
|
[data-source example](../sync/SKILL.md#choose-the-database-source).
|
|
202
201
|
|
|
202
|
+
## Configure event schedules and watched data sources
|
|
203
|
+
|
|
204
|
+
Use `events` from `@notionhq/apps` or `@notionhq/apps/events`. Keep the workflow
|
|
205
|
+
configuration key `triggers`.
|
|
206
|
+
|
|
207
|
+
- `events.scheduled({ frequency, interval, start, timeZone, ... })` configures a
|
|
208
|
+
recurrence. Weekly schedules also require a nonempty `weekdays` selection.
|
|
209
|
+
- `events.notionPageCreated({ dataSource: tasks.dataSource })` watches new rows.
|
|
210
|
+
- `events.notionPageUpdated({ dataSource: tasks.dataSource,
|
|
211
|
+
properties: [tasks.dataSource.properties.Status] })` watches property edits.
|
|
212
|
+
Reference the typed property handles, not strings. Use `includePageContent: true`
|
|
213
|
+
for page-content changes, alone or with properties.
|
|
214
|
+
|
|
215
|
+
Deploy configured triggers with `ntn apps deploy`. Deployment updates the workflow
|
|
216
|
+
draft and removes configured triggers omitted on redeploy, while preserving
|
|
217
|
+
triggers added in Notion.
|
|
218
|
+
Open the workflow in Notion and save it to activate or change its schedule and
|
|
219
|
+
page watches. Deployment grants read access to watched databases. Add explicit
|
|
220
|
+
`access` declarations for writes. Zero-argument event helpers remain available
|
|
221
|
+
for UI configuration.
|
|
222
|
+
|
|
203
223
|
## Review a workflow
|
|
204
224
|
|
|
205
225
|
Review every file in `src/workflows/` and the modules it calls. Report each
|
package/src/cli/build.test.ts
CHANGED
|
@@ -489,6 +489,36 @@ describe("buildApp", () => {
|
|
|
489
489
|
}
|
|
490
490
|
});
|
|
491
491
|
|
|
492
|
+
it("builds configured events into JSON-safe trigger declarations", async () => {
|
|
493
|
+
const { manifest } = await buildApp(fixture("configured-events"));
|
|
494
|
+
expect(manifest.capabilities).toEqual([
|
|
495
|
+
{
|
|
496
|
+
type: "workflow",
|
|
497
|
+
key: "tasks",
|
|
498
|
+
config: {
|
|
499
|
+
name: "Tasks",
|
|
500
|
+
description: "Watches task events",
|
|
501
|
+
triggers: [
|
|
502
|
+
{
|
|
503
|
+
type: "recurrence",
|
|
504
|
+
frequency: "day",
|
|
505
|
+
interval: 1,
|
|
506
|
+
start: "2026-09-23T09:00:00",
|
|
507
|
+
timeZone: "UTC",
|
|
508
|
+
},
|
|
509
|
+
{ type: "notion.page.created", dataSourceResourceId: "tasks-source" },
|
|
510
|
+
{
|
|
511
|
+
type: "notion.page.updated",
|
|
512
|
+
dataSourceResourceId: "tasks-source",
|
|
513
|
+
propertyResourceIds: ["status"],
|
|
514
|
+
includePageContent: false,
|
|
515
|
+
},
|
|
516
|
+
],
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
]);
|
|
520
|
+
});
|
|
521
|
+
|
|
492
522
|
it("builds a workflow bundle and manifest", async () => {
|
|
493
523
|
const { manifest, bundlePath, manifestPath } = await buildApp(example("workflow"));
|
|
494
524
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { events } from "./events.generated.js";
|
|
4
|
+
import { database } from "./notion-as-code/database.js";
|
|
5
|
+
import { finishMetadataRecording, startMetadataRecording } from "./notion-as-code/recorder.js";
|
|
6
|
+
import type { DataSourceHandle } from "./notion-as-code/database.js";
|
|
7
|
+
|
|
8
|
+
function tasks() {
|
|
9
|
+
const recorder = startMetadataRecording();
|
|
10
|
+
const handle = database("tasks-db", {
|
|
11
|
+
dataSourceResourceId: "tasks",
|
|
12
|
+
name: "Tasks",
|
|
13
|
+
schema: {
|
|
14
|
+
Name: { resourceId: "name", type: "title" },
|
|
15
|
+
Status: { resourceId: "status", type: "select", options: [] },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
finishMetadataRecording(recorder);
|
|
19
|
+
return handle.dataSource;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("configured Apps events", () => {
|
|
23
|
+
it("serializes property handles without including declaration objects", () => {
|
|
24
|
+
const dataSource = tasks();
|
|
25
|
+
expectTypeOf(dataSource.properties.Status.resourceId).toEqualTypeOf<"status">();
|
|
26
|
+
expectTypeOf(dataSource.properties.Status.propertyType).toEqualTypeOf<"select">();
|
|
27
|
+
expect(
|
|
28
|
+
events.notionPageUpdated({ dataSource, properties: [dataSource.properties.Status] }),
|
|
29
|
+
).toEqual({
|
|
30
|
+
type: "notion.page.updated",
|
|
31
|
+
dataSourceResourceId: "tasks",
|
|
32
|
+
propertyResourceIds: ["status"],
|
|
33
|
+
includePageContent: false,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it("serializes a page-created data source", () => {
|
|
37
|
+
expect(events.notionPageCreated({ dataSource: tasks() })).toEqual({
|
|
38
|
+
type: "notion.page.created",
|
|
39
|
+
dataSourceResourceId: "tasks",
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it("supports page-content-only watches", () => {
|
|
43
|
+
expect(events.notionPageUpdated({ dataSource: tasks(), includePageContent: true })).toEqual(
|
|
44
|
+
{
|
|
45
|
+
type: "notion.page.updated",
|
|
46
|
+
dataSourceResourceId: "tasks",
|
|
47
|
+
includePageContent: true,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
it("checks property ownership even when source types have been widened", () => {
|
|
52
|
+
const original = tasks();
|
|
53
|
+
const dataSource: DataSourceHandle = original;
|
|
54
|
+
const status = original.properties.Status;
|
|
55
|
+
if (!status) throw new Error("Missing Status property");
|
|
56
|
+
const property = { ...status, dataSourceResourceId: "other-source" };
|
|
57
|
+
expect(() => events.notionPageUpdated({ dataSource, properties: [property] })).toThrow(
|
|
58
|
+
"does not belong",
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
it("serializes weekly schedule details", () => {
|
|
62
|
+
expect(
|
|
63
|
+
events.scheduled({
|
|
64
|
+
frequency: "week",
|
|
65
|
+
interval: 1,
|
|
66
|
+
weekdays: { MO: true, FR: true },
|
|
67
|
+
start: "2026-09-23T09:00:00",
|
|
68
|
+
timeZone: "America/Los_Angeles",
|
|
69
|
+
}),
|
|
70
|
+
).toEqual({
|
|
71
|
+
type: "recurrence",
|
|
72
|
+
frequency: "week",
|
|
73
|
+
interval: 1,
|
|
74
|
+
weekdays: { MO: true, FR: true },
|
|
75
|
+
start: "2026-09-23T09:00:00",
|
|
76
|
+
timeZone: "America/Los_Angeles",
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("retains unconfigured events for setup in Notion", () => {
|
|
80
|
+
expect([
|
|
81
|
+
events.scheduled(),
|
|
82
|
+
events.notionPageCreated(),
|
|
83
|
+
events.notionPageUpdated(),
|
|
84
|
+
]).toEqual([
|
|
85
|
+
{ type: "recurrence" },
|
|
86
|
+
{ type: "notion.page.created" },
|
|
87
|
+
{ type: "notion.page.updated" },
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { DataSourceHandle, PropertyHandle } from "./notion-as-code/database.js";
|
|
2
|
+
import type { NotionAsCodeSchema } from "./notion-as-code/intents.js";
|
|
3
|
+
import type { RecurrenceSchedule } from "./notion-as-code/recurrence.js";
|
|
4
|
+
|
|
5
|
+
export type RecurrenceTrigger = { type: "recurrence" } & (
|
|
6
|
+
| RecurrenceSchedule
|
|
7
|
+
| { frequency?: never }
|
|
8
|
+
);
|
|
9
|
+
export type NotionPageCreatedTrigger = {
|
|
10
|
+
type: "notion.page.created";
|
|
11
|
+
dataSourceResourceId?: string;
|
|
12
|
+
};
|
|
13
|
+
export type NotionPageUpdatedTrigger = {
|
|
14
|
+
type: "notion.page.updated";
|
|
15
|
+
dataSourceResourceId?: string;
|
|
16
|
+
propertyResourceIds?: string[];
|
|
17
|
+
includePageContent?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type WatchablePropertyType =
|
|
21
|
+
| "title"
|
|
22
|
+
| "text"
|
|
23
|
+
| "number"
|
|
24
|
+
| "select"
|
|
25
|
+
| "multi_select"
|
|
26
|
+
| "status"
|
|
27
|
+
| "date"
|
|
28
|
+
| "person"
|
|
29
|
+
| "checkbox"
|
|
30
|
+
| "url"
|
|
31
|
+
| "email"
|
|
32
|
+
| "phone_number"
|
|
33
|
+
| "relation";
|
|
34
|
+
|
|
35
|
+
type WatchableProperty<Property extends NotionAsCodeSchema[string]> = Property extends {
|
|
36
|
+
type: WatchablePropertyType;
|
|
37
|
+
}
|
|
38
|
+
? PropertyHandle<Property>
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
type SourceProperty<Schema extends NotionAsCodeSchema> = WatchableProperty<Schema[keyof Schema]>;
|
|
42
|
+
export type PageUpdatedOptions<Schema extends NotionAsCodeSchema> = {
|
|
43
|
+
dataSource: DataSourceHandle<Schema>;
|
|
44
|
+
} & (
|
|
45
|
+
| {
|
|
46
|
+
properties: readonly [
|
|
47
|
+
SourceProperty<NoInfer<Schema>>,
|
|
48
|
+
...SourceProperty<NoInfer<Schema>>[],
|
|
49
|
+
];
|
|
50
|
+
includePageContent?: boolean;
|
|
51
|
+
}
|
|
52
|
+
| { properties?: readonly SourceProperty<NoInfer<Schema>>[]; includePageContent: true }
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** Configure a recurrence, or omit options to set it up in Notion. */
|
|
56
|
+
export function scheduled(options?: RecurrenceSchedule): RecurrenceTrigger {
|
|
57
|
+
return { type: "recurrence", ...options };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Watch new rows in a declared data source, or configure the source in Notion. */
|
|
61
|
+
export function notionPageCreated(options?: {
|
|
62
|
+
dataSource: DataSourceHandle;
|
|
63
|
+
}): NotionPageCreatedTrigger {
|
|
64
|
+
return {
|
|
65
|
+
type: "notion.page.created",
|
|
66
|
+
...(options ? { dataSourceResourceId: options.dataSource.resourceId } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Watch typed properties and/or page content in a declared data source. */
|
|
71
|
+
export function notionPageUpdated<const Schema extends NotionAsCodeSchema>(
|
|
72
|
+
options?: PageUpdatedOptions<Schema>,
|
|
73
|
+
): NotionPageUpdatedTrigger {
|
|
74
|
+
if (!options) return { type: "notion.page.updated" };
|
|
75
|
+
const { dataSource, properties = [], includePageContent = false } = options;
|
|
76
|
+
if (properties.length === 0 && !includePageContent) {
|
|
77
|
+
throw new Error("Page-updated events must watch at least one property or page content");
|
|
78
|
+
}
|
|
79
|
+
for (const property of properties) {
|
|
80
|
+
if (
|
|
81
|
+
property.dataSourceResourceId !== dataSource.resourceId ||
|
|
82
|
+
dataSource.properties[property.name]?.resourceId !== property.resourceId
|
|
83
|
+
) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Property "${property.name}" does not belong to data source "${dataSource.resourceId}"`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: "notion.page.updated",
|
|
91
|
+
dataSourceResourceId: dataSource.resourceId,
|
|
92
|
+
...(properties.length
|
|
93
|
+
? {
|
|
94
|
+
propertyResourceIds: [
|
|
95
|
+
...new Set(properties.map((property) => property.resourceId)),
|
|
96
|
+
],
|
|
97
|
+
}
|
|
98
|
+
: {}),
|
|
99
|
+
includePageContent,
|
|
100
|
+
};
|
|
101
|
+
}
|
package/src/connections.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validateOAuthConfiguration, type OAuthConfiguration } from "./oauth.js";
|
|
2
2
|
import { connectionTriggerDefinitions } from "./connection-trigger-definitions.generated.js";
|
|
3
|
-
import type { WorkflowTrigger } from "./
|
|
3
|
+
import type { WorkflowTrigger } from "./events.generated.js";
|
|
4
4
|
import type { Client } from "@notionhq/client";
|
|
5
5
|
import {
|
|
6
6
|
connections as providerConnections,
|