From 8afa0cc0748865ac29f6a66d9c656d535f3742ab Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Wed, 19 Feb 2025 12:13:51 -0600 Subject: [PATCH 1/3] feat: data checklist --- .changeset/few-sloths-clean.md | 5 + flatfilers/sandbox/src/index.ts | 112 +++++++++++++++++- package-lock.json | 15 ++- plugins/space-configure/src/index.ts | 2 + .../src/utils/data.checklist.ts | 51 ++++++++ 5 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 .changeset/few-sloths-clean.md create mode 100644 plugins/space-configure/src/utils/data.checklist.ts diff --git a/.changeset/few-sloths-clean.md b/.changeset/few-sloths-clean.md new file mode 100644 index 000000000..42711fade --- /dev/null +++ b/.changeset/few-sloths-clean.md @@ -0,0 +1,5 @@ +--- +'@flatfile/plugin-space-configure': minor +--- + +This release adds a data checklist utility that can be used to create a Data Checklist Document diff --git a/flatfilers/sandbox/src/index.ts b/flatfilers/sandbox/src/index.ts index f6ab47330..1473c652b 100644 --- a/flatfilers/sandbox/src/index.ts +++ b/flatfilers/sandbox/src/index.ts @@ -1,6 +1,9 @@ -import type { FlatfileListener } from '@flatfile/listener' +import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener' +import { exportDelimitedZip } from '@flatfile/plugin-export-delimited-zip' +import { type TickFunction } from '@flatfile/plugin-job-handler' +import { JSONExtractor } from '@flatfile/plugin-json-extractor' import { bulkRecordHook } from '@flatfile/plugin-record-hook' -import { configureSpace } from '@flatfile/plugin-space-configure' +import { configureSpace, createDataChecklist } from '@flatfile/plugin-space-configure' import { storedConstraint } from '@flatfile/plugin-stored-constraints' import { ExcelExtractor } from '@flatfile/plugin-xlsx-extractor' import { contacts } from './sheets/contacts' @@ -36,7 +39,106 @@ export default async function (listener: FlatfileListener) { workbooks: [ { name: 'Sandbox', - sheets: [contacts], + sheets: [ + { + name: 'Sales', + slug: 'sales', + fields: [ + { + key: 'date', + type: 'string', + label: 'Date', + description: 'The date of the sale', + constraints: [ + { + type: 'required', + }, + { + type: 'unique', + } + ], + }, + { + key: 'product', + type: 'string', + label: 'Product', + description: 'The product sold', + constraints: [ + { + type: 'required', + }, + ], + }, + { + key: 'category', + type: 'string', + label: 'Category', + description: 'The category of the product', + }, + { + key: 'region', + type: 'string', + label: 'Region', + description: 'The region of the sale', + }, + { + key: 'salesAmount', + type: 'number', + label: 'Sales Amount', + description: 'The amount of the sale', + }, + ], + actions: [ + { + operation: 'generateExampleRecords', + label: 'Generate Example Records', + description: 'This custom action code generates example records using Anthropic.', + primary: false, + mode: 'foreground', + }, + ], + }, + { + name: 'Sales 2', + slug: 'sales-2', + 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: 'export-external-api', + label: 'Export to External API', + description: 'This custom action code exports the records in the Sales sheet to an external API.', + primary: false, + mode: 'foreground', + }, + ], + }, + ], actions: [ { operation: 'export-delimited-zip', @@ -46,6 +148,8 @@ export default async function (listener: FlatfileListener) { ], }, ], - }) + }, async (event: FlatfileEvent, _workbookIds: string[], _tick: TickFunction) => { + await createDataChecklist(event) + }), ) } diff --git a/package-lock.json b/package-lock.json index cdc1aea0e..a4b2b1b03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -296,7 +296,6 @@ "flatfilers/playground": { "name": "@private/playground", "version": "0.0.0", - "extraneous": true, "license": "ISC", "dependencies": { "@flatfile/api": "^1.9.19", @@ -4999,6 +4998,10 @@ "node": ">=14" } }, + "node_modules/@private/playground": { + "resolved": "flatfilers/playground", + "link": true + }, "node_modules/@private/sandbox": { "resolved": "flatfilers/sandbox", "link": true @@ -17813,7 +17816,7 @@ }, "plugins/record-hook": { "name": "@flatfile/plugin-record-hook", - "version": "2.0.0", + "version": "2.0.1", "license": "ISC", "dependencies": { "@flatfile/util-common": "^1.6.0" @@ -17917,7 +17920,7 @@ }, "plugins/stored-constraints": { "name": "@flatfile/plugin-stored-constraints", - "version": "1.0.0", + "version": "1.0.1", "license": "ISC", "dependencies": { "country-state-city": "^3.2.1", @@ -18017,10 +18020,10 @@ }, "plugins/xlsx-extractor": { "name": "@flatfile/plugin-xlsx-extractor", - "version": "3.4.1", + "version": "3.5.1", "license": "ISC", "dependencies": { - "@flatfile/util-extractor": "^2.3.0", + "@flatfile/util-extractor": "^2.5.0", "remeda": "^1.14.0", "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" }, @@ -18191,7 +18194,7 @@ }, "utils/extractor": { "name": "@flatfile/util-extractor", - "version": "2.4.1", + "version": "2.5.0", "license": "ISC", "dependencies": { "@flatfile/util-common": "^1.6.0", diff --git a/plugins/space-configure/src/index.ts b/plugins/space-configure/src/index.ts index 2af05e817..fd683bc39 100644 --- a/plugins/space-configure/src/index.ts +++ b/plugins/space-configure/src/index.ts @@ -1 +1,3 @@ export * from './space.configure' +export * from './utils/data.checklist' + diff --git a/plugins/space-configure/src/utils/data.checklist.ts b/plugins/space-configure/src/utils/data.checklist.ts new file mode 100644 index 000000000..2cbb54404 --- /dev/null +++ b/plugins/space-configure/src/utils/data.checklist.ts @@ -0,0 +1,51 @@ +import { FlatfileClient } from "@flatfile/api"; +import { FlatfileEvent } from "@flatfile/listener"; + +const api = new FlatfileClient() + +export const createDataChecklist = async (event: FlatfileEvent) => { + const {spaceId} = event.context + + const {data: workbooks} = await api.workbooks.list({spaceId}) + + let body = `
\n`; + + for(const workbook of workbooks) { + const {data: sheets} = await api.sheets.list({workbookId: workbook.id}) + body += `

