Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JSON Schema implementation #294

Merged
merged 14 commits into from
Nov 6, 2023
Merged

Conversation

carlbrugger
Copy link
Contributor

@carlbrugger carlbrugger commented Nov 1, 2023

Guide: FlatFilers/Guides#940
Kitchen Sink: FlatFilers/flatfile-docs-kitchen-sink#32

This PR introduces the @flatfile/plugin-convert-json-schema plugin to configure a Flatfile Space based on a provided JSON Schema (draft 2020-12).

Basic Usage

listener.use(
  configureSpaceWithJsonSchema(
    [{ sourceUrl:'https://example.com/customer.schema.json' }]
  )
)

Advanced Usage

const workbookActions: Flatfile.Action[] = [
  {
    operation: 'submitAction',
    mode: 'foreground',
    label: 'Submit data',
    type: 'string',
    description: 'Submit this data to a webhook.',
    primary: true,
  },
  {
    operation: 'downloadWorkbook',
    mode: 'foreground',
    label: 'Download Workbook',
    description: 'Downloads Excel Workbook of Data',
  },
]

const sheetActions: Flatfile.Action[] = [
  {
    operation: 'duplicateSheet',
    mode: 'foreground',
    label: 'Duplicate',
    description: 'Duplicate this sheet.',
    primary: true,
  },
]

const customerModel: PartialSheetConfig = {
  slug: 'customer',
  name: 'Customer',
  actions: sheetActions,
}
const personModel: PartialSheetConfig = {
  slug: 'person',
  name: 'Person',
  actions: sheetActions,
}

const workbookConfig: PartialWorkbookConfig = { actions: workbookActions }

const callback = async (event, workbookIds, tick) => {
  const { spaceId } = event.context
  await api.documents.create(spaceId, {
    title: 'Welcome',
    body: `<div>
    <h1>Welcome!</h1>
    <h2>To get started, follow these steps:</h2>
    <h2>1. Step One</h2>
    <p>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.</p>
    <h3>Remember, if you need any assistance, you can always refer back to this page by clicking "Welcome" in the left-hand sidebar!</h3>
    </div>`,
  })
  await tick(80, 'Document created')
}

listener.use(
  configureSpaceWithJsonSchema(
    [
      {
        sourceUrl: 'https://example.com/customer.schema.json',
        ...customerModel,
      },
      { sourceUrl: 'https://example.com/person.schema.json', ...personModel },
    ],
    { workbookConfig, debug: true },
    callback
  )
)

const model: PartialSheetConfig = { slug: 'model2', name: 'Addresses', actions: sheetActions }

const workbookConfig: PartialWorkbookConfig = { actions: workbookActions }

const callback = async (event, workbookIds, tick) => {
  const { spaceId } = event.context
  await api.documents.create(spaceId, {
    title: 'Welcome',
    body: `<div>
      <h1>Welcome!</h1>
      <h2>To get started, follow these steps:</h2>
      <h2>1. Step One</h2>
      <p>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.</p>
      <h3>Remember, if you need any assistance, you can always refer back to this page by clicking "Welcome" in the left-hand sidebar!</h3>
      </div>`,
  })
  await tick(80, 'Document created')
}

listener.use(
  configureSpaceWithJsonSchema(
    'https://example.com/customer.schema.json',
    { model, workbookConfig },
    callback
  )
)

Closes #136

@carlbrugger carlbrugger self-assigned this Nov 1, 2023
Copy link

socket-security bot commented Nov 1, 2023

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
express 4.18.2 network, filesystem +39 1.08 MB dougwilson
@hyperjump/json-schema 1.6.4 network, environment +9 1.78 MB jason.desrosiers

@madaley1 madaley1 marked this pull request as ready for review November 1, 2023 23:58
@carlbrugger carlbrugger merged commit 7d34a17 into main Nov 6, 2023
3 checks passed
@carlbrugger carlbrugger deleted the feat/json-schema-implementation branch November 6, 2023 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@flatfile/plugin-jsonschema-converter
3 participants