Skip to content

Commit

Permalink
feat: fix build bug, remove environmentId requirement and stop deleti…
Browse files Browse the repository at this point in the history
…ng spaces
  • Loading branch information
bangarang committed Apr 11, 2024
1 parent d788180 commit f10e61e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 15 deletions.
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 16 additions & 8 deletions packages/angular/projects/spaces/src/utils/createSimpleListener.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import api from '@flatfile/api'
import { FlatfileClient } from '@flatfile/api'
import {
DefaultSubmitSettings,
JobHandler,
SheetHandler,
SimpleOnboarding,
Expand All @@ -9,27 +10,33 @@ import { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { recordHook } from '@flatfile/plugin-record-hook'

interface SimpleListenerType
extends Pick<SimpleOnboarding, 'onRecordHook' | 'onSubmit'> {
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) {
client.use(
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) => {
Expand All @@ -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)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit f10e61e

Please sign in to comment.