![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@flatfile/sdk
Advanced tools
npm install @flatfile/sdk --save
flatfileImporter(**token**
)
(GitHub)
const importer = flatfileImporter("<%= token %>");
Name | Type |
---|---|
token | string |
The token
parameter is a JSON Web Token (JWT) generated for a given end user. The JWT should be generated on the application server to prevent dissemination of your private key. The JWT is signed using the the Embed ID of the Flatfile embed (created on the dashboard), the Private Key (also provided on the dashboard, but only available once during the creation of the embed), and an identifier for the end user (an email or other ID).
// Example token generation in Node.js:
const jwt = require("jsonwebtoken");
const EMBED_ID = "YOUR_EMBED_ID";
const PRIVATE_KEY = "YOUR_PRIVATE_KEY";
const token = await jwt.sign(
{
embed: EMBED_ID,
sub: currentUser.email, // a unique identifier such as an id or email
},
PRIVATE_KEY
);
Note: The below snippet is for testing purposes only. This is not safe to use in your production application, but can be useful when testing out for the first time.
// Example token generation in the browser *unsafe*
import { flatfileImporter } from "@flatfile/sdk";
const importer = flatfileImporter("");
await importer.__unsafeGenerateToken({
privateKey: "YOUR_PRIVATE_KEY",
embedId: "YOUR_EMBED_ID",
endUserEmail: "max@mail.com",
});
importer.launch();
The sub
field is unique to each end user. This unique identification allows Flatfile to continue an import after an interruption and reduce upload abandonment. For more information on this unique identifier.
Launches the Flatfile Importer inside of an iFrame by calling openInIframe
(GitHub).
await importer.launch();
Destroys the flatfileImporter.
The following events will be emitted to the client.
Returns a batchId
unique to the end user the token was generated for. This allows uploads to be continued after an interruption (such as a user closing a browser tab) and can be used to request data from the Flatfile API.
importer.on('init', ({ batchId }) => {
console.log(`ImportSession ${batchId} has been initialized.`)
})
Returns the same batchId
generated during initialization (see above) that is unique to the end user the token was generated for. This allows uploads to be continued after an interruption (such as a user closing a browser tab) and can be used to request data from the Flatfile API.
importer.on("launch", ({ batchId }) => {
console.log(`ImportSession ${batchId} has been launched.`);
});
Returns a JavaScript error object.
importer.on("error", (error) => {
console.error(error);
});
Returns a payload with a copy of the validated data from the upload.
importer.on("complete", async (payload) => {
console.log(JSON.stringify(await payload.data(), null, 4));
});
FAQs
Flatfile SDK
We found that @flatfile/sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 26 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.