@tmlmobilidade/interfaces 20260720.2249.10 → 20260723.1350.16

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 (64) hide show
  1. package/dist/common/index.d.ts +0 -1
  2. package/dist/common/index.js +0 -1
  3. package/dist/interfaces/index.d.ts +0 -8
  4. package/dist/interfaces/index.js +0 -8
  5. package/dist/interfaces/rides/index.d.ts +0 -5
  6. package/dist/interfaces/rides/index.js +0 -5
  7. package/dist/interfaces/rides/pipelines.d.ts +1 -1
  8. package/dist/interfaces/rides/pipelines.js +3 -3
  9. package/dist/interfaces/simplified-apex/index.d.ts +0 -2
  10. package/dist/interfaces/simplified-apex/index.js +0 -2
  11. package/dist/interfaces/vehicle-events/simplified-vehicle-events.d.ts +1 -1
  12. package/package.json +3 -2
  13. package/dist/common/mongo-transaction.d.ts +0 -25
  14. package/dist/common/mongo-transaction.js +0 -61
  15. package/dist/interfaces/alerts/alerts.d.ts +0 -124
  16. package/dist/interfaces/alerts/alerts.js +0 -50
  17. package/dist/interfaces/alerts/index.d.ts +0 -1
  18. package/dist/interfaces/alerts/index.js +0 -1
  19. package/dist/interfaces/file-exports/file-exports.d.ts +0 -20
  20. package/dist/interfaces/file-exports/file-exports.js +0 -47
  21. package/dist/interfaces/file-exports/index.d.ts +0 -1
  22. package/dist/interfaces/file-exports/index.js +0 -1
  23. package/dist/interfaces/files/files.d.ts +0 -63
  24. package/dist/interfaces/files/files.js +0 -198
  25. package/dist/interfaces/files/index.d.ts +0 -1
  26. package/dist/interfaces/files/index.js +0 -1
  27. package/dist/interfaces/gtfs-validations/gtfs-validations.d.ts +0 -71
  28. package/dist/interfaces/gtfs-validations/gtfs-validations.js +0 -40
  29. package/dist/interfaces/gtfs-validations/index.d.ts +0 -1
  30. package/dist/interfaces/gtfs-validations/index.js +0 -1
  31. package/dist/interfaces/pcgidb/index.d.ts +0 -3
  32. package/dist/interfaces/pcgidb/index.js +0 -3
  33. package/dist/interfaces/pcgidb/pcgidb-legacy.d.ts +0 -21
  34. package/dist/interfaces/pcgidb/pcgidb-legacy.js +0 -82
  35. package/dist/interfaces/pcgidb/pcgidb-ticketing.d.ts +0 -20
  36. package/dist/interfaces/pcgidb/pcgidb-ticketing.js +0 -81
  37. package/dist/interfaces/pcgidb/pcgidb-validations.d.ts +0 -21
  38. package/dist/interfaces/pcgidb/pcgidb-validations.js +0 -84
  39. package/dist/interfaces/plans/index.d.ts +0 -1
  40. package/dist/interfaces/plans/index.js +0 -1
  41. package/dist/interfaces/plans/plans.d.ts +0 -83
  42. package/dist/interfaces/plans/plans.js +0 -41
  43. package/dist/interfaces/rides/hashed-patterns.d.ts +0 -16
  44. package/dist/interfaces/rides/hashed-patterns.js +0 -35
  45. package/dist/interfaces/rides/hashed-shapes.d.ts +0 -16
  46. package/dist/interfaces/rides/hashed-shapes.js +0 -34
  47. package/dist/interfaces/rides/hashed-trips.d.ts +0 -16
  48. package/dist/interfaces/rides/hashed-trips.js +0 -35
  49. package/dist/interfaces/rides/ride-acceptances.d.ts +0 -23
  50. package/dist/interfaces/rides/ride-acceptances.js +0 -85
  51. package/dist/interfaces/rides/rides.d.ts +0 -922
  52. package/dist/interfaces/rides/rides.js +0 -107
  53. package/dist/interfaces/simplified-apex/simplified-apex-inspection-decisions.d.ts +0 -13
  54. package/dist/interfaces/simplified-apex/simplified-apex-inspection-decisions.js +0 -36
  55. package/dist/interfaces/simplified-apex/simplified-apex-inspections.d.ts +0 -13
  56. package/dist/interfaces/simplified-apex/simplified-apex-inspections.js +0 -36
  57. package/dist/interfaces/stops/index.d.ts +0 -1
  58. package/dist/interfaces/stops/index.js +0 -1
  59. package/dist/interfaces/stops/stops.d.ts +0 -289
  60. package/dist/interfaces/stops/stops.js +0 -105
  61. package/dist/interfaces/vehicles/index.d.ts +0 -1
  62. package/dist/interfaces/vehicles/index.js +0 -1
  63. package/dist/interfaces/vehicles/vehicles.d.ts +0 -16
  64. package/dist/interfaces/vehicles/vehicles.js +0 -34
