@lenne.tech/nest-server 12.9.1 → 12.9.3

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 (54) hide show
  1. package/.claude/rules/configurable-features.md +1 -1
  2. package/.claude/rules/testing.md +4 -4
  3. package/FRAMEWORK-API.md +1 -1
  4. package/dist/core/common/helpers/byte-range.helper.d.ts +8 -0
  5. package/dist/core/common/helpers/byte-range.helper.js +71 -0
  6. package/dist/core/common/helpers/byte-range.helper.js.map +1 -0
  7. package/dist/core/common/helpers/gridfs.helper.d.ts +7 -2
  8. package/dist/core/common/helpers/gridfs.helper.js +7 -4
  9. package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
  10. package/dist/core/common/services/core-s3.service.d.ts +3 -0
  11. package/dist/core/common/services/core-s3.service.js +8 -1
  12. package/dist/core/common/services/core-s3.service.js.map +1 -1
  13. package/dist/core/modules/error-code/error-codes.d.ts +9 -0
  14. package/dist/core/modules/error-code/error-codes.js +8 -0
  15. package/dist/core/modules/error-code/error-codes.js.map +1 -1
  16. package/dist/core/modules/file/core-file.controller.d.ts +6 -0
  17. package/dist/core/modules/file/core-file.controller.js +84 -27
  18. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  19. package/dist/core/modules/file/core-file.service.d.ts +2 -0
  20. package/dist/core/modules/file/core-file.service.js +17 -6
  21. package/dist/core/modules/file/core-file.service.js.map +1 -1
  22. package/dist/core/modules/file/filesystem-file.helper.d.ts +2 -1
  23. package/dist/core/modules/file/filesystem-file.helper.js +2 -2
  24. package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
  25. package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +2 -0
  26. package/dist/core/modules/file/s3-file.helper.d.ts +2 -0
  27. package/dist/core/modules/file/s3-file.helper.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/server/modules/error-code/error-codes.d.ts +1 -0
  32. package/dist/test/test.helper.d.ts +1 -0
  33. package/dist/test/test.helper.js +6 -0
  34. package/dist/test/test.helper.js.map +1 -1
  35. package/docs/REQUEST-LIFECYCLE.md +1 -1
  36. package/docs/error-codes.md +14 -0
  37. package/migration-guides/12.8.8-to-12.8.9.md +15 -3
  38. package/migration-guides/12.9.1-to-12.9.2.md +75 -0
  39. package/migration-guides/12.9.2-to-12.9.3.md +127 -0
  40. package/package.json +1 -1
  41. package/src/core/common/helpers/byte-range.helper.ts +144 -0
  42. package/src/core/common/helpers/gridfs.helper.ts +20 -6
  43. package/src/core/common/services/core-s3.service.ts +16 -2
  44. package/src/core/modules/error-code/error-codes.ts +13 -0
  45. package/src/core/modules/file/INTEGRATION-CHECKLIST.md +17 -15
  46. package/src/core/modules/file/README.md +90 -3
  47. package/src/core/modules/file/core-file.controller.ts +185 -32
  48. package/src/core/modules/file/core-file.service.ts +33 -13
  49. package/src/core/modules/file/filesystem-file.helper.ts +8 -3
  50. package/src/core/modules/file/interfaces/file-service-options.interface.ts +13 -0
  51. package/src/core/modules/file/s3-file.helper.ts +3 -2
  52. package/src/index.ts +1 -0
  53. package/src/test/README.md +8 -4
  54. package/src/test/test.helper.ts +12 -0
@@ -1,6 +1,7 @@
1
1
  import type { Types } from 'mongoose';
2
2
  import { Readable } from 'stream';
3
3
 
4
+ import type { ByteRange } from '../../common/helpers/byte-range.helper.js';
4
5
  import { CoreS3Service } from '../../common/services/core-s3.service.js';
