@friggframework/core 2.0.0--canary.658.164d92b.0 → 2.0.0--canary.657.07aea31.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/CLAUDE.md +76 -52
- package/core/CLAUDE.md +25 -0
- package/core/Worker.js +304 -9
- package/handlers/backend-utils.js +28 -0
- package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +2 -0
- package/integrations/integration-base.js +0 -16
- package/integrations/repositories/integration-repository-documentdb.js +10 -23
- package/integrations/repositories/integration-repository-interface.js +7 -21
- package/integrations/repositories/integration-repository-mongo.js +16 -29
- package/integrations/repositories/integration-repository-postgres.js +16 -30
- package/integrations/tests/doubles/test-integration-repository.js +2 -15
- package/integrations/use-cases/clear-rate-limit-wait.js +23 -0
- package/integrations/use-cases/index.js +5 -1
- package/integrations/use-cases/record-rate-limit-wait.js +35 -0
- package/integrations/use-cases/update-integration-messages.js +9 -28
- package/modules/module.js +0 -27
- package/modules/requester/oauth-2.js +7 -0
- package/modules/requester/requester.js +0 -28
- package/package.json +7 -5
- package/queues/queue-deferral.js +69 -0
- package/queues/queue-delivery.js +1 -0
- package/queues/queuer-util.js +1 -1
- package/types/core/index.d.ts +15 -0
- package/types/integrations/index.d.ts +4 -20
- package/types/module-plugin/index.d.ts +1 -5
- package/integrations/repositories/message-item-shared.js +0 -4
- package/integrations/tests/doubles/prisma-message-row.js +0 -24
- package/integrations/use-cases/record-rate-limit-message.js +0 -110
|
@@ -14,7 +14,6 @@ const {
|
|
|
14
14
|
IntegrationRepositoryInterface,
|
|
15
15
|
} = require('./integration-repository-interface');
|
|
16
16
|
const { validateConfigPatch } = require('./config-patch-shared');
|
|
17
|
-
const { messagesOfType } = require('./message-item-shared');
|
|
18
17
|
|
|
19
18
|
class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
20
19
|
constructor() {
|
|
@@ -95,8 +94,9 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
95
94
|
async updateIntegrationMessages(
|
|
96
95
|
integrationId,
|
|
97
96
|
messageType,
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
messageTitle,
|
|
98
|
+
messageBody,
|
|
99
|
+
messageTimestamp
|
|
100
100
|
) {
|
|
101
101
|
const objectId = toObjectId(integrationId);
|
|
102
102
|
if (!objectId) {
|
|
@@ -107,12 +107,13 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
107
107
|
throw new Error(`Integration ${integrationId} not found`);
|
|
108
108
|
}
|
|
109
109
|
const messages = this._extractMessages(existing);
|
|
110
|
-
const list = [...
|
|
111
|
-
list.push({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
110
|
+
const list = Array.isArray(messages[messageType]) ? [...messages[messageType]] : [];
|
|
111
|
+
list.push({
|
|
112
|
+
title: messageTitle ?? null,
|
|
113
|
+
message: messageBody,
|
|
114
|
+
timestamp: messageTimestamp,
|
|
115
|
+
});
|
|
116
|
+
const updatedMessages = { ...messages, [messageType]: list };
|
|
116
117
|
await updateOne(
|
|
117
118
|
this.prisma,
|
|
118
119
|
'Integration',
|
|
@@ -131,20 +132,6 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
|
|
|
131
132
|
return true;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
async findIntegrationMessages(integrationId, messageType) {
|
|
135
|
-
const objectId = toObjectId(integrationId);
|
|
136
|
-
if (!objectId) {
|
|
137
|
-
throw new Error(`Integration ${integrationId} not found`);
|
|
138
|
-
}
|
|
139
|
-
const existing = await findOne(this.prisma, 'Integration', {
|
|
140
|
-
_id: objectId,
|
|
141
|
-
});
|
|
142
|
-
if (!existing) {
|
|
143
|
-
throw new Error(`Integration ${integrationId} not found`);
|
|
144
|
-
}
|
|
145
|
-
return messagesOfType(this._extractMessages(existing), messageType);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
135
|
async createIntegration(entities, userId, config) {
|
|
149
136
|
const now = new Date();
|
|
150
137
|
const document = {
|
|
@@ -97,40 +97,26 @@ class IntegrationRepositoryInterface {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* Update integration messages
|
|
101
101
|
*
|
|
102
102
|
* @param {string|number} integrationId - Integration ID
|
|
103
103
|
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
104
|
-
* @param {
|
|
105
|
-
* @param {
|
|
106
|
-
* @param {
|
|
104
|
+
* @param {string} messageTitle - Message title
|
|
105
|
+
* @param {string} messageBody - Message body
|
|
106
|
+
* @param {Date} messageTimestamp - Message timestamp
|
|
107
107
|
* @returns {Promise<boolean>} Success indicator
|
|
108
108
|
* @abstract
|
|
109
109
|
*/
|
|
110
110
|
async updateIntegrationMessages(
|
|
111
111
|
integrationId,
|
|
112
112
|
messageType,
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
messageTitle,
|
|
114
|
+
messageBody,
|
|
115
|
+
messageTimestamp
|
|
115
116
|
) {
|
|
116
117
|
throw new Error('Method updateIntegrationMessages must be implemented by subclass');
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
/**
|
|
120
|
-
* Find the stored messages of one type. Reads the stored items, not the
|
|
121
|
-
* `messages` of an integration record, which some adapters do not fill.
|
|
122
|
-
*
|
|
123
|
-
* @param {string|number} integrationId - Integration ID
|
|
124
|
-
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
125
|
-
* @returns {Promise<Array>} The stored message items of that type, oldest first
|
|
126
|
-
* @abstract
|
|
127
|
-
*/
|
|
128
|
-
async findIntegrationMessages(integrationId, messageType) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
'Method findIntegrationMessages must be implemented by subclass'
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
120
|
/**
|
|
135
121
|
* Create a new integration
|
|
136
122
|
*
|
|
@@ -3,7 +3,6 @@ const {
|
|
|
3
3
|
IntegrationRepositoryInterface,
|
|
4
4
|
} = require('./integration-repository-interface');
|
|
5
5
|
const { validateConfigPatch } = require('./config-patch-shared');
|
|
6
|
-
const { messagesOfType } = require('./message-item-shared');
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* MongoDB Integration Repository Adapter
|
|
@@ -230,16 +229,17 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
|
|
|
230
229
|
*
|
|
231
230
|
* @param {string} integrationId - Integration ID
|
|
232
231
|
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
233
|
-
* @param {
|
|
234
|
-
* @param {
|
|
235
|
-
* @param {
|
|
232
|
+
* @param {string} messageTitle - Message title
|
|
233
|
+
* @param {string} messageBody - Message body
|
|
234
|
+
* @param {Date} messageTimestamp - Message timestamp
|
|
236
235
|
* @returns {Promise<boolean>} Success indicator
|
|
237
236
|
*/
|
|
238
237
|
async updateIntegrationMessages(
|
|
239
238
|
integrationId,
|
|
240
239
|
messageType,
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
messageTitle,
|
|
241
|
+
messageBody,
|
|
242
|
+
messageTimestamp
|
|
243
243
|
) {
|
|
244
244
|
// Get current integration
|
|
245
245
|
const integration = await this.prisma.integration.findUnique({
|
|
@@ -251,42 +251,29 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
// Parse existing messages (JSON field)
|
|
254
|
-
const
|
|
254
|
+
const messages = integration.messages || {};
|
|
255
|
+
const messageArray = Array.isArray(messages[messageType])
|
|
256
|
+
? messages[messageType]
|
|
257
|
+
: [];
|
|
255
258
|
|
|
256
259
|
// Add new message
|
|
257
|
-
messageArray.push(
|
|
260
|
+
messageArray.push({
|
|
261
|
+
title: messageTitle,
|
|
262
|
+
message: messageBody,
|
|
263
|
+
timestamp: messageTimestamp,
|
|
264
|
+
});
|
|
258
265
|
|
|
259
266
|
// Update messages
|
|
260
267
|
await this.prisma.integration.update({
|
|
261
268
|
where: { id: integrationId },
|
|
262
269
|
data: {
|
|
263
|
-
[messageType]: messageArray
|
|
270
|
+
[messageType]: messageArray,
|
|
264
271
|
},
|
|
265
272
|
});
|
|
266
273
|
|
|
267
274
|
return true; // Mongoose compatibility
|
|
268
275
|
}
|
|
269
276
|
|
|
270
|
-
/**
|
|
271
|
-
* Find the stored messages of one type
|
|
272
|
-
*
|
|
273
|
-
* @param {string} integrationId - Integration ID
|
|
274
|
-
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
275
|
-
* @returns {Promise<Array>} The stored message items of that type, oldest first
|
|
276
|
-
*/
|
|
277
|
-
async findIntegrationMessages(integrationId, messageType) {
|
|
278
|
-
const integration = await this.prisma.integration.findUnique({
|
|
279
|
-
where: { id: integrationId },
|
|
280
|
-
select: { [messageType]: true },
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
if (!integration) {
|
|
284
|
-
throw new Error(`Integration ${integrationId} not found`);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return messagesOfType(integration, messageType);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
277
|
/**
|
|
291
278
|
* Find all integrations whose entity set includes the given entity ID.
|
|
292
279
|
*
|
|
@@ -3,7 +3,6 @@ const {
|
|
|
3
3
|
IntegrationRepositoryInterface,
|
|
4
4
|
} = require('./integration-repository-interface');
|
|
5
5
|
const { validateConfigPatch } = require('./config-patch-shared');
|
|
6
|
-
const { messagesOfType } = require('./message-item-shared');
|
|
7
6
|
const { strictIntId } = require('./report-id');
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -274,16 +273,17 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
|
|
|
274
273
|
*
|
|
275
274
|
* @param {string} integrationId - Integration ID (string from application layer)
|
|
276
275
|
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
277
|
-
* @param {
|
|
278
|
-
* @param {
|
|
279
|
-
* @param {
|
|
276
|
+
* @param {string} messageTitle - Message title
|
|
277
|
+
* @param {string} messageBody - Message body
|
|
278
|
+
* @param {Date} messageTimestamp - Message timestamp
|
|
280
279
|
* @returns {Promise<boolean>} Success indicator
|
|
281
280
|
*/
|
|
282
281
|
async updateIntegrationMessages(
|
|
283
282
|
integrationId,
|
|
284
283
|
messageType,
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
messageTitle,
|
|
285
|
+
messageBody,
|
|
286
|
+
messageTimestamp
|
|
287
287
|
) {
|
|
288
288
|
const intId = this._convertId(integrationId);
|
|
289
289
|
|
|
@@ -297,43 +297,29 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
|
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
// Parse existing messages (JSON field)
|
|
300
|
-
const
|
|
300
|
+
const messages = integration.messages || {};
|
|
301
|
+
const messageArray = Array.isArray(messages[messageType])
|
|
302
|
+
? messages[messageType]
|
|
303
|
+
: [];
|
|
301
304
|
|
|
302
305
|
// Add new message
|
|
303
|
-
messageArray.push(
|
|
306
|
+
messageArray.push({
|
|
307
|
+
title: messageTitle,
|
|
308
|
+
message: messageBody,
|
|
309
|
+
timestamp: messageTimestamp,
|
|
310
|
+
});
|
|
304
311
|
|
|
305
312
|
// Update messages
|
|
306
313
|
await this.prisma.integration.update({
|
|
307
314
|
where: { id: intId },
|
|
308
315
|
data: {
|
|
309
|
-
[messageType]: messageArray
|
|
316
|
+
[messageType]: messageArray,
|
|
310
317
|
},
|
|
311
318
|
});
|
|
312
319
|
|
|
313
320
|
return true; // Mongoose compatibility
|
|
314
321
|
}
|
|
315
322
|
|
|
316
|
-
/**
|
|
317
|
-
* Find the stored messages of one type
|
|
318
|
-
*
|
|
319
|
-
* @param {string} integrationId - Integration ID (string from application layer)
|
|
320
|
-
* @param {string} messageType - Type of message (errors, warnings, info, logs)
|
|
321
|
-
* @returns {Promise<Array>} The stored message items of that type, oldest first
|
|
322
|
-
*/
|
|
323
|
-
async findIntegrationMessages(integrationId, messageType) {
|
|
324
|
-
const intId = this._convertId(integrationId);
|
|
325
|
-
const integration = await this.prisma.integration.findUnique({
|
|
326
|
-
where: { id: intId },
|
|
327
|
-
select: { [messageType]: true },
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
if (!integration) {
|
|
331
|
-
throw new Error(`Integration ${integrationId} not found`);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return messagesOfType(integration, messageType);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
323
|
/**
|
|
338
324
|
* Create a new integration
|
|
339
325
|
*
|
|
@@ -72,31 +72,18 @@ class TestIntegrationRepository {
|
|
|
72
72
|
return results;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async updateIntegrationMessages(id, type,
|
|
75
|
+
async updateIntegrationMessages(id, type, title, body, timestamp) {
|
|
76
76
|
const rec = this.store.get(id);
|
|
77
77
|
if (!rec) {
|
|
78
78
|
this.operationHistory.push({ operation: 'updateMessages', id, success: false });
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
if (!rec.messages[type]) rec.messages[type] = [];
|
|
82
|
-
rec.messages[type].push(
|
|
83
|
-
rec.messages[type] = rec.messages[type].slice(-keepLast);
|
|
82
|
+
rec.messages[type].push({ title, message: body, timestamp });
|
|
84
83
|
this.operationHistory.push({ operation: 'updateMessages', id, type, success: true });
|
|
85
84
|
return true;
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
async findIntegrationMessages(id, type) {
|
|
89
|
-
const rec = this.store.get(id);
|
|
90
|
-
this.operationHistory.push({
|
|
91
|
-
operation: 'findMessages',
|
|
92
|
-
id,
|
|
93
|
-
type,
|
|
94
|
-
found: !!rec,
|
|
95
|
-
});
|
|
96
|
-
if (!rec) throw new Error(`Integration ${id} not found`);
|
|
97
|
-
return [...(rec.messages[type] ?? [])];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
87
|
async updateIntegrationConfig(id, config) {
|
|
101
88
|
if (config === null || config === undefined) {
|
|
102
89
|
throw new Error('Config parameter is required');
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const CLEAR_RATE_LIMIT_TOLERANCE_MS = 5_000;
|
|
2
|
+
|
|
3
|
+
class ClearRateLimitWait {
|
|
4
|
+
constructor({ processRepository }) {
|
|
5
|
+
if (!processRepository) {
|
|
6
|
+
throw new Error('processRepository is required');
|
|
7
|
+
}
|
|
8
|
+
this.processRepository = processRepository;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async execute(processId) {
|
|
12
|
+
const process = await this.processRepository.findById(processId);
|
|
13
|
+
const current = process?.context?.rateLimit;
|
|
14
|
+
if (current?.status !== 'WAITING') return;
|
|
15
|
+
const remainingMs = Date.parse(current.retryAt) - Date.now();
|
|
16
|
+
if (remainingMs > CLEAR_RATE_LIMIT_TOLERANCE_MS) return;
|
|
17
|
+
await this.processRepository.applyProcessUpdate(processId, {
|
|
18
|
+
set: { 'context.rateLimit': null },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { ClearRateLimitWait };
|
|
@@ -6,6 +6,8 @@ const { CreateProcess } = require('./create-process');
|
|
|
6
6
|
const { UpdateProcessState } = require('./update-process-state');
|
|
7
7
|
const { UpdateProcessMetrics } = require('./update-process-metrics');
|
|
8
8
|
const { GetProcess } = require('./get-process');
|
|
9
|
+
const { RecordRateLimitWait } = require('./record-rate-limit-wait');
|
|
10
|
+
const { ClearRateLimitWait } = require('./clear-rate-limit-wait');
|
|
9
11
|
|
|
10
12
|
module.exports = {
|
|
11
13
|
GetIntegrationsForUser,
|
|
@@ -16,4 +18,6 @@ module.exports = {
|
|
|
16
18
|
UpdateProcessState,
|
|
17
19
|
UpdateProcessMetrics,
|
|
18
20
|
GetProcess,
|
|
19
|
-
|
|
21
|
+
RecordRateLimitWait,
|
|
22
|
+
ClearRateLimitWait,
|
|
23
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const keepsCurrentRateLimit = (current, next) => {
|
|
2
|
+
if (!current) return false;
|
|
3
|
+
if (next.status === 'EXHAUSTED') return false;
|
|
4
|
+
if (current.status === 'EXHAUSTED') return true;
|
|
5
|
+
return Date.parse(current.retryAt) > next.retryAt.getTime();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
class RecordRateLimitWait {
|
|
9
|
+
constructor({ processRepository }) {
|
|
10
|
+
if (!processRepository) {
|
|
11
|
+
throw new Error('processRepository is required');
|
|
12
|
+
}
|
|
13
|
+
this.processRepository = processRepository;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async execute(processId, wait) {
|
|
17
|
+
const process = await this.processRepository.findById(processId);
|
|
18
|
+
if (keepsCurrentRateLimit(process?.context?.rateLimit, wait)) return;
|
|
19
|
+
await this.processRepository.applyProcessUpdate(processId, {
|
|
20
|
+
set: {
|
|
21
|
+
'context.rateLimit': {
|
|
22
|
+
status: wait.status,
|
|
23
|
+
mechanism: wait.mechanism,
|
|
24
|
+
retryAt: wait.retryAt.toISOString(),
|
|
25
|
+
reason: wait.reason,
|
|
26
|
+
module: wait.module,
|
|
27
|
+
deferrals: wait.deferrals,
|
|
28
|
+
updatedAt: new Date().toISOString(),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { RecordRateLimitWait };
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
const MAX_MESSAGES_PER_TYPE = 50;
|
|
2
|
-
|
|
3
|
-
const isPlainObject = (value) =>
|
|
4
|
-
value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
-
|
|
6
|
-
function toMessageItem(titleOrItem, messageBody, messageTimestamp) {
|
|
7
|
-
if (isPlainObject(titleOrItem)) return { ...titleOrItem };
|
|
8
|
-
return {
|
|
9
|
-
title: titleOrItem,
|
|
10
|
-
message: messageBody,
|
|
11
|
-
timestamp: messageTimestamp,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
1
|
/**
|
|
16
2
|
* Use case for updating messages associated with an integration.
|
|
17
3
|
* @class UpdateIntegrationMessages
|
|
@@ -27,21 +13,19 @@ class UpdateIntegrationMessages {
|
|
|
27
13
|
}
|
|
28
14
|
|
|
29
15
|
/**
|
|
30
|
-
* Executes the integration messages update.
|
|
31
|
-
* (title, body, timestamp) or one message item object; the keys of an item
|
|
32
|
-
* object are stored as they are.
|
|
16
|
+
* Executes the integration messages update.
|
|
33
17
|
* @async
|
|
34
18
|
* @param {string} integrationId - ID of the integration to update.
|
|
35
19
|
* @param {string} messageType - Type of message: 'errors', 'warnings', 'info', or 'logs'.
|
|
36
|
-
* @param {string
|
|
37
|
-
* @param {string}
|
|
38
|
-
* @param {string}
|
|
20
|
+
* @param {string} messageTitle - Title of the message.
|
|
21
|
+
* @param {string} messageBody - Body content of the message.
|
|
22
|
+
* @param {string} messageTimestamp - Timestamp when the message was created.
|
|
39
23
|
* @returns {Promise<Object>} The updated integration record.
|
|
40
24
|
*/
|
|
41
25
|
async execute(
|
|
42
26
|
integrationId,
|
|
43
27
|
messageType,
|
|
44
|
-
|
|
28
|
+
messageTitle,
|
|
45
29
|
messageBody,
|
|
46
30
|
messageTimestamp
|
|
47
31
|
) {
|
|
@@ -49,15 +33,12 @@ class UpdateIntegrationMessages {
|
|
|
49
33
|
await this.integrationRepository.updateIntegrationMessages(
|
|
50
34
|
integrationId,
|
|
51
35
|
messageType,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
messageTimestamp
|
|
56
|
-
),
|
|
57
|
-
{ keepLast: MAX_MESSAGES_PER_TYPE }
|
|
36
|
+
messageTitle,
|
|
37
|
+
messageBody,
|
|
38
|
+
messageTimestamp
|
|
58
39
|
);
|
|
59
40
|
return integration;
|
|
60
41
|
}
|
|
61
42
|
}
|
|
62
43
|
|
|
63
|
-
module.exports = {
|
|
44
|
+
module.exports = { UpdateIntegrationMessages };
|
package/modules/module.js
CHANGED
|
@@ -8,7 +8,6 @@ const {
|
|
|
8
8
|
const {
|
|
9
9
|
createModuleRepository,
|
|
10
10
|
} = require('./repositories/module-repository-factory');
|
|
11
|
-
const { readRateLimitPolicy } = require('./requester/rate-limit');
|
|
12
11
|
|
|
13
12
|
// todo: this class should be a Domain class, and the Delegate function is preventing us from
|
|
14
13
|
// doing that, we probably have to get rid of the Delegate class as well as the event based
|
|
@@ -52,8 +51,6 @@ class Module extends Delegate {
|
|
|
52
51
|
this.delegateTypes.push(this.DLGT_CREDENTIAL_INVALIDATED);
|
|
53
52
|
this.DLGT_CREDENTIAL_VALIDATED = 'CREDENTIAL_VALIDATED';
|
|
54
53
|
this.delegateTypes.push(this.DLGT_CREDENTIAL_VALIDATED);
|
|
55
|
-
this.DLGT_RATE_LIMITED = 'RATE_LIMITED';
|
|
56
|
-
this.delegateTypes.push(this.DLGT_RATE_LIMITED);
|
|
57
54
|
|
|
58
55
|
Object.assign(this, this.definition.requiredAuthMethods);
|
|
59
56
|
|
|
@@ -163,8 +160,6 @@ class Module extends Delegate {
|
|
|
163
160
|
await this.deauthorize();
|
|
164
161
|
} else if (delegateString === this.api.DLGT_INVALID_AUTH) {
|
|
165
162
|
await this.markCredentialsInvalid(object);
|
|
166
|
-
} else if (delegateString === this.api.DLGT_RATE_LIMITED) {
|
|
167
|
-
await this.reportRateLimit(object);
|
|
168
163
|
} else if (delegateString === this.api.DLGT_CREDENTIAL_RELOAD) {
|
|
169
164
|
return this.reloadCredential();
|
|
170
165
|
}
|
|
@@ -239,28 +234,6 @@ class Module extends Delegate {
|
|
|
239
234
|
}
|
|
240
235
|
}
|
|
241
236
|
|
|
242
|
-
async reportRateLimit(rateLimitError) {
|
|
243
|
-
const { reason, retryAt, policy, statusCode } = rateLimitError;
|
|
244
|
-
const links =
|
|
245
|
-
readRateLimitPolicy(this.apiClass)?.userHints?.[reason]?.links ??
|
|
246
|
-
[];
|
|
247
|
-
try {
|
|
248
|
-
await this.notify(this.DLGT_RATE_LIMITED, {
|
|
249
|
-
moduleName: this.name,
|
|
250
|
-
reason,
|
|
251
|
-
retryAt,
|
|
252
|
-
policy,
|
|
253
|
-
statusCode,
|
|
254
|
-
links,
|
|
255
|
-
});
|
|
256
|
-
} catch (err) {
|
|
257
|
-
this.logger.warn('Failed to propagate RATE_LIMITED', {
|
|
258
|
-
eventName: `${this.logger.name}.rate_limit_propagation_failed`,
|
|
259
|
-
error: err,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
237
|
async deauthorize() {
|
|
265
238
|
//todo: Check if this is correct, we're instantiating a new api without params (credentials, tokens, etc...)
|
|
266
239
|
this.api = new this.apiClass();
|
|
@@ -398,6 +398,13 @@ class OAuth2Requester extends Requester {
|
|
|
398
398
|
);
|
|
399
399
|
transportError.statusCode = status;
|
|
400
400
|
transportError.isTokenRefreshTransportFailure = true;
|
|
401
|
+
if (error?.isRateLimited) {
|
|
402
|
+
transportError.isRateLimited = true;
|
|
403
|
+
transportError.retryAt = error.retryAt;
|
|
404
|
+
transportError.waitMs = error.waitMs;
|
|
405
|
+
transportError.reason = error.reason;
|
|
406
|
+
transportError.module = error.module;
|
|
407
|
+
}
|
|
401
408
|
return transportError;
|
|
402
409
|
}
|
|
403
410
|
|
|
@@ -10,7 +10,6 @@ const { redactUrl } = require('../../logs/redact');
|
|
|
10
10
|
const { toSanitizedSurrogate } = require('../../logs/serialize');
|
|
11
11
|
const { getLoggerScope } = require('../../logs/context');
|
|
12
12
|
const {
|
|
13
|
-
DEFAULT_MAX_IN_PROCESS_WAIT_MS,
|
|
14
13
|
computeScopeKey,
|
|
15
14
|
computeWaitMs,
|
|
16
15
|
inProcessBudgetMs,
|
|
@@ -55,8 +54,6 @@ class Requester extends Delegate {
|
|
|
55
54
|
this._authGeneration = 0;
|
|
56
55
|
this.DLGT_INVALID_AUTH = 'INVALID_AUTH';
|
|
57
56
|
this.delegateTypes.push(this.DLGT_INVALID_AUTH);
|
|
58
|
-
this.DLGT_RATE_LIMITED = 'RATE_LIMITED';
|
|
59
|
-
this.delegateTypes.push(this.DLGT_RATE_LIMITED);
|
|
60
57
|
this.agent = get(params, 'agent', null);
|
|
61
58
|
|
|
62
59
|
// Per-attempt HTTP timeout. Without this the framework called fetch()
|
|
@@ -531,7 +528,6 @@ class Requester extends Delegate {
|
|
|
531
528
|
module: this._telemetryModuleLabel(),
|
|
532
529
|
scopeKey: computeScopeKey(this._rateLimitPolicy, this),
|
|
533
530
|
});
|
|
534
|
-
await this._notifyRateLimited(rateLimitError);
|
|
535
531
|
throw this._maybeFlagTimeoutDuringBodyRead(rateLimitError, timeoutMs);
|
|
536
532
|
}
|
|
537
533
|
|
|
@@ -599,30 +595,6 @@ class Requester extends Delegate {
|
|
|
599
595
|
});
|
|
600
596
|
}
|
|
601
597
|
|
|
602
|
-
async _notifyRateLimited(rateLimitError) {
|
|
603
|
-
if (!this._waitsLongerThanInProcessCap(rateLimitError)) return;
|
|
604
|
-
try {
|
|
605
|
-
await this.notify(this.DLGT_RATE_LIMITED, rateLimitError);
|
|
606
|
-
} catch (error) {
|
|
607
|
-
const logger = this.logger;
|
|
608
|
-
logger.warn('Rate limit notification failed', {
|
|
609
|
-
eventName: `${logger.name}.rate_limit_notify_failed`,
|
|
610
|
-
statusCode: rateLimitError.statusCode,
|
|
611
|
-
error,
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
_waitsLongerThanInProcessCap(rateLimitError) {
|
|
617
|
-
const waitMs = Number.isFinite(rateLimitError?.waitMs)
|
|
618
|
-
? rateLimitError.waitMs
|
|
619
|
-
: new Date(rateLimitError?.retryAt).getTime() - Date.now();
|
|
620
|
-
const capMs =
|
|
621
|
-
this._rateLimitPolicy?.maxInProcessWaitMs ??
|
|
622
|
-
DEFAULT_MAX_IN_PROCESS_WAIT_MS;
|
|
623
|
-
return waitMs > capMs;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
598
|
_logRequestFailed(encodedUrl, options, status) {
|
|
627
599
|
const logger = this.logger;
|
|
628
600
|
if (!logger.isLevelEnabled('DEBUG')) return;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.657.07aea31.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
8
8
|
"@aws-sdk/client-lambda": "^3.714.0",
|
|
9
9
|
"@aws-sdk/client-s3": "^3.588.0",
|
|
10
|
+
"@aws-sdk/client-scheduler": "^3.588.0",
|
|
10
11
|
"@aws-sdk/client-sqs": "^3.588.0",
|
|
11
12
|
"@aws-sdk/client-ssm": "^3.588.0",
|
|
12
13
|
"@aws-sdk/s3-request-presigner": "^3.588.0",
|
|
@@ -47,12 +48,13 @@
|
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
51
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
52
|
-
"@friggframework/test": "2.0.0--canary.
|
|
51
|
+
"@friggframework/eslint-config": "2.0.0--canary.657.07aea31.0",
|
|
52
|
+
"@friggframework/prettier-config": "2.0.0--canary.657.07aea31.0",
|
|
53
|
+
"@friggframework/test": "2.0.0--canary.657.07aea31.0",
|
|
53
54
|
"@prisma/client": "^6.19.3",
|
|
54
55
|
"@types/lodash": "4.17.15",
|
|
55
56
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
57
|
+
"aws-sdk-client-mock": "^4.1.0",
|
|
56
58
|
"chai": "^4.3.6",
|
|
57
59
|
"eslint": "^8.22.0",
|
|
58
60
|
"eslint-plugin-import": "^2.29.1",
|
|
@@ -89,5 +91,5 @@
|
|
|
89
91
|
"publishConfig": {
|
|
90
92
|
"access": "public"
|
|
91
93
|
},
|
|
92
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "07aea3197703a6bc5116bdb6c52308c0ac9b50db"
|
|
93
95
|
}
|