fuse-importer 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/lib/esm/types.d.ts +4 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -261,3 +261,23 @@ importer.onSubmit = async (records) => {
|
|
|
261
261
|
};
|
|
262
262
|
};
|
|
263
263
|
```
|
|
264
|
+
|
|
265
|
+
##### Original file
|
|
266
|
+
|
|
267
|
+
`onSubmit` receives a second argument with the file the user picked, exactly as it was selected (CSV, XLS or XLSX). This is useful in Incognito Mode, where Fuse does not store your data or files: you can keep the original file in your own system, next to the records it produced.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
importer.onSubmit = async (records, { originalFile }) => {
|
|
271
|
+
const body = new FormData();
|
|
272
|
+
body.append("records", JSON.stringify(records));
|
|
273
|
+
// A File keeps its name when appended to FormData.
|
|
274
|
+
if (originalFile) body.append("original_file", originalFile);
|
|
275
|
+
|
|
276
|
+
await fetch("/your-backend/imports", { method: "POST", body });
|
|
277
|
+
|
|
278
|
+
return { message: "Data imported successfully", errors: {} };
|
|
279
|
+
};
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- `originalFile` is a [`File`](https://developer.mozilla.org/docs/Web/API/File), or `null` when the user entered the data manually. It carries the file's `name`, `size` and `type`.
|
|
283
|
+
- `onSubmit` can run more than once for the same file (for example, when the user fixes rows your backend rejected and submits again), so store the file once per import.
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -105,7 +105,10 @@ export type AppResponse = {
|
|
|
105
105
|
errors?: SpreadsheetValidationErrors;
|
|
106
106
|
message?: string;
|
|
107
107
|
};
|
|
108
|
-
export type
|
|
108
|
+
export type OnSubmitMeta = {
|
|
109
|
+
originalFile: File | null;
|
|
110
|
+
};
|
|
111
|
+
export type OnSubmit = (reviewedData: Record[], meta: OnSubmitMeta) => Promise<AppResponse>;
|
|
109
112
|
export type GetSessionToken = () => Promise<string>;
|
|
110
113
|
export type ValidationOptionKeys = "pattern" | "max_length" | "min_length" | "length" | "min" | "max" | "less_than" | "before_date" | "greater_than" | "after_date";
|
|
111
114
|
export declare const validationTypesBase: readonly ["cannot_contain", "contain", "max_length", "min_length", "length_exactly", "unique_case_sensitive", "unique_case_insensitive", "regex", "integer", "less_than", "greater_than", "even", "odd", "float", "email", "url", "boolean", "before_date", "after_date"];
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AA6CrE,MAAM,CAAN,IAAY,UAWX;AAXD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,mCAAqB,CAAA;IACrB,2BAAa,CAAA;AACf,CAAC,EAXW,UAAU,KAAV,UAAU,QAWrB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AA6CrE,MAAM,CAAN,IAAY,UAWX;AAXD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,mCAAqB,CAAA;IACrB,2BAAa,CAAA;AACf,CAAC,EAXW,UAAU,KAAV,UAAU,QAWrB;AAmGD,MAAM,CAAC,IAAM,mBAAmB,GAAG;IACjC,gBAAgB;IAChB,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,uBAAuB;IACvB,yBAAyB;IACzB,OAAO;IACP,SAAS;IACT,WAAW;IACX,cAAc;IACd,MAAM;IACN,KAAK;IACL,OAAO;IACP,OAAO;IACP,KAAK;IACL,SAAS;IACT,aAAa;IACb,YAAY;CACJ,CAAC;AAEX,MAAM,CAAC,IAAM,sBAAsB,qBAAO,mBAAmB,OAAC,CAAC;AAM/D,MAAM,CAAC,IAAM,uBAAuB,GAAG;IACrC,eAAe;IACf,YAAY;IACZ,WAAW;IACX,WAAW;IACX,iBAAiB;IACjB,YAAY;IACZ,QAAQ;IACR,oBAAoB;IACpB,OAAO;IACP,OAAO;IACP,SAAS;CACD,CAAC;AAEX,MAAM,CAAC,IAAM,0BAA0B,qBAAO,uBAAuB,OAAC,CAAC"}
|
package/package.json
CHANGED