Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atlaskit/media-store

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlaskit/media-store - npm Package Compare versions

Comparing version 1.0.8 to 2.0.0

3

CHANGELOG.md
# @atlaskit/media-store
## 2.0.0
- [major] FileDetails' `id` property is now mandatory\nAuth interfaces moves from media-core to media-store, though still exported from media-core\nNew Interfaces (UploadableFile, UploadFileCallbacks) are exported from media-store\nMediaStore calls fixed with collection supplied during auth-provider call [d7b5021](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/d7b5021)
## 1.0.8

@@ -4,0 +7,0 @@

3

dist/es2015/index.d.ts
export { MediaStore } from './media-store';
export { MediaFile } from './models/media';
export { uploadFile } from './uploader';
export { Auth, ClientBasedAuth, isClientBasedAuth, AsapBasedAuth, isAsapBasedAuth, AuthContext, AuthProvider, MediaApiConfig, ContextConfig } from './models/auth';
export { uploadFile, UploadableFile, UploadFileCallbacks } from './uploader';
export { MediaStore } from './media-store';
export { isClientBasedAuth, isAsapBasedAuth, } from './models/auth';
export { uploadFile } from './uploader';
//# sourceMappingURL=index.js.map

@@ -1,12 +0,8 @@

import { AuthProvider, AuthContext } from './models/auth-provider';
import { MediaFile, MediaCollection, MediaCollectionItems, MediaUpload, MediaChunksProbe } from './models/media';
import { AuthContext, MediaApiConfig } from './models/auth';
import { RequestMethod, RequestParams, RequestHeaders } from './utils/request';
export interface MediaStoreConfig {
readonly apiUrl: string;
readonly authProvider: AuthProvider;
}
export declare class MediaStore {
private readonly config;
constructor(config: MediaStoreConfig);
createCollection(name: string): Promise<MediaStoreResponse<MediaCollection>>;
constructor(config: MediaApiConfig);
createCollection(collectionName: string): Promise<MediaStoreResponse<MediaCollection>>;
getCollection(collectionName: string): Promise<MediaStoreResponse<MediaCollection>>;

@@ -56,3 +52,3 @@ getCollectionItems(collectionName: string, params: MediaStoreGetCollectionItemsPrams): Promise<MediaStoreResponse<MediaCollectionItems>>;

readonly version?: number;
readonly collection?: number;
readonly collection?: string;
readonly width?: number;

@@ -59,0 +55,0 @@ readonly height?: number;

@@ -9,25 +9,20 @@ import * as tslib_1 from "tslib";

if (params === void 0) { params = {}; }
return _this.request("/file/" + fileId, { params: params }).then(mapResponseToJson);
return _this.request("/file/" + fileId, {
params: params,
authContext: { collectionName: params.collection },
}).then(mapResponseToJson);
};
this.getFileImageURL = function (id, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
_a = createUrl;
_b = [this.config.apiUrl + "/file/" + id + "/image"];
_c = {
params: params
};
return [4 /*yield*/, this.config.authProvider()];
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([(_c.auth = _d.sent(),
_c)]))];
}
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, createUrl(this.config.serviceHost + "/file/" + id + "/image", {
params: params,
})];
});
}); };
}
MediaStore.prototype.createCollection = function (name) {
MediaStore.prototype.createCollection = function (collectionName) {
return this.request('/collection', {
method: 'POST',
body: JSON.stringify({ name: name }),
body: JSON.stringify({ name: collectionName }),
authContext: { collectionName: collectionName },
headers: {

@@ -41,2 +36,3 @@ 'Content-Type': 'application/json',

return this.request("/collection/" + collectionName, {
authContext: { collectionName: collectionName },
headers: {

@@ -49,2 +45,3 @@ Accept: 'application/json',

return this.request("/collection/" + collectionName + "/items", {
authContext: { collectionName: collectionName },
params: params,

@@ -90,2 +87,3 @@ headers: {

method: 'POST',
authContext: { collectionName: params.collection },
params: params,

@@ -114,7 +112,7 @@ body: JSON.stringify(body),

return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, apiUrl, authProvider, method, authContext, params, headers, body, auth;
var _a, serviceHost, authProvider, method, authContext, params, headers, body, auth;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.config, apiUrl = _a.apiUrl, authProvider = _a.authProvider;
_a = this.config, serviceHost = _a.serviceHost, authProvider = _a.authProvider;
method = options.method, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body;

@@ -124,3 +122,3 @@ return [4 /*yield*/, authProvider(authContext)];

auth = _b.sent();
return [2 /*return*/, request("" + apiUrl + path, {
return [2 /*return*/, request("" + serviceHost + path, {
method: method,

@@ -127,0 +125,0 @@ auth: auth,

@@ -12,1 +12,15 @@ export interface ClientBasedAuth {

export declare function isAsapBasedAuth(auth: Auth): auth is AsapBasedAuth;
export interface ContextConfig {
readonly serviceHost: string;
readonly cacheSize?: number;
readonly authProvider: AuthProvider;
readonly userAuthProvider?: AuthProvider;
}
export interface AuthContext {
readonly collectionName?: string;
}
export declare type AuthProvider = (context?: AuthContext) => Promise<Auth>;
export declare type MediaApiConfig = {
serviceHost: string;
authProvider: AuthProvider;
};
import { ChunkinatorFile } from 'chunkinator';
import { MediaStoreConfig } from './media-store';
import { MediaApiConfig } from './models/auth';
export declare type UploadableFile = {

@@ -9,5 +9,5 @@ content: ChunkinatorFile;

};
export declare type Callbacks = {
export declare type UploadFileCallbacks = {
onProgress: (progress: number) => void;
};
export declare const uploadFile: (file: UploadableFile, config: MediaStoreConfig, callbacks?: Callbacks | undefined) => Promise<string>;
export declare const uploadFile: (file: UploadableFile, config: MediaApiConfig, callbacks?: UploadFileCallbacks | undefined) => Promise<string>;

@@ -5,3 +5,2 @@ var _this = this;

import * as Rusha from 'rusha';
import * as PQueue from 'p-queue';
import { MediaStore } from './media-store';

@@ -36,3 +35,4 @@ // TODO: Replace custom FileReader by Rusha.createHash().update(blob)

export var uploadFile = function (file, config, callbacks) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var content, collection, name, mimeType, store, deferredUploadId, uploadingFunction, offset, queue, uploadId, fileId;
var _this = this;
var content, collection, name, mimeType, store, deferredUploadId, uploadingFunction, offset, processingFunction, uploadId, fileId;
return tslib_1.__generator(this, function (_a) {

@@ -50,3 +50,20 @@ switch (_a.label) {

offset = 0;
queue = new PQueue({ concurrency: 1 });
processingFunction = function (chunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = (_a = store).appendChunksToUpload;
return [4 /*yield*/, deferredUploadId];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
chunks: hashedChunks(chunks),
offset: offset,
}])];
case 2:
_c.sent();
offset += chunks.length;
return [2 /*return*/];
}
});
}); };
return [4 /*yield*/, chunkinator(content, {

@@ -58,34 +75,11 @@ hashingFunction: hashingFunction,

uploadingConcurrency: 3,
progressBatchSize: 1000,
uploadingFunction: uploadingFunction,
probingFunction: createProbingFunction(store),
processingBatchSize: 1000,
processingFunction: processingFunction,
}, {
onProgress: function (progress, chunks) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
queue.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = (_a = store).appendChunksToUpload;
return [4 /*yield*/, deferredUploadId];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
chunks: hashedChunks(chunks),
offset: offset,
}])];
case 2:
_c.sent();
offset += chunks.length;
return [2 /*return*/];
}
});
}); });
if (callbacks && callbacks.onProgress) {
callbacks.onProgress(progress);
}
return [2 /*return*/];
});
});
onProgress: function (progress) {
if (callbacks && callbacks.onProgress) {
callbacks.onProgress(progress);
}
},

@@ -95,5 +89,5 @@ })];