${workbook.name}

`; + + for(const sheet of sheets) { + const fields = sheet.config.fields; + const fieldTable = fields.map(field => { + const constraints = field.constraints?.map(constraint => `${constraint.type}`).join(''); + return ` + + ${field.label}${constraints ?? ''} + ${field.type} + ${field.description || ''} + `; + }).join('') + + body += ` +

${sheet.name}

+ + + + + + + + +${fieldTable} + +
Field NameData TypeDescription
`; + } + } + + body += `\n
`; + + await api.documents.create(spaceId, { + title: `Data Checklist`, + body, + }); +} From 1cc8e4bf6eb7f1d49082719c6eab0d761d0adab2 Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Wed, 19 Feb 2025 12:16:52 -0600 Subject: [PATCH 2/3] chore: formatting --- flatfilers/sandbox/src/index.ts | 246 +++++++++--------- plugins/space-configure/src/index.ts | 1 - .../src/utils/data.checklist.ts | 53 ++-- 3 files changed, 159 insertions(+), 141 deletions(-) diff --git a/flatfilers/sandbox/src/index.ts b/flatfilers/sandbox/src/index.ts index 1473c652b..f24077565 100644 --- a/flatfilers/sandbox/src/index.ts +++ b/flatfilers/sandbox/src/index.ts @@ -3,7 +3,10 @@ import { exportDelimitedZip } from '@flatfile/plugin-export-delimited-zip' import { type TickFunction } from '@flatfile/plugin-job-handler' import { JSONExtractor } from '@flatfile/plugin-json-extractor' import { bulkRecordHook } from '@flatfile/plugin-record-hook' -import { configureSpace, createDataChecklist } from '@flatfile/plugin-space-configure' +import { + configureSpace, + createDataChecklist, +} from '@flatfile/plugin-space-configure' import { storedConstraint } from '@flatfile/plugin-stored-constraints' import { ExcelExtractor } from '@flatfile/plugin-xlsx-extractor' import { contacts } from './sheets/contacts' @@ -35,121 +38,130 @@ export default async function (listener: FlatfileListener) { ) ) listener.use( - configureSpace({ - workbooks: [ - { - name: 'Sandbox', - sheets: [ - { - name: 'Sales', - slug: 'sales', - fields: [ - { - key: 'date', - type: 'string', - label: 'Date', - description: 'The date of the sale', - constraints: [ - { - type: 'required', - }, - { - type: 'unique', - } - ], - }, - { - key: 'product', - type: 'string', - label: 'Product', - description: 'The product sold', - constraints: [ - { - type: 'required', - }, - ], - }, - { - key: 'category', - type: 'string', - label: 'Category', - description: 'The category of the product', - }, - { - key: 'region', - type: 'string', - label: 'Region', - description: 'The region of the sale', - }, - { - key: 'salesAmount', - type: 'number', - label: 'Sales Amount', - description: 'The amount of the sale', - }, - ], - actions: [ - { - operation: 'generateExampleRecords', - label: 'Generate Example Records', - description: 'This custom action code generates example records using Anthropic.', - primary: false, - mode: 'foreground', - }, - ], - }, - { - name: 'Sales 2', - slug: 'sales-2', - 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: 'export-external-api', - label: 'Export to External API', - description: 'This custom action code exports the records in the Sales sheet to an external API.', - primary: false, - mode: 'foreground', - }, - ], - }, - ], - actions: [ - { - operation: 'export-delimited-zip', - label: 'Export to Delimited ZIP', - mode: 'foreground', - }, - ], - }, - ], - }, async (event: FlatfileEvent, _workbookIds: string[], _tick: TickFunction) => { - await createDataChecklist(event) - }), + configureSpace( + { + workbooks: [ + { + name: 'Sandbox', + sheets: [ + { + name: 'Sales', + slug: 'sales', + fields: [ + { + key: 'date', + type: 'string', + label: 'Date', + description: 'The date of the sale', + constraints: [ + { + type: 'required', + }, + { + type: 'unique', + }, + ], + }, + { + key: 'product', + type: 'string', + label: 'Product', + description: 'The product sold', + constraints: [ + { + type: 'required', + }, + ], + }, + { + key: 'category', + type: 'string', + label: 'Category', + description: 'The category of the product', + }, + { + key: 'region', + type: 'string', + label: 'Region', + description: 'The region of the sale', + }, + { + key: 'salesAmount', + type: 'number', + label: 'Sales Amount', + description: 'The amount of the sale', + }, + ], + actions: [ + { + operation: 'generateExampleRecords', + label: 'Generate Example Records', + description: + 'This custom action code generates example records using Anthropic.', + primary: false, + mode: 'foreground', + }, + ], + }, + { + name: 'Sales 2', + slug: 'sales-2', + 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: 'export-external-api', + label: 'Export to External API', + description: + 'This custom action code exports the records in the Sales sheet to an external API.', + primary: false, + mode: 'foreground', + }, + ], + }, + ], + actions: [ + { + operation: 'export-delimited-zip', + label: 'Export to Delimited ZIP', + mode: 'foreground', + }, + ], + }, + ], + }, + async ( + event: FlatfileEvent, + _workbookIds: string[], + _tick: TickFunction + ) => { + await createDataChecklist(event) + } + ) ) } diff --git a/plugins/space-configure/src/index.ts b/plugins/space-configure/src/index.ts index fd683bc39..ec931e448 100644 --- a/plugins/space-configure/src/index.ts +++ b/plugins/space-configure/src/index.ts @@ -1,3 +1,2 @@ export * from './space.configure' export * from './utils/data.checklist' - diff --git a/plugins/space-configure/src/utils/data.checklist.ts b/plugins/space-configure/src/utils/data.checklist.ts index 2cbb54404..8e5537da7 100644 --- a/plugins/space-configure/src/utils/data.checklist.ts +++ b/plugins/space-configure/src/utils/data.checklist.ts @@ -1,30 +1,37 @@ -import { FlatfileClient } from "@flatfile/api"; -import { FlatfileEvent } from "@flatfile/listener"; +import { FlatfileClient } from '@flatfile/api' +import { FlatfileEvent } from '@flatfile/listener' const api = new FlatfileClient() export const createDataChecklist = async (event: FlatfileEvent) => { - const {spaceId} = event.context - - const {data: workbooks} = await api.workbooks.list({spaceId}) - - let body = `
\n`; - - for(const workbook of workbooks) { - const {data: sheets} = await api.sheets.list({workbookId: workbook.id}) - body += `

