@naturalcycles/backend-lib 5.4.2 → 5.5.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.
|
@@ -41,7 +41,7 @@ export declare class BaseAdminService {
|
|
|
41
41
|
* Current implementation is based on req=Request (from Express).
|
|
42
42
|
* Override if needed.
|
|
43
43
|
*/
|
|
44
|
-
getAdminToken(req: BackendRequest):
|
|
44
|
+
getAdminToken(req: BackendRequest): string | undefined;
|
|
45
45
|
isAdmin(req: BackendRequest | undefined): Promise<boolean>;
|
|
46
46
|
getAdminInfo(req: BackendRequest): Promise<AdminInfo | undefined>;
|
|
47
47
|
/**
|
|
@@ -70,7 +70,7 @@ class BaseAdminService {
|
|
|
70
70
|
* Current implementation is based on req=Request (from Express).
|
|
71
71
|
* Override if needed.
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
getAdminToken(req) {
|
|
74
74
|
return (req.cookies?.[this.cfg.adminTokenKey] ||
|
|
75
75
|
req.header(this.cfg.adminTokenKey) ||
|
|
76
76
|
req.header('x-admin-token'));
|
|
@@ -78,7 +78,7 @@ class BaseAdminService {
|
|
|
78
78
|
async isAdmin(req) {
|
|
79
79
|
if (!req)
|
|
80
80
|
return false;
|
|
81
|
-
const adminToken =
|
|
81
|
+
const adminToken = this.getAdminToken(req);
|
|
82
82
|
const email = await this.getEmailByToken(req, adminToken);
|
|
83
83
|
return !!this.getEmailPermissions(email);
|
|
84
84
|
}
|
|
@@ -96,7 +96,7 @@ class BaseAdminService {
|
|
|
96
96
|
async hasPermissions(req, reqPermissions = [], meta = {}) {
|
|
97
97
|
if (!this.cfg.authEnabled)
|
|
98
98
|
return adminInfoDisabled();
|
|
99
|
-
const adminToken =
|
|
99
|
+
const adminToken = this.getAdminToken(req);
|
|
100
100
|
const email = await this.getEmailByToken(req, adminToken);
|
|
101
101
|
const hasPermissions = this.getEmailPermissions(email);
|
|
102
102
|
if (!hasPermissions)
|
|
@@ -113,7 +113,7 @@ class BaseAdminService {
|
|
|
113
113
|
async requirePermissions(req, reqPermissions = [], meta = {}, andComparison = true) {
|
|
114
114
|
if (!this.cfg.authEnabled)
|
|
115
115
|
return adminInfoDisabled();
|
|
116
|
-
const adminToken =
|
|
116
|
+
const adminToken = this.getAdminToken(req);
|
|
117
117
|
const email = await this.getEmailByToken(req, adminToken);
|
|
118
118
|
if (!email) {
|
|
119
119
|
throw new js_lib_1.AppError('adminToken required', {
|
package/package.json
CHANGED
|
@@ -115,7 +115,7 @@ export class BaseAdminService {
|
|
|
115
115
|
* Current implementation is based on req=Request (from Express).
|
|
116
116
|
* Override if needed.
|
|
117
117
|
*/
|
|
118
|
-
|
|
118
|
+
getAdminToken(req: BackendRequest): string | undefined {
|
|
119
119
|
return (
|
|
120
120
|
req.cookies?.[this.cfg.adminTokenKey] ||
|
|
121
121
|
req.header(this.cfg.adminTokenKey) ||
|
|
@@ -125,7 +125,7 @@ export class BaseAdminService {
|
|
|
125
125
|
|
|
126
126
|
async isAdmin(req: BackendRequest | undefined): Promise<boolean> {
|
|
127
127
|
if (!req) return false
|
|
128
|
-
const adminToken =
|
|
128
|
+
const adminToken = this.getAdminToken(req)
|
|
129
129
|
const email = await this.getEmailByToken(req, adminToken)
|
|
130
130
|
return !!this.getEmailPermissions(email)
|
|
131
131
|
}
|
|
@@ -150,7 +150,7 @@ export class BaseAdminService {
|
|
|
150
150
|
): Promise<AdminInfo | undefined> {
|
|
151
151
|
if (!this.cfg.authEnabled) return adminInfoDisabled()
|
|
152
152
|
|
|
153
|
-
const adminToken =
|
|
153
|
+
const adminToken = this.getAdminToken(req)
|
|
154
154
|
const email = await this.getEmailByToken(req, adminToken)
|
|
155
155
|
const hasPermissions = this.getEmailPermissions(email)
|
|
156
156
|
if (!hasPermissions) return
|
|
@@ -175,7 +175,7 @@ export class BaseAdminService {
|
|
|
175
175
|
): Promise<AdminInfo> {
|
|
176
176
|
if (!this.cfg.authEnabled) return adminInfoDisabled()
|
|
177
177
|
|
|
178
|
-
const adminToken =
|
|
178
|
+
const adminToken = this.getAdminToken(req)
|
|
179
179
|
const email = await this.getEmailByToken(req, adminToken)
|
|
180
180
|
|
|
181
181
|
if (!email) {
|