From 507c6fb4870a406b3cb6fa1d0944a1f11203aba4 Mon Sep 17 00:00:00 2001 From: Demetrio Marino Date: Wed, 26 Jul 2023 11:10:30 +0200 Subject: [PATCH 1/4] feat: importData --- src/events/bk/index.ts | 1 + src/utils/http-client.ts | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/events/bk/index.ts b/src/events/bk/index.ts index 5ab53f9..008f19a 100644 --- a/src/events/bk/index.ts +++ b/src/events/bk/index.ts @@ -23,6 +23,7 @@ export * from './fetchedFiles' export * from './fetchFiles' export * from './filter' export * from './formSubmit' +export * from './importData' export * from './initPlugin' export * from './httpDelete' export * from './layoutChange' diff --git a/src/utils/http-client.ts b/src/utils/http-client.ts index 0cf01a8..5df3559 100644 --- a/src/utils/http-client.ts +++ b/src/utils/http-client.ts @@ -25,6 +25,10 @@ type PostMultipartHandler = (url: string, data: FormData, config?: HttpClientConfig) => Promise> +type PatchMultipartHandler = + (url: string, data: FormData, config?: HttpClientConfig) => + Promise> + export type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' export interface HttpClientSupport extends Element { @@ -45,6 +49,7 @@ export type HttpClientInstance = { patch: WithBodyHandler delete: WithBodyHandler postMultipart: PostMultipartHandler + patchMultipart: PatchMultipartHandler fetch: FetchHandler } @@ -217,26 +222,45 @@ const withBody = (method: 'POST' | 'DELETE' | 'PUT' | 'PATCH') => } } -async function postMultipart ( +async function postMultipart( + this: HttpClientSupport, + path: string, + data: FormData, + config?: HttpClientConfig +): Promise> { + return await executeMultipart(this, 'POST', path, data, config) +} + +async function patchMultipart( this: HttpClientSupport, path: string, data: FormData, config?: HttpClientConfig +): Promise> { + return await executeMultipart(this, 'PATCH', path, data, config) +} + +async function executeMultipart ( + httpClient: HttpClientSupport, + method: 'POST' | 'PATCH', + path: string, + data: FormData, + config?: HttpClientConfig ): Promise> { try { - const {proxyWindow = window} = this + const {proxyWindow = window} = httpClient const [url, { outputTransform, ...fetchConfig - }] = initParams(path, this.basePath, config) + }] = initParams(path, httpClient.basePath, config) const fetchPromise = proxyWindow.fetch(url.toString(), { ...fetchConfig, - method: 'POST', + method, body: data, headers: { - ...this.headers ?? {}, ...fetchConfig.headers ?? {} + ...httpClient.headers ?? {}, ...fetchConfig.headers ?? {} }, - credentials: fetchConfig.credentials ?? this.credentials, + credentials: fetchConfig.credentials ?? httpClient.credentials, }) if (fetchConfig.raw) { @@ -285,6 +309,7 @@ export function createFetchHttpClient (this: HttpClientSupport): HttpClientInsta put: withBody('PUT').bind(this), patch: withBody('PATCH').bind(this), postMultipart: postMultipart.bind(this), + patchMultipart: patchMultipart.bind(this), fetch: _fetch.bind(this) } } From 0bd6f23eec1c77982897da054d37a80b9d8a6123 Mon Sep 17 00:00:00 2001 From: Demetrio Marino Date: Wed, 26 Jul 2023 12:44:50 +0200 Subject: [PATCH 2/4] feat: importData --- src/events/bk/importData.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/events/bk/importData.ts diff --git a/src/events/bk/importData.ts b/src/events/bk/importData.ts new file mode 100644 index 0000000..523edb4 --- /dev/null +++ b/src/events/bk/importData.ts @@ -0,0 +1,12 @@ +import {factory, Payload} from '../factory' + +export type ImportDataPayload = Payload + +/** + * @registeredEvent + * @title Import Data + * @description raised when the import button is clicked + * @payload { + * } + */ +export const importData = factory('import-data') From b0dad6cf4468744584205f6cc86e9c8fd7ff6acd Mon Sep 17 00:00:00 2001 From: Demetrio Marino Date: Wed, 26 Jul 2023 15:58:55 +0200 Subject: [PATCH 3/4] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b559d76..1ea2399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- new event `import-data` is available + ## [1.0.10] - 2023-06-22 - new events `fetch-files`, `fetched-files` are available From 6f19d1155a8cf63d0b55eeeb918018f1629edd9e Mon Sep 17 00:00:00 2001 From: Demetrio Marino Date: Wed, 26 Jul 2023 15:59:16 +0200 Subject: [PATCH 4/4] docs: updated readme with patchMultipart --- base/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/base/README.md b/base/README.md index 9ab3930..78b6731 100644 --- a/base/README.md +++ b/base/README.md @@ -281,6 +281,7 @@ export declare type HttpClientInstance = { put: PostHandler delete: PostHandler postMultipart: PostMultipartHandler + patchMultipart: PatchMultipartHandler, fetch: FetchHandler }