@naturalcycles/backend-lib 9.59.3 → 9.61.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
  /**
@@ -110,7 +110,7 @@ export class BaseAdminService {
110
110
  return;
111
111
  return {
112
112
  email: email,
113
- permissions: [...hasPermissions],
113
+ permissions: Array.from(hasPermissions),
114
114
  };
115
115
  }
116
116
  async requirePermissions(req, reqPermissions = [], meta = {}, andComparison = true) {
@@ -154,7 +154,7 @@ export class BaseAdminService {
154
154
  }
155
155
  return {
156
156
  email,
157
- permissions: [...grantedPermissions],
157
+ permissions: grantedPermissions.slice(),
158
158
  };
159
159
  }
160
160
  // convenience method
@@ -1,5 +1,5 @@
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
3
  export interface FirebaseSharedServiceCfg {
4
4
  /**
5
5
  * If undefined - will try to use credential.applicationDefault()
@@ -32,6 +32,6 @@ export declare class FirebaseSharedService {
32
32
  cfg: FirebaseSharedServiceCfg;
33
33
  constructor(cfg: FirebaseSharedServiceCfg);
34
34
  init(): Promise<void>;
35
- admin(): Promise<FirebaseAdmin.app.App>;
36
- auth(): Promise<FirebaseAdmin.auth.Auth>;
35
+ admin(): Promise<App>;
36
+ auth(): Promise<Auth>;
37
37
  }
@@ -11,18 +11,17 @@ 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);
26
25
  }
27
26
  }
28
27
  __decorate([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.59.3",
4
+ "version": "9.61.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.45.1"
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
 
@@ -168,7 +168,7 @@ export class BaseAdminService {
168
168
 
169
169
  return {
170
170
  email: email!,
171
- permissions: [...hasPermissions],
171
+ permissions: Array.from(hasPermissions),
172
172
  }
173
173
  }
174
174
 
@@ -221,7 +221,7 @@ export class BaseAdminService {
221
221
 
222
222
  return {
223
223
  email,
224
- permissions: [...grantedPermissions],
224
+ permissions: grantedPermissions.slice(),
225
225
  }
226
226
  }
227
227
 
@@ -1,6 +1,6 @@
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
4
 
5
5
  export interface FirebaseSharedServiceCfg {
6
6
  /**
@@ -44,17 +44,15 @@ export class FirebaseSharedService {
44
44
  }
45
45
 
46
46
  @_Memo()
47
- async admin(): Promise<FirebaseAdmin.app.App> {
47
+ async admin(): Promise<App> {
48
48
  const { serviceAccount } = this.cfg
49
49
 
50
50
  // lazy loading
51
- const { default: admin } = await import('firebase-admin')
51
+ const { initializeApp, cert, applicationDefault } = await import('firebase-admin/app')
52
52
 
53
- const credential = serviceAccount
54
- ? admin.credential.cert(serviceAccount)
55
- : admin.credential.applicationDefault()
53
+ const credential = serviceAccount ? cert(serviceAccount) : applicationDefault()
56
54
 
57
- return admin.initializeApp(
55
+ return initializeApp(
58
56
  {
59
57
  credential,
60
58
  ...this.cfg.opt,
@@ -63,8 +61,9 @@ export class FirebaseSharedService {
63
61
  )
64
62
  }
65
63
 
66
- async auth(): Promise<FirebaseAdmin.auth.Auth> {
67
- const admin = await this.admin()
68
- return admin.auth()
64
+ async auth(): Promise<Auth> {
65
+ const app = await this.admin()
66
+ const { getAuth } = await import('firebase-admin/auth')
67
+ return getAuth(app)
69
68
  }
70
69
  }