From 84a1ccfc4c8776685da057540b3f77c96d21a9c1 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 24 Feb 2025 14:59:04 +0000 Subject: [PATCH 01/63] Fixing an issue with scrollbar always appearing on end user portal. --- packages/bbui/src/Layout/Page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bbui/src/Layout/Page.svelte b/packages/bbui/src/Layout/Page.svelte index e469927e60..e8dad8bc38 100644 --- a/packages/bbui/src/Layout/Page.svelte +++ b/packages/bbui/src/Layout/Page.svelte @@ -47,7 +47,7 @@ overflow-x: hidden; } .main { - overflow-y: scroll; + overflow-y: auto; } .content { display: flex; From f5a7e5bf4951c5c1cc62adfb88f2d51b291fdfb4 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 24 Feb 2025 15:34:30 +0000 Subject: [PATCH 02/63] Fixing app count in user page. --- .../src/pages/builder/portal/users/users/index.svelte | 2 +- packages/shared-core/src/sdk/documents/users.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/portal/users/users/index.svelte b/packages/builder/src/pages/builder/portal/users/users/index.svelte index c77e40c964..6a1facfd01 100644 --- a/packages/builder/src/pages/builder/portal/users/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/index.svelte @@ -128,7 +128,7 @@ $auth.user?.email === user.email ? false : true, - apps: [...new Set(Object.keys(user.roles))], + apps: sdk.users.userAppAccessList(user, $groups), access: role.sortOrder, } }) diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index 17aa8a1e58..c4f1a16025 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -4,6 +4,7 @@ import { SEPARATOR, User, InternalTable, + UserGroup, } from "@budibase/types" import { getProdAppID } from "./applications" import * as _ from "lodash/fp" @@ -129,3 +130,13 @@ export function containsUserID(value: string | undefined): boolean { } return value.includes(`${DocumentType.USER}${SEPARATOR}`) } + +export function userAppAccessList(user: User, groups?: UserGroup[]) { + const userGroups = + groups?.filter(group => group.users?.find(u => u._id === user._id)) || [] + const userGroupApps = userGroups.flatMap(userGroup => + Object.keys(userGroup.roles || {}) + ) + const fullList = [...Object.keys(user.roles), ...userGroupApps] + return [...new Set(fullList)] +} From a1589b0dc05af57d65aa9ac6dda7dd81d3ea814f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 24 Feb 2025 18:07:01 +0000 Subject: [PATCH 03/63] Adding group badges to users. --- packages/bbui/src/Badge/Badge.svelte | 2 ++ .../[application]/_components/BuilderSidePanel.svelte | 5 +++++ packages/shared-core/src/sdk/documents/users.ts | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/bbui/src/Badge/Badge.svelte b/packages/bbui/src/Badge/Badge.svelte index e4ec7d4f33..03aa544dfe 100644 --- a/packages/bbui/src/Badge/Badge.svelte +++ b/packages/bbui/src/Badge/Badge.svelte @@ -11,6 +11,7 @@ export let active = false export let inactive = false export let hoverable = false + export let customColor = null @@ -29,6 +30,7 @@ class:spectrum-Label--seafoam={seafoam} class:spectrum-Label--active={active} class:spectrum-Label--inactive={inactive} + style={customColor ? `background-color: ${customColor};` : ""} > diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 2260892913..5b1bf852aa 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -13,6 +13,7 @@ FancyInput, Button, FancySelect, + Badge, } from "@budibase/bbui" import { builderStore, appStore, roles, appPublished } from "@/stores/builder" import { @@ -741,11 +742,15 @@
Access
{#each allUsers as user} + {@const userGroups = sdk.users.getUserGroups(user, $groups)}
{user.email}
+ {#each userGroups as group} + {group.name} + {/each}
group.users?.find(u => u._id === user._id)) || [] + ) +} + +export function userAppAccessList(user: User, groups?: UserGroup[]) { + const userGroups = getUserGroups(user, groups) const userGroupApps = userGroups.flatMap(userGroup => Object.keys(userGroup.roles || {}) ) From f7d216c188562cf793673e04d3a17e5face33264 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 24 Feb 2025 18:08:20 +0000 Subject: [PATCH 04/63] Setting override placeholder. --- .../app/[application]/_components/BuilderSidePanel.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 5b1bf852aa..a9d3bb70ba 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -755,7 +755,7 @@
Date: Tue, 25 Feb 2025 10:45:50 +0000 Subject: [PATCH 05/63] Changing how badges are displayed. --- .../_components/BuilderSidePanel.svelte | 27 ++++++++++++++----- .../shared-core/src/sdk/documents/users.ts | 12 +++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index a9d3bb70ba..8136dd256c 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -742,15 +742,19 @@
Access
{#each allUsers as user} - {@const userGroups = sdk.users.getUserGroups(user, $groups)} + {@const userGroups = sdk.users.getUserAppGroups($appStore.appId, user, $groups)}
-
- {user.email} +
+
+ {user.email} +
+
+ {#each userGroups as group} + {group.name} + {/each} +
- {#each userGroups as group} - {group.name} - {/each}
diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index 8b5abfd822..d2ee2dec00 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -137,6 +137,18 @@ export function getUserGroups(user: User, groups?: UserGroup[]) { ) } +export function getUserAppGroups( + appId: string, + user: User, + groups?: UserGroup[] +) { + const prodAppId = getProdAppID(appId) + const userGroups = getUserGroups(user, groups) + return userGroups.filter(group => + Object.keys(group.roles || {}).find(app => app === prodAppId) + ) +} + export function userAppAccessList(user: User, groups?: UserGroup[]) { const userGroups = getUserGroups(user, groups) const userGroupApps = userGroups.flatMap(userGroup => From c93d413d67c04e57ab9936b8aa6bb2d30eeba7cb Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 25 Feb 2025 11:03:04 +0000 Subject: [PATCH 06/63] Improve typing around plugins. --- packages/pro | 2 +- .../src/api/controllers/plugin/index.ts | 14 ++++--- packages/server/src/sdk/index.ts | 2 +- packages/server/src/sdk/plugins/index.ts | 42 +++++++++++++++++-- packages/server/src/sdk/plugins/plugins.ts | 41 ------------------ .../server/src/utilities/fileSystem/plugin.ts | 35 ++++++++-------- packages/server/src/watch.ts | 5 ++- packages/types/src/documents/global/plugin.ts | 26 ++++++++++-- 8 files changed, 92 insertions(+), 75 deletions(-) delete mode 100644 packages/server/src/sdk/plugins/plugins.ts diff --git a/packages/pro b/packages/pro index 45f5673d5e..219be3ef38 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 45f5673d5e5ab3c22deb6663cea2e31a628aa133 +Subproject commit 219be3ef380ac8cb16b34892f62117d31b50eec7 diff --git a/packages/server/src/api/controllers/plugin/index.ts b/packages/server/src/api/controllers/plugin/index.ts index 2a4d69b671..6f7cceca10 100644 --- a/packages/server/src/api/controllers/plugin/index.ts +++ b/packages/server/src/api/controllers/plugin/index.ts @@ -11,6 +11,7 @@ import { UploadPluginResponse, FetchPluginResponse, DeletePluginResponse, + PluginMetadata, } from "@budibase/types" import env from "../../../environment" import { clientAppSocket } from "../../../websockets" @@ -53,10 +54,11 @@ export async function create( const { source, url, headers, githubToken } = ctx.request.body try { - let metadata - let directory + let metadata: PluginMetadata + let directory: string + // Generating random name as a backup and needed for url - let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000) + const name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000) switch (source) { case PluginSource.NPM: { @@ -81,12 +83,14 @@ export async function create( directory = directoryUrl break } + default: + ctx.throw(400, "Invalid source") } - pluginCore.validate(metadata?.schema) + pluginCore.validate(metadata.schema) // Only allow components in cloud - if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) { + if (!env.SELF_HOSTED && metadata.schema?.type !== PluginType.COMPONENT) { throw new Error( "Only component plugins are supported outside of self-host" ) diff --git a/packages/server/src/sdk/index.ts b/packages/server/src/sdk/index.ts index e3e88c25c4..6d6bf00ee0 100644 --- a/packages/server/src/sdk/index.ts +++ b/packages/server/src/sdk/index.ts @@ -7,7 +7,7 @@ import { default as queries } from "./app/queries" import { default as rows } from "./app/rows" import { default as links } from "./app/links" import { default as users } from "./users" -import { default as plugins } from "./plugins" +import * as plugins from "./plugins" import * as views from "./app/views" import * as permissions from "./app/permissions" import * as rowActions from "./app/rowActions" diff --git a/packages/server/src/sdk/plugins/index.ts b/packages/server/src/sdk/plugins/index.ts index 863cfa0db6..03dd2be256 100644 --- a/packages/server/src/sdk/plugins/index.ts +++ b/packages/server/src/sdk/plugins/index.ts @@ -1,5 +1,41 @@ -import * as plugins from "./plugins" +import { KoaFile, Plugin, PluginSource, PluginType } from "@budibase/types" +import { + db as dbCore, + objectStore, + plugins as pluginCore, + tenancy, +} from "@budibase/backend-core" +import { fileUpload } from "../../api/controllers/plugin/file" +import env from "../../environment" +import { clientAppSocket } from "../../websockets" +import { sdk as pro } from "@budibase/pro" -export default { - ...plugins, +export async function fetch(type?: PluginType): Promise { + const db = tenancy.getGlobalDB() + const response = await db.allDocs( + dbCore.getPluginParams(null, { + include_docs: true, + }) + ) + let plugins = response.rows.map((row: any) => row.doc) as Plugin[] + plugins = await objectStore.enrichPluginURLs(plugins) + if (type) { + return plugins.filter((plugin: Plugin) => plugin.schema?.type === type) + } else { + return plugins + } +} + +export async function processUploaded(plugin: KoaFile, source: PluginSource) { + const { metadata, directory } = await fileUpload(plugin) + pluginCore.validate(metadata.schema) + + // Only allow components in cloud + if (!env.SELF_HOSTED && metadata.schema?.type !== PluginType.COMPONENT) { + throw new Error("Only component plugins are supported outside of self-host") + } + + const doc = await pro.plugins.storePlugin(metadata, directory, source) + clientAppSocket?.emit("plugin-update", { name: doc.name, hash: doc.hash }) + return doc } diff --git a/packages/server/src/sdk/plugins/plugins.ts b/packages/server/src/sdk/plugins/plugins.ts deleted file mode 100644 index bff24dcef7..0000000000 --- a/packages/server/src/sdk/plugins/plugins.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { KoaFile, Plugin, PluginSource, PluginType } from "@budibase/types" -import { - db as dbCore, - objectStore, - plugins as pluginCore, - tenancy, -} from "@budibase/backend-core" -import { fileUpload } from "../../api/controllers/plugin/file" -import env from "../../environment" -import { clientAppSocket } from "../../websockets" -import { sdk as pro } from "@budibase/pro" - -export async function fetch(type?: PluginType): Promise { - const db = tenancy.getGlobalDB() - const response = await db.allDocs( - dbCore.getPluginParams(null, { - include_docs: true, - }) - ) - let plugins = response.rows.map((row: any) => row.doc) as Plugin[] - plugins = await objectStore.enrichPluginURLs(plugins) - if (type) { - return plugins.filter((plugin: Plugin) => plugin.schema?.type === type) - } else { - return plugins - } -} - -export async function processUploaded(plugin: KoaFile, source?: PluginSource) { - const { metadata, directory } = await fileUpload(plugin) - pluginCore.validate(metadata?.schema) - - // Only allow components in cloud - if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) { - throw new Error("Only component plugins are supported outside of self-host") - } - - const doc = await pro.plugins.storePlugin(metadata, directory, source) - clientAppSocket?.emit("plugin-update", { name: doc.name, hash: doc.hash }) - return doc -} diff --git a/packages/server/src/utilities/fileSystem/plugin.ts b/packages/server/src/utilities/fileSystem/plugin.ts index 2949daef61..1c62e9c1e9 100644 --- a/packages/server/src/utilities/fileSystem/plugin.ts +++ b/packages/server/src/utilities/fileSystem/plugin.ts @@ -1,4 +1,4 @@ -import { Plugin } from "@budibase/types" +import { Plugin, PluginUpload } from "@budibase/types" import { budibaseTempDir } from "../budibaseDir" import fs from "fs" import { join } from "path" @@ -8,23 +8,22 @@ import stream from "stream" const DATASOURCE_PATH = join(budibaseTempDir(), "datasource") const AUTOMATION_PATH = join(budibaseTempDir(), "automation") -export const getPluginMetadata = async (path: string) => { - let metadata: any = {} +export const getPluginMetadata = async ( + path: string +): Promise => { + let pkg: any + let schema: any try { - const pkg = fs.readFileSync(join(path, "package.json"), "utf8") - const schema = fs.readFileSync(join(path, "schema.json"), "utf8") - - metadata.schema = JSON.parse(schema) - metadata.package = JSON.parse(pkg) - - if ( - !metadata.package.name || - !metadata.package.version || - !metadata.package.description - ) { - throw new Error( - "package.json is missing one of 'name', 'version' or 'description'." - ) + pkg = JSON.parse(fs.readFileSync(join(path, "pkg.json"), "utf8")) + schema = JSON.parse(fs.readFileSync(join(path, "schema.json"), "utf8")) + if (!pkg.name) { + throw new Error("package.json is missing 'name'.") + } + if (!pkg.version) { + throw new Error("package.json is missing 'version'.") + } + if (!pkg.description) { + throw new Error("package.json is missing 'description'.") } } catch (err: any) { throw new Error( @@ -32,7 +31,7 @@ export const getPluginMetadata = async (path: string) => { ) } - return { metadata, directory: path } + return { metadata: { package: pkg, schema }, directory: path } } async function getPluginImpl(path: string, plugin: Plugin) { diff --git a/packages/server/src/watch.ts b/packages/server/src/watch.ts index 8f3fe22023..16b8800887 100644 --- a/packages/server/src/watch.ts +++ b/packages/server/src/watch.ts @@ -3,7 +3,8 @@ import env from "./environment" import chokidar from "chokidar" import fs from "fs" import { constants, tenancy } from "@budibase/backend-core" -import pluginsSdk from "./sdk/plugins" +import { processUploaded } from "./sdk/plugins" +import { PluginSource } from "@budibase/types" export function watch() { const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz") @@ -27,7 +28,7 @@ export function watch() { const split = path.split("/") const name = split[split.length - 1] console.log("Importing plugin:", path) - await pluginsSdk.processUploaded({ name, path }) + await processUploaded({ name, path }, PluginSource.FILE) } catch (err: any) { const message = err?.message ? err?.message : err console.error("Failed to import plugin:", message) diff --git a/packages/types/src/documents/global/plugin.ts b/packages/types/src/documents/global/plugin.ts index eeddc04e58..56611d2d24 100644 --- a/packages/types/src/documents/global/plugin.ts +++ b/packages/types/src/documents/global/plugin.ts @@ -24,10 +24,7 @@ export interface Plugin extends Document { source: PluginSource package: { [key: string]: any } hash: string - schema: { - type: PluginType - [key: string]: any - } + schema: PluginSchema iconFileName?: string // Populated on read jsUrl?: string @@ -36,3 +33,24 @@ export interface Plugin extends Document { } export const PLUGIN_TYPE_ARR = Object.values(PluginType) + +export interface PluginSchema { + type: PluginType + [key: string]: any +} + +interface Package { + name: string + version: string + description: string +} + +export interface PluginMetadata { + schema: PluginSchema + package: Package +} + +export interface PluginUpload { + metadata: PluginMetadata + directory: string +} From b23aee478da9ecdfbbd8d6d4fa0d359f242d651c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 25 Feb 2025 15:18:28 +0000 Subject: [PATCH 07/63] Fix plugin tests. --- packages/server/src/utilities/fileSystem/plugin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utilities/fileSystem/plugin.ts b/packages/server/src/utilities/fileSystem/plugin.ts index 1c62e9c1e9..15238637c1 100644 --- a/packages/server/src/utilities/fileSystem/plugin.ts +++ b/packages/server/src/utilities/fileSystem/plugin.ts @@ -14,7 +14,7 @@ export const getPluginMetadata = async ( let pkg: any let schema: any try { - pkg = JSON.parse(fs.readFileSync(join(path, "pkg.json"), "utf8")) + pkg = JSON.parse(fs.readFileSync(join(path, "package.json"), "utf8")) schema = JSON.parse(fs.readFileSync(join(path, "schema.json"), "utf8")) if (!pkg.name) { throw new Error("package.json is missing 'name'.") @@ -27,7 +27,8 @@ export const getPluginMetadata = async ( } } catch (err: any) { throw new Error( - `Unable to process schema.json/package.json in plugin. ${err.message}` + `Unable to process schema.json/package.json in plugin. ${err.message}`, + { cause: err } ) } From df102e7b6b6e9e518bfec8907eba79782f06b551 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 25 Feb 2025 17:18:27 +0000 Subject: [PATCH 08/63] Opacity of group badges. --- packages/bbui/src/Badge/Badge.svelte | 2 +- .../app/[application]/_components/BuilderSidePanel.svelte | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/bbui/src/Badge/Badge.svelte b/packages/bbui/src/Badge/Badge.svelte index 03aa544dfe..15bb6c62c2 100644 --- a/packages/bbui/src/Badge/Badge.svelte +++ b/packages/bbui/src/Badge/Badge.svelte @@ -30,7 +30,7 @@ class:spectrum-Label--seafoam={seafoam} class:spectrum-Label--active={active} class:spectrum-Label--inactive={inactive} - style={customColor ? `background-color: ${customColor};` : ""} + style={customColor ? `background-color: ${customColor}` : ""} > diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 8136dd256c..ff4b872153 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -742,7 +742,7 @@
Access
{#each allUsers as user} - {@const userGroups = sdk.users.getUserAppGroups($appStore.appId, user, $groups)} + {@const userGroups = sdk.users.getUserAppGroups($appStore.appId, user, $groups).slice(0, 3)}
@@ -751,7 +751,7 @@
{#each userGroups as group} - {group.name} + {group.name} {/each}
@@ -949,6 +949,8 @@ grid-template-columns: 1fr 220px; align-items: center; gap: var(--spacing-xl); + border-bottom: var(--border-light); + padding-bottom: var(--spacing-s); } .auth-entity .details { From c3de44a6a9270fba6b8184ed379fa4b304ba4efe Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 25 Feb 2025 18:17:41 +0000 Subject: [PATCH 09/63] Adding a way to limit the groups shown and then display a popover. --- packages/bbui/src/Icon/Icon.svelte | 3 ++ .../_components/BuilderGroupPopover.svelte | 49 +++++++++++++++++++ .../_components/BuilderSidePanel.svelte | 15 ++++-- .../_components/GroupBadge.svelte | 10 ++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte create mode 100644 packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte diff --git a/packages/bbui/src/Icon/Icon.svelte b/packages/bbui/src/Icon/Icon.svelte index 2f12935f53..46b3140be8 100644 --- a/packages/bbui/src/Icon/Icon.svelte +++ b/packages/bbui/src/Icon/Icon.svelte @@ -28,6 +28,9 @@ + import { Icon, Popover } from "@budibase/bbui" + import GroupBadge from "./GroupBadge.svelte" + + export let groups = [] + + let anchor, popover + + function show() { + popover.show() + } + + function hide() { + popover.hide() + } + + +
+ +
+ + +
+ {#each groups as group} + + {/each} +
+
+ + diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index ff4b872153..11a36706cf 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -38,6 +38,8 @@ import { emailValidator } from "@/helpers/validation" import { fly } from "svelte/transition" import InfoDisplay from "../design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte" + import BuilderGroupPopover from "./BuilderGroupPopover.svelte" + import GroupBadge from "./GroupBadge.svelte" let query = null let loaded = false @@ -742,7 +744,11 @@
Access
{#each allUsers as user} - {@const userGroups = sdk.users.getUserAppGroups($appStore.appId, user, $groups).slice(0, 3)} + {@const userGroups = sdk.users.getUserAppGroups( + $appStore.appId, + user, + $groups + )}
@@ -750,9 +756,12 @@ {user.email}
- {#each userGroups as group} - {group.name} + {#each userGroups.slice(0, 3) as group} + {/each} + {#if userGroups.length > 3} + + {/if}
diff --git a/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte b/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte new file mode 100644 index 0000000000..f10e2aa220 --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte @@ -0,0 +1,10 @@ + + +{name} From 336bc72de27860e8941e3a984929d2b83062de01 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 26 Feb 2025 12:53:18 +0000 Subject: [PATCH 10/63] Design after discussion with Cheeks and Joe. --- packages/bbui/src/Badge/Badge.svelte | 4 +- .../_components/BuilderGroupPopover.svelte | 41 +++------------- .../_components/BuilderSidePanel.svelte | 48 ++++++++++--------- .../_components/GroupBadge.svelte | 10 ---- packages/shared-core/src/helpers/index.ts | 1 + packages/shared-core/src/helpers/lists.ts | 7 +++ 6 files changed, 43 insertions(+), 68 deletions(-) delete mode 100644 packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte create mode 100644 packages/shared-core/src/helpers/lists.ts diff --git a/packages/bbui/src/Badge/Badge.svelte b/packages/bbui/src/Badge/Badge.svelte index 15bb6c62c2..dadbaa3317 100644 --- a/packages/bbui/src/Badge/Badge.svelte +++ b/packages/bbui/src/Badge/Badge.svelte @@ -11,7 +11,7 @@ export let active = false export let inactive = false export let hoverable = false - export let customColor = null + export let outlineColor = null @@ -30,7 +30,7 @@ class:spectrum-Label--seafoam={seafoam} class:spectrum-Label--active={active} class:spectrum-Label--inactive={inactive} - style={customColor ? `background-color: ${customColor}` : ""} + style={outlineColor ? `border: 2px solid ${outlineColor}` : ""} > diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte index 47811cbcb9..43c662a6d2 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte @@ -1,49 +1,22 @@ -
- +
+
- -
- {#each groups as group} - - {/each} -
-
- diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 11a36706cf..0bf32e4b76 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -13,7 +13,6 @@ FancyInput, Button, FancySelect, - Badge, } from "@budibase/bbui" import { builderStore, appStore, roles, appPublished } from "@/stores/builder" import { @@ -39,7 +38,6 @@ import { fly } from "svelte/transition" import InfoDisplay from "../design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte" import BuilderGroupPopover from "./BuilderGroupPopover.svelte" - import GroupBadge from "./GroupBadge.svelte" let query = null let loaded = false @@ -542,6 +540,12 @@ creationAccessType = Constants.Roles.CREATOR } } + + const itemCountText = (word, count) => { + return `${count} ${word}${ + count !== 1 ? "s" : "" + }` + } @@ -708,9 +712,7 @@ {group.name}
- {`${group.users?.length} user${ - group.users?.length != 1 ? "s" : "" - }`} + {itemCountText("user", group.users?.length)}
@@ -755,20 +757,20 @@
{user.email}
-
- {#each userGroups.slice(0, 3) as group} - - {/each} - {#if userGroups.length > 3} - - {/if} -
+ {#if userGroups.length} +
+
+ {itemCountText("group", userGroups.length)} +
+ +
+ {/if}
diff --git a/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte b/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte deleted file mode 100644 index f10e2aa220..0000000000 --- a/packages/builder/src/pages/builder/app/[application]/_components/GroupBadge.svelte +++ /dev/null @@ -1,10 +0,0 @@ - - -{name} diff --git a/packages/shared-core/src/helpers/index.ts b/packages/shared-core/src/helpers/index.ts index 0aa378b46a..b924617a0f 100644 --- a/packages/shared-core/src/helpers/index.ts +++ b/packages/shared-core/src/helpers/index.ts @@ -6,3 +6,4 @@ export * as cron from "./cron" export * as schema from "./schema" export * as views from "./views" export * as roles from "./roles" +export * as lists from "./lists" diff --git a/packages/shared-core/src/helpers/lists.ts b/packages/shared-core/src/helpers/lists.ts new file mode 100644 index 0000000000..64b906fef8 --- /dev/null +++ b/packages/shared-core/src/helpers/lists.ts @@ -0,0 +1,7 @@ +export function punctuateList(list: string[]) { + if (list.length === 0) return "" + if (list.length === 1) return list[0] + if (list.length === 2) return list.join(" and ") + // For more than 2 elements: join all but the last with commas, then add "and" before the last element. + return list.slice(0, -1).join(", ") + " and " + list[list.length - 1] +} From daf317b0a72c96eb815e473ea8d283c63586def9 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Wed, 26 Feb 2025 13:19:59 +0000 Subject: [PATCH 11/63] Bump version to 3.4.18 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 8ea860e3c4..055b8b5ca8 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "3.4.17", + "version": "3.4.18", "npmClient": "yarn", "concurrency": 20, "command": { From c2841b824d5ad83a12fe777f356ae0ef55548152 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 26 Feb 2025 13:25:58 +0000 Subject: [PATCH 12/63] Linting. --- .../_components/BuilderGroupPopover.svelte | 13 +++++++++++-- .../_components/BuilderSidePanel.svelte | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte index 43c662a6d2..367d84e029 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderGroupPopover.svelte @@ -4,13 +4,22 @@ export let groups = [] function tooltip(groups) { - const sortedNames = groups.sort((a, b) => a.name.localeCompare(b.name)).map(group => group.name) + const sortedNames = groups + .sort((a, b) => a.name.localeCompare(b.name)) + .map(group => group.name) return `Member of ${helpers.lists.punctuateList(sortedNames)}` }
- +
From b0c4bc5d3dbb887b0597c63d0293de9cb6845942 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 13:10:09 +0100 Subject: [PATCH 39/63] Remove unnecessary numArgs --- .../scripts/gen-collection-info.ts | 5 - packages/string-templates/src/manifest.json | 138 ------------------ 2 files changed, 143 deletions(-) diff --git a/packages/string-templates/scripts/gen-collection-info.ts b/packages/string-templates/scripts/gen-collection-info.ts index 61edd0d2fb..ffe9f68add 100644 --- a/packages/string-templates/scripts/gen-collection-info.ts +++ b/packages/string-templates/scripts/gen-collection-info.ts @@ -17,7 +17,6 @@ type BudibaseAnnotation = Annotation & { type Helper = { args: string[] - numArgs: number example?: string description: string requiresBlock?: boolean @@ -35,14 +34,12 @@ const ADDED_HELPERS = { date: { date: { args: ["datetime", "format", "options"], - numArgs: 3, example: '{{date now "DD-MM-YYYY" "America/New_York" }} -> 21-01-2021', description: "Format a date using moment.js date formatting - the timezone is optional and uses the tz database.", }, duration: { args: ["time", "durationType"], - numArgs: 2, example: '{{duration 8 "seconds"}} -> a few seconds', description: "Produce a humanized duration left/until given an amount of time and the type of time measurement.", @@ -53,7 +50,6 @@ const ADDED_HELPERS = { function fixSpecialCases(name: string, obj: Helper) { if (name === "ifNth") { obj.args = ["a", "b", "options"] - obj.numArgs = 3 } if (name === "eachIndex") { obj.description = "Iterates the array, listing an item and the index of it." @@ -163,7 +159,6 @@ function run() { .map(tag => tag.description!.replace(/`/g, "").split(" ")[0].trim()) collectionInfo[name] = fixSpecialCases(name, { args, - numArgs: args.length, example: jsDocInfo.example || undefined, description: jsDocInfo.description, requiresBlock: jsDocInfo.acceptsBlock && !jsDocInfo.acceptsInline, diff --git a/packages/string-templates/src/manifest.json b/packages/string-templates/src/manifest.json index f36746f3d0..e47af7d69a 100644 --- a/packages/string-templates/src/manifest.json +++ b/packages/string-templates/src/manifest.json @@ -4,7 +4,6 @@ "args": [ "a" ], - "numArgs": 1, "example": "{{ abs 12012.1000 }} -> 12012.1", "description": "

Return the magnitude of a.

\n", "requiresBlock": false @@ -14,7 +13,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ add 1 2 }} -> 3", "description": "

Return the sum of a plus b.

\n", "requiresBlock": false @@ -23,7 +21,6 @@ "args": [ "array" ], - "numArgs": 1, "example": "{{ avg 1 2 3 4 5 }} -> 3", "description": "

Returns the average of all numbers in the given array.

\n", "requiresBlock": false @@ -32,7 +29,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{ ceil 1.2 }} -> 2", "description": "

Get the Math.ceil() of the given value.

\n", "requiresBlock": false @@ -42,7 +38,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ divide 10 5 }} -> 2", "description": "

Divide a by b

\n", "requiresBlock": false @@ -51,7 +46,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{ floor 1.2 }} -> 1", "description": "

Get the Math.floor() of the given value.

\n", "requiresBlock": false @@ -61,7 +55,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", "description": "

Return the product of a minus b.

\n", "requiresBlock": false @@ -71,7 +64,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ modulo 10 5 }} -> 0", "description": "

Get the remainder of a division operation.

\n", "requiresBlock": false @@ -81,7 +73,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ multiply 10 5 }} -> 50", "description": "

Multiply number a by number b.

\n", "requiresBlock": false @@ -91,7 +82,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ plus 10 5 }} -> 15", "description": "

Add a by b.

\n", "requiresBlock": false @@ -101,7 +91,6 @@ "min", "max" ], - "numArgs": 2, "example": "{{ random 0 20 }} -> 10", "description": "

Generate a random number between two values

\n", "requiresBlock": false @@ -111,7 +100,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ remainder 10 6 }} -> 4", "description": "

Get the remainder when a is divided by b.

\n", "requiresBlock": false @@ -120,7 +108,6 @@ "args": [ "number" ], - "numArgs": 1, "example": "{{ round 10.3 }} -> 10", "description": "

Round the given number.

\n", "requiresBlock": false @@ -130,7 +117,6 @@ "a", "b" ], - "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", "description": "

Return the product of a minus b.

\n", "requiresBlock": false @@ -139,7 +125,6 @@ "args": [ "array" ], - "numArgs": 1, "example": "{{ sum [1, 2, 3] }} -> 6", "description": "

Returns the sum of all numbers in the given array.

\n", "requiresBlock": false @@ -151,7 +136,6 @@ "array", "n" ], - "numArgs": 2, "example": "{{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd']", "description": "

Returns all of the items in an array after the specified index. Opposite of before.

\n", "requiresBlock": false @@ -160,7 +144,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{ arrayify 'foo' }} -> ['foo']", "description": "

Cast the given value to an array.

\n", "requiresBlock": false @@ -170,7 +153,6 @@ "array", "n" ], - "numArgs": 2, "example": "{{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b']", "description": "

Return all of the items in the collection before the specified count. Opposite of after.

\n", "requiresBlock": false @@ -180,7 +162,6 @@ "array", "options" ], - "numArgs": 2, "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '", "description": "

Iterates the array, listing an item and the index of it.

\n", "requiresBlock": true @@ -191,7 +172,6 @@ "value", "options" ], - "numArgs": 3, "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found", "description": "

Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned.

\n", "requiresBlock": true @@ -201,7 +181,6 @@ "array", "n" ], - "numArgs": 2, "example": "{{first [1, 2, 3, 4] 2}} -> 1,2", "description": "

Returns the first item, or first n items of an array.

\n", "requiresBlock": false @@ -211,7 +190,6 @@ "array", "options" ], - "numArgs": 2, "example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John '", "description": "

Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index - total - isFirst - isLast Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.

\n", "requiresBlock": true @@ -222,7 +200,6 @@ "value", "options" ], - "numArgs": 3, "example": "{{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists '", "description": "

Block helper that renders the block if an array has the given value. Optionally specify an inverse block to render when the array does not have the given value.

\n", "requiresBlock": true @@ -231,7 +208,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{isArray [1, 2]}} -> true", "description": "

Returns true if value is an es5 array.

\n", "requiresBlock": false @@ -241,7 +217,6 @@ "array", "idx" ], - "numArgs": 2, "example": "{{itemAt [1, 2, 3] 1}} -> 2", "description": "

Returns the item from array at index idx.

\n", "requiresBlock": false @@ -251,7 +226,6 @@ "array", "separator" ], - "numArgs": 2, "example": "{{join [1, 2, 3]}} -> 1, 2, 3", "description": "

Join all elements of array into a string, optionally using a given separator.

\n", "requiresBlock": false @@ -261,7 +235,6 @@ "value", "length" ], - "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", "requiresBlock": false @@ -271,7 +244,6 @@ "value", "n" ], - "numArgs": 2, "example": "{{last [1, 2, 3]}} -> 3", "description": "

Returns the last item, or last n items of an array or string. Opposite of first.

\n", "requiresBlock": false @@ -280,7 +252,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{length [1, 2, 3]}} -> 3", "description": "

Returns the length of the given string or array.

\n", "requiresBlock": false @@ -290,7 +261,6 @@ "value", "length" ], - "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", "requiresBlock": false @@ -300,7 +270,6 @@ "array", "fn" ], - "numArgs": 2, "example": "{{map [1, 2, 3] double}} -> [2, 4, 6]", "description": "

Returns a new array, created by calling function on each element of the given array. For example,

\n", "requiresBlock": false @@ -310,7 +279,6 @@ "collection", "prop" ], - "numArgs": 2, "example": "{{pluck [{ 'name': 'Bob' }] 'name' }} -> ['Bob']", "description": "

Map over the given object or array or objects and create an array of values from the given prop. Dot-notation may be used (as a string) to get nested properties.

\n", "requiresBlock": false @@ -319,7 +287,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{reverse [1, 2, 3]}} -> [3, 2, 1]", "description": "

Reverse the elements in an array, or the characters in a string.

\n", "requiresBlock": false @@ -330,7 +297,6 @@ "iter", "provided" ], - "numArgs": 3, "example": "{{#some [1, \"b\", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found '", "description": "

Block helper that returns the block if the callback returns true for some value in the given array.

\n", "requiresBlock": true @@ -340,7 +306,6 @@ "array", "key" ], - "numArgs": 2, "example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']", "description": "

Sort the given array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", "requiresBlock": false @@ -350,7 +315,6 @@ "array", "props" ], - "numArgs": 2, "example": "{{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}]", "description": "

Sort an array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", "requiresBlock": false @@ -361,7 +325,6 @@ "idx", "options" ], - "numArgs": 3, "example": "{{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 '", "description": "

Use the items in the array after the specified index as context inside a block. Opposite of withBefore.

\n", "requiresBlock": true @@ -372,7 +335,6 @@ "idx", "options" ], - "numArgs": 3, "example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '", "description": "

Use the items in the array before the specified index as context inside a block. Opposite of withAfter.

\n", "requiresBlock": true @@ -383,7 +345,6 @@ "idx", "options" ], - "numArgs": 3, "example": "{{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1", "description": "

Use the first item in a collection inside a handlebars block expression. Opposite of withLast.

\n", "requiresBlock": true @@ -394,7 +355,6 @@ "size", "options" ], - "numArgs": 3, "example": "{{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}
{{/withGroup}} -> 12
34
", "description": "

Block helper that groups array elements by given group size.

\n", "requiresBlock": true @@ -405,7 +365,6 @@ "idx", "options" ], - "numArgs": 3, "example": "{{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4", "description": "

Use the last item or n items in an array as context inside a block. Opposite of withFirst.

\n", "requiresBlock": true @@ -416,7 +375,6 @@ "prop", "options" ], - "numArgs": 3, "example": "{{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc", "description": "

Block helper that sorts a collection and exposes the sorted collection as context inside the block.

\n", "requiresBlock": true @@ -426,7 +384,6 @@ "array", "options" ], - "numArgs": 2, "example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe", "description": "

Block helper that return an array with all duplicate values removed. Best used along with a each helper.

\n", "requiresBlock": true @@ -437,7 +394,6 @@ "args": [ "number" ], - "numArgs": 1, "example": "{{ bytes 1386 1 }} -> 1.4 kB", "description": "

Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. Examples: - 'foo' => 3 B - 13661855 => 13.66 MB - 825399 => 825.39 kB - 1396 => 1.4 kB

\n", "requiresBlock": false @@ -446,7 +402,6 @@ "args": [ "num" ], - "numArgs": 1, "example": "{{ addCommas 1000000 }} -> 1,000,000", "description": "

Add commas to numbers

\n", "requiresBlock": false @@ -455,7 +410,6 @@ "args": [ "num" ], - "numArgs": 1, "example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212", "description": "

Convert a string or number to a formatted phone number.

\n", "requiresBlock": false @@ -465,7 +419,6 @@ "number", "precision" ], - "numArgs": 2, "example": "{{ toAbbr 10123 2 }} -> 10.12k", "description": "

Abbreviate numbers to the given number of precision. This for general numbers, not size in bytes.

\n", "requiresBlock": false @@ -475,7 +428,6 @@ "number", "fractionDigits" ], - "numArgs": 2, "example": "{{ toExponential 10123 2 }} -> 1.01e+4", "description": "

Returns a string representing the given number in exponential notation.

\n", "requiresBlock": false @@ -485,7 +437,6 @@ "number", "digits" ], - "numArgs": 2, "example": "{{ toFixed 1.1234 2 }} -> 1.12", "description": "

Formats the given number using fixed-point notation.

\n", "requiresBlock": false @@ -494,7 +445,6 @@ "args": [ "number" ], - "numArgs": 1, "description": "

Convert input to a float.

\n", "requiresBlock": false }, @@ -502,7 +452,6 @@ "args": [ "number" ], - "numArgs": 1, "description": "

Convert input to an integer.

\n", "requiresBlock": false }, @@ -511,7 +460,6 @@ "number", "precision" ], - "numArgs": 2, "example": "{{toPrecision '1.1234' 2}} -> 1.1", "description": "

Returns a string representing the Number object to the specified precision.

\n", "requiresBlock": false @@ -522,7 +470,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There", "description": "

Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.

\n", "requiresBlock": false @@ -531,7 +478,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere", "description": "

Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.

\n", "requiresBlock": false @@ -540,7 +486,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There", "description": "

Decode a Uniform Resource Identifier (URI) component.

\n", "requiresBlock": false @@ -550,7 +495,6 @@ "base", "href" ], - "numArgs": 2, "example": "{{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test", "description": "

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

\n", "requiresBlock": false @@ -559,7 +503,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ urlParse 'https://myurl/api/test' }}", "description": "

Parses a url string into an object.

\n", "requiresBlock": false @@ -568,7 +511,6 @@ "args": [ "url" ], - "numArgs": 1, "example": "{{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test'", "description": "

Strip the query string from the given url.

\n", "requiresBlock": false @@ -577,7 +519,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test'", "description": "

Strip protocol from a url. Useful for displaying media that may have an 'http' protocol on secure connections.

\n", "requiresBlock": false @@ -589,7 +530,6 @@ "str", "suffix" ], - "numArgs": 2, "example": "{{append 'index' '.html'}} -> index.html", "description": "

Append the specified suffix to the given string.

\n", "requiresBlock": false @@ -598,7 +538,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{camelcase 'foo bar baz'}} -> fooBarBaz", "description": "

camelCase the characters in the given string.

\n", "requiresBlock": false @@ -607,7 +546,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{capitalize 'foo bar baz'}} -> Foo bar baz", "description": "

Capitalize the first word in a sentence.

\n", "requiresBlock": false @@ -616,7 +554,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz", "description": "

Capitalize all words in a string.

\n", "requiresBlock": false @@ -626,7 +563,6 @@ "str", "spaces" ], - "numArgs": 2, "example": "{{ center 'test' 1}} -> ' test '", "description": "

Center a string using non-breaking spaces

\n", "requiresBlock": false @@ -635,7 +571,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{ chop ' ABC '}} -> ABC", "description": "

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

\n", "requiresBlock": false @@ -644,7 +579,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{dashcase 'a-b-c d_e'}} -> a-b-c-d-e", "description": "

dash-case the characters in string. Replaces non-word characters and periods with hyphens.

\n", "requiresBlock": false @@ -653,7 +587,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{dotcase 'a-b-c d_e'}} -> a.b.c.d.e", "description": "

dot.case the characters in string.

\n", "requiresBlock": false @@ -662,7 +595,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{downcase 'aBcDeF'}} -> abcdef", "description": "

Lowercase all of the characters in the given string. Alias for lowercase.

\n", "requiresBlock": false @@ -672,7 +604,6 @@ "str", "length" ], - "numArgs": 2, "example": "{{ellipsis 'foo bar baz' 7}} -> foo bar…", "description": "

Truncates a string to the specified length, and appends it with an elipsis, ….

\n", "requiresBlock": false @@ -681,7 +612,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{hyphenate 'foo bar baz qux'}} -> foo-bar-baz-qux", "description": "

Replace spaces in a string with hyphens.

\n", "requiresBlock": false @@ -690,7 +620,6 @@ "args": [ "value" ], - "numArgs": 1, "example": "{{isString 'foo'}} -> true", "description": "

Return true if value is a string.

\n", "requiresBlock": false @@ -699,7 +628,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{lowercase 'Foo BAR baZ'}} -> foo bar baz", "description": "

Lowercase all characters in the given string.

\n", "requiresBlock": false @@ -709,7 +637,6 @@ "str", "substring" ], - "numArgs": 2, "example": "{{occurrences 'foo bar foo bar baz' 'foo'}} -> 2", "description": "

Return the number of occurrences of substring within the given string.

\n", "requiresBlock": false @@ -718,7 +645,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{pascalcase 'foo bar baz'}} -> FooBarBaz", "description": "

PascalCase the characters in string.

\n", "requiresBlock": false @@ -727,7 +653,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{pathcase 'a-b-c d_e'}} -> a/b/c/d/e", "description": "

path/case the characters in string.

\n", "requiresBlock": false @@ -736,7 +661,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{plusify 'foo bar baz'}} -> foo+bar+baz", "description": "

Replace spaces in the given string with pluses.

\n", "requiresBlock": false @@ -746,7 +670,6 @@ "str", "prefix" ], - "numArgs": 2, "example": "{{prepend 'bar' 'foo-'}} -> foo-bar", "description": "

Prepends the given string with the specified prefix.

\n", "requiresBlock": false @@ -756,7 +679,6 @@ "str", "substring" ], - "numArgs": 2, "example": "{{remove 'a b a b a b' 'a '}} -> b b b", "description": "

Remove all occurrences of substring from the given str.

\n", "requiresBlock": false @@ -766,7 +688,6 @@ "str", "substring" ], - "numArgs": 2, "example": "{{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b'", "description": "

Remove the first occurrence of substring from the given str.

\n", "requiresBlock": false @@ -777,7 +698,6 @@ "a", "b" ], - "numArgs": 3, "example": "{{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b", "description": "

Replace all occurrences of substring a with substring b.

\n", "requiresBlock": false @@ -788,7 +708,6 @@ "a", "b" ], - "numArgs": 3, "example": "{{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b", "description": "

Replace the first occurrence of substring a with substring b.

\n", "requiresBlock": false @@ -797,7 +716,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world.", "description": "

Sentence case the given string

\n", "requiresBlock": false @@ -806,7 +724,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{snakecase 'a-b-c d_e'}} -> a_b_c_d_e", "description": "

snake_case the characters in the given string.

\n", "requiresBlock": false @@ -815,7 +732,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{split 'a,b,c'}} -> ['a', 'b', 'c']", "description": "

Split string by the given character.

\n", "requiresBlock": false @@ -826,7 +742,6 @@ "testString", "options" ], - "numArgs": 3, "example": "{{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope", "description": "

Tests whether a string begins with the given prefix.

\n", "requiresBlock": true @@ -835,7 +750,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{titleize 'this is title case' }} -> This Is Title Case", "description": "

Title case the given string.

\n", "requiresBlock": false @@ -844,7 +758,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{trim ' ABC ' }} -> ABC", "description": "

Removes extraneous whitespace from the beginning and end of a string.

\n", "requiresBlock": false @@ -853,7 +766,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{trimLeft ' ABC ' }} -> 'ABC '", "description": "

Removes extraneous whitespace from the beginning of a string.

\n", "requiresBlock": false @@ -862,7 +774,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{trimRight ' ABC ' }} -> ' ABC'", "description": "

Removes extraneous whitespace from the end of a string.

\n", "requiresBlock": false @@ -873,7 +784,6 @@ "limit", "suffix" ], - "numArgs": 3, "example": "{{truncate 'foo bar baz' 7 }} -> foo bar", "description": "

Truncate a string to the specified length. Also see ellipsis.

\n", "requiresBlock": false @@ -884,7 +794,6 @@ "limit", "suffix" ], - "numArgs": 3, "example": "{{truncateWords 'foo bar baz' 1 }} -> foo…", "description": "

Truncate a string to have the specified number of words. Also see truncate.

\n", "requiresBlock": false @@ -893,7 +802,6 @@ "args": [ "string" ], - "numArgs": 1, "example": "{{upcase 'aBcDef'}} -> ABCDEF", "description": "

Uppercase all of the characters in the given string. Alias for uppercase.

\n", "requiresBlock": false @@ -903,7 +811,6 @@ "str", "options" ], - "numArgs": 2, "example": "{{uppercase 'aBcDef'}} -> ABCDEF", "description": "

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

\n", "requiresBlock": false @@ -912,7 +819,6 @@ "args": [ "num" ], - "numArgs": 1, "example": "{{lorem 11}} -> Lorem ipsum", "description": "

Takes a number and returns that many charaters of Lorem Ipsum

\n", "requiresBlock": false @@ -925,7 +831,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no", "description": "

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

\n", "requiresBlock": true @@ -937,7 +842,6 @@ "b", "options" ], - "numArgs": 4, "example": "{{compare 10 '<' 5 }} -> false", "description": "

Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.

\n", "requiresBlock": false @@ -949,7 +853,6 @@ "[startIndex=0]", "options" ], - "numArgs": 4, "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '", "description": "

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

\n", "requiresBlock": true @@ -959,7 +862,6 @@ "value", "defaultValue" ], - "numArgs": 2, "example": "{{default null null 'default'}} -> default", "description": "

Returns the first value that is not undefined, otherwise the 'default' value is returned.

\n", "requiresBlock": false @@ -970,7 +872,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal", "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", "requiresBlock": true @@ -981,7 +882,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than'", "description": "

Block helper that renders a block if a is greater than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", "requiresBlock": true @@ -992,7 +892,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal'", "description": "

Block helper that renders a block if a is greater than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", "requiresBlock": true @@ -1003,7 +902,6 @@ "pattern", "options" ], - "numArgs": 3, "example": "{{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it", "description": "

Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.

\n", "requiresBlock": true @@ -1013,7 +911,6 @@ "val", "options" ], - "numArgs": 2, "example": "{{isFalsey '' }} -> true", "description": "

Returns true if the given value is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", "requiresBlock": false @@ -1023,7 +920,6 @@ "val", "options" ], - "numArgs": 2, "example": "{{isTruthy '12' }} -> true", "description": "

Returns true if the given value is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", "requiresBlock": false @@ -1033,7 +929,6 @@ "number", "options" ], - "numArgs": 2, "example": "{{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even '", "description": "

Return true if the given value is an even number.

\n", "requiresBlock": true @@ -1044,7 +939,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder", "description": "

Conditionally renders a block if the remainder is zero when b operand is divided by a. If an inverse block is specified it will be rendered when the remainder is not zero.

\n", "requiresBlock": true @@ -1054,7 +948,6 @@ "value", "options" ], - "numArgs": 2, "example": "{{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd", "description": "

Block helper that renders a block if value is an odd number. If an inverse block is specified it will be rendered when falsy.

\n", "requiresBlock": true @@ -1065,7 +958,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#is 3 3}} is {{else}} is not {{/is}} -> ' is '", "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.

\n", "requiresBlock": true @@ -1076,7 +968,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is '", "description": "

Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.

\n", "requiresBlock": true @@ -1086,7 +977,6 @@ "context", "options" ], - "numArgs": 2, "example": "{{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than '", "description": "

Block helper that renders a block if a is less than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", "requiresBlock": true @@ -1097,7 +987,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal '", "description": "

Block helper that renders a block if a is less than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", "requiresBlock": true @@ -1108,7 +997,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey", "description": "

Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.

\n", "requiresBlock": true @@ -1118,7 +1006,6 @@ "val", "options" ], - "numArgs": 2, "example": "{{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey", "description": "

Returns true if val is falsey. Works as a block or inline helper.

\n", "requiresBlock": true @@ -1128,7 +1015,6 @@ "arguments", "options" ], - "numArgs": 2, "example": "{{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy '", "description": "

Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.

\n", "requiresBlock": true @@ -1139,7 +1025,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal '", "description": "

Block helper that always renders the inverse block unless a is equal to b.

\n", "requiresBlock": true @@ -1150,7 +1035,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than '", "description": "

Block helper that always renders the inverse block unless a is greater than b.

\n", "requiresBlock": true @@ -1161,7 +1045,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal", "description": "

Block helper that always renders the inverse block unless a is less than b.

\n", "requiresBlock": true @@ -1172,7 +1055,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to", "description": "

Block helper that always renders the inverse block unless a is greater than or equal to b.

\n", "requiresBlock": true @@ -1183,7 +1065,6 @@ "b", "options" ], - "numArgs": 3, "example": "{{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than '", "description": "

Block helper that always renders the inverse block unless a is less than or equal to b.

\n", "requiresBlock": true @@ -1194,7 +1075,6 @@ "args": [ "objects" ], - "numArgs": 1, "description": "

Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

\n", "requiresBlock": false }, @@ -1203,7 +1083,6 @@ "context", "options" ], - "numArgs": 2, "description": "

Block helper that iterates over the properties of an object, exposing each key and value on the context.

\n", "requiresBlock": true }, @@ -1212,7 +1091,6 @@ "obj", "options" ], - "numArgs": 2, "description": "

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

\n", "requiresBlock": true }, @@ -1220,7 +1098,6 @@ "args": [ "prop" ], - "numArgs": 1, "description": "

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

\n", "requiresBlock": false }, @@ -1230,7 +1107,6 @@ "context", "options" ], - "numArgs": 3, "description": "

Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

\n", "requiresBlock": true }, @@ -1239,7 +1115,6 @@ "prop", "context" ], - "numArgs": 2, "description": "

Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

\n", "requiresBlock": false }, @@ -1248,7 +1123,6 @@ "key", "context" ], - "numArgs": 2, "description": "

Return true if key is an own, enumerable property of the given context object.

\n", "requiresBlock": false }, @@ -1256,7 +1130,6 @@ "args": [ "value" ], - "numArgs": 1, "description": "

Return true if value is an object.

\n", "requiresBlock": false }, @@ -1264,7 +1137,6 @@ "args": [ "string" ], - "numArgs": 1, "description": "

Parses the given string using JSON.parse.

\n", "requiresBlock": true }, @@ -1272,7 +1144,6 @@ "args": [ "obj" ], - "numArgs": 1, "description": "

Stringify an object using JSON.stringify.

\n", "requiresBlock": false }, @@ -1281,7 +1152,6 @@ "object", "objects" ], - "numArgs": 2, "description": "

Deeply merge the properties of the given objects with the context object.

\n", "requiresBlock": false }, @@ -1289,7 +1159,6 @@ "args": [ "string" ], - "numArgs": 1, "description": "

Parses the given string using JSON.parse.

\n", "requiresBlock": true }, @@ -1299,7 +1168,6 @@ "context", "options" ], - "numArgs": 3, "description": "

Pick properties from the context object.

\n", "requiresBlock": true }, @@ -1307,7 +1175,6 @@ "args": [ "obj" ], - "numArgs": 1, "description": "

Stringify an object using JSON.stringify.

\n", "requiresBlock": false } @@ -1317,7 +1184,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{toRegex 'foo'}} -> /foo/", "description": "

Convert the given string to a regular expression.

\n", "requiresBlock": false @@ -1326,7 +1192,6 @@ "args": [ "str" ], - "numArgs": 1, "example": "{{test 'foobar' (toRegex 'foo')}} -> true", "description": "

Returns true if the given str matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.

\n", "requiresBlock": false @@ -1335,7 +1200,6 @@ "uuid": { "uuid": { "args": [], - "numArgs": 0, "example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc", "description": "

Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).

\n", "requiresBlock": false @@ -1348,7 +1212,6 @@ "format", "options" ], - "numArgs": 3, "example": "{{date now \"DD-MM-YYYY\" \"America/New_York\" }} -> 21-01-2021", "description": "

Format a date using moment.js date formatting - the timezone is optional and uses the tz database.

\n" }, @@ -1357,7 +1220,6 @@ "time", "durationType" ], - "numArgs": 2, "example": "{{duration 8 \"seconds\"}} -> a few seconds", "description": "

Produce a humanized duration left/until given an amount of time and the type of time measurement.

\n" } From 20c956e0d6ec2c66e50d96443252dbec94b69917 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 13:18:39 +0100 Subject: [PATCH 40/63] Validate blocks --- .../src/components/common/CodeEditor/validator/hbs.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts index c2b3b464da..cb55dfa7eb 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts @@ -45,7 +45,10 @@ export function validateHbsTemplate( ) { const ignoreMissing = options?.ignoreMissing || false nodes.forEach(node => { - if (isMustacheStatement(node) && isPathExpression(node.path)) { + if ( + (isMustacheStatement(node) || isBlockStatement(node)) && + isPathExpression(node.path) + ) { const helperName = node.path.original const from = From 6c3382f2ae17fef71cce2a1f802eed98c774c87c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 13:20:22 +0100 Subject: [PATCH 41/63] Fix body count --- .../components/common/CodeEditor/validator/hbs.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts index cb55dfa7eb..284164a914 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts @@ -80,18 +80,22 @@ export function validateHbsTemplate( return } - const providedParams = node.params + let providedParamsCount = node.params.length + if (isBlockStatement(node)) { + // Block body counts as a parameter + providedParamsCount++ + } - if (providedParams.length !== expectedArguments.length) { + if (providedParamsCount !== expectedArguments.length) { diagnostics.push({ from, to, severity: "error", message: `Helper "${helperName}" expects ${ expectedArguments.length - } parameters (${expectedArguments.join(", ")}), but got ${ - providedParams.length - }.`, + } parameters (${expectedArguments.join( + ", " + )}), but got ${providedParamsCount}.`, }) } } From 56e143625d5b2d30d23d227219e5d861a0509a27 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 13:22:53 +0100 Subject: [PATCH 42/63] Body checks --- .../src/components/common/CodeEditor/validator/hbs.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts index 284164a914..b954bb1e8f 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts @@ -78,6 +78,14 @@ export function validateHbsTemplate( message: `Helper "${helperName}" requires a body:\n{{#${helperName} ...}} [body] {{/${helperName}}}`, }) return + } else if (!requiresBlock && isBlockStatement(node)) { + diagnostics.push({ + from, + to, + severity: "error", + message: `Helper "${helperName}" should not contain a body.`, + }) + return } let providedParamsCount = node.params.length From 33b8751d7817b0f385cd0e9f081aad8177cd7a39 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 27 Feb 2025 12:36:42 +0000 Subject: [PATCH 43/63] Fixing users meta info for groups. --- .../app/[application]/_components/BuilderSidePanel.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 16af731e02..4a7af9342e 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -706,7 +706,7 @@ >
-
+
{group.name}
@@ -935,6 +935,7 @@ color: var(--spectrum-global-color-gray-600); font-size: 12px; white-space: nowrap; + text-align: end; } .auth-entity-access { @@ -970,7 +971,7 @@ width: 100%; } - .auth-entity .user-email { + .auth-entity .user-email, .group-name { flex: 1 1 0; min-width: 0; overflow: hidden; @@ -1073,7 +1074,7 @@ .user-groups { display: flex; flex-direction: row; - justify-content: flex-start; /* or space-between */ + justify-content: flex-start; align-items: center; gap: var(--spacing-m); width: 100%; From 78e558c4aa4baa958062cff08d64038195457529 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 14:16:52 +0100 Subject: [PATCH 44/63] Handle conditional arguments --- .../common/CodeEditor/validator/hbs.ts | 33 +++++++++- .../CodeEditor/validator/tests/hbs.spec.ts | 64 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts index b954bb1e8f..357cb04a86 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts @@ -94,7 +94,15 @@ export function validateHbsTemplate( providedParamsCount++ } - if (providedParamsCount !== expectedArguments.length) { + const optionalArgMatcher = new RegExp(/^\[(.+)\]$/) + const optionalArgs = expectedArguments.filter(a => + optionalArgMatcher.test(a) + ) + + if ( + !optionalArgs.length && + providedParamsCount !== expectedArguments.length + ) { diagnostics.push({ from, to, @@ -105,6 +113,29 @@ export function validateHbsTemplate( ", " )}), but got ${providedParamsCount}.`, }) + } else if (optionalArgs.length) { + const maxArgs = expectedArguments.length + const minArgs = maxArgs - optionalArgs.length + const parameters = expectedArguments + .map(a => { + const test = optionalArgMatcher.exec(a) + if (!test?.[1]) { + return a + } + return `${test[1]} (optional)` + }) + .join(", ") + if ( + minArgs > providedParamsCount || + maxArgs < providedParamsCount + ) { + diagnostics.push({ + from, + to, + severity: "error", + message: `Helper "${helperName}" expects between ${minArgs} to ${expectedArguments.length} parameters (${parameters}), but got ${providedParamsCount}.`, + }) + } } } diff --git a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts index 9484c7a4a5..95ec2e540e 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts @@ -138,5 +138,69 @@ describe("hbs validator", () => { }, ]) }) + + describe("optional parameters", () => { + it("supports empty parameters", () => { + const validators: CodeValidator = { + helperFunction: { + arguments: ["a", "b", "[c]"], + }, + } + const text = "{{ helperFunction 1 99 }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toHaveLength(0) + }) + + it("supports valid parameters", () => { + const validators: CodeValidator = { + helperFunction: { + arguments: ["a", "b", "[c]"], + }, + } + const text = "{{ helperFunction 1 99 'a' }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toHaveLength(0) + }) + + it("returns a valid message on missing parameters", () => { + const validators: CodeValidator = { + helperFunction: { + arguments: ["a", "b", "[c]"], + }, + } + const text = "{{ helperFunction 1 }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "helperFunction" expects between 2 to 3 parameters (a, b, c (optional)), but got 1.`, + severity: "error", + to: 22, + }, + ]) + }) + + it("returns a valid message on too many parameters", () => { + const validators: CodeValidator = { + helperFunction: { + arguments: ["a", "b", "[c]"], + }, + } + const text = "{{ helperFunction 1 2 3 4 }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "helperFunction" expects between 2 to 3 parameters (a, b, c (optional)), but got 4.`, + severity: "error", + to: 28, + }, + ]) + }) + }) }) }) From 7905df5a4a866857445cf8f8c04cbfd8de93a203 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 14:18:38 +0100 Subject: [PATCH 45/63] Date options as optional --- packages/string-templates/scripts/gen-collection-info.ts | 2 +- packages/string-templates/src/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/string-templates/scripts/gen-collection-info.ts b/packages/string-templates/scripts/gen-collection-info.ts index ffe9f68add..f34d54b2e1 100644 --- a/packages/string-templates/scripts/gen-collection-info.ts +++ b/packages/string-templates/scripts/gen-collection-info.ts @@ -33,7 +33,7 @@ const outputJSON: Manifest = {} const ADDED_HELPERS = { date: { date: { - args: ["datetime", "format", "options"], + args: ["datetime", "format", "[options]"], example: '{{date now "DD-MM-YYYY" "America/New_York" }} -> 21-01-2021', description: "Format a date using moment.js date formatting - the timezone is optional and uses the tz database.", diff --git a/packages/string-templates/src/manifest.json b/packages/string-templates/src/manifest.json index e47af7d69a..931700bf1d 100644 --- a/packages/string-templates/src/manifest.json +++ b/packages/string-templates/src/manifest.json @@ -1210,7 +1210,7 @@ "args": [ "datetime", "format", - "options" + "[options]" ], "example": "{{date now \"DD-MM-YYYY\" \"America/New_York\" }} -> 21-01-2021", "description": "

Format a date using moment.js date formatting - the timezone is optional and uses the tz database.

\n" From e8b6a3c90ee45b3d20bf66e09836df38b32b025c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 14:39:13 +0100 Subject: [PATCH 46/63] Validate bodies --- .../CodeEditor/validator/tests/hbs.spec.ts | 136 +++++++++++++----- 1 file changed, 103 insertions(+), 33 deletions(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts index 95ec2e540e..4d303e6e27 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts @@ -98,45 +98,115 @@ describe("hbs validator", () => { }) describe("expressions with parameters", () => { - const validators: CodeValidator = { - helperFunction: { - arguments: ["a", "b", "c"], - }, - } + describe("basic expression", () => { + const validators: CodeValidator = { + helperFunction: { + arguments: ["a", "b", "c"], + }, + } - it("validate valid params", () => { - const text = "{{ helperFunction 1 99 'a' }}" + it("validate valid params", () => { + const text = "{{ helperFunction 1 99 'a' }}" - const result = validateHbsTemplate(text, validators) - expect(result).toHaveLength(0) + const result = validateHbsTemplate(text, validators) + expect(result).toHaveLength(0) + }) + + it("throws on too few params", () => { + const text = "{{ helperFunction 100 }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "helperFunction" expects 3 parameters (a, b, c), but got 1.`, + severity: "error", + to: 24, + }, + ]) + }) + + it("throws on too many params", () => { + const text = "{{ helperFunction 1 99 'a' 100 }}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "helperFunction" expects 3 parameters (a, b, c), but got 4.`, + severity: "error", + to: 34, + }, + ]) + }) }) - it("throws on too few params", () => { - const text = "{{ helperFunction 100 }}" - - const result = validateHbsTemplate(text, validators) - expect(result).toEqual([ - { - from: 0, - message: `Helper "helperFunction" expects 3 parameters (a, b, c), but got 1.`, - severity: "error", - to: 24, + describe("body expressions", () => { + const validators: CodeValidator = { + bodyFunction: { + arguments: ["a", "b", "c"], + requiresBlock: true, }, - ]) - }) - - it("throws on too many params", () => { - const text = "{{ helperFunction 1 99 'a' 100 }}" - - const result = validateHbsTemplate(text, validators) - expect(result).toEqual([ - { - from: 0, - message: `Helper "helperFunction" expects 3 parameters (a, b, c), but got 4.`, - severity: "error", - to: 34, + nonBodyFunction: { + arguments: ["a", "b"], }, - ]) + } + + it("validate valid params", () => { + const text = "{{#bodyFunction 1 99 }}body{{/bodyFunction}}" + + const result = validateHbsTemplate(text, validators) + expect(result).toHaveLength(0) + }) + + it("validate empty bodies", () => { + const text = "{{#bodyFunction 1 99 }}{{/bodyFunction}}" + + const result = validateHbsTemplate(text, validators) + expect(result).toHaveLength(0) + }) + + it("validate too little parameters", () => { + const text = "{{#bodyFunction 1 }}{{/bodyFunction}}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "bodyFunction" expects 3 parameters (a, b, c), but got 2.`, + severity: "error", + to: 37, + }, + ]) + }) + + it("validate too many parameters", () => { + const text = "{{#bodyFunction 1 99 'a' 0 }}{{/bodyFunction}}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "bodyFunction" expects 3 parameters (a, b, c), but got 5.`, + severity: "error", + to: 46, + }, + ]) + }) + + it("validate non-supported body usages", () => { + const text = "{{#nonBodyFunction 1 99}}{{/nonBodyFunction}}" + + const result = validateHbsTemplate(text, validators) + expect(result).toEqual([ + { + from: 0, + message: `Helper "nonBodyFunction" should not contain a body.`, + severity: "error", + to: 45, + }, + ]) + }) }) describe("optional parameters", () => { From af74d3df620e9232f2370057cbe5371dc96956c6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 14:41:37 +0100 Subject: [PATCH 47/63] Add wrong hbs tests --- .../CodeEditor/validator/tests/hbs.spec.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts index 4d303e6e27..5d2cfa06c2 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/tests/hbs.spec.ts @@ -2,7 +2,7 @@ import { validateHbsTemplate } from "../hbs" import { CodeValidator } from "@/types" describe("hbs validator", () => { - it("validate empty strings", () => { + it("validates empty strings", () => { const text = "" const validators = {} @@ -10,7 +10,7 @@ describe("hbs validator", () => { expect(result).toHaveLength(0) }) - it("validate strings without hbs expressions", () => { + it("validates strings without hbs expressions", () => { const text = "first line\nand another one" const validators = {} @@ -23,7 +23,7 @@ describe("hbs validator", () => { fieldName: {}, } - it("validate valid expressions", () => { + it("validates valid expressions", () => { const text = "{{ fieldName }}" const result = validateHbsTemplate(text, validators) @@ -105,7 +105,7 @@ describe("hbs validator", () => { }, } - it("validate valid params", () => { + it("validates valid params", () => { const text = "{{ helperFunction 1 99 'a' }}" const result = validateHbsTemplate(text, validators) @@ -152,21 +152,21 @@ describe("hbs validator", () => { }, } - it("validate valid params", () => { + it("validates valid params", () => { const text = "{{#bodyFunction 1 99 }}body{{/bodyFunction}}" const result = validateHbsTemplate(text, validators) expect(result).toHaveLength(0) }) - it("validate empty bodies", () => { + it("validates empty bodies", () => { const text = "{{#bodyFunction 1 99 }}{{/bodyFunction}}" const result = validateHbsTemplate(text, validators) expect(result).toHaveLength(0) }) - it("validate too little parameters", () => { + it("validates too little parameters", () => { const text = "{{#bodyFunction 1 }}{{/bodyFunction}}" const result = validateHbsTemplate(text, validators) @@ -180,7 +180,7 @@ describe("hbs validator", () => { ]) }) - it("validate too many parameters", () => { + it("validates too many parameters", () => { const text = "{{#bodyFunction 1 99 'a' 0 }}{{/bodyFunction}}" const result = validateHbsTemplate(text, validators) @@ -194,7 +194,7 @@ describe("hbs validator", () => { ]) }) - it("validate non-supported body usages", () => { + it("validates non-supported body usages", () => { const text = "{{#nonBodyFunction 1 99}}{{/nonBodyFunction}}" const result = validateHbsTemplate(text, validators) @@ -273,4 +273,18 @@ describe("hbs validator", () => { }) }) }) + + it("validates wrong hbs code", () => { + const text = "{{#fieldName}}{{/wrong}}" + + const result = validateHbsTemplate(text, {}) + expect(result).toEqual([ + { + from: 0, + message: `The handlebars code is not valid:\nfieldName doesn't match wrong - 1:3`, + severity: "error", + to: text.length, + }, + ]) + }) }) From e4ae1d90b1fffdda1af41044bb9443a1cc937c0d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 27 Feb 2025 14:27:34 +0000 Subject: [PATCH 48/63] Reinstate mocks.email.mock(), it wasn't as unused as I thought. --- packages/worker/src/tests/mocks/email.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/worker/src/tests/mocks/email.ts b/packages/worker/src/tests/mocks/email.ts index d98552e1bc..3fd2962fdd 100644 --- a/packages/worker/src/tests/mocks/email.ts +++ b/packages/worker/src/tests/mocks/email.ts @@ -2,6 +2,20 @@ import MailDev from "maildev" import { promisify } from "util" import TestConfiguration from "../TestConfiguration" +/** + * @deprecated please use the `MailDev` email server instead of this mock. + */ +export function mock() { + // mock the email system + const sendMailMock = jest.fn() + const nodemailer = require("nodemailer") + nodemailer.createTransport.mockReturnValue({ + sendMail: sendMailMock, + verify: jest.fn(), + }) + return sendMailMock +} + export type Mailserver = InstanceType export type MailserverConfig = ConstructorParameters[0] From 304047c922952e1801e5cafe7502ee77feacd665 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 27 Feb 2025 14:42:15 +0000 Subject: [PATCH 49/63] Update yarn.lock. --- yarn.lock | 192 ++++++++++++++---------------------------------------- 1 file changed, 50 insertions(+), 142 deletions(-) diff --git a/yarn.lock b/yarn.lock index 846a149495..279c4067a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1468,7 +1468,7 @@ "@azure/abort-controller" "^2.0.0" tslib "^2.6.2" -"@azure/identity@^4.2.1": +"@azure/identity@4.2.1", "@azure/identity@^4.2.1": version "4.2.1" resolved "https://registry.yarnpkg.com/@azure/identity/-/identity-4.2.1.tgz#22b366201e989b7b41c0e1690e103bd579c31e4c" integrity sha512-U8hsyC9YPcEIzoaObJlRDvp7KiF0MGS7xcWbyJSVvXRkC/HXo1f0oYeBYmEvVgRfacw7GHf6D6yAoh9JHz6A5Q== @@ -2795,6 +2795,28 @@ pouchdb-promise "^6.0.4" through2 "^2.0.0" +"@budibase/pro@npm:@budibase/pro@latest": + version "3.4.20" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.4.20.tgz#0d855d6ed8fe92fd178c74a8963d879cc124b034" + integrity sha512-hUteGvhMOKjBo0fluxcqNs7d4x8OU5W8Oqqrm7eIS9Ohe7ala2iWNCcrj+x+S9CavIm6s7JZZnAewa2Maiz2zQ== + dependencies: + "@anthropic-ai/sdk" "^0.27.3" + "@budibase/backend-core" "*" + "@budibase/shared-core" "*" + "@budibase/string-templates" "*" + "@budibase/types" "*" + "@koa/router" "13.1.0" + bull "4.10.1" + dd-trace "5.26.0" + joi "17.6.0" + jsonwebtoken "9.0.2" + lru-cache "^7.14.1" + memorystream "^0.3.1" + node-fetch "2.6.7" + openai "4.59.0" + scim-patch "^0.8.1" + scim2-parse-filter "^0.2.8" + "@budibase/vm-browserify@^1.1.4": version "1.1.4" resolved "https://registry.yarnpkg.com/@budibase/vm-browserify/-/vm-browserify-1.1.4.tgz#eecb001bd9521cb7647e26fb4d2d29d0a4dce262" @@ -8187,23 +8209,7 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.13.2.tgz#0aa167216965ac9474ccfa83892cfb6b3e1e52ef" integrity sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw== -axios@1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35" - integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA== - dependencies: - follow-redirects "^1.15.0" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - -axios@^0.21.1: - version "0.21.4" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" - integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== - dependencies: - follow-redirects "^1.14.0" - -axios@^1.0.0, axios@^1.1.3, axios@^1.4.0, axios@^1.6.2, axios@^1.6.8: +axios@1.1.3, axios@1.7.7, axios@^0.21.1, axios@^1.0.0, axios@^1.1.3, axios@^1.4.0, axios@^1.6.2, axios@^1.6.8: version "1.7.7" resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== @@ -11985,7 +11991,7 @@ fn.name@1.x.x: resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc" integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw== -follow-redirects@^1.14.0, follow-redirects@^1.15.0, follow-redirects@^1.15.6: +follow-redirects@^1.15.6: version "1.15.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ== @@ -12605,22 +12611,10 @@ global@~4.4.0: min-document "^2.19.0" process "^0.11.10" -globals@^11.1.0: - version "11.12.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" - integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== - -globals@^13.19.0: - version "13.24.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.24.0.tgz#8432a19d78ce0c1e833949c36adb345400bb1171" - integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== - dependencies: - type-fest "^0.20.2" - -globals@^14.0.0: - version "14.0.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-14.0.0.tgz#898d7413c29babcf6bafe56fcadded858ada724e" - integrity sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ== +globals@15.13.0, globals@^11.1.0, globals@^13.19.0, globals@^14.0.0: + version "15.13.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-15.13.0.tgz#bbec719d69aafef188ecd67954aae76a696010fc" + integrity sha512-49TewVEz0UxZjr1WYYsWpPrhyC/B/pA8Bq0fUmet2n+eR7yn0IvNzNaoBwnK6mdkzcN+se7Ez9zUgULTz2QH4g== globalthis@^1.0.1, globalthis@^1.0.4: version "1.0.4" @@ -13037,12 +13031,7 @@ http-assert@^1.3.0: deep-equal "~1.0.1" http-errors "~1.8.0" -http-cache-semantics@3.8.1: - version "3.8.1" - resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz#39b0e16add9b605bf0a9ef3d9daaf4843b4cacd2" - integrity sha512-5ai2iksyV8ZXmnZhHH4rWPoxxistEexSi5936zIQ1bnNTW5VnA85B6P/VpXiRM017IgRvb2kKo1a//y+0wSp3w== - -http-cache-semantics@^4.0.0, http-cache-semantics@^4.1.0, http-cache-semantics@^4.1.1: +http-cache-semantics@3.8.1, http-cache-semantics@4.1.1, http-cache-semantics@^4.0.0, http-cache-semantics@^4.1.0, http-cache-semantics@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a" integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ== @@ -13523,11 +13512,6 @@ is-boolean-object@^1.1.0: call-bind "^1.0.2" has-tostringtag "^1.0.0" -is-buffer@^1.1.5: - version "1.1.6" - resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" - integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== - is-buffer@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191" @@ -13967,6 +13951,11 @@ isobject@^3.0.1: resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" integrity sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg== +isobject@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0" + integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA== + isolated-vm@^4.7.2: version "4.7.2" resolved "https://registry.yarnpkg.com/isolated-vm/-/isolated-vm-4.7.2.tgz#5670d5cce1d92004f9b825bec5b0b11fc7501b65" @@ -14873,14 +14862,7 @@ kill-port@^1.6.1: get-them-args "1.3.2" shell-exec "1.0.2" -kind-of@^3.0.2, kind-of@^3.1.0: - version "3.2.2" - resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" - integrity sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ== - dependencies: - is-buffer "^1.1.5" - -kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3: +kind-of@6.0.3, kind-of@^3.0.2, kind-of@^3.1.0, kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3: version "6.0.3" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== @@ -16314,7 +16296,7 @@ msgpackr-extract@^3.0.2: "@msgpackr-extract/msgpackr-extract-linux-x64" "3.0.2" "@msgpackr-extract/msgpackr-extract-win32-x64" "3.0.2" -msgpackr@^1.5.2: +msgpackr@1.10.1, msgpackr@^1.5.2: version "1.10.1" resolved "https://registry.yarnpkg.com/msgpackr/-/msgpackr-1.10.1.tgz#51953bb4ce4f3494f0c4af3f484f01cfbb306555" integrity sha512-r5VRLv9qouXuLiIBrLpl2d5ZvPt8svdQTl5/vMvE4nzDMyEX4sgW5yWhuBBj5UmgwOTWj8CIdSXn5sAfsHAWIQ== @@ -16512,27 +16494,13 @@ node-domexception@1.0.0: resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== -node-fetch@2.6.7, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7: +node-fetch@2.6.7, node-fetch@2.6.9, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7, node-fetch@^2.6.9: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== dependencies: whatwg-url "^5.0.0" -node-fetch@2.6.9: - version "2.6.9" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.9.tgz#7c7f744b5cc6eb5fd404e0c7a9fec630a55657e6" - integrity sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg== - dependencies: - whatwg-url "^5.0.0" - -node-fetch@^2.6.9: - version "2.7.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" - integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== - dependencies: - whatwg-url "^5.0.0" - node-forge@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" @@ -17581,15 +17549,7 @@ passport-strategy@1.x.x, passport-strategy@^1.0.0: resolved "https://registry.yarnpkg.com/passport-strategy/-/passport-strategy-1.0.0.tgz#b5539aa8fc225a3d1ad179476ddf236b440f52e4" integrity sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA== -passport@^0.4.0: - version "0.4.1" - resolved "https://registry.yarnpkg.com/passport/-/passport-0.4.1.tgz#941446a21cb92fc688d97a0861c38ce9f738f270" - integrity sha512-IxXgZZs8d7uFSt3eqNjM9NQ3g3uQCW5avD8mRNoXV99Yig50vjuaez6dQK2qC0kVWPRTujxY0dWgGfT09adjYg== - dependencies: - passport-strategy "1.x.x" - pause "0.0.1" - -passport@^0.6.0: +passport@0.6.0, passport@^0.4.0, passport@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/passport/-/passport-0.6.0.tgz#e869579fab465b5c0b291e841e6cc95c005fac9d" integrity sha512-0fe+p3ZnrWRW74fe8+SvCyf4a3Pb2/h7gFkQ8yTJpAO50gDzlfjZUZTO1k5Eg9kUct22OxHLqDZoKUWRHOh9ug== @@ -18582,13 +18542,6 @@ pseudomap@^1.0.2: resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" integrity sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ== -psl@^1.1.28: - version "1.15.0" - resolved "https://registry.yarnpkg.com/psl/-/psl-1.15.0.tgz#bdace31896f1d97cec6a79e8224898ce93d974c6" - integrity sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w== - dependencies: - punycode "^2.3.1" - psl@^1.1.33: version "1.9.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" @@ -19473,11 +19426,6 @@ sax@1.2.1: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a" integrity sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA== -sax@>=0.1.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f" - integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg== - sax@>=0.6.0: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -19550,28 +19498,13 @@ semver-diff@^3.1.1: dependencies: semver "^6.3.0" -"semver@2 || 3 || 4 || 5", semver@^5.6.0, semver@^5.7.1: - version "5.7.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" - integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== - -semver@7.5.3, semver@^7.0.0, semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3: +"semver@2 || 3 || 4 || 5", semver@7.5.3, semver@^5.6.0, semver@^5.7.1, semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0, semver@^6.3.1, semver@^7.0.0, semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.2: version "7.5.3" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e" integrity sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ== dependencies: lru-cache "^6.0.0" -semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0, semver@^6.3.1: - version "6.3.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" - integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== - -semver@^7.5.4, semver@^7.6.0, semver@^7.6.2: - version "7.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.1.tgz#abd5098d82b18c6c81f6074ff2647fd3e7220c9f" - integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== - send@0.19.0: version "0.19.0" resolved "https://registry.yarnpkg.com/send/-/send-0.19.0.tgz#bbc5a388c8ea6c048967049dbeac0e4a3f09d7f8" @@ -21092,7 +21025,7 @@ touch@^3.1.0: dependencies: nopt "~1.0.10" -"tough-cookie@^2.3.3 || ^3.0.1 || ^4.0.0", tough-cookie@^4.0.0, tough-cookie@^4.1.2: +tough-cookie@4.1.3, "tough-cookie@^2.3.3 || ^3.0.1 || ^4.0.0", tough-cookie@^4.0.0, tough-cookie@^4.1.2, tough-cookie@^4.1.4, tough-cookie@~2.5.0: version "4.1.3" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.3.tgz#97b9adb0728b42280aa3d814b6b999b2ff0318bf" integrity sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw== @@ -21102,24 +21035,6 @@ touch@^3.1.0: universalify "^0.2.0" url-parse "^1.5.3" -tough-cookie@^4.1.4: - version "4.1.4" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.4.tgz#945f1461b45b5a8c76821c33ea49c3ac192c1b36" - integrity sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag== - dependencies: - psl "^1.1.33" - punycode "^2.1.1" - universalify "^0.2.0" - url-parse "^1.5.3" - -tough-cookie@~2.5.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" - integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g== - dependencies: - psl "^1.1.28" - punycode "^2.1.1" - tr46@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240" @@ -21594,6 +21509,14 @@ unpipe@1.0.0, unpipe@~1.0.0: resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ== +unset-value@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-2.0.1.tgz#57bed0c22d26f28d69acde5df9a11b77c74d2df3" + integrity sha512-2hvrBfjUE00PkqN+q0XP6yRAOGrR06uSiUoIQGZkc7GxvQ9H7v8quUPNtZjMg4uux69i8HWpIjLPUKwCuRGyNg== + dependencies: + has-value "^2.0.2" + isobject "^4.0.0" + untildify@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b" @@ -22347,14 +22270,7 @@ xml-parse-from-string@^1.0.0: resolved "https://registry.yarnpkg.com/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz#a9029e929d3dbcded169f3c6e28238d95a5d5a28" integrity sha512-ErcKwJTF54uRzzNMXq2X5sMIy88zJvfN2DmdoQvy7PAFJ+tPRU6ydWuOKNMyfmOjdyBQTFREi60s0Y0SyI0G0g== -xml2js@0.1.x: - version "0.1.14" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.1.14.tgz#5274e67f5a64c5f92974cd85139e0332adc6b90c" - integrity sha512-pbdws4PPPNc1HPluSUKamY4GWMk592K7qwcj6BExbVOhhubub8+pMda/ql68b6L3luZs/OGjGSB5goV7SnmgnA== - dependencies: - sax ">=0.1.1" - -xml2js@0.6.2: +xml2js@0.1.x, xml2js@0.6.2, xml2js@^0.5.0: version "0.6.2" resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499" integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA== @@ -22362,14 +22278,6 @@ xml2js@0.6.2: sax ">=0.6.0" xmlbuilder "~11.0.0" -xml2js@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.5.0.tgz#d9440631fbb2ed800203fad106f2724f62c493b7" - integrity sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA== - dependencies: - sax ">=0.6.0" - xmlbuilder "~11.0.0" - xmlbuilder@~11.0.0: version "11.0.1" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" From 6499f7a2706269075e9a4eda6ad32f8c8ed9f55a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 17:11:47 +0100 Subject: [PATCH 50/63] Support empty {{ date }} --- packages/string-templates/scripts/gen-collection-info.ts | 2 +- packages/string-templates/src/helpers/date.ts | 6 ++++-- packages/string-templates/src/manifest.json | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/string-templates/scripts/gen-collection-info.ts b/packages/string-templates/scripts/gen-collection-info.ts index f34d54b2e1..d231908a05 100644 --- a/packages/string-templates/scripts/gen-collection-info.ts +++ b/packages/string-templates/scripts/gen-collection-info.ts @@ -33,7 +33,7 @@ const outputJSON: Manifest = {} const ADDED_HELPERS = { date: { date: { - args: ["datetime", "format", "[options]"], + args: ["[datetime]", "[format]", "[options]"], example: '{{date now "DD-MM-YYYY" "America/New_York" }} -> 21-01-2021', description: "Format a date using moment.js date formatting - the timezone is optional and uses the tz database.", diff --git a/packages/string-templates/src/helpers/date.ts b/packages/string-templates/src/helpers/date.ts index 589cb3d978..8b52fb61e2 100644 --- a/packages/string-templates/src/helpers/date.ts +++ b/packages/string-templates/src/helpers/date.ts @@ -71,7 +71,7 @@ function getContext(thisArg: any, locals: any, options: any) { function initialConfig(str: any, pattern: any, options?: any) { if (isOptions(pattern)) { options = pattern - pattern = null + pattern = DEFAULT_FORMAT } if (isOptions(str)) { @@ -93,13 +93,15 @@ function setLocale(this: any, str: any, pattern: any, options?: any) { dayjs.locale(opts.lang || opts.language) } +const DEFAULT_FORMAT = "MMMM DD, YYYY" + export const date = (str: any, pattern: any, options: any) => { const config = initialConfig(str, pattern, options) // if no args are passed, return a formatted date if (config.str == null && config.pattern == null) { dayjs.locale("en") - return dayjs().format("MMMM DD, YYYY") + return dayjs().format(DEFAULT_FORMAT) } setLocale(config.str, config.pattern, config.options) diff --git a/packages/string-templates/src/manifest.json b/packages/string-templates/src/manifest.json index 931700bf1d..e399dbff94 100644 --- a/packages/string-templates/src/manifest.json +++ b/packages/string-templates/src/manifest.json @@ -1208,8 +1208,8 @@ "date": { "date": { "args": [ - "datetime", - "format", + "[datetime]", + "[format]", "[options]" ], "example": "{{date now \"DD-MM-YYYY\" \"America/New_York\" }} -> 21-01-2021", From aa2537c4b2af903e0193c17e3551802622b2ed40 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 17:15:58 +0100 Subject: [PATCH 51/63] Clean --- .../common/CodeEditor/validator/hbs.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts index 357cb04a86..1fca3967fc 100644 --- a/packages/builder/src/components/common/CodeEditor/validator/hbs.ts +++ b/packages/builder/src/components/common/CodeEditor/validator/hbs.ts @@ -116,19 +116,19 @@ export function validateHbsTemplate( } else if (optionalArgs.length) { const maxArgs = expectedArguments.length const minArgs = maxArgs - optionalArgs.length - const parameters = expectedArguments - .map(a => { - const test = optionalArgMatcher.exec(a) - if (!test?.[1]) { - return a - } - return `${test[1]} (optional)` - }) - .join(", ") if ( minArgs > providedParamsCount || maxArgs < providedParamsCount ) { + const parameters = expectedArguments + .map(a => { + const test = optionalArgMatcher.exec(a) + if (!test?.[1]) { + return a + } + return `${test[1]} (optional)` + }) + .join(", ") diagnostics.push({ from, to, From cca955da06530277b4ecc55a5e390a3dfa0ae2ab Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 27 Feb 2025 17:27:59 +0100 Subject: [PATCH 52/63] Fixing whitespaces on formulas --- .../src/components/backend/DataTable/formula.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/formula.js b/packages/builder/src/components/backend/DataTable/formula.js index 9ec75b52c0..c0fdb96a07 100644 --- a/packages/builder/src/components/backend/DataTable/formula.js +++ b/packages/builder/src/components/backend/DataTable/formula.js @@ -26,7 +26,7 @@ export function getBindings({ if (!table) { return bindings } - for (let [column, schema] of Object.entries(table.schema)) { + for (const [column, schema] of Object.entries(table.schema)) { const isRelationship = schema.type === FieldType.LINK // skip relationships after a certain depth and types which // can't bind to @@ -62,6 +62,12 @@ export function getBindings({ const label = path == null ? column : `${path}.0.${column}` const binding = path == null ? `[${column}]` : `[${path}].0.[${column}]` + + let readableBinding = label + if (readableBinding.includes(" ")) { + readableBinding = `[${readableBinding}]` + } + // only supply a description for relationship paths const description = path == null @@ -75,7 +81,7 @@ export function getBindings({ description, // don't include path, it messes things up, relationship path // will be replaced by the main array binding - readableBinding: label, + readableBinding, runtimeBinding: binding, display: { name: label, From 6b67eaf9a3c6d1e9f8aa1cf083ba7f32bb79350f Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Thu, 27 Feb 2025 17:07:44 +0000 Subject: [PATCH 53/63] Bump version to 3.4.21 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index b391c8e05c..8972a00565 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "3.4.20", + "version": "3.4.21", "npmClient": "yarn", "concurrency": 20, "command": { From 4f697b7731a3e3eca298a69196383bd4f256e987 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 27 Feb 2025 17:12:20 +0000 Subject: [PATCH 54/63] Adding groups to user app list. --- .../_components/BuilderSidePanel.svelte | 3 +- .../portal/users/users/[userId].svelte | 40 ++++++++++++------- .../_components/AppRoleTableRenderer.svelte | 4 +- packages/frontend-core/src/constants.ts | 1 + 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 4a7af9342e..59d14770ae 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -971,7 +971,8 @@ width: 100%; } - .auth-entity .user-email, .group-name { + .auth-entity .user-email, + .group-name { flex: 1 1 0; min-width: 0; overflow: hidden; diff --git a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte index 6c480d9ef8..f02c2fe058 100644 --- a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte @@ -98,7 +98,9 @@ $: privileged = sdk.users.isAdminOrGlobalBuilder(user) $: nameLabel = getNameLabel(user) $: filteredGroups = getFilteredGroups(internalGroups, searchTerm) - $: availableApps = getAvailableApps($appsStore.apps, privileged, user?.roles) + $: availableApps = user + ? getApps(user, sdk.users.userAppAccessList(user, $groups || [])) + : [] $: userGroups = $groups.filter(x => { return x.users?.find(y => { return y._id === userId @@ -107,23 +109,19 @@ $: globalRole = users.getUserRole(user) $: isTenantOwner = tenantOwner?.email && tenantOwner.email === user?.email - const getAvailableApps = (appList, privileged, roles) => { - let availableApps = appList.slice() - if (!privileged) { - availableApps = availableApps.filter(x => { - let roleKeys = Object.keys(roles || {}) - return roleKeys.concat(user?.builder?.apps).find(y => { - return x.appId === appsStore.extractAppId(y) - }) - }) - } + const getApps = (user, appIds) => { + let availableApps = $appsStore.apps + .slice() + .filter(app => + appIds.find(id => id === appsStore.getProdAppID(app.devId)) + ) return availableApps.map(app => { const prodAppId = appsStore.getProdAppID(app.devId) return { name: app.name, devId: app.devId, icon: app.icon, - role: getRole(prodAppId, roles), + role: getRole(prodAppId, user), } }) } @@ -136,7 +134,7 @@ return groups.filter(group => group.name?.toLowerCase().includes(search)) } - const getRole = (prodAppId, roles) => { + const getRole = (prodAppId, user) => { if (privileged) { return Constants.Roles.ADMIN } @@ -145,7 +143,21 @@ return Constants.Roles.CREATOR } - return roles[prodAppId] + if (user?.roles[prodAppId]) { + return user.roles[prodAppId] + } + + // check if access via group for creator + const foundGroup = $groups?.find( + group => group.roles[prodAppId] || group.builder?.apps[prodAppId] + ) + if (foundGroup.builder?.apps[prodAppId]) { + return Constants.Roles.CREATOR + } + // can't tell how groups will control role + if (foundGroup.roles[prodAppId]) { + return Constants.Roles.GROUP + } } const getNameLabel = user => { diff --git a/packages/builder/src/pages/builder/portal/users/users/_components/AppRoleTableRenderer.svelte b/packages/builder/src/pages/builder/portal/users/users/_components/AppRoleTableRenderer.svelte index 9429cfbc23..5adc38ebc6 100644 --- a/packages/builder/src/pages/builder/portal/users/users/_components/AppRoleTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/_components/AppRoleTableRenderer.svelte @@ -15,7 +15,9 @@ } -{#if value === Constants.Roles.CREATOR} +{#if value === Constants.Roles.GROUP} + Controlled by group +{:else if value === Constants.Roles.CREATOR} Can edit {:else} Date: Fri, 28 Feb 2025 10:12:58 +0100 Subject: [PATCH 55/63] Handle whitespaces on complex keys --- packages/builder/src/dataBinding.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/dataBinding.js b/packages/builder/src/dataBinding.js index 80bcd1984a..1b4c69be71 100644 --- a/packages/builder/src/dataBinding.js +++ b/packages/builder/src/dataBinding.js @@ -373,6 +373,18 @@ const getContextBindings = (asset, componentId) => { .flat() } +const makeReadableKeyPropSafe = key => { + if (!key.includes(" ")) { + return key + } + + if (new RegExp(/^\[(.+)\]$/).test(key.test)) { + return key + } + + return `[${key}]` +} + /** * Generates a set of bindings for a given component context */ @@ -457,15 +469,11 @@ const generateComponentContextBindings = (asset, componentContext) => { const runtimeBinding = `${safeComponentId}.${safeKey}` // Optionally use a prefix with readable bindings - let readableBinding = component._instanceName + let readableBinding = makeReadableKeyPropSafe(component._instanceName) if (readablePrefix) { readableBinding += `.${readablePrefix}` } - readableBinding += `.${fieldSchema.name || key}` - - if (readableBinding.includes(" ")) { - readableBinding = `[${readableBinding}]` - } + readableBinding += `.${makeReadableKeyPropSafe(fieldSchema.name || key)}` // Determine which category this binding belongs in const bindingCategory = getComponentBindingCategory( @@ -477,7 +485,7 @@ const generateComponentContextBindings = (asset, componentContext) => { bindings.push({ type: "context", runtimeBinding, - readableBinding: `${readableBinding}`, + readableBinding, // Field schema and provider are required to construct relationship // datasource options, based on bindable properties fieldSchema, @@ -1358,13 +1366,14 @@ const bindingReplacement = ( } // work from longest to shortest const convertFromProps = bindableProperties + // TODO check whitespaces .map(el => el[convertFrom]) .sort((a, b) => { return b.length - a.length }) const boundValues = textWithBindings.match(regex) || [] let result = textWithBindings - for (let boundValue of boundValues) { + for (const boundValue of boundValues) { let newBoundValue = boundValue // we use a search string, where any time we replace something we blank it out // in the search, working from longest to shortest so always use best match first From d7702810c2236fa5a69915d1ef4d2fc3771f8618 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 28 Feb 2025 10:27:36 +0100 Subject: [PATCH 56/63] Handle whitespaces on complex keys in formulas --- .../builder/src/components/backend/DataTable/formula.js | 9 ++++----- packages/builder/src/dataBinding.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/formula.js b/packages/builder/src/components/backend/DataTable/formula.js index c0fdb96a07..8dcda83c27 100644 --- a/packages/builder/src/components/backend/DataTable/formula.js +++ b/packages/builder/src/components/backend/DataTable/formula.js @@ -2,6 +2,7 @@ import { FieldType } from "@budibase/types" import { FIELDS } from "@/constants/backend" import { tables } from "@/stores/builder" import { get as svelteGet } from "svelte/store" +import { makeReadableKeyPropSafe } from "@/dataBinding" // currently supported level of relationship depth (server side) const MAX_DEPTH = 1 @@ -62,11 +63,9 @@ export function getBindings({ const label = path == null ? column : `${path}.0.${column}` const binding = path == null ? `[${column}]` : `[${path}].0.[${column}]` - - let readableBinding = label - if (readableBinding.includes(" ")) { - readableBinding = `[${readableBinding}]` - } + const readableBinding = (path == null ? [column] : [path, "0", column]) + .map(makeReadableKeyPropSafe) + .join(".") // only supply a description for relationship paths const description = diff --git a/packages/builder/src/dataBinding.js b/packages/builder/src/dataBinding.js index 1b4c69be71..c6171c72a4 100644 --- a/packages/builder/src/dataBinding.js +++ b/packages/builder/src/dataBinding.js @@ -373,7 +373,7 @@ const getContextBindings = (asset, componentId) => { .flat() } -const makeReadableKeyPropSafe = key => { +export const makeReadableKeyPropSafe = key => { if (!key.includes(" ")) { return key } From 48dafb42bc7cebcd791a803311c5980075de7dde Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 28 Feb 2025 10:47:31 +0100 Subject: [PATCH 57/63] Update md --- docs/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 311afbe706..ed2d94aacd 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -108,7 +108,7 @@ You can install them following any of the steps described below: - Installation steps: https://asdf-vm.com/guide/getting-started.html - asdf plugin add nodejs - asdf plugin add python - - npm install -g yarn + - asdf plugin add yarn ### Using NVM and pyenv From 5cd5a201772b18863176d53d558ee44452be482d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 15:01:34 +0000 Subject: [PATCH 58/63] Fixing an issue switching back to controlled by group. --- .../_components/BuilderSidePanel.svelte | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 59d14770ae..737edd69f7 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -198,12 +198,19 @@ return } const update = await users.get(user._id) + const newRoles = { + ...update.roles, + [prodAppId]: role, + } + // make sure no undefined/null roles (during removal) + for (let [appId, role] of Object.entries(newRoles)) { + if (!role) { + delete newRoles[appId] + } + } await users.save({ ...update, - roles: { - ...update.roles, - [prodAppId]: role, - }, + roles: newRoles, }) await searchUsers(query, $builderStore.builderSidePanel, loaded) } From 67d31b971a69e3d664606c36672c2758f51df7ab Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 16:56:31 +0000 Subject: [PATCH 59/63] Updating master reference. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index e3843dd4ea..b28dbd5492 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit e3843dd4eaced68ae063355b77df200dbc789c98 +Subproject commit b28dbd549284cf450be7f25ad85aadf614d08f0b From ebfd8eb6c8a75e682ead8fd94d1079e11bd27c1f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 17:14:19 +0000 Subject: [PATCH 60/63] Fixing readme action. --- .github/workflows/readme-openapi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/readme-openapi.yml b/.github/workflows/readme-openapi.yml index 9f42f6141b..e6224156b6 100644 --- a/.github/workflows/readme-openapi.yml +++ b/.github/workflows/readme-openapi.yml @@ -20,7 +20,7 @@ jobs: - run: yarn --frozen-lockfile - name: Install OpenAPI pkg - run: yarn global add openapi + run: yarn global add rdme openapi - name: update specs - run: cd packages/server && yarn specs && openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841 + run: cd packages/server && yarn specs && rdme openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841 From 415570b802b3eea7aa9e4d2b5a5d0b135d70eb17 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 17:21:57 +0000 Subject: [PATCH 61/63] Another readme action fix. --- .github/workflows/readme-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/readme-openapi.yml b/.github/workflows/readme-openapi.yml index e6224156b6..f7a563fc45 100644 --- a/.github/workflows/readme-openapi.yml +++ b/.github/workflows/readme-openapi.yml @@ -23,4 +23,4 @@ jobs: run: yarn global add rdme openapi - name: update specs - run: cd packages/server && yarn specs && rdme openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841 + run: cd packages/server && yarn specs && rdme openapi upload specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841 From 4077a6df35c319bfdab9962ea7c2101388e7702c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 17:48:23 +0000 Subject: [PATCH 62/63] Final fix for rdme. --- .github/workflows/readme-openapi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/readme-openapi.yml b/.github/workflows/readme-openapi.yml index f7a563fc45..ec04e4001c 100644 --- a/.github/workflows/readme-openapi.yml +++ b/.github/workflows/readme-openapi.yml @@ -20,7 +20,7 @@ jobs: - run: yarn --frozen-lockfile - name: Install OpenAPI pkg - run: yarn global add rdme openapi + run: yarn global add rdme - name: update specs - run: cd packages/server && yarn specs && rdme openapi upload specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=6728a74f5918b50036c61841 + run: cd packages/server && yarn specs && rdme openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=67c16880add6da002352069a From b4ad744261a9cb47fcadf8e25af57909311900ee Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 28 Feb 2025 17:52:18 +0000 Subject: [PATCH 63/63] Set rdme cli version (hardcoded). --- .github/workflows/readme-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/readme-openapi.yml b/.github/workflows/readme-openapi.yml index ec04e4001c..27a68e69cf 100644 --- a/.github/workflows/readme-openapi.yml +++ b/.github/workflows/readme-openapi.yml @@ -20,7 +20,7 @@ jobs: - run: yarn --frozen-lockfile - name: Install OpenAPI pkg - run: yarn global add rdme + run: yarn global add rdme@8.6.6 - name: update specs run: cd packages/server && yarn specs && rdme openapi specs/openapi.yaml --key=${{ secrets.README_API_KEY }} --id=67c16880add6da002352069a