- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
18869 feature upgrade notion create page in data source action to support templates #18888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
18869 feature upgrade notion create page in data source action to support templates #18888
Conversation
- Added `listTemplates` method to the Notion client for retrieving available templates. - Updated `create-page-from-database` action to support template selection, including new properties for template type and ID. - Bumped version to 2.0.0 for the `create-page-from-database` action and updated package version to 1.0.6. - Upgraded `@notionhq/client` dependency to version 5.3.0.
| The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
 | 
| WalkthroughThe PR adds template support to the "Create Page from Data Source" action, enabling users to select and apply Notion page templates when creating pages. A new  Changes
 Sequence Diagram(s)sequenceDiagram
    actor User
    participant Action as Create Page<br/>Action
    participant App as Notion<br/>App
    participant API as Notion<br/>API
    rect rgb(220, 240, 255)
    note over User,API: Template Selection Flow
    User->>Action: Select templateType<br/>(none/default/template_id)
    alt templateType = template_id
        Action->>App: listTemplates()
        App->>API: Fetch available templates
        API-->>App: Return templates list
        App-->>Action: Template options
        User->>Action: Select specific template
    end
    end
    rect rgb(240, 255, 220)
    note over User,API: Page Creation with Batching
    User->>Action: Create page with properties<br/>& child blocks
    Action->>Action: buildPage() → {metadata,<br/>properties, children}
    alt Total blocks ≤ 100
        Action->>API: Single request with<br/>all blocks
    else Total blocks > 100
        Action->>API: Request 1: 100 blocks
        Action->>API: Request 2+: Remaining<br/>blocks (batched)
    end
    API-->>Action: Page created
    Action-->>User: Success response
    end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 
 Areas requiring attention: 
 Possibly related PRs
 Suggested labels
 Suggested reviewers
 Poem
 Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
 ✅ Passed checks (1 passed)
 ✨ Finishing touches
 🧪 Generate unit tests (beta)
 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
 🧰 Additional context used🧠 Learnings (2)📚 Learning: 2025-01-23T03:55:51.998ZApplied to files: 
 📚 Learning: 2025-09-15T22:01:17.593ZApplied to files: 
 🧬 Code graph analysis (1)components/notion/actions/create-page-from-database/create-page-from-database.mjs (4)
 🪛 Biome (2.1.2)components/notion/actions/create-page-from-database/create-page-from-database.mjs[error] 91-91: Other switch clauses can erroneously access this declaration. The declaration is defined in this switch clause: Safe fix: Wrap the declaration in a block. (lint/correctness/noSwitchDeclarations) [error] 92-92: Other switch clauses can erroneously access this declaration. The declaration is defined in this switch clause: Safe fix: Wrap the declaration in a block. (lint/correctness/noSwitchDeclarations) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
 🔇 Additional comments (2)
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️  Outside diff range comments (1)
components/notion/actions/create-page-from-database/create-page-from-database.mjs (1)
59-59: Fix typo.“Willl” → “Will”.
- description: "Select one or more page properties. Willl override properties set in the `Properties` prop below.", + description: "Select one or more page properties. Will override properties set in the `Properties` prop below.",
🧹 Nitpick comments (3)
components/notion/actions/create-page-from-database/create-page-from-database.mjs (3)
30-49: Set a default for templateType and tighten descriptions.
- Defaulting to "none" avoids undefined paths in additionalProps().
- Minor copy nits for clarity.
templateType: { type: "string", label: "Template Type", description: "The type of template to use for the page. [See the documentation](https://developers.notion.com/docs/creating-pages-from-templates) for more information.", + default: "none", options: [ { label: "No template. Provided children and properties are immediately applied.", value: "none", }, { - label: "Applies the data source's default template to the newly created page. `children` cannot be specified in the create page request.", + label: "Apply the data source's default template. `children` cannot be specified in the create request.", value: "default", }, { - label: "Indicates which exact template to apply to the newly created page. children cannot be specified in the create page request.", + label: "Apply a specific template by ID. `children` cannot be specified in the create request.", value: "template_id", }, ], reloadProps: true, },
165-186: Preflight check for default template presence.Per PR objective, check if a default template exists right before create (defaults can be removed at any time). If missing, fail fast with a clear message.
@@ - const response = await this.notion.createPage({ + if (this.templateType === "default") { + const res = await this.notion.listTemplates({ data_source_id: this.parentDataSource }); + const templates = res.templates ?? res.results ?? []; + const hasDefault = templates.some(t => t.is_default === true || t.default === true); + if (!hasDefault) { + throw new Error("No default template configured for the selected data source."); + } + } + const response = await this.notion.createPage({If the default-indicator property isn’t
is_default, adjust accordingly to the official schema.
81-86: UX: Hide or gate Page Content when using templates.You already show an alert that Page Content doesn’t apply for template flows. Consider conditionally surfacing Page Content only for templateType = "none" to avoid confusion.
- Move Page Content into additionalProps for the "none" branch, or
- Add a runtime guard that ignores non-empty pageContent with a warning when templateType ≠ "none".
Also applies to: 104-111, 137-142
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
- pnpm-lock.yamlis excluded by- !**/pnpm-lock.yaml
📒 Files selected for processing (3)
- components/notion/actions/create-page-from-database/create-page-from-database.mjs(4 hunks)
- components/notion/notion.app.mjs(1 hunks)
- components/notion/package.json(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/notion/actions/create-page-from-database/create-page-from-database.mjs (4)
components/notion/actions/update-page/update-page.mjs (4)
selectedProperties(69-69)
properties(94-94)
meta(93-93)
page(132-132)components/notion/actions/append-block/append-block.mjs (2)
children(86-86)
response(126-130)components/notion/actions/common/base-page-builder.mjs (3)
children(270-270)
page(352-352)
response(353-356)components/notion/actions/create-page/create-page.mjs (1)
response(52-64)
🪛 Biome (2.1.2)
components/notion/actions/create-page-from-database/create-page-from-database.mjs
[error] 91-91: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Safe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 92-92: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Safe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Verify TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (3)
components/notion/actions/create-page-from-database/create-page-from-database.mjs (1)
165-191: Disregard this review comment —verifyTemplateReadydoes not exist in notion-helper.The suggested import will fail at runtime. Existing notion-helper exports are
createPage,createNotionBuilder, andappendBlocks. The web search confirms that official Notion guidance for waiting until templates apply uses webhooks (page.content_updatedevent) or polling the Retrieve block children API—not a helper function. While the intent (delay block appending until template finishes) aligns with the PR objective, the proposed implementation does not exist in notion-helper and contradicts the library's actual API and Notion's official guidance.Likely an incorrect or invalid review comment.
components/notion/package.json (1)
3-3: Version bump and @notionhq/client update are compatible with template features.@notionhq/client v5.3.0 includes dataSources.listTemplates support, and API version 2025-09-03 enables creating pages using the template parameter (with type = "default" or "template_id"). The changes are safe to merge.
components/notion/notion.app.mjs (1)
278-280: No changes needed; original implementation is correct.The Notion API explicitly returns a top-level
templatesarray in the response, eliminating the ambiguity the review suggested. The current simple delegation tothis._getNotionClient().dataSources.listTemplates(params)correctly handles this. Adding defensive fallbacks forresultsor empty defaults is unnecessary when the API contract is clear and consistent.
        
          
                components/notion/actions/create-page-from-database/create-page-from-database.mjs
          
            Show resolved
            Hide resolved
        
              
          
                components/notion/actions/create-page-from-database/create-page-from-database.mjs
          
            Show resolved
            Hide resolved
        
              
          
                components/notion/actions/create-page-from-database/create-page-from-database.mjs
          
            Show resolved
            Hide resolved
        
      - Bumped versions for multiple actions and sources, including `append-block`, `complete-file-upload`, `create-comment`, `create-database`, `create-file-upload`, `create-page`, `delete-block`, `duplicate-page`, `get-current-user`, `list-all-users`, `list-file-uploads`, `query-database`, `retrieve-block`, `retrieve-database-content`, `retrieve-database-schema`, `retrieve-file-upload`, `retrieve-page`, `retrieve-page-property-item`, `retrieve-user`, `search`, `send-file-upload`, `update-block`, `update-database`, `update-page`, and various sources. - Ensured all components are aligned with the latest API specifications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
components/notion/sources/page-properties-updated-instant/page-properties-updated-instant.mjs (2)
63-76: Possible mismatch: filtering by property IDs but webhook may send property names
props.propertiesstores IDs (value: prop[1].id), butevent.data.updated_propertiesmay be names. If so, the filter won’t match and events won’t emit as expected. Please confirm payload shape; if names are sent, normalize by mapping names→IDs before comparing. Example:- let propertyHasChanged = false; - for (const propertyName of updatedProperties) { - if (!this.properties || this.properties.includes(propertyName)) { - propertyHasChanged = true; - } - } + let propertyHasChanged = false; + if (!this.properties?.length) { + propertyHasChanged = true; + } else { + const selected = new Set(this.properties); + // First try direct ID match + for (const p of updatedProperties) { + if (selected.has(p)) { propertyHasChanged = true; break; } + } + // Fallback: map names -> IDs if still no match + if (!propertyHasChanged) { + try { + const { properties } = await this.notion.retrieveDataSource(this.dataSourceId); + const nameToId = new Map(Object.values(properties).map((pr) => [pr.name, pr.id])); + for (const p of updatedProperties) { + const id = nameToId.get(p); + if (id && selected.has(id)) { propertyHasChanged = true; break; } + } + } catch (e) { + console.log("Failed to map Notion property names to IDs", e); + } + } + }
79-86: Harden page fetch with try/catchNetwork/API hiccups from Notion can throw and drop the event. Wrap
retrievePageand$emitin try/catch with a concise log; keep behavior unchanged.- const page = await this.notion.retrievePage(event.entity.id); - - const meta = this._generateMeta(page); - this.$emit({ - ...event, - page, - }, meta); + try { + const page = await this.notion.retrievePage(event.entity.id); + const meta = this._generateMeta(page); + this.$emit({ ...event, page }, meta); + } catch (err) { + console.log("Failed to retrieve Notion page", err); + }components/notion/actions/delete-block/delete-block.mjs (2)
31-31: Wording nit: align summary with Notion’s “archive” semantics.The API sets archived: true (moves to Trash). Consider reflecting that to avoid confusion.
- $.export("$summary", `Successfully deleted block with ID ${this.blockId}`); + $.export("$summary", `Archived block (moved to Trash) with ID ${this.blockId}`);
9-9: LGTM: patch version bump is appropriate and verified.Verification confirms deleteBlock exists in notion.app (line 316) and is correctly invoked in delete-block.mjs (line 30). Version 0.0.8 is correct for this metadata-only update.
Optional improvements to consider:
- Extract blockId prop to a shared propDefinition in notion.app for consistency with other actions (e.g., append-block.mjs), though this would require creating the shared definition first.
- Align summary text with API terminology: change "deleted" to "archived" for clarity, though the existing infoLabel already clarifies the block moves to Trash.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (33)
- components/notion/actions/append-block/append-block.mjs(1 hunks)
- components/notion/actions/complete-file-upload/complete-file-upload.mjs(1 hunks)
- components/notion/actions/create-comment/create-comment.mjs(1 hunks)
- components/notion/actions/create-database/create-database.mjs(1 hunks)
- components/notion/actions/create-file-upload/create-file-upload.mjs(1 hunks)
- components/notion/actions/create-page/create-page.mjs(1 hunks)
- components/notion/actions/delete-block/delete-block.mjs(1 hunks)
- components/notion/actions/duplicate-page/duplicate-page.mjs(1 hunks)
- components/notion/actions/get-current-user/get-current-user.mjs(1 hunks)
- components/notion/actions/list-all-users/list-all-users.mjs(1 hunks)
- components/notion/actions/list-file-uploads/list-file-uploads.mjs(1 hunks)
- components/notion/actions/query-database/query-database.mjs(1 hunks)
- components/notion/actions/retrieve-block/retrieve-block.mjs(1 hunks)
- components/notion/actions/retrieve-database-content/retrieve-database-content.mjs(1 hunks)
- components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs(1 hunks)
- components/notion/actions/retrieve-file-upload/retrieve-file-upload.mjs(1 hunks)
- components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs(1 hunks)
- components/notion/actions/retrieve-page/retrieve-page.mjs(1 hunks)
- components/notion/actions/retrieve-user/retrieve-user.mjs(1 hunks)
- components/notion/actions/search/search.mjs(1 hunks)
- components/notion/actions/send-file-upload/send-file-upload.mjs(1 hunks)
- components/notion/actions/update-block/update-block.mjs(1 hunks)
- components/notion/actions/update-database/update-database.mjs(1 hunks)
- components/notion/actions/update-page/update-page.mjs(1 hunks)
- components/notion/sources/new-comment-created/new-comment-created.mjs(1 hunks)
- components/notion/sources/new-database/new-database.mjs(1 hunks)
- components/notion/sources/new-page/new-page.mjs(1 hunks)
- components/notion/sources/new-webhook-event-instant/new-webhook-event-instant.mjs(1 hunks)
- components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs(1 hunks)
- components/notion/sources/page-properties-updated-instant/page-properties-updated-instant.mjs(1 hunks)
- components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs(1 hunks)
- components/notion/sources/updated-page-id/updated-page-id.mjs(1 hunks)
- components/notion/sources/updated-page/updated-page.mjs(1 hunks)
✅ Files skipped from review due to trivial changes (19)
- components/notion/sources/new-database/new-database.mjs
- components/notion/actions/create-comment/create-comment.mjs
- components/notion/actions/retrieve-block/retrieve-block.mjs
- components/notion/actions/update-page/update-page.mjs
- components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs
- components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs
- components/notion/actions/create-file-upload/create-file-upload.mjs
- components/notion/actions/query-database/query-database.mjs
- components/notion/sources/new-comment-created/new-comment-created.mjs
- components/notion/actions/append-block/append-block.mjs
- components/notion/actions/update-database/update-database.mjs
- components/notion/actions/list-file-uploads/list-file-uploads.mjs
- components/notion/actions/create-page/create-page.mjs
- components/notion/actions/list-all-users/list-all-users.mjs
- components/notion/actions/retrieve-page/retrieve-page.mjs
- components/notion/sources/new-page/new-page.mjs
- components/notion/actions/complete-file-upload/complete-file-upload.mjs
- components/notion/sources/updated-page/updated-page.mjs
- components/notion/actions/search/search.mjs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Publish TypeScript components
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Lint Code Base
🔇 Additional comments (14)
components/notion/actions/retrieve-user/retrieve-user.mjs (1)
7-7: LGTM! Coordinated version bump.The patch version increment is appropriate for this coordinated release across the Notion integration.
components/notion/actions/update-block/update-block.mjs (1)
10-10: LGTM! Version bump aligns with package updates.The patch version bump from 0.0.7 to 0.0.8 is appropriate given the package-level updates (Notion package 1.0.5→1.0.6 and @notionhq/client ^5.0.0→^5.3.0) in this PR. Since no code changes were made to this action, a patch bump maintains version consistency across the Notion component suite.
components/notion/actions/get-current-user/get-current-user.mjs (1)
7-7: LGTM: Version bump with no functional changes.The patch version increment from 0.0.1 to 0.0.2 aligns with the coordinated release pattern across Notion components in this PR. No code changes means no risk of regressions.
components/notion/sources/new-webhook-event-instant/new-webhook-event-instant.mjs (1)
9-9: LGTM! Version bump with no functional changes.The version increment is part of a coordinated update across the Notion integration components.
components/notion/sources/updated-page-id/updated-page-id.mjs (1)
10-10: Verify necessity of version bump.This source has no functional changes, and the PR's template support feature applies to the create-page-from-database action. Is this version bump necessary, or is it part of a coordinated release strategy across Notion components?
components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs (1)
7-7: LGTM! Version bump aligns with package-level dependency updates.The patch version increment is appropriate as part of the coordinated package update (notably the @notionhq/client dependency bump from ^5.0.0 to ^5.3.0).
components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs (1)
10-10: Version bump to 0.0.14 — LGTM.No logic changes; safe to merge.
components/notion/actions/create-database/create-database.mjs (1)
10-10: LGTM! Version bump aligns with package dependency updates.The patch version bump is appropriate for maintaining compatibility with the updated Notion package (1.0.6) and @notionhq/client dependency (^5.3.0), even though this specific action has no functional changes.
components/notion/actions/send-file-upload/send-file-upload.mjs (1)
11-11: Version bump is appropriate for the coordinated package update.The patch-level version increment aligns with the broader Notion package updates (parent package and @notionhq/client dependency upgrade) and maintains consistency across the module.
components/notion/actions/duplicate-page/duplicate-page.mjs (1)
10-10: LGTM! Routine version bump.The version increment with no logic changes is appropriate for package maintenance, consistent with the broader dependency updates in this PR.
components/notion/actions/retrieve-file-upload/retrieve-file-upload.mjs (1)
9-9: Version bump acknowledged.The patch version increment aligns with the coordinated version updates across multiple Notion actions in this PR.
components/notion/sources/page-properties-updated-instant/page-properties-updated-instant.mjs (1)
9-9: Patch bump LGTMVersion 1.0.1 is appropriate given no functional changes here.
components/notion/actions/retrieve-database-content/retrieve-database-content.mjs (1)
7-7: Let me verify the actual code changes in the file to understand the version bump context.Version bump is correct and follows Pipedream standards—original concern about package.json mismatch is invalid.
In Pipedream's architecture, when you update a file, you must increment the versions of all components that import or are affected by the updated file. The individual action version (1.0.2) is separate from the
components/notion/package.jsonversion (1.0.6). Individual components have independent versioning—when you add an action to the registry, the version should be 0.0.1; if the action was at version 0.1.0 and you've fixed a bug, change it to 0.1.1 when committing your final code. The current public marketplace shows this action was previously at 1.0.1, so bumping to 1.0.2 is a standard patch increment for a bug fix or minor update. This is correct and follows Pipedream component guidelines.Likely an incorrect or invalid review comment.
components/notion/actions/delete-block/delete-block.mjs (1)
23-27: The review comment is based on an incorrect assumption—no blockId propDefinition exists in notion.app.mjs.The suggested refactor cannot be applied. The propDefinitions object contains: dataSourceId, pageId, pageIdInDataSource, propertyId, metaTypes, propertyTypes, archived, title, userId, fileUploadId, sortDirection, pageSize, startCursor, filter, and pageContent—but no blockId propDefinition. The current inline definition in delete-block.mjs is the correct approach.
Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Ready for QA.
- Updated the `listTemplates` method call to use a parameters object for improved readability and maintainability. - Added support for optional `start_cursor` parameter to handle pagination when retrieving templates.
47e9127    to
    1c54013      
    Compare
  
    
Resolves #18869
Summary by CodeRabbit
Release Notes
New Features
Updates