@naturalcycles/backend-lib 9.60.0 → 9.62.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.
@@ -1,4 +1,4 @@
1
- import type FirebaseAdmin from 'firebase-admin';
1
+ import type { Auth } from 'firebase-admin/auth';
2
2
  import type { BackendRequest, BackendRequestHandler } from '../server/server.model.js';
3
3
  export interface AdminServiceCfg {
4
4
  /**
@@ -21,7 +21,7 @@ export interface AdminInfo {
21
21
  */
22
22
  export declare class BaseAdminService {
23
23
  private loadFirebaseAuth;
24
- constructor(loadFirebaseAuth: () => Promise<FirebaseAdmin.auth.Auth>, cfg: AdminServiceCfg);
24
+ constructor(loadFirebaseAuth: () => Promise<Auth>, cfg: AdminServiceCfg);
25
25
  cfg: Required<AdminServiceCfg>;
26
26
  adminInfoDisabled(): AdminInfo;
27
27
  /**
@@ -1,5 +1,6 @@
1
- import type { AppOptions, ServiceAccount } from 'firebase-admin';
2
- import type FirebaseAdmin from 'firebase-admin';
1
+ import type { App, AppOptions, ServiceAccount } from 'firebase-admin/app';
2
+ import type { Auth } from 'firebase-admin/auth';
3
+ import type { Messaging } from 'firebase-admin/messaging';
3
4
  export interface FirebaseSharedServiceCfg {
4
5
  /**
5
6
  * If undefined - will try to use credential.applicationDefault()
@@ -32,6 +33,7 @@ export declare class FirebaseSharedService {
32
33
  cfg: FirebaseSharedServiceCfg;
33
34
  constructor(cfg: FirebaseSharedServiceCfg);
34
35
  init(): Promise<void>;
35
- admin(): Promise<FirebaseAdmin.app.App>;
36
- auth(): Promise<FirebaseAdmin.auth.Auth>;
36
+ admin(): Promise<App>;
37
+ auth(): Promise<Auth>;
38
+ messaging(): Promise<Messaging>;
37
39
  }
@@ -11,18 +11,22 @@ export class FirebaseSharedService {
11
11
  async admin() {
12
12
  const { serviceAccount } = this.cfg;
13
13
  // lazy loading
14
- const { default: admin } = await import('firebase-admin');
15
- const credential = serviceAccount
16
- ? admin.credential.cert(serviceAccount)
17
- : admin.credential.applicationDefault();
18
- return admin.initializeApp({
14
+ const { initializeApp, cert, applicationDefault } = await import('firebase-admin/app');
15
+ const credential = serviceAccount ? cert(serviceAccount) : applicationDefault();
16
+ return initializeApp({
19
17
  credential,
20
18
  ...this.cfg.opt,
21
19
  }, this.cfg.appName);
22
20
  }
23
21
  async auth() {
24
- const admin = await this.admin();
25
- return admin.auth();
22
+ const app = await this.admin();
23
+ const { getAuth } = await import('firebase-admin/auth');
24
+ return getAuth(app);
25
+ }
26
+ async messaging() {
27
+ const app = await this.admin();
28
+ const { getMessaging } = await import('firebase-admin/messaging');
29
+ return getMessaging(app);
26
30
  }
27
31
  }
28
32
  __decorate([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.60.0",
4
+ "version": "9.62.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/db-lib": "^10",
7
7
  "@naturalcycles/js-lib": "^15",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@sentry/node-core": "^10",
30
- "firebase-admin": "^13",
30
+ "firebase-admin": "^14",
31
31
  "simple-git": "^3"
32
32
  },
33
33
  "peerDependenciesMeta": {
@@ -45,7 +45,7 @@
45
45
  "@sentry/node-core": "^10",
46
46
  "@typescript/native-preview": "beta",
47
47
  "fastify": "^5",
48
- "@naturalcycles/dev-lib": "20.48.0"
48
+ "@naturalcycles/dev-lib": "18.4.2"
49
49
  },
50
50
  "exports": {
51
51
  ".": "./dist/index.js",
@@ -1,7 +1,7 @@
1
1
  import { _Memo } from '@naturalcycles/js-lib/decorators'
2
2
  import { _assert, AppError } from '@naturalcycles/js-lib/error'
3
3
  import { dimGrey, green, red } from '@naturalcycles/nodejs-lib/colors'
4
- import type FirebaseAdmin from 'firebase-admin'
4
+ import type { Auth } from 'firebase-admin/auth'
5
5
  import type { BackendRequest, BackendRequestHandler } from '../server/server.model.js'
6
6
 
7
7
  export interface AdminServiceCfg {
@@ -33,7 +33,7 @@ const adminInfoDisabled = (): AdminInfo => ({
33
33
  */
34
34
  export class BaseAdminService {
35
35
  constructor(
36
- private loadFirebaseAuth: () => Promise<FirebaseAdmin.auth.Auth>,
36
+ private loadFirebaseAuth: () => Promise<Auth>,
37
37
  cfg: AdminServiceCfg,
38
38
  ) {
39
39
  this.cfg = {
@@ -112,7 +112,7 @@ export class BaseAdminService {
112
112
  }
113
113
 
114
114
  @_Memo()
115
- private async getFirebaseAuth(): Promise<FirebaseAdmin.auth.Auth> {
115
+ private async getFirebaseAuth(): Promise<Auth> {
116
116
  return await this.loadFirebaseAuth()
117
117
  }
118
118
 
@@ -1,6 +1,7 @@
1
1
  import { _Memo } from '@naturalcycles/js-lib/decorators/memo.decorator.js'
2
- import type { AppOptions, ServiceAccount } from 'firebase-admin'
3
- import type FirebaseAdmin from 'firebase-admin'
2
+ import type { App, AppOptions, ServiceAccount } from 'firebase-admin/app'
3
+ import type { Auth } from 'firebase-admin/auth'
4
+ import type { Messaging } from 'firebase-admin/messaging'
4
5
 
5
6
  export interface FirebaseSharedServiceCfg {
6
7
  /**
@@ -44,17 +45,15 @@ export class FirebaseSharedService {
44
45
  }
45
46
 
46
47
  @_Memo()
47
- async admin(): Promise<FirebaseAdmin.app.App> {
48
+ async admin(): Promise<App> {
48
49
  const { serviceAccount } = this.cfg
49
50
 
50
51
  // lazy loading
51
- const { default: admin } = await import('firebase-admin')
52
+ const { initializeApp, cert, applicationDefault } = await import('firebase-admin/app')
52
53
 
53
- const credential = serviceAccount
54
- ? admin.credential.cert(serviceAccount)
55
- : admin.credential.applicationDefault()
54
+ const credential = serviceAccount ? cert(serviceAccount) : applicationDefault()
56
55
 
57
- return admin.initializeApp(
56
+ return initializeApp(
58
57
  {
59
58
  credential,
60
59
  ...this.cfg.opt,
@@ -63,8 +62,15 @@ export class FirebaseSharedService {
63
62
  )
64
63
  }
65
64
 
66
- async auth(): Promise<FirebaseAdmin.auth.Auth> {
67
- const admin = await this.admin()
68
- return admin.auth()
65
+ async auth(): Promise<Auth> {
66
+ const app = await this.admin()
67
+ const { getAuth } = await import('firebase-admin/auth')
68
+ return getAuth(app)
69
+ }
70
+
71
+ async messaging(): Promise<Messaging> {
72
+ const app = await this.admin()
73
+ const { getMessaging } = await import('firebase-admin/messaging')
74
+ return getMessaging(app)
69
75
  }
70
76
  }