@@ -1,198 +0,0 @@
1
- /* * */
2
- import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { StorageFactory } from '../../providers/index.js';
4
- import { HTTP_STATUS, HttpException } from '@tmlmobilidade/consts';
5
- import { Files } from '@tmlmobilidade/files';
6
- import { generateRandomString } from '@tmlmobilidade/strings';
7
- import { CreateFileSchema, UpdateFileSchema } from '@tmlmobilidade/types';
8
- import { asyncSingletonProxy, convertObject } from '@tmlmobilidade/utils';
9
- /* * */
10
- class FilesClass extends MongoCollectionClass {
11
- //
12
- static _instance;
13
- createSchema = CreateFileSchema;
14
- updateSchema = UpdateFileSchema;
15
- bucketName;
16
- storageService;
17
- constructor() {
18
- super();
19
- switch (process.env.STORAGE_TYPE) {
20
- case 'oci':
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');
26
- }
27
- this.bucketName = process.env.OCI_BUCKET_NAME;
28
- this.storageService = StorageFactory.create({
29
- oci_config: {
30
- bucket_name: process.env.OCI_BUCKET_NAME,
31
- fingerprint: process.env.OCI_FINGERPRINT,
32
- namespace: process.env.OCI_NAMESPACE,
33
- private_key: process.env.OCI_PRIVATE_KEY,
34
- private_key_path: process.env.OCI_PRIVATE_KEY_PATH,
35
- region: process.env.OCI_REGION,
36
- tenancy: process.env.OCI_TENANCY,
37
- user: process.env.OCI_USER,
38
- },
39
- type: 'oci',
40
- });
41
- break;
42
- default:
43
- throw new Error(`Invalid storage type: ${process.env.STORAGE_TYPE}`);
44
- }
45
- }
46
- static async getInstance() {
47
- if (!FilesClass._instance) {
48
- const instance = new FilesClass();
49
- await instance.connect();
50
- FilesClass._instance = instance;
51
- }
52
- return FilesClass._instance;
53
- }
54
- /**
55
- * Clones a file from one resource to another.
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.
58
- * @returns The file that was cloned.
59
- */
60
- async clone(fileId, scope, resourceId, options) {
61
- const _id = generateRandomString({ length: 5 });
62
- const file = await this.findOne({ _id: fileId });
63
- if (!file)
64
- throw new HttpException(HTTP_STATUS.NOT_FOUND, 'File not found');
65
- const originalFilePath = `${file.scope}/${file.resource_id}/${file._id}.${Files.getFileExtension(file.name)}`;
66
- const newFilePath = `${scope}/${resourceId}/${_id}.${Files.getFileExtension(file.name)}`;
67
- await this.storageService.copyFile(originalFilePath, newFilePath);
68
- const newFile = convertObject(file, CreateFileSchema);
69
- return await this.insertOne({ ...newFile, _id, resource_id: resourceId, scope }, { options });
70
- }
71
- /**
72
- * Deletes a file from the storage service and the database.
73
- * @param fileId - The unique identifier of the file in the database.
74
- * @returns The file that was deleted.
75
- */
76
- async deleteById(fileId, options) {
77
- const foundFile = await this.findById(fileId);
78
- if (!foundFile)
79
- throw new HttpException(HTTP_STATUS.NOT_FOUND, 'File not found');
80
- await this.storageService.deleteFile(`${foundFile.scope}/${foundFile.resource_id}/${foundFile._id}.${Files.getFileExtensionFromMimeType(foundFile.type)}`);
81
- return await super.deleteById(fileId, { ...options, forceIfLocked: true });
82
- }
83
- /**
84
- * Retrieves a file from the database and adds the signed URL to the file object.
85
- * @param file_id - The unique identifier of the file in the database.
86
- * @returns The file with the signed URL.
87
- */
88
- async findById(id, options) {
89
- const file = await super.findById(id, options);
90
- if (!file) {
91
- return null;
92
- }
93
- file.url = await this.getFileUrl({ file_id: file._id }, options);
94
- return file;
95
- }
96
- /**
97
- * Retrieves the signed URL of a file from the storage service.
98
- * @param params - Object containing either `file_id` or `key`.
99
- * @param params.file_id - The unique identifier of the file in the database.
100
- * @param params.key - The storage key of the file.
101
- * @param options - Optional options.
102
- * @returns The signed URL of the file.
103
- * @throws {Error} If neither `file_id` nor `key` is provided.
104
- * @throws {HttpException} If `file_id` is provided but the file is not found.
105
- */
106
- async getFileUrl({ file_id, key }, options) {
107
- if (!file_id && !key) {
108
- throw new Error('Either "file_id" or "key" must be provided');
109
- }
110
- // If `file_id` is provided, fetch the file and use its key
111
- let file = null;
112
- if (file_id) {
113
- file = await this.findOne({ _id: file_id }, options);
114
- if (!file) {
115
- throw new HttpException(HTTP_STATUS.NOT_FOUND, 'File not found');
116
- }
117
- key = `${file.scope}/${file.resource_id}/${file._id}.${Files.getFileExtension(file.name)}`; // Use the file's storage key
118
- }
119
- // Check if key exists
120
- const keyExists = await this.storageService.fileExists(key);
121
- if (!keyExists) {
122
- throw new HttpException(HTTP_STATUS.NOT_FOUND, `Key ${key} does not exist in bucket ${this.bucketName}`);
123
- }
124
- // At this point, `key` must exist
125
- return this.storageService.getFileUrl(key);
126
- }
127
- /**
128
- * Uploads a file to the storage service and inserts it into the database.
129
- * @param file - The file to upload, either as a string, buffer, or readable stream.
130
- * @param createFileDto - The file type to create.
131
- * @returns The file that was uploaded.
132
- */
133
- async upload(file, createFileDto, options) {
134
- //
135
- //
136
- // A. Define variables
137
- if (createFileDto._id && !options?.override) {
138
- throw new HttpException(HTTP_STATUS.INTERNAL_SERVER_ERROR, 'When File ID is provided, override must be true');
139
- }
140
- const fileId = createFileDto._id || generateRandomString({ length: 5 });
141
- const fileExtension = Files.getFileExtension(createFileDto.name);
142
- const mimeType = Files.getMimeTypeFromFileExtension(createFileDto.name);
143
- const filePath = `${createFileDto.scope}/${createFileDto.resource_id}/${fileId}.${fileExtension}`;
144
- //
145
- // C. Handle database transaction
146
- const session = this.getMongoConnector().client.startSession();
147
- let result;
148
- try {
149
- session.startTransaction();
150
- //
151
- // C.1. Handle file override if specified
152
- if (options?.override) {
153
- const existingFile = await this.findOne({ _id: fileId });
154
- if (existingFile) {
155
- const existingFileExtension = Files.getFileExtension(existingFile.name);
156
- const existingFilePath = `${existingFile.scope}/${existingFile.resource_id}/${existingFile._id}.${existingFileExtension}`;
157
- if (existingFilePath !== filePath) {
158
- throw new HttpException(HTTP_STATUS.INTERNAL_SERVER_ERROR, 'File ID is provided, but the file path is different from the existing file', { cause: { existingFilePath, filePath } });
159
- }
160
- await super.deleteById(fileId);
161
- }
162
- }
163
- //
164
- // C.2. Upload file to storage
165
- await this.storageService.uploadFile(filePath, file, mimeType);
166
- //
167
- // C.3. Insert file record
168
- result = await this.insertOne({ ...createFileDto, _id: fileId, type: mimeType }, { options });
169
- await session.commitTransaction();
170
- }
171
- catch (error) {
172
- await session.abortTransaction();
173
- throw error;
174
- }
175
- finally {
176
- await session.endSession();
177
- }
178
- return result;
179
- }
180
- getCollectionIndexes() {
181
- return [
182
- { background: true, key: { created_by: 1 } },
183
- { background: true, key: { updated_by: 1 } },
184
- { background: true, key: { name: 1 } },
185
- { background: true, key: { type: 1 } },
186
- { background: true, key: { created_at: -1 } },
187
- { background: true, key: { updated_at: -1 } },
188
- ];
189
- }
190
- getCollectionName() {
191
- return 'files';
192
- }
193
- getEnvName() {
194
- return 'DATABASE_URI';
195
- }
196
- }
197
- /* * */
198
- export const files = asyncSingletonProxy(FilesClass);
@@ -1 +0,0 @@
1
- export * from './files.js';
@@ -1 +0,0 @@
1
- export * from './files.js';
@@ -1,71 +0,0 @@
1
- import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
- import { type CreateGtfsValidationDto, type GtfsValidation, type UpdateGtfsValidationDto } from '@tmlmobilidade/types';
3
- import { type IndexDescription } from 'mongodb';
4
- import { z } from 'zod';
5
- declare class GtfValidationsClass extends MongoCollectionClass<GtfsValidation, CreateGtfsValidationDto, UpdateGtfsValidationDto> {
6
- private static _instance;
7
- protected createSchema: z.ZodSchema;
8
- protected updateSchema: z.ZodSchema;
9
- private constructor();
10
- static getInstance(): Promise<GtfValidationsClass>;
11
- /**
12
- * Finds GTFS Validation documents by agency ID.
13
- * @param agencyId The agency ID to search for.
14
- * @returns A promise that resolves to an array of matching documents
15
- */
16
- findByAgencyId(agencyId: string): Promise<import("mongodb").WithId<{
17
- _id: string;
18
- created_at: number & {
19
- __brand: "UnixTimestamp";
20
- };
21
- created_by: string | null;
22
- is_locked: boolean;
23
- updated_at: number & {
24
- __brand: "UnixTimestamp";
25
- };
26
- file_id: string;
27
- processing_status: "error" | "waiting" | "processing" | "complete" | "skipped";
28
- gtfs_agency: {
29
- agency_id: string;
30
- agency_name: string;
31
- agency_timezone: string;
32
- agency_email?: string | null | undefined;
33
- agency_fare_url?: string | null | undefined;
34
- agency_lang?: string | null | undefined;
35
- agency_phone?: string | null | undefined;
36
- agency_url?: string | null | undefined;
37
- };
38
- gtfs_feed_info: {
39
- feed_lang: string;
40
- feed_end_date?: import("@tmlmobilidade/types").OperationalDate | null | undefined;
41
- feed_start_date?: import("@tmlmobilidade/types").OperationalDate | null | undefined;
42
- default_lang?: string | null | undefined;
43
- feed_contact_email?: string | null | undefined;
44
- feed_contact_url?: string | null | undefined;
45
- feed_publisher_name?: string | null | undefined;
46
- feed_publisher_url?: string | null | undefined;
47
- feed_version?: string | null | undefined;
48
- };
49
- notification_sent: boolean;
50
- validation_attempts: number;
51
- validity_status: "valid" | "unknown" | "invalid";
52
- updated_by?: string | undefined;
53
- summary?: {
54
- messages: {
55
- message: string;
56
- file_name: string;
57
- field: string;
58
- rows: number[];
59
- rule_id: string;
60
- severity: "error" | "warning" | "ignore" | "forbidden";
61
- }[];
62
- total_errors: number;
63
- total_warnings: number;
64
- } | null | undefined;
65
- }>[]>;
66
- protected getCollectionIndexes(): IndexDescription[];
67
- protected getCollectionName(): string;
68
- protected getEnvName(): string;
69
- }
70
- export declare const gtfsValidations: GtfValidationsClass;
71
- export {};
@@ -1,40 +0,0 @@
1
- /* * */
2
- import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
- import { CreateGtfsValidationSchema, UpdateGtfsValidationSchema } from '@tmlmobilidade/types';
4
- import { asyncSingletonProxy } from '@tmlmobilidade/utils';
5
- /* * */
6
- class GtfValidationsClass extends MongoCollectionClass {
7
- static _instance;
8
- createSchema = CreateGtfsValidationSchema;
9
- updateSchema = UpdateGtfsValidationSchema;
10
- constructor() {
11
- super();
12
- }
13
- static async getInstance() {
14
- if (!GtfValidationsClass._instance) {
15
- const instance = new GtfValidationsClass();
16
- await instance.connect();
17
- GtfValidationsClass._instance = instance;
18
- }
19
- return GtfValidationsClass._instance;
20
- }
21
- /**
22
- * Finds GTFS Validation documents by agency ID.
23
- * @param agencyId The agency ID to search for.
24
- * @returns A promise that resolves to an array of matching documents
25
- */
26
- async findByAgencyId(agencyId) {
27
- return this.mongoCollection.find({ agency_id: agencyId }).toArray();
28
- }
29
- getCollectionIndexes() {
30
- return [];
31
- }
32
- getCollectionName() {
33
- return 'gtfs_validations';
34
- }
35
- getEnvName() {
36
- return 'DATABASE_URI';
37
- }
38
- }
39
- /* * */
40
- export const gtfsValidations = asyncSingletonProxy(GtfValidationsClass);
@@ -1 +0,0 @@
1
- export * from './gtfs-validations.js';
@@ -1 +0,0 @@
1
- export * from './gtfs-validations.js';
@@ -1,3 +0,0 @@
1
- export * from './pcgidb-legacy.js';
2
- export * from './pcgidb-ticketing.js';
3
- export * from './pcgidb-validations.js';
@@ -1,3 +0,0 @@
1
- export * from './pcgidb-legacy.js';
2
- export * from './pcgidb-ticketing.js';
3
- export * from './pcgidb-validations.js';
@@ -1,21 +0,0 @@
1
- import { type Collection } from 'mongodb';
2
- declare class PCGIDBLegacyClass {
3
- VehicleEventsCore: Collection;
4
- VehicleEventsLog: Collection;
5
- /**
6
- * Establishes a connection to the Mongo database and initializes the collection.
7
- * @throws If connection fails.
8
- */
9
- connect(): Promise<void>;
10
- /**
11
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
12
- * @throws If required environment variables are missing or if the tunnel setup fails.
13
- */
14
- getPcgidbLegacyConnectionString(): Promise<string>;
15
- }
16
- /**
17
- * @deprecated This should not be used anymore. Only inside the `apex` module
18
- * and then you should use the services provided by the local package.
19
- */
20
- export declare const pcgidbLegacy: PCGIDBLegacyClass;
21
- export {};
@@ -1,82 +0,0 @@
1
- /* * */
2
- import { Logger } from '@tmlmobilidade/logger';
3
- import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
- /* * */
6
- let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
- /* * */
8
- class PCGIDBLegacyClass {
9
- //
10
- VehicleEventsCore;
11
- VehicleEventsLog;
12
- /**
13
- * Establishes a connection to the Mongo database and initializes the collection.
14
- * @throws If connection fails.
15
- */
16
- async connect() {
17
- //
18
- //
19
- // Setup SSH Tunnel, if required
20
- const pcgidbLegacyConnectionString = await this.getPcgidbLegacyConnectionString();
21
- //
22
- // Get the database URI from environment variables
23
- const mongoClientOptions = {
24
- connectTimeoutMS: 10_000,
25
- maxPoolSize: 20,
26
- minPoolSize: 2,
27
- readPreference: 'secondaryPreferred',
28
- serverSelectionTimeoutMS: 10_000,
29
- };
30
- Logger.info({ message: 'Connecting to PCGIDB Legacy...' });
31
- try {
32
- // Connect to the MongoDB database
33
- const mongoConnector = new MongoConnector(pcgidbLegacyConnectionString, mongoClientOptions);
34
- await mongoConnector.connect();
35
- // Setup collections
36
- this.VehicleEventsCore = mongoConnector.client.db('CoreManagement').collection('VehicleEvents');
37
- this.VehicleEventsLog = mongoConnector.client.db('OfferApiLog').collection('VehicleEvents');
38
- // Log success message
39
- Logger.success('Connected to PCGIDB Legacy successfully.');
40
- }
41
- catch (error) {
42
- throw new Error('Error connecting to PCGIDB Legacy:', { cause: error });
43
- }
44
- }
45
- /**
46
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
47
- * @throws If required environment variables are missing or if the tunnel setup fails.
48
- */
49
- async getPcgidbLegacyConnectionString() {
50
- //
51
- //
52
- // Check if the required PCGIDB environment variables are set.
53
- if (!process.env.PCGIDB_LEGACY_USER || !process.env.PCGIDB_LEGACY_PASSWORD) {
54
- throw new Error('Missing PCGIDB_LEGACY_USER or PCGIDB_LEGACY_PASSWORD environment variable.');
55
- }
56
- if (!process.env.PCGIDB_LEGACY_ADDRESS_1 || !process.env.PCGIDB_LEGACY_ADDRESS_2 || !process.env.PCGIDB_LEGACY_ADDRESS_3 || !process.env.PCGIDB_LEGACY_PORT) {
57
- throw new Error('Missing PCGIDB_LEGACY_ADDRESS_1, PCGIDB_LEGACY_ADDRESS_2, PCGIDB_LEGACY_ADDRESS_3 or PCGIDB_LEGACY_PORT environment variable.');
58
- }
59
- //
60
- // Setup the SSH Tunnel connection configuration
61
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_LEGACY_ADDRESS_1, dstPort: Number(process.env.PCGIDB_LEGACY_PORT) });
62
- if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
63
- return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@${process.env.PCGIDB_LEGACY_ADDRESS_1}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_2}:${process.env.PCGIDB_LEGACY_PORT},${process.env.PCGIDB_LEGACY_ADDRESS_3}:${process.env.PCGIDB_LEGACY_PORT}/`;
64
- }
65
- Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Legacy...' });
66
- const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
67
- //
68
- // Construct the PCGIDB connection string using the SSH Tunnel local address
69
- const localAddress = sshTunnelConnection.address();
70
- if (!localAddress || typeof localAddress !== 'object') {
71
- throw new Error('Failed to retrieve the SSH tunnel address for PCGIDB Legacy.');
72
- }
73
- return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@localhost:${localAddress.port}/?directConnection=true`;
74
- //
75
- }
76
- }
77
- /* * */
78
- /**
79
- * @deprecated This should not be used anymore. Only inside the `apex` module
80
- * and then you should use the services provided by the local package.
81
- */
82
- export const pcgidbLegacy = new PCGIDBLegacyClass();
@@ -1,20 +0,0 @@
1
- import { type Collection } from 'mongodb';
2
- declare class PCGIDBTicketingClass {
3
- SalesEntity: Collection;
4
- /**
5
- * Establishes a connection to the Mongo database and initializes the collection.
6
- * @throws If connection fails.
7
- */
8
- connect(): Promise<void>;
9
- /**
10
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
11
- * @throws If required environment variables are missing or if the tunnel setup fails.
12
- */
13
- getPcgidbTicketingConnectionString(): Promise<string>;
14
- }
15
- /**
16
- * @deprecated This should not be used anymore. Only inside the `apex` module
17
- * and then you should use the services provided by the local package.
18
- */
19
- export declare const pcgidbTicketing: PCGIDBTicketingClass;
20
- export {};
@@ -1,81 +0,0 @@
1
- /* * */
2
- import { Logger } from '@tmlmobilidade/logger';
3
- import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
- /* * */
6
- let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
- /* * */
8
- class PCGIDBTicketingClass {
9
- //
10
- SalesEntity;
11
- /**
12
- * Establishes a connection to the Mongo database and initializes the collection.
13
- * @throws If connection fails.
14
- */
15
- async connect() {
16
- //
17
- //
18
- // Setup SSH Tunnel, if required
19
- const pcgidbTicketingConnectionString = await this.getPcgidbTicketingConnectionString();
20
- //
21
- // Get the database URI from environment variables
22
- const mongoClientOptions = {
23
- connectTimeoutMS: 10_000,
24
- directConnection: process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging' ? false : true,
25
- maxPoolSize: 20,
26
- minPoolSize: 2,
27
- readPreference: 'secondaryPreferred',
28
- serverSelectionTimeoutMS: 10_000,
29
- };
30
- Logger.info({ message: 'Connecting to PCGIDB Ticketing...' });
31
- try {
32
- // Connect to the MongoDB database
33
- const mongoConnector = new MongoConnector(pcgidbTicketingConnectionString, mongoClientOptions);
34
- await mongoConnector.connect();
35
- // Setup collections
36
- this.SalesEntity = mongoConnector.client.db('SalesManagement').collection('salesEntity');
37
- // Log success message
38
- Logger.success('Connected to PCGIDB Ticketing successfully.');
39
- }
40
- catch (error) {
41
- throw new Error('Error connecting to PCGIDB Ticketing:', { cause: error });
42
- }
43
- }
44
- /**
45
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
46
- * @throws If required environment variables are missing or if the tunnel setup fails.
47
- */
48
- async getPcgidbTicketingConnectionString() {
49
- //
50
- //
51
- // Check if the required PCGIDB environment variables are set.
52
- if (!process.env.PCGIDB_TICKETING_USER || !process.env.PCGIDB_TICKETING_PASSWORD) {
53
- throw new Error('Missing PCGIDB_TICKETING_USER or PCGIDB_TICKETING_PASSWORD environment variable.');
54
- }
55
- if (!process.env.PCGIDB_TICKETING_ADDRESS_1 || !process.env.PCGIDB_TICKETING_ADDRESS_2 || !process.env.PCGIDB_TICKETING_ADDRESS_3 || !process.env.PCGIDB_TICKETING_PORT) {
56
- throw new Error('Missing PCGIDB_TICKETING_ADDRESS_1, PCGIDB_TICKETING_ADDRESS_2, PCGIDB_TICKETING_ADDRESS_3 or PCGIDB_TICKETING_PORT environment variable.');
57
- }
58
- //
59
- // Setup the SSH Tunnel
60
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_TICKETING_ADDRESS_1, dstPort: Number(process.env.PCGIDB_TICKETING_PORT) });
61
- if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
62
- return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@${process.env.PCGIDB_TICKETING_ADDRESS_1}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_2}:${process.env.PCGIDB_TICKETING_PORT},${process.env.PCGIDB_TICKETING_ADDRESS_3}:${process.env.PCGIDB_TICKETING_PORT}/`;
63
- }
64
- Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Ticketing...' });
65
- const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
66
- //
67
- // Construct the PCGIDB connection string using the SSH Tunnel local address
68
- const localAddress = sshTunnelConnection.address();
69
- if (!localAddress || typeof localAddress !== 'object') {
70
- throw new Error('Failed to retrieve the SSH tunnel address for PCGIDB Ticketing.');
71
- }
72
- return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@localhost:${localAddress.port}/`;
73
- //
74
- }
75
- }
76
- /* * */
77
- /**
78
- * @deprecated This should not be used anymore. Only inside the `apex` module
79
- * and then you should use the services provided by the local package.
80
- */
81
- export const pcgidbTicketing = new PCGIDBTicketingClass();
@@ -1,21 +0,0 @@
1
- import { type Collection } from 'mongodb';
2
- declare class PCGIDBValidationsClass {
3
- LocationEntity: Collection;
4
- ValidationEntity: Collection;
5
- /**
6
- * Establishes a connection to the Mongo database and initializes the collection.
7
- * @throws If connection fails.
8
- */
9
- connect(): Promise<void>;
10
- /**
11
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
12
- * @throws If required environment variables are missing or if the tunnel setup fails.
13
- */
14
- getPcgidbValidationsConnectionString(): Promise<string>;
15
- }
16
- /**
17
- * @deprecated This should not be used anymore. Only inside the `apex` module
18
- * and then you should use the services provided by the local package.
19
- */
20
- export declare const pcgidbValidations: PCGIDBValidationsClass;
21
- export {};
@@ -1,84 +0,0 @@
1
- /* * */
2
- import { Logger } from '@tmlmobilidade/logger';
3
- import { MongoConnector } from '@tmlmobilidade/mongo';
4
- import { pcgiSshTunnel } from '@tmlmobilidade/ssh';
5
- /* * */
6
- let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
7
- /* * */
8
- class PCGIDBValidationsClass {
9
- //
10
- LocationEntity;
11
- ValidationEntity;
12
- /**
13
- * Establishes a connection to the Mongo database and initializes the collection.
14
- * @throws If connection fails.
15
- */
16
- async connect() {
17
- //
18
- //
19
- // Setup SSH Tunnel, if required
20
- const pcgidbValidationsConnectionString = await this.getPcgidbValidationsConnectionString();
21
- //
22
- // Get the database URI from environment variables
23
- const mongoClientOptions = {
24
- connectTimeoutMS: 10_000,
25
- directConnection: process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging' ? false : true,
26
- maxPoolSize: 20,
27
- minPoolSize: 2,
28
- readPreference: 'secondaryPreferred',
29
- serverSelectionTimeoutMS: 10_000,
30
- };
31
- Logger.info({ message: 'Connecting to PCGIDB Validations...' });
32
- try {
33
- // Connect to the MongoDB database
34
- const mongoConnector = new MongoConnector(pcgidbValidationsConnectionString, mongoClientOptions);
35
- await mongoConnector.connect();
36
- // Setup collections
37
- this.LocationEntity = mongoConnector.client.db('LocationManagement').collection('locationEntity');
38
- this.ValidationEntity = mongoConnector.client.db('ValidationsManagement').collection('validationEntity');
39
- // Log success message
40
- Logger.success('Connected to PCGIDB Validations successfully.');
41
- }
42
- catch (error) {
43
- throw new Error('Error connecting to PCGIDB Validations:', { cause: error });
44
- }
45
- }
46
- /**
47
- * Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
48
- * @throws If required environment variables are missing or if the tunnel setup fails.
49
- */
50
- async getPcgidbValidationsConnectionString() {
51
- //
52
- //
53
- // Check if the required PCGIDB environment variables are set.
54
- if (!process.env.PCGIDB_VALIDATIONS_USER || !process.env.PCGIDB_VALIDATIONS_PASSWORD) {
55
- throw new Error('Missing PCGIDB_VALIDATIONS_USER or PCGIDB_VALIDATIONS_PASSWORD environment variable.');
56
- }
57
- if (!process.env.PCGIDB_VALIDATIONS_ADDRESS_1 || !process.env.PCGIDB_VALIDATIONS_ADDRESS_2 || !process.env.PCGIDB_VALIDATIONS_ADDRESS_3 || !process.env.PCGIDB_VALIDATIONS_PORT) {
58
- throw new Error('Missing PCGIDB_VALIDATIONS_ADDRESS_1, PCGIDB_VALIDATIONS_ADDRESS_2, PCGIDB_VALIDATIONS_ADDRESS_3 or PCGIDB_VALIDATIONS_PORT environment variable.');
59
- }
60
- //
61
- // Setup the SSH Tunnel
62
- GLOBAL_PCGIDB_TUNNEL_INSTANCE = pcgiSshTunnel({ dstAddr: process.env.PCGIDB_VALIDATIONS_ADDRESS_1, dstPort: Number(process.env.PCGIDB_VALIDATIONS_PORT) });
63
- if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
64
- return `mongodb://${process.env.PCGIDB_VALIDATIONS_USER}:${process.env.PCGIDB_VALIDATIONS_PASSWORD}@${process.env.PCGIDB_VALIDATIONS_ADDRESS_1}:${process.env.PCGIDB_VALIDATIONS_PORT},${process.env.PCGIDB_VALIDATIONS_ADDRESS_2}:${process.env.PCGIDB_VALIDATIONS_PORT},${process.env.PCGIDB_VALIDATIONS_ADDRESS_3}:${process.env.PCGIDB_VALIDATIONS_PORT}/`;
65
- }
66
- //
67
- Logger.info({ message: 'Setting up SSH Tunnel for PCGIDB Validations...' });
68
- const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
69
- //
70
- // Construct the PCGIDB connection string using the SSH Tunnel local address
71
- const localAddress = sshTunnelConnection.address();
72
- if (!localAddress || typeof localAddress !== 'object') {
73
- throw new Error('Failed to retrieve the SSH tunnel address for PCGIDB Validations.');
74
- }
75
- return `mongodb://${process.env.PCGIDB_VALIDATIONS_USER}:${process.env.PCGIDB_VALIDATIONS_PASSWORD}@localhost:${localAddress.port}/`;
76
- //
77
- }
78
- }
79
- /* * */
80
- /**
81
- * @deprecated This should not be used anymore. Only inside the `apex` module
82
- * and then you should use the services provided by the local package.
83
- */
84
- export const pcgidbValidations = new PCGIDBValidationsClass();
@@ -1 +0,0 @@
1
- export * from './plans.js';
@@ -1 +0,0 @@
1
- export * from './plans.js';