Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
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
9 changes: 9 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
},
},
rules: {
'import/no-unresolved': 'off',
'import/extensions': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
Expand All @@ -39,5 +40,13 @@ module.exports = {
'no-console': 'off',
},
},
{
files: 'examples/**',
rules: {
'no-console': 0,
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
},
},
],
}
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:
strategy:
matrix:
node:
- 18
- 20
- 22
steps:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
max-parallel: 1
matrix:
node:
- 18
- 20.15.1
- 22.3.0
steps:
Expand All @@ -43,7 +42,7 @@ jobs:
DEBUG: 'transloadit:*'

- name: Generate the badge from the json-summary
run: node test/generate-coverage-badge.js coverage/coverage-summary.json
run: yarn exec tsx test/generate-coverage-badge.ts coverage/coverage-summary.json
- name: Move HTML report and badge to the correct location
run: |
mv coverage/lcov-report static-build
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This is a **Node.js** SDK to make it easy to talk to the

## Requirements

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

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

```javascript
const { Transloadit } = require('transloadit')
import { Transloadit } from 'transloadit'

const transloadit = new Transloadit({
authKey: 'YOUR_TRANSLOADIT_KEY',
Expand Down Expand Up @@ -451,7 +451,7 @@ There are three kinds of retries:

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).

#### GOT HTTP retries (`gotRetry`, default `0`)
#### GOT HTTP retries (`gotRetry`, default `{ limit: 0 }`)

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).

Expand Down
7 changes: 0 additions & 7 deletions examples/.eslintrc.js

This file was deleted.

41 changes: 0 additions & 41 deletions examples/convert_to_webp.js

This file was deleted.

35 changes: 35 additions & 0 deletions examples/convert_to_webp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node examples/convert_to_webp.js ./examples/fixtures/berkley.jpg
//
// You may need to build the project first using:
//
// yarn prepack
//
import { Transloadit } from 'transloadit'

const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
})

const filePath = process.argv[2]

const status = await transloadit.createAssembly({
files: {
file1: filePath,
},
params: {
steps: {
webp: {
use: ':original',
robot: '/image/resize',
result: true,
imagemagick_stack: 'v2.0.7',
format: 'webp',
},
},
},
waitForCompletion: true,
})
console.log('Your WebP file:', status.results.webp[0].url)
86 changes: 0 additions & 86 deletions examples/credentials.js

This file was deleted.

76 changes: 76 additions & 0 deletions examples/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable max-len */
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node template_api.js
//
// You may need to build the project first using:
//
// yarn prepack
//
import { CreateTemplateCredentialParams, Transloadit } from 'transloadit'

const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
})

const firstName = 'myProductionS3'
const secondName = 'myStagingS3'

const credentialParams: CreateTemplateCredentialParams = {
name: firstName,
type: 's3',
content: {
key: 'xyxy',
secret: 'xyxyxyxy',
bucket: 'mybucket.example.com',
bucket_region: 'us-east-1',
},
}

console.log(`==> listTemplateCredentials`)
const { credentials } = await transloadit.listTemplateCredentials({
sort: 'created',
order: 'asc',
})
console.log('Successfully fetched', credentials.length, 'credential(s)')

// ^-- with Templates, there is `items` and `count`.
// with Credentials, there is `ok`, `message`, `credentials`

for (const credential of credentials) {
if ([firstName, secondName].includes(credential.name)) {
console.log(`==> deleteTemplateCredential: ${credential.id} (${credential.name})`)
const delResult = await transloadit.deleteTemplateCredential(credential.id)
console.log('Successfully deleted credential', delResult)
// ^-- identical structure between `Templates` and `Credentials`
}
}

console.log(`==> createTemplateCredential`)
const createTemplateCredentialResult = await transloadit.createTemplateCredential(credentialParams)
console.log('TemplateCredential created successfully:', createTemplateCredentialResult)
// ^-- with Templates, there is `ok`, `message`, `id`, `content`, `name`, `require_signature_auth`. Same is true for: created, updated, fetched
// 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

console.log(
`==> editTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
)
const editResult = await transloadit.editTemplateCredential(
createTemplateCredentialResult.credential.id,
{
...credentialParams,
name: secondName,
}
)
console.log('Successfully edited credential', editResult)
// ^-- see create

console.log(
`==> getTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
)
const getTemplateCredentialResult = await transloadit.getTemplateCredential(
createTemplateCredentialResult.credential.id
)
console.log('Successfully fetched credential', getTemplateCredentialResult)
// ^-- not working at al, getting a 404. looking at the API, this is not implemented yet
56 changes: 0 additions & 56 deletions examples/face_detect_download.js

This file was deleted.

Loading