Skip to content

Commit b48d87e

Browse files
committed
Migrate from upload-js to @bytescale/sdk
1 parent d015176 commit b48d87e

File tree

124 files changed

+25325
-25655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+25325
-25655
lines changed
File renamed without changes.
File renamed without changes.
161 KB
Loading

.github/assets/bytescale-javascript-sdk.svg

+1
Loading

.github/assets/logo.svg

-1
This file was deleted.

.github/workflows/ci.yml

+15-78
Original file line numberDiff line numberDiff line change
@@ -11,118 +11,55 @@ defaults:
1111
shell: bash
1212

1313
jobs:
14-
build:
15-
runs-on: ubuntu-22.04
16-
14+
ci:
15+
name: "Continuous Integration"
16+
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
19-
18+
- name: "Checkout code"
19+
uses: actions/checkout@v3
2020
- name: "Install node & npm"
21-
uses: actions/setup-node@v1
21+
uses: actions/setup-node@v3
2222
with:
23-
node-version: 18.x
24-
25-
- name: "Install repository dependencies"
23+
node-version: 16
24+
- name: "Install dependencies"
2625
run: npm ci
27-
28-
- name: "Upload.js (npm install)"
29-
run: npm ci
30-
working-directory: ./lib
31-
32-
- name: "Upload.js (npm pack)"
33-
run: npm pack
34-
working-directory: ./lib
35-
env:
36-
NODE_OPTIONS: --openssl-legacy-provider
37-
38-
- name: "Acceptance tests (npm install)"
39-
run:
40-
# We use 'install' rather than 'ci' due to lack of 'packages-lock.json' in this specific
41-
# project: we don't use 'packages-lock.json' because this project has a local dependency on
42-
# 'upload-js' via tarball, which is rarely rebuilt on the developers machine, making the
43-
# 'package-lock.json' often stale, causing 'npm ci' to fail. We don't mind using 'npm install'
44-
# and missing out on the hash-checks, as we don't actually publish this package, so security
45-
# isn't as much of a concern.
46-
npm install
47-
working-directory: ./examples
48-
4926
- name: "Type checks"
5027
run: npm run typecheck
51-
5228
- name: "Linting"
5329
run: npm run lint
54-
55-
- name: "Acceptance tests (start web server)"
56-
run:
57-
# Run in 'dist' mode to ensure the packaged 'uploadjs' NPM module is used,
58-
# rather than loading 'upload-js' from source (for a better end-to-end test).
59-
npm run start:dist &
60-
working-directory: ./examples
61-
env:
62-
NODE_OPTIONS: --openssl-legacy-provider
63-
64-
- name: "Documentation (npm install)"
65-
run: npm ci
66-
working-directory: ./docs
67-
68-
- name: "Verify POLYFILLS.md up-to-date"
69-
run: |
70-
npm run generate-polyfills-md
71-
changes=$(git --no-pager diff -- ../POLYFILLS.md)
72-
if [[ ! -z "$changes" ]]; then
73-
echo "Changes to POLYFILLS.md:"
74-
echo ""
75-
echo $changes
76-
echo ""
77-
echo "POLYFILLS.md needs updating!"
78-
echo ""
79-
echo "Please run the following command:"
80-
echo ""
81-
echo " (cd docs && npm run generate-polyfills-md)"
82-
echo ""
83-
exit 1
84-
fi
85-
working-directory: ./docs
86-
env:
87-
NODE_OPTIONS: --openssl-legacy-provider
88-
89-
# Note: we put other steps between the 'npm start' and the test runs, just to make time for the server to spin-up.
90-
- name: "Acceptance tests"
30+
- name: "Tests"
9131
run: npm test
92-
working-directory: ./lib
93-
32+
env:
33+
BYTESCALE_ACCOUNT_ID: ${{ secrets.BYTESCALE_ACCOUNT_ID }}
34+
BYTESCALE_SECRET_API_KEY: ${{ secrets.BYTESCALE_SECRET_API_KEY }}
9435
- name: "Publish"
9536
if: github.ref == 'refs/heads/main'
9637
env:
9738
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
9839
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
9940
AWS_EC2_METADATA_DISABLED: true
10041
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically generated by GitHub / is not in our secrets.
101-
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
102-
NODE_OPTIONS: --openssl-legacy-provider
103-
working-directory: ./lib
42+
NPM_AUTH_TOKEN: ${{ secrets.BYTESCALE_NPM_AUTH_TOKEN }}
10443
run: |
10544
npm set //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
10645
npm run publish:executeIfReleaseCommit
107-
10846
- name: "Notification on success"
10947
if: github.ref == 'refs/heads/main'
11048
uses: rtCamp/action-slack-notify@v2
11149
env:
11250
SLACK_CHANNEL: deployments
11351
SLACK_COLOR: "#17BB5E"
114-
SLACK_TITLE: "Built: upload-js :rocket:"
52+
SLACK_TITLE: "Built: bytescale-javascript-sdk :rocket:"
11553
SLACK_FOOTER: "This package was successfully built."
11654
MSG_MINIMAL: true
11755
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
118-
11956
- name: "Notification on failure"
12057
if: github.ref == 'refs/heads/main' && failure()
12158
uses: rtCamp/action-slack-notify@v2
12259
env:
12360
SLACK_CHANNEL: deployments
12461
SLACK_COLOR: "#BB1717"
125-
SLACK_TITLE: "Failed: upload-js :boom:"
62+
SLACK_TITLE: "Failed: bytescale-javascript-sdk :boom:"
12663
SLACK_FOOTER: "No packages published."
12764
MSG_MINIMAL: true
12865
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ $RECYCLE.BIN/
2323

