From 6d569627e12b2fbbc7b3a452f99a1e8023d969c5 Mon Sep 17 00:00:00 2001 From: Alex Rock Date: Thu, 11 Apr 2024 15:13:12 -0600 Subject: [PATCH] feat: fix build bug, remove environmentId requirement and stop deleting spaces --- package-lock.json | 120 ++++++++++++++++++ .../space/space-frame/spaceFrame.component.ts | 2 +- .../spaces/src/utils/createSimpleListener.ts | 24 ++-- .../spaces/src/utils/useInitializeSpace.ts | 4 - packages/angular/src/app/app.component.ts | 4 +- 5 files changed, 139 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9806ae07..1ac41bf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41083,6 +41083,126 @@ "@vue/server-renderer": "3.3.4", "@vue/shared": "3.3.4" } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.1.tgz", + "integrity": "sha512-uvTZrZa4D0bdWa1jJ7X1tBGIxzpqSnw/ATxWvoRO9CVBvXSx87JyuISY+BWsfLFF59IRodESdeZwkWM2l6+Kjg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.5.1.tgz", + "integrity": "sha512-/52ThlqdORPQt3+AlMoO+omicdYyUEDeRDGPAj86ULpV4dg+/GCFCKAmFWT0Q4zChFwsAoZUECLcKbRdcc0SNg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.5.1.tgz", + "integrity": "sha512-L4qNXSOHeu1hEAeeNsBgIYVnvm0gg9fj2O2Yx/qawgQEGuFBfcKqlmIE/Vp8z6gwlppxz5d7v6pmHs1NB6R37w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.1.tgz", + "integrity": "sha512-QVvMrlrFFYvLtABk092kcZ5Mzlmsk2+SV3xYuAu8sbTuIoh0U2+HGNhVklmuYCuM3DAAxdiMQTNlRQmNH11udw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.1.tgz", + "integrity": "sha512-bBnr+XuWc28r9e8gQ35XBtyi5KLHLhTbEvrSgcWna8atI48sNggjIK8IyiEBO3KIrcUVXYkldAzGXPEYMnKt1g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.1.tgz", + "integrity": "sha512-EQGeE4S5c9v06jje9gr4UlxqUEA+zrsgPi6kg9VwR+dQHirzbnVJISF69UfKVkmLntknZJJI9XpWPB6q0Z7mTg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.1.tgz", + "integrity": "sha512-1y31Q6awzofVjmbTLtRl92OX3s+W0ZfO8AP8fTnITcIo9a6ATDc/eqa08fd6tSpFu6IFpxOBbdevOjwYTGx/AQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "13.5.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.1.tgz", + "integrity": "sha512-+9XBQizy7X/GuwNegq+5QkkxAPV7SBsIwapVRQd9WSvvU20YO23B3bZUpevdabi4fsd25y9RJDDncljy/V54ww==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/packages/angular/projects/spaces/src/lib/space/space-frame/spaceFrame.component.ts b/packages/angular/projects/spaces/src/lib/space/space-frame/spaceFrame.component.ts index 540214bf..ff31a095 100644 --- a/packages/angular/projects/spaces/src/lib/space/space-frame/spaceFrame.component.ts +++ b/packages/angular/projects/spaces/src/lib/space/space-frame/spaceFrame.component.ts @@ -57,7 +57,7 @@ export class SpaceFrame implements OnInit { const dispatchEvent = (event: any) => { if (!event) return - const eventPayload = event.src ? event.src : event + const eventPayload = event.src || event const eventInstance = new FlatfileEvent(eventPayload, accessToken, apiUrl) return listenerInstance?.dispatchEvent(eventInstance) diff --git a/packages/angular/projects/spaces/src/utils/createSimpleListener.ts b/packages/angular/projects/spaces/src/utils/createSimpleListener.ts index 32c0d472..6a420bab 100644 --- a/packages/angular/projects/spaces/src/utils/createSimpleListener.ts +++ b/packages/angular/projects/spaces/src/utils/createSimpleListener.ts @@ -1,5 +1,6 @@ -import api from '@flatfile/api' +import { FlatfileClient } from '@flatfile/api' import { + DefaultSubmitSettings, JobHandler, SheetHandler, SimpleOnboarding, @@ -9,14 +10,20 @@ import { FlatfileEvent, FlatfileListener } from '@flatfile/listener' import { recordHook } from '@flatfile/plugin-record-hook' interface SimpleListenerType - extends Pick { + extends Pick< + SimpleOnboarding, + 'onRecordHook' | 'onSubmit' | 'submitSettings' + > { slug: string } +const api = new FlatfileClient() + const createSimpleListener = ({ onRecordHook, onSubmit, slug, + submitSettings, }: SimpleListenerType) => FlatfileListener.create((client: FlatfileListener) => { if (onRecordHook) { @@ -24,12 +31,12 @@ const createSimpleListener = ({ recordHook( slug, async (record: FlatfileRecord, event?: FlatfileEvent) => - // @ts-ignore - something weird with the `data` prop and the types upstream in the packages being declared in different places, but overall this is fine onRecordHook(record, event) ) ) } if (onSubmit) { + const onSubmitSettings = { ...DefaultSubmitSettings, ...submitSettings } client.filter( { job: 'workbook:simpleSubmitAction' }, (configure: FlatfileListener) => { @@ -46,21 +53,22 @@ const createSimpleListener = ({ // this assumes we are only allowing 1 sheet here (which we've talked about doing initially) const sheet = new SheetHandler(workbookSheets[0].id) - await onSubmit({ job, sheet }) + if (onSubmit) { + await onSubmit({ job, sheet, event }) + } await api.jobs.complete(jobId, { outcome: { message: 'complete', }, }) - await api.spaces.delete(spaceId) + if (onSubmitSettings.deleteSpaceAfterSubmit) { + await api.spaces.archiveSpace(spaceId) + } } catch (error: any) { if (jobId) { await api.jobs.cancel(jobId) } - if (spaceId) { - await api.spaces.delete(spaceId) - } console.error('Error:', error.stack) } }) diff --git a/packages/angular/projects/spaces/src/utils/useInitializeSpace.ts b/packages/angular/projects/spaces/src/utils/useInitializeSpace.ts index fd0ba0f1..97572741 100644 --- a/packages/angular/projects/spaces/src/utils/useInitializeSpace.ts +++ b/packages/angular/projects/spaces/src/utils/useInitializeSpace.ts @@ -38,10 +38,6 @@ const useInitializeSpace = ( throw new Error('Missing required publishable key') } - if (!environmentId) { - throw new Error('Missing required environment id') - } - const limitedAccessApi = authenticate(publishableKey, apiUrl) const spaceRequestBody = { name, diff --git a/packages/angular/src/app/app.component.ts b/packages/angular/src/app/app.component.ts index 11fc3510..8bc30c35 100644 --- a/packages/angular/src/app/app.component.ts +++ b/packages/angular/src/app/app.component.ts @@ -24,8 +24,8 @@ export class AppComponent { spaceProps: ISpace = { name: 'Trste!', - environmentId: 'us_env_1234', - publishableKey: 'sk_1234', + environmentId: 'us_env_ZvaDGP3B', + publishableKey: 'pk_0d40167fccfc47e9a4ec0223e9787e63', workbook, listener, userInfo: {