Skip to content

Commit

Permalink
refactor(uploads) Move to new upload system with application/json pay…
Browse files Browse the repository at this point in the history
…loads

* test(jest): move intagration tests to other repo and add unit test with jest

* refactor(request): move superagent to axios

* refactor(tests): add more unit tests

* test(network): Add tests to uplaod start

* test(network): Add unit tests for complete method

* test(store): update store test for cancel method

* fix(cloud): Add cancel method to clouds using token

* fix(resolveHostFix): Fix iteration object in resolveHost

* refactor(uploads): refactor uploads, update build script

* refactor(upload/fallbac): Add multipart true when fallback is enabled

* refactor(uploads): Update progress method

* refactor(upload): Cleanup upload class

* refactor(uploads): Fix fallback mode for files below 5mb

* refactor(uploads): Add better cleanup after upload

* refactor(uploads): Do not store chunks in memory

* refactor(uploads): lower p-queue version, fix file library get slice method

* refactor(fix intelligent size header):

* refactor(uploads): cleanup

* test(file_utils): add file utils test, split test to envs

* fix(api/file): Fix params in file reuqests

* test(uploads): Add tests to main upload class

* test(uploaders/s3): add basic tests

* test(uploader/s3): Add tests to uplaoders/s3 class (wip)

* test(Uploaders/s3): Refactor tests, Add ii tests

* test(uploader/s3): Add more units

* test(uploader/s3): Fix store/workflows option

* test(request): add request units, update request to support application/json format instead of multi

* test(uploads): Add missing units, replace error with FilestackError

* refactor(pickeropiotns): remove preferlinkoverstorage option

* refactor(cloudClient): remove link option

* build(codecov): add code cov to repo

* docs(README): Add codecov badge to readme

* docs(README): Update readme file

* refactor(uploads): Move uploads to new backend

* feat(SRI): Add sri manifest.json and update README

* docs(README): Update readme -> sri description

* refactor(uploads): change multipart to ffi param

* ci(codeconv): add codeconv config to repo

* refactor(trace-id): comment for now

* fix(uploads/fii): send fii field in upload

* test(upload/fii): Update tests with fii support

* refactor(uploads, validation): update uploads response, move security and storeOptions to json schem

* refactor(validation): replace tcomb params validation with jsonschema

* refactor(tcomb-validation): remove tcomb-validation and replace it with json schema

* refactor(uploads/validation): add validation to uploads and tests for it

* fix(uploadSchema): add missing filename

* fix(pickerSchema): add filename to picker schema

* test(pickerSchema): add tests to picker schema

* fix(sanitizer): fix sanitizer "\" in regexp

* test(utils): remove only keyword

* test(all): Update tests for filelink, uploader/s3

* fix(uploader/s3): do not change oryginal store options/ copy it befre removing filenmae

* docs(cleanup): cleanup docs in new files

* refactor(upload/s3): change copy function to obj.assign

* refactor(validator): Update html element validator

* test(FilestackError): add tests for filestack error

* refactor(uploads): move store options under store param

* refactor(utils): update base64 function to work in both envs

* refactor(pr): fixes from pr

* test(security): add tests for security

* refactor(upload): change name from get/set host to url

* feat(filestack/debug): add debug for filestack headers

* fix(file_tools): Fix isSvg in browser

* refactor(cleanup): cleanup methods, change codeconv percent

* docs(releases): Add detailed releases description

* docs(README.md): add information about releases

* docs(releases_notes): fix typo, move examples to correct pleace

* test(cleanup): remove only from tests

* fix(sanitizeOptions): pass sanitize options to uploader

* docs(release-notes): refactor sanitize section

* docs(release-notes): add line break

* test(sanitizer): add tests to sanitizer

* fix(schema): move sanitizer to correct schema

* refactor(schema): remove sanitizer from upload schema

* test(upload): add sanitizer check

* refactor(ie): Fix require in ie

* test(utils): add tests to requireNode

* refactor(utils): add one more safety condition to requireNode

* fix(memoryleak): Fix memory leak in cancel token (axios)

* fix(uploader/s3): move cleaning cancelToken to last promise

* refactor(upload/s3): Standarize errors

* feat(eventemmiter): add event emmiter with error to upload stack

* feat(FilestackError): Add error types

* test(cloud): refactor cloud units

* refactor(upload/s3): change complete method call

* refactor(upload/s3): revert complete request after each file

