@optimizely-opal/opal-tool-ocp-sdk 0.0.0-OCP-1487.6 → 0.0.0-OCP-1487.8
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/README.md +56 -11
- package/dist/auth/AuthUtils.d.ts +15 -4
- package/dist/auth/AuthUtils.d.ts.map +1 -1
- package/dist/auth/AuthUtils.js +8 -7
- package/dist/auth/AuthUtils.js.map +1 -1
- package/dist/auth/AuthUtils.test.js +39 -39
- package/dist/auth/AuthUtils.test.js.map +1 -1
- package/dist/decorator/Decorator.d.ts +6 -1
- package/dist/decorator/Decorator.d.ts.map +1 -1
- package/dist/decorator/Decorator.js +32 -2
- package/dist/decorator/Decorator.js.map +1 -1
- package/dist/decorator/Decorator.test.js +182 -10
- package/dist/decorator/Decorator.test.js.map +1 -1
- package/dist/function/GlobalToolFunction.d.ts.map +1 -1
- package/dist/function/GlobalToolFunction.js +8 -2
- package/dist/function/GlobalToolFunction.js.map +1 -1
- package/dist/function/ToolFunction.js +1 -1
- package/dist/function/ToolFunction.js.map +1 -1
- package/dist/service/Service.d.ts +11 -1
- package/dist/service/Service.d.ts.map +1 -1
- package/dist/service/Service.js +22 -8
- package/dist/service/Service.js.map +1 -1
- package/dist/utils/ImportUtils.d.ts +15 -0
- package/dist/utils/ImportUtils.d.ts.map +1 -0
- package/dist/utils/ImportUtils.js +77 -0
- package/dist/utils/ImportUtils.js.map +1 -0
- package/package.json +1 -1
- package/src/auth/AuthUtils.test.ts +40 -40
- package/src/auth/AuthUtils.ts +6 -6
- package/src/decorator/Decorator.test.ts +265 -12
- package/src/decorator/Decorator.ts +43 -3
- package/src/function/GlobalToolFunction.ts +10 -3
- package/src/function/ToolFunction.ts +2 -2
- package/src/service/Service.ts +25 -8
- package/src/utils/ImportUtils.ts +45 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.importAsGlobal = importAsGlobal;
|
|
37
|
+
exports.importAsRegular = importAsRegular;
|
|
38
|
+
const Service_1 = require("../service/Service");
|
|
39
|
+
/**
|
|
40
|
+
* Import a module as global tools
|
|
41
|
+
* @param modulePath The path to the module to import
|
|
42
|
+
* @param baseUrl The base URL for resolving relative imports (optional)
|
|
43
|
+
* @returns The imported module
|
|
44
|
+
*/
|
|
45
|
+
async function importAsGlobal(modulePath, baseUrl) {
|
|
46
|
+
try {
|
|
47
|
+
Service_1.toolsService.setImportContext('global');
|
|
48
|
+
// If baseUrl is provided, resolve the module path relative to it
|
|
49
|
+
// Otherwise, use the modulePath as-is
|
|
50
|
+
const resolvedPath = baseUrl ? new URL(modulePath, baseUrl).href : modulePath;
|
|
51
|
+
const module = await Promise.resolve(`${resolvedPath}`).then(s => __importStar(require(s)));
|
|
52
|
+
return module;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
Service_1.toolsService.clearImportContext();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Import a module as regular tools
|
|
60
|
+
* @param modulePath The path to the module to import
|
|
61
|
+
* @param baseUrl The base URL for resolving relative imports (optional)
|
|
62
|
+
* @returns The imported module
|
|
63
|
+
*/
|
|
64
|
+
async function importAsRegular(modulePath, baseUrl) {
|
|
65
|
+
try {
|
|
66
|
+
Service_1.toolsService.setImportContext('regular');
|
|
67
|
+
// If baseUrl is provided, resolve the module path relative to it
|
|
68
|
+
// Otherwise, use the modulePath as-is
|
|
69
|
+
const resolvedPath = baseUrl ? new URL(modulePath, baseUrl).href : modulePath;
|
|
70
|
+
const module = await Promise.resolve(`${resolvedPath}`).then(s => __importStar(require(s)));
|
|
71
|
+
return module;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
Service_1.toolsService.clearImportContext();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=ImportUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportUtils.js","sourceRoot":"","sources":["../../src/utils/ImportUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,wCAcC;AAQD,0CAcC;AA5CD,gDAAkD;AAElD;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,UAAkB,EAClB,OAAgB;IAEhB,IAAI,CAAC;QACH,sBAAY,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACxC,iEAAiE;QACjE,sCAAsC;QACtC,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;QAC9E,MAAM,MAAM,GAAG,yBAAa,YAAY,uCAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,sBAAY,CAAC,kBAAkB,EAAE,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,UAAkB,EAClB,OAAgB;IAEhB,IAAI,CAAC;QACH,sBAAY,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACzC,iEAAiE;QACjE,sCAAsC;QACtC,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;QAC9E,MAAM,MAAM,GAAG,yBAAa,YAAY,uCAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,sBAAY,CAAC,kBAAkB,EAAE,CAAC;IACpC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
2
|
import { getAppContext, logger } from '@zaiusinc/app-sdk';
|
|
3
3
|
import { getTokenVerifier } from './TokenVerifier';
|
|
4
|
-
import {
|
|
4
|
+
import { authenticateRegularRequest, authenticateGlobalRequest } from './AuthUtils';
|
|
5
5
|
|
|
6
6
|
// Mock the dependencies
|
|
7
7
|
jest.mock('./TokenVerifier', () => ({
|
|
@@ -43,7 +43,7 @@ describe('AuthUtils', () => {
|
|
|
43
43
|
} as any);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
describe('
|
|
46
|
+
describe('authenticateRegularRequest', () => {
|
|
47
47
|
beforeEach(() => {
|
|
48
48
|
// Default to successful token verification
|
|
49
49
|
mockTokenVerifier.verify.mockResolvedValue(true);
|
|
@@ -53,7 +53,7 @@ describe('AuthUtils', () => {
|
|
|
53
53
|
it('should return true without authentication', async () => {
|
|
54
54
|
const request = { path: '/discovery' };
|
|
55
55
|
|
|
56
|
-
const result = await
|
|
56
|
+
const result = await authenticateRegularRequest(request);
|
|
57
57
|
|
|
58
58
|
expect(result).toBe(true);
|
|
59
59
|
expect(mockGetTokenVerifier).not.toHaveBeenCalled();
|
|
@@ -65,7 +65,7 @@ describe('AuthUtils', () => {
|
|
|
65
65
|
it('should return true without authentication', async () => {
|
|
66
66
|
const request = { path: '/ready' };
|
|
67
67
|
|
|
68
|
-
const result = await
|
|
68
|
+
const result = await authenticateRegularRequest(request);
|
|
69
69
|
|
|
70
70
|
expect(result).toBe(true);
|
|
71
71
|
expect(mockGetTokenVerifier).not.toHaveBeenCalled();
|
|
@@ -88,7 +88,7 @@ describe('AuthUtils', () => {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const result = await
|
|
91
|
+
const result = await authenticateRegularRequest(request);
|
|
92
92
|
|
|
93
93
|
expect(result).toBe(true);
|
|
94
94
|
expect(mockGetTokenVerifier).toHaveBeenCalled();
|
|
@@ -109,7 +109,7 @@ describe('AuthUtils', () => {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
const result = await
|
|
112
|
+
const result = await authenticateRegularRequest(request);
|
|
113
113
|
|
|
114
114
|
expect(result).toBe(true);
|
|
115
115
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -129,7 +129,7 @@ describe('AuthUtils', () => {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
const result = await
|
|
132
|
+
const result = await authenticateRegularRequest(request);
|
|
133
133
|
|
|
134
134
|
expect(result).toBe(true);
|
|
135
135
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -143,7 +143,7 @@ describe('AuthUtils', () => {
|
|
|
143
143
|
bodyJSON: {}
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
const result = await
|
|
146
|
+
const result = await authenticateRegularRequest(request);
|
|
147
147
|
|
|
148
148
|
expect(result).toBe(false);
|
|
149
149
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -155,7 +155,7 @@ describe('AuthUtils', () => {
|
|
|
155
155
|
path: '/some-tool'
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
const result = await
|
|
158
|
+
const result = await authenticateRegularRequest(request);
|
|
159
159
|
|
|
160
160
|
expect(result).toBe(false);
|
|
161
161
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -175,7 +175,7 @@ describe('AuthUtils', () => {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
const result = await
|
|
178
|
+
const result = await authenticateRegularRequest(request);
|
|
179
179
|
|
|
180
180
|
expect(result).toBe(false);
|
|
181
181
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -195,7 +195,7 @@ describe('AuthUtils', () => {
|
|
|
195
195
|
}
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
-
const result = await
|
|
198
|
+
const result = await authenticateRegularRequest(request);
|
|
199
199
|
|
|
200
200
|
expect(result).toBe(false);
|
|
201
201
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -215,7 +215,7 @@ describe('AuthUtils', () => {
|
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
-
const result = await
|
|
218
|
+
const result = await authenticateRegularRequest(request);
|
|
219
219
|
|
|
220
220
|
expect(result).toBe(false);
|
|
221
221
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -235,7 +235,7 @@ describe('AuthUtils', () => {
|
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
const result = await
|
|
238
|
+
const result = await authenticateRegularRequest(request);
|
|
239
239
|
|
|
240
240
|
expect(result).toBe(false);
|
|
241
241
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -257,7 +257,7 @@ describe('AuthUtils', () => {
|
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
259
|
|
|
260
|
-
const result = await
|
|
260
|
+
const result = await authenticateRegularRequest(request);
|
|
261
261
|
|
|
262
262
|
expect(result).toBe(false);
|
|
263
263
|
expect(logger.error).toHaveBeenCalledWith(
|
|
@@ -280,7 +280,7 @@ describe('AuthUtils', () => {
|
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
|
|
283
|
-
const result = await
|
|
283
|
+
const result = await authenticateRegularRequest(request);
|
|
284
284
|
|
|
285
285
|
expect(result).toBe(false);
|
|
286
286
|
expect(logger.error).toHaveBeenCalledWith('Organisation ID is required but not provided');
|
|
@@ -300,7 +300,7 @@ describe('AuthUtils', () => {
|
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
302
|
|
|
303
|
-
const result = await
|
|
303
|
+
const result = await authenticateRegularRequest(request);
|
|
304
304
|
|
|
305
305
|
expect(result).toBe(false);
|
|
306
306
|
expect(logger.error).toHaveBeenCalledWith('Organisation ID is required but not provided');
|
|
@@ -322,7 +322,7 @@ describe('AuthUtils', () => {
|
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
const result = await
|
|
325
|
+
const result = await authenticateRegularRequest(request);
|
|
326
326
|
|
|
327
327
|
expect(result).toBe(false);
|
|
328
328
|
expect(logger.error).toHaveBeenCalledWith(
|
|
@@ -346,7 +346,7 @@ describe('AuthUtils', () => {
|
|
|
346
346
|
}
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
-
const result = await
|
|
349
|
+
const result = await authenticateRegularRequest(request);
|
|
350
350
|
|
|
351
351
|
expect(result).toBe(false);
|
|
352
352
|
expect(logger.error).toHaveBeenCalledWith(
|
|
@@ -372,7 +372,7 @@ describe('AuthUtils', () => {
|
|
|
372
372
|
}
|
|
373
373
|
};
|
|
374
374
|
|
|
375
|
-
const result = await
|
|
375
|
+
const result = await authenticateRegularRequest(request);
|
|
376
376
|
|
|
377
377
|
expect(result).toBe(false);
|
|
378
378
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('invalid-token');
|
|
@@ -395,7 +395,7 @@ describe('AuthUtils', () => {
|
|
|
395
395
|
}
|
|
396
396
|
};
|
|
397
397
|
|
|
398
|
-
const result = await
|
|
398
|
+
const result = await authenticateRegularRequest(request);
|
|
399
399
|
|
|
400
400
|
expect(result).toBe(false);
|
|
401
401
|
expect(logger.error).toHaveBeenCalledWith('OptiID token validation failed:', verificationError);
|
|
@@ -418,7 +418,7 @@ describe('AuthUtils', () => {
|
|
|
418
418
|
}
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
-
const result = await
|
|
421
|
+
const result = await authenticateRegularRequest(request);
|
|
422
422
|
|
|
423
423
|
expect(result).toBe(false);
|
|
424
424
|
expect(logger.error).toHaveBeenCalledWith('OptiID token validation failed:', verifierError);
|
|
@@ -426,7 +426,7 @@ describe('AuthUtils', () => {
|
|
|
426
426
|
});
|
|
427
427
|
});
|
|
428
428
|
|
|
429
|
-
describe('
|
|
429
|
+
describe('authenticateGlobalRequest', () => {
|
|
430
430
|
beforeEach(() => {
|
|
431
431
|
// Default to successful token verification
|
|
432
432
|
mockTokenVerifier.verify.mockResolvedValue(true);
|
|
@@ -436,7 +436,7 @@ describe('AuthUtils', () => {
|
|
|
436
436
|
it('should return true without authentication', async () => {
|
|
437
437
|
const request = { path: '/discovery' };
|
|
438
438
|
|
|
439
|
-
const result = await
|
|
439
|
+
const result = await authenticateGlobalRequest(request);
|
|
440
440
|
|
|
441
441
|
expect(result).toBe(true);
|
|
442
442
|
expect(mockGetTokenVerifier).not.toHaveBeenCalled();
|
|
@@ -448,7 +448,7 @@ describe('AuthUtils', () => {
|
|
|
448
448
|
it('should return true without authentication', async () => {
|
|
449
449
|
const request = { path: '/ready' };
|
|
450
450
|
|
|
451
|
-
const result = await
|
|
451
|
+
const result = await authenticateGlobalRequest(request);
|
|
452
452
|
|
|
453
453
|
expect(result).toBe(true);
|
|
454
454
|
expect(mockGetTokenVerifier).not.toHaveBeenCalled();
|
|
@@ -471,7 +471,7 @@ describe('AuthUtils', () => {
|
|
|
471
471
|
}
|
|
472
472
|
};
|
|
473
473
|
|
|
474
|
-
const result = await
|
|
474
|
+
const result = await authenticateGlobalRequest(request);
|
|
475
475
|
|
|
476
476
|
expect(result).toBe(true);
|
|
477
477
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -495,7 +495,7 @@ describe('AuthUtils', () => {
|
|
|
495
495
|
}
|
|
496
496
|
};
|
|
497
497
|
|
|
498
|
-
const result = await
|
|
498
|
+
const result = await authenticateGlobalRequest(request);
|
|
499
499
|
|
|
500
500
|
expect(result).toBe(true);
|
|
501
501
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -515,7 +515,7 @@ describe('AuthUtils', () => {
|
|
|
515
515
|
}
|
|
516
516
|
};
|
|
517
517
|
|
|
518
|
-
const result = await
|
|
518
|
+
const result = await authenticateGlobalRequest(request);
|
|
519
519
|
|
|
520
520
|
expect(result).toBe(true);
|
|
521
521
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -529,7 +529,7 @@ describe('AuthUtils', () => {
|
|
|
529
529
|
bodyJSON: {}
|
|
530
530
|
};
|
|
531
531
|
|
|
532
|
-
const result = await
|
|
532
|
+
const result = await authenticateGlobalRequest(request);
|
|
533
533
|
|
|
534
534
|
expect(result).toBe(false);
|
|
535
535
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -549,7 +549,7 @@ describe('AuthUtils', () => {
|
|
|
549
549
|
}
|
|
550
550
|
};
|
|
551
551
|
|
|
552
|
-
const result = await
|
|
552
|
+
const result = await authenticateGlobalRequest(request);
|
|
553
553
|
|
|
554
554
|
expect(result).toBe(false);
|
|
555
555
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -569,7 +569,7 @@ describe('AuthUtils', () => {
|
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
571
|
|
|
572
|
-
const result = await
|
|
572
|
+
const result = await authenticateGlobalRequest(request);
|
|
573
573
|
|
|
574
574
|
expect(result).toBe(false);
|
|
575
575
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -589,7 +589,7 @@ describe('AuthUtils', () => {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
|
|
592
|
-
const result = await
|
|
592
|
+
const result = await authenticateGlobalRequest(request);
|
|
593
593
|
|
|
594
594
|
expect(result).toBe(false);
|
|
595
595
|
expect(logger.error).toHaveBeenCalledWith('OptiID token is required but not provided');
|
|
@@ -613,7 +613,7 @@ describe('AuthUtils', () => {
|
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
615
|
|
|
616
|
-
const result = await
|
|
616
|
+
const result = await authenticateGlobalRequest(request);
|
|
617
617
|
|
|
618
618
|
expect(result).toBe(false);
|
|
619
619
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('invalid-token');
|
|
@@ -636,14 +636,14 @@ describe('AuthUtils', () => {
|
|
|
636
636
|
}
|
|
637
637
|
};
|
|
638
638
|
|
|
639
|
-
const result = await
|
|
639
|
+
const result = await authenticateGlobalRequest(request);
|
|
640
640
|
|
|
641
641
|
expect(result).toBe(false);
|
|
642
642
|
expect(logger.error).toHaveBeenCalledWith('OptiID token validation failed:', verificationError);
|
|
643
643
|
});
|
|
644
644
|
});
|
|
645
645
|
|
|
646
|
-
describe('organization validation differences from
|
|
646
|
+
describe('organization validation differences from authenticateRegularRequest', () => {
|
|
647
647
|
it('should NOT validate organization ID and allow any customer_id', async () => {
|
|
648
648
|
const request = {
|
|
649
649
|
path: '/global-tool',
|
|
@@ -658,7 +658,7 @@ describe('AuthUtils', () => {
|
|
|
658
658
|
}
|
|
659
659
|
};
|
|
660
660
|
|
|
661
|
-
const result = await
|
|
661
|
+
const result = await authenticateGlobalRequest(request);
|
|
662
662
|
|
|
663
663
|
expect(result).toBe(true);
|
|
664
664
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -687,7 +687,7 @@ describe('AuthUtils', () => {
|
|
|
687
687
|
}
|
|
688
688
|
};
|
|
689
689
|
|
|
690
|
-
const result = await
|
|
690
|
+
const result = await authenticateGlobalRequest(request);
|
|
691
691
|
|
|
692
692
|
expect(result).toBe(true);
|
|
693
693
|
expect(mockTokenVerifier.verify).toHaveBeenCalledWith('valid-token-123');
|
|
@@ -702,8 +702,8 @@ describe('AuthUtils', () => {
|
|
|
702
702
|
bodyJSON: null
|
|
703
703
|
};
|
|
704
704
|
|
|
705
|
-
const result1 = await
|
|
706
|
-
const result2 = await
|
|
705
|
+
const result1 = await authenticateRegularRequest(request);
|
|
706
|
+
const result2 = await authenticateGlobalRequest(request);
|
|
707
707
|
|
|
708
708
|
expect(result1).toBe(false);
|
|
709
709
|
expect(result2).toBe(false);
|
|
@@ -718,8 +718,8 @@ describe('AuthUtils', () => {
|
|
|
718
718
|
}
|
|
719
719
|
};
|
|
720
720
|
|
|
721
|
-
const result1 = await
|
|
722
|
-
const result2 = await
|
|
721
|
+
const result1 = await authenticateRegularRequest(request);
|
|
722
|
+
const result2 = await authenticateGlobalRequest(request);
|
|
723
723
|
|
|
724
724
|
expect(result1).toBe(false);
|
|
725
725
|
expect(result2).toBe(false);
|
package/src/auth/AuthUtils.ts
CHANGED
|
@@ -27,7 +27,7 @@ async function validateAccessToken(accessToken: string | undefined): Promise<boo
|
|
|
27
27
|
* @param request - The incoming request
|
|
28
28
|
* @returns object with authData and accessToken, or null if invalid
|
|
29
29
|
*/
|
|
30
|
-
function extractAuthData(request: any): { authData: OptiIdAuthData; accessToken: string } | null {
|
|
30
|
+
export function extractAuthData(request: any): { authData: OptiIdAuthData; accessToken: string } | null {
|
|
31
31
|
const authData = request?.bodyJSON?.auth as OptiIdAuthData;
|
|
32
32
|
const accessToken = authData?.credentials?.access_token;
|
|
33
33
|
if (!accessToken || authData?.provider?.toLowerCase() !== 'optiid') {
|
|
@@ -76,7 +76,7 @@ function shouldSkipAuth(request: any): boolean {
|
|
|
76
76
|
* @param validateOrg - Whether to validate organization ID
|
|
77
77
|
* @returns true if authentication succeeds
|
|
78
78
|
*/
|
|
79
|
-
async function authenticateRequest(request: any, validateOrg: boolean
|
|
79
|
+
async function authenticateRequest(request: any, validateOrg: boolean): Promise<boolean> {
|
|
80
80
|
if (shouldSkipAuth(request)) {
|
|
81
81
|
return true;
|
|
82
82
|
}
|
|
@@ -97,21 +97,21 @@ async function authenticateRequest(request: any, validateOrg: boolean = false):
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* Authenticate a request for regular functions (with organization validation)
|
|
101
101
|
*
|
|
102
102
|
* @param request - The incoming request
|
|
103
103
|
* @returns true if authentication and authorization succeed
|
|
104
104
|
*/
|
|
105
|
-
export async function
|
|
105
|
+
export async function authenticateRegularRequest(request: any): Promise<boolean> {
|
|
106
106
|
return await authenticateRequest(request, true);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Authenticate a request for global functions (without organization validation)
|
|
111
111
|
*
|
|
112
112
|
* @param request - The incoming request
|
|
113
113
|
* @returns true if authentication succeeds
|
|
114
114
|
*/
|
|
115
|
-
export async function
|
|
115
|
+
export async function authenticateGlobalRequest(request: any): Promise<boolean> {
|
|
116
116
|
return await authenticateRequest(request, false);
|
|
117
117
|
}
|