5
6
  import {
6
7
  ensureFilenameIndex,
@@ -216,12 +217,12 @@ export class S3FileHelper {
216
217
  }
217
218
 
218
219
  /**
219
- * Get the download stream of a file
220
+ * Get the download stream of a file — with `range`, only those bytes (both inclusive)
220
221
  */
221
222
  static async getStream(
222
223
  s3Service: CoreS3Service,
223
224
  id: string | Types.ObjectId,
224
- options?: { abortSignal?: AbortSignal; idleTimeoutMs?: false | number },
225
+ options?: { abortSignal?: AbortSignal; idleTimeoutMs?: false | number; range?: ByteRange },
225
226
  ): Promise<Readable> {
226
227
  const objectId = typeof id === 'string' ? newObjectId(id) : id;
227
228
  return (await s3Service.getObject(objectId.toHexString(), options)).body;
package/src/index.ts CHANGED
@@ -30,6 +30,7 @@ export * from './core/common/enums/sort-order.emum.js';
30
30
  export * from './core/common/exceptions/access-denied.exception.js';
31
31
  export * from './core/common/filters/http-exception-log.filter.js';
32
32
  export * from './core/common/filters/mongoose-cast-error.filter.js';
33
+ export * from './core/common/helpers/byte-range.helper.js';
33
34
  export * from './core/common/helpers/common.helper.js';
34
35
  export * from './core/common/helpers/config.helper.js';
35
36
  export * from './core/common/helpers/config-endpoint.helper.js';
@@ -205,10 +205,11 @@ await fs.promises.writeFile('/tmp/downloaded.bin', buffer);
205
205
 
206
206
  The second parameter accepts either a plain token string or a `TestDownloadOptions` object:
207
207
 
208
- | Option | Type | Description |
209
- | --------- | -------- | ------------------------------------------------------------- |
210
- | `token` | `string` | Bearer token via Authorization header (JWT) |
211
- | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
208
+ | Option | Type | Description |
209
+ | --------- | ------------------------ | ------------------------------------------------------------- |
210
+ | `token` | `string` | Bearer token via Authorization header (JWT) |
211
+ | `cookies` | `string` | Plain session token, converted via `buildBetterAuthCookies()` |
212
+ | `headers` | `Record<string, string>` | Additional request headers, e.g. `Range` (since 12.9.3) |
212
213
 
213
214
  Both can be used simultaneously — `token` sets the Authorization header while `cookies` sets the Cookie header.
214
215
 
@@ -224,6 +225,9 @@ await testHelper.download('/files/id/abc123', { cookies: sessionToken });
224
225
 
225
226
  // Both simultaneously
226
227
  await testHelper.download('/files/id/abc123', { cookies: sessionToken, token: jwtToken });
228
+
229
+ // A byte range: 206, `Content-Range: bytes 0-1/<length>`, two bytes in `res.data`
230
+ const res = await testHelper.download('/files/id/abc123', { headers: { Range: 'bytes=0-1' }, token: jwtToken });
227
231
  ```
228
232
 
229
233
  ## GraphQL Testing (`testHelper.graphQl()`)
@@ -190,6 +190,12 @@ export interface TestDownloadOptions {
190
190
  */
191
191
  cookies?: string;
192
192
 
193
+ /**
194
+ * Additional request headers, e.g. `{ Range: 'bytes=0-1' }` for a ranged download or `If-None-Match`.
195
+ * Set before `cookies` and `token`, which win for their own header. Since 12.9.3.
196
+ */
197
+ headers?: Record<string, string>;
198
+
193
199
  /**
194
200
  * Bearer token via Authorization header (JWT authentication).
195
201
  * Can be used simultaneously with `cookies` — token sets the Authorization header
@@ -386,6 +392,9 @@ export class TestHelper {
386
392
  if (typeof tokenOrOptions === 'string') {
387
393
  request.set('Authorization', `bearer ${tokenOrOptions}`);
388
394
  } else if (tokenOrOptions) {
395
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
396
+ request.set(name, value);
397
+ }
389
398
  if (tokenOrOptions.cookies) {
390
399
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
391
400
  request.set(
@@ -431,6 +440,9 @@ export class TestHelper {
431
440
  if (typeof tokenOrOptions === 'string') {
432
441
  request.set('Authorization', `bearer ${tokenOrOptions}`);
433
442
  } else if (tokenOrOptions) {
443
+ for (const [name, value] of Object.entries(tokenOrOptions.headers ?? {})) {
444
+ request.set(name, value);
445
+ }
434
446
  if (tokenOrOptions.cookies) {
435
447
  const cookieRecord = TestHelper.buildBetterAuthCookies(tokenOrOptions.cookies);
436
448
  request.set(