diff --git a/.changeset/eleven-badgers-shout.md b/.changeset/eleven-badgers-shout.md
new file mode 100644
index 000000000..6b0d40af0
--- /dev/null
+++ b/.changeset/eleven-badgers-shout.md
@@ -0,0 +1,9 @@
+---
+'@flatfile/plugin-convert-sql-ddl': patch
+'@flatfile/plugin-convert-openapi-schema': patch
+'@flatfile/plugin-convert-json-schema': patch
+'@flatfile/plugin-convert-yaml-schema': patch
+'@flatfile/plugin-connect-via-merge': patch
+---
+
+This release fixes an async/await bug
diff --git a/flatfilers/sandbox/src/index.ts b/flatfilers/sandbox/src/index.ts
index 677d7e0b9..bd7e5bc6a 100644
--- a/flatfilers/sandbox/src/index.ts
+++ b/flatfilers/sandbox/src/index.ts
@@ -1,68 +1,113 @@
+import api, { Flatfile } from '@flatfile/api'
import type { FlatfileListener } from '@flatfile/listener'
-import { importLLMRecords } from '@flatfile/plugin-import-llm-records'
-import { configureSpace } from '@flatfile/plugin-space-configure'
+import {
+ PartialSheetConfig,
+ PartialWorkbookConfig,
+ configureSpaceWithJsonSchema,
+ fetchExternalReference,
+} from '@flatfile/plugin-convert-json-schema'
-export default async function (listener: FlatfileListener) {
- listener.use(
- importLLMRecords({
- llmSecretName: 'OPENAI_API_KEY',
- model: 'gpt-4o',
- job: 'generateExampleRecords',
- numberOfRecords: 10,
- debug: true,
- })
- )
- listener.use(
- configureSpace({
- workbooks: [
- {
- name: 'Sandbox',
- sheets: [
- {
- name: 'Sales',
- slug: 'sales',
- fields: [
- {
- key: 'date',
- type: 'string',
- label: 'Date',
- },
- {
- key: 'product',
- type: 'string',
- label: 'Product',
- },
- {
- key: 'category',
- type: 'string',
- label: 'Category',
- },
- {
- key: 'region',
- type: 'string',
- label: 'Region',
- },
- {
- key: 'salesAmount',
- type: 'number',
- label: 'Sales Amount',
- },
- ],
- actions: [
- {
- operation: 'generateExampleRecords',
- label: 'Generate Example Records',
- description:
- 'This custom action code generates example records using Anthropic.',
- primary: false,
- mode: 'foreground',
- type: 'string',
- },
- ],
- },
- ],
+export default function (listener: FlatfileListener) {
+ const workbookActions: Flatfile.Action[] = [
+ {
+ operation: 'submitAction',
+ mode: 'foreground',
+ label: 'Submit data',
+ type: 'string',
+ description: 'Submit this data to a webhook.',
+ primary: true,
+ },
+ ]
+
+ const sheetActions: Flatfile.Action[] = [
+ {
+ operation: 'duplicateSheet',
+ mode: 'foreground',
+ label: 'Duplicate',
+ description: 'Duplicate this sheet.',
+ primary: true,
+ },
+ ]
+
+ const personModel: PartialSheetConfig = {
+ source: {
+ $id: 'https://raw.githubusercontent.com/FlatFilers/flatfile-docs-kitchen-sink/main/typescript/dynamic-configurations-json-schema/example-schemas/person.json',
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ title: 'Person',
+ type: 'object',
+ properties: {
+ firstName: {
+ type: 'string',
+ description: "The person's first name.",
+ },
+ lastName: {
+ type: 'string',
+ description: "The person's last name.",
+ },
+ age: {
+ description:
+ 'Age in years which must be equal to or greater than zero.',
+ type: 'integer',
+ minimum: 0,
},
- ],
+ },
+ },
+ slug: 'person',
+ name: 'Person',
+ actions: sheetActions,
+ }
+
+ const customerModel: PartialSheetConfig = {
+ source:
+ 'https://raw.githubusercontent.com/FlatFilers/flatfile-docs-kitchen-sink/main/typescript/dynamic-configurations-json-schema/example-schemas/customer.json',
+ slug: 'customer',
+ name: 'Customer',
+ actions: sheetActions,
+ }
+
+ const productModel: PartialSheetConfig = {
+ source: () =>
+ fetchExternalReference(
+ 'https://raw.githubusercontent.com/FlatFilers/flatfile-docs-kitchen-sink/main/typescript/dynamic-configurations-json-schema/example-schemas/product.json'
+ ),
+ slug: 'product',
+ name: 'Product',
+ actions: sheetActions,
+ }
+
+ const workbookOne: PartialWorkbookConfig = {
+ name: 'Store Workbook',
+ sheets: [customerModel, productModel],
+ actions: workbookActions,
+ }
+
+ const workbookTwo: PartialWorkbookConfig = {
+ name: 'Person Workbook',
+ sheets: [personModel],
+ actions: workbookActions,
+ }
+
+ const callback = async (event, workbookIds, tick) => {
+ const { spaceId } = event.context
+ await api.documents.create(spaceId, {
+ title: 'Welcome',
+ body: `
+
Welcome!
+
To get started, follow these steps:
+
1. Step One
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+
Remember, if you need any assistance, you can always refer back to this page by clicking "Welcome" in the left-hand sidebar!
+
`,
})
+ await tick(80, 'Document created')
+ }
+
+ listener.use(
+ configureSpaceWithJsonSchema(
+ {
+ workbooks: [workbookOne, workbookTwo],
+ },
+ callback
+ )
)
}
diff --git a/package-lock.json b/package-lock.json
index 1545e0f65..f22c67534 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -263,6 +263,7 @@
}
},
"flatfilers/playground": {
+ "name": "@private/playground",
"version": "0.0.0",
"license": "ISC",
"dependencies": {
@@ -21657,6 +21658,9 @@
"@flatfile/plugin-job-handler": "^0.6.1",
"@mergeapi/merge-node-client": "^1.0.4"
},
+ "devDependencies": {
+ "@flatfile/plugin-space-configure": "^0.6.1"
+ },
"engines": {
"node": ">= 16"
},
diff --git a/plugins/graphql-schema/src/index.ts b/plugins/graphql-schema/src/index.ts
index 56bf04c4c..2f41b5755 100644
--- a/plugins/graphql-schema/src/index.ts
+++ b/plugins/graphql-schema/src/index.ts
@@ -1,5 +1,5 @@
import type { Flatfile } from '@flatfile/api'
-import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
+import type { FlatfileEvent } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
import { generateSetup } from './setup.factory'
import type { GraphQLSetupFactory } from './types'
@@ -12,9 +12,5 @@ export function configureSpaceGraphQL(
tick: (progress: number, message?: string) => Promise
) => any | Promise
) {
- return async (listener: FlatfileListener) => {
- listener.use(
- configureSpace((event) => generateSetup(setupFactory, event), callback)
- )
- }
+ return configureSpace((event) => generateSetup(setupFactory, event), callback)
}
diff --git a/plugins/json-schema/src/index.ts b/plugins/json-schema/src/index.ts
index 0d63f63fb..ffd640e30 100644
--- a/plugins/json-schema/src/index.ts
+++ b/plugins/json-schema/src/index.ts
@@ -1,7 +1,7 @@
import type { Flatfile } from '@flatfile/api'
-import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
+import type { FlatfileEvent } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
-import { JsonSetupFactory, generateSetup } from './setup.factory'
+import { generateSetup, type JsonSetupFactory } from './setup.factory'
export function configureSpaceWithJsonSchema(
setupFactory: JsonSetupFactory,
@@ -11,9 +11,7 @@ export function configureSpaceWithJsonSchema(
tick: (progress?: number, message?: string) => Promise
) => any | Promise
) {
- return async function (listener: FlatfileListener) {
- listener.use(configureSpace(await generateSetup(setupFactory), callback))
- }
+ return configureSpace(() => generateSetup(setupFactory), callback)
}
export * from './setup.factory'
diff --git a/plugins/json-schema/src/setup.factory.ts b/plugins/json-schema/src/setup.factory.ts
index 12b7bc72c..2a045f934 100644
--- a/plugins/json-schema/src/setup.factory.ts
+++ b/plugins/json-schema/src/setup.factory.ts
@@ -1,5 +1,5 @@
-import { Flatfile } from '@flatfile/api'
-import { SetupFactory } from '@flatfile/plugin-space-configure'
+import type { Flatfile } from '@flatfile/api'
+import type { Setup } from '@flatfile/plugin-space-configure'
import fetch from 'cross-fetch'
export type JsonSetupFactory = {
@@ -20,13 +20,12 @@ export interface PartialSheetConfig
export async function generateSetup(
setupFactory: JsonSetupFactory
-): Promise {
+): Promise {
const workbooks = await Promise.all(
setupFactory.workbooks.map(async (workbook) => {
const sheets = await Promise.all(
workbook.sheets.map(async (partialSheetConfig: PartialSheetConfig) => {
const model = await getModel(partialSheetConfig.source)
- delete partialSheetConfig.source
const fields = await generateFields(model)
return {
@@ -72,7 +71,7 @@ function isValidUrl(url: string) {
}
export async function generateFields(data: any): Promise {
- if (!data.properties) return []
+ if (!data || !data.properties) return []
const getOrigin = (url: string) => {
try {
diff --git a/plugins/merge-connection/package.json b/plugins/merge-connection/package.json
index 488331bcc..80906a8bd 100644
--- a/plugins/merge-connection/package.json
+++ b/plugins/merge-connection/package.json
@@ -32,6 +32,9 @@
"@flatfile/plugin-job-handler": "^0.6.1",
"@mergeapi/merge-node-client": "^1.0.4"
},
+ "devDependencies": {
+ "@flatfile/plugin-space-configure": "^0.6.1"
+ },
"peerDependencies": {
"@flatfile/api": "^1.9.19",
"@flatfile/listener": "^1.1.0"
diff --git a/plugins/merge-connection/src/create.workbook.ts b/plugins/merge-connection/src/create.workbook.ts
index 86a1a67dd..c577bf191 100644
--- a/plugins/merge-connection/src/create.workbook.ts
+++ b/plugins/merge-connection/src/create.workbook.ts
@@ -2,10 +2,10 @@ import type { Flatfile } from '@flatfile/api'
import { FlatfileClient } from '@flatfile/api'
import type { FlatfileEvent } from '@flatfile/listener'
import {
- PartialSheetConfig,
- SetupFactory,
+ type PartialSheetConfig,
generateSetup,
} from '@flatfile/plugin-convert-openapi-schema'
+import type { Setup } from '@flatfile/plugin-space-configure'
import { MergeClient } from '@mergeapi/merge-node-client'
import {
CATEGORY_MODELS,
@@ -103,7 +103,7 @@ export function handleCreateConnectedWorkbooks() {
}
})
- const setup: SetupFactory = await generateSetup({
+ const config: Setup = await generateSetup({
workbooks: [
{
source: `https://api.merge.dev/api/${category}/v1/schema`,
@@ -111,7 +111,6 @@ export function handleCreateConnectedWorkbooks() {
},
],
})
- const config = typeof setup === 'function' ? await setup(event) : setup
config.workbooks.map((workbook) => {
workbook.sheets.map((sheet) => {
sheet.fields.map((field) => {
diff --git a/plugins/openapi-schema/src/index.ts b/plugins/openapi-schema/src/index.ts
index 500a4203b..886e0eccd 100644
--- a/plugins/openapi-schema/src/index.ts
+++ b/plugins/openapi-schema/src/index.ts
@@ -1,7 +1,7 @@
import type { Flatfile } from '@flatfile/api'
-import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
+import type { FlatfileEvent } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
-import { OpenAPISetupFactory, generateSetup } from './setup.factory'
+import { generateSetup, type OpenAPISetupFactory } from './setup.factory'
export function configureSpaceWithOpenAPI(
setupFactory: OpenAPISetupFactory,
@@ -11,9 +11,7 @@ export function configureSpaceWithOpenAPI(
tick: (progress?: number, message?: string) => Promise
) => any | Promise
) {
- return async function (listener: FlatfileListener) {
- listener.use(configureSpace(await generateSetup(setupFactory), callback))
- }
+ return configureSpace(() => generateSetup(setupFactory), callback)
}
export type { SetupFactory } from '@flatfile/plugin-space-configure'
diff --git a/plugins/openapi-schema/src/setup.factory.ts b/plugins/openapi-schema/src/setup.factory.ts
index b5a5c0d1d..4e8bd1a3a 100644
--- a/plugins/openapi-schema/src/setup.factory.ts
+++ b/plugins/openapi-schema/src/setup.factory.ts
@@ -1,5 +1,5 @@
-import { Flatfile } from '@flatfile/api'
-import { PartialWb, SetupFactory } from '@flatfile/plugin-space-configure'
+import type { Flatfile } from '@flatfile/api'
+import type { PartialWb, Setup } from '@flatfile/plugin-space-configure'
import fetch from 'cross-fetch'
export type OpenAPISetupFactory = {
@@ -40,7 +40,7 @@ interface ApiSchemas {
export async function generateSetup(
setupFactory: OpenAPISetupFactory
-): Promise {
+): Promise {
try {
const workbooks: PartialWb[] = await Promise.all(
setupFactory.workbooks.map(async (workbook) => {
@@ -80,8 +80,6 @@ export async function generateSetup(
)
).filter(Boolean)
- delete workbook.source
-
return {
name: data.info.title,
...workbook,
@@ -100,7 +98,7 @@ export async function generateFields(
data: any,
origin: any
): Promise {
- if (!data.properties) return []
+ if (!data || !data.properties) return []
const fields = await Promise.all(
Object.keys(data.properties).map((key) =>
diff --git a/plugins/sql-ddl-converter/src/index.ts b/plugins/sql-ddl-converter/src/index.ts
index 3360e66bf..0335d4fa5 100644
--- a/plugins/sql-ddl-converter/src/index.ts
+++ b/plugins/sql-ddl-converter/src/index.ts
@@ -1,19 +1,17 @@
import type { Flatfile } from '@flatfile/api'
-import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
+import type { FlatfileEvent } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
-import { SqlSetupFactory, generateSetup } from './setup.factory'
+import { generateSetup, type SqlSetupFactory } from './setup.factory'
export function configureSpaceWithSqlDDL(
- setup: SqlSetupFactory,
+ setupFactory: SqlSetupFactory,
callback?: (
event: FlatfileEvent,
workbookIds: string[],
tick: (progress?: number, message?: string) => Promise
) => any | Promise
) {
- return async function (listener: FlatfileListener) {
- listener.use(configureSpace(await generateSetup(setup), callback))
- }
+ return configureSpace(() => generateSetup(setupFactory), callback)
}
export * from './setup.factory'
diff --git a/plugins/sql-ddl-converter/src/setup.factory.ts b/plugins/sql-ddl-converter/src/setup.factory.ts
index 595351ced..6a6a04a71 100644
--- a/plugins/sql-ddl-converter/src/setup.factory.ts
+++ b/plugins/sql-ddl-converter/src/setup.factory.ts
@@ -1,6 +1,6 @@
-import { Flatfile } from '@flatfile/api'
+import type { Flatfile } from '@flatfile/api'
import { generateFields } from '@flatfile/plugin-convert-json-schema'
-import { PartialWb, SetupFactory } from '@flatfile/plugin-space-configure'
+import type { PartialWb, Setup } from '@flatfile/plugin-space-configure'
import { Parser } from 'sql-ddl-to-json-schema'
import * as fs from 'fs'
@@ -22,9 +22,7 @@ export interface PartialSheetConfig
slug: string
}
-export async function generateSetup(
- setup: SqlSetupFactory
-): Promise {
+export async function generateSetup(setup: SqlSetupFactory): Promise {
const workbooks: PartialWb[] = await Promise.all(
setup.workbooks.map(async (workbook) => {
const sql: string = retrieveFromSource(workbook.source)
@@ -63,8 +61,6 @@ export async function generateSetup(
)
).filter(Boolean)
- delete workbook.source
-
return {
...workbook,
sheets,
diff --git a/plugins/yaml-schema/src/index.ts b/plugins/yaml-schema/src/index.ts
index 89049dc18..e16263fcc 100644
--- a/plugins/yaml-schema/src/index.ts
+++ b/plugins/yaml-schema/src/index.ts
@@ -1,5 +1,5 @@
import type { Flatfile } from '@flatfile/api'
-import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
+import type { FlatfileEvent } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
import type { ModelToSheetConfig, PartialWorkbookConfig } from './setup.factory'
import { generateSetup } from './setup.factory'
@@ -16,9 +16,7 @@ export function configureSpaceWithYamlSchema(
tick: (progress: number, message?: string) => Promise
) => any | Promise
) {
- return async function (listener: FlatfileListener) {
- listener.use(configureSpace(await generateSetup(models, options), callback))
- }
+ return configureSpace(() => generateSetup(models, options), callback)
}
export * from './setup.factory'
diff --git a/plugins/yaml-schema/src/setup.factory.ts b/plugins/yaml-schema/src/setup.factory.ts
index 45a7d952d..d1b9dd740 100644
--- a/plugins/yaml-schema/src/setup.factory.ts
+++ b/plugins/yaml-schema/src/setup.factory.ts
@@ -1,7 +1,6 @@
import type { Flatfile } from '@flatfile/api'
import { generateFields } from '@flatfile/plugin-convert-json-schema'
-import { Setup, SetupFactory } from '@flatfile/plugin-space-configure'
-
+import type { Setup } from '@flatfile/plugin-space-configure'
import jsYaml from 'js-yaml'
export interface ModelToSheetConfig extends PartialSheetConfig {
@@ -24,7 +23,7 @@ export async function generateSetup(
workbookConfig?: PartialWorkbookConfig
debug?: boolean
}
-): Promise {
+): Promise {
const schemas = await getSchemas(models)
const asdf = schemas.map((schema) => jsYaml.load(schema))
@@ -32,7 +31,7 @@ export async function generateSetup(
models.map(async (model: ModelToSheetConfig, i) => {
const data = asdf[i]
const fields = await generateFields(data)
- delete model.sourceUrl
+
return {
name: model?.name || data.title,
...(data?.description && { description: data.description }),