* refactor(types): remove retry event

* feat(picker): add imageMinMaxBlock option

* feat(picker): add force param to picker transformations

* refactor(filelink): add "," to escape chars in filelink

* feat(picker): Add viewType option to schema, update picker types

* test(cloud): fix wrong promise

* docs(release-notes): Add info about escaping , in storeUrl

* docs(release-notes): Update release notes - add picker fixed issues

* docs(readme): update readme polyfils seciton

* feat(picker): bump picker version
  • Loading branch information
pcholuj authored May 30, 2019
1 parent ce77599 commit a8b496f
Show file tree
Hide file tree
Showing 113 changed files with 15,220 additions and 13,289 deletions.
8 changes: 8 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
codecov:
notify:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "99...100"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ coverage
*.log
.env
.nyc_output
.stats.json
.DS_Store

# VS Code
.vscode
!.vscode/tasks.js
!.vscode/tasks.js
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ tsconfig.json
tslint.json
.travis.yml
.github
.codecov.yml
.stats.json
build/temp
build/docs

Expand Down
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"printWidth" : 180,
"parser": "typescript",
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ git:
submodules: false
depth: 1

addons:
firefox: latest
chrome: stable

before_install:
- npm i -g npm@latest

after_success:
- npm run test:codecov

env:
global:
- secure: uveWmRaiGKxKAYEP86LTSGmTmUvIXqBi0uNai087MDKvzdPuMQZSay3DSN9MLxAskbch1OjKoRCpkKy+z6tJsQL5z8tptpEcI5mD7LJU8U2akskEXANgqH8nPjqC0YPMPU2y8gWSLd/y22VaIKsF8WxXmVpjc57EXrXQtSqCUI9PI3cnyw9eqcv6Pf+3iXLEL4nr+ORvq+bQgEYk8U6ME+49KULRz+R4VhltZxy5F7T0vFEpAyRfsVYyKBwPss1NXE/M+EMqECRgTyXe1+roDO+DFHP+L0qrOrNEbjJSY5iYDfYOIfdtNYz6rvSbTl9jmsLYphb/BJy4eEB1DV38/K3WJ510gi0n3lWgFPlZB9Wh3S7LXQh4yieHbB2ddWYtX6IP9LNeNpdn/vgJwmuNyiAYsEdeqYdPSUynJ50RlwDVCLd4GkB5qpMBjMgtfXiY4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gmEsCWQlTFiEbnieb2xxTMNrzl1WsrtANC9aQTeWVsNcW8xtDA/aQYefaQykOjHPJyyWaiLeBZ9Te0nMD7SeCSQUVywLT77saQJfsnHiCIKvv4lk+rvi6hQypAjBSznFwBa+Zkgk6y5DjT0SDhYXUVY3Kb8AJDFhgIwRlz74/ST9lGuEGnOjHZcQfqarbhcgbg8/HrsPP+spZwa4h0eRPNHfSDmrxTFDZXYDkULeLFPheMkvKKSqq0O+QdMmaL7hPuNWmEQINQg+quxHTjj/ldolL9Vb5db2zMu/jAYGmPDqQOk3GCilUcT4Eh64NmwEShfPY3VMuO/Weg37MJaFNX2efcKxCRWthpwEApqg/4GSk2Qeev7TY/mKkxNFXiXjMwjrXpobEtbQf4Kdy/vpyNE1YtxGiXBsSMMheMeDcVG2ryxaMNcKEyB2uncKqMH3jCU2lDJ/xoJfLmx2+FgxlrTtISl424lshQitWPU9co+FzBnXfyyZILxjsJZSzzZXe3ppWqAg=
32 changes: 15 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*
* Copyright (c) ${year} by Filestack.
* Some rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
Copyright (c) ${year} by Filestack.
Some rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

143 changes: 100 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,129 @@
<p align="center">
<strong>Javascript SDK for the Filestack API and content management system.</strong>
</p>
<p align="center">
<a href="https://codecov.io/gh/filestack/filestack-js">
<img src="https://codecov.io/gh/filestack/filestack-js/branch/master/graph/badge.svg" />
</a>

