node-server-engine 1.1.5 → 1.1.7
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/.env.example +0 -38
- package/.nycrc +9 -3
- package/README.md +2 -3
- package/dist/const/tokenIssuer.d.ts +2 -4
- package/dist/const/tokenIssuer.js +0 -1
- package/dist/const/tokenIssuer.js.map +1 -1
- package/dist/entities/Endpoint/Endpoint.types.d.ts +2 -19
- package/dist/entities/Endpoint/Endpoint.types.js +1 -8
- package/dist/entities/Endpoint/Endpoint.types.js.map +1 -1
- package/dist/middleware/index.d.ts +0 -1
- package/dist/middleware/index.js +0 -11
- package/dist/middleware/index.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -11
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/jwt/jwt.d.ts +0 -1
- package/dist/utils/jwt/jwt.js +2 -23
- package/dist/utils/jwt/jwt.js.map +1 -1
- package/dist/utils/report/report.js +1 -2
- package/dist/utils/report/report.js.map +1 -1
- package/package.json +8 -7
- package/src/const/tokenIssuer.ts +1 -3
- package/src/entities/Endpoint/Endpoint.test.ts +0 -89
- package/src/entities/Endpoint/Endpoint.types.ts +3 -30
- package/src/entities/KeySet/KeySet.test.ts +1 -1
- package/src/middleware/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/jwt/jwt.test.ts +0 -13
- package/src/utils/jwt/jwt.ts +2 -25
- package/src/utils/report/report.ts +1 -2
- package/test/env.ts +0 -5
- package/test/hooks.ts +0 -2
- package/dist/middleware/authAdmin/authAdmin.d.ts +0 -4
- package/dist/middleware/authAdmin/authAdmin.js +0 -105
- package/dist/middleware/authAdmin/authAdmin.js.map +0 -1
- package/dist/middleware/authAdmin/authAdmin.types.d.ts +0 -16
- package/dist/middleware/authAdmin/authAdmin.types.js +0 -2
- package/dist/middleware/authAdmin/authAdmin.types.js.map +0 -1
- package/dist/middleware/authAdmin/index.d.ts +0 -2
- package/dist/middleware/authAdmin/index.js +0 -28
- package/dist/middleware/authAdmin/index.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.d.ts +0 -3
- package/dist/utils/getDynamicLink/getDynamicLink.js +0 -28
- package/dist/utils/getDynamicLink/getDynamicLink.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.types.d.ts +0 -10
- package/dist/utils/getDynamicLink/getDynamicLink.types.js +0 -2
- package/dist/utils/getDynamicLink/getDynamicLink.types.js.map +0 -1
- package/dist/utils/getDynamicLink/getDynamicLink.validate.d.ts +0 -2
- package/dist/utils/getDynamicLink/getDynamicLink.validate.js +0 -14
- package/dist/utils/getDynamicLink/getDynamicLink.validate.js.map +0 -1
- package/dist/utils/getDynamicLink/index.d.ts +0 -2
- package/dist/utils/getDynamicLink/index.js +0 -28
- package/dist/utils/getDynamicLink/index.js.map +0 -1
- package/src/middleware/authAdmin/authAdmin.test.ts +0 -199
- package/src/middleware/authAdmin/authAdmin.ts +0 -114
- package/src/middleware/authAdmin/authAdmin.types.ts +0 -19
- package/src/middleware/authAdmin/index.ts +0 -2
- package/src/utils/getDynamicLink/getDynamicLink.test.ts +0 -51
- package/src/utils/getDynamicLink/getDynamicLink.ts +0 -28
- package/src/utils/getDynamicLink/getDynamicLink.types.ts +0 -11
- package/src/utils/getDynamicLink/getDynamicLink.validate.ts +0 -6
- package/src/utils/getDynamicLink/index.ts +0 -2
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validateDynamicLinkEnvironment = validateDynamicLinkEnvironment;
|
|
7
|
-
var _ = require("./..");
|
|
8
|
-
/** Environment variable validator for get dynamic link from LinkService */
|
|
9
|
-
function validateDynamicLinkEnvironment() {
|
|
10
|
-
(0, _.assertEnvironment)({
|
|
11
|
-
LINKS_SERVICE_URL: _.envAssert.isURL()
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=getDynamicLink.validate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDynamicLink.validate.js","names":["_","require","validateDynamicLinkEnvironment","assertEnvironment","LINKS_SERVICE_URL","envAssert","isURL"],"sources":["../../../src/utils/getDynamicLink/getDynamicLink.validate.ts"],"sourcesContent":["import { assertEnvironment, envAssert } from 'utils';\n\n/** Environment variable validator for get dynamic link from LinkService */\nexport function validateDynamicLinkEnvironment(): void {\n assertEnvironment({ LINKS_SERVICE_URL: envAssert.isURL() });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,OAAA;AAEA;AACO,SAASC,8BAA8BA,CAAA,EAAS;EACrD,IAAAC,mBAAiB,EAAC;IAAEC,iBAAiB,EAAEC,WAAS,CAACC,KAAK,CAAC;EAAE,CAAC,CAAC;AAC7D","ignoreList":[]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _getDynamicLink = require("./getDynamicLink");
|
|
7
|
-
Object.keys(_getDynamicLink).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _getDynamicLink[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _getDynamicLink[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _getDynamicLink2 = require("./getDynamicLink.types");
|
|
18
|
-
Object.keys(_getDynamicLink2).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _getDynamicLink2[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _getDynamicLink2[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_getDynamicLink","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_getDynamicLink2"],"sources":["../../../src/utils/getDynamicLink/index.ts"],"sourcesContent":["export * from './getDynamicLink';\nexport * from './getDynamicLink.types';\n"],"mappings":";;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,eAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,eAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,eAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,gBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,gBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,gBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,gBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { factory, generateAccessToken, getBearer } from 'backend-test-tools';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
import { faker } from '@faker-js/faker';
|
|
5
|
-
import { fake } from 'sinon';
|
|
6
|
-
import { authAdmin } from './authAdmin';
|
|
7
|
-
import {} from './authAdmin.types';
|
|
8
|
-
|
|
9
|
-
describe('Middleware - Auth Admin', () => {
|
|
10
|
-
it('should authenticate with a JWT (auth-service)', async () => {
|
|
11
|
-
const email = faker.internet.email();
|
|
12
|
-
const permission = faker.lorem.word();
|
|
13
|
-
const request = {
|
|
14
|
-
headers: {
|
|
15
|
-
authorization: `Bearer ${generateAccessToken(
|
|
16
|
-
email,
|
|
17
|
-
{
|
|
18
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
19
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
20
|
-
},
|
|
21
|
-
{ per: permission }
|
|
22
|
-
)}`
|
|
23
|
-
}
|
|
24
|
-
} as unknown as Request;
|
|
25
|
-
const next = fake();
|
|
26
|
-
|
|
27
|
-
await authAdmin({ permission })(
|
|
28
|
-
request,
|
|
29
|
-
undefined as unknown as Response,
|
|
30
|
-
next
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(next).to.have.been.calledOnceWithExactly();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should populate the admin object in the request (auth-service)', async () => {
|
|
37
|
-
const email = faker.internet.email();
|
|
38
|
-
const permission = faker.lorem.word();
|
|
39
|
-
const permissions = [permission, faker.lorem.word(), faker.lorem.word()];
|
|
40
|
-
const request = {
|
|
41
|
-
headers: {
|
|
42
|
-
authorization: `Bearer ${generateAccessToken(
|
|
43
|
-
email,
|
|
44
|
-
{
|
|
45
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
46
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
47
|
-
},
|
|
48
|
-
{ per: permissions }
|
|
49
|
-
)}`
|
|
50
|
-
}
|
|
51
|
-
} as unknown as Request;
|
|
52
|
-
const next = fake();
|
|
53
|
-
|
|
54
|
-
await authAdmin({ permission })(
|
|
55
|
-
request,
|
|
56
|
-
undefined as unknown as Response,
|
|
57
|
-
next
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
expect(request.admin?.email).to.equal(email);
|
|
61
|
-
expect(request.admin?.permissions).to.deep.members(permissions);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should throw an error if there is no token', async () => {
|
|
65
|
-
const request = { headers: {} } as unknown as Request;
|
|
66
|
-
const next = fake();
|
|
67
|
-
|
|
68
|
-
await expect(
|
|
69
|
-
authAdmin({ permission: faker.lorem.word() })(
|
|
70
|
-
request,
|
|
71
|
-
undefined as unknown as Response,
|
|
72
|
-
next
|
|
73
|
-
)
|
|
74
|
-
).to.eventually.be.rejected;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should throw an error if the audience is not valid', async () => {
|
|
78
|
-
const user = factory.build('user');
|
|
79
|
-
const permission = faker.lorem.word();
|
|
80
|
-
const request = {
|
|
81
|
-
headers: {
|
|
82
|
-
authorization: getBearer(
|
|
83
|
-
user.id,
|
|
84
|
-
{ audience: faker.internet.url() },
|
|
85
|
-
{ per: permission }
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
} as unknown as Request;
|
|
89
|
-
const next = fake();
|
|
90
|
-
|
|
91
|
-
await expect(
|
|
92
|
-
authAdmin({ permission })(request, undefined as unknown as Response, next)
|
|
93
|
-
).to.eventually.be.rejected;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should check user has permission', async () => {
|
|
97
|
-
const email = faker.internet.email();
|
|
98
|
-
const permissions = [faker.lorem.word(), faker.lorem.word()];
|
|
99
|
-
const request = {
|
|
100
|
-
headers: {
|
|
101
|
-
authorization: `Bearer ${generateAccessToken(
|
|
102
|
-
email,
|
|
103
|
-
{
|
|
104
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
105
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
106
|
-
},
|
|
107
|
-
{ per: permissions }
|
|
108
|
-
)}`
|
|
109
|
-
}
|
|
110
|
-
} as unknown as Request;
|
|
111
|
-
const next = fake();
|
|
112
|
-
|
|
113
|
-
await authAdmin({ permission: permissions[0] })(
|
|
114
|
-
request,
|
|
115
|
-
undefined as unknown as Response,
|
|
116
|
-
next
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
expect(request.admin?.email).to.equal(email);
|
|
120
|
-
expect(request.admin?.permissions).to.deep.members(permissions);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should all user has endpoint permission', async () => {
|
|
124
|
-
const email = faker.internet.email();
|
|
125
|
-
const permission = faker.lorem.word();
|
|
126
|
-
const request = {
|
|
127
|
-
headers: {
|
|
128
|
-
authorization: `Bearer ${generateAccessToken(
|
|
129
|
-
email,
|
|
130
|
-
{
|
|
131
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
132
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
133
|
-
},
|
|
134
|
-
{ per: permission }
|
|
135
|
-
)}`
|
|
136
|
-
}
|
|
137
|
-
} as unknown as Request;
|
|
138
|
-
const next = fake();
|
|
139
|
-
|
|
140
|
-
await authAdmin({ permission })(
|
|
141
|
-
request,
|
|
142
|
-
undefined as unknown as Response,
|
|
143
|
-
next
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expect(request.admin?.email).to.equal(email);
|
|
147
|
-
expect(request.admin?.permissions).to.includes(permission);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('should throw error if user does not have permission', async () => {
|
|
151
|
-
const email = faker.internet.email();
|
|
152
|
-
const permissions = [faker.lorem.word(), faker.lorem.word()];
|
|
153
|
-
const request = {
|
|
154
|
-
headers: {
|
|
155
|
-
authorization: `Bearer ${generateAccessToken(
|
|
156
|
-
email,
|
|
157
|
-
{
|
|
158
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
159
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
160
|
-
},
|
|
161
|
-
{ per: permissions }
|
|
162
|
-
)}`
|
|
163
|
-
}
|
|
164
|
-
} as unknown as Request;
|
|
165
|
-
const next = fake();
|
|
166
|
-
|
|
167
|
-
await expect(
|
|
168
|
-
authAdmin({ permission: faker.lorem.word() })(
|
|
169
|
-
request,
|
|
170
|
-
undefined as unknown as Response,
|
|
171
|
-
next
|
|
172
|
-
)
|
|
173
|
-
).to.eventually.rejected;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('should allow wildcard permissions', async () => {
|
|
177
|
-
const email = faker.internet.email();
|
|
178
|
-
const permission = faker.lorem.word();
|
|
179
|
-
const request = {
|
|
180
|
-
headers: {
|
|
181
|
-
authorization: `Bearer ${generateAccessToken(
|
|
182
|
-
email,
|
|
183
|
-
{
|
|
184
|
-
audience: [process.env.ADMIN_API_ACCESS_TOKEN_AUDIENCE as string],
|
|
185
|
-
issuer: process.env.ADMIN_ACCESS_TOKEN_ISSUER
|
|
186
|
-
},
|
|
187
|
-
{ per: `${permission}:*` }
|
|
188
|
-
)}`
|
|
189
|
-
}
|
|
190
|
-
} as unknown as Request;
|
|
191
|
-
const next = fake();
|
|
192
|
-
|
|
193
|
-
await authAdmin({ permission: `${permission}:${faker.lorem.word()}` })(
|
|
194
|
-
request,
|
|
195
|
-
undefined as unknown as Response,
|
|
196
|
-
next
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import { TokenIssuer } from 'const';
|
|
3
|
-
import { EndpointAuthParams, EndpointAuthType } from 'entities/Endpoint';
|
|
4
|
-
import { EngineError } from 'entities/EngineError';
|
|
5
|
-
import { WebError } from 'entities/WebError';
|
|
6
|
-
import { reportDebug, jwtVerify } from 'utils';
|
|
7
|
-
import {} from './authAdmin.types';
|
|
8
|
-
|
|
9
|
-
const namespace = 'engine:middleware:authAdmin';
|
|
10
|
-
|
|
11
|
-
/** Generate a middleware to authenticate the client connection with a Admin api */
|
|
12
|
-
export function authAdmin(
|
|
13
|
-
options: EndpointAuthParams<EndpointAuthType.ADMIN>
|
|
14
|
-
): (request: Request, response: Response, next: NextFunction) => Promise<void> {
|
|
15
|
-
if (!options.permission)
|
|
16
|
-
throw new EngineError({
|
|
17
|
-
message: 'Endpoint using admin auth type must specify permission'
|
|
18
|
-
});
|
|
19
|
-
return async (
|
|
20
|
-
request: Request,
|
|
21
|
-
response: Response,
|
|
22
|
-
next: NextFunction
|
|
23
|
-
): Promise<void> => {
|
|
24
|
-
const [scheme, credentials] =
|
|
25
|
-
request.headers?.authorization?.split(' ') ?? [];
|
|
26
|
-
// No bearer token has been sent
|
|
27
|
-
if (!credentials || scheme.toLowerCase() !== 'bearer') {
|
|
28
|
-
throw new WebError({
|
|
29
|
-
errorCode: 'unauthorized',
|
|
30
|
-
statusCode: 401,
|
|
31
|
-
message: 'No bearer token found',
|
|
32
|
-
data: { authorization: request.headers?.authorization }
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
reportDebug({
|
|
36
|
-
namespace,
|
|
37
|
-
message: 'Performing JWT authentication',
|
|
38
|
-
data: { scheme, credentials }
|
|
39
|
-
});
|
|
40
|
-
// Verify token and extract its payload
|
|
41
|
-
const payload = await jwtVerify(credentials, TokenIssuer.ADMIN_API);
|
|
42
|
-
reportDebug({
|
|
43
|
-
namespace,
|
|
44
|
-
message: 'Extracted user data from JWT',
|
|
45
|
-
data: { payload, credentials }
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (!payload.per)
|
|
49
|
-
throw new WebError({
|
|
50
|
-
errorCode: 'unauthorized',
|
|
51
|
-
statusCode: 401,
|
|
52
|
-
message: `User token does not contain any permission claim`
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// User Permission
|
|
56
|
-
const permissions = payload.per;
|
|
57
|
-
const userPermissions =
|
|
58
|
-
permissions instanceof Array ? permissions : [permissions];
|
|
59
|
-
|
|
60
|
-
reportDebug({
|
|
61
|
-
namespace,
|
|
62
|
-
message: 'Performing Admin Permission check',
|
|
63
|
-
data: {
|
|
64
|
-
permissions,
|
|
65
|
-
endpointPermission: options.permission,
|
|
66
|
-
adminPermissions: userPermissions
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (!checkUserPermissions(userPermissions, options.permission)) {
|
|
71
|
-
throw new WebError({
|
|
72
|
-
errorCode: 'unauthorized',
|
|
73
|
-
statusCode: 401,
|
|
74
|
-
message: `User does not have required permission "${options.permission}"`,
|
|
75
|
-
data: { userPermissions }
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// The user object on the request is hydrated with data from the token
|
|
80
|
-
request.admin = {
|
|
81
|
-
...request.admin,
|
|
82
|
-
email: payload.sub,
|
|
83
|
-
permissions: userPermissions
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
next();
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** */
|
|
91
|
-
function checkUserPermissions(
|
|
92
|
-
userPermissions: Array<string>,
|
|
93
|
-
endpointPermission: string
|
|
94
|
-
): boolean {
|
|
95
|
-
const endpointPermissionParts = endpointPermission.split(':');
|
|
96
|
-
userPermissionLoop: for (const permission of userPermissions) {
|
|
97
|
-
const permissionParts = permission.split(':');
|
|
98
|
-
|
|
99
|
-
// Ignore if both are not same length
|
|
100
|
-
if (permissionParts.length !== endpointPermissionParts.length)
|
|
101
|
-
continue userPermissionLoop;
|
|
102
|
-
|
|
103
|
-
for (let i = 0; i < permissionParts.length; i++) {
|
|
104
|
-
// Wildcards get automatic validation, otherwise it must match with the same part of the endpoint permission
|
|
105
|
-
if (
|
|
106
|
-
permissionParts[i] !== '*' &&
|
|
107
|
-
permissionParts[i] !== endpointPermissionParts[i]
|
|
108
|
-
)
|
|
109
|
-
continue userPermissionLoop;
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Override the Express request object to add the files
|
|
2
|
-
declare global {
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
4
|
-
namespace Express {
|
|
5
|
-
/** Express request object */
|
|
6
|
-
interface Request {
|
|
7
|
-
/** User that identified using a JWT */
|
|
8
|
-
admin?: RequestAdminProps;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Admin auth properties of the request */
|
|
14
|
-
export interface RequestAdminProps {
|
|
15
|
-
/** Email address of the user */
|
|
16
|
-
email: string;
|
|
17
|
-
/** List of permissions that the user has */
|
|
18
|
-
permissions: Array<string>;
|
|
19
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import chai, { expect } from 'chai';
|
|
3
|
-
import { faker } from '@faker-js/faker';
|
|
4
|
-
import { stub, SinonStub, match } from 'sinon';
|
|
5
|
-
import sinonChai from 'sinon-chai';
|
|
6
|
-
import { getDynamicLink } from './getDynamicLink';
|
|
7
|
-
import { DynamicLinkResponseBody } from './getDynamicLink.types';
|
|
8
|
-
import * as tlsRequest from 'utils/tlsRequest/tlsRequest';
|
|
9
|
-
|
|
10
|
-
chai.use(sinonChai);
|
|
11
|
-
|
|
12
|
-
describe('Utils - Get Dynamic Link', () => {
|
|
13
|
-
let expectedPayload: AxiosRequestConfig;
|
|
14
|
-
let path: string;
|
|
15
|
-
let requestStub: SinonStub;
|
|
16
|
-
let link: string;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
link = faker.internet.url();
|
|
20
|
-
requestStub = stub(tlsRequest, 'tlsRequest').resolves({
|
|
21
|
-
data: { link }
|
|
22
|
-
} as AxiosResponse<DynamicLinkResponseBody>);
|
|
23
|
-
path = faker.system.directoryPath();
|
|
24
|
-
expectedPayload = {
|
|
25
|
-
method: 'get',
|
|
26
|
-
url: '/link',
|
|
27
|
-
baseURL: process.env.LINKS_SERVICE_URL,
|
|
28
|
-
params: {
|
|
29
|
-
path
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should get a dynamic link', async () => {
|
|
35
|
-
// should return a link from the res
|
|
36
|
-
const dynamicLink = await getDynamicLink(path);
|
|
37
|
-
expect(dynamicLink).to.equal(link);
|
|
38
|
-
expect(requestStub).to.have.been.calledOnceWithExactly(
|
|
39
|
-
match(expectedPayload)
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should get a dynamic link with custom settings', async () => {
|
|
44
|
-
// should return a link from the res
|
|
45
|
-
const dynamicLink = await getDynamicLink(path, { short: false });
|
|
46
|
-
expect(dynamicLink).to.equal(link);
|
|
47
|
-
expect(requestStub).to.have.been.calledOnceWithExactly(
|
|
48
|
-
match({ ...expectedPayload, params: { path, short: false } })
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
getDynamicLinksOptions,
|
|
4
|
-
DynamicLinkResponseBody
|
|
5
|
-
} from './getDynamicLink.types';
|
|
6
|
-
import { validateDynamicLinkEnvironment } from './getDynamicLink.validate';
|
|
7
|
-
import { tlsRequest } from 'utils/tlsRequest';
|
|
8
|
-
|
|
9
|
-
/** Fetch a dynamic link from the links service */
|
|
10
|
-
export async function getDynamicLink(
|
|
11
|
-
path: string,
|
|
12
|
-
options: getDynamicLinksOptions = {}
|
|
13
|
-
): Promise<string> {
|
|
14
|
-
validateDynamicLinkEnvironment();
|
|
15
|
-
const option: AxiosRequestConfig = {
|
|
16
|
-
method: 'get',
|
|
17
|
-
url: '/link',
|
|
18
|
-
baseURL: process.env.LINKS_SERVICE_URL,
|
|
19
|
-
params: {
|
|
20
|
-
path,
|
|
21
|
-
short: options.short ?? true
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const {
|
|
25
|
-
data: { link }
|
|
26
|
-
} = await tlsRequest<DynamicLinkResponseBody>(option);
|
|
27
|
-
return link;
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Options to fetch dynamic links */
|
|
2
|
-
export interface getDynamicLinksOptions {
|
|
3
|
-
/** Make a shortened link */
|
|
4
|
-
short?: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/** Dynamic link query server response */
|
|
8
|
-
export interface DynamicLinkResponseBody {
|
|
9
|
-
/** The generated dynamic link */
|
|
10
|
-
link: string;
|
|
11
|
-
}
|