From 1518f04ea7007435e15565bd189becde211f1c81 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Mon, 14 Jul 2025 17:13:35 +0100 Subject: [PATCH 1/3] chore: add show branding flag --- README.md | 2 ++ src/filePicker.ts | 4 ++++ src/specs/url.spec.ts | 14 ++++++++++++++ src/types.ts | 1 + src/utils/url.ts | 2 ++ 5 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 0cd31a2..735b3a1 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ const options = { containerId = 'file-picker-container', baseUrl = 'https://app.stackone.com', fields = ['name', 'path', 'driveId'], + showBranding = false, onFilesPicked = (files) => { console.log('Selected files:', files); }, @@ -80,6 +81,7 @@ const filePicker = new FilePicker(options); | **containerId** | string | No | ID of the container element where the file picker will be mounted. | | **baseUrl** | string | No | Which API instance should it connect to. | | **fields** | string[] | No | Which fields from the raw picked file will be mapped on the files picked callback. | +| **showBranding** | string | No | Show StackOne footer on the file picker, it is defaulted to true. | | **onFilesPicked** | function | No | Called when files are selected. | | **onOpen()** | function | No | Called when the file picker is opened. | | **onClose()** | function | No | Called every time the file picker is closed regardless of whether a file has been picked or not. | diff --git a/src/filePicker.ts b/src/filePicker.ts index 3637bfd..2e3d729 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -9,6 +9,7 @@ export class FilePicker { #apiUrl: string; #iframe: HTMLIFrameElement | null = null; #isListenerAttached = false; + #showBranding = true; #fields?: string[]; #onFilesPicked: (data: File[]) => void; #onClose: () => void; @@ -23,6 +24,7 @@ export class FilePicker { baseUrl, apiUrl, fields, + showBranding, onFilesPicked, onClose, onOpen, @@ -34,6 +36,7 @@ export class FilePicker { this.#fields = fields; this.#baseUrl = baseUrl ?? 'https://app.stackone.com'; this.#apiUrl = apiUrl ?? 'https://api.stackone.com'; + this.#showBranding = showBranding ?? true; this.#onFilesPicked = onFilesPicked ?? (() => {}); this.#onClose = onClose ?? (() => {}); this.#onOpen = onOpen ?? (() => {}); @@ -71,6 +74,7 @@ export class FilePicker { window.origin, this.#fields, this.#apiUrl, + this.#showBranding, ); this.#iframe.src = url; } diff --git a/src/specs/url.spec.ts b/src/specs/url.spec.ts index 21f17ee..073ae43 100644 --- a/src/specs/url.spec.ts +++ b/src/specs/url.spec.ts @@ -44,5 +44,19 @@ describe('#url', () => { expect(parsedUrl.searchParams.has('fields')).toBe(false); }); }); + + describe('when showBranding is false', () => { + it('creates URL without showBranding parameter', () => { + const baseUrl = 'https://example.com'; + const sessionToken = 'test-token'; + const origin = 'https://myapp.com'; + const showBranding = false; + + const url = createUrl(baseUrl, sessionToken, origin, undefined, undefined, showBranding); + const parsedUrl = new URL(url); + + expect(parsedUrl.searchParams.get('showBranding')).toBe('false'); + }); + }); }); }); diff --git a/src/types.ts b/src/types.ts index 6bf717c..94da561 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,6 +11,7 @@ export interface FilePickerOptions { baseUrl?: string; apiUrl?: string; fields?: string[]; + showBranding?: boolean; onFilesPicked?: (data: File[]) => void; onError?: (error: Error) => void; onClose?: () => void; diff --git a/src/utils/url.ts b/src/utils/url.ts index bfaa1f5..d507059 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -4,10 +4,12 @@ export const createUrl = ( origin: string, fields?: string[], apiUrl?: string, + showBranding?: boolean, ) => { const url = new URL(baseUrl); url.searchParams.set('token', sessionToken); url.searchParams.set('origin', btoa(origin)); + url.searchParams.set('showBranding', showBranding ? 'true' : 'false'); if (fields) { url.searchParams.set('fields', btoa(JSON.stringify(fields))); From f6b02d5eb446b2b179ac81993373973cf6875e3e Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Mon, 14 Jul 2025 17:24:44 +0100 Subject: [PATCH 2/3] chore: lint --- src/specs/url.spec.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/specs/url.spec.ts b/src/specs/url.spec.ts index 073ae43..13eb9b8 100644 --- a/src/specs/url.spec.ts +++ b/src/specs/url.spec.ts @@ -52,7 +52,14 @@ describe('#url', () => { const origin = 'https://myapp.com'; const showBranding = false; - const url = createUrl(baseUrl, sessionToken, origin, undefined, undefined, showBranding); + const url = createUrl( + baseUrl, + sessionToken, + origin, + undefined, + undefined, + showBranding, + ); const parsedUrl = new URL(url); expect(parsedUrl.searchParams.get('showBranding')).toBe('false'); From c76f95d6bd27b3a022a8f5a0c33671f0828c5c2c Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Tue, 15 Jul 2025 15:42:26 +0100 Subject: [PATCH 3/3] fix: showBranding type --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 735b3a1..9017f8f 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ const filePicker = new FilePicker(options); | **containerId** | string | No | ID of the container element where the file picker will be mounted. | | **baseUrl** | string | No | Which API instance should it connect to. | | **fields** | string[] | No | Which fields from the raw picked file will be mapped on the files picked callback. | -| **showBranding** | string | No | Show StackOne footer on the file picker, it is defaulted to true. | +| **showBranding** | boolean | No | Show StackOne footer on the file picker, it is defaulted to true. | | **onFilesPicked** | function | No | Called when files are selected. | | **onOpen()** | function | No | Called when the file picker is opened. | | **onClose()** | function | No | Called every time the file picker is closed regardless of whether a file has been picked or not. |