_a.sent();
return [4 /*yield*/, Promise.all([deferredUploadId, queue.onIdle()])];
return [4 /*yield*/, deferredUploadId];
case 2:
uploadId = (_a.sent())[0];
uploadId = _a.sent();
return [4 /*yield*/, store.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, {

@@ -100,0 +94,0 @@ collection: collection,

@@ -8,2 +8,10 @@ import * as tslib_1 from "tslib";

var _a = options.method, method = _a === void 0 ? 'GET' : _a, auth = options.auth, params = options.params, headers = options.headers, body = options.body;
var processFetchResponse = function (response) {
if (response.ok || response.redirected) {
return response;
}
else {
throw response;
}
};
if (method === 'GET') {

@@ -14,3 +22,3 @@ return fetch(createUrl(url, { params: params, auth: auth }), {

headers: headers,
});
}).then(processFetchResponse);
}

@@ -22,3 +30,3 @@ else {

headers: withAuth(auth)(headers),
});
}).then(processFetchResponse);
}

@@ -25,0 +33,0 @@ }

export { MediaStore } from './media-store';
export { MediaFile } from './models/media';
export { uploadFile } from './uploader';
export { Auth, ClientBasedAuth, isClientBasedAuth, AsapBasedAuth, isAsapBasedAuth, AuthContext, AuthProvider, MediaApiConfig, ContextConfig } from './models/auth';
export { uploadFile, UploadableFile, UploadFileCallbacks } from './uploader';

