npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arteneo/forge-uppy

v3.0.1

Published

Forge Uppy

Downloads

21

Readme

Future plans

When uploading an image and could not refresh token anymore via RefreshToken we get 401 and uppy error, but it is not shown in UppyError component.

When using UppySingleDragDropImage and you cancel an upload, image should revert to previous one (or empty if it will be very hard to do). Probably the same case with UppySingleInputFile.

help flag is not tested with UppySingleDragDropImage.

Some kind of onChange prop for BaseUpload (which means UppySingleDragDropImage and UppySingleFile will also have it).

Branches

You can use following branches:

  1. main (default) - branch for current version 3.x
  2. v2 - branch for version 2.x

Restrictions

Uppy documentation: https://uppy.io/docs/uppy/#restrictions

Max file size

Maximum file size in bytes for each individual file.

const options = {
    restrictions: {
        // 500 kb
        maxFileSize: 500 * 1024,
    },
};

Allowed file types

Array of wildcards image/*, exact mime types image/jpeg, or file extensions .jpg.

const options = {
    restrictions: {
        allowedFileTypes: ["image/*", ".jpg", ".jpeg", ".png", ".gif"],
    },
};

Note! Allowed file types will also be used in hidden file input (in accept HTML attribute). This means selecting a file from your PC will also be restricted (i.e. Chrome is actually hiding not accepted files).

Access and refresh tokens (JWT)

We can pass additional options in uppyTusOptions to add access token to headers and use refresh token when needed.

Example implementation in utilities/uppy.tsx as follows.

import { TusOptions } from "@uppy/tus";
import { DetailedError } from "tus-js-client";
import { getAccessToken, refreshAccessToken, updateLastAlive } from "~app/utilities/authenticationTokens";

export const uppyTusOptions: TusOptions = {
    async onBeforeRequest(req) {
        const accessToken = await getAccessToken();
        req.setHeader("Authorization", "Bearer " + accessToken);
    },
    onShouldRetry(err, retryAttempt, options, next) {
        if ((err as DetailedError)?.originalResponse?.getStatus() === 401) {
            return true;
        }

        return next(err);
    },
    async onAfterResponse(req, res) {
        if (res.getStatus() === 401) {
            await refreshAccessToken();
            updateLastAlive();
        }
    },
};

Explanation for internal functions:

  1. getAccessToken - Returns access token (as a string)
  2. refreshAccessToken - Refreshes access token using refresh token
  3. updateLastAlive - Application specific, can be used to keep alive session

Example usage:

import React from "react";
import { getFields } from "@arteneo/forge";
import { UploadSingleDragDropImage } from "@arteneo/forge-uppy";
import { uppyTusOptions } from "~app/utilities/uppy";

type FieldName = "image";

const fields = {
    image: <UploadSingleDragDropImage {...{ uppyTusOptions }} />,
};

export default (names?: FieldName[]) => getFields<FieldName>(names, fields);
export { FieldName };

Translations

Did not find a good solution to handle translations within Uppy. In our case it applies only to errors emitted by Restrictor (restriction of number of files, file sizes or file types). It seems that we need to prepare translation files specifically for Uppy if we want different translations. Uppy uses internal Translator with has different variable syntax and probably different pluralization.

More on translations:

https://uppy.io/docs/locales/

Development

  1. Install dependencies using npm install.
  2. Build package using npm run build.
  3. Update version in package.json.
  4. Commit and push changes.
  5. Publish package using npm publish.