${workbook.name}

`; - - for(const sheet of sheets) { - const fields = sheet.config.fields; - const fieldTable = fields.map(field => { - const constraints = field.constraints?.map(constraint => `${constraint.type}`).join(''); - return ` + const { spaceId } = event.context + + const { data: workbooks } = await api.workbooks.list({ spaceId }) + + let body = `
\n` + + for (const workbook of workbooks) { + const { data: sheets } = await api.sheets.list({ workbookId: workbook.id }) + body += `

${workbook.name}

` + + for (const sheet of sheets) { + const fields = sheet.config.fields + const fieldTable = fields + .map((field) => { + const constraints = field.constraints + ?.map( + (constraint) => + `${constraint.type}` + ) + .join('') + return ` ${field.label}${constraints ?? ''} ${field.type} ${field.description || ''} - `; - }).join('') + ` + }) + .join('') body += `

${sheet.name}

@@ -38,14 +45,14 @@ export const createDataChecklist = async (event: FlatfileEvent) => { ${fieldTable} -`; +` } } - body += `\n
`; - + body += `\n
` + await api.documents.create(spaceId, { title: `Data Checklist`, body, - }); + }) } From 8877849b0674fe70c9c50edd56c3163b9ddfc4fa Mon Sep 17 00:00:00 2001 From: Carl Brugger Date: Wed, 19 Feb 2025 12:27:09 -0600 Subject: [PATCH 3/3] function params to spaceId --- flatfilers/sandbox/src/index.ts | 2 +- plugins/space-configure/src/utils/data.checklist.ts | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/flatfilers/sandbox/src/index.ts b/flatfilers/sandbox/src/index.ts index f24077565..df55995ff 100644 --- a/flatfilers/sandbox/src/index.ts +++ b/flatfilers/sandbox/src/index.ts @@ -160,7 +160,7 @@ export default async function (listener: FlatfileListener) { _workbookIds: string[], _tick: TickFunction ) => { - await createDataChecklist(event) + await createDataChecklist(event.context.spaceId) } ) ) diff --git a/plugins/space-configure/src/utils/data.checklist.ts b/plugins/space-configure/src/utils/data.checklist.ts index 8e5537da7..34db12259 100644 --- a/plugins/space-configure/src/utils/data.checklist.ts +++ b/plugins/space-configure/src/utils/data.checklist.ts @@ -1,11 +1,8 @@ -import { FlatfileClient } from '@flatfile/api' -import { FlatfileEvent } from '@flatfile/listener' +import { Flatfile, FlatfileClient } from '@flatfile/api' const api = new FlatfileClient() -export const createDataChecklist = async (event: FlatfileEvent) => { - const { spaceId } = event.context - +export const createDataChecklist = async (spaceId: Flatfile.SpaceId) => { const { data: workbooks } = await api.workbooks.list({ spaceId }) let body = `
\n`