@@ -5,4 +5,7 @@ "use strict";

exports.MediaStore = media_store_1.MediaStore;
var auth_1 = require("./models/auth");
exports.isClientBasedAuth = auth_1.isClientBasedAuth;
exports.isAsapBasedAuth = auth_1.isAsapBasedAuth;
var uploader_1 = require("./uploader");
exports.uploadFile = uploader_1.uploadFile;
//# sourceMappingURL=index.js.map

@@ -1,12 +0,8 @@

import { AuthProvider, AuthContext } from './models/auth-provider';
import { MediaFile, MediaCollection, MediaCollectionItems, MediaUpload, MediaChunksProbe } from './models/media';
import { AuthContext, MediaApiConfig } from './models/auth';
import { RequestMethod, RequestParams, RequestHeaders } from './utils/request';
export interface MediaStoreConfig {
readonly apiUrl: string;
readonly authProvider: AuthProvider;
}
export declare class MediaStore {
private readonly config;
constructor(config: MediaStoreConfig);
createCollection(name: string): Promise<MediaStoreResponse<MediaCollection>>;
constructor(config: MediaApiConfig);
createCollection(collectionName: string): Promise<MediaStoreResponse<MediaCollection>>;
getCollection(collectionName: string): Promise<MediaStoreResponse<MediaCollection>>;

@@ -56,3 +52,3 @@ getCollectionItems(collectionName: string, params: MediaStoreGetCollectionItemsPrams): Promise<MediaStoreResponse<MediaCollectionItems>>;

readonly version?: number;
readonly collection?: number;
readonly collection?: string;
readonly width?: number;

@@ -59,0 +55,0 @@ readonly height?: number;

@@ -11,25 +11,20 @@ "use strict";

if (params === void 0) { params = {}; }
return _this.request("/file/" + fileId, { params: params }).then(request_1.mapResponseToJson);
return _this.request("/file/" + fileId, {
params: params,
authContext: { collectionName: params.collection },
}).then(request_1.mapResponseToJson);
};
this.getFileImageURL = function (id, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
_a = request_1.createUrl;
_b = [this.config.apiUrl + "/file/" + id + "/image"];
_c = {
params: params
};
return [4 /*yield*/, this.config.authProvider()];
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([(_c.auth = _d.sent(),
_c)]))];
}
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, request_1.createUrl(this.config.serviceHost + "/file/" + id + "/image", {
params: params,
})];
});
}); };
}
MediaStore.prototype.createCollection = function (name) {
MediaStore.prototype.createCollection = function (collectionName) {
return this.request('/collection', {
method: 'POST',
body: JSON.stringify({ name: name }),
body: JSON.stringify({ name: collectionName }),
authContext: { collectionName: collectionName },
headers: {

@@ -43,2 +38,3 @@ 'Content-Type': 'application/json',

return this.request("/collection/" + collectionName, {
authContext: { collectionName: collectionName },
headers: {

@@ -51,2 +47,3 @@ Accept: 'application/json',

return this.request("/collection/" + collectionName + "/items", {
authContext: { collectionName: collectionName },
params: params,

@@ -92,2 +89,3 @@ headers: {

method: 'POST',
authContext: { collectionName: params.collection },
params: params,

@@ -116,7 +114,7 @@ body: JSON.stringify(body),

return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, apiUrl, authProvider, method, authContext, params, headers, body, auth;
var _a, serviceHost, authProvider, method, authContext, params, headers, body, auth;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.config, apiUrl = _a.apiUrl, authProvider = _a.authProvider;
_a = this.config, serviceHost = _a.serviceHost, authProvider = _a.authProvider;
method = options.method, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body;

@@ -126,3 +124,3 @@ return [4 /*yield*/, authProvider(authContext)];

auth = _b.sent();
return [2 /*return*/, request_1.request("" + apiUrl + path, {
return [2 /*return*/, request_1.request("" + serviceHost + path, {
method: method,

@@ -129,0 +127,0 @@ auth: auth,

@@ -12,1 +12,15 @@ export interface ClientBasedAuth {

export declare function isAsapBasedAuth(auth: Auth): auth is AsapBasedAuth;
export interface ContextConfig {
readonly serviceHost: string;
readonly cacheSize?: number;
readonly authProvider: AuthProvider;
readonly userAuthProvider?: AuthProvider;
}
export interface AuthContext {
readonly collectionName?: string;
}
export declare type AuthProvider = (context?: AuthContext) => Promise<Auth>;
export declare type MediaApiConfig = {
serviceHost: string;
authProvider: AuthProvider;
};
import { ChunkinatorFile } from 'chunkinator';
import { MediaStoreConfig } from './media-store';
import { MediaApiConfig } from './models/auth';
export declare type UploadableFile = {

@@ -9,5 +9,5 @@ content: ChunkinatorFile;

};
export declare type Callbacks = {
export declare type UploadFileCallbacks = {
onProgress: (progress: number) => void;
};
export declare const uploadFile: (file: UploadableFile, config: MediaStoreConfig, callbacks?: Callbacks | undefined) => Promise<string>;
export declare const uploadFile: (file: UploadableFile, config: MediaApiConfig, callbacks?: UploadFileCallbacks | undefined) => Promise<string>;

@@ -7,3 +7,2 @@ "use strict";

var Rusha = require("rusha");
var PQueue = require("p-queue");
var media_store_1 = require("./media-store");

@@ -38,3 +37,4 @@ // TODO: Replace custom FileReader by Rusha.createHash().update(blob)

exports.uploadFile = function (file, config, callbacks) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var content, collection, name, mimeType, store, deferredUploadId, uploadingFunction, offset, queue, uploadId, fileId;
var _this = this;
var content, collection, name, mimeType, store, deferredUploadId, uploadingFunction, offset, processingFunction, uploadId, fileId;
return tslib_1.__generator(this, function (_a) {

@@ -52,3 +52,20 @@ switch (_a.label) {

offset = 0;
queue = new PQueue({ concurrency: 1 });
processingFunction = function (chunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = (_a = store).appendChunksToUpload;
return [4 /*yield*/, deferredUploadId];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
chunks: hashedChunks(chunks),
offset: offset,
}])];
case 2:
_c.sent();
offset += chunks.length;
return [2 /*return*/];
}
});
}); };
return [4 /*yield*/, chunkinator_1.default(content, {

@@ -60,34 +77,11 @@ hashingFunction: hashingFunction,

uploadingConcurrency: 3,
progressBatchSize: 1000,
uploadingFunction: uploadingFunction,
probingFunction: createProbingFunction(store),
processingBatchSize: 1000,
processingFunction: processingFunction,
}, {
onProgress: function (progress, chunks) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
queue.add(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = (_a = store).appendChunksToUpload;
return [4 /*yield*/, deferredUploadId];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
chunks: hashedChunks(chunks),
offset: offset,
}])];
case 2:
_c.sent();
offset += chunks.length;
return [2 /*return*/];
}
});
}); });
if (callbacks && callbacks.onProgress) {
callbacks.onProgress(progress);
}
return [2 /*return*/];
});
});
onProgress: function (progress) {
if (callbacks && callbacks.onProgress) {
callbacks.onProgress(progress);
}
},

@@ -97,5 +91,5 @@ })];

