@tmlmobilidade/interfaces 20251031.1051.3 → 20251202.1817.5
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/{src → common}/enrich-user-refs.js +1 -2
- package/dist/common/index.d.ts +4 -0
- package/dist/common/index.js +4 -0
- package/dist/{src → common}/mongo-collection.d.ts +3 -3
- package/dist/{src → common}/mongo-collection.js +4 -3
- package/dist/{src → common}/mongo-transaction.d.ts +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.js +3 -6
- package/dist/{src/interfaces → interfaces}/agencies/agencies.d.ts +3 -3
- package/dist/{src/interfaces → interfaces}/agencies/agencies.js +1 -1
- package/dist/{src/interfaces → interfaces}/alerts/alerts.d.ts +42 -4
- package/dist/{src/interfaces → interfaces}/alerts/alerts.js +4 -1
- package/dist/interfaces/alerts/index.d.ts +1 -0
- package/dist/interfaces/alerts/index.js +1 -0
- package/dist/interfaces/auth/roles.d.ts +240 -0
- package/dist/interfaces/auth/roles.js +69 -0
- package/dist/{src/interfaces → interfaces}/auth/sessions.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/auth/sessions.js +1 -1
- package/dist/interfaces/auth/users.d.ts +522 -0
- package/dist/interfaces/auth/users.js +118 -0
- package/dist/{src/interfaces → interfaces}/auth/verification-tokens.d.ts +2 -2
- package/dist/{src/interfaces → interfaces}/auth/verification-tokens.js +1 -1
- package/dist/{src/interfaces → interfaces}/file-exports/file-exports.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/file-exports/file-exports.js +2 -2
- package/dist/{src/interfaces → interfaces}/files/files.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/files/files.js +6 -36
- package/dist/{src/interfaces → interfaces}/gtfs-validations/gtfs-validations.d.ts +3 -3
- package/dist/{src/interfaces → interfaces}/gtfs-validations/gtfs-validations.js +1 -1
- package/dist/{src/interfaces → interfaces}/index.d.ts +1 -0
- package/dist/{src/interfaces → interfaces}/index.js +1 -0
- package/dist/interfaces/locations/index.d.ts +2 -0
- package/dist/interfaces/locations/index.js +2 -0
- package/dist/{src/interfaces → interfaces}/locations/locations.d.ts +17 -17
- package/dist/{src/interfaces → interfaces}/locations/locations.js +3 -3
- package/dist/interfaces/locations/municipalities.d.ts +13 -0
- package/dist/interfaces/locations/municipalities.js +29 -0
- package/dist/{src/interfaces → interfaces}/metrics/metrics.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/metrics/metrics.js +1 -1
- package/dist/{src/interfaces → interfaces}/notifications/notifications.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/notifications/notifications.js +5 -5
- package/dist/{src/interfaces → interfaces}/organizations/organizations.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/organizations/organizations.js +3 -3
- package/dist/interfaces/pcgidb/index.d.ts +3 -0
- package/dist/interfaces/pcgidb/index.js +3 -0
- package/dist/interfaces/pcgidb/pcgidb-legacy.d.ts +19 -0
- package/dist/interfaces/pcgidb/pcgidb-legacy.js +133 -0
- package/dist/interfaces/pcgidb/pcgidb-ticketing.d.ts +16 -0
- package/dist/interfaces/pcgidb/pcgidb-ticketing.js +127 -0
- package/dist/interfaces/pcgidb/pcgidb-validations.d.ts +17 -0
- package/dist/interfaces/pcgidb/pcgidb-validations.js +129 -0
- package/dist/{src/interfaces → interfaces}/plans/plans.d.ts +12 -6
- package/dist/{src/interfaces → interfaces}/plans/plans.js +1 -1
- package/dist/{src/interfaces → interfaces}/proposed-changes/proposed-changes.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/proposed-changes/proposed-changes.js +1 -1
- package/dist/{src/interfaces → interfaces}/rides/hashed-shapes.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/rides/hashed-shapes.js +1 -1
- package/dist/{src/interfaces → interfaces}/rides/hashed-trips.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/rides/hashed-trips.js +1 -1
- package/dist/{src/interfaces → interfaces}/rides/pipelines.d.ts +9 -9
- package/dist/{src/interfaces → interfaces}/rides/pipelines.js +20 -2
- package/dist/{src/interfaces → interfaces}/rides/ride-acceptances.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/rides/ride-acceptances.js +4 -3
- package/dist/{src/interfaces → interfaces}/rides/rides.d.ts +313 -313
- package/dist/{src/interfaces → interfaces}/rides/rides.js +1 -1
- package/dist/{src/interfaces → interfaces}/sams/sams.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/sams/sams.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspection-decisions.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspection-decisions.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspections.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspections.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-locations.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-locations.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-refunds.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-refunds.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-sales.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-sales.js +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-validations.d.ts +1 -1
- package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-validations.js +1 -1
- package/dist/{src/interfaces → interfaces}/stops/stops.d.ts +7 -7
- package/dist/{src/interfaces → interfaces}/stops/stops.js +1 -1
- package/dist/interfaces/vehicle-events/index.d.ts +1 -0
- package/dist/interfaces/vehicle-events/index.js +1 -0
- package/dist/interfaces/vehicle-events/simplified-vehicle-events.d.ts +13 -0
- package/dist/interfaces/vehicle-events/simplified-vehicle-events.js +33 -0
- package/dist/{src/interfaces → interfaces}/zones/zones.d.ts +3 -3
- package/dist/{src/interfaces → interfaces}/zones/zones.js +1 -1
- package/dist/{src/providers → providers}/auth/auth.d.ts +21 -12
- package/dist/{src/providers → providers}/auth/auth.js +71 -60
- package/dist/providers/auth/index.d.ts +1 -0
- package/dist/providers/auth/index.js +1 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +2 -0
- package/dist/providers/storage/index.d.ts +3 -0
- package/dist/providers/storage/index.js +3 -0
- package/dist/{src/providers → providers}/storage/oci-storage.js +2 -1
- package/dist/{src/providers → providers}/storage/storage.factory.d.ts +2 -11
- package/dist/{src/providers → providers}/storage/storage.factory.js +0 -5
- package/package.json +25 -26
- package/dist/src/interfaces/alerts/alerts-realtime.d.ts +0 -86
- package/dist/src/interfaces/alerts/alerts-realtime.js +0 -47
- package/dist/src/interfaces/alerts/index.d.ts +0 -2
- package/dist/src/interfaces/alerts/index.js +0 -2
- package/dist/src/interfaces/auth/roles.d.ts +0 -39
- package/dist/src/interfaces/auth/roles.js +0 -42
- package/dist/src/interfaces/auth/users.d.ts +0 -107
- package/dist/src/interfaces/auth/users.js +0 -110
- package/dist/src/interfaces/locations/index.d.ts +0 -1
- package/dist/src/interfaces/locations/index.js +0 -1
- package/dist/src/interfaces/vehicle-events/index.d.ts +0 -1
- package/dist/src/interfaces/vehicle-events/index.js +0 -1
- package/dist/src/interfaces/vehicle-events/vehicle-events.d.ts +0 -13
- package/dist/src/interfaces/vehicle-events/vehicle-events.js +0 -37
- package/dist/src/providers/index.d.ts +0 -5
- package/dist/src/providers/index.js +0 -6
- package/dist/src/providers/storage/s3-storage.d.ts +0 -64
- package/dist/src/providers/storage/s3-storage.js +0 -184
- /package/dist/{src → common}/aggregation-pipeline.d.ts +0 -0
- /package/dist/{src → common}/aggregation-pipeline.js +0 -0
- /package/dist/{src → common}/enrich-user-refs.d.ts +0 -0
- /package/dist/{src → common}/mongo-transaction.js +0 -0
- /package/dist/{src/interfaces → interfaces}/agencies/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/agencies/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/auth/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/auth/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/file-exports/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/file-exports/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/files/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/files/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/gtfs-validations/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/gtfs-validations/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/metrics/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/metrics/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/notifications/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/notifications/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/organizations/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/organizations/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/plans/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/plans/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/proposed-changes/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/proposed-changes/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/rides/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/rides/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/sams/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/sams/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/simplified-apex/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/simplified-apex/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/stops/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/stops/index.js +0 -0
- /package/dist/{src/interfaces → interfaces}/zones/index.d.ts +0 -0
- /package/dist/{src/interfaces → interfaces}/zones/index.js +0 -0
- /package/dist/{src/providers → providers}/storage/oci-storage.d.ts +0 -0
- /package/dist/{src/providers → providers}/storage/storage.interface.d.ts +0 -0
- /package/dist/{src/providers → providers}/storage/storage.interface.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* * */
|
|
3
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
3
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
4
4
|
import { FileExportSchema, UpdateFileExportSchema } from '@tmlmobilidade/types';
|
|
5
5
|
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
6
6
|
/* * */
|
|
@@ -33,7 +33,7 @@ class FileExportsClass extends MongoCollectionClass {
|
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
35
|
getCollectionName() {
|
|
36
|
-
return '
|
|
36
|
+
return 'exports';
|
|
37
37
|
}
|
|
38
38
|
getEnvName() {
|
|
39
39
|
return 'DATABASE_URI';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
1
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
2
2
|
import { CreateFileDto, File, UpdateFileDto } from '@tmlmobilidade/types';
|
|
3
3
|
import { DeleteOptions, DeleteResult, IndexDescription, InsertOneOptions, WithId } from 'mongodb';
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
3
|
import { StorageFactory } from '../../providers/index.js';
|
|
4
|
-
import { HttpException, HttpStatus } from '@tmlmobilidade/
|
|
4
|
+
import { HttpException, HttpStatus } from '@tmlmobilidade/consts';
|
|
5
|
+
import { Files } from '@tmlmobilidade/files';
|
|
6
|
+
import { generateRandomString } from '@tmlmobilidade/strings';
|
|
5
7
|
import { CreateFileSchema, FileSchema, UpdateFileSchema } from '@tmlmobilidade/types';
|
|
6
8
|
import { AsyncSingletonProxy, convertObject } from '@tmlmobilidade/utils';
|
|
7
|
-
import { generateRandomString } from '@tmlmobilidade/utils';
|
|
8
|
-
import { Files } from '@tmlmobilidade/utils';
|
|
9
9
|
/* * */
|
|
10
10
|
class FilesClass extends MongoCollectionClass {
|
|
11
11
|
static _instance;
|
|
@@ -15,37 +15,7 @@ class FilesClass extends MongoCollectionClass {
|
|
|
15
15
|
storageService;
|
|
16
16
|
constructor() {
|
|
17
17
|
super();
|
|
18
|
-
switch (process.env.
|
|
19
|
-
case 'aws':
|
|
20
|
-
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_BUCKET_NAME || !process.env.AWS_SECRET_ACCESS_KEY) {
|
|
21
|
-
throw new Error('AWS_ACCESS_KEY_ID, AWS_BUCKET_NAME, and AWS_SECRET_ACCESS_KEY must be set');
|
|
22
|
-
}
|
|
23
|
-
this.bucketName = process.env.AWS_BUCKET_NAME;
|
|
24
|
-
this.storageService = StorageFactory.create({
|
|
25
|
-
aws_config: {
|
|
26
|
-
access_key_id: process.env.AWS_ACCESS_KEY_ID,
|
|
27
|
-
bucket_name: process.env.AWS_BUCKET_NAME,
|
|
28
|
-
secret_access_key: process.env.AWS_SECRET_ACCESS_KEY,
|
|
29
|
-
},
|
|
30
|
-
type: 'aws',
|
|
31
|
-
});
|
|
32
|
-
break;
|
|
33
|
-
case 'cloudflare':
|
|
34
|
-
if (!process.env.CLOUDFLARE_ACCESS_KEY_ID || !process.env.CLOUDFLARE_BUCKET_NAME || !process.env.CLOUDFLARE_SECRET_ACCESS_KEY) {
|
|
35
|
-
throw new Error('CLOUDFLARE_ACCESS_KEY_ID, CLOUDFLARE_BUCKET_NAME, and CLOUDFLARE_SECRET_ACCESS_KEY must be set');
|
|
36
|
-
}
|
|
37
|
-
this.bucketName = process.env.CLOUDFLARE_BUCKET_NAME;
|
|
38
|
-
this.storageService = StorageFactory.create({
|
|
39
|
-
cloudflare_config: {
|
|
40
|
-
access_key_id: process.env.CLOUDFLARE_ACCESS_KEY_ID,
|
|
41
|
-
bucket_name: process.env.CLOUDFLARE_BUCKET_NAME,
|
|
42
|
-
endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
43
|
-
region: 'auto',
|
|
44
|
-
secret_access_key: process.env.CLOUDFLARE_SECRET_ACCESS_KEY,
|
|
45
|
-
},
|
|
46
|
-
type: 'cloudflare',
|
|
47
|
-
});
|
|
48
|
-
break;
|
|
18
|
+
switch (process.env.STORAGE_TYPE) {
|
|
49
19
|
case 'oci':
|
|
50
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) {
|
|
51
21
|
throw new Error('OCI_BUCKET_NAME, OCI_FINGERPRINT, OCI_NAMESPACE, OCI_PRIVATE_KEY, OCI_REGION, OCI_TENANCY, and OCI_USER must be set');
|
|
@@ -65,7 +35,7 @@ class FilesClass extends MongoCollectionClass {
|
|
|
65
35
|
});
|
|
66
36
|
break;
|
|
67
37
|
default:
|
|
68
|
-
throw new Error(`Invalid storage type: ${process.env.
|
|
38
|
+
throw new Error(`Invalid storage type: ${process.env.STORAGE_TYPE}`);
|
|
69
39
|
}
|
|
70
40
|
}
|
|
71
41
|
static async getInstance() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
1
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
2
2
|
import { CreateGtfsValidationDto, GtfsValidation, UpdateGtfsValidationDto } from '@tmlmobilidade/types';
|
|
3
3
|
import { IndexDescription } from 'mongodb';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -23,7 +23,7 @@ declare class GtfValidationsClass extends MongoCollectionClass<GtfsValidation, C
|
|
|
23
23
|
__brand: "UnixTimestamp";
|
|
24
24
|
};
|
|
25
25
|
file_id: string;
|
|
26
|
-
feeder_status: "
|
|
26
|
+
feeder_status: "waiting" | "processing" | "complete" | "error" | "skipped";
|
|
27
27
|
gtfs_agency: {
|
|
28
28
|
agency_id: string;
|
|
29
29
|
agency_name: string;
|
|
@@ -52,10 +52,10 @@ declare class GtfValidationsClass extends MongoCollectionClass<GtfsValidation, C
|
|
|
52
52
|
messages: {
|
|
53
53
|
message: string;
|
|
54
54
|
field: string;
|
|
55
|
+
validation_id: string;
|
|
55
56
|
file_name: string;
|
|
56
57
|
rows: number[];
|
|
57
58
|
severity: "error" | "warning" | "ignore" | "forbidden";
|
|
58
|
-
validation_id: string;
|
|
59
59
|
}[];
|
|
60
60
|
total_errors: number;
|
|
61
61
|
total_warnings: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
3
|
import { GtfsValidationSchema, UpdateGtfsValidationSchema } from '@tmlmobilidade/types';
|
|
4
4
|
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
5
5
|
/* * */
|
|
@@ -8,6 +8,7 @@ export * from './locations/index.js';
|
|
|
8
8
|
export * from './metrics/index.js';
|
|
9
9
|
export * from './notifications/index.js';
|
|
10
10
|
export * from './organizations/index.js';
|
|
11
|
+
export * from './pcgidb/index.js';
|
|
11
12
|
export * from './plans/index.js';
|
|
12
13
|
export * from './proposed-changes/index.js';
|
|
13
14
|
export * from './rides/index.js';
|
|
@@ -8,6 +8,7 @@ export * from './locations/index.js';
|
|
|
8
8
|
export * from './metrics/index.js';
|
|
9
9
|
export * from './notifications/index.js';
|
|
10
10
|
export * from './organizations/index.js';
|
|
11
|
+
export * from './pcgidb/index.js';
|
|
11
12
|
export * from './plans/index.js';
|
|
12
13
|
export * from './proposed-changes/index.js';
|
|
13
14
|
export * from './rides/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CensusFeature, type District, type Locality, type Location, type Municipality, type Parish } from '@tmlmobilidade/types';
|
|
2
2
|
import { Filter, FindOptions, WithId } from 'mongodb';
|
|
3
3
|
declare class LocationsClass {
|
|
4
4
|
private static _instance;
|
|
@@ -6,26 +6,26 @@ declare class LocationsClass {
|
|
|
6
6
|
private mongoConnector;
|
|
7
7
|
private constructor();
|
|
8
8
|
static getInstance(): Promise<LocationsClass>;
|
|
9
|
-
countCensus: (filter?: Filter<
|
|
9
|
+
countCensus: (filter?: Filter<CensusFeature>) => Promise<number>;
|
|
10
10
|
countDistricts: (filter?: Filter<District>) => Promise<number>;
|
|
11
11
|
countLocalities: (filter?: Filter<Locality>) => Promise<number>;
|
|
12
12
|
countMunicipalities: (filter?: Filter<Municipality>) => Promise<number>;
|
|
13
13
|
countParishes: (filter?: Filter<Parish>) => Promise<number>;
|
|
14
|
-
findCensus: (filter?: Filter<
|
|
15
|
-
findDistricts: (filter?: Filter<District>, options?: FindOptions
|
|
16
|
-
findLocalities: (filter?: Filter<Locality>, options?: FindOptions
|
|
17
|
-
findMunicipalities: (filter?: Filter<Municipality>, options?: FindOptions
|
|
18
|
-
findParishes: (filter?: Filter<Parish>, options?: FindOptions
|
|
19
|
-
findCensusById: (id: string, options?: FindOptions
|
|
20
|
-
findDistrictById: (id: string, options?: FindOptions
|
|
21
|
-
findLocalityById: (id: string, options?: FindOptions
|
|
22
|
-
findMunicipalityById: (id: string, options?: FindOptions
|
|
23
|
-
findParishById: (id: string, options?: FindOptions
|
|
24
|
-
findMunicipalitiesByGeo: (lat: number, lon: number, options?: FindOptions
|
|
25
|
-
findParishesByGeo: (lat: number, lon: number, options?: FindOptions
|
|
26
|
-
findDistrictsByGeo: (lat: number, lon: number, options?: FindOptions
|
|
27
|
-
findLocalitiesByGeo: (lat: number, lon: number, options?: FindOptions
|
|
28
|
-
findCensusByGeo: (lat: number, lon: number, options?: FindOptions
|
|
14
|
+
findCensus: (filter?: Filter<CensusFeature>, options?: FindOptions) => Promise<WithId<CensusFeature>[]>;
|
|
15
|
+
findDistricts: (filter?: Filter<District>, options?: FindOptions) => Promise<District[]>;
|
|
16
|
+
findLocalities: (filter?: Filter<Locality>, options?: FindOptions) => Promise<Locality[]>;
|
|
17
|
+
findMunicipalities: (filter?: Filter<Municipality>, options?: FindOptions) => Promise<Municipality[]>;
|
|
18
|
+
findParishes: (filter?: Filter<Parish>, options?: FindOptions) => Promise<Parish[]>;
|
|
19
|
+
findCensusById: (id: string, options?: FindOptions) => Promise<null | WithId<CensusFeature>>;
|
|
20
|
+
findDistrictById: (id: string, options?: FindOptions) => Promise<District | null>;
|
|
21
|
+
findLocalityById: (id: string, options?: FindOptions) => Promise<Locality | null>;
|
|
22
|
+
findMunicipalityById: (id: string, options?: FindOptions) => Promise<Municipality | null>;
|
|
23
|
+
findParishById: (id: string, options?: FindOptions) => Promise<null | Parish>;
|
|
24
|
+
findMunicipalitiesByGeo: (lat: number, lon: number, options?: FindOptions) => Promise<Municipality | null>;
|
|
25
|
+
findParishesByGeo: (lat: number, lon: number, options?: FindOptions) => Promise<null | Parish>;
|
|
26
|
+
findDistrictsByGeo: (lat: number, lon: number, options?: FindOptions) => Promise<District | null>;
|
|
27
|
+
findLocalitiesByGeo: (lat: number, lon: number, options?: FindOptions) => Promise<Locality | null>;
|
|
28
|
+
findCensusByGeo: (lat: number, lon: number, options?: FindOptions) => Promise<null | WithId<CensusFeature>>;
|
|
29
29
|
findLocationByGeo(lat: number, lon: number, { census }?: {
|
|
30
30
|
census?: boolean;
|
|
31
31
|
}): Promise<Location>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable perfectionist/sort-classes */
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { HttpException, HttpStatus } from '@tmlmobilidade/consts';
|
|
4
|
+
import { MongoConnector } from '@tmlmobilidade/mongo';
|
|
5
5
|
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
6
6
|
/* * */
|
|
7
7
|
class LocationsClass {
|
|
@@ -105,7 +105,7 @@ class LocationsClass {
|
|
|
105
105
|
const locality = await this.findLocalitiesByGeo(lat, lon, { projection: { _id: 1, properties: 1 } });
|
|
106
106
|
const _census = census ? await this.findCensusByGeo(lat, lon, { projection: { _id: 1, properties: 1 } }) : undefined;
|
|
107
107
|
return {
|
|
108
|
-
census: _census,
|
|
108
|
+
census: { ..._census.properties, _id: _census._id },
|
|
109
109
|
district: district,
|
|
110
110
|
latitude: lat,
|
|
111
111
|
locality: locality,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
2
|
+
import { type Municipality } from '@tmlmobilidade/types';
|
|
3
|
+
import { type IndexDescription } from 'mongodb';
|
|
4
|
+
declare class MunicipalitiesClass extends MongoCollectionClass<Municipality, Municipality, Municipality> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<MunicipalitiesClass>;
|
|
8
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
9
|
+
protected getCollectionName(): string;
|
|
10
|
+
protected getEnvName(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const municipalities: MunicipalitiesClass;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
4
|
+
/* * */
|
|
5
|
+
class MunicipalitiesClass extends MongoCollectionClass {
|
|
6
|
+
static _instance;
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
static async getInstance() {
|
|
11
|
+
if (!MunicipalitiesClass._instance) {
|
|
12
|
+
const instance = new MunicipalitiesClass();
|
|
13
|
+
await instance.connect();
|
|
14
|
+
MunicipalitiesClass._instance = instance;
|
|
15
|
+
}
|
|
16
|
+
return MunicipalitiesClass._instance;
|
|
17
|
+
}
|
|
18
|
+
getCollectionIndexes() {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
getCollectionName() {
|
|
22
|
+
return 'municipalities';
|
|
23
|
+
}
|
|
24
|
+
getEnvName() {
|
|
25
|
+
return 'DATABASE_URI';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/* * */
|
|
29
|
+
export const municipalities = AsyncSingletonProxy(MunicipalitiesClass);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
3
|
import { MetricSchema } from '@tmlmobilidade/types';
|
|
4
4
|
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
5
5
|
/* * */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
1
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
2
2
|
import { CreateNotificationDto, Notification, UpdateNotificationDto, User } from '@tmlmobilidade/types';
|
|
3
3
|
import { IndexDescription } from 'mongodb';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
|
+
import { roles } from '../auth/roles.js';
|
|
4
|
+
import { users } from '../auth/users.js';
|
|
5
|
+
import { getAppConfig } from '@tmlmobilidade/consts';
|
|
3
6
|
import { sendNotificationEmail } from '@tmlmobilidade/emails';
|
|
4
|
-
import { getAppConfig } from '@tmlmobilidade/lib';
|
|
5
7
|
import { NotificationSchema, UpdateNotificationSchema } from '@tmlmobilidade/types';
|
|
6
8
|
import { AsyncSingletonProxy, mergeObjects } from '@tmlmobilidade/utils';
|
|
7
|
-
import { roles } from '../auth/roles.js';
|
|
8
|
-
import { users } from '../auth/users.js';
|
|
9
9
|
/* * */
|
|
10
10
|
class NotificationsClass extends MongoCollectionClass {
|
|
11
11
|
static _instance;
|
|
@@ -107,7 +107,7 @@ class NotificationsClass extends MongoCollectionClass {
|
|
|
107
107
|
*/
|
|
108
108
|
getNotificationPermission(permissions, topic) {
|
|
109
109
|
const permission = permissions.get(`notifications:${topic}`);
|
|
110
|
-
return permission
|
|
110
|
+
return permission['resource']?.send_mail ?? false;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
export const notifications = AsyncSingletonProxy(NotificationsClass);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
1
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
2
2
|
import { CreateOrganizationDto, Organization, UpdateOrganizationDto } from '@tmlmobilidade/types';
|
|
3
3
|
import { IndexDescription } from 'mongodb';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { MongoCollectionClass } from '../../mongo-collection.js';
|
|
3
|
-
import { OrganizationSchema, UpdateOrganizationSchema } from '@tmlmobilidade/types';
|
|
2
|
+
import { MongoCollectionClass } from '../../common/mongo-collection.js';
|
|
3
|
+
import { CreateOrganizationSchema, OrganizationSchema, UpdateOrganizationSchema } from '@tmlmobilidade/types';
|
|
4
4
|
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
5
5
|
/* * */
|
|
6
6
|
class OrganizationsClass extends MongoCollectionClass {
|
|
7
7
|
static _instance;
|
|
8
|
-
createSchema =
|
|
8
|
+
createSchema = CreateOrganizationSchema;
|
|
9
9
|
updateSchema = UpdateOrganizationSchema;
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Collection } from 'mongodb';
|
|
2
|
+
declare class PCGIDBLegacyClass {
|
|
3
|
+
LocationEntity: Collection;
|
|
4
|
+
SalesEntity: Collection;
|
|
5
|
+
ValidationEntity: Collection;
|
|
6
|
+
VehicleEvents: Collection;
|
|
7
|
+
/**
|
|
8
|
+
* Establishes a connection to the Mongo database and initializes the collection.
|
|
9
|
+
* @throws If connection fails.
|
|
10
|
+
*/
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
|
|
14
|
+
* @throws If required environment variables are missing or if the tunnel setup fails.
|
|
15
|
+
*/
|
|
16
|
+
getPcgidbLegacyConnectionString(): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
export declare const pcgidbLegacy: PCGIDBLegacyClass;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
+
import { MongoConnector } from '@tmlmobilidade/mongo';
|
|
4
|
+
import { SshTunnelService } from '@tmlmobilidade/ssh';
|
|
5
|
+
/* * */
|
|
6
|
+
let GLOBAL_PCGIDB_TUNNEL_INSTANCE;
|
|
7
|
+
/* * */
|
|
8
|
+
class PCGIDBLegacyClass {
|
|
9
|
+
//
|
|
10
|
+
LocationEntity;
|
|
11
|
+
SalesEntity;
|
|
12
|
+
ValidationEntity;
|
|
13
|
+
VehicleEvents;
|
|
14
|
+
/**
|
|
15
|
+
* Establishes a connection to the Mongo database and initializes the collection.
|
|
16
|
+
* @throws If connection fails.
|
|
17
|
+
*/
|
|
18
|
+
async connect() {
|
|
19
|
+
//
|
|
20
|
+
//
|
|
21
|
+
// Setup SSH Tunnel, if required
|
|
22
|
+
const pcgidbLegacyConnectionString = await this.getPcgidbLegacyConnectionString();
|
|
23
|
+
//
|
|
24
|
+
// Get the database URI from environment variables
|
|
25
|
+
const mongoClientOptions = {
|
|
26
|
+
connectTimeoutMS: 10_000,
|
|
27
|
+
directConnection: true,
|
|
28
|
+
maxPoolSize: 20,
|
|
29
|
+
minPoolSize: 2,
|
|
30
|
+
readPreference: 'secondaryPreferred',
|
|
31
|
+
serverSelectionTimeoutMS: 10_000,
|
|
32
|
+
};
|
|
33
|
+
Logger.info('Connecting to PCGIDB Legacy...');
|
|
34
|
+
try {
|
|
35
|
+
// Connect to the MongoDB database
|
|
36
|
+
const mongoConnector = new MongoConnector(pcgidbLegacyConnectionString, mongoClientOptions);
|
|
37
|
+
await mongoConnector.connect();
|
|
38
|
+
// Setup collections
|
|
39
|
+
this.LocationEntity = mongoConnector.client.db('LocationManagement').collection('locationEntity');
|
|
40
|
+
this.SalesEntity = mongoConnector.client.db('SalesManagement').collection('salesEntity');
|
|
41
|
+
this.ValidationEntity = mongoConnector.client.db('ValidationsManagement').collection('validationEntity');
|
|
42
|
+
this.VehicleEvents = mongoConnector.client.db('CoreManagement').collection('VehicleEvents');
|
|
43
|
+
// Log success message
|
|
44
|
+
Logger.success('Connected to PCGIDB Legacy successfully.');
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error('Error connecting to PCGIDB Legacy:', { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sets up an SSH Tunnel, if required, and returns the appropriate database URL.
|
|
52
|
+
* @throws If required environment variables are missing or if the tunnel setup fails.
|
|
53
|
+
*/
|
|
54
|
+
async getPcgidbLegacyConnectionString() {
|
|
55
|
+
//
|
|
56
|
+
//
|
|
57
|
+
// Check if the required PCGIDB environment variables are set.
|
|
58
|
+
if (!process.env.PCGIDB_LEGACY_USER || !process.env.PCGIDB_LEGACY_PASSWORD) {
|
|
59
|
+
throw new Error('Missing PCGIDB_LEGACY_USER or PCGIDB_LEGACY_PASSWORD environment variable.');
|
|
60
|
+
}
|
|
61
|
+
if (!process.env.PCGIDB_LEGACY_ADDRESS || !process.env.PCGIDB_LEGACY_PORT) {
|
|
62
|
+
throw new Error('Missing PCGIDB_LEGACY_ADDRESS or PCGIDB_LEGACY_PORT environment variable.');
|
|
63
|
+
}
|
|
64
|
+
//
|
|
65
|
+
// Check if the SSH Tunnel is required based on the environment.
|
|
66
|
+
// In 'production' and 'staging', we assume direct connection is used.
|
|
67
|
+
if (process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging') {
|
|
68
|
+
return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@${process.env.PCGIDB_LEGACY_ADDRESS}:${process.env.PCGIDB_LEGACY_PORT}/`;
|
|
69
|
+
}
|
|
70
|
+
//
|
|
71
|
+
// If we're here, then the SSH Tunnel is to be used.
|
|
72
|
+
// Check if the required SSH Tunnel environment variables are set.
|
|
73
|
+
if (!process.env.PCGIDB_LEGACY_ADDRESS || !process.env.PCGIDB_LEGACY_PORT) {
|
|
74
|
+
throw new Error('Missing PCGIDB_LEGACY_ADDRESS or PCGIDB_LEGACY_PORT environment variable.');
|
|
75
|
+
}
|
|
76
|
+
if (!process.env.PCGIDB_TUNNEL_LOCAL_PORT) {
|
|
77
|
+
throw new Error('Missing PCGIDB_TUNNEL_LOCAL_PORT environment variable.');
|
|
78
|
+
}
|
|
79
|
+
if (!process.env.PCGIDB_TUNNEL_SSH_HOST || !process.env.PCGIDB_TUNNEL_SSH_USERNAME) {
|
|
80
|
+
throw new Error('Missing PCGIDB_TUNNEL_SSH_HOST or PCGIDB_TUNNEL_SSH_USERNAME environment variable.');
|
|
81
|
+
}
|
|
82
|
+
//
|
|
83
|
+
// Setup the SSH Tunnel connection configuration
|
|
84
|
+
const sshConfig = {
|
|
85
|
+
forwardOptions: {
|
|
86
|
+
dstAddr: process.env.PCGIDB_LEGACY_ADDRESS,
|
|
87
|
+
dstPort: Number(process.env.PCGIDB_LEGACY_PORT),
|
|
88
|
+
srcAddr: 'localhost',
|
|
89
|
+
srcPort: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
|
|
90
|
+
},
|
|
91
|
+
serverOptions: {
|
|
92
|
+
port: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
|
|
93
|
+
},
|
|
94
|
+
sshOptions: {
|
|
95
|
+
/**
|
|
96
|
+
* Using SSH Agent for authentication.
|
|
97
|
+
* Ensure that your SSH key is added to the SSH agent beforehand.
|
|
98
|
+
* @see https://developer.1password.com/docs/ssh/agent/compatibility/#ssh-auth-sock
|
|
99
|
+
*/
|
|
100
|
+
agent: process.env.SSH_AUTH_SOCK,
|
|
101
|
+
host: process.env.PCGIDB_TUNNEL_SSH_HOST,
|
|
102
|
+
keepaliveCountMax: 3, // Retry 3 times before closing the connection
|
|
103
|
+
keepaliveInterval: 10000, // Send keep-alive every 10 seconds
|
|
104
|
+
port: 22,
|
|
105
|
+
username: process.env.PCGIDB_TUNNEL_SSH_USERNAME,
|
|
106
|
+
},
|
|
107
|
+
tunnelOptions: {
|
|
108
|
+
autoClose: false,
|
|
109
|
+
reconnectOnError: true,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
const sshOptions = {
|
|
113
|
+
maxRetries: 3,
|
|
114
|
+
};
|
|
115
|
+
//
|
|
116
|
+
// Actually create the SSH Tunnel connection
|
|
117
|
+
if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
|
|
118
|
+
GLOBAL_PCGIDB_TUNNEL_INSTANCE = new SshTunnelService(sshConfig, sshOptions);
|
|
119
|
+
}
|
|
120
|
+
Logger.info('Setting up SSH Tunnel for PCGIDB Legacy...');
|
|
121
|
+
const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
|
|
122
|
+
//
|
|
123
|
+
// Construct the PCGIDB connection string using the SSH Tunnel local address
|
|
124
|
+
const localAddress = sshTunnelConnection.address();
|
|
125
|
+
if (!localAddress || typeof localAddress !== 'object') {
|
|
126
|
+
throw new Error('Failed to retrieve the SSH tunnel address for PCGIDB Legacy.');
|
|
127
|
+
}
|
|
128
|
+
return `mongodb://${process.env.PCGIDB_LEGACY_USER}:${process.env.PCGIDB_LEGACY_PASSWORD}@localhost:${localAddress.port}/`;
|
|
129
|
+
//
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/* * */
|
|
133
|
+
export const pcgidbLegacy = new PCGIDBLegacyClass();
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare const pcgidbTicketing: PCGIDBTicketingClass;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { Logger } from '@tmlmobilidade/logger';
|
|
3
|
+
import { MongoConnector } from '@tmlmobilidade/mongo';
|
|
4
|
+
import { SshTunnelService } 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: true,
|
|
25
|
+
maxPoolSize: 20,
|
|
26
|
+
minPoolSize: 2,
|
|
27
|
+
readPreference: 'secondaryPreferred',
|
|
28
|
+
serverSelectionTimeoutMS: 10_000,
|
|
29
|
+
};
|
|
30
|
+
Logger.info('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 || !process.env.PCGIDB_TICKETING_PORT) {
|
|
56
|
+
throw new Error('Missing PCGIDB_TICKETING_ADDRESS or PCGIDB_TICKETING_PORT environment variable.');
|
|
57
|
+
}
|
|
58
|
+
//
|
|
59
|
+
// Check if the SSH Tunnel is required based on the environment.
|
|
60
|
+
// In 'production' and 'staging', we assume direct connection is used.
|
|
61
|
+
if (process.env.ENVIRONMENT === 'production' || process.env.ENVIRONMENT === 'staging') {
|
|
62
|
+
return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@${process.env.PCGIDB_TICKETING_ADDRESS}:${process.env.PCGIDB_TICKETING_PORT}/`;
|
|
63
|
+
}
|
|
64
|
+
//
|
|
65
|
+
// If we're here, then the SSH Tunnel is to be used.
|
|
66
|
+
// Check if the required SSH Tunnel environment variables are set.
|
|
67
|
+
if (!process.env.PCGIDB_TICKETING_ADDRESS || !process.env.PCGIDB_TICKETING_PORT) {
|
|
68
|
+
throw new Error('Missing PCGIDB_TICKETING_ADDRESS or PCGIDB_TICKETING_PORT environment variable.');
|
|
69
|
+
}
|
|
70
|
+
if (!process.env.PCGIDB_TUNNEL_LOCAL_PORT) {
|
|
71
|
+
throw new Error('Missing PCGIDB_TUNNEL_LOCAL_PORT environment variable.');
|
|
72
|
+
}
|
|
73
|
+
if (!process.env.PCGIDB_TUNNEL_SSH_HOST || !process.env.PCGIDB_TUNNEL_SSH_USERNAME) {
|
|
74
|
+
throw new Error('Missing PCGIDB_TUNNEL_SSH_HOST or PCGIDB_TUNNEL_SSH_USERNAME environment variable.');
|
|
75
|
+
}
|
|
76
|
+
//
|
|
77
|
+
// Setup the SSH Tunnel connection configuration
|
|
78
|
+
const sshConfig = {
|
|
79
|
+
forwardOptions: {
|
|
80
|
+
dstAddr: process.env.PCGIDB_TICKETING_ADDRESS,
|
|
81
|
+
dstPort: Number(process.env.PCGIDB_TICKETING_PORT),
|
|
82
|
+
srcAddr: 'localhost',
|
|
83
|
+
srcPort: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
|
|
84
|
+
},
|
|
85
|
+
serverOptions: {
|
|
86
|
+
port: Number(process.env.PCGIDB_TUNNEL_LOCAL_PORT),
|
|
87
|
+
},
|
|
88
|
+
sshOptions: {
|
|
89
|
+
/**
|
|
90
|
+
* Using SSH Agent for authentication.
|
|
91
|
+
* Ensure that your SSH key is added to the SSH agent beforehand.
|
|
92
|
+
* @see https://developer.1password.com/docs/ssh/agent/compatibility/#ssh-auth-sock
|
|
93
|
+
*/
|
|
94
|
+
agent: process.env.SSH_AUTH_SOCK,
|
|
95
|
+
host: process.env.PCGIDB_TUNNEL_SSH_HOST,
|
|
96
|
+
keepaliveCountMax: 3, // Retry 3 times before closing the connection
|
|
97
|
+
keepaliveInterval: 10000, // Send keep-alive every 10 seconds
|
|
98
|
+
port: 22,
|
|
99
|
+
username: process.env.PCGIDB_TUNNEL_SSH_USERNAME,
|
|
100
|
+
},
|
|
101
|
+
tunnelOptions: {
|
|
102
|
+
autoClose: false,
|
|
103
|
+
reconnectOnError: true,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const sshOptions = {
|
|
107
|
+
maxRetries: 3,
|
|
108
|
+
};
|
|
109
|
+
//
|
|
110
|
+
// Actually create the SSH Tunnel connection
|
|
111
|
+
if (!GLOBAL_PCGIDB_TUNNEL_INSTANCE) {
|
|
112
|
+
GLOBAL_PCGIDB_TUNNEL_INSTANCE = new SshTunnelService(sshConfig, sshOptions);
|
|
113
|
+
}
|
|
114
|
+
Logger.info('Setting up SSH Tunnel for PCGIDB Ticketing...');
|
|
115
|
+
const sshTunnelConnection = await GLOBAL_PCGIDB_TUNNEL_INSTANCE.connect();
|
|
116
|
+
//
|
|
117
|
+
// Construct the PCGIDB connection string using the SSH Tunnel local address
|
|
118
|
+
const localAddress = sshTunnelConnection.address();
|
|
119
|
+
if (!localAddress || typeof localAddress !== 'object') {
|
|
120
|
+
throw new Error('Failed to retrieve the SSH tunnel address for PCGIDB Ticketing.');
|
|
121
|
+
}
|
|
122
|
+
return `mongodb://${process.env.PCGIDB_TICKETING_USER}:${process.env.PCGIDB_TICKETING_PASSWORD}@localhost:${localAddress.port}/`;
|
|
123
|
+
//
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/* * */
|
|
127
|
+
export const pcgidbTicketing = new PCGIDBTicketingClass();
|