Skip to content
Draft
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
256 changes: 83 additions & 173 deletions apps/getting-started/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,185 +2,95 @@ import api from '@flatfile/api'
import { FlatfileListener } from '@flatfile/listener'

export default function (listener: FlatfileListener) {
listener.namespace(['*:red'], (red) => {
red.filter({ job: 'space:configure' }, (configure) => {
configure.on(
'job:ready',
async ({ context: { spaceId, environmentId, jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: 'Gettin started.',
progress: 10,
})
listener.filter({ job: 'space:configure' }, (configure) => {
configure.on(
'job:ready',
async ({ context: { spaceId, environmentId, jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: 'Getting started.',
progress: 10,
})

await api.workbooks.create({
spaceId,
environmentId,
name: 'Red',
labels: ['primary'],
// namespace: 'red',
sheets: [
{
name: 'Red Contacts',
slug: 'contacts',
fields: [
{
key: 'firstName',
type: 'string',
label: 'First Name',
},
{
key: 'lastName',
type: 'string',
label: 'Last Name',
},
{
key: 'email',
type: 'string',
label: 'Email',
},
],
actions: [
{
operation: 'duplicate',
mode: 'background',
label: 'Duplicate Sheet',
type: 'string',
description:
'Duplicate this Sheet and lock down the original.',
primary: true,
},
],
},
],
actions: [
{
operation: 'submitActionFg',
mode: 'foreground',
label: 'Submit foreground',
type: 'string',
description: 'Submit data to webhook.site',
primary: true,
},
],
})

await api.documents.create(spaceId, {
title: 'Getting Started',
body:
'# Welcome\n' +
'### Say hello to your first customer Space in the new Flatfile!\n' +
"Let's begin by first getting acquainted with what you're seeing in your Space initially.\n" +
'---\n',
})

await api.jobs.complete(jobId, {
outcome: {
message: 'This job is now complete.',
await api.workbooks.create({
spaceId,
environmentId,
name: 'Contacts',
labels: ['primary'],
sheets: [
{
name: 'Contacts',
slug: 'contacts',
fields: [
{
key: 'firstName',
type: 'string',
label: 'First Name',
},
{
key: 'lastName',
type: 'string',
label: 'Last Name',
},
{
key: 'email',
type: 'string',
label: 'Email',
},
],
actions: [
{
operation: 'duplicate',
mode: 'background',
label: 'Duplicate Sheet',
type: 'string',
description:
'Duplicate this Sheet and lock down the original.',
primary: true,
},
],
},
})
} catch (error) {
console.error('Error:', error.stack)

await api.jobs.fail(jobId, {
outcome: {
message: 'This job encountered an error.',
],
actions: [
{
operation: 'submitActionFg',
mode: 'foreground',
label: 'Submit foreground',
type: 'string',
description: 'Submit data to webhook.site',
primary: true,
},
})
}
}
)
})
})

listener.namespace(['space:green'], (green) => {
green.filter({ job: 'space:configure' }, (configure) => {
configure.on(
'job:ready',
async ({ context: { spaceId, environmentId, jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: 'Gettin started.',
progress: 10,
})
],
})

await api.workbooks.create({
spaceId,
environmentId,
name: 'Green',
labels: ['primary'],
sheets: [
{
name: 'Green Contacts',
slug: 'contacts',
// namespace: 'green',
fields: [
{
key: 'firstName',
type: 'string',
label: 'First Name',
},
{
key: 'lastName',
type: 'string',
label: 'Last Name',
},
{
key: 'email',
type: 'string',
label: 'Email',
},
],
actions: [
{
operation: 'duplicate',
mode: 'background',
label: 'Duplicate Sheet',
type: 'string',
description:
'Duplicate this Sheet and lock down the original.',
primary: true,
},
],
},
],
actions: [
{
operation: 'submitActionFg',
mode: 'foreground',
label: 'Submit foreground',
type: 'string',
description: 'Submit data to webhook.site',
primary: true,
},
],
})
await api.documents.create(spaceId, {
title: 'Getting Started',
body:
'# Welcome\n' +
'### Say hello to your first customer Space in the new Flatfile!\n' +
"Let's begin by first getting acquainted with what you're seeing in your Space initially.\n" +
'---\n',
})

await api.documents.create(spaceId, {
title: 'Getting Started',
body:
'# Welcome\n' +
'### Say hello to your first customer Space in the new Flatfile!\n' +
"Let's begin by first getting acquainted with what you're seeing in your Space initially.\n" +
'---\n',
})
await api.jobs.complete(jobId, {
outcome: {
message: 'This job is now complete.',
},
})
} catch (error) {
console.error('Error:', error.stack)

await api.jobs.complete(jobId, {
outcome: {
message: 'This job is now complete.',
},
})
} catch (error) {
console.error('Error:', error.stack)

await api.jobs.fail(jobId, {
outcome: {
message: 'This job encountered an error.',
},
})
}
await api.jobs.fail(jobId, {
outcome: {
message: 'This job encountered an error.',
},
})
}
)
})
}
)
})

listener.on("**", async (record) => {
console.log("Event -> ", record.topic)
})
}
6 changes: 5 additions & 1 deletion apps/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"scripts": {
"develop": "flatfile develop index.ts",
"deploy": "flatfile deploy index.ts",
"paginate": "flatfile develop paginate-records.ts"
"paginate": "flatfile develop paginate-records.ts",
"flatfile": "flatfile",
"logs": "aws logs tail /aws/lambda/agent_us_ag_1oz3Oy4N --follow --region us-west-2",
"spaces:list": "flatfile api spaces list",
"workbooks:get": "flatfile api workbooks get 'us_wb_ewnlxUPw'"
},
"keywords": [],
"author": "",
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
node = "18.16"
Loading
Loading