Skip to content

Commit 51206e0

Browse files
mifiremcohaszing
andauthored
rewrite to esm and upgrade packages (#223)
* rewrite to esm and upgrade `got` * fix lint * upgrade the rest of packages closes #155 * update doc * export more * fix ts deprecated syntax * fix proxy * fix lint * fix test * yarn dedupe * remove try catch in exacmples * fix exports * remove redundant moduleResolution * add test for `error` field in GET assembly * use tsconfig.build.json for prepack because type errors in examples, test etc shouldn't block publish those are handled in `lint:ts` * refactor examples and script to ts * require node 20 and upgrade got * lint * use yarn exec instead of tsx #223 (comment) * Update test/generate-coverage-badge.ts Co-authored-by: Remco Haszing <[email protected]> * use experimental-strip-types --------- Co-authored-by: Remco Haszing <[email protected]>
1 parent 6fdd4bc commit 51206e0

39 files changed

+2263
-2060
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
},
2020
},
2121
rules: {
22+
'import/no-unresolved': 'off',
2223
'import/extensions': 'off',
2324
'no-unused-vars': 'off',
2425
'@typescript-eslint/no-unused-vars': ['error'],
@@ -39,5 +40,13 @@ module.exports = {
3940
'no-console': 'off',
4041
},
4142
},
43+
{
44+
files: 'examples/**',
45+
rules: {
46+
'no-console': 0,
47+
'import/no-extraneous-dependencies': 0,
48+
'import/no-unresolved': 0,
49+
},
50+
},
4251
],
4352
}

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
strategy:
5959
matrix:
6060
node:
61-
- 18
6261
- 20
6362
- 22
6463
steps:

.github/workflows/integration.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
max-parallel: 1
1717
matrix:
1818
node:
19-
- 18
2019
- 20.15.1
2120
- 22.3.0
2221
steps:
@@ -43,7 +42,7 @@ jobs:
4342
DEBUG: 'transloadit:*'
4443

4544
- name: Generate the badge from the json-summary
46-
run: node test/generate-coverage-badge.js coverage/coverage-summary.json
45+
run: node --experimental-strip-types test/generate-coverage-badge.ts coverage/coverage-summary.json
4746
- name: Move HTML report and badge to the correct location
4847
run: |
4948
mv coverage/lcov-report static-build

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This is a **Node.js** SDK to make it easy to talk to the
2424

2525
## Requirements
2626

