transloadit 4.0.7 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +200 -21
- package/dist/ApiError.d.ts +1 -1
- package/dist/ApiError.d.ts.map +1 -1
- package/dist/ApiError.js.map +1 -1
- package/dist/Transloadit.d.ts +23 -4
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +62 -28
- package/dist/Transloadit.js.map +1 -1
- package/dist/apiTypes.d.ts +1 -1
- package/dist/apiTypes.d.ts.map +1 -1
- package/dist/cli/OutputCtl.d.ts +46 -0
- package/dist/cli/OutputCtl.d.ts.map +1 -0
- package/dist/cli/OutputCtl.js +85 -0
- package/dist/cli/OutputCtl.js.map +1 -0
- package/dist/cli/commands/BaseCommand.d.ts +23 -0
- package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
- package/dist/cli/commands/BaseCommand.js +52 -0
- package/dist/cli/commands/BaseCommand.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +93 -0
- package/dist/cli/commands/assemblies.d.ts.map +1 -0
- package/dist/cli/commands/assemblies.js +1021 -0
- package/dist/cli/commands/assemblies.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +28 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +280 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/bills.d.ts +14 -0
- package/dist/cli/commands/bills.d.ts.map +1 -0
- package/dist/cli/commands/bills.js +69 -0
- package/dist/cli/commands/bills.js.map +1 -0
- package/dist/cli/commands/index.d.ts +3 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +39 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/notifications.d.ts +16 -0
- package/dist/cli/commands/notifications.d.ts.map +1 -0
- package/dist/cli/commands/notifications.js +44 -0
- package/dist/cli/commands/notifications.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +81 -0
- package/dist/cli/commands/templates.d.ts.map +1 -0
- package/dist/cli/commands/templates.js +428 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/helpers.d.ts +13 -0
- package/dist/cli/helpers.d.ts.map +1 -0
- package/dist/cli/helpers.js +39 -0
- package/dist/cli/helpers.js.map +1 -0
- package/dist/cli/template-last-modified.d.ts +10 -0
- package/dist/cli/template-last-modified.d.ts.map +1 -0
- package/dist/cli/template-last-modified.js +134 -0
- package/dist/cli/template-last-modified.js.map +1 -0
- package/dist/cli/types.d.ts +152 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +64 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli.d.ts +2 -12
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -256
- package/dist/cli.js.map +1 -1
- package/dist/tus.d.ts +2 -1
- package/dist/tus.d.ts.map +1 -1
- package/dist/tus.js +33 -5
- package/dist/tus.js.map +1 -1
- package/package.json +12 -7
- package/src/ApiError.ts +2 -1
- package/src/Transloadit.ts +98 -39
- package/src/apiTypes.ts +1 -1
- package/src/cli/OutputCtl.ts +115 -0
- package/src/cli/commands/BaseCommand.ts +71 -0
- package/src/cli/commands/assemblies.ts +1373 -0
- package/src/cli/commands/auth.ts +354 -0
- package/src/cli/commands/bills.ts +91 -0
- package/src/cli/commands/index.ts +65 -0
- package/src/cli/commands/notifications.ts +63 -0
- package/src/cli/commands/templates.ts +556 -0
- package/src/cli/helpers.ts +50 -0
- package/src/cli/template-last-modified.ts +156 -0
- package/src/cli/types.ts +183 -0
- package/src/cli.ts +12 -305
- package/src/tus.ts +37 -5
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels following syslog severity (https://en.wikipedia.org/wiki/Syslog#Severity_level)
|
|
3
|
+
* Lower numbers = more severe, higher numbers = more verbose
|
|
4
|
+
*/
|
|
5
|
+
export const LOG_LEVEL = {
|
|
6
|
+
ERR: 3, // Error conditions
|
|
7
|
+
WARN: 4, // Warning conditions
|
|
8
|
+
NOTICE: 5, // Normal but significant (default)
|
|
9
|
+
INFO: 6, // Informational
|
|
10
|
+
DEBUG: 7, // Debug-level messages
|
|
11
|
+
TRACE: 8, // Most verbose/detailed
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
export type LogLevelName = keyof typeof LOG_LEVEL
|
|
15
|
+
export type LogLevelValue = (typeof LOG_LEVEL)[LogLevelName]
|
|
16
|
+
|
|
17
|
+
export const LOG_LEVEL_DEFAULT: LogLevelValue = LOG_LEVEL.NOTICE
|
|
18
|
+
|
|
19
|
+
/** Valid log level names for CLI parsing */
|
|
20
|
+
export const LOG_LEVEL_NAMES = Object.keys(LOG_LEVEL).map((k) =>
|
|
21
|
+
k.toLowerCase(),
|
|
22
|
+
) as Lowercase<LogLevelName>[]
|
|
23
|
+
|
|
24
|
+
/** Valid numeric log level values */
|
|
25
|
+
const LOG_LEVEL_VALUES = new Set(Object.values(LOG_LEVEL))
|
|
26
|
+
|
|
27
|
+
/** Parse a log level string (name or number) to its numeric value */
|
|
28
|
+
export function parseLogLevel(level: string): LogLevelValue {
|
|
29
|
+
// Try parsing as number first
|
|
30
|
+
const num = Number(level)
|
|
31
|
+
if (!Number.isNaN(num)) {
|
|
32
|
+
if (LOG_LEVEL_VALUES.has(num as LogLevelValue)) {
|
|
33
|
+
return num as LogLevelValue
|
|
34
|
+
}
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Invalid log level: ${level}. Valid values: ${[...LOG_LEVEL_VALUES].join(', ')} or ${LOG_LEVEL_NAMES.join(', ')}`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Try as level name
|
|
41
|
+
const upper = level.toUpperCase() as LogLevelName
|
|
42
|
+
if (upper in LOG_LEVEL) {
|
|
43
|
+
return LOG_LEVEL[upper]
|
|
44
|
+
}
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Invalid log level: ${level}. Valid levels: ${LOG_LEVEL_NAMES.join(', ')} or ${[...LOG_LEVEL_VALUES].join(', ')}`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface OutputCtlOptions {
|
|
51
|
+
logLevel?: LogLevelValue
|
|
52
|
+
jsonMode?: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Interface for output controllers (used to allow test mocks) */
|
|
56
|
+
export interface IOutputCtl {
|
|
57
|
+
error(msg: unknown): void
|
|
58
|
+
warn(msg: unknown): void
|
|
59
|
+
notice(msg: unknown): void
|
|
60
|
+
info(msg: unknown): void
|
|
61
|
+
debug(msg: unknown): void
|
|
62
|
+
trace(msg: unknown): void
|
|
63
|
+
print(simple: unknown, json: unknown): void
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default class OutputCtl implements IOutputCtl {
|
|
67
|
+
private json: boolean
|
|
68
|
+
private logLevel: LogLevelValue
|
|
69
|
+
|
|
70
|
+
constructor({ logLevel = LOG_LEVEL_DEFAULT, jsonMode = false }: OutputCtlOptions = {}) {
|
|
71
|
+
this.json = jsonMode
|
|
72
|
+
this.logLevel = logLevel
|
|
73
|
+
|
|
74
|
+
process.stdout.on('error', (err: NodeJS.ErrnoException) => {
|
|
75
|
+
if (err.code === 'EPIPE') {
|
|
76
|
+
process.exitCode = 0
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
process.stderr.on('error', (err: NodeJS.ErrnoException) => {
|
|
80
|
+
if (err.code === 'EPIPE') {
|
|
81
|
+
process.exitCode = 0
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
error(msg: unknown): void {
|
|
87
|
+
if (this.logLevel >= LOG_LEVEL.ERR) console.error('err ', msg)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
warn(msg: unknown): void {
|
|
91
|
+
if (this.logLevel >= LOG_LEVEL.WARN) console.error('warn ', msg)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
notice(msg: unknown): void {
|
|
95
|
+
if (this.logLevel >= LOG_LEVEL.NOTICE) console.error('notice ', msg)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
info(msg: unknown): void {
|
|
99
|
+
if (this.logLevel >= LOG_LEVEL.INFO) console.error('info ', msg)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
debug(msg: unknown): void {
|
|
103
|
+
if (this.logLevel >= LOG_LEVEL.DEBUG) console.error('debug ', msg)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
trace(msg: unknown): void {
|
|
107
|
+
if (this.logLevel >= LOG_LEVEL.TRACE) console.error('trace ', msg)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
print(simple: unknown, json: unknown): void {
|
|
111
|
+
if (this.json) console.log(JSON.stringify(json))
|
|
112
|
+
else if (typeof simple === 'string') console.log(simple)
|
|
113
|
+
else console.dir(simple, { depth: null })
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { Command, Option } from 'clipanion'
|
|
4
|
+
import { Transloadit as TransloaditClient } from '../../Transloadit.ts'
|
|
5
|
+
import { getEnvCredentials } from '../helpers.ts'
|
|
6
|
+
import type { IOutputCtl } from '../OutputCtl.ts'
|
|
7
|
+
import OutputCtl, { LOG_LEVEL_DEFAULT, LOG_LEVEL_NAMES, parseLogLevel } from '../OutputCtl.ts'
|
|
8
|
+
|
|
9
|
+
export abstract class BaseCommand extends Command {
|
|
10
|
+
logLevelOption = Option.String('-l,--log-level', {
|
|
11
|
+
description: `Log level: ${LOG_LEVEL_NAMES.join(', ')} or 3-8 (default: notice)`,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
json = Option.Boolean('-j,--json', false, {
|
|
15
|
+
description: 'Output in JSON format',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
endpoint = Option.String('--endpoint', {
|
|
19
|
+
description:
|
|
20
|
+
'API endpoint URL (default: https://api2.transloadit.com, or TRANSLOADIT_ENDPOINT env var)',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
protected output!: IOutputCtl
|
|
24
|
+
protected client!: TransloaditClient
|
|
25
|
+
|
|
26
|
+
protected setupOutput(): void {
|
|
27
|
+
const logLevel = this.logLevelOption ? parseLogLevel(this.logLevelOption) : LOG_LEVEL_DEFAULT
|
|
28
|
+
this.output = new OutputCtl({
|
|
29
|
+
logLevel,
|
|
30
|
+
jsonMode: this.json,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected setupClient(): boolean {
|
|
35
|
+
const creds = getEnvCredentials()
|
|
36
|
+
if (!creds) {
|
|
37
|
+
this.output.error(
|
|
38
|
+
'Please provide API authentication in the environment variables TRANSLOADIT_KEY and TRANSLOADIT_SECRET',
|
|
39
|
+
)
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const endpoint = this.endpoint || process.env.TRANSLOADIT_ENDPOINT
|
|
44
|
+
|
|
45
|
+
this.client = new TransloaditClient({ ...creds, ...(endpoint && { endpoint }) })
|
|
46
|
+
return true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
abstract override execute(): Promise<number | undefined>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export abstract class AuthenticatedCommand extends BaseCommand {
|
|
53
|
+
override async execute(): Promise<number | undefined> {
|
|
54
|
+
this.setupOutput()
|
|
55
|
+
if (!this.setupClient()) {
|
|
56
|
+
return 1
|
|
57
|
+
}
|
|
58
|
+
return await this.run()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected abstract run(): Promise<number | undefined>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export abstract class UnauthenticatedCommand extends BaseCommand {
|
|
65
|
+
override async execute(): Promise<number | undefined> {
|
|
66
|
+
this.setupOutput()
|
|
67
|
+
return await this.run()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected abstract run(): Promise<number | undefined>
|
|
71
|
+
}
|