@friggframework/core 2.0.0--canary.657.18fb0ee.0 → 2.0.0--canary.658.130b4ec.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/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.657.18fb0ee.0",
4
+ "version": "2.0.0--canary.658.130b4ec.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",
11
10
  "@aws-sdk/client-sqs": "^3.588.0",
12
11
  "@aws-sdk/client-ssm": "^3.588.0",
13
12
  "@aws-sdk/s3-request-presigner": "^3.588.0",
@@ -48,13 +47,12 @@
48
47
  }
49
48
  },
50
49
  "devDependencies": {
51
- "@friggframework/eslint-config": "2.0.0--canary.657.18fb0ee.0",
52
- "@friggframework/prettier-config": "2.0.0--canary.657.18fb0ee.0",
53
- "@friggframework/test": "2.0.0--canary.657.18fb0ee.0",
50
+ "@friggframework/eslint-config": "2.0.0--canary.658.130b4ec.0",
51
+ "@friggframework/prettier-config": "2.0.0--canary.658.130b4ec.0",
52
+ "@friggframework/test": "2.0.0--canary.658.130b4ec.0",
54
53
  "@prisma/client": "^6.19.3",
55
54
  "@types/lodash": "4.17.15",
56
55
  "@typescript-eslint/eslint-plugin": "^8.0.0",
57
- "aws-sdk-client-mock": "^4.1.0",
58
56
  "chai": "^4.3.6",
59
57
  "eslint": "^8.22.0",
60
58
  "eslint-plugin-import": "^2.29.1",
@@ -91,5 +89,5 @@
91
89
  "publishConfig": {
92
90
  "access": "public"
93
91
  },
94
- "gitHead": "18fb0eec33ecfe46362d17ff8660d06a929ae9ae"
92
+ "gitHead": "130b4ec4ebf0f605416f3db316b5ddbe54a37d32"
95
93
  }
@@ -38,5 +38,4 @@ module.exports = {
38
38
  INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
39
39
  QUEUE_MAX_RECEIVE_COUNT_ENV,
40
40
  readQueueDelivery,
41
- toPositiveInteger,
42
41
  };
@@ -126,4 +126,4 @@ const QueuerUtil = {
126
126
  },
127
127
  };
128
128
 
129
- module.exports = { QueuerUtil, awsConfigOptions };
129
+ module.exports = { QueuerUtil };
@@ -47,27 +47,8 @@ declare module "@friggframework/core" {
47
47
  send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;
48
48
 
49
49
  sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
50
-
51
- recordRateLimitWait(
52
- body: object,
53
- error: Error,
54
- state: RateLimitWaitState
55
- ): Promise<void>;
56
-
57
- clearRateLimitWait(
58
- body: object,
59
- options?: { deferralId?: string }
60
- ): Promise<void>;
61
50
  }
62
51
 