2424
# Node.js
2525
node_modules/
26+
peer_modules/
2627
npm-debug.log*
2728

2829
# NPM Packages
2930
*.tgz
3031
dist/
3132

33+
# Serverless directories
34+
.serverless
35+
36+
# Webpack directories
37+
.webpack
38+
3239
# Standard
3340
tmp/
41+
.tmp/
3442
*.log

.husky/.gitignore

-1
This file was deleted.

.prettierignore

-3
This file was deleted.

BUILD.md

-53
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Bytescale Ltd
3+
Copyright (c) 2020 Upload Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MIGRATE.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Migration Guide
2+
3+
## From Upload.js (`upload-js`)
4+
5+
Steps:
6+
7+
1. Install `@bytescale/sdk`
8+
2. Uninstall `upload-js`
9+
3. Replace `"upload-js"` with `"@bytescale/sdk"` in your `import` statements
10+
4. Replace `Upload({ apiKey })` with `new UploadManager({ apiKey })`
11+
5. Replace `.uploadFile(file, options)` with `.upload({ data: file, ...options })`
12+
13+
### Before
14+
15+
```javascript
16+
import { Upload } from "upload-js";
17+
18+
const upload = Upload({ apiKey: "free" });
19+
20+
//
21+
// Uploading files...
22+
//
23+
const { fileUrl } = await upload.uploadFile(file, {
24+
onBegin: ({ cancel }) => {
25+
/* Optional. To cancel, you would call 'cancel()' */
26+
},
27+
...additionalParams
28+
});
29+
30+
//
31+
// Making URLs....
32+
//
33+
upload.url("/my-uploaded-image.jpg", "thumbnail");
34+
35+
//
36+
// JWT authorization...
37+
//
38+
await upload.beginAuthSession("https://my-auth-url", async () => ({ Authorization: "Bearer AuthTokenForMyApi" }));
39+
```
40+
41+
### After
42+
43+
```javascript
44+
import { AuthManager, UrlBuilder, UploadManager } from "@bytescale/sdk";
45+
46+
//
47+
// Uploading files...
48+
//
49+
const uploadManager = new UploadManager({
50+
fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js. TypeScript: 'nodeFetch as any' may be necessary.
51+
apiKey: "free" // Get API keys from: www.bytescale.com
52+
});
53+
const cancellationToken = {
54+
isCancelled: false // Set to 'true' at any point to cancel the upload.
55+
};
56+
const { fileUrl } = await uploadManager.upload({
57+
data: file,
58+
cancellationToken, // optional
59+
...additionalParams
60+
});
61+
62+
//
63+
// Making URLs...
64+
//
65+
UrlBuilder.url({
66+
accountId,
67+
filePath: "/my-uploaded-image.jpg",
68+
options: {
69+
transformation: "preset",
70+
transformationPreset: "thumbnail"
71+
}
72+
});
73+
74+
//
75+
// JWT authorization...
76+
//
77+
await AuthManager.beginAuthSession({
78+
accountId,
79+
authUrl: "https://my-auth-url",
80+
authHeaders: async () => ({ Authorization: "Bearer AuthTokenForMyApi" })
81+
});
82+
```
83+
84+
## From Upload JavaScript SDK (`upload-js-full`)
85+
86+
Steps:
87+
88+
1. Install `@bytescale/sdk`
89+
2. Uninstall `upload-js-full`
90+
3. Replace `"upload-js-full"` with `"@bytescale/sdk"` in your `import` statements
91+
4. Remove `accountId` from `uploadManager.upload({...options...})` (it's no-longer required).
92+
93+
## See also
94+
95+
Bytescale migration guides listed below:
96+
97+
- [Migrating from `upload-js` to `@bytescale/sdk`](https://github.com/bytescale/bytescale-javascript-sdk/blob/main/MIGRATE.md)
98+
- [Migrating from `uploader` to `@bytescale/upload-widget`](https://github.com/bytescale/bytescale-upload-widget/blob/main/MIGRATE.md)
99+
- [Migrating from `react-uploader` to `@bytescale/upload-widget-react`](https://github.com/bytescale/bytescale-upload-widget-react/blob/main/MIGRATE.md)
100+
- [Migrating from `angular-uploader` to `@bytescale/upload-widget-angular`](https://github.com/bytescale/bytescale-upload-widget-angular/blob/main/MIGRATE.md)
101+
- [Migrating from `@upload-io/vue-uploader` to `@bytescale/upload-widget-vue`](https://github.com/bytescale/bytescale-upload-widget-vue/blob/main/MIGRATE.md)
102+
- [Migrating from `@upload-io/jquery-uploader` to `@bytescale/upload-widget-jquery`](https://github.com/bytescale/bytescale-upload-widget-jquery/blob/main/MIGRATE.md)

POLYFILLS.md

-49
This file was deleted.

0 commit comments

Comments
 (0)