Socket
Socket
Sign inDemoInstall

@uppy/provider-views

Package Overview
Dependencies
Maintainers
6
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/provider-views - npm Package Compare versions

Comparing version 3.4.1 to 3.5.0

8

CHANGELOG.md
# @uppy/provider-views
## 3.5.0
Released: 2023-08-15
Included in: Uppy v3.14.0
- @uppy/companion-client,@uppy/provider-views: make authentication optional (Dominik Schmidt / #4556)
- @uppy/provider-views: fix ProviderView error on empty plugin.icon (Dominik Schmidt / #4553)
## 3.4.1

@@ -4,0 +12,0 @@

2

lib/index.js

@@ -1,2 +0,2 @@

export { default as ProviderViews } from './ProviderView/index.js';
export { default as ProviderViews, defaultPickerIcon } from './ProviderView/index.js';
export { default as SearchProviderViews } from './SearchProviderView/index.js';

@@ -1,1 +0,1 @@

export { default } from "./ProviderView.js";
export { default, defaultPickerIcon } from "./ProviderView.js";

@@ -15,22 +15,4 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }

const packageJson = {
"version": "3.4.1"
"version": "3.5.0"
};
function getOrigin() {
// eslint-disable-next-line no-restricted-globals
return location.origin;
}
function getRegex(value) {
if (typeof value === 'string') {
return new RegExp(`^${value}$`);
}
if (value instanceof RegExp) {
return value;
}
return undefined;
}
function isOriginAllowed(origin, allowedOrigin) {
const patterns = Array.isArray(allowedOrigin) ? allowedOrigin.map(getRegex) : [getRegex(allowedOrigin)];
return patterns.some(pattern => (pattern == null ? void 0 : pattern.test(origin)) || (pattern == null ? void 0 : pattern.test(`${origin}/`))); // allowing for trailing '/'
}
function formatBreadcrumbs(breadcrumbs) {

@@ -43,2 +25,13 @@ return breadcrumbs.slice(1).map(directory => directory.name).join('/');

}
export function defaultPickerIcon() {
return h("svg", {
"aria-hidden": "true",
focusable: "false",
width: "30",
height: "30",
viewBox: "0 0 30 30"
}, h("path", {
d: "M15 30c8.284 0 15-6.716 15-15 0-8.284-6.716-15-15-15C6.716 0 0 6.716 0 15c0 8.284 6.716 15 15 15zm4.258-12.676v6.846h-8.426v-6.846H5.204l9.82-12.364 9.82 12.364H19.26z"
}));
}

@@ -231,45 +224,14 @@ /**

async handleAuth() {
await this.provider.ensurePreAuth();
const authState = btoa(JSON.stringify({
origin: getOrigin()
}));
const clientVersion = `@uppy/provider-views=${ProviderView.VERSION}`;
const link = this.provider.authUrl({
state: authState,
uppyVersions: clientVersion
});
const authWindow = window.open(link, '_blank');
const handleToken = e => {
if (e.source !== authWindow) {
this.plugin.uppy.log('rejecting event from unknown source');
return;
}
if (!isOriginAllowed(e.origin, this.plugin.opts.companionAllowedHosts) || e.source !== authWindow) {
this.plugin.uppy.log(`rejecting event from ${e.origin} vs allowed pattern ${this.plugin.opts.companionAllowedHosts}`);
}
// Check if it's a string before doing the JSON.parse to maintain support
// for older Companion versions that used object references
const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
if (data.error) {
this.plugin.uppy.log('auth aborted', 'warning');
const {
uppy
} = this.plugin;
const message = uppy.i18n('authAborted');
uppy.info({
message
}, 'warning', 5000);
return;
}
if (!data.token) {
this.plugin.uppy.log('did not receive token from auth window', 'error');
return;
}
authWindow.close();
window.removeEventListener('message', handleToken);
this.provider.setAuthToken(data.token);
try {
await this.provider.login({
uppyVersions: clientVersion
});
this.plugin.setPluginState({
authenticated: true
});
this.preFirstRender();
};
window.addEventListener('message', handleToken);
} catch (e) {
this.plugin.uppy.log(`login failed: ${e.message}`);
}
}

@@ -433,2 +395,3 @@ async handleScroll(event) {

const hasInput = filterInput !== '';
const pluginIcon = this.plugin.icon || defaultPickerIcon;
const headerProps = {

@@ -438,3 +401,3 @@ showBreadcrumbs: targetViewOptions.showBreadcrumbs,

breadcrumbs: this.plugin.getPluginState().breadcrumbs,
pluginIcon: this.plugin.icon,
pluginIcon,
title: this.plugin.title,

@@ -474,3 +437,3 @@ logout: this.logout,

showBreadcrumbs: targetViewOptions.showBreadcrumbs,
pluginIcon: this.plugin.icon,
pluginIcon,
i18n: this.plugin.uppy.i18n,

@@ -495,3 +458,3 @@ uppyFiles: this.plugin.uppy.getFiles(),

pluginName: this.plugin.title,
pluginIcon: this.plugin.icon,
pluginIcon: pluginIcon,
handleAuth: this.handleAuth,

@@ -498,0 +461,0 @@ i18n: this.plugin.uppy.i18n,

@@ -10,3 +10,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }

const packageJson = {
"version": "3.4.1"
"version": "3.5.0"
};

@@ -13,0 +13,0 @@ /**

{
"name": "@uppy/provider-views",
"description": "View library for Uppy remote provider plugins.",
"version": "3.4.1",
"version": "3.5.0",
"license": "MIT",

@@ -23,3 +23,3 @@ "main": "lib/index.js",

"dependencies": {
"@uppy/utils": "^5.4.2",
"@uppy/utils": "^5.4.3",
"classnames": "^2.2.6",

@@ -31,4 +31,4 @@ "nanoid": "^4.0.0",

"peerDependencies": {
"@uppy/core": "^3.3.1"
"@uppy/core": "^3.4.0"
}
}

@@ -1,2 +0,2 @@

export { default as ProviderViews } from './ProviderView/index.js'
export { default as ProviderViews, defaultPickerIcon } from './ProviderView/index.js'
export { default as SearchProviderViews } from './SearchProviderView/index.js'

@@ -1,1 +0,1 @@

export { default } from './ProviderView.jsx'
export { default, defaultPickerIcon } from './ProviderView.jsx'

@@ -16,21 +16,2 @@ import { h } from 'preact'

function getOrigin () {
// eslint-disable-next-line no-restricted-globals
return location.origin
}
function getRegex (value) {
if (typeof value === 'string') {
return new RegExp(`^${value}$`)
} if (value instanceof RegExp) {
return value
}
return undefined
}
function isOriginAllowed (origin, allowedOrigin) {
const patterns = Array.isArray(allowedOrigin) ? allowedOrigin.map(getRegex) : [getRegex(allowedOrigin)]
return patterns
.some((pattern) => pattern?.test(origin) || pattern?.test(`${origin}/`)) // allowing for trailing '/'
}
function formatBreadcrumbs (breadcrumbs) {

@@ -45,2 +26,10 @@ return breadcrumbs.slice(1).map((directory) => directory.name).join('/')

export function defaultPickerIcon () {
return (
<svg aria-hidden="true" focusable="false" width="30" height="30" viewBox="0 0 30 30">
<path d="M15 30c8.284 0 15-6.716 15-15 0-8.284-6.716-15-15-15C6.716 0 0 6.716 0 15c0 8.284 6.716 15 15 15zm4.258-12.676v6.846h-8.426v-6.846H5.204l9.82-12.364 9.82 12.364H19.26z" />
</svg>
)
}
/**

@@ -259,41 +248,10 @@ * Class to easily generate generic views for Provider plugins

async handleAuth () {
await this.provider.ensurePreAuth()
const authState = btoa(JSON.stringify({ origin: getOrigin() }))
const clientVersion = `@uppy/provider-views=${ProviderView.VERSION}`
const link = this.provider.authUrl({ state: authState, uppyVersions: clientVersion })
const authWindow = window.open(link, '_blank')
const handleToken = (e) => {
if (e.source !== authWindow) {
this.plugin.uppy.log('rejecting event from unknown source')
return
}
if (!isOriginAllowed(e.origin, this.plugin.opts.companionAllowedHosts) || e.source !== authWindow) {
this.plugin.uppy.log(`rejecting event from ${e.origin} vs allowed pattern ${this.plugin.opts.companionAllowedHosts}`)
}
// Check if it's a string before doing the JSON.parse to maintain support
// for older Companion versions that used object references
const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data
if (data.error) {
this.plugin.uppy.log('auth aborted', 'warning')
const { uppy } = this.plugin
const message = uppy.i18n('authAborted')
uppy.info({ message }, 'warning', 5000)
return
}
if (!data.token) {
this.plugin.uppy.log('did not receive token from auth window', 'error')
return
}
authWindow.close()
window.removeEventListener('message', handleToken)
this.provider.setAuthToken(data.token)
try {
await this.provider.login({ uppyVersions: clientVersion })
this.plugin.setPluginState({ authenticated: true })
this.preFirstRender()
} catch (e) {
this.plugin.uppy.log(`login failed: ${e.message}`)
}
window.addEventListener('message', handleToken)
}

@@ -459,2 +417,4 @@

const hasInput = filterInput !== ''
const pluginIcon = this.plugin.icon || defaultPickerIcon
const headerProps = {

@@ -464,3 +424,3 @@ showBreadcrumbs: targetViewOptions.showBreadcrumbs,

breadcrumbs: this.plugin.getPluginState().breadcrumbs,
pluginIcon: this.plugin.icon,
pluginIcon,
title: this.plugin.title,

@@ -503,3 +463,3 @@ logout: this.logout,

showBreadcrumbs: targetViewOptions.showBreadcrumbs,
pluginIcon: this.plugin.icon,
pluginIcon,
i18n: this.plugin.uppy.i18n,

@@ -523,3 +483,3 @@ uppyFiles: this.plugin.uppy.getFiles(),

pluginName={this.plugin.title}
pluginIcon={this.plugin.icon}
pluginIcon={pluginIcon}
handleAuth={this.handleAuth}

@@ -526,0 +486,0 @@ i18n={this.plugin.uppy.i18n}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc