@tmlmobilidade/interfaces 20260411.1243.43 → 20260411.1248.30

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.
@@ -13,11 +13,11 @@ declare class FilesClass extends MongoCollectionClass<File, CreateFileDto, Updat
13
13
  static getInstance(): Promise<FilesClass>;
14
14
  /**
15
15
  * Clones a file from one resource to another.
16
- * @param file_id - The unique identifier of the file in the database.
17
- * @param resource_id - The unique identifier of the resource to clone the file to.
16
+ * @param fileId - The unique identifier of the file in the database.
17
+ * @param resourceId - The unique identifier of the resource to clone the file to.
18
18
  * @returns The file that was cloned.
19
19
  */
20
- clone(file_id: string, scope: string, resource_id: string, options?: InsertOneOptions): Promise<File>;
20
+ clone(fileId: string, scope: string, resourceId: string, options?: InsertOneOptions): Promise<File>;
21
21
  /**
22
22
  * Deletes a file from the storage service and the database.
23
23
  * @param fileId - The unique identifier of the file in the database.
@@ -8,6 +8,7 @@ import { CreateFileSchema, UpdateFileSchema } from '@tmlmobilidade/types';
8
8
  import { asyncSingletonProxy, convertObject } from '@tmlmobilidade/utils';
9
9
  /* * */
10
10
  class FilesClass extends MongoCollectionClass {
11
+ //
11
12
  static _instance;
12
13
  createSchema = CreateFileSchema;
13
14
  updateSchema = UpdateFileSchema;
@@ -17,8 +18,11 @@ class FilesClass extends MongoCollectionClass {
17
18
  super();
18
19
  switch (process.env.STORAGE_TYPE) {
19
20
  case 'oci':
20
- if (!process.env.OCI_BUCKET_NAME || !process.env.OCI_FINGERPRINT || !process.env.OCI_NAMESPACE || !process.env.OCI_PRIVATE_KEY || !process.env.OCI_REGION || !process.env.OCI_TENANCY || !process.env.OCI_USER) {
21
- throw new Error('OCI_BUCKET_NAME, OCI_FINGERPRINT, OCI_NAMESPACE, OCI_PRIVATE_KEY, OCI_REGION, OCI_TENANCY, and OCI_USER must be set');
21
+ if (!process.env.OCI_PRIVATE_KEY && !process.env.OCI_PRIVATE_KEY_PATH) {
22
+ throw new Error('Either OCI_PRIVATE_KEY or OCI_PRIVATE_KEY_PATH must be set');
23
+ }
24
+ if (!process.env.OCI_BUCKET_NAME || !process.env.OCI_FINGERPRINT || !process.env.OCI_NAMESPACE || !process.env.OCI_REGION || !process.env.OCI_TENANCY || !process.env.OCI_USER) {
25
+ throw new Error('OCI_BUCKET_NAME, OCI_FINGERPRINT, OCI_NAMESPACE, OCI_REGION, OCI_TENANCY, and OCI_USER must be set');
22
26
  }
23
27
  this.bucketName = process.env.OCI_BUCKET_NAME;
24
28
  this.storageService = StorageFactory.create({
@@ -27,6 +31,7 @@ class FilesClass extends MongoCollectionClass {
27
31
  fingerprint: process.env.OCI_FINGERPRINT,
28
32
  namespace: process.env.OCI_NAMESPACE,
29
33
  private_key: process.env.OCI_PRIVATE_KEY,
34
+ private_key_path: process.env.OCI_PRIVATE_KEY_PATH,
30
35
  region: process.env.OCI_REGION,
31
36
  tenancy: process.env.OCI_TENANCY,
32
37
  user: process.env.OCI_USER,
@@ -48,20 +53,20 @@ class FilesClass extends MongoCollectionClass {
48
53
  }
49
54
  /**
50
55
  * Clones a file from one resource to another.
51
- * @param file_id - The unique identifier of the file in the database.
52
- * @param resource_id - The unique identifier of the resource to clone the file to.
56
+ * @param fileId - The unique identifier of the file in the database.
57
+ * @param resourceId - The unique identifier of the resource to clone the file to.
53
58
  * @returns The file that was cloned.
54
59
  */
55
- async clone(file_id, scope, resource_id, options) {
60
+ async clone(fileId, scope, resourceId, options) {
56
61
  const _id = generateRandomString({ length: 5 });
57
- const file = await this.findOne({ _id: file_id });
62
+ const file = await this.findOne({ _id: fileId });
58
63
  if (!file)
59
64
  throw new HttpException(HTTP_STATUS.NOT_FOUND, 'File not found');
60
65
  const originalFilePath = `${file.scope}/${file.resource_id}/${file._id}.${Files.getFileExtension(file.name)}`;
61
- const newFilePath = `${scope}/${resource_id}/${_id}.${Files.getFileExtension(file.name)}`;
66
+ const newFilePath = `${scope}/${resourceId}/${_id}.${Files.getFileExtension(file.name)}`;
62
67
  await this.storageService.copyFile(originalFilePath, newFilePath);
63
68
  const newFile = convertObject(file, CreateFileSchema);
64
- return await this.insertOne({ ...newFile, _id, resource_id, scope }, { options });
69
+ return await this.insertOne({ ...newFile, _id, resource_id: resourceId, scope }, { options });
65
70
  }
66
71
  /**
67
72
  * Deletes a file from the storage service and the database.
@@ -4,7 +4,8 @@ export interface OCIStorageProviderConfiguration {
4
4
  bucket_name: string;
5
5
  fingerprint: string;
6
6
  namespace: string;
7
- private_key: string;
7
+ private_key?: string;
8
+ private_key_path?: string;
8
9
  region: string;
9
10
  tenancy: string;
10
11
  user: string;
@@ -1,5 +1,5 @@
1
1
  /* * */
2
- import { HttpException, HTTP_STATUS } from '@tmlmobilidade/consts';
2
+ import { HTTP_STATUS, HttpException } from '@tmlmobilidade/consts';
3
3
  import { mimeTypes } from '@tmlmobilidade/consts';
4
4
  import { readFileSync } from 'node:fs';
5
5
  import { OciError, Region, SimpleAuthenticationDetailsProvider } from 'oci-common';
@@ -13,7 +13,7 @@ export class OCIStorageProvider {
13
13
  region;
14
14
  constructor(config) {
15
15
  this.ociClient = new ObjectStorageClient({
16
- authenticationDetailsProvider: new SimpleAuthenticationDetailsProvider(config.tenancy, config.user, config.fingerprint, readFileSync(config.private_key, 'utf8'), null, Region.fromRegionId(config.region)),
16
+ authenticationDetailsProvider: new SimpleAuthenticationDetailsProvider(config.tenancy, config.user, config.fingerprint, config.private_key_path ? readFileSync(config.private_key_path, 'utf8') : config.private_key, null, Region.fromRegionId(config.region)),
17
17
  });
18
18
  this.region = Region.fromRegionId(config.region);
19
19
  this.namespace = config.namespace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20260411.1243.43",
3
+ "version": "20260411.1248.30",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"
@@ -49,14 +49,14 @@
49
49
  "@tmlmobilidade/writers": "*",
50
50
  "bcryptjs": "3.0.3",
51
51
  "mongodb": "7.1.1",
52
- "oci-common": "2.126.3",
53
- "oci-objectstorage": "2.126.3",
52
+ "oci-common": "2.127.0",
53
+ "oci-objectstorage": "2.127.0",
54
54
  "zod": "3.25.76"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@tmlmobilidade/tsconfig": "*",
58
58
  "@tmlmobilidade/types": "*",
59
- "@types/node": "25.5.0",
59
+ "@types/node": "25.5.2",
60
60
  "resolve-tspaths": "0.8.23",
61
61
  "tsc-watch": "7.2.0",
62
62
  "typescript": "5.9.3"