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

Configure Space with YAML Plugin #312

Merged
merged 31 commits into from
Nov 16, 2023
Merged

Conversation

madaley1
Copy link
Contributor

@madaley1 madaley1 commented Nov 7, 2023

Guide: https://flatfile.com/docs/plugins/schemas/convert-yaml-schema

Kitchen Sink: WIP

This PR introduces the @flatfile/plugin-convert-yaml-schema plugin to configure a Flatfile Space based on a provided YAML Schema. The usage for this plugin closely mirrors @flatfile/plugin-convert-json-schema.

Basic Usage

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

Advanced Usage

import api, { Flatfile } from "@flatfile/api";
import type { FlatfileEvent, FlatfileListener } from "@flatfile/listener";
import {
  ModelToSheetConfig,
  PartialWorkbookConfig,
  configureSpaceWithYamlSchema,
} from "@flatfile/plugin-convert-yaml-schema";

export default function (listener: FlatfileListener) {
  const workbookActions: Flatfile.Action[] = [
    {
      operation: "submitActionFg",
      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 callback = async (
    event: FlatfileEvent,
    workbookIds: string[],
    tick: (progress?: number, message?: string) => Promise<Flatfile.JobResponse>
  ) => {
    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(
    configureSpaceWithYamlSchema(
      [
        {
          sourceUrl:
            "https://raw.githubusercontent.com/FlatFilers/flatfile-docs-kitchen-sink/main/typescript/fetch-schemas/example-schemas/yaml/person.yml",
          name: "Custom Person Sheet Name",
          actions: sheetActions,
        },
        {
          sourceUrl:
            "https://raw.githubusercontent.com/FlatFilers/flatfile-docs-kitchen-sink/main/typescript/fetch-schemas/example-schemas/yaml/product.yml",
        },
      ] as ModelToSheetConfig[],
      {
        workbookConfig: {
          name: "Custom YAML Schema Workbook Name",
          actions: workbookActions,
        } as PartialWorkbookConfig,
        debug: true,
      },
      callback
    )
  );
}

Closes: No associated Issue or Track.

plugins/json-schema/README.md Outdated Show resolved Hide resolved
plugins/json-schema/package.json Outdated Show resolved Hide resolved
plugins/yaml-schema/CHANGELOG.md Show resolved Hide resolved
plugins/yaml-schema/README.md Outdated Show resolved Hide resolved
plugins/yaml-schema/package.json Outdated Show resolved Hide resolved
plugins/yaml-schema/src/setup.factory.ts Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/test-server/server.ts Outdated Show resolved Hide resolved
@madaley1 madaley1 enabled auto-merge (squash) November 7, 2023 14:56
@madaley1
Copy link
Contributor Author

madaley1 commented Nov 7, 2023

Want to put a note here, the failing tests are due to the zip-extractor plugin, I'll probably figure out what's wrong with it in another PR.

Edit: Tests passing locally, not sure why they're failing here

@madaley1
Copy link
Contributor Author

madaley1 commented Nov 7, 2023

After rerunning the tests in debug they're passing. I wonder if it's something with async timing since the tests are somewhat slower when debug is enabled?

plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts Outdated Show resolved Hide resolved
utils/testing/src/server.ts Show resolved Hide resolved
plugins/yaml-schema/src/setup.factory.ts Outdated Show resolved Hide resolved
Copy link
Contributor Author

@madaley1 madaley1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some more review, I realized I jumped the gun when I removed the code from JSON schema, so this last commit undoes those changes. I feel it is best to keep JSON Schema unchanged and add the DRYed up YAML code, and then DRY up the JSON schema in a separate PR. LMK if there's a better way to do this!

@carlbrugger
Copy link
Contributor

After some more review, I realized I jumped the gun when I removed the code from JSON schema, so this last commit undoes those changes. I feel it is best to keep JSON Schema unchanged and add the DRYed up YAML code, and then DRY up the JSON schema in a separate PR. LMK if there's a better way to do this!

I agree!

plugins/yaml-schema/src/index.ts Outdated Show resolved Hide resolved
.changeset/yellow-rats-enjoy.md Outdated Show resolved Hide resolved
.changeset/yellow-rats-enjoy.md Outdated Show resolved Hide resolved
.changeset/young-bottles-thank.md Outdated Show resolved Hide resolved
plugins/json-schema/package.json Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/exampleData.yml Outdated Show resolved Hide resolved
plugins/yaml-schema/tests/yaml-schema.e2e.spec.ts Outdated Show resolved Hide resolved
madaley1 and others added 8 commits November 13, 2023 13:33
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Co-authored-by: Carl Brugger <carl.brugger@flatfile.io>
Copy link

socket-security bot commented Nov 13, 2023

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

Packages Version New capabilities Transitives Size Publisher
@flatfile/plugin-json-schema 0.0.2 None +0 872 B flatfileinfra
axios 1.6.0...1.6.1 None +0/-0 1.8 MB jasonsaayman

@madaley1
Copy link
Contributor Author

After troubleshooting this for a bit, I have realized that the reason it's failing was because this was built around the changes to JSON-schema I reverted. I was able to patch around it, but it'll take some refactoring after release when we transition json-schema to DRY it up overall.

@madaley1
Copy link
Contributor Author

Also I had to revert one of the JSON -> YAML corrections due to how the plugin uses the JSON-schema plugin and it using the default defined in JSON-Schema and it's not redefined anywhere in YAML-Schema

plugins/yaml-schema/CHANGELOG.md Outdated Show resolved Hide resolved
.changeset/yellow-rats-enjoy.md Outdated Show resolved Hide resolved
plugins/yaml-schema/src/index.ts Outdated Show resolved Hide resolved
@carlbrugger carlbrugger self-requested a review November 16, 2023 15:55
Copy link
Contributor

@carlbrugger carlbrugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@madaley1 madaley1 merged commit 0d5f2c1 into main Nov 16, 2023
4 checks passed
@madaley1 madaley1 deleted the feat/yaml-schema-implementation branch November 16, 2023 16:05
@FlatFilers FlatFilers deleted a comment from madaley1 Nov 16, 2023
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.

2 participants