@notionhq/apps 0.0.16 → 0.0.18
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 +27 -0
- package/README.md +86 -36
- package/dist/connections.d.ts +39 -11
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +85 -21
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/notion-as-code/database.d.ts +89 -48
- package/dist/notion-as-code/database.d.ts.map +1 -1
- package/dist/notion-as-code/database.js +132 -45
- package/dist/notion-as-code/database.test.d.ts +2 -0
- package/dist/notion-as-code/database.test.d.ts.map +1 -0
- package/dist/notion-as-code/handles.d.ts +2 -0
- package/dist/notion-as-code/handles.d.ts.map +1 -1
- package/dist/notion-as-code/handles.js +2 -0
- package/dist/notion-as-code/index.d.ts +5 -2
- package/dist/notion-as-code/index.d.ts.map +1 -1
- package/dist/notion-as-code/intents.d.ts +36 -3
- package/dist/notion-as-code/intents.d.ts.map +1 -1
- package/dist/notion-as-code/schema.d.ts +8 -4
- package/dist/notion-as-code/schema.d.ts.map +1 -1
- package/dist/notion-as-code/view.d.ts +12 -0
- package/dist/notion-as-code/view.d.ts.map +1 -0
- package/dist/notion-as-code/view.js +13 -0
- package/dist/notion-as-code/views-types.test.d.ts +2 -0
- package/dist/notion-as-code/views-types.test.d.ts.map +1 -0
- package/dist/notion-as-code/views.d.ts +488 -0
- package/dist/notion-as-code/views.d.ts.map +1 -0
- package/dist/notion-as-code/views.js +0 -0
- package/dist/oauth.d.ts +11 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +26 -0
- package/dist/providers.generated.d.ts +26 -86
- package/dist/providers.generated.d.ts.map +1 -1
- package/dist/providers.generated.js +54 -66
- package/dist/sync.d.ts +33 -15
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +12 -0
- package/dist/triggers.generated.d.ts +3 -3
- package/dist/triggers.generated.d.ts.map +1 -1
- package/dist/workflow-state.d.ts +13 -0
- package/dist/workflow-state.d.ts.map +1 -0
- package/dist/workflow-state.js +107 -0
- package/dist/workflow.d.ts +56 -11
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +123 -10
- package/docs/BUILD.md +96 -0
- package/docs/CONNECTIONS.md +70 -22
- package/package.json +1 -1
- package/skills/connections/SKILL.md +7 -8
- package/skills/notion-as-code/SKILL.md +88 -50
- package/skills/sync/SKILL.md +21 -18
- package/skills/workflow/SKILL.md +52 -3
- package/src/cli/build.test.ts +124 -64
- package/src/connections.test.ts +205 -41
- package/src/connections.ts +144 -38
- package/src/index.ts +2 -0
- package/src/notion-as-code/database.test.ts +661 -0
- package/src/notion-as-code/database.ts +346 -129
- package/src/notion-as-code/handles.ts +2 -0
- package/src/notion-as-code/index.ts +71 -1
- package/src/notion-as-code/intents.ts +41 -4
- package/src/notion-as-code/schema.ts +11 -3
- package/src/notion-as-code/view.ts +23 -0
- package/src/notion-as-code/views-types.test.ts +59 -0
- package/src/notion-as-code/views.ts +573 -0
- package/src/oauth.ts +40 -0
- package/src/providers.generated.ts +68 -163
- package/src/sync.test.ts +295 -0
- package/src/sync.ts +85 -21
- package/src/triggers.generated.ts +4 -4
- package/src/workflow-connections-types.test.ts +16 -10
- package/src/workflow-state.ts +152 -0
- package/src/workflow-types.test.ts +88 -16
- package/src/workflow.test.ts +374 -18
- package/src/workflow.ts +211 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CustomAgentArgs } from "./custom-agent.js";
|
|
2
|
-
import type { DatabaseArgs } from "./database.js";
|
|
3
2
|
import type { PageArgs } from "./page.js";
|
|
4
3
|
import type { TeamspaceArgs } from "./teamspace.js";
|
|
4
|
+
import type { ViewSchema } from "./views.js";
|
|
5
5
|
|
|
6
6
|
/** Apps-specific resource IDs used while declaring Notion-as-Code metadata. */
|
|
7
7
|
/** Synthetic workspace parent for teamspaces declared by an Apps project. */
|
|
@@ -65,6 +65,7 @@ type UnsupportedProperty = PropertyBase & {
|
|
|
65
65
|
[key: string]: unknown;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
/** A normalized Notion-as-Code property with its resolved display name. */
|
|
68
69
|
export type NotionAsCodeProperty =
|
|
69
70
|
| (PropertyBase & { type: "title" })
|
|
70
71
|
| (PropertyBase & { type: "text" })
|
|
@@ -91,6 +92,28 @@ export type NotionAsCodeProperty =
|
|
|
91
92
|
| (PropertyBase & { type: "file" })
|
|
92
93
|
| UnsupportedProperty;
|
|
93
94
|
|
|
95
|
+
/**
|
|
96
|
+
* `T extends unknown` applies Omit to each property variant separately, preserving
|
|
97
|
+
* variant-specific fields such as required status options. Plain Omit on the union
|
|
98
|
+
* would retain only shared keys. Pick also restores type/resourceId on the
|
|
99
|
+
* unsupported variant, whose string index signature would otherwise erase them.
|
|
100
|
+
*/
|
|
101
|
+
type DistributivePropertyConfig<T extends NotionAsCodeProperty> = T extends unknown
|
|
102
|
+
? Omit<T, "name"> & Pick<T, "type" | "resourceId">
|
|
103
|
+
: never;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Authoring properties are keyed by their schema object name. A property-level
|
|
107
|
+
* `name` override would make the key and serialized property diverge, so it is
|
|
108
|
+
* explicitly rejected even for the string-indexed unsupported-property variant.
|
|
109
|
+
*/
|
|
110
|
+
export type NotionAsCodePropertyConfig = DistributivePropertyConfig<NotionAsCodeProperty> & {
|
|
111
|
+
name?: never;
|
|
112
|
+
};
|
|
113
|
+
/** A keyed property schema, with object keys supplying serialized property names. */
|
|
114
|
+
export type NotionAsCodeSchema = Record<string, NotionAsCodePropertyConfig>;
|
|
115
|
+
|
|
116
|
+
/** The normalized data-source shape emitted in provisioning artifacts. */
|
|
94
117
|
export type DataSourceDefinition<
|
|
95
118
|
Properties extends readonly NotionAsCodeProperty[] = readonly NotionAsCodeProperty[],
|
|
96
119
|
> = {
|
|
@@ -106,9 +129,24 @@ export type TeamspaceIntent = TeamspaceArgs & {
|
|
|
106
129
|
parent: Parent;
|
|
107
130
|
};
|
|
108
131
|
|
|
109
|
-
|
|
132
|
+
/**
|
|
133
|
+
* The normalized database shape emitted in provisioning artifacts.
|
|
134
|
+
*
|
|
135
|
+
* This intentionally does not depend on the authoring argument shape. Authoring
|
|
136
|
+
* accepts keyed schemas and data-source maps; the recorder always stores arrays.
|
|
137
|
+
*/
|
|
138
|
+
export type DatabaseIntent = {
|
|
139
|
+
resourceId: ResourceId;
|
|
110
140
|
parent: Parent;
|
|
111
141
|
dataSources: readonly DataSourceDefinition[];
|
|
142
|
+
views?: readonly ViewSchema[];
|
|
143
|
+
icon?: NotionAsCodeIcon;
|
|
144
|
+
// TODO: Port cover types.
|
|
145
|
+
cover?: unknown;
|
|
146
|
+
hideDataSourceTitle?: boolean;
|
|
147
|
+
hideDatabaseTitleIfEmpty?: boolean;
|
|
148
|
+
name?: string;
|
|
149
|
+
description?: string;
|
|
112
150
|
};
|
|
113
151
|
|
|
114
152
|
export type PageIntent = PageArgs & { parent: Parent };
|
|
@@ -116,8 +154,7 @@ export type CustomAgentIntent = CustomAgentArgs;
|
|
|
116
154
|
|
|
117
155
|
export type ViewIntent = {
|
|
118
156
|
databaseResourceId: ResourceId;
|
|
119
|
-
|
|
120
|
-
view: unknown;
|
|
157
|
+
view: ViewSchema;
|
|
121
158
|
};
|
|
122
159
|
|
|
123
160
|
export type InfraAsCodeIntent =
|
|
@@ -5,11 +5,15 @@ import type { SelectOption, StatusGroup } from "../types.js";
|
|
|
5
5
|
import type {
|
|
6
6
|
DataSourceDefinition,
|
|
7
7
|
NotionAsCodeProperty,
|
|
8
|
+
NotionAsCodePropertyConfig,
|
|
9
|
+
NotionAsCodeSchema,
|
|
8
10
|
NotionAsCodeSelectOption,
|
|
9
11
|
NotionAsCodeStatusOption,
|
|
10
12
|
} from "./intents.js";
|
|
11
13
|
|
|
12
|
-
type AppsPropertyFor<Property extends
|
|
14
|
+
type AppsPropertyFor<Property extends NotionAsCodePropertyConfig> = Property extends {
|
|
15
|
+
type: "title";
|
|
16
|
+
}
|
|
13
17
|
? { type: "title" }
|
|
14
18
|
: Property extends { type: "text" }
|
|
15
19
|
? { type: "text" }
|
|
@@ -35,8 +39,12 @@ type AppsPropertyFor<Property extends NotionAsCodeProperty> = Property extends {
|
|
|
35
39
|
? { type: "file" }
|
|
36
40
|
: PropertyConfiguration;
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Map keyed authoring properties to the Apps schema used by sync handlers. The explicit
|
|
44
|
+
* string-key mapping avoids a homomorphic mapped type interfering with `NoInfer` key checks.
|
|
45
|
+
*/
|
|
46
|
+
export type AppsSchemaForSchema<Schema extends NotionAsCodeSchema> = {
|
|
47
|
+
[Property in keyof Schema & string]: AppsPropertyFor<Schema[Property]>;
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
/** Convert a Notion-as-Code data source into the Apps database used by sync handlers. */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ResourceId } from "./intents.js";
|
|
2
|
+
import { recordIntent } from "./recorder.js";
|
|
3
|
+
import { assertUserResourceId } from "./resource.js";
|
|
4
|
+
import type { ViewSchema } from "./views.js";
|
|
5
|
+
|
|
6
|
+
/** Declare a view attached to a database resource. */
|
|
7
|
+
export type ViewArgs = ViewSchema & {
|
|
8
|
+
databaseResourceId: ResourceId;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ViewHandle = {
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Record a database view for provisioning without making a Notion API request. */
|
|
16
|
+
export function view(args: ViewArgs): ViewHandle {
|
|
17
|
+
assertUserResourceId(args.resourceId);
|
|
18
|
+
assertUserResourceId(args.databaseResourceId);
|
|
19
|
+
assertUserResourceId(args.dataSourceResourceId);
|
|
20
|
+
const { databaseResourceId, ...schema } = args;
|
|
21
|
+
recordIntent({ type: "view", databaseResourceId, view: schema });
|
|
22
|
+
return { resourceId: args.resourceId };
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { expectTypeOf, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DatabaseArgs,
|
|
5
|
+
DatabaseHandle,
|
|
6
|
+
DatePropertyFilter,
|
|
7
|
+
GroupByFormat,
|
|
8
|
+
ViewSchema,
|
|
9
|
+
} from "./index.js";
|
|
10
|
+
|
|
11
|
+
it("requires date properties for calendar and timeline views at both entrypoints", () => {
|
|
12
|
+
type MissingDateProperty = {
|
|
13
|
+
resourceId: "view";
|
|
14
|
+
dataSourceResourceId: "source";
|
|
15
|
+
type: "calendar" | "timeline";
|
|
16
|
+
};
|
|
17
|
+
expectTypeOf<MissingDateProperty>().not.toExtend<ViewSchema>();
|
|
18
|
+
expectTypeOf<MissingDateProperty>().not.toExtend<NonNullable<DatabaseArgs["views"]>[number]>();
|
|
19
|
+
expectTypeOf<MissingDateProperty>().not.toExtend<Parameters<DatabaseHandle["addView"]>[0]>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("couples date operators to their value shapes and requires a range bound", () => {
|
|
23
|
+
type DateFilter = {
|
|
24
|
+
type: "property";
|
|
25
|
+
propertyId: "due";
|
|
26
|
+
propertyType: "date";
|
|
27
|
+
};
|
|
28
|
+
expectTypeOf<
|
|
29
|
+
DateFilter & {
|
|
30
|
+
operator: "date_is_within";
|
|
31
|
+
value: { type: "exact_range"; value: { startDate: "2026-01-01" } };
|
|
32
|
+
}
|
|
33
|
+
>().toExtend<DatePropertyFilter>();
|
|
34
|
+
expectTypeOf<
|
|
35
|
+
DateFilter & {
|
|
36
|
+
operator: "date_is_within";
|
|
37
|
+
value: { type: "exact_range"; value: {} };
|
|
38
|
+
}
|
|
39
|
+
>().not.toExtend<DatePropertyFilter>();
|
|
40
|
+
expectTypeOf<
|
|
41
|
+
DateFilter & {
|
|
42
|
+
operator: "date_is_relative_to";
|
|
43
|
+
value: { type: "exact"; value: "2026-01-01" };
|
|
44
|
+
}
|
|
45
|
+
>().not.toExtend<DatePropertyFilter>();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("limits status grouping options to status properties", () => {
|
|
49
|
+
expectTypeOf<{
|
|
50
|
+
type: "status";
|
|
51
|
+
property: "status";
|
|
52
|
+
statusBy: "group";
|
|
53
|
+
}>().toExtend<GroupByFormat>();
|
|
54
|
+
expectTypeOf<{
|
|
55
|
+
type: "select";
|
|
56
|
+
property: "status";
|
|
57
|
+
statusBy: "group";
|
|
58
|
+
}>().not.toExtend<GroupByFormat>();
|
|
59
|
+
});
|