Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.32.2](https://github.com/filestack/filestack-js/compare/v3.32.1...v3.32.2) (2024-06-14)
* **picker:** Upgraded picker to v1.27.3.
* **fromSources:** Fixed declaring the custom source at first place in fromSources array

## [3.32.1](https://github.com/filestack/filestack-js/compare/v3.32.0...v3.32.1) (2024-05-30)
* **miemtypes:** Fixed support for vsdx file using through accept params

## [3.32.0](https://github.com/filestack/filestack-js/compare/v3.31.0...v3.32.0) (2024-04-03)

### Updgrade
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ Polyfills we recommend:**
Module (for bundling):
* https://babeljs.io/docs/en/babel-polyfill

Script (for script tag):
* https://polyfill.io/v3/polyfill.min.js?features=Promise%2CSymbol%2CSymbol.iterator%2CArray.from%2CObject.assign%2CNumber.isFinite%2CString.prototype.includes

## Development

Expand Down Expand Up @@ -239,7 +237,6 @@ If you're using [Sentry](https://sentry.io/welcome/) to monitor your application
## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags](https://github.com/filestack/filestack-js/tags) on this repository.

## Contributing

We follow the [conventional commits](https://conventionalcommits.org/) specification to ensure consistent commit messages and changelog formatting.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filestack-js",
"version": "3.32.0",
"version": "3.32.2",
"description": "Official JavaScript library for Filestack",
"main": "build/main/index.js",
"module": "build/module/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @private
*/
const PICKER_VERSION = '1.27.1';
const PICKER_VERSION = 'beta';

/**
* @private
Expand Down
2 changes: 2 additions & 0 deletions src/lib/api/upload/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class File {

public uploadTags: UploadTags;

public alt: string;

constructor(private readonly _file: FileInstance, private readonly _sanitizeOptions?: SanitizeOptions) {
this._file.name = sanitizeName(this._file.name, this._sanitizeOptions);
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/api/upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface UploadOptions {
* @memberof UploadOptions
*/
tags?: UploadTags;

altText?: string;
}

export type StoreUploadOptions = StoreBaseParams & {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/api/upload/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ export class Upload extends EventEmitter {
* Upload single file
*
* @param {(InputFile)} file
* @param {(string)} altText
* @returns {Promise<any>}
* @memberof Upload
*/
async upload(input: InputFile): Promise<any> {
async upload(input: InputFile, altText?: string): Promise<any> {

const f = await getFile(input, this.sanitizerOptions);
f.customName = this.overrideFileName;
if (altText) {
f.alt = altText;
}

this.uploader.addFile(f);

this.startProgressInterval();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/api/upload/uploaders/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export class S3Uploader extends UploaderAbstract {
location_url: payload.location_url,
upload_id: payload.upload_id,
region: payload.region,
alt: payload.file.alt,
};

if (this.uploadMode === UploadMode.INTELLIGENT || (this.uploadMode === UploadMode.FALLBACK && fiiFallback)) {
Expand Down Expand Up @@ -687,7 +688,7 @@ export class S3Uploader extends UploaderAbstract {
return FsRequest.post(
`${this.getUploadUrl(id)}/multipart/complete`,
{
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii'], true),
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii', 'alt'], true),
// method specific keys
filename: payload.file.name,
mimetype: payload.file.type,
Expand Down
27 changes: 25 additions & 2 deletions src/lib/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,30 @@ describe('client', () => {

expect(Upload.prototype.setToken).toHaveBeenCalledWith(token);
expect(Upload.prototype.setSecurity).toHaveBeenCalledWith(defaultSecurity);
expect(Upload.prototype.upload).toHaveBeenCalledWith(file);
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, undefined);
});

it('should be able to upload file with alt text', async () => {
const client = new Client(defaultApikey);
const file = 'anyFile';
const uploadOptions = {
altText: 'alt',
};
const storeOptions = {};
const token = {};

jest.spyOn(Upload.prototype, 'upload').mockImplementation(() => Promise.resolve());

await client.upload(file, uploadOptions, storeOptions, token, defaultSecurity);

expect(Upload.prototype.setSession).toHaveBeenCalledWith({
apikey: defaultApikey,
urls: sessionURls,
});

expect(Upload.prototype.setToken).toHaveBeenCalledWith(token);
expect(Upload.prototype.setSecurity).toHaveBeenCalledWith(defaultSecurity);
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, uploadOptions.altText);
});

it('should be able to upload file without token and security', async () => {
Expand All @@ -228,7 +251,7 @@ describe('client', () => {
urls: sessionURls,
});

expect(Upload.prototype.upload).toHaveBeenCalledWith(file);
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, undefined);
});

it('should emit error', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class Client extends EventEmitter {
this.emit('upload.error', e);
});

return upload.upload(file);
return upload.upload(file, options.altText);
}

/**
Expand Down
20 changes: 19 additions & 1 deletion src/lib/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export interface PickerFileMetadata {
* The Filestack CDN URL for the uploaded file.
*/
url: string;
/**
* Alt text for images
*/
alt: string;
}

export interface CustomAuthTextOptions {
Expand Down Expand Up @@ -683,6 +687,10 @@ export interface PickerOptions {
* Specify options for images passed to the crop UI.
*/
transformations?: PickerTransformationOptions;
/**
* Whether to use the new transformations UI. Defaults to `false`.
*/
useNewTransformer?: boolean;
/**
* Options for local file uploads.
*/
Expand Down Expand Up @@ -779,7 +787,17 @@ class PickerLoader {
const validateRes = getValidator(PickerParamsSchema)(options);

if (validateRes.errors.length) {
throw new FilestackError(`Invalid picker params`, validateRes.errors, FilestackErrorType.VALIDATION);
validateRes.errors.forEach(error => {
if (error.path.includes('fromSources')) {
console.warn(`Warning: Invalid source \"${error.instance}\" found and removed!`);
options.fromSources = options.fromSources.filter(source => source !== error.instance);
} else {
throw new FilestackError(`Invalid picker params`, validateRes.errors, FilestackErrorType.VALIDATION);
}
});
if (!options.fromSources.length) {
delete options.fromSources;
}
}

this._initialized = this.loadModule(client, options);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export const ExtensionsMap = {
'image/jls': ['jls'],
'image/jp2': ['jp2', 'jpg2'],
'image/jpeg': ['jpeg', 'jpg', 'jpe'],
'image/jpg': ['jpeg', 'jpg', 'jpe'],
'image/jpm': ['jpm'],
'image/jpx': ['jpx', 'jpf'],
'image/jxr': ['jxr'],
Expand Down Expand Up @@ -640,6 +641,7 @@ export const ExtensionsMap = {
'application/vnd.uoml+xml': ['uoml'],
'application/vnd.vcx': ['vcx'],
'application/vnd.visio': ['vsd', 'vst', 'vss', 'vsw'],
'application/vnd.ms-visio.drawing.main+xml': ['vsdx'],
'application/vnd.visionary': ['vis'],
'application/vnd.vsf': ['vsf'],
'application/vnd.wap.wbxml': ['wbxml'],
Expand Down Expand Up @@ -929,6 +931,8 @@ export const ExtensionsMap = {
'video/x-ms-wmx': ['wmx'],
'video/x-ms-wvx': ['wvx'],
'video/vnd.avi': ['avi'],
'video/x-msvideo': ['avi'],
'video/avi': ['avi'],
'video/x-sgi-movie': ['movie'],
'video/x-smv': ['smv'],
'x-conference/x-cooltalk': ['ice'],
Expand Down
65 changes: 36 additions & 29 deletions src/schema/picker.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,39 @@ export const PickerParamsSchema = {
},
fromSources: {
type: 'array',
items: [
{
type: ['string', 'object'],
additionalProperties: false,
enum: [
'local_file_system',
'url',
'imagesearch',
'facebook',
'instagram',
'googledrive',
'unsplash',
'dropbox',
'webcam',
'video',
'audio',
'box',
'github',
'gmail',
'googlephotos',
'onedrive',
'onedriveforbusiness',
'clouddrive',
'googlephotos',
'customsource',
'tint',
],
},
],
items: {
anyOf: [
{
type: 'string',
enum: [
'local_file_system',
'url',
'imagesearch',
'facebook',
'instagram',
'googledrive',
'picasa',
'unsplash',
'dropbox',
'webcam',
'video',
'audio',
'box',
'github',
'gmail',
'googlephotos',
'onedrive',
'onedriveforbusiness',
'clouddrive',
'customsource',
'tint',
],
},
{
type: 'object',
},
],
},
},
container: {
format: 'HTMLContainer',
Expand Down Expand Up @@ -439,6 +443,9 @@ export const PickerParamsSchema = {
useSentryBreadcrumbs: {
type: 'boolean',
},
useNewTransformer: {
type: 'boolean',
},
pasteMode: {
type: 'object',
additionalProperties: false,
Expand Down
4 changes: 4 additions & 0 deletions src/schema/upload.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ export const UploadParamsSchema = {
maxlength: 256,
},
},
altText: {
type: ['string', 'null'],
maxLength: 60,
},
},
};