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.
Files changed (80) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +200 -21
  3. package/dist/ApiError.d.ts +1 -1
  4. package/dist/ApiError.d.ts.map +1 -1
  5. package/dist/ApiError.js.map +1 -1
  6. package/dist/Transloadit.d.ts +23 -4
  7. package/dist/Transloadit.d.ts.map +1 -1
  8. package/dist/Transloadit.js +62 -28
  9. package/dist/Transloadit.js.map +1 -1
  10. package/dist/apiTypes.d.ts +1 -1
  11. package/dist/apiTypes.d.ts.map +1 -1
  12. package/dist/cli/OutputCtl.d.ts +46 -0
  13. package/dist/cli/OutputCtl.d.ts.map +1 -0
  14. package/dist/cli/OutputCtl.js +85 -0
  15. package/dist/cli/OutputCtl.js.map +1 -0
  16. package/dist/cli/commands/BaseCommand.d.ts +23 -0
  17. package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
  18. package/dist/cli/commands/BaseCommand.js +52 -0
  19. package/dist/cli/commands/BaseCommand.js.map +1 -0
  20. package/dist/cli/commands/assemblies.d.ts +93 -0
  21. package/dist/cli/commands/assemblies.d.ts.map +1 -0
  22. package/dist/cli/commands/assemblies.js +1021 -0
  23. package/dist/cli/commands/assemblies.js.map +1 -0
  24. package/dist/cli/commands/auth.d.ts +28 -0
  25. package/dist/cli/commands/auth.d.ts.map +1 -0
  26. package/dist/cli/commands/auth.js +280 -0
  27. package/dist/cli/commands/auth.js.map +1 -0
  28. package/dist/cli/commands/bills.d.ts +14 -0
  29. package/dist/cli/commands/bills.d.ts.map +1 -0
  30. package/dist/cli/commands/bills.js +69 -0
  31. package/dist/cli/commands/bills.js.map +1 -0
  32. package/dist/cli/commands/index.d.ts +3 -0
  33. package/dist/cli/commands/index.d.ts.map +1 -0
  34. package/dist/cli/commands/index.js +39 -0
  35. package/dist/cli/commands/index.js.map +1 -0
  36. package/dist/cli/commands/notifications.d.ts +16 -0
  37. package/dist/cli/commands/notifications.d.ts.map +1 -0
  38. package/dist/cli/commands/notifications.js +44 -0
  39. package/dist/cli/commands/notifications.js.map +1 -0
  40. package/dist/cli/commands/templates.d.ts +81 -0
  41. package/dist/cli/commands/templates.d.ts.map +1 -0
  42. package/dist/cli/commands/templates.js +428 -0
  43. package/dist/cli/commands/templates.js.map +1 -0
  44. package/dist/cli/helpers.d.ts +13 -0
  45. package/dist/cli/helpers.d.ts.map +1 -0
  46. package/dist/cli/helpers.js +39 -0
  47. package/dist/cli/helpers.js.map +1 -0
  48. package/dist/cli/template-last-modified.d.ts +10 -0
  49. package/dist/cli/template-last-modified.d.ts.map +1 -0
  50. package/dist/cli/template-last-modified.js +134 -0
  51. package/dist/cli/template-last-modified.js.map +1 -0
  52. package/dist/cli/types.d.ts +152 -0
  53. package/dist/cli/types.d.ts.map +1 -0
  54. package/dist/cli/types.js +64 -0
  55. package/dist/cli/types.js.map +1 -0
  56. package/dist/cli.d.ts +2 -12
  57. package/dist/cli.d.ts.map +1 -1
  58. package/dist/cli.js +11 -256
  59. package/dist/cli.js.map +1 -1
  60. package/dist/tus.d.ts +2 -1
  61. package/dist/tus.d.ts.map +1 -1
  62. package/dist/tus.js +33 -5
  63. package/dist/tus.js.map +1 -1
  64. package/package.json +12 -7
  65. package/src/ApiError.ts +2 -1
  66. package/src/Transloadit.ts +98 -39
  67. package/src/apiTypes.ts +1 -1
  68. package/src/cli/OutputCtl.ts +115 -0
  69. package/src/cli/commands/BaseCommand.ts +71 -0
  70. package/src/cli/commands/assemblies.ts +1373 -0
  71. package/src/cli/commands/auth.ts +354 -0
  72. package/src/cli/commands/bills.ts +91 -0
  73. package/src/cli/commands/index.ts +65 -0
  74. package/src/cli/commands/notifications.ts +63 -0
  75. package/src/cli/commands/templates.ts +556 -0
  76. package/src/cli/helpers.ts +50 -0
  77. package/src/cli/template-last-modified.ts +156 -0
  78. package/src/cli/types.ts +183 -0
  79. package/src/cli.ts +12 -305
  80. 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
+ }