<a href="https://travis-ci.org/filestack/filestack-js">
<img src="https://travis-ci.org/filestack/filestack-js.svg?branch=master" />
</a>
</p>
<p align="center">
<a href="https://npmjs.com/package/filestack-js"><img src="https://img.shields.io/npm/v/filestack-js.svg" /></a>
<a href="https://static.filestackapi.com/filestack-js/2.x.x/filestack.min.js"><img src="https://img.badgesize.io/https://static.filestackapi.com/filestack-js/2.x.x/filestack.min.js?compression=gzip&color=green" /></a>
<a href="https://static.filestackapi.com/filestack-js/2.x.x/filestack.min.js"><img src="https://img.badgesize.io/https://static.filestackapi.com/filestack-js/2.x.x/filestack.min.js?color=green" /></a>
<a href="https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js"><img src="https://img.badgesize.io/https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js?compression=gzip&color=green" /></a>
<a href="https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js"><img src="https://img.badgesize.io/https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js?color=green" /></a>
<img src="https://img.shields.io/badge/module%20formats-umd%2C%20esm%2C%20cjs-green.svg" />
<br/>
<img src="https://badges.herokuapp.com/browsers?labels=none&googlechrome=latest&firefox=latest&microsoftedge=latest&iexplore=11&safari=latest&iphone=latest" />
</p>
<hr/>

**Table of Contents**

