@casual-simulation/aux-records 3.4.6-alpha.14601027727 → 3.5.0-alpha.15117651144
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/AIController.js +835 -890
- package/AIController.js.map +1 -1
- package/AIHumeInterface.js +43 -54
- package/AIHumeInterface.js.map +1 -1
- package/AIOpenAIRealtimeInterface.js +60 -71
- package/AIOpenAIRealtimeInterface.js.map +1 -1
- package/AnthropicAIChatInterface.js +96 -142
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +3 -2
- package/AuthController.js +1907 -1933
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -10
- package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.js +30 -45
- package/CachingConfigStore.js.map +1 -1
- package/CachingPolicyStore.d.ts +8 -2
- package/CachingPolicyStore.js +108 -135
- package/CachingPolicyStore.js.map +1 -1
- package/ComIdConfig.d.ts +18 -18
- package/ComIdConfig.js.map +1 -1
- package/ConsoleAuthMessenger.js +7 -20
- package/ConsoleAuthMessenger.js.map +1 -1
- package/DataRecordsController.d.ts +2 -2
- package/DataRecordsController.js +369 -377
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/DataRecordsStore.js +1 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.js +226 -240
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -2
- package/FileRecordsController.js +458 -450
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +133 -179
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +43 -54
- package/LivekitController.js.map +1 -1
- package/LoomController.js +64 -75
- package/LoomController.js.map +1 -1
- package/MemoryAuthMessenger.js +10 -23
- package/MemoryAuthMessenger.js.map +1 -1
- package/MemoryCache.js +18 -35
- package/MemoryCache.js.map +1 -1
- package/MemoryFileRecordsLookup.js +105 -125
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryModerationJobProvider.js +17 -30
- package/MemoryModerationJobProvider.js.map +1 -1
- package/MemoryRateLimiter.js +12 -27
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +18 -6
- package/MemoryStore.js +1879 -1997
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +2 -2
- package/ModerationController.js +186 -200
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +105 -135
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +57 -51
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +150 -10
- package/PolicyController.js +1546 -1299
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +110 -2
- package/PolicyStore.js +36 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.js +398 -435
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +25 -36
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.js +51 -74
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +2 -42
- package/RecordsController.js +1026 -1182
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +196 -27
- package/RecordsServer.js +1701 -1343
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +1 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +339 -195
- package/ServerConfig.js +13 -0
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +62 -75
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +150 -167
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +6 -1
- package/SubscriptionConfigBuilder.js +22 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +266 -169
- package/SubscriptionConfiguration.js +101 -79
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +2 -1
- package/SubscriptionController.js +643 -650
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +21 -4
- package/SystemNotificationMessenger.js +36 -30
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +9 -1
- package/TestUtils.js +105 -129
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +2 -16
- package/Utils.js +21 -22
- package/Utils.js.map +1 -1
- package/crud/CrudHelpers.js +17 -26
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +1 -1
- package/crud/CrudRecordsController.js +259 -267
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.js +174 -185
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/CrudRecordsStore.d.ts +7 -3
- package/crud/MemoryCrudRecordsStore.d.ts +4 -4
- package/crud/MemoryCrudRecordsStore.js +98 -118
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
- package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
- package/crud/sub/SubCrudRecordsController.d.ts +182 -0
- package/crud/sub/SubCrudRecordsController.js +360 -0
- package/crud/sub/SubCrudRecordsController.js.map +1 -0
- package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
- package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
- package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
- package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
- package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
- package/crud/sub/SubCrudRecordsStore.js.map +1 -0
- package/crud/sub/index.d.ts +3 -0
- package/crud/sub/index.js +20 -0
- package/{forms → crud/sub}/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/notifications/MemoryNotificationRecordsStore.js +189 -198
- package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
- package/notifications/NotificationRecordsController.js +438 -460
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/NotificationRecordsStore.d.ts +2 -1
- package/notifications/WebPushInterface.d.ts +0 -1
- package/notifications/WebPushInterface.js +0 -1
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +6 -6
- package/packages/MemoryPackageRecordsStore.d.ts +10 -0
- package/packages/MemoryPackageRecordsStore.js +38 -0
- package/packages/MemoryPackageRecordsStore.js.map +1 -0
- package/packages/PackageRecordsController.d.ts +26 -0
- package/packages/PackageRecordsController.js +49 -0
- package/packages/PackageRecordsController.js.map +1 -0
- package/packages/PackageRecordsStore.d.ts +32 -0
- package/packages/PackageRecordsStore.js +19 -0
- package/packages/PackageRecordsStore.js.map +1 -0
- package/packages/index.d.ts +4 -0
- package/packages/index.js +21 -0
- package/packages/index.js.map +1 -0
- package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
- package/packages/version/PackageVersionRecordsController.d.ts +144 -0
- package/packages/version/PackageVersionRecordsController.js +656 -0
- package/packages/version/PackageVersionRecordsController.js.map +1 -0
- package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
- package/packages/version/PackageVersionRecordsStore.js +126 -0
- package/packages/version/PackageVersionRecordsStore.js.map +1 -0
- package/packages/version/index.d.ts +4 -0
- package/packages/version/index.js +21 -0
- package/packages/version/index.js.map +1 -0
- package/tracing/TracingDecorators.js +31 -40
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/MemoryWebhookRecordsStore.js +56 -72
- package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +3 -3
- package/webhooks/WebhookRecordsController.d.ts +2 -1
- package/webhooks/WebhookRecordsController.js +389 -382
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/webhooks/WebhookRecordsStore.d.ts +2 -1
- package/websockets/InstRecordsStore.d.ts +50 -0
- package/websockets/InstRecordsStore.js +17 -0
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
- package/websockets/MemoryTempInstRecordsStore.js +168 -179
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +98 -135
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +29 -48
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.d.ts +4 -1
- package/websockets/SplitInstRecordsStore.js +167 -185
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
- package/websockets/TemporaryInstRecordsStore.js +17 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +147 -3
- package/websockets/WebsocketController.js +1735 -1391
- package/websockets/WebsocketController.js.map +1 -1
- package/websockets/index.d.ts +0 -1
- package/websockets/index.js +0 -1
- package/websockets/index.js.map +1 -1
- package/AAGUID.d.ts +0 -11
- package/AAGUID.js +0 -116
- package/AAGUID.js.map +0 -1
- package/AuthUtils.d.ts +0 -162
- package/AuthUtils.js +0 -327
- package/AuthUtils.js.map +0 -1
- package/forms/FormError.d.ts +0 -43
- package/forms/FormError.js +0 -56
- package/forms/FormError.js.map +0 -1
- package/forms/index.d.ts +0 -2
- package/websockets/Utils.d.ts +0 -33
- package/websockets/Utils.js +0 -82
- package/websockets/Utils.js.map +0 -1
|
@@ -4,22 +4,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
import { DEFAULT_BRANCH_NAME, } from '@casual-simulation/aux-common';
|
|
17
|
-
import { CrudRecordsController, } from '../crud/CrudRecordsController';
|
|
7
|
+
import { DEFAULT_BRANCH_NAME, tryParseJson, } from '@casual-simulation/aux-common';
|
|
8
|
+
import { CrudRecordsController } from '../crud/CrudRecordsController';
|
|
18
9
|
import { getWebhookFeatures } from '../SubscriptionConfiguration';
|
|
19
10
|
import { traced } from '../tracing/TracingDecorators';
|
|
20
11
|
import { SpanStatusCode, trace } from '@opentelemetry/api';
|
|
21
|
-
import { STORED_AUX_SCHEMA
|
|
22
|
-
import { tryParseJson } from '../Utils';
|
|
12
|
+
import { STORED_AUX_SCHEMA } from './WebhookEnvironment';
|
|
23
13
|
import { v7 as uuidv7 } from 'uuid';
|
|
24
14
|
import stringify from '@casual-simulation/fast-json-stable-stringify';
|
|
25
15
|
import { sha256 } from 'hash.js';
|
|
@@ -34,7 +24,11 @@ export class WebhookRecordsController extends CrudRecordsController {
|
|
|
34
24
|
return this._websockets;
|
|
35
25
|
}
|
|
36
26
|
constructor(config) {
|
|
37
|
-
super(
|
|
27
|
+
super({
|
|
28
|
+
...config,
|
|
29
|
+
resourceKind: 'webhook',
|
|
30
|
+
name: 'WebhookRecordsController',
|
|
31
|
+
});
|
|
38
32
|
this._environment = config.environment;
|
|
39
33
|
this._data = config.data;
|
|
40
34
|
this._files = config.files;
|
|
@@ -45,433 +39,446 @@ export class WebhookRecordsController extends CrudRecordsController {
|
|
|
45
39
|
* Handles a webhook request.
|
|
46
40
|
* @param request The request to handle.
|
|
47
41
|
*/
|
|
48
|
-
handleWebhook(request) {
|
|
49
|
-
var _a, _b, _c, _d, _e;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
async handleWebhook(request) {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
44
|
+
try {
|
|
45
|
+
const requestTimeMs = Date.now();
|
|
46
|
+
const webhookContext = await this.policies.constructAuthorizationContext({
|
|
47
|
+
recordKeyOrRecordName: request.recordName,
|
|
48
|
+
userId: request.userId,
|
|
49
|
+
});
|
|
50
|
+
if (webhookContext.success === false) {
|
|
51
|
+
return webhookContext;
|
|
52
|
+
}
|
|
53
|
+
const recordName = webhookContext.context.recordName;
|
|
54
|
+
const webhook = await this.store.getItemByAddress(recordName, request.address);
|
|
55
|
+
if (!webhook) {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
errorCode: 'not_found',
|
|
59
|
+
errorMessage: 'Webhook not found.',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const webhookAuthorization = await this.policies.authorizeUserAndInstancesForResources(webhookContext.context, {
|
|
63
|
+
instances: request.instances,
|
|
64
|
+
userId: request.userId,
|
|
65
|
+
resources: [
|
|
66
|
+
{
|
|
67
|
+
resourceKind: 'webhook',
|
|
68
|
+
resourceId: webhook.address,
|
|
69
|
+
action: 'run',
|
|
70
|
+
markers: webhook.markers,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
if (webhookAuthorization.success === false) {
|
|
75
|
+
return webhookAuthorization;
|
|
76
|
+
}
|
|
77
|
+
const checkMetrics = await this._checkSubscriptionMetrics('run', webhookContext.context, webhookAuthorization, webhook);
|
|
78
|
+
if (checkMetrics.success === false) {
|
|
79
|
+
return checkMetrics;
|
|
80
|
+
}
|
|
81
|
+
let state;
|
|
82
|
+
const stateRecordName = webhook.targetRecordName;
|
|
83
|
+
let stateInstName = undefined;
|
|
84
|
+
if (webhook.targetResourceKind === 'data') {
|
|
85
|
+
if (!webhook.targetRecordName) {
|
|
63
86
|
return {
|
|
64
87
|
success: false,
|
|
65
|
-
errorCode: '
|
|
66
|
-
errorMessage: '
|
|
88
|
+
errorCode: 'invalid_webhook_target',
|
|
89
|
+
errorMessage: 'Invalid webhook target. The targeted record does not contain a valid name.',
|
|
67
90
|
};
|
|
68
91
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
action: 'run',
|
|
77
|
-
markers: webhook.markers,
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
});
|
|
81
|
-
if (webhookAuthorization.success === false) {
|
|
82
|
-
return webhookAuthorization;
|
|
83
|
-
}
|
|
84
|
-
const checkMetrics = yield this._checkSubscriptionMetrics('run', webhookContext.context, webhookAuthorization, webhook);
|
|
85
|
-
if (checkMetrics.success === false) {
|
|
86
|
-
return checkMetrics;
|
|
87
|
-
}
|
|
88
|
-
let state = null;
|
|
89
|
-
const stateRecordName = webhook.targetRecordName;
|
|
90
|
-
let stateInstName = undefined;
|
|
91
|
-
if (webhook.targetResourceKind === 'data') {
|
|
92
|
-
const data = yield this._data.getData(webhook.targetRecordName, webhook.targetAddress, webhook.userId, request.instances);
|
|
93
|
-
if (data.success === false) {
|
|
94
|
-
return {
|
|
95
|
-
success: false,
|
|
96
|
-
errorCode: 'invalid_webhook_target',
|
|
97
|
-
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
98
|
-
internalError: data,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
let auxData;
|
|
102
|
-
if (typeof data.data === 'string') {
|
|
103
|
-
const stored = tryParseJson(data.data);
|
|
104
|
-
if (stored.success === true) {
|
|
105
|
-
auxData = stored.value;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (typeof data.data === 'object') {
|
|
109
|
-
auxData = data.data;
|
|
110
|
-
}
|
|
111
|
-
const parseResult = STORED_AUX_SCHEMA.safeParse(auxData);
|
|
112
|
-
if (parseResult.success === false) {
|
|
113
|
-
return {
|
|
114
|
-
success: false,
|
|
115
|
-
errorCode: 'invalid_webhook_target',
|
|
116
|
-
errorMessage: 'Invalid webhook target. The targeted record does not contain valid data.',
|
|
117
|
-
internalError: {
|
|
118
|
-
success: false,
|
|
119
|
-
errorCode: 'unacceptable_request',
|
|
120
|
-
errorMessage: 'The data record does not contain valid AUX data.',
|
|
121
|
-
issues: parseResult.error.issues,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
state = {
|
|
126
|
-
type: 'aux',
|
|
127
|
-
state: parseResult.data,
|
|
92
|
+
const data = await this._data.getData(webhook.targetRecordName, webhook.targetAddress, webhook.userId, request.instances);
|
|
93
|
+
if (data.success === false) {
|
|
94
|
+
return {
|
|
95
|
+
success: false,
|
|
96
|
+
errorCode: 'invalid_webhook_target',
|
|
97
|
+
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
98
|
+
internalError: data,
|
|
128
99
|
};
|
|
129
100
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
errorCode: 'invalid_webhook_target',
|
|
136
|
-
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
137
|
-
internalError: file,
|
|
138
|
-
};
|
|
101
|
+
let auxData;
|
|
102
|
+
if (typeof data.data === 'string') {
|
|
103
|
+
const stored = tryParseJson(data.data);
|
|
104
|
+
if (stored.success === true) {
|
|
105
|
+
auxData = stored.value;
|
|
139
106
|
}
|
|
140
|
-
state = {
|
|
141
|
-
type: 'url',
|
|
142
|
-
requestUrl: file.requestUrl,
|
|
143
|
-
requestMethod: file.requestMethod,
|
|
144
|
-
requestHeaders: file.requestHeaders,
|
|
145
|
-
};
|
|
146
107
|
}
|
|
147
|
-
else if (
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
success: false,
|
|
151
|
-
errorCode: 'invalid_webhook_target',
|
|
152
|
-
errorMessage: 'Invalid webhook target. Inst records are not supported in this environment.',
|
|
153
|
-
internalError: {
|
|
154
|
-
success: false,
|
|
155
|
-
errorCode: 'not_supported',
|
|
156
|
-
errorMessage: 'Inst records are not supported in this environment.',
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const inst = yield this._websockets.getBranchData(webhook.userId, webhook.targetRecordName, webhook.targetAddress, DEFAULT_BRANCH_NAME, 2);
|
|
161
|
-
if (inst.success === false) {
|
|
162
|
-
return {
|
|
163
|
-
success: false,
|
|
164
|
-
errorCode: 'invalid_webhook_target',
|
|
165
|
-
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
166
|
-
internalError: inst,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
stateInstName = webhook.targetAddress;
|
|
170
|
-
state = {
|
|
171
|
-
type: 'aux',
|
|
172
|
-
state: inst.data,
|
|
173
|
-
};
|
|
108
|
+
else if (typeof data.data === 'object') {
|
|
109
|
+
auxData = data.data;
|
|
174
110
|
}
|
|
175
|
-
|
|
111
|
+
const parseResult = STORED_AUX_SCHEMA.safeParse(auxData);
|
|
112
|
+
if (parseResult.success === false) {
|
|
176
113
|
return {
|
|
177
114
|
success: false,
|
|
178
115
|
errorCode: 'invalid_webhook_target',
|
|
179
|
-
errorMessage: 'Invalid webhook target. The targeted record does not contain
|
|
116
|
+
errorMessage: 'Invalid webhook target. The targeted record does not contain valid data.',
|
|
117
|
+
internalError: {
|
|
118
|
+
success: false,
|
|
119
|
+
errorCode: 'unacceptable_request',
|
|
120
|
+
errorMessage: 'The data record does not contain valid AUX data.',
|
|
121
|
+
issues: parseResult.error.issues,
|
|
122
|
+
},
|
|
180
123
|
};
|
|
181
124
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (webhook.userId) {
|
|
186
|
-
// Create a session for the user
|
|
187
|
-
const issueSessionResult = yield this._auth.issueSession({
|
|
188
|
-
userId: webhook.userId,
|
|
189
|
-
requestingUserId: null,
|
|
190
|
-
requestingUserRole: 'system',
|
|
191
|
-
ipAddress: null,
|
|
192
|
-
lifetimeMs: (_a = checkMetrics.features.tokenLifetimeMs) !== null && _a !== void 0 ? _a : 5 * 60 * 1000,
|
|
193
|
-
});
|
|
194
|
-
if (issueSessionResult.success === true) {
|
|
195
|
-
sessionUserId = issueSessionResult.userId;
|
|
196
|
-
sessionKey = issueSessionResult.sessionKey;
|
|
197
|
-
connectionKey = issueSessionResult.connectionKey;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
console.warn('[WebhookRecordsController] Error issuing session for webhook:', issueSessionResult);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
const options = {
|
|
204
|
-
initTimeoutMs: (_b = checkMetrics.features.initTimeoutMs) !== null && _b !== void 0 ? _b : 5000,
|
|
205
|
-
requestTimeoutMs: (_c = checkMetrics.features.requestTimeoutMs) !== null && _c !== void 0 ? _c : 5000,
|
|
206
|
-
fetchTimeoutMs: (_d = checkMetrics.features.fetchTimeoutMs) !== null && _d !== void 0 ? _d : 5000,
|
|
207
|
-
addStateTimeoutMs: (_e = checkMetrics.features.addStateTimeoutMs) !== null && _e !== void 0 ? _e : 1000,
|
|
125
|
+
state = {
|
|
126
|
+
type: 'aux',
|
|
127
|
+
state: parseResult.data,
|
|
208
128
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
sessionKey,
|
|
217
|
-
connectionKey,
|
|
218
|
-
options,
|
|
219
|
-
});
|
|
220
|
-
const responseTimeMs = Date.now();
|
|
221
|
-
const stateHash = getHash(state);
|
|
222
|
-
const runId = uuidv7();
|
|
223
|
-
let infoFileName = null;
|
|
224
|
-
let infoRecordName = null;
|
|
225
|
-
if (webhook.userId) {
|
|
226
|
-
const recordName = webhook.userId;
|
|
227
|
-
const dataFile = {
|
|
228
|
-
runId,
|
|
229
|
-
version: 1,
|
|
230
|
-
request: request.request,
|
|
231
|
-
requestUserId: request.userId,
|
|
232
|
-
response: result.success === true ? result.response : null,
|
|
233
|
-
logs: result.success === true ? result.logs : [],
|
|
234
|
-
state,
|
|
235
|
-
stateSha256: stateHash,
|
|
236
|
-
authorization: webhookAuthorization,
|
|
129
|
+
}
|
|
130
|
+
else if (webhook.targetResourceKind === 'file') {
|
|
131
|
+
if (!webhook.targetRecordName) {
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
errorCode: 'invalid_webhook_target',
|
|
135
|
+
errorMessage: 'Invalid webhook target. The targeted record does not contain a valid name.',
|
|
237
136
|
};
|
|
238
|
-
const json = stringify(dataFile);
|
|
239
|
-
const data = new TextEncoder().encode(json);
|
|
240
|
-
const recordResult = yield this._files.recordFile(recordName, recordName, {
|
|
241
|
-
fileSha256Hex: sha256().update(data).digest('hex'),
|
|
242
|
-
fileByteLength: data.byteLength,
|
|
243
|
-
fileDescription: `Webhook data for run ${runId}`,
|
|
244
|
-
fileMimeType: 'application/json',
|
|
245
|
-
headers: {},
|
|
246
|
-
markers: [`private:logs`],
|
|
247
|
-
});
|
|
248
|
-
if (recordResult.success === false) {
|
|
249
|
-
console.error('[WebhookRecordsController] Error recording webhook info file:', recordResult);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
infoRecordName = recordName;
|
|
253
|
-
infoFileName = recordResult.fileName;
|
|
254
|
-
const requestResult = yield axios.request({
|
|
255
|
-
method: recordResult.uploadMethod,
|
|
256
|
-
headers: recordResult.uploadHeaders,
|
|
257
|
-
url: recordResult.uploadUrl,
|
|
258
|
-
data: data,
|
|
259
|
-
validateStatus: () => true,
|
|
260
|
-
});
|
|
261
|
-
if (requestResult.status <= 199 ||
|
|
262
|
-
requestResult.status >= 300) {
|
|
263
|
-
console.error('[WebhookRecordsController] Error uploading webhook info file:', requestResult);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
137
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
recordName: recordName,
|
|
270
|
-
webhookAddress: request.address,
|
|
271
|
-
errorResult: result.success === false ? result : null,
|
|
272
|
-
requestTimeMs,
|
|
273
|
-
responseTimeMs,
|
|
274
|
-
statusCode: result.success === true ? result.response.statusCode : null,
|
|
275
|
-
stateSha256: stateHash,
|
|
276
|
-
infoRecordName,
|
|
277
|
-
infoFileName,
|
|
278
|
-
options,
|
|
279
|
-
};
|
|
280
|
-
yield this.store.recordWebhookRun(run);
|
|
281
|
-
if (result.success === true) {
|
|
138
|
+
const file = await this._files.readFile(webhook.targetRecordName, webhook.targetAddress, (_a = webhook.userId) !== null && _a !== void 0 ? _a : null, request.instances);
|
|
139
|
+
if (file.success === false) {
|
|
282
140
|
return {
|
|
283
|
-
success:
|
|
284
|
-
|
|
141
|
+
success: false,
|
|
142
|
+
errorCode: 'invalid_webhook_target',
|
|
143
|
+
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
144
|
+
internalError: file,
|
|
285
145
|
};
|
|
286
146
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const span = trace.getActiveSpan();
|
|
293
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
294
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
295
|
-
console.error('[WebhookRecordsController] Error handling webhook:', err);
|
|
296
|
-
return {
|
|
297
|
-
success: false,
|
|
298
|
-
errorCode: 'server_error',
|
|
299
|
-
errorMessage: 'A server error occurred.',
|
|
147
|
+
state = {
|
|
148
|
+
type: 'url',
|
|
149
|
+
requestUrl: file.requestUrl,
|
|
150
|
+
requestMethod: file.requestMethod,
|
|
151
|
+
requestHeaders: file.requestHeaders,
|
|
300
152
|
};
|
|
301
153
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
listWebhookRuns(request) {
|
|
305
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
try {
|
|
307
|
-
const context = yield this.policies.constructAuthorizationContext({
|
|
308
|
-
userId: request.userId,
|
|
309
|
-
recordKeyOrRecordName: request.recordName,
|
|
310
|
-
});
|
|
311
|
-
if (context.success === false) {
|
|
312
|
-
return context;
|
|
313
|
-
}
|
|
314
|
-
const recordName = context.context.recordName;
|
|
315
|
-
const webhook = yield this.store.getItemByAddress(recordName, request.address);
|
|
316
|
-
if (!webhook) {
|
|
154
|
+
else if (webhook.targetResourceKind === 'inst') {
|
|
155
|
+
if (!this._websockets) {
|
|
317
156
|
return {
|
|
318
157
|
success: false,
|
|
319
|
-
errorCode: '
|
|
320
|
-
errorMessage: '
|
|
158
|
+
errorCode: 'invalid_webhook_target',
|
|
159
|
+
errorMessage: 'Invalid webhook target. Inst records are not supported in this environment.',
|
|
160
|
+
internalError: {
|
|
161
|
+
success: false,
|
|
162
|
+
errorCode: 'not_supported',
|
|
163
|
+
errorMessage: 'Inst records are not supported in this environment.',
|
|
164
|
+
},
|
|
321
165
|
};
|
|
322
166
|
}
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
markers: webhook.markers,
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
});
|
|
335
|
-
if (authorization.success === false) {
|
|
336
|
-
return authorization;
|
|
167
|
+
const inst = await this._websockets.getBranchData((_b = webhook.userId) !== null && _b !== void 0 ? _b : null, webhook.targetRecordName, webhook.targetAddress, DEFAULT_BRANCH_NAME, 2);
|
|
168
|
+
if (inst.success === false) {
|
|
169
|
+
return {
|
|
170
|
+
success: false,
|
|
171
|
+
errorCode: 'invalid_webhook_target',
|
|
172
|
+
errorMessage: 'Invalid webhook target. The targeted record was not able to be retrieved.',
|
|
173
|
+
internalError: inst,
|
|
174
|
+
};
|
|
337
175
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
items: runs.items,
|
|
343
|
-
totalCount: runs.totalCount,
|
|
344
|
-
marker: runs.marker,
|
|
176
|
+
stateInstName = webhook.targetAddress;
|
|
177
|
+
state = {
|
|
178
|
+
type: 'aux',
|
|
179
|
+
state: inst.data,
|
|
345
180
|
};
|
|
346
181
|
}
|
|
347
|
-
|
|
348
|
-
const span = trace.getActiveSpan();
|
|
349
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
350
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
351
|
-
console.error('[WebhookRecordsController] Error listing webhook runs:', err);
|
|
182
|
+
else {
|
|
352
183
|
return {
|
|
353
184
|
success: false,
|
|
354
|
-
errorCode: '
|
|
355
|
-
errorMessage: '
|
|
185
|
+
errorCode: 'invalid_webhook_target',
|
|
186
|
+
errorMessage: 'Invalid webhook target. The targeted record does not contain a valid AUX.',
|
|
356
187
|
};
|
|
357
188
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
const context = yield this.policies.constructAuthorizationContext({
|
|
372
|
-
userId: request.userId,
|
|
373
|
-
recordKeyOrRecordName: run.run.recordName,
|
|
189
|
+
let sessionUserId = undefined;
|
|
190
|
+
let sessionKey = undefined;
|
|
191
|
+
let connectionKey = undefined;
|
|
192
|
+
if (webhook.userId) {
|
|
193
|
+
// Create a session for the user
|
|
194
|
+
const issueSessionResult = await this._auth.issueSession({
|
|
195
|
+
userId: webhook.userId,
|
|
196
|
+
requestingUserId: null,
|
|
197
|
+
requestingUserRole: 'system',
|
|
198
|
+
ipAddress: null,
|
|
199
|
+
lifetimeMs: (_c = checkMetrics.features.tokenLifetimeMs) !== null && _c !== void 0 ? _c : 5 * 60 * 1000,
|
|
374
200
|
});
|
|
375
|
-
if (
|
|
376
|
-
|
|
201
|
+
if (issueSessionResult.success === true) {
|
|
202
|
+
sessionUserId = issueSessionResult.userId;
|
|
203
|
+
sessionKey = issueSessionResult.sessionKey;
|
|
204
|
+
connectionKey = issueSessionResult.connectionKey;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.warn('[WebhookRecordsController] Error issuing session for webhook:', issueSessionResult);
|
|
377
208
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
209
|
+
}
|
|
210
|
+
const options = {
|
|
211
|
+
initTimeoutMs: (_d = checkMetrics.features.initTimeoutMs) !== null && _d !== void 0 ? _d : 5000,
|
|
212
|
+
requestTimeoutMs: (_e = checkMetrics.features.requestTimeoutMs) !== null && _e !== void 0 ? _e : 5000,
|
|
213
|
+
fetchTimeoutMs: (_f = checkMetrics.features.fetchTimeoutMs) !== null && _f !== void 0 ? _f : 5000,
|
|
214
|
+
addStateTimeoutMs: (_g = checkMetrics.features.addStateTimeoutMs) !== null && _g !== void 0 ? _g : 1000,
|
|
215
|
+
};
|
|
216
|
+
const result = await this._environment.handleHttpRequest({
|
|
217
|
+
state: state,
|
|
218
|
+
recordName: stateRecordName,
|
|
219
|
+
inst: stateInstName,
|
|
220
|
+
request: request.request,
|
|
221
|
+
requestUserId: request.userId,
|
|
222
|
+
sessionUserId,
|
|
223
|
+
sessionKey,
|
|
224
|
+
connectionKey,
|
|
225
|
+
options,
|
|
226
|
+
});
|
|
227
|
+
const responseTimeMs = Date.now();
|
|
228
|
+
const stateHash = getHash(state);
|
|
229
|
+
const runId = uuidv7();
|
|
230
|
+
let infoFileName = null;
|
|
231
|
+
let infoRecordName = null;
|
|
232
|
+
if (webhook.userId) {
|
|
233
|
+
const recordName = webhook.userId;
|
|
234
|
+
const dataFile = {
|
|
235
|
+
runId,
|
|
236
|
+
version: 1,
|
|
237
|
+
request: request.request,
|
|
238
|
+
requestUserId: request.userId,
|
|
239
|
+
response: result.success === true ? result.response : null,
|
|
240
|
+
logs: result.success === true ? result.logs : [],
|
|
241
|
+
state,
|
|
242
|
+
stateSha256: stateHash,
|
|
243
|
+
authorization: webhookAuthorization,
|
|
244
|
+
};
|
|
245
|
+
const json = stringify(dataFile);
|
|
246
|
+
const data = new TextEncoder().encode(json);
|
|
247
|
+
const recordResult = await this._files.recordFile(recordName, recordName, {
|
|
248
|
+
fileSha256Hex: sha256().update(data).digest('hex'),
|
|
249
|
+
fileByteLength: data.byteLength,
|
|
250
|
+
fileDescription: `Webhook data for run ${runId}`,
|
|
251
|
+
fileMimeType: 'application/json',
|
|
252
|
+
headers: {},
|
|
253
|
+
markers: [`private:logs`],
|
|
385
254
|
});
|
|
386
|
-
if (
|
|
387
|
-
|
|
255
|
+
if (recordResult.success === false) {
|
|
256
|
+
console.error('[WebhookRecordsController] Error recording webhook info file:', recordResult);
|
|
388
257
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
258
|
+
else {
|
|
259
|
+
infoRecordName = recordName;
|
|
260
|
+
infoFileName = recordResult.fileName;
|
|
261
|
+
const requestResult = await axios.request({
|
|
262
|
+
method: recordResult.uploadMethod,
|
|
263
|
+
headers: recordResult.uploadHeaders,
|
|
264
|
+
url: recordResult.uploadUrl,
|
|
265
|
+
data: data,
|
|
266
|
+
validateStatus: () => true,
|
|
267
|
+
});
|
|
268
|
+
if (requestResult.status <= 199 ||
|
|
269
|
+
requestResult.status >= 300) {
|
|
270
|
+
console.error('[WebhookRecordsController] Error uploading webhook info file:', requestResult);
|
|
271
|
+
}
|
|
392
272
|
}
|
|
273
|
+
}
|
|
274
|
+
const run = {
|
|
275
|
+
runId: uuidv7(),
|
|
276
|
+
recordName: recordName,
|
|
277
|
+
webhookAddress: request.address,
|
|
278
|
+
errorResult: result.success === false ? result : null,
|
|
279
|
+
requestTimeMs,
|
|
280
|
+
responseTimeMs,
|
|
281
|
+
statusCode: result.success === true ? result.response.statusCode : null,
|
|
282
|
+
stateSha256: stateHash,
|
|
283
|
+
infoRecordName,
|
|
284
|
+
infoFileName,
|
|
285
|
+
options,
|
|
286
|
+
};
|
|
287
|
+
await this.store.recordWebhookRun(run);
|
|
288
|
+
if (result.success === true) {
|
|
393
289
|
return {
|
|
394
290
|
success: true,
|
|
395
|
-
|
|
396
|
-
infoFileResult,
|
|
291
|
+
response: result.response,
|
|
397
292
|
};
|
|
398
293
|
}
|
|
399
|
-
|
|
400
|
-
|
|
294
|
+
else {
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
const span = trace.getActiveSpan();
|
|
300
|
+
if (err instanceof Error) {
|
|
401
301
|
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
402
|
-
|
|
403
|
-
|
|
302
|
+
}
|
|
303
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
304
|
+
console.error('[WebhookRecordsController] Error handling webhook:', err);
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
errorCode: 'server_error',
|
|
308
|
+
errorMessage: 'A server error occurred.',
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async listWebhookRuns(request) {
|
|
313
|
+
try {
|
|
314
|
+
const context = await this.policies.constructAuthorizationContext({
|
|
315
|
+
userId: request.userId,
|
|
316
|
+
recordKeyOrRecordName: request.recordName,
|
|
317
|
+
});
|
|
318
|
+
if (context.success === false) {
|
|
319
|
+
return context;
|
|
320
|
+
}
|
|
321
|
+
const recordName = context.context.recordName;
|
|
322
|
+
const webhook = await this.store.getItemByAddress(recordName, request.address);
|
|
323
|
+
if (!webhook) {
|
|
404
324
|
return {
|
|
405
325
|
success: false,
|
|
406
|
-
errorCode: '
|
|
407
|
-
errorMessage: '
|
|
326
|
+
errorCode: 'data_not_found',
|
|
327
|
+
errorMessage: 'The webhook was not found.',
|
|
408
328
|
};
|
|
409
329
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
330
|
+
const authorization = await this.policies.authorizeUserAndInstancesForResources(context.context, {
|
|
331
|
+
instances: request.instances,
|
|
332
|
+
userId: context.context.userId,
|
|
333
|
+
resources: [
|
|
334
|
+
{
|
|
335
|
+
resourceKind: 'webhook',
|
|
336
|
+
resourceId: webhook.address,
|
|
337
|
+
action: 'read',
|
|
338
|
+
markers: webhook.markers,
|
|
339
|
+
},
|
|
340
|
+
],
|
|
418
341
|
});
|
|
419
|
-
|
|
420
|
-
|
|
342
|
+
if (authorization.success === false) {
|
|
343
|
+
return authorization;
|
|
344
|
+
}
|
|
345
|
+
const runs = await this.store.listWebhookRunsForWebhook(recordName, request.address, request.requestTimeMs);
|
|
346
|
+
return {
|
|
347
|
+
success: true,
|
|
348
|
+
recordName: recordName,
|
|
349
|
+
items: runs.items,
|
|
350
|
+
totalCount: runs.totalCount,
|
|
351
|
+
marker: runs.marker,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
const span = trace.getActiveSpan();
|
|
356
|
+
if (err instanceof Error) {
|
|
357
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
358
|
+
}
|
|
359
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
360
|
+
console.error('[WebhookRecordsController] Error listing webhook runs:', err);
|
|
361
|
+
return {
|
|
362
|
+
success: false,
|
|
363
|
+
errorCode: 'server_error',
|
|
364
|
+
errorMessage: 'A server error occurred.',
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async getWebhookRun(request) {
|
|
369
|
+
var _a;
|
|
370
|
+
try {
|
|
371
|
+
const run = await this.store.getWebhookRunInfo(request.runId);
|
|
372
|
+
if (!run) {
|
|
421
373
|
return {
|
|
422
374
|
success: false,
|
|
423
|
-
errorCode: '
|
|
424
|
-
errorMessage: '
|
|
375
|
+
errorCode: 'data_not_found',
|
|
376
|
+
errorMessage: 'The webhook run was not found.',
|
|
425
377
|
};
|
|
426
378
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
};
|
|
434
|
-
}
|
|
379
|
+
const context = await this.policies.constructAuthorizationContext({
|
|
380
|
+
userId: request.userId,
|
|
381
|
+
recordKeyOrRecordName: run.run.recordName,
|
|
382
|
+
});
|
|
383
|
+
if (context.success === false) {
|
|
384
|
+
return context;
|
|
435
385
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
item.userId = result.userId;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
386
|
+
const authorization = await this.policies.authorizeUserAndInstances(context.context, {
|
|
387
|
+
action: 'read',
|
|
388
|
+
resourceKind: 'webhook',
|
|
389
|
+
resourceId: run.webhook.address,
|
|
390
|
+
markers: run.webhook.markers,
|
|
391
|
+
instances: request.instances,
|
|
392
|
+
userId: context.context.userId,
|
|
393
|
+
});
|
|
394
|
+
if (authorization.success === false) {
|
|
395
|
+
return authorization;
|
|
451
396
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return {
|
|
456
|
-
success: false,
|
|
457
|
-
errorCode: 'subscription_limit_reached',
|
|
458
|
-
errorMessage: 'The maximum number of webhook runs has been reached for your subscription.',
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
if (typeof features.maxRunsPerHour === 'number' &&
|
|
462
|
-
metrics.totalRunsInLastHour >= features.maxRunsPerHour) {
|
|
463
|
-
return {
|
|
464
|
-
success: false,
|
|
465
|
-
errorCode: 'subscription_limit_reached',
|
|
466
|
-
errorMessage: 'The maximum number of webhook runs has been reached for your subscription.',
|
|
467
|
-
};
|
|
468
|
-
}
|
|
397
|
+
let infoFileResult = null;
|
|
398
|
+
if (run.run.infoRecordName && run.run.infoFileName) {
|
|
399
|
+
infoFileResult = await this._files.readFile(run.run.infoRecordName, run.run.infoFileName, (_a = run.webhook.userId) !== null && _a !== void 0 ? _a : null, request.instances);
|
|
469
400
|
}
|
|
470
401
|
return {
|
|
471
402
|
success: true,
|
|
472
|
-
|
|
403
|
+
run: run.run,
|
|
404
|
+
infoFileResult,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
const span = trace.getActiveSpan();
|
|
409
|
+
if (err instanceof Error) {
|
|
410
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
411
|
+
}
|
|
412
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
413
|
+
console.error('[WebhookRecordsController] Error getting webhook run:', err);
|
|
414
|
+
return {
|
|
415
|
+
success: false,
|
|
416
|
+
errorCode: 'server_error',
|
|
417
|
+
errorMessage: 'A server error occurred.',
|
|
473
418
|
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async _checkSubscriptionMetrics(action, context, authorization, item) {
|
|
422
|
+
const config = await this.config.getSubscriptionConfiguration();
|
|
423
|
+
const metrics = await this.store.getSubscriptionMetrics({
|
|
424
|
+
ownerId: context.recordOwnerId,
|
|
425
|
+
studioId: context.recordStudioId,
|
|
474
426
|
});
|
|
427
|
+
const features = getWebhookFeatures(config, metrics.subscriptionStatus, metrics.subscriptionId, metrics.subscriptionType);
|
|
428
|
+
if (!features.allowed) {
|
|
429
|
+
return {
|
|
430
|
+
success: false,
|
|
431
|
+
errorCode: 'not_authorized',
|
|
432
|
+
errorMessage: 'Webhooks are not allowed for this subscription.',
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
if (action === 'create' && typeof features.maxItems === 'number') {
|
|
436
|
+
if (metrics.totalItems >= features.maxItems) {
|
|
437
|
+
return {
|
|
438
|
+
success: false,
|
|
439
|
+
errorCode: 'subscription_limit_reached',
|
|
440
|
+
errorMessage: 'The maximum number of webhook items has been reached for your subscription.',
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (action === 'create') {
|
|
445
|
+
// create a user for the webhook
|
|
446
|
+
if (item && !item.userId) {
|
|
447
|
+
const result = await this._auth.createAccount({
|
|
448
|
+
userRole: 'superUser', // The system gets superUser permissions when performing administrative tasks
|
|
449
|
+
ipAddress: null,
|
|
450
|
+
createSession: false,
|
|
451
|
+
});
|
|
452
|
+
if (result.success === false) {
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
item.userId = result.userId;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (action === 'run') {
|
|
461
|
+
if (typeof features.maxRunsPerPeriod === 'number' &&
|
|
462
|
+
metrics.totalRunsInPeriod >= features.maxRunsPerPeriod) {
|
|
463
|
+
return {
|
|
464
|
+
success: false,
|
|
465
|
+
errorCode: 'subscription_limit_reached',
|
|
466
|
+
errorMessage: 'The maximum number of webhook runs has been reached for your subscription.',
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (typeof features.maxRunsPerHour === 'number' &&
|
|
470
|
+
metrics.totalRunsInLastHour >= features.maxRunsPerHour) {
|
|
471
|
+
return {
|
|
472
|
+
success: false,
|
|
473
|
+
errorCode: 'subscription_limit_reached',
|
|
474
|
+
errorMessage: 'The maximum number of webhook runs has been reached for your subscription.',
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
success: true,
|
|
480
|
+
features,
|
|
481
|
+
};
|
|
475
482
|
}
|
|
476
483
|
_transformInputItem(item) {
|
|
477
484
|
delete item.userId;
|