@fluxfiles/node 0.1.6 → 0.1.8

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/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@ type FluxPermission = 'read' | 'write' | 'delete' | 'audit';
5
5
  * decrypted only at runtime by the FluxFiles server. Only S3-compatible
6
6
  * storage is allowed — the server rejects the `local` driver.
7
7
  */
8
- interface ByobDiskConfig {
8
+ interface ByobS3DiskConfig {
9
9
  driver: 's3';
10
10
  key: string;
11
11
  secret: string;
@@ -17,6 +17,22 @@ interface ByobDiskConfig {
17
17
  /** Public base URL for direct (unsigned) object links on a public disk. */
18
18
  public_url?: string;
19
19
  }
20
+ /**
21
+ * A BYOB SFTP disk — a user's own SFTP server (e.g. a VPS). Auth is a password OR
22
+ * a private key. The server SSRF-checks the host (no loopback/private/metadata
23
+ * targets). SFTP files are streamed through the app (no static/presigned URL).
24
+ */
25
+ interface ByobSftpDiskConfig {
26
+ driver: 'sftp';
27
+ host: string;
28
+ username: string;
29
+ password?: string;
30
+ private_key?: string;
31
+ private_key_passphrase?: string;
32
+ port?: number;
33
+ root?: string;
34
+ }
35
+ type ByobDiskConfig = ByobS3DiskConfig | ByobSftpDiskConfig;
20
36
  /** Options shared by all token builders. */
21
37
  interface BaseTokenOptions {
22
38
  /** HS256 signing secret. Defaults to `process.env.FLUXFILES_SECRET`. Must be ≥ 32 bytes. */
@@ -83,6 +99,16 @@ interface BaseTokenOptions {
83
99
  watermarkOpacity?: number;
84
100
  /** Font size for text watermark. Default 24. */
85
101
  watermarkFontSize?: number;
102
+ /** Usage-summary cache TTL (seconds). `0`/omitted = inherit (900). */
103
+ usageCacheTtl?: number;
104
+ /** Percent at which quota status becomes "warning". `0`/omitted = inherit (70). */
105
+ usageWarningThreshold?: number;
106
+ /** Percent at which quota status becomes "critical". `0`/omitted = inherit (90). */
107
+ usageCriticalThreshold?: number;
108
+ /** Number of largest folders the usage dashboard returns. `0`/omitted = inherit (10). */
109
+ usageTopFoldersCount?: number;
110
+ /** Folder grouping depth for the usage breakdown. `0`/omitted = inherit (1). */
111
+ usageFolderDepth?: number;
86
112
  }
87
113
  interface CreateTokenOptions extends BaseTokenOptions {
88
114
  /** Disk names the token may access. */
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ type FluxPermission = 'read' | 'write' | 'delete' | 'audit';
5
5
  * decrypted only at runtime by the FluxFiles server. Only S3-compatible
6
6
  * storage is allowed — the server rejects the `local` driver.
7
7
  */
8
- interface ByobDiskConfig {
8
+ interface ByobS3DiskConfig {
9
9
  driver: 's3';
10
10
  key: string;
11
11
  secret: string;
@@ -17,6 +17,22 @@ interface ByobDiskConfig {
17
17
  /** Public base URL for direct (unsigned) object links on a public disk. */
18
18
  public_url?: string;
19
19
  }
20
+ /**
21
+ * A BYOB SFTP disk — a user's own SFTP server (e.g. a VPS). Auth is a password OR
22
+ * a private key. The server SSRF-checks the host (no loopback/private/metadata
23
+ * targets). SFTP files are streamed through the app (no static/presigned URL).
24
+ */
25
+ interface ByobSftpDiskConfig {
26
+ driver: 'sftp';
27
+ host: string;
28
+ username: string;
29
+ password?: string;
30
+ private_key?: string;
31
+ private_key_passphrase?: string;
32
+ port?: number;
33
+ root?: string;
34
+ }
35
+ type ByobDiskConfig = ByobS3DiskConfig | ByobSftpDiskConfig;
20
36
  /** Options shared by all token builders. */
21
37
  interface BaseTokenOptions {
22
38
  /** HS256 signing secret. Defaults to `process.env.FLUXFILES_SECRET`. Must be ≥ 32 bytes. */
@@ -83,6 +99,16 @@ interface BaseTokenOptions {
83
99
  watermarkOpacity?: number;
84
100
  /** Font size for text watermark. Default 24. */
85
101
  watermarkFontSize?: number;
102
+ /** Usage-summary cache TTL (seconds). `0`/omitted = inherit (900). */
103
+ usageCacheTtl?: number;
104
+ /** Percent at which quota status becomes "warning". `0`/omitted = inherit (70). */
105
+ usageWarningThreshold?: number;
106
+ /** Percent at which quota status becomes "critical". `0`/omitted = inherit (90). */
107
+ usageCriticalThreshold?: number;
108
+ /** Number of largest folders the usage dashboard returns. `0`/omitted = inherit (10). */
109
+ usageTopFoldersCount?: number;
110
+ /** Folder grouping depth for the usage breakdown. `0`/omitted = inherit (1). */
111
+ usageFolderDepth?: number;
86
112
  }
87
113
  interface CreateTokenOptions extends BaseTokenOptions {
88
114
  /** Disk names the token may access. */
package/dist/index.js CHANGED
@@ -167,10 +167,26 @@ function applyTenantOverrides(payload, opts) {
167
167
  if (opts.watermarkOpacity !== void 0) payload.watermark_opacity = opts.watermarkOpacity;
168
168
  if (opts.watermarkFontSize && opts.watermarkFontSize > 0) payload.watermark_font_size = Math.trunc(opts.watermarkFontSize);
169
169
  }
170
+ if (opts.usageCacheTtl && opts.usageCacheTtl > 0) payload.usage_cache_ttl = Math.trunc(opts.usageCacheTtl);
171
+ if (opts.usageWarningThreshold && opts.usageWarningThreshold > 0) payload.usage_warning_threshold = Math.trunc(opts.usageWarningThreshold);
172
+ if (opts.usageCriticalThreshold && opts.usageCriticalThreshold > 0) payload.usage_critical_threshold = Math.trunc(opts.usageCriticalThreshold);
173
+ if (opts.usageTopFoldersCount && opts.usageTopFoldersCount > 0) payload.usage_top_folders_count = Math.trunc(opts.usageTopFoldersCount);
174
+ if (opts.usageFolderDepth && opts.usageFolderDepth > 0) payload.usage_folder_depth = Math.trunc(opts.usageFolderDepth);
170
175
  }
171
176
  function validateByobDisk(name, config) {
172
- if (!config || config.driver !== "s3") {
173
- throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" (the server rejects "local").`);
177
+ if (!config || config.driver !== "s3" && config.driver !== "sftp") {
178
+ throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" or "sftp" (the server rejects "local").`);
179
+ }
180
+ if (config.driver === "sftp") {
181
+ for (const field of ["host", "username"]) {
182
+ if (!config[field]) {
183
+ throw new Error(`FluxFiles BYOB disk "${name}": missing required "${field}".`);
184
+ }
185
+ }
186
+ if (!config.password && !config.private_key) {
187
+ throw new Error(`FluxFiles BYOB disk "${name}": needs a "password" or "private_key".`);
188
+ }
189
+ return;
174
190
  }
175
191
  for (const field of ["key", "secret", "bucket"]) {
176
192
  if (!config[field]) {
package/dist/index.mjs CHANGED
@@ -145,10 +145,26 @@ function applyTenantOverrides(payload, opts) {
145
145
  if (opts.watermarkOpacity !== void 0) payload.watermark_opacity = opts.watermarkOpacity;
146
146
  if (opts.watermarkFontSize && opts.watermarkFontSize > 0) payload.watermark_font_size = Math.trunc(opts.watermarkFontSize);
147
147
  }
148
+ if (opts.usageCacheTtl && opts.usageCacheTtl > 0) payload.usage_cache_ttl = Math.trunc(opts.usageCacheTtl);
149
+ if (opts.usageWarningThreshold && opts.usageWarningThreshold > 0) payload.usage_warning_threshold = Math.trunc(opts.usageWarningThreshold);
150
+ if (opts.usageCriticalThreshold && opts.usageCriticalThreshold > 0) payload.usage_critical_threshold = Math.trunc(opts.usageCriticalThreshold);
151
+ if (opts.usageTopFoldersCount && opts.usageTopFoldersCount > 0) payload.usage_top_folders_count = Math.trunc(opts.usageTopFoldersCount);
152
+ if (opts.usageFolderDepth && opts.usageFolderDepth > 0) payload.usage_folder_depth = Math.trunc(opts.usageFolderDepth);
148
153
  }
149
154
  function validateByobDisk(name, config) {
150
- if (!config || config.driver !== "s3") {
151
- throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" (the server rejects "local").`);
155
+ if (!config || config.driver !== "s3" && config.driver !== "sftp") {
156
+ throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" or "sftp" (the server rejects "local").`);
157
+ }
158
+ if (config.driver === "sftp") {
159
+ for (const field of ["host", "username"]) {
160
+ if (!config[field]) {
161
+ throw new Error(`FluxFiles BYOB disk "${name}": missing required "${field}".`);
162
+ }
163
+ }
164
+ if (!config.password && !config.private_key) {
165
+ throw new Error(`FluxFiles BYOB disk "${name}": needs a "password" or "private_key".`);
166
+ }
167
+ return;
152
168
  }
153
169
  for (const field of ["key", "secret", "bucket"]) {
154
170
  if (!config[field]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/node",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Server-side Node/TypeScript SDK for minting FluxFiles JWTs (plain + BYOB), byte-compatible with the PHP core",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
package/src/token.ts CHANGED
@@ -137,6 +137,13 @@ function applyTenantOverrides(payload: Record<string, unknown>, opts: BaseTokenO
137
137
  if (opts.watermarkOpacity !== undefined) payload.watermark_opacity = opts.watermarkOpacity;
138
138
  if (opts.watermarkFontSize && opts.watermarkFontSize > 0) payload.watermark_font_size = Math.trunc(opts.watermarkFontSize);
139
139
  }
140
+
141
+ // Usage-dashboard claims.
142
+ if (opts.usageCacheTtl && opts.usageCacheTtl > 0) payload.usage_cache_ttl = Math.trunc(opts.usageCacheTtl);
143
+ if (opts.usageWarningThreshold && opts.usageWarningThreshold > 0) payload.usage_warning_threshold = Math.trunc(opts.usageWarningThreshold);
144
+ if (opts.usageCriticalThreshold && opts.usageCriticalThreshold > 0) payload.usage_critical_threshold = Math.trunc(opts.usageCriticalThreshold);
145
+ if (opts.usageTopFoldersCount && opts.usageTopFoldersCount > 0) payload.usage_top_folders_count = Math.trunc(opts.usageTopFoldersCount);
146
+ if (opts.usageFolderDepth && opts.usageFolderDepth > 0) payload.usage_folder_depth = Math.trunc(opts.usageFolderDepth);
140
147
  }
141
148
 
142
149
  /**
@@ -144,8 +151,19 @@ function applyTenantOverrides(payload: Record<string, unknown>, opts: BaseTokenO
144
151
  * SSRF checks on the endpoint), so this only catches obvious mistakes early.
145
152
  */
146
153
  function validateByobDisk(name: string, config: ByobDiskConfig): void {
147
- if (!config || config.driver !== 's3') {
148
- throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" (the server rejects "local").`);
154
+ if (!config || (config.driver !== 's3' && config.driver !== 'sftp')) {
155
+ throw new Error(`FluxFiles BYOB disk "${name}": driver must be "s3" or "sftp" (the server rejects "local").`);
156
+ }
157
+ if (config.driver === 'sftp') {
158
+ for (const field of ['host', 'username'] as const) {
159
+ if (!config[field]) {
160
+ throw new Error(`FluxFiles BYOB disk "${name}": missing required "${field}".`);
161
+ }
162
+ }
163
+ if (!config.password && !config.private_key) {
164
+ throw new Error(`FluxFiles BYOB disk "${name}": needs a "password" or "private_key".`);
165
+ }
166
+ return;
149
167
  }
150
168
  for (const field of ['key', 'secret', 'bucket'] as const) {
151
169
  if (!config[field]) {
package/src/types.ts CHANGED
@@ -6,7 +6,7 @@ export type FluxPermission = 'read' | 'write' | 'delete' | 'audit';
6
6
  * decrypted only at runtime by the FluxFiles server. Only S3-compatible
7
7
  * storage is allowed — the server rejects the `local` driver.
8
8
  */
9
- export interface ByobDiskConfig {
9
+ export interface ByobS3DiskConfig {
10
10
  driver: 's3';
11
11
  key: string;
12
12
  secret: string;
@@ -19,6 +19,24 @@ export interface ByobDiskConfig {
19
19
  public_url?: string;
20
20
  }
21
21
 
22
+ /**
23
+ * A BYOB SFTP disk — a user's own SFTP server (e.g. a VPS). Auth is a password OR
24
+ * a private key. The server SSRF-checks the host (no loopback/private/metadata
25
+ * targets). SFTP files are streamed through the app (no static/presigned URL).
26
+ */
27
+ export interface ByobSftpDiskConfig {
28
+ driver: 'sftp';
29
+ host: string;
30
+ username: string;
31
+ password?: string;
32
+ private_key?: string;
33
+ private_key_passphrase?: string;
34
+ port?: number;
35
+ root?: string;
36
+ }
37
+
38
+ export type ByobDiskConfig = ByobS3DiskConfig | ByobSftpDiskConfig;
39
+
22
40
  /** Options shared by all token builders. */
23
41
  export interface BaseTokenOptions {
24
42
  /** HS256 signing secret. Defaults to `process.env.FLUXFILES_SECRET`. Must be ≥ 32 bytes. */
@@ -85,6 +103,16 @@ export interface BaseTokenOptions {
85
103
  watermarkOpacity?: number;
86
104
  /** Font size for text watermark. Default 24. */
87
105
  watermarkFontSize?: number;
106
+ /** Usage-summary cache TTL (seconds). `0`/omitted = inherit (900). */
107
+ usageCacheTtl?: number;
108
+ /** Percent at which quota status becomes "warning". `0`/omitted = inherit (70). */
109
+ usageWarningThreshold?: number;
110
+ /** Percent at which quota status becomes "critical". `0`/omitted = inherit (90). */
111
+ usageCriticalThreshold?: number;
112
+ /** Number of largest folders the usage dashboard returns. `0`/omitted = inherit (10). */
113
+ usageTopFoldersCount?: number;
114
+ /** Folder grouping depth for the usage breakdown. `0`/omitted = inherit (1). */
115
+ usageFolderDepth?: number;
88
116
  }
89
117
 
90
118
  export interface CreateTokenOptions extends BaseTokenOptions {