@causa/runtime-google 0.30.0 → 0.32.0

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.
@@ -0,0 +1,6 @@
1
+ import { v1 } from 'firebase-admin/firestore';
2
+ /**
3
+ * The low-level client to access administrative Firestore operations.
4
+ */
5
+ export declare const FirestoreAdminClient: typeof import("@google-cloud/firestore/types/v1/firestore_admin_client.js").FirestoreAdminClient;
6
+ export type FirestoreAdminClient = InstanceType<typeof v1.FirestoreAdminClient>;
@@ -0,0 +1,5 @@
1
+ import { v1 } from 'firebase-admin/firestore';
2
+ /**
3
+ * The low-level client to access administrative Firestore operations.
4
+ */
5
+ export const FirestoreAdminClient = v1.FirestoreAdminClient;
@@ -1,3 +1,4 @@
1
1
  export { getDefaultFirebaseApp } from './app.js';
2
+ export { FirestoreAdminClient } from './firestore-admin-client.type.js';
2
3
  export { FIREBASE_APP_TOKEN, InjectFirebaseApp, } from './inject-firebase-app.decorator.js';
3
4
  export { FirebaseModule } from './module.js';
@@ -1,3 +1,4 @@
1
1
  export { getDefaultFirebaseApp } from './app.js';
2
+ export { FirestoreAdminClient } from './firestore-admin-client.type.js';
2
3
  export { FIREBASE_APP_TOKEN, InjectFirebaseApp, } from './inject-firebase-app.decorator.js';
3
4
  export { FirebaseModule } from './module.js';
@@ -1,6 +1,7 @@
1
1
  import { OnApplicationShutdown } from '@nestjs/common';
2
2
  import { App } from 'firebase-admin/app';
3
3
  import { Firestore } from 'firebase-admin/firestore';
4
+ import { FirestoreAdminClient } from './firestore-admin-client.type.js';
4
5
  /**
5
6
  * A private service that handles the graceful shutdown of the Firebase App.
6
7
  * Should be imported in the `FirebaseModule`.
@@ -8,6 +9,7 @@ import { Firestore } from 'firebase-admin/firestore';
8
9
  export declare class FirebaseLifecycleService implements OnApplicationShutdown {
9
10
  private readonly app;
10
11
  private readonly firestore;
11
- constructor(app: App, firestore: Firestore);
12
+ private readonly firestoreAdmin;
13
+ constructor(app: App, firestore: Firestore, firestoreAdmin: FirestoreAdminClient);
12
14
  onApplicationShutdown(): Promise<void>;
13
15
  }
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  import { Injectable } from '@nestjs/common';
14
14
  import { deleteApp } from 'firebase-admin/app';
15
15
  import { Firestore } from 'firebase-admin/firestore';
16
+ import { FirestoreAdminClient } from './firestore-admin-client.type.js';
16
17
  import { InjectFirebaseApp } from './inject-firebase-app.decorator.js';
17
18
  /**
18
19
  * A private service that handles the graceful shutdown of the Firebase App.
@@ -21,11 +22,14 @@ import { InjectFirebaseApp } from './inject-firebase-app.decorator.js';
21
22
  let FirebaseLifecycleService = class FirebaseLifecycleService {
22
23
  app;
23
24
  firestore;
24
- constructor(app, firestore) {
25
+ firestoreAdmin;
26
+ constructor(app, firestore, firestoreAdmin) {
25
27
  this.app = app;
26
28
  this.firestore = firestore;
29
+ this.firestoreAdmin = firestoreAdmin;
27
30
  }
28
31
  async onApplicationShutdown() {
32
+ await this.firestoreAdmin.close();
29
33
  await this.firestore.terminate();
30
34
  await deleteApp(this.app);
31
35
  }
@@ -33,6 +37,7 @@ let FirebaseLifecycleService = class FirebaseLifecycleService {
33
37
  FirebaseLifecycleService = __decorate([
34
38
  Injectable(),
35
39
  __param(0, InjectFirebaseApp()),
36
- __metadata("design:paramtypes", [Object, Firestore])
40
+ __metadata("design:paramtypes", [Object, Firestore,
41
+ FirestoreAdminClient])
37
42
  ], FirebaseLifecycleService);
38
43
  export { FirebaseLifecycleService };
@@ -12,6 +12,7 @@ import { Auth, getAuth } from 'firebase-admin/auth';
12
12
  import { Firestore, getFirestore } from 'firebase-admin/firestore';
13
13
  import { Messaging, getMessaging } from 'firebase-admin/messaging';
14
14
  import { getDefaultFirebaseApp } from './app.js';
15
+ import { FirestoreAdminClient } from './firestore-admin-client.type.js';
15
16
  import { FIREBASE_APP_TOKEN } from './inject-firebase-app.decorator.js';
16
17
  import { FirebaseLifecycleService } from './lifecycle.service.js';
17
18
  /**
@@ -31,6 +32,10 @@ const childProviders = [
31
32
  useFactory: getMessaging,
32
33
  inject: [FIREBASE_APP_TOKEN],
33
34
  },
35
+ {
36
+ provide: FirestoreAdminClient,
37
+ useFactory: () => new FirestoreAdminClient(),
38
+ },
34
39
  ];
35
40
  /**
36
41
  * Creates the module metadata for the {@link FirebaseModule}.
@@ -1,11 +1,16 @@
1
1
  import { BaseHealthIndicatorService } from '@causa/runtime/nestjs';
2
2
  import { HealthIndicatorResult } from '@nestjs/terminus';
3
3
  import { Firestore } from 'firebase-admin/firestore';
4
+ import { FirestoreAdminClient } from '../firebase/index.js';
4
5
  /**
5
6
  * A service testing the availability of the Firestore service.
6
7
  */