_a.sent();
return [4 /*yield*/, Promise.all([deferredUploadId, queue.onIdle()])];
return [4 /*yield*/, deferredUploadId];
case 2:
uploadId = (_a.sent())[0];
uploadId = _a.sent();
return [4 /*yield*/, store.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, {

@@ -102,0 +96,0 @@ collection: collection,

@@ -10,2 +10,10 @@ "use strict";

var _a = options.method, method = _a === void 0 ? 'GET' : _a, auth = options.auth, params = options.params, headers = options.headers, body = options.body;
var processFetchResponse = function (response) {
if (response.ok || response.redirected) {
return response;
}
else {
throw response;
}
};
if (method === 'GET') {

@@ -16,3 +24,3 @@ return fetch(createUrl(url, { params: params, auth: auth }), {

headers: headers,
});
}).then(processFetchResponse);
}

@@ -24,3 +32,3 @@ else {

headers: withAuth(auth)(headers),
});
}).then(processFetchResponse);
}

@@ -27,0 +35,0 @@ }

{
"name": "@atlaskit/media-store",
"version": "1.0.7",
"version": "1.0.8",
"sideEffects": false
}
{
"name": "@atlaskit/media-store",
"version": "1.0.8",
"version": "2.0.0",
"description": "Media Store API Web Client Library",

@@ -22,4 +22,3 @@ "license": "Apache-2.0",

"@types/query-string": "^4.3.1",
"chunkinator": "^0.0.15",
"p-queue": "^2.3.0",
"chunkinator": "^1.0.1",
"query-string": "^4.3.2",

@@ -29,3 +28,3 @@ "rusha": "^0.8.13"

"devDependencies": {
"@atlaskit/media-test-helpers": "^12.0.0",
"@atlaskit/media-test-helpers": "^12.0.3",
"@types/fetch-mock": "^5.12.1",

@@ -32,0 +31,0 @@ "@types/p-queue": "^2.3.1",

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

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

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