@notionhq/apps 0.0.30 → 0.0.32
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/dist/cli/codegen.d.ts.map +1 -1
- package/dist/cli/codegen.js +6 -1
- package/dist/custom-block.d.ts +9 -2
- package/dist/custom-block.d.ts.map +1 -1
- package/dist/custom-block.js +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/notion-as-code/custom-agent.d.ts +6 -5
- package/dist/notion-as-code/custom-agent.d.ts.map +1 -1
- package/dist/notion-as-code/custom-agent.js +15 -4
- 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 +61 -2
- package/dist/notion-as-code/index.d.ts +3 -3
- package/dist/notion-as-code/index.d.ts.map +1 -1
- package/dist/notion-as-code/intents.d.ts +7 -1
- package/dist/notion-as-code/intents.d.ts.map +1 -1
- package/dist/notion-as-code/provisioning.d.ts.map +1 -1
- package/dist/notion-as-code/provisioning.js +25 -0
- package/dist/notion-as-code/provisioning.test.d.ts +2 -0
- package/dist/notion-as-code/provisioning.test.d.ts.map +1 -0
- package/dist/notion-as-code/recorder.d.ts +6 -0
- package/dist/notion-as-code/recorder.d.ts.map +1 -1
- package/dist/notion-as-code/recorder.js +22 -1
- package/dist/notion-as-code/views.d.ts +11 -2
- package/dist/notion-as-code/views.d.ts.map +1 -1
- package/dist/workflow-access.d.ts +8 -3
- package/dist/workflow-access.d.ts.map +1 -1
- package/dist/workflow-access.js +33 -34
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/notion-as-code/SKILL.md +39 -8
- package/src/cli/build.test.ts +11 -0
- package/src/cli/codegen.test.ts +26 -1
- package/src/cli/codegen.ts +10 -2
- package/src/custom-block.test.ts +14 -0
- package/src/custom-block.ts +10 -0
- package/src/index.ts +2 -2
- package/src/notion-as-code/custom-agent.test.ts +62 -3
- package/src/notion-as-code/custom-agent.ts +19 -10
- package/src/notion-as-code/database.test.ts +105 -1
- package/src/notion-as-code/database.ts +77 -1
- package/src/notion-as-code/index.ts +2 -1
- package/src/notion-as-code/intents.ts +4 -1
- package/src/notion-as-code/notion-as-code-types.test.ts +21 -11
- package/src/notion-as-code/provisioning.test.ts +69 -0
- package/src/notion-as-code/provisioning.ts +27 -0
- package/src/notion-as-code/recorder.ts +27 -0
- package/src/notion-as-code/views-types.test.ts +24 -0
- package/src/notion-as-code/views.ts +24 -2
- package/src/workflow-access.ts +56 -51
- package/src/workflow.ts +1 -1
package/src/workflow-access.ts
CHANGED
|
@@ -20,17 +20,17 @@ type WorkflowAccessContentResource = Exclude<WorkflowAccessResource, CustomAgent
|
|
|
20
20
|
export type WorkflowAccessResourceType = WorkflowAccessResource["resourceType"];
|
|
21
21
|
|
|
22
22
|
/** Levels accepted by pages, databases, and data sources. */
|
|
23
|
-
export type
|
|
23
|
+
export type ResourceAccessLevel = "view" | "comment" | "edit" | "fullAccess";
|
|
24
24
|
|
|
25
25
|
/** The only level accepted by a custom agent. */
|
|
26
26
|
export type WorkflowAccessAgentLevel = "call";
|
|
27
27
|
|
|
28
28
|
/** Every level accepted by at least one workflow access resource. */
|
|
29
|
-
export type WorkflowAccessLevel =
|
|
29
|
+
export type WorkflowAccessLevel = ResourceAccessLevel | WorkflowAccessAgentLevel;
|
|
30
30
|
|
|
31
31
|
/** The level set accepted by a particular resource kind. */
|
|
32
32
|
export type WorkflowAccessLevelFor<TType extends WorkflowAccessResourceType> =
|
|
33
|
-
TType extends "customAgent" ? WorkflowAccessAgentLevel :
|
|
33
|
+
TType extends "customAgent" ? WorkflowAccessAgentLevel : ResourceAccessLevel;
|
|
34
34
|
|
|
35
35
|
type AccessResourceFor<TType extends WorkflowAccessResourceType> = Extract<
|
|
36
36
|
WorkflowAccessResource,
|
|
@@ -159,57 +159,62 @@ export function normalizeWorkflowAccess(
|
|
|
159
159
|
if (!ACCESS_ALIAS_PATTERN.test(alias) || RESERVED_ACCESS_ALIASES.has(alias)) {
|
|
160
160
|
throw new Error(`Invalid workflow access alias: ${alias}`);
|
|
161
161
|
}
|
|
162
|
+
normalized[alias] = normalizeAccessDeclaration(source[alias], `Workflow access "${alias}"`);
|
|
163
|
+
}
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
return Object.freeze(normalized);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check one access entry and return its resource type, ID, and level.
|
|
170
|
+
* Workflows check the entry's alias separately; custom-agent grants have no alias.
|
|
171
|
+
*/
|
|
172
|
+
export function normalizeAccessDeclaration(
|
|
173
|
+
declaration: unknown,
|
|
174
|
+
label: string,
|
|
175
|
+
): WorkflowAccessRequirement {
|
|
176
|
+
if (
|
|
177
|
+
!isRecord(declaration) ||
|
|
178
|
+
!Object.hasOwn(declaration, "resource") ||
|
|
179
|
+
!Object.hasOwn(declaration, "level")
|
|
180
|
+
) {
|
|
181
|
+
throw new Error(`${label} must declare a resource and level.`);
|
|
182
|
+
}
|
|
183
|
+
const resource: unknown = declaration.resource;
|
|
184
|
+
if (
|
|
185
|
+
!isRecord(resource) ||
|
|
186
|
+
!Object.hasOwn(resource, "resourceType") ||
|
|
187
|
+
!Object.hasOwn(resource, "resourceId") ||
|
|
188
|
+
typeof resource.resourceId !== "string" ||
|
|
189
|
+
resource.resourceId.length === 0 ||
|
|
190
|
+
!isWorkflowAccessResourceType(resource.resourceType)
|
|
191
|
+
) {
|
|
192
|
+
throw new Error(`${label} must reference a supported NaC resource handle.`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let requirement: WorkflowAccessRequirement;
|
|
196
|
+
if (resource.resourceType === "customAgent") {
|
|
197
|
+
if (declaration.level !== "call") {
|
|
198
|
+
throw new Error(`${label} custom agents only support level "call".`);
|
|
170
199
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
!isWorkflowAccessResourceType(resource.resourceType)
|
|
179
|
-
) {
|
|
200
|
+
requirement = {
|
|
201
|
+
type: resource.resourceType,
|
|
202
|
+
resourceId: resource.resourceId,
|
|
203
|
+
level: declaration.level,
|
|
204
|
+
};
|
|
205
|
+
} else {
|
|
206
|
+
if (!isResourceAccessLevel(declaration.level)) {
|
|
180
207
|
throw new Error(
|
|
181
|
-
|
|
208
|
+
`${label} ${resource.resourceType} level must be view, comment, edit, or fullAccess.`,
|
|
182
209
|
);
|
|
183
210
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
`Workflow access "${alias}" custom agents only support level "call".`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
requirement = {
|
|
193
|
-
type: resource.resourceType,
|
|
194
|
-
resourceId: resource.resourceId,
|
|
195
|
-
level: declaration.level,
|
|
196
|
-
};
|
|
197
|
-
} else {
|
|
198
|
-
if (!isWorkflowAccessResourceLevel(declaration.level)) {
|
|
199
|
-
throw new Error(
|
|
200
|
-
`Workflow access "${alias}" ${resource.resourceType} level must be view, comment, edit, or fullAccess.`,
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
requirement = {
|
|
204
|
-
type: resource.resourceType,
|
|
205
|
-
resourceId: resource.resourceId,
|
|
206
|
-
level: declaration.level,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
normalized[alias] = Object.freeze(requirement);
|
|
211
|
+
requirement = {
|
|
212
|
+
type: resource.resourceType,
|
|
213
|
+
resourceId: resource.resourceId,
|
|
214
|
+
level: declaration.level,
|
|
215
|
+
};
|
|
210
216
|
}
|
|
211
|
-
|
|
212
|
-
return Object.freeze(normalized);
|
|
217
|
+
return Object.freeze(requirement);
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
/**
|
|
@@ -294,14 +299,14 @@ function isWorkflowAccessResourceType(value: unknown): value is WorkflowAccessRe
|
|
|
294
299
|
return typeof value === "string" && Object.hasOwn(RESOURCE_TYPES, value);
|
|
295
300
|
}
|
|
296
301
|
|
|
297
|
-
function
|
|
302
|
+
function isResourceAccessLevel(value: unknown): value is ResourceAccessLevel {
|
|
298
303
|
return value === "view" || value === "comment" || value === "edit" || value === "fullAccess";
|
|
299
304
|
}
|
|
300
305
|
|
|
301
306
|
function isBinding(value: unknown): value is {
|
|
302
307
|
type: WorkflowAccessResourceType;
|
|
303
308
|
resourceId: string;
|
|
304
|
-
level:
|
|
309
|
+
level: ResourceAccessLevel | WorkflowAccessAgentLevel;
|
|
305
310
|
id: string;
|
|
306
311
|
} {
|
|
307
312
|
if (!isRecord(value) || Reflect.ownKeys(value).length !== 4) return false;
|
|
@@ -320,7 +325,7 @@ function isBinding(value: unknown): value is {
|
|
|
320
325
|
typeof value.resourceId === "string" &&
|
|
321
326
|
value.resourceId.length > 0 &&
|
|
322
327
|
typeof value.level === "string" &&
|
|
323
|
-
(
|
|
328
|
+
(isResourceAccessLevel(value.level) || value.level === "call") &&
|
|
324
329
|
typeof value.id === "string" &&
|
|
325
330
|
value.id.length > 0
|
|
326
331
|
);
|
package/src/workflow.ts
CHANGED