@friggframework/admin-scripts 2.0.0--canary.517.971202e.0 → 2.0.0--canary.517.7d448e0.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.
package/index.js
CHANGED
|
@@ -15,9 +15,6 @@ const { AdminScriptBase } = require('./src/application/admin-script-base');
|
|
|
15
15
|
const {
|
|
16
16
|
AdminScriptContext,
|
|
17
17
|
createAdminScriptContext,
|
|
18
|
-
// Legacy aliases (deprecated)
|
|
19
|
-
AdminFriggCommands,
|
|
20
|
-
createAdminFriggCommands,
|
|
21
18
|
} = require('./src/application/admin-frigg-commands');
|
|
22
19
|
const {
|
|
23
20
|
ScriptRunner,
|
|
@@ -55,9 +52,6 @@ module.exports = {
|
|
|
55
52
|
createScriptFactory,
|
|
56
53
|
AdminScriptContext,
|
|
57
54
|
createAdminScriptContext,
|
|
58
|
-
// Legacy aliases (deprecated)
|
|
59
|
-
AdminFriggCommands,
|
|
60
|
-
createAdminFriggCommands,
|
|
61
55
|
ScriptRunner,
|
|
62
56
|
createScriptRunner,
|
|
63
57
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/admin-scripts",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.517.
|
|
4
|
+
"version": "2.0.0--canary.517.7d448e0.0",
|
|
5
5
|
"description": "Admin Script Runner for Frigg - Execute maintenance and operational scripts in hosted environments",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@aws-sdk/client-scheduler": "^3.588.0",
|
|
8
|
-
"@friggframework/core": "2.0.0--canary.517.
|
|
8
|
+
"@friggframework/core": "2.0.0--canary.517.7d448e0.0",
|
|
9
9
|
"@hapi/boom": "^10.0.1",
|
|
10
10
|
"express": "^4.18.2",
|
|
11
11
|
"serverless-http": "^3.2.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@friggframework/eslint-config": "2.0.0--canary.517.
|
|
15
|
-
"@friggframework/prettier-config": "2.0.0--canary.517.
|
|
16
|
-
"@friggframework/test": "2.0.0--canary.517.
|
|
14
|
+
"@friggframework/eslint-config": "2.0.0--canary.517.7d448e0.0",
|
|
15
|
+
"@friggframework/prettier-config": "2.0.0--canary.517.7d448e0.0",
|
|
16
|
+
"@friggframework/test": "2.0.0--canary.517.7d448e0.0",
|
|
17
17
|
"eslint": "^8.22.0",
|
|
18
18
|
"jest": "^29.7.0",
|
|
19
19
|
"prettier": "^2.7.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"maintenance",
|
|
45
45
|
"operations"
|
|
46
46
|
],
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7d448e09858f5a215e43b3a210fe15efe4d76732"
|
|
48
48
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AdminScriptContext,
|
|
3
|
+
createAdminScriptContext,
|
|
4
4
|
} = require('../admin-frigg-commands');
|
|
5
5
|
|
|
6
6
|
// Mock all repository factories
|
|
@@ -81,7 +81,7 @@ describe('AdminScriptContext', () => {
|
|
|
81
81
|
|
|
82
82
|
describe('Constructor', () => {
|
|
83
83
|
it('creates with executionId', () => {
|
|
84
|
-
const ctx = new
|
|
84
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_123' });
|
|
85
85
|
|
|
86
86
|
expect(ctx.executionId).toBe('exec_123');
|
|
87
87
|
expect(ctx.logs).toEqual([]);
|
|
@@ -90,7 +90,7 @@ describe('AdminScriptContext', () => {
|
|
|
90
90
|
|
|
91
91
|
it('creates with integrationFactory', () => {
|
|
92
92
|
const mockFactory = { getInstanceFromIntegrationId: jest.fn() };
|
|
93
|
-
const ctx = new
|
|
93
|
+
const ctx = new AdminScriptContext({
|
|
94
94
|
integrationFactory: mockFactory,
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -98,7 +98,7 @@ describe('AdminScriptContext', () => {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it('creates without params (defaults)', () => {
|
|
101
|
-
const ctx = new
|
|
101
|
+
const ctx = new AdminScriptContext();
|
|
102
102
|
|
|
103
103
|
expect(ctx.executionId).toBeNull();
|
|
104
104
|
expect(ctx.logs).toEqual([]);
|
|
@@ -108,7 +108,7 @@ describe('AdminScriptContext', () => {
|
|
|
108
108
|
|
|
109
109
|
describe('Lazy Repository Loading', () => {
|
|
110
110
|
it('creates integrationRepository on first access', () => {
|
|
111
|
-
const ctx = new
|
|
111
|
+
const ctx = new AdminScriptContext();
|
|
112
112
|
const {
|
|
113
113
|
createIntegrationRepository,
|
|
114
114
|
} = require('@friggframework/core/integrations/repositories/integration-repository-factory');
|
|
@@ -122,7 +122,7 @@ describe('AdminScriptContext', () => {
|
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
it('returns same instance on subsequent access', () => {
|
|
125
|
-
const ctx = new
|
|
125
|
+
const ctx = new AdminScriptContext();
|
|
126
126
|
|
|
127
127
|
const repo1 = ctx.integrationRepository;
|
|
128
128
|
const repo2 = ctx.integrationRepository;
|
|
@@ -132,7 +132,7 @@ describe('AdminScriptContext', () => {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it('creates userRepository on first access', () => {
|
|
135
|
-
const ctx = new
|
|
135
|
+
const ctx = new AdminScriptContext();
|
|
136
136
|
const {
|
|
137
137
|
createUserRepository,
|
|
138
138
|
} = require('@friggframework/core/user/repositories/user-repository-factory');
|
|
@@ -146,7 +146,7 @@ describe('AdminScriptContext', () => {
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
it('creates moduleRepository on first access', () => {
|
|
149
|
-
const ctx = new
|
|
149
|
+
const ctx = new AdminScriptContext();
|
|
150
150
|
const {
|
|
151
151
|
createModuleRepository,
|
|
152
152
|
} = require('@friggframework/core/modules/repositories/module-repository-factory');
|
|
@@ -160,7 +160,7 @@ describe('AdminScriptContext', () => {
|
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
it('creates credentialRepository on first access', () => {
|
|
163
|
-
const ctx = new
|
|
163
|
+
const ctx = new AdminScriptContext();
|
|
164
164
|
const {
|
|
165
165
|
createCredentialRepository,
|
|
166
166
|
} = require('@friggframework/core/credential/repositories/credential-repository-factory');
|
|
@@ -176,7 +176,7 @@ describe('AdminScriptContext', () => {
|
|
|
176
176
|
|
|
177
177
|
describe('instantiate()', () => {
|
|
178
178
|
it('throws if no integrationFactory', async () => {
|
|
179
|
-
const ctx = new
|
|
179
|
+
const ctx = new AdminScriptContext();
|
|
180
180
|
|
|
181
181
|
await expect(ctx.instantiate('int_123')).rejects.toThrow(
|
|
182
182
|
'instantiate() requires integrationFactory. ' +
|
|
@@ -191,7 +191,7 @@ describe('AdminScriptContext', () => {
|
|
|
191
191
|
.fn()
|
|
192
192
|
.mockResolvedValue(mockInstance),
|
|
193
193
|
};
|
|
194
|
-
const ctx = new
|
|
194
|
+
const ctx = new AdminScriptContext({
|
|
195
195
|
integrationFactory: mockFactory,
|
|
196
196
|
});
|
|
197
197
|
|
|
@@ -213,7 +213,7 @@ describe('AdminScriptContext', () => {
|
|
|
213
213
|
.fn()
|
|
214
214
|
.mockResolvedValue(mockInstance),
|
|
215
215
|
};
|
|
216
|
-
const ctx = new
|
|
216
|
+
const ctx = new AdminScriptContext({
|
|
217
217
|
integrationFactory: mockFactory,
|
|
218
218
|
});
|
|
219
219
|
|
|
@@ -238,7 +238,7 @@ describe('AdminScriptContext', () => {
|
|
|
238
238
|
|
|
239
239
|
it('throws if ADMIN_SCRIPT_QUEUE_URL not set', async () => {
|
|
240
240
|
delete process.env.ADMIN_SCRIPT_QUEUE_URL;
|
|
241
|
-
const ctx = new
|
|
241
|
+
const ctx = new AdminScriptContext();
|
|
242
242
|
|
|
243
243
|
await expect(ctx.queueScript('test-script', {})).rejects.toThrow(
|
|
244
244
|
'ADMIN_SCRIPT_QUEUE_URL environment variable not set'
|
|
@@ -248,7 +248,7 @@ describe('AdminScriptContext', () => {
|
|
|
248
248
|
it('calls QueuerUtil.send with correct params', async () => {
|
|
249
249
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
250
250
|
'https://sqs.us-east-1.amazonaws.com/123456789012/admin-scripts';
|
|
251
|
-
const ctx = new
|
|
251
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_123' });
|
|
252
252
|
const params = { integrationId: 'int_456' };
|
|
253
253
|
|
|
254
254
|
await ctx.queueScript('test-script', params);
|
|
@@ -267,7 +267,7 @@ describe('AdminScriptContext', () => {
|
|
|
267
267
|
it('includes parentExecutionId from constructor', async () => {
|
|
268
268
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
269
269
|
'https://sqs.example.com/queue';
|
|
270
|
-
const ctx = new
|
|
270
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_parent' });
|
|
271
271
|
|
|
272
272
|
await ctx.queueScript('my-script', {});
|
|
273
273
|
|
|
@@ -278,7 +278,7 @@ describe('AdminScriptContext', () => {
|
|
|
278
278
|
it('logs queuing operation', async () => {
|
|
279
279
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
280
280
|
'https://sqs.example.com/queue';
|
|
281
|
-
const ctx = new
|
|
281
|
+
const ctx = new AdminScriptContext();
|
|
282
282
|
const params = { batchId: 'batch_1' };
|
|
283
283
|
|
|
284
284
|
await ctx.queueScript('test-script', params);
|
|
@@ -304,7 +304,7 @@ describe('AdminScriptContext', () => {
|
|
|
304
304
|
|
|
305
305
|
it('throws if ADMIN_SCRIPT_QUEUE_URL not set', async () => {
|
|
306
306
|
delete process.env.ADMIN_SCRIPT_QUEUE_URL;
|
|
307
|
-
const ctx = new
|
|
307
|
+
const ctx = new AdminScriptContext();
|
|
308
308
|
|
|
309
309
|
await expect(ctx.queueScriptBatch([])).rejects.toThrow(
|
|
310
310
|
'ADMIN_SCRIPT_QUEUE_URL environment variable not set'
|
|
@@ -314,7 +314,7 @@ describe('AdminScriptContext', () => {
|
|
|
314
314
|
it('calls QueuerUtil.batchSend', async () => {
|
|
315
315
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
316
316
|
'https://sqs.example.com/queue';
|
|
317
|
-
const ctx = new
|
|
317
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_123' });
|
|
318
318
|
const entries = [
|
|
319
319
|
{ scriptName: 'script-1', params: { id: '1' } },
|
|
320
320
|
{ scriptName: 'script-2', params: { id: '2' } },
|
|
@@ -344,7 +344,7 @@ describe('AdminScriptContext', () => {
|
|
|
344
344
|
it('maps entries correctly', async () => {
|
|
345
345
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
346
346
|
'https://sqs.example.com/queue';
|
|
347
|
-
const ctx = new
|
|
347
|
+
const ctx = new AdminScriptContext();
|
|
348
348
|
const entries = [
|
|
349
349
|
{ scriptName: 'test-script', params: { value: 'abc' } },
|
|
350
350
|
];
|
|
@@ -361,7 +361,7 @@ describe('AdminScriptContext', () => {
|
|
|
361
361
|
it('handles entries without params', async () => {
|
|
362
362
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
363
363
|
'https://sqs.example.com/queue';
|
|
364
|
-
const ctx = new
|
|
364
|
+
const ctx = new AdminScriptContext();
|
|
365
365
|
const entries = [{ scriptName: 'no-params-script' }];
|
|
366
366
|
|
|
367
367
|
await ctx.queueScriptBatch(entries);
|
|
@@ -373,7 +373,7 @@ describe('AdminScriptContext', () => {
|
|
|
373
373
|
it('logs batch queuing operation', async () => {
|
|
374
374
|
process.env.ADMIN_SCRIPT_QUEUE_URL =
|
|
375
375
|
'https://sqs.example.com/queue';
|
|
376
|
-
const ctx = new
|
|
376
|
+
const ctx = new AdminScriptContext();
|
|
377
377
|
const entries = [
|
|
378
378
|
{ scriptName: 'script-1', params: {} },
|
|
379
379
|
{ scriptName: 'script-2', params: {} },
|
|
@@ -391,7 +391,7 @@ describe('AdminScriptContext', () => {
|
|
|
391
391
|
|
|
392
392
|
describe('Logging', () => {
|
|
393
393
|
it('log() adds entry to logs array', () => {
|
|
394
|
-
const ctx = new
|
|
394
|
+
const ctx = new AdminScriptContext();
|
|
395
395
|
|
|
396
396
|
const entry = ctx.log('info', 'Test message', { key: 'value' });
|
|
397
397
|
|
|
@@ -404,7 +404,7 @@ describe('AdminScriptContext', () => {
|
|
|
404
404
|
});
|
|
405
405
|
|
|
406
406
|
it('log() is in-memory only (no DB persistence)', () => {
|
|
407
|
-
const ctx = new
|
|
407
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_123' });
|
|
408
408
|
|
|
409
409
|
ctx.log('warn', 'Warning message', { detail: 'xyz' });
|
|
410
410
|
|
|
@@ -415,7 +415,7 @@ describe('AdminScriptContext', () => {
|
|
|
415
415
|
});
|
|
416
416
|
|
|
417
417
|
it('getLogs() returns all logs', () => {
|
|
418
|
-
const ctx = new
|
|
418
|
+
const ctx = new AdminScriptContext();
|
|
419
419
|
|
|
420
420
|
ctx.log('info', 'First');
|
|
421
421
|
ctx.log('warn', 'Second');
|
|
@@ -430,7 +430,7 @@ describe('AdminScriptContext', () => {
|
|
|
430
430
|
});
|
|
431
431
|
|
|
432
432
|
it('clearLogs() clears logs array', () => {
|
|
433
|
-
const ctx = new
|
|
433
|
+
const ctx = new AdminScriptContext();
|
|
434
434
|
|
|
435
435
|
ctx.log('info', 'First');
|
|
436
436
|
ctx.log('info', 'Second');
|
|
@@ -442,30 +442,30 @@ describe('AdminScriptContext', () => {
|
|
|
442
442
|
});
|
|
443
443
|
|
|
444
444
|
it('getExecutionId() returns executionId', () => {
|
|
445
|
-
const ctx = new
|
|
445
|
+
const ctx = new AdminScriptContext({ executionId: 'exec_789' });
|
|
446
446
|
|
|
447
447
|
expect(ctx.getExecutionId()).toBe('exec_789');
|
|
448
448
|
});
|
|
449
449
|
|
|
450
450
|
it('getExecutionId() returns null if not set', () => {
|
|
451
|
-
const ctx = new
|
|
451
|
+
const ctx = new AdminScriptContext();
|
|
452
452
|
|
|
453
453
|
expect(ctx.getExecutionId()).toBeNull();
|
|
454
454
|
});
|
|
455
455
|
});
|
|
456
456
|
|
|
457
|
-
describe('
|
|
457
|
+
describe('createAdminScriptContext factory', () => {
|
|
458
458
|
it('creates AdminScriptContext instance', () => {
|
|
459
|
-
const ctx =
|
|
459
|
+
const ctx = createAdminScriptContext({ executionId: 'exec_123' });
|
|
460
460
|
|
|
461
|
-
expect(ctx).toBeInstanceOf(
|
|
461
|
+
expect(ctx).toBeInstanceOf(AdminScriptContext);
|
|
462
462
|
expect(ctx.executionId).toBe('exec_123');
|
|
463
463
|
});
|
|
464
464
|
|
|
465
465
|
it('creates with default params', () => {
|
|
466
|
-
const ctx =
|
|
466
|
+
const ctx = createAdminScriptContext();
|
|
467
467
|
|
|
468
|
-
expect(ctx).toBeInstanceOf(
|
|
468
|
+
expect(ctx).toBeInstanceOf(AdminScriptContext);
|
|
469
469
|
expect(ctx.executionId).toBeNull();
|
|
470
470
|
});
|
|
471
471
|
});
|
|
@@ -27,7 +27,8 @@ class AdminScriptContext {
|
|
|
27
27
|
|
|
28
28
|
this.integrationFactory = params.integrationFactory || null;
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// Repositories are created on first use so the Prisma client is only
|
|
31
|
+
// initialized (and only for the repos a script actually touches) when needed.
|
|
31
32
|
this._integrationRepository = null;
|
|
32
33
|
this._userRepository = null;
|
|
33
34
|
this._moduleRepository = null;
|
|
@@ -170,14 +171,7 @@ function createAdminScriptContext(params = {}) {
|
|
|
170
171
|
return new AdminScriptContext(params);
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
// Legacy aliases for backwards compatibility
|
|
174
|
-
const AdminFriggCommands = AdminScriptContext;
|
|
175
|
-
const createAdminFriggCommands = createAdminScriptContext;
|
|
176
|
-
|
|
177
174
|
module.exports = {
|
|
178
175
|
AdminScriptContext,
|
|
179
176
|
createAdminScriptContext,
|
|
180
|
-
// Legacy exports (deprecated)
|
|
181
|
-
AdminFriggCommands,
|
|
182
|
-
createAdminFriggCommands,
|
|
183
177
|
};
|