63
- export type RateLimitWaitState = {
64
- status: "WAITING" | "EXHAUSTED";
65
- mechanism: "delay" | "schedule" | "visibility" | "none";
66
- deferrals: number;
67
- deferralId?: string;
68
- retryAt: Date;
69
- };
70
-
71
52
  interface IWorker {
72
53
  getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;
73
54
  run(params: { Records: any }, context?: object): Promise<BatchItemFailuresResponse>;
@@ -1,6 +1,22 @@
1
1
  declare module "@friggframework/integrations" {
2
2
  import { Delegate, IFriggDelegate } from "@friggframework/core";
3
3
 
4
+ export type IntegrationMessageAction =
5
+ | { type: "RETRY_WHEN_READY" }
6
+ | { type: "LINK"; label: string; url: string };
7
+
8
+ export interface IntegrationMessage {
9
+ title: string;
10
+ message: string;
11
+ timestamp: number;
12
+ code?: string;
13
+ module?: string;
14
+ reason?: string;
15
+ retryAt?: string;
16
+ actions?: IntegrationMessageAction[];
17
+ [key: string]: unknown;
18
+ }
19
+
4
20
  export interface Integration {
5
21
  entities: any[];
6
22
  userId: string;
@@ -8,10 +24,10 @@ declare module "@friggframework/integrations" {
8
24
  config: any;
9
25
  version: string;
10
26
  messages: {
11
- errors: [];
12
- warnings: [];
13
- info: [];
14
- logs: [];
27
+ errors: IntegrationMessage[];
28
+ warnings: IntegrationMessage[];
29
+ info: IntegrationMessage[];
30
+ logs: IntegrationMessage[];
15
31
  };
16
32
  }
17
33
 
@@ -1,6 +1,6 @@
1
1
  declare module "@friggframework/module-plugin" {
2
2
  import { Delegate, IFriggDelegate } from "@friggframework/core";
3
- import type { RateLimitHint } from "@friggframework/errors";
3
+ import type { RateLimitError, RateLimitHint } from "@friggframework/errors";
4
4
 
5
5
  export interface Credential {
6
6
  id?: string;
@@ -65,6 +65,7 @@ declare module "@friggframework/module-plugin" {
65
65
  static requestTimeoutMs?: number;
66
66
 
67
67
  DLGT_INVALID_AUTH: string;
68
+ DLGT_RATE_LIMITED: string;
68
69
  requestTimeoutMs: number;
69
70
  backOff: number[];
70
71
  fetch: any;
@@ -84,6 +85,7 @@ declare module "@friggframework/module-plugin" {
84
85
  parseBody(response: any): Promise<any>;
85
86
  refreshAuth(): Promise<any>;
86
87
  _adoptNewerCredential(): Promise<boolean>;
88
+ _notifyRateLimited(rateLimitError: RateLimitError): Promise<void>;
87
89
 
88
90
  delegate: any;
89
91
  delegateTypes: any[];
@@ -101,6 +103,7 @@ declare module "@friggframework/module-plugin" {
101
103
  isRefreshable: boolean;
102
104
  refreshCount: number;
103
105
  DLGT_INVALID_AUTH: string;
106
+ DLGT_RATE_LIMITED: string;
104
107
  fetch: any;
105
108
 
106
109
  parseBody(response: any): Promise<any>;
@@ -116,6 +119,7 @@ declare module "@friggframework/module-plugin" {
116
119
  _delete(options: RequestOptions): Promise<any>;
117
120
  refreshAuth(): Promise<any>;
118
121
  _adoptNewerCredential(): Promise<boolean>;
122
+ _notifyRateLimited(rateLimitError: RateLimitError): Promise<void>;
119
123
  }
120
124
 
121
125
  type RequestOptions = {
@@ -1,28 +0,0 @@
1
- const CLEAR_RATE_LIMIT_TOLERANCE_MS = 5_000;
2
-
3
- const isOwnWait = (current, deferralId) =>
4
- Boolean(deferralId) && current.deferralId === deferralId;
5
-
6
- const isOver = (current) =>
7
- Date.parse(current.retryAt) - Date.now() <= CLEAR_RATE_LIMIT_TOLERANCE_MS;
8
-
9
- class ClearRateLimitWait {
10
- constructor({ processRepository }) {
11
- if (!processRepository) {
12
- throw new Error('processRepository is required');
13
- }
14
- this.processRepository = processRepository;
15
- }
16
-
17
- async execute(processId, { deferralId } = {}) {
18
- const process = await this.processRepository.findById(processId);
19
- const current = process?.context?.rateLimit;
20
- if (current?.status !== 'WAITING') return;
21
- if (!isOwnWait(current, deferralId) && !isOver(current)) return;
22
- await this.processRepository.applyProcessUpdate(processId, {
23
- set: { 'context.rateLimit': null },
24
- });
25
- }
26
- }
27
-
28
- module.exports = { ClearRateLimitWait };
@@ -1,36 +0,0 @@
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
- deferralId: wait.deferralId,
29
- updatedAt: new Date().toISOString(),
30
- },
31
- },
32
- });
33
- }
34
- }
35
-
36
- module.exports = { RecordRateLimitWait };
@@ -1,74 +0,0 @@
1
- const { toPositiveInteger } = require('./queue-delivery');
2
-
3
- const MAX_DEFERRALS = 30;
4
- const MAX_DEFERRED_MS = 26 * 60 * 60 * 1000;
5
- const MAX_DELAY_SECONDS = 900;
6
- const MAX_VISIBILITY_TIMEOUT_SECONDS = 43_200;
7
- const MAX_LAMBDA_RUN_SECONDS = 900;
8
- const MAX_BATCHING_WINDOW_SECONDS = 300;
9
- const MAX_DEFERRED_VISIBILITY_SECONDS =
10
- MAX_VISIBILITY_TIMEOUT_SECONDS -
11
- MAX_LAMBDA_RUN_SECONDS -
12
- MAX_BATCHING_WINDOW_SECONDS;
13
- const MAX_DEFERRALS_ENV = 'FRIGG_QUEUE_MAX_DEFERRALS';
14
- const MAX_DEFERRED_MS_ENV = 'FRIGG_QUEUE_MAX_DEFERRED_MS';
15
-
16
- const readDeferralLimits = (env = process.env) => ({
17
- maxDeferrals: toPositiveInteger(env[MAX_DEFERRALS_ENV]) ?? MAX_DEFERRALS,
18
- maxDeferredMs:
19
- toPositiveInteger(env[MAX_DEFERRED_MS_ENV]) ?? MAX_DEFERRED_MS,
20
- });
21
-
22
- const readDeferral = (body) => {
23
- const frigg = body?._frigg;
24
- const deferrals =
25
- Number.isInteger(frigg?.deferrals) && frigg.deferrals > 0
26
- ? frigg.deferrals
27
- : 0;
28
- const firstDeferredAt =
29
- typeof frigg?.firstDeferredAt === 'string' &&
30
- !Number.isNaN(Date.parse(frigg.firstDeferredAt))
31
- ? frigg.firstDeferredAt
32
- : undefined;
33
- const deferralId =
34
- typeof frigg?.deferralId === 'string' && frigg.deferralId !== ''
35
- ? frigg.deferralId
36
- : undefined;
37
- return { deferrals, firstDeferredAt, deferralId };
38
- };
39
-
40
- const nextDeferral = (body, now = Date.now(), messageId) => {
41
- const current = readDeferral(body);
42
- return {
43
- deferrals: current.deferrals + 1,
44
- firstDeferredAt: current.firstDeferredAt ?? new Date(now).toISOString(),
45
- deferralId: current.deferralId ?? messageId,
46
- };
47
- };
48
-
49
- const withDeferral = (body, deferral) => ({
50
- ...body,
51
- _frigg: { ...body._frigg, ...deferral },
52
- });
53
-
54
- const deferredMs = ({ firstDeferredAt, retryAt }) =>
55
- retryAt.getTime() - Date.parse(firstDeferredAt);
56
-
57
- const isDeferralCapped = (deferral, { maxDeferrals, maxDeferredMs }) =>
58
- deferral.deferrals > maxDeferrals || deferredMs(deferral) > maxDeferredMs;
59
-
60
- module.exports = {
61
- MAX_DEFERRALS,
62
- MAX_DEFERRALS_ENV,
63
- MAX_DEFERRED_MS,
64
- MAX_DEFERRED_MS_ENV,
65
- MAX_DEFERRED_VISIBILITY_SECONDS,
66
- MAX_DELAY_SECONDS,
67
- MAX_VISIBILITY_TIMEOUT_SECONDS,
68
- deferredMs,
69
- isDeferralCapped,
70
- nextDeferral,
71
- readDeferral,
72
- readDeferralLimits,
73
- withDeferral,
74
- };