Skip to content

Commit

Permalink
Merge branch 'main' into 334-refactor-yaml-plugin-to-match-json-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
madaley1 committed Nov 29, 2023
2 parents cadae42 + 4e872b8 commit bdd0958
Show file tree
Hide file tree
Showing 10 changed files with 13,894 additions and 3,071 deletions.
5 changes: 0 additions & 5 deletions .changeset/few-yaks-fetch.md

This file was deleted.

16,884 changes: 13,849 additions & 3,035 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions plugins/job-handler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @flatfile/plugin-job-handler

## 0.1.6

### Patch Changes

- 3d31680: Display Modal instead of a Toast on Job error

## 0.1.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion plugins/job-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flatfile/plugin-job-handler",
"version": "0.1.5",
"version": "0.1.6",
"description": "A plugin for handling Flatfile Jobs.",
"registryMetadata": {
"category": "core"
Expand Down
1 change: 1 addition & 0 deletions plugins/job-handler/src/job.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function jobHandler(
outcome ?? {
info: String(error.message),
outcome: {
acknowledge: true,
message: String(error.message),
},
}
Expand Down
12 changes: 12 additions & 0 deletions plugins/record-hook/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @flatfile/plugin-record-hook

## 1.1.14

### Patch Changes

- 920df43: This update handles caching of record messages.

## 1.1.13

### Patch Changes

- f18a889: Human-readable errors from recordHook

## 1.1.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion plugins/record-hook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flatfile/plugin-record-hook",
"version": "1.1.12",
"version": "1.1.14",
"description": "A plugin for writing custom record-level hooks in Flatfile.",
"registryMetadata": {
"category": "records"
Expand Down
43 changes: 16 additions & 27 deletions plugins/record-hook/src/RecordHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,41 @@ export const BulkRecordHook = async (
const fetchData = async () => {
try {
const data = await event.data
return data.records && data.records.length
? prepareXRecords(data.records)
: undefined
return data.records && data.records.length ? data.records : undefined
} catch (e) {
console.log(`Error fetching records: ${e}`)
}
}

try {
const batch = await event.cache.init<FlatfileRecords<any>>(
'records',
const originalRecords = await event.cache.init<Flatfile.Record_[]>(
'originalRecords',
fetchData
)

if (!batch || batch.records.length === 0) {
if (!originalRecords || originalRecords.length === 0) {
if (options.debug) {
console.log('No records to process')
}
await completeCommit()
return
}

await event.cache.init<FlatfileRecords<any>>('originalRecords', fetchData)
const batch = await event.cache.init<FlatfileRecords<any>>(
'records',
async () => await prepareXRecords(originalRecords)
)

// Execute client-defined data hooks
await asyncBatch(batch.records, handler, options, event)

event.afterAll(async () => {
const batch = event.cache.get<FlatfileRecords<any>>('records')
const { records } = event.cache.get<FlatfileRecords<any>>('records')
const batch = new RecordTranslator<FlatfileRecord>(records).toXRecords()
const originalRecords =
event.cache.get<FlatfileRecords<any>>('originalRecords')
const modifiedRecords = batch.records.filter((record) =>
hasRecordChanges(record, originalRecords.records)
event.cache.get<Flatfile.Record_[]>('originalRecords')
const modifiedRecords = batch.filter((record) =>
hasRecordChanges(record, originalRecords)
)
if (!modifiedRecords || modifiedRecords.length === 0) {
if (options.debug) {
Expand All @@ -120,12 +122,8 @@ export const BulkRecordHook = async (
return
}

const recordsUpdates = new RecordTranslator<FlatfileRecord>(
modifiedRecords
).toXRecords()

try {
return await event.update(recordsUpdates)
return await event.update(modifiedRecords)
} catch (e) {
console.log(`Error updating records: ${e}`)
}
Expand All @@ -144,16 +142,7 @@ const hasRecordChanges = (record, originalRecords) => {
return JSON.stringify(record) !== JSON.stringify(originalRecord)
}

const prepareXRecords = (records: any): FlatfileRecords<any> => {
const clearedMessages: Flatfile.Record_[] = records.map(
(record: { values: { [x: string]: { messages: never[] } } }) => {
// clear existing cell validation messages
Object.keys(record.values).forEach((k) => {
record.values[k].messages = []
})
return record
}
)
const fromX = new RecordTranslator<Flatfile.Record_>(clearedMessages)
const prepareXRecords = async (records: any): Promise<FlatfileRecords<any>> => {
const fromX = new RecordTranslator<Flatfile.Record_>(records)
return fromX.toFlatFileRecords()
}
6 changes: 6 additions & 0 deletions plugins/space-configure/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @flatfile/plugin-space-configure

## 0.1.7

### Patch Changes

- 91662e0: Dependency update

## 0.1.6

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions plugins/space-configure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flatfile/plugin-space-configure",
"version": "0.1.6",
"version": "0.1.7",
"description": "A plugin for configuring a Flatfile Space.",
"registryMetadata": {
"category": "core"
Expand Down Expand Up @@ -29,6 +29,6 @@
"dependencies": {
"@flatfile/api": "^1.5.37",
"@flatfile/listener": "^0.3.17",
"@flatfile/plugin-job-handler": "^0.1.5"
"@flatfile/plugin-job-handler": "^0.1.6"
}
}

0 comments on commit bdd0958

Please sign in to comment.