27-
- [Node.js](https://nodejs.org/en/) version 18 or newer
27+
- [Node.js](https://nodejs.org/en/) version 20 or newer
2828
- [A Transloadit account](https://transloadit.com/signup/) ([free signup](https://transloadit.com/pricing/))
2929
- [Your API credentials](https://transloadit.com/c/template-credentials) (`authKey`, `authSecret`)
3030

@@ -47,7 +47,7 @@ npm install --save transloadit
4747
The following code will upload an image and resize it to a thumbnail:
4848

4949
```javascript
50-
const { Transloadit } = require('transloadit')
50+
import { Transloadit } from 'transloadit'
5151

5252
const transloadit = new Transloadit({
5353
authKey: 'YOUR_TRANSLOADIT_KEY',
@@ -451,7 +451,7 @@ There are three kinds of retries:
451451

452452
All functions of the client automatically obey all rate limiting imposed by Transloadit (e.g. `RATE_LIMIT_REACHED`), so there is no need to write your own wrapper scripts to handle rate limits. The SDK will by default retry requests **5 times** with auto back-off (See `maxRetries` constructor option).
453453

454-
#### GOT HTTP retries (`gotRetry`, default `0`)
454+
#### GOT HTTP retries (`gotRetry`, default `{ limit: 0 }`)
455455

456456
Because we use [got](https://github.com/sindresorhus/got) under the hood, you can pass a `gotRetry` constructor option which is passed on to `got`. This offers great flexibility for handling retries on network errors and HTTP status codes with auto back-off. See [`got` `retry` object documentation](https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md).
457457

examples/.eslintrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/convert_to_webp.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/convert_to_webp.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Run this file as:
2+
//
3+
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node examples/convert_to_webp.js ./examples/fixtures/berkley.jpg
4+
//
5+
// You may need to build the project first using:
6+
//
7+
// yarn prepack
8+
//
9+
import { Transloadit } from 'transloadit'
10+
11+
const transloadit = new Transloadit({
12+
authKey: process.env.TRANSLOADIT_KEY!,
13+
authSecret: process.env.TRANSLOADIT_SECRET!,
14+
})
15+
16+
const filePath = process.argv[2]
17+
18+
const status = await transloadit.createAssembly({
19+
files: {
20+
file1: filePath,
21+
},
22+
params: {
23+
steps: {
24+
webp: {
25+
use: ':original',
26+
robot: '/image/resize',
27+
result: true,
28+
imagemagick_stack: 'v2.0.7',
29+
format: 'webp',
30+
},
31+
},
32+
},
33+
waitForCompletion: true,
34+
})
35+
console.log('Your WebP file:', status.results.webp[0].url)

examples/credentials.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

examples/credentials.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* eslint-disable max-len */
2+
// Run this file as:
3+
//
4+
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node template_api.js
5+
//
6+
// You may need to build the project first using:
7+
//
8+
// yarn prepack
9+
//
10+
import { CreateTemplateCredentialParams, Transloadit } from 'transloadit'
11+
12+
const transloadit = new Transloadit({
13+
authKey: process.env.TRANSLOADIT_KEY!,
14+
authSecret: process.env.TRANSLOADIT_SECRET!,
15+
})
16+
17+
const firstName = 'myProductionS3'
18+
const secondName = 'myStagingS3'
19+
20+
const credentialParams: CreateTemplateCredentialParams = {
21+
name: firstName,
22+
type: 's3',
23+
content: {
24+
key: 'xyxy',
25+
secret: 'xyxyxyxy',
26+
bucket: 'mybucket.example.com',
27+
bucket_region: 'us-east-1',
28+
},
29+
}
30+
31+
console.log(`==> listTemplateCredentials`)
32+
const { credentials } = await transloadit.listTemplateCredentials({
33+
sort: 'created',
34+
order: 'asc',
35+
})
36+
console.log('Successfully fetched', credentials.length, 'credential(s)')
37+
38+
// ^-- with Templates, there is `items` and `count`.
39+
// with Credentials, there is `ok`, `message`, `credentials`
40+
41+
for (const credential of credentials) {
42+
if ([firstName, secondName].includes(credential.name)) {
43+
console.log(`==> deleteTemplateCredential: ${credential.id} (${credential.name})`)
44+
const delResult = await transloadit.deleteTemplateCredential(credential.id)
45+
console.log('Successfully deleted credential', delResult)
46+
// ^-- identical structure between `Templates` and `Credentials`
47+
}
48+
}
49+
50+
console.log(`==> createTemplateCredential`)
51+
const createTemplateCredentialResult = await transloadit.createTemplateCredential(credentialParams)
52+
console.log('TemplateCredential created successfully:', createTemplateCredentialResult)
53+
// ^-- with Templates, there is `ok`, `message`, `id`, `content`, `name`, `require_signature_auth`. Same is true for: created, updated, fetched
54+
// with Credentials, there is `ok`, `message`, `credentials` <-- and a single object nested directly under it, which is unexpected with that plural imho. Same is true for created, updated, fetched
55+
56+
console.log(
57+
`==> editTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
58+
)
59+
const editResult = await transloadit.editTemplateCredential(
60+
createTemplateCredentialResult.credential.id,
61+
{
62+
...credentialParams,
63+
name: secondName,
64+
}
65+
)
66+
console.log('Successfully edited credential', editResult)
67+
// ^-- see create
68+
69+
console.log(
70+
`==> getTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
71+
)
72+
const getTemplateCredentialResult = await transloadit.getTemplateCredential(
73+
createTemplateCredentialResult.credential.id
74+
)
75+
console.log('Successfully fetched credential', getTemplateCredentialResult)
76+
// ^-- not working at al, getting a 404. looking at the API, this is not implemented yet

examples/face_detect_download.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)