<!-- toc -->
- [What's in the box?](#whats-in-the-box)
- [Installation](#installation)
- [API Documentation](#api-documentation)
- [Usage](#usage)
- [Browsers](#browsers)
- [ES module](#es-module)
- [UMD module](#umd-module)
- [GZIP support](#gzip-support)
- [SRI](#sri)
- [Node](#node)
- [CommonJS module](#commonjs-module)
- [Module Overview](#module-overview)
- [Releases Info](#releases-info)
- [Live examples (JSFiddle)](#live-examples-jsfiddle)
- [Picker Quick Start](#picker-quick-start)
- [Promises](#promises)
- [Development](#development)
- [Debugging](#debugging)
- [Node](#node-1)
- [Browser](#browser)
- [Versioning](#versioning)
- [Contributing](#contributing)


## What's in the box?

* A multi-part uploader powered on the backend by the [Filestack CIN](https://www.filestack.com/products/content-ingestion-network).
* An interface to the [Filestack Processing Engine](https://www.filestack.com/docs/image-transformations) for transforming assets via URLs.
* The Filestack Picker - an upload widget for the web that integrates over a dozen cloud providers and provides pre-upload image editing.


## Installation

```sh
npm install filestack-js
```

## API Documentation

[https://filestack.github.io/filestack-js/](https://filestack.github.io/filestack-js/)

## Usage

### Browsers

**ES module**:
#### ES module
```js
import * as filestack from 'filestack-js';
const client = filestack.init('apikey');
```

**UMD module**:
#### UMD module
```HTML
<script src="//static.filestackapi.com/filestack-js/{MAJOR_VERSION}.x.x/filestack.min.js"></script>
<script src="//static.filestackapi.com/filestack-js/{MAJOR_VERSION}.x.x/filestack.min.js" crossorigin="anonymous"></script>
<script>
const client = filestack.init('apikey');
</script>
```

where VERSION is one of the MAJOR versions of the filestack-js ie:
where ```{MAJOR_VERSION}``` is one of the MAJOR versions of the filestack-js ie:
```HTML
<script src="//static.filestackapi.com/filestack-js/2.x.x/filestack.min.js"></script>
<script src="//static.filestackapi.com/filestack-js/3.x.x/filestack.min.js" crossorigin="anonymous"></script>
<script>
const client = filestack.init('apikey');
</script>
```

**GZIP support**
#### GZIP support
To speed up library loading you can use gzipped file available after adding gz to file extension
```HTML
To speed up library loading you can use gzipped file available after adding gz before the file extension

<script src="//static.filestackapi.com/filestack-js/{MAJOR_VERSION}.x.x/filestack.min.gz.js"></script>
<script src="//static.filestackapi.com/filestack-js/{MAJOR_VERSION}.x.x/filestack.min.js.gz" crossorigin="anonymous"></script>
<script>
const client = filestack.init('apikey');
</script>
```

#### SRI
Subresource Integrity (SRI) is a security feature that enables browsers to verify that files they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched file must match

To obtain sri hashes for filestack-js library check manifest.json file on CDN:

```
https://static.filestackapi.com/filestack-js/{LIBRARY_VERSION}/manifest.json
```

```HTML
<script src="//static.filestackapi.com/filestack-js/{LIBRARY_VERSION}/filestack.min.js.gz" integrity="{FILE_HASH}" crossorigin="anonymous"></script>
```

Where ```{LIBRARY_VERSION}``` is currently used library version and ```{FILE_HASH}``` is one of the hashes from integrity field in manifest.json file


### Node

**CommonJS module**:
#### CommonJS module
```js
const client = require('filestack-js').init('apikey');
```

### Module Overview

## Module Overview

The `package.json` specifies two separate modules:

Expand All @@ -79,8 +137,13 @@ Node projects which depend on filestack-js will follow the `main` field in `pack

The pre-bundled browser module is also available in UMD format. This is useful if you are using script tags on a web page instead of bundling your application. It can be retrieved from both the Filestack CDN and the unpkg CDN:

* [Filestack CDN](https://static.filestackapi.com/filestack-js/1.x.x/filestack.min.js)
* [unpkg](https://unpkg.com/[email protected])
* [Filestack CDN](https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js)
* [unpkg](https://unpkg.com/[email protected])

## Releases Info

Major releases will bo listed (with detailed examples) in releases folder starting from version 3.0.0


## Live examples (JSFiddle)

Expand Down Expand Up @@ -114,58 +177,52 @@ The picker instance returned from `client.picker` can be controlled with a few m

Please see our examples above to learn more about customizing the picker for your use case.

## API Documentation

[https://filestack.github.io/filestack-js/](https://filestack.github.io/filestack-js/)

### Promises
## Promises

This library requires an environment that implements the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object spec.
If you target IE11 or iOS before 8.0 you will need to add a `Promise` polyfill to your page or application.
If you target IE11 or iOS before 8.0 you will need to add a `Promise` and `Symbol` polyfill to your page or application.

**Polyfills we recommend:**
Polyfills we recommend:**

Module (for bundling):
* https://github.com/taylorhakes/promise-polyfill
* https://babeljs.io/docs/en/babel-polyfill

Script (for script tag):
* https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise
* https://polyfill.io/v3/polyfill.min.js?features=Promise%2CPromise.prototype.finally%2CSymbol

## Development

Most tests in this library are expected to interface with actual backend services. Because we like to run tests during development, these services are mocked
during unit testing.
Most tests in this library are expected to interface with actual backend services. Because we like to run tests during development, these services are mocked during unit testing.

All tests are using Mocha. Browser tests are run with Karma.
All tests are using Jest.

To run units:

```
npm test
```

To run integration tests:
## Debugging

```
npm run test:integration
Filestack-js uses [`debug`](https://github.com/visionmedia/debug), so just run with environmental variable `DEBUG` set to `fs.*`.

### Node
```js
DEBUG=fs.* node example_upload.js
```

Integration tests require a `.env` file in the root of your project with the following fields:
### Browser
Debug's enable state is persisted by localStorage

```js
localStorage.debug = 'fs:*'
```
BROWSERSTACK_USERNAME=
BROWSERSTACK_ACCESS_KEY=
TEST_APIKEY=
TEST_CLOUD_APIKEY=
TEST_INTELLIGENT_APIKEY=
TEST_SECURE_APIKEY=
TEST_SIGNATURE=
TEST_POLICY=
TEST_FILELINK=
TEST_SECURE_FILELINK=
```

You will need to acquire this data from a Filestack developer if you plan on running the integration suite.
And then refresh the page.

## 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

Expand Down
1 change: 0 additions & 1 deletion examples/transform/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ window.addEventListener('DOMContentLoaded', function () {
}
);


const img = document.createElement('img');
img.src = src.toString();

Expand Down
36 changes: 36 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
name: 'filestack-js',
collectCoverage: true,
clearMocks: true,
projects: [{
displayName: 'Common',
clearMocks: true,
testMatch: ['<rootDir>/src/**/*.spec.ts'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
}, {
displayName: 'Node',
clearMocks: true,
testMatch: ['<rootDir>/src/**/*.spec.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testMatch: ['<rootDir>/src/**/*.spec.node.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
}, {
displayName: 'Browser',
testMatch: ['<rootDir>/src/**/*.browser.spec.ts'],
clearMocks: true,
testEnvironment: 'jsdom',
setupFiles: ['jest-localstorage-mock'],
testMatch: ['<rootDir>/src/**/*.spec.browser.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
}]
};
Loading

0 comments on commit a8b496f

Please sign in to comment.