Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@
"optionalDependencies": {
"@flatfile/changelog": "^1.0.3",
"@rollup/rollup-linux-x64-gnu": "^4.8.0"
},
"dependencies": {
"@flatfile/api": "^1.13.0"
}
}
Empty file.
81 changes: 81 additions & 0 deletions plugins/space-configure-from-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!-- START_INFOCARD -->

The `@flatfile/plugin-space-configure-from-template` plugin streamlines the setup of a new Flatfile Space from a Space Template.

**Event Type:**
`listener.on('space:configure')`

<!-- END_INFOCARD -->


> When embedding Flatfile, this plugin should be deployed in a server-side listener. [Learn more](/docs/orchestration/listeners#listener-types)


## Parameters

#### `callback` - `function`

The `callback` parameter receives three arguments: `event`, `workbookIds`, and a `tick` function. The `tick` function can be used to update the Job's progress. The `callback` function is invoked once the Space and Workbooks are fully configured.


## API Calls

- `api.spaces.update`
- `api.workbooks.create`
- `api.documents.create`



## Usage

The `@flatfile/plugin-space-configure-from-template` plugin simplifies the setup of a new Flatfile Space from a Space Template.

Designed for server-side listeners, it auto-configures the Space using the supplied settings.

#### Install

```bash install
npm i @flatfile/plugin-space-configure-from-template
```

#### Example

#### `listener.ts`

```typescript listener.ts
import { configureSpaceFromTemplate } from "@flatfile/plugin-space-configure-from-template";

export default function (listener: FlatfileListener) {
listener.use(configureSpaceFromTemplate());
}
```


## Example with Callback

#### `listener.ts`

```typescript listener.ts
import api from "@flatfile/api";
import type { FlatfileListener } from "@flatfile/listener";
import { configureSpaceFromTemplate } from "@flatfile/plugin-space-configure-from-template";
import { contactsSheet } from "./contactsSheet";
import { companiesSheet } from "./companiesSheet";

export default function (listener: FlatfileListener) {
listener.use(
configureSpaceFromTemplate(
async (event, workbookIds, tick) => {
const { spaceId } = event.context;
// Callback is invoked once the Space and Workbooks are fully configured.
// Job progress will be at 50% when the callback is invoked.
tick(51, "Running callback!");

// Do something...

await tick(99, "Callback complete!");
}
)
);
}
```
76 changes: 76 additions & 0 deletions plugins/space-configure-from-template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@flatfile/plugin-space-configure-from-template",
"version": "0.0.1",
"url": "https://github.com/FlatFilers/flatfile-plugins/tree/main/plugins/space-configure-from-template",
"description": "A plugin for configuring a Flatfile Space from a Space Template.",
"registryMetadata": {
"category": "core"
},
"type": "module",
"engines": {
"node": ">= 18"
},
"exports": {
".": {
"node": {
"types": {
"import": "./dist/index.d.ts",
"require": "./dist/index.d.cts"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"browser": {
"types": {
"import": "./dist/index.d.ts",
"require": "./dist/index.d.cts"
},
"import": "./dist/index.browser.js",
"require": "./dist/index.browser.cjs"
},
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
"scripts": {
"build": "tsup",
"build:watch": "tsup --watch",
"build:prod": "NODE_ENV=production tsup",
"checks": "tsc --noEmit && attw --pack . && publint .",
"lint": "tsc --noEmit",
"test": "vitest run --mode defaults src/*.spec.ts --passWithNoTests",
"test:unit": "vitest run --mode defaults src/*.spec.ts --passWithNoTests --exclude src/*.e2e.spec.ts",
"test:e2e": "vitest run --mode defaults src/*.e2e.spec.ts --passWithNoTests --no-file-parallelism"
},
"keywords": [
"flatfile-plugins",
"category-core"
],
"author": "Flatfile, Inc.",
"repository": {
"type": "git",
"url": "git+https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "plugins/space-configure-from-template"
},
"license": "ISC",
"dependencies": {
"@flatfile/plugin-job-handler": "^0.8.1"
},
"peerDependencies": {
"@flatfile/api": "^1.9.19",
"@flatfile/listener": "^1.1.0"
},
"devDependencies": {
"@flatfile/api": "^1.9.19",
"@flatfile/bundler-config-tsup": "^0.2.0",
"@flatfile/config-vitest": "^0.0.0",
"@flatfile/utils-testing": "^0.5.0"
}
}
1 change: 1 addition & 0 deletions plugins/space-configure-from-template/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './space.configure.from.template'
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { FlatfileClient } from '@flatfile/api'
import {
deleteSpace,
setupDriver,
setupSpace,
TestListener,
} from '@flatfile/utils-testing'
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
vi,
} from 'vitest'
import { configureSpaceFromTemplate } from '.'

const api = new FlatfileClient()

describe('SpaceConfigureFromTemplate plugin e2e tests', () => {
const mockFn = vi.fn()
const listener = new TestListener()
const driver = setupDriver()
let spaceId: string

beforeAll(async () => {
await driver.start()
listener.mount(driver)

listener.use(configureSpaceFromTemplate(mockFn))

const space = await setupSpace()
spaceId = space.id
})

afterAll(async () => {
await deleteSpace(spaceId)

driver.shutdown()
})

beforeEach(() => {
listener.resetCount()
})

afterEach(() => {
listener.reset()
})

it.skip('should configure a space & run callback', async () => {
await listener.waitFor('job:ready', 1, 'space:configure')

const space = await api.spaces.get(spaceId)
const workspace = await api.workbooks.get(space.data.primaryWorkbookId!)

// expect(workspace.data.name).toBe(setup.workbooks[0].name)
// expect(workspace.data.labels).toMatchObject(setup.workbooks[0].labels!)
// expect(workspace.data.sheets![0].name).toBe(
// setup.workbooks[0].sheets![0].name
// )
// expect(workspace.data.sheets![0].config).toMatchObject(
// setup.workbooks[0].sheets![0]
// )
// expect(workspace.data.actions).toMatchObject(setup.workbooks[0].actions!)
// expect(mockFn).toHaveBeenCalled()
})
})
Loading