7
8
  export declare class FirestoreHealthIndicator extends BaseHealthIndicatorService {
8
- private readonly firestore;
9
- constructor(firestore: Firestore);
9
+ private readonly admin;
10
+ /**
11
+ * The ID of the database used by Firestore.
12
+ */
13
+ private readonly databaseId;
14
+ constructor(admin: FirestoreAdminClient, firestore: Firestore);
10
15
  check(): Promise<HealthIndicatorResult>;
11
16
  }
@@ -11,6 +11,7 @@ import { BaseHealthIndicatorService } from '@causa/runtime/nestjs';
11
11
  import { Injectable } from '@nestjs/common';
12
12
  import { HealthCheckError } from '@nestjs/terminus';
13
13
  import { Firestore } from 'firebase-admin/firestore';
14
+ import { FirestoreAdminClient } from '../firebase/index.js';
14
15
  /**
15
16
  * The key used to identify the Firestore health indicator.
16
17
  */
@@ -19,18 +20,25 @@ const FIRESTORE_HEALTH_KEY = 'google.firestore';
19
20
  * A service testing the availability of the Firestore service.
20
21
  */
21
22
  let FirestoreHealthIndicator = class FirestoreHealthIndicator extends BaseHealthIndicatorService {
22
- firestore;
23
- constructor(firestore) {
23
+ admin;
24
+ /**
25
+ * The ID of the database used by Firestore.
26
+ */
27
+ databaseId;
28
+ constructor(admin, firestore) {
24
29
  super();
25
- this.firestore = firestore;
30
+ this.admin = admin;
31
+ this.databaseId = firestore.databaseId;
26
32
  }
27
33
  async check() {
28
34
  try {
29
- await this.firestore.listCollections();
35
+ const projectId = await this.admin.getProjectId();
36
+ const name = this.admin.databasePath(projectId, this.databaseId);
37
+ await this.admin.getDatabase({ name });
30
38
  return this.getStatus(FIRESTORE_HEALTH_KEY, true);
31
39
  }
32
40
  catch (error) {
33
- throw new HealthCheckError('Failed to check health by listing Firestore collections.', this.getStatus(FIRESTORE_HEALTH_KEY, false, {
41
+ throw new HealthCheckError('Failed to check health by getting Firestore database.', this.getStatus(FIRESTORE_HEALTH_KEY, false, {
34
42
  error: error.message,
35
43
  }));
36
44
  }
@@ -38,6 +46,7 @@ let FirestoreHealthIndicator = class FirestoreHealthIndicator extends BaseHealth
38
46
  };
39
47
  FirestoreHealthIndicator = __decorate([
40
48
  Injectable(),
41
- __metadata("design:paramtypes", [Firestore])
49
+ __metadata("design:paramtypes", [FirestoreAdminClient,
50
+ Firestore])
42
51
  ], FirestoreHealthIndicator);
43
52
  export { FirestoreHealthIndicator };
@@ -1,4 +1,5 @@
1
1
  import { CloudTasksClient, protos } from '@google-cloud/tasks';
2
+ import { ConfigService } from '@nestjs/config';
2
3
  import { RetryOptions } from 'google-gax';
3
4
  export import Task = protos.google.cloud.tasks.v2.ITask;
4
5
  export import HttpMethod = protos.google.cloud.tasks.v2.HttpMethod;
@@ -22,7 +23,16 @@ export type HttpRequestCreation = Omit<HttpRequest, 'body' | 'oidcToken'> & {
22
23
  */
23
24
  export declare class CloudTasksScheduler {
24
25
  private readonly client;
25
- constructor(client: CloudTasksClient);
26
+ private readonly configService;
27
+ constructor(client: CloudTasksClient, configService: ConfigService);
28
+ /**
29
+ * Returns the full path of the queue with the given name.
30
+ * It gets the path from the configuration, using the `TASKS_QUEUE_` prefix and the uppercase and underscored name.
31
+ *
32
+ * @param name The name of the queue.
33
+ * @returns The full path of the queue, or `null` if the configuration could not be found.
34
+ */
35
+ getQueuePath(name: string): string | null;
26
36
  /**
27
37
  * The promise resolving to the email of the service account used by the Cloud Tasks client.
28
38
  * This assumes that it is the account used by the current service / application.
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { CloudTasksClient, protos } from '@google-cloud/tasks';
11
11
  import { Injectable } from '@nestjs/common';
12
+ import { ConfigService } from '@nestjs/config';
12
13
  import { grpc } from 'google-gax';
13
14
  import { TemporaryCloudTasksError } from './errors.js';
14
15
  export var HttpMethod = protos.google.cloud.tasks.v2.HttpMethod;
@@ -44,8 +45,22 @@ const GRPC_RETRYABLE_CODES = [
44
45
  */
45
46
  let CloudTasksScheduler = class CloudTasksScheduler {
46
47
  client;
47
- constructor(client) {
48
+ configService;
49
+ constructor(client, configService) {
48
50
  this.client = client;
51
+ this.configService = configService;
52
+ }
53
+ /**
54
+ * Returns the full path of the queue with the given name.
55
+ * It gets the path from the configuration, using the `TASKS_QUEUE_` prefix and the uppercase and underscored name.
56
+ *
57
+ * @param name The name of the queue.
58
+ * @returns The full path of the queue, or `null` if the configuration could not be found.
59
+ */
60
+ getQueuePath(name) {
61
+ const configName = `TASKS_QUEUE_${name.toUpperCase().replace(/[\.-]{1}/g, '_')}`;
62
+ const queuePath = this.configService.get(configName);
63
+ return queuePath ?? null;
49
64
  }
50
65
  /**
51
66
  * The promise resolving to the email of the service account used by the Cloud Tasks client.
@@ -124,6 +139,7 @@ let CloudTasksScheduler = class CloudTasksScheduler {
124
139
  };
125
140
  CloudTasksScheduler = __decorate([
126
141
  Injectable(),
127
- __metadata("design:paramtypes", [CloudTasksClient])
142
+ __metadata("design:paramtypes", [CloudTasksClient,
143
+ ConfigService])
128
144
  ], CloudTasksScheduler);
129
145
  export { CloudTasksScheduler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/runtime-google",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "description": "An extension to the Causa runtime SDK (`@causa/runtime`), providing Google-specific features.",
5
5
  "repository": "github:causa-io/runtime-typescript-google",
6
6
  "license": "ISC",
@@ -31,20 +31,20 @@
31
31
  "dependencies": {
32
32
  "@causa/runtime": ">= 0.22.0 < 1.0.0",
33
33
  "@google-cloud/precise-date": "^4.0.0",
34
- "@google-cloud/pubsub": "^4.7.0",
34
+ "@google-cloud/pubsub": "^4.7.2",
35
35
  "@google-cloud/spanner": "^7.14.0",
36
36
  "@google-cloud/tasks": "^5.5.0",
37
- "@grpc/grpc-js": "^1.11.1",
38
- "@nestjs/common": "^10.4.1",
37
+ "@grpc/grpc-js": "^1.11.3",
38
+ "@nestjs/common": "^10.4.3",
39
39
  "@nestjs/config": "^3.2.3",
40
- "@nestjs/core": "^10.4.1",
40
+ "@nestjs/core": "^10.4.3",
41
41
  "@nestjs/passport": "^10.0.3",
42
- "@nestjs/swagger": "^7.4.0",
42
+ "@nestjs/swagger": "^7.4.2",
43
43
  "@nestjs/terminus": "^10.2.3",
44
44
  "class-transformer": "^0.5.1",
45
45
  "class-validator": "^0.14.1",
46
- "express": "^4.19.2",
47
- "firebase-admin": "^12.4.0",
46
+ "express": "^4.21.0",
47
+ "firebase-admin": "^12.5.0",
48
48
  "jsonwebtoken": "^9.0.2",
49
49
  "nestjs-pino": "^4.1.0",
50
50
  "passport-http-bearer": "^1.0.1",
@@ -52,16 +52,16 @@
52
52
  "reflect-metadata": "^0.2.2"
53
53
  },
54
54
  "devDependencies": {
55
- "@nestjs/testing": "^10.4.1",
55
+ "@nestjs/testing": "^10.4.3",
56
56
  "@tsconfig/node18": "^18.2.4",
57
- "@types/jest": "^29.5.12",
58
- "@types/jsonwebtoken": "^9.0.6",
59
- "@types/node": "^18.19.49",
57
+ "@types/jest": "^29.5.13",
58
+ "@types/jsonwebtoken": "^9.0.7",
59
+ "@types/node": "^18.19.50",
60
60
  "@types/passport-http-bearer": "^1.0.41",
61
61
  "@types/supertest": "^6.0.2",
62
62
  "@types/uuid": "^10.0.0",
63
63
  "dotenv": "^16.4.5",
64
- "eslint": "^9.9.1",
64
+ "eslint": "^9.10.0",
65
65
  "eslint-config-prettier": "^9.1.0",
66
66
  "eslint-plugin-prettier": "^5.2.1",
67
67
  "jest": "^29.7.0",
@@ -71,7 +71,7 @@
71
71
  "ts-jest": "^29.2.5",
72
72
  "ts-node": "^10.9.2",
73
73
  "typescript": "^5.5.4",
74
- "typescript-eslint": "^8.4.0",
74
+ "typescript-eslint": "^8.6.0",
75
75
  "uuid": "^10.0.0"
76
76
  }
77
77
  }