skedyul 1.7.17 → 1.7.21
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/dist/.build-stamp +1 -1
- package/dist/cli/index.js +77 -61
- package/dist/dedicated/server.js +77 -61
- package/dist/esm/index.mjs +77 -61
- package/dist/index.js +77 -61
- package/dist/server/handler-helpers.d.ts +7 -0
- package/dist/server.js +77 -61
- package/dist/serverless/server.mjs +77 -61
- package/package.json +1 -1
package/dist/.build-stamp
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1786331544611
|
package/dist/cli/index.js
CHANGED
|
@@ -3729,6 +3729,60 @@ function isProvisionConfig(value) {
|
|
|
3729
3729
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
3730
3730
|
}
|
|
3731
3731
|
|
|
3732
|
+
// src/server/handler-helpers.ts
|
|
3733
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
3734
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
3735
|
+
return null;
|
|
3736
|
+
}
|
|
3737
|
+
const envelope = parsedBody;
|
|
3738
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
3739
|
+
return null;
|
|
3740
|
+
}
|
|
3741
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
3742
|
+
return null;
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
env: envelope.env,
|
|
3746
|
+
request: envelope.request,
|
|
3747
|
+
context: envelope.context
|
|
3748
|
+
};
|
|
3749
|
+
}
|
|
3750
|
+
function buildRequestFromRaw(raw) {
|
|
3751
|
+
let parsedBody = raw.body;
|
|
3752
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
3753
|
+
if (contentType.includes("application/json")) {
|
|
3754
|
+
try {
|
|
3755
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
3756
|
+
} catch {
|
|
3757
|
+
parsedBody = raw.body;
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
return {
|
|
3761
|
+
method: raw.method,
|
|
3762
|
+
url: raw.url,
|
|
3763
|
+
path: raw.path,
|
|
3764
|
+
headers: raw.headers,
|
|
3765
|
+
query: raw.query,
|
|
3766
|
+
body: parsedBody,
|
|
3767
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
3768
|
+
};
|
|
3769
|
+
}
|
|
3770
|
+
function buildRequestScopedConfig(env) {
|
|
3771
|
+
return {
|
|
3772
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
3773
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
3774
|
+
};
|
|
3775
|
+
}
|
|
3776
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
3777
|
+
const originalEnv = { ...process.env };
|
|
3778
|
+
Object.assign(process.env, requestEnv);
|
|
3779
|
+
try {
|
|
3780
|
+
return await fn();
|
|
3781
|
+
} finally {
|
|
3782
|
+
process.env = originalEnv;
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
|
|
3732
3786
|
// src/server/handlers/install-handler.ts
|
|
3733
3787
|
async function handleInstall(body, hooks) {
|
|
3734
3788
|
if (!hooks?.install) {
|
|
@@ -3763,9 +3817,11 @@ async function handleInstall(body, hooks) {
|
|
|
3763
3817
|
try {
|
|
3764
3818
|
const installHook = hooks.install;
|
|
3765
3819
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
3766
|
-
const result = await
|
|
3820
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3767
3821
|
return await runWithConfig(requestConfig, async () => {
|
|
3768
|
-
return await
|
|
3822
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3823
|
+
return await installHandler(installContext);
|
|
3824
|
+
});
|
|
3769
3825
|
});
|
|
3770
3826
|
});
|
|
3771
3827
|
return {
|
|
@@ -3831,9 +3887,11 @@ async function handleUninstall(body, hooks) {
|
|
|
3831
3887
|
try {
|
|
3832
3888
|
const uninstallHook = hooks.uninstall;
|
|
3833
3889
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
3834
|
-
const result = await
|
|
3890
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3835
3891
|
return await runWithConfig(requestConfig, async () => {
|
|
3836
|
-
return await
|
|
3892
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3893
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
3894
|
+
});
|
|
3837
3895
|
});
|
|
3838
3896
|
});
|
|
3839
3897
|
return {
|
|
@@ -3892,9 +3950,11 @@ async function handleProvision(body, hooks) {
|
|
|
3892
3950
|
try {
|
|
3893
3951
|
const provisionHook = hooks.provision;
|
|
3894
3952
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
3895
|
-
const result = await
|
|
3953
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3896
3954
|
return await runWithConfig(requestConfig, async () => {
|
|
3897
|
-
return await
|
|
3955
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3956
|
+
return await provisionHandler(provisionContext);
|
|
3957
|
+
});
|
|
3898
3958
|
});
|
|
3899
3959
|
});
|
|
3900
3960
|
return {
|
|
@@ -3952,14 +4012,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
3952
4012
|
};
|
|
3953
4013
|
try {
|
|
3954
4014
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
3955
|
-
const result = await
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
return await runWithConfig(requestConfig, async () => {
|
|
4015
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4016
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4017
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3959
4018
|
return await handler(ctx);
|
|
3960
4019
|
});
|
|
3961
|
-
}
|
|
3962
|
-
);
|
|
4020
|
+
});
|
|
4021
|
+
});
|
|
3963
4022
|
return {
|
|
3964
4023
|
status: 200,
|
|
3965
4024
|
body: {
|
|
@@ -3980,51 +4039,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
3980
4039
|
}
|
|
3981
4040
|
}
|
|
3982
4041
|
|
|
3983
|
-
// src/server/handler-helpers.ts
|
|
3984
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
3985
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
3986
|
-
return null;
|
|
3987
|
-
}
|
|
3988
|
-
const envelope = parsedBody;
|
|
3989
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
3990
|
-
return null;
|
|
3991
|
-
}
|
|
3992
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
3993
|
-
return null;
|
|
3994
|
-
}
|
|
3995
|
-
return {
|
|
3996
|
-
env: envelope.env,
|
|
3997
|
-
request: envelope.request,
|
|
3998
|
-
context: envelope.context
|
|
3999
|
-
};
|
|
4000
|
-
}
|
|
4001
|
-
function buildRequestFromRaw(raw) {
|
|
4002
|
-
let parsedBody = raw.body;
|
|
4003
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
4004
|
-
if (contentType.includes("application/json")) {
|
|
4005
|
-
try {
|
|
4006
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
4007
|
-
} catch {
|
|
4008
|
-
parsedBody = raw.body;
|
|
4009
|
-
}
|
|
4010
|
-
}
|
|
4011
|
-
return {
|
|
4012
|
-
method: raw.method,
|
|
4013
|
-
url: raw.url,
|
|
4014
|
-
path: raw.path,
|
|
4015
|
-
headers: raw.headers,
|
|
4016
|
-
query: raw.query,
|
|
4017
|
-
body: parsedBody,
|
|
4018
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
4019
|
-
};
|
|
4020
|
-
}
|
|
4021
|
-
function buildRequestScopedConfig(env) {
|
|
4022
|
-
return {
|
|
4023
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
4024
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
4025
|
-
};
|
|
4026
|
-
}
|
|
4027
|
-
|
|
4028
4042
|
// src/server/handlers/oauth-callback-handler.ts
|
|
4029
4043
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
4030
4044
|
if (!hooks?.oauth_callback) {
|
|
@@ -4057,9 +4071,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
4057
4071
|
try {
|
|
4058
4072
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
4059
4073
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
4060
|
-
const result = await
|
|
4074
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
4061
4075
|
return await runWithConfig(requestConfig, async () => {
|
|
4062
|
-
return await
|
|
4076
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
4077
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
4078
|
+
});
|
|
4063
4079
|
});
|
|
4064
4080
|
});
|
|
4065
4081
|
return {
|
|
@@ -4178,8 +4194,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
4178
4194
|
invocation: data.invocation,
|
|
4179
4195
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
4180
4196
|
};
|
|
4181
|
-
webhookResponse = await
|
|
4182
|
-
return await
|
|
4197
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
4198
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
4183
4199
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
4184
4200
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
4185
4201
|
});
|
package/dist/dedicated/server.js
CHANGED
|
@@ -1038,6 +1038,60 @@ function isProvisionConfig(value) {
|
|
|
1038
1038
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
+
// src/server/handler-helpers.ts
|
|
1042
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
1043
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1046
|
+
const envelope = parsedBody;
|
|
1047
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
return {
|
|
1054
|
+
env: envelope.env,
|
|
1055
|
+
request: envelope.request,
|
|
1056
|
+
context: envelope.context
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
function buildRequestFromRaw(raw) {
|
|
1060
|
+
let parsedBody = raw.body;
|
|
1061
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
1062
|
+
if (contentType.includes("application/json")) {
|
|
1063
|
+
try {
|
|
1064
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1065
|
+
} catch {
|
|
1066
|
+
parsedBody = raw.body;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return {
|
|
1070
|
+
method: raw.method,
|
|
1071
|
+
url: raw.url,
|
|
1072
|
+
path: raw.path,
|
|
1073
|
+
headers: raw.headers,
|
|
1074
|
+
query: raw.query,
|
|
1075
|
+
body: parsedBody,
|
|
1076
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function buildRequestScopedConfig(env) {
|
|
1080
|
+
return {
|
|
1081
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1082
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
1086
|
+
const originalEnv = { ...process.env };
|
|
1087
|
+
Object.assign(process.env, requestEnv);
|
|
1088
|
+
try {
|
|
1089
|
+
return await fn();
|
|
1090
|
+
} finally {
|
|
1091
|
+
process.env = originalEnv;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1041
1095
|
// src/server/handlers/install-handler.ts
|
|
1042
1096
|
async function handleInstall(body, hooks) {
|
|
1043
1097
|
if (!hooks?.install) {
|
|
@@ -1072,9 +1126,11 @@ async function handleInstall(body, hooks) {
|
|
|
1072
1126
|
try {
|
|
1073
1127
|
const installHook = hooks.install;
|
|
1074
1128
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
1075
|
-
const result = await
|
|
1129
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1076
1130
|
return await runWithConfig(requestConfig, async () => {
|
|
1077
|
-
return await
|
|
1131
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1132
|
+
return await installHandler(installContext);
|
|
1133
|
+
});
|
|
1078
1134
|
});
|
|
1079
1135
|
});
|
|
1080
1136
|
return {
|
|
@@ -1140,9 +1196,11 @@ async function handleUninstall(body, hooks) {
|
|
|
1140
1196
|
try {
|
|
1141
1197
|
const uninstallHook = hooks.uninstall;
|
|
1142
1198
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
1143
|
-
const result = await
|
|
1199
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1144
1200
|
return await runWithConfig(requestConfig, async () => {
|
|
1145
|
-
return await
|
|
1201
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1202
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
1203
|
+
});
|
|
1146
1204
|
});
|
|
1147
1205
|
});
|
|
1148
1206
|
return {
|
|
@@ -1201,9 +1259,11 @@ async function handleProvision(body, hooks) {
|
|
|
1201
1259
|
try {
|
|
1202
1260
|
const provisionHook = hooks.provision;
|
|
1203
1261
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
1204
|
-
const result = await
|
|
1262
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1205
1263
|
return await runWithConfig(requestConfig, async () => {
|
|
1206
|
-
return await
|
|
1264
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1265
|
+
return await provisionHandler(provisionContext);
|
|
1266
|
+
});
|
|
1207
1267
|
});
|
|
1208
1268
|
});
|
|
1209
1269
|
return {
|
|
@@ -1261,14 +1321,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1261
1321
|
};
|
|
1262
1322
|
try {
|
|
1263
1323
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
1264
|
-
const result = await
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
return await runWithConfig(requestConfig, async () => {
|
|
1324
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1325
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1326
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1268
1327
|
return await handler(ctx);
|
|
1269
1328
|
});
|
|
1270
|
-
}
|
|
1271
|
-
);
|
|
1329
|
+
});
|
|
1330
|
+
});
|
|
1272
1331
|
return {
|
|
1273
1332
|
status: 200,
|
|
1274
1333
|
body: {
|
|
@@ -1289,51 +1348,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1289
1348
|
}
|
|
1290
1349
|
}
|
|
1291
1350
|
|
|
1292
|
-
// src/server/handler-helpers.ts
|
|
1293
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1294
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1295
|
-
return null;
|
|
1296
|
-
}
|
|
1297
|
-
const envelope = parsedBody;
|
|
1298
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1302
|
-
return null;
|
|
1303
|
-
}
|
|
1304
|
-
return {
|
|
1305
|
-
env: envelope.env,
|
|
1306
|
-
request: envelope.request,
|
|
1307
|
-
context: envelope.context
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
function buildRequestFromRaw(raw) {
|
|
1311
|
-
let parsedBody = raw.body;
|
|
1312
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1313
|
-
if (contentType.includes("application/json")) {
|
|
1314
|
-
try {
|
|
1315
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1316
|
-
} catch {
|
|
1317
|
-
parsedBody = raw.body;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
return {
|
|
1321
|
-
method: raw.method,
|
|
1322
|
-
url: raw.url,
|
|
1323
|
-
path: raw.path,
|
|
1324
|
-
headers: raw.headers,
|
|
1325
|
-
query: raw.query,
|
|
1326
|
-
body: parsedBody,
|
|
1327
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
function buildRequestScopedConfig(env) {
|
|
1331
|
-
return {
|
|
1332
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1333
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
1351
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1338
1352
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1339
1353
|
if (!hooks?.oauth_callback) {
|
|
@@ -1366,9 +1380,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1366
1380
|
try {
|
|
1367
1381
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1368
1382
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1369
|
-
const result = await
|
|
1383
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1370
1384
|
return await runWithConfig(requestConfig, async () => {
|
|
1371
|
-
return await
|
|
1385
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1386
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1387
|
+
});
|
|
1372
1388
|
});
|
|
1373
1389
|
});
|
|
1374
1390
|
return {
|
|
@@ -1487,8 +1503,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
1487
1503
|
invocation: data.invocation,
|
|
1488
1504
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
1489
1505
|
};
|
|
1490
|
-
webhookResponse = await
|
|
1491
|
-
return await
|
|
1506
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
1507
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
1492
1508
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
1493
1509
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
1494
1510
|
});
|
package/dist/esm/index.mjs
CHANGED
|
@@ -4593,6 +4593,60 @@ function isProvisionConfig(value) {
|
|
|
4593
4593
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
4594
4594
|
}
|
|
4595
4595
|
|
|
4596
|
+
// src/server/handler-helpers.ts
|
|
4597
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
4598
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
4599
|
+
return null;
|
|
4600
|
+
}
|
|
4601
|
+
const envelope = parsedBody;
|
|
4602
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
4603
|
+
return null;
|
|
4604
|
+
}
|
|
4605
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
4606
|
+
return null;
|
|
4607
|
+
}
|
|
4608
|
+
return {
|
|
4609
|
+
env: envelope.env,
|
|
4610
|
+
request: envelope.request,
|
|
4611
|
+
context: envelope.context
|
|
4612
|
+
};
|
|
4613
|
+
}
|
|
4614
|
+
function buildRequestFromRaw(raw) {
|
|
4615
|
+
let parsedBody = raw.body;
|
|
4616
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
4617
|
+
if (contentType.includes("application/json")) {
|
|
4618
|
+
try {
|
|
4619
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
4620
|
+
} catch {
|
|
4621
|
+
parsedBody = raw.body;
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
return {
|
|
4625
|
+
method: raw.method,
|
|
4626
|
+
url: raw.url,
|
|
4627
|
+
path: raw.path,
|
|
4628
|
+
headers: raw.headers,
|
|
4629
|
+
query: raw.query,
|
|
4630
|
+
body: parsedBody,
|
|
4631
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
4632
|
+
};
|
|
4633
|
+
}
|
|
4634
|
+
function buildRequestScopedConfig(env) {
|
|
4635
|
+
return {
|
|
4636
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
4637
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
4638
|
+
};
|
|
4639
|
+
}
|
|
4640
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
4641
|
+
const originalEnv = { ...process.env };
|
|
4642
|
+
Object.assign(process.env, requestEnv);
|
|
4643
|
+
try {
|
|
4644
|
+
return await fn();
|
|
4645
|
+
} finally {
|
|
4646
|
+
process.env = originalEnv;
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4596
4650
|
// src/server/handlers/install-handler.ts
|
|
4597
4651
|
async function handleInstall(body, hooks) {
|
|
4598
4652
|
if (!hooks?.install) {
|
|
@@ -4627,9 +4681,11 @@ async function handleInstall(body, hooks) {
|
|
|
4627
4681
|
try {
|
|
4628
4682
|
const installHook = hooks.install;
|
|
4629
4683
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
4630
|
-
const result = await
|
|
4684
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4631
4685
|
return await runWithConfig(requestConfig, async () => {
|
|
4632
|
-
return await
|
|
4686
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4687
|
+
return await installHandler(installContext);
|
|
4688
|
+
});
|
|
4633
4689
|
});
|
|
4634
4690
|
});
|
|
4635
4691
|
return {
|
|
@@ -4695,9 +4751,11 @@ async function handleUninstall(body, hooks) {
|
|
|
4695
4751
|
try {
|
|
4696
4752
|
const uninstallHook = hooks.uninstall;
|
|
4697
4753
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
4698
|
-
const result = await
|
|
4754
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4699
4755
|
return await runWithConfig(requestConfig, async () => {
|
|
4700
|
-
return await
|
|
4756
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4757
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
4758
|
+
});
|
|
4701
4759
|
});
|
|
4702
4760
|
});
|
|
4703
4761
|
return {
|
|
@@ -4756,9 +4814,11 @@ async function handleProvision(body, hooks) {
|
|
|
4756
4814
|
try {
|
|
4757
4815
|
const provisionHook = hooks.provision;
|
|
4758
4816
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
4759
|
-
const result = await
|
|
4817
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4760
4818
|
return await runWithConfig(requestConfig, async () => {
|
|
4761
|
-
return await
|
|
4819
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4820
|
+
return await provisionHandler(provisionContext);
|
|
4821
|
+
});
|
|
4762
4822
|
});
|
|
4763
4823
|
});
|
|
4764
4824
|
return {
|
|
@@ -4816,14 +4876,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
4816
4876
|
};
|
|
4817
4877
|
try {
|
|
4818
4878
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
4819
|
-
const result = await
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
return await runWithConfig(requestConfig, async () => {
|
|
4879
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4880
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4881
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4823
4882
|
return await handler(ctx);
|
|
4824
4883
|
});
|
|
4825
|
-
}
|
|
4826
|
-
);
|
|
4884
|
+
});
|
|
4885
|
+
});
|
|
4827
4886
|
return {
|
|
4828
4887
|
status: 200,
|
|
4829
4888
|
body: {
|
|
@@ -4844,51 +4903,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
4844
4903
|
}
|
|
4845
4904
|
}
|
|
4846
4905
|
|
|
4847
|
-
// src/server/handler-helpers.ts
|
|
4848
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
4849
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
4850
|
-
return null;
|
|
4851
|
-
}
|
|
4852
|
-
const envelope = parsedBody;
|
|
4853
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
4854
|
-
return null;
|
|
4855
|
-
}
|
|
4856
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
4857
|
-
return null;
|
|
4858
|
-
}
|
|
4859
|
-
return {
|
|
4860
|
-
env: envelope.env,
|
|
4861
|
-
request: envelope.request,
|
|
4862
|
-
context: envelope.context
|
|
4863
|
-
};
|
|
4864
|
-
}
|
|
4865
|
-
function buildRequestFromRaw(raw) {
|
|
4866
|
-
let parsedBody = raw.body;
|
|
4867
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
4868
|
-
if (contentType.includes("application/json")) {
|
|
4869
|
-
try {
|
|
4870
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
4871
|
-
} catch {
|
|
4872
|
-
parsedBody = raw.body;
|
|
4873
|
-
}
|
|
4874
|
-
}
|
|
4875
|
-
return {
|
|
4876
|
-
method: raw.method,
|
|
4877
|
-
url: raw.url,
|
|
4878
|
-
path: raw.path,
|
|
4879
|
-
headers: raw.headers,
|
|
4880
|
-
query: raw.query,
|
|
4881
|
-
body: parsedBody,
|
|
4882
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
4883
|
-
};
|
|
4884
|
-
}
|
|
4885
|
-
function buildRequestScopedConfig(env) {
|
|
4886
|
-
return {
|
|
4887
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
4888
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
4889
|
-
};
|
|
4890
|
-
}
|
|
4891
|
-
|
|
4892
4906
|
// src/server/handlers/oauth-callback-handler.ts
|
|
4893
4907
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
4894
4908
|
if (!hooks?.oauth_callback) {
|
|
@@ -4921,9 +4935,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
4921
4935
|
try {
|
|
4922
4936
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
4923
4937
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
4924
|
-
const result = await
|
|
4938
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
4925
4939
|
return await runWithConfig(requestConfig, async () => {
|
|
4926
|
-
return await
|
|
4940
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
4941
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
4942
|
+
});
|
|
4927
4943
|
});
|
|
4928
4944
|
});
|
|
4929
4945
|
return {
|
|
@@ -5037,8 +5053,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
5037
5053
|
invocation: data.invocation,
|
|
5038
5054
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
5039
5055
|
};
|
|
5040
|
-
webhookResponse = await
|
|
5041
|
-
return await
|
|
5056
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
5057
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
5042
5058
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
5043
5059
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
5044
5060
|
});
|
package/dist/index.js
CHANGED
|
@@ -4982,6 +4982,60 @@ function isProvisionConfig(value) {
|
|
|
4982
4982
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
4983
4983
|
}
|
|
4984
4984
|
|
|
4985
|
+
// src/server/handler-helpers.ts
|
|
4986
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
4987
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
4988
|
+
return null;
|
|
4989
|
+
}
|
|
4990
|
+
const envelope = parsedBody;
|
|
4991
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
4992
|
+
return null;
|
|
4993
|
+
}
|
|
4994
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
4995
|
+
return null;
|
|
4996
|
+
}
|
|
4997
|
+
return {
|
|
4998
|
+
env: envelope.env,
|
|
4999
|
+
request: envelope.request,
|
|
5000
|
+
context: envelope.context
|
|
5001
|
+
};
|
|
5002
|
+
}
|
|
5003
|
+
function buildRequestFromRaw(raw) {
|
|
5004
|
+
let parsedBody = raw.body;
|
|
5005
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
5006
|
+
if (contentType.includes("application/json")) {
|
|
5007
|
+
try {
|
|
5008
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
5009
|
+
} catch {
|
|
5010
|
+
parsedBody = raw.body;
|
|
5011
|
+
}
|
|
5012
|
+
}
|
|
5013
|
+
return {
|
|
5014
|
+
method: raw.method,
|
|
5015
|
+
url: raw.url,
|
|
5016
|
+
path: raw.path,
|
|
5017
|
+
headers: raw.headers,
|
|
5018
|
+
query: raw.query,
|
|
5019
|
+
body: parsedBody,
|
|
5020
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
5021
|
+
};
|
|
5022
|
+
}
|
|
5023
|
+
function buildRequestScopedConfig(env) {
|
|
5024
|
+
return {
|
|
5025
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
5026
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
5027
|
+
};
|
|
5028
|
+
}
|
|
5029
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
5030
|
+
const originalEnv = { ...process.env };
|
|
5031
|
+
Object.assign(process.env, requestEnv);
|
|
5032
|
+
try {
|
|
5033
|
+
return await fn();
|
|
5034
|
+
} finally {
|
|
5035
|
+
process.env = originalEnv;
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
|
|
4985
5039
|
// src/server/handlers/install-handler.ts
|
|
4986
5040
|
async function handleInstall(body, hooks) {
|
|
4987
5041
|
if (!hooks?.install) {
|
|
@@ -5016,9 +5070,11 @@ async function handleInstall(body, hooks) {
|
|
|
5016
5070
|
try {
|
|
5017
5071
|
const installHook = hooks.install;
|
|
5018
5072
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
5019
|
-
const result = await
|
|
5073
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5020
5074
|
return await runWithConfig(requestConfig, async () => {
|
|
5021
|
-
return await
|
|
5075
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5076
|
+
return await installHandler(installContext);
|
|
5077
|
+
});
|
|
5022
5078
|
});
|
|
5023
5079
|
});
|
|
5024
5080
|
return {
|
|
@@ -5084,9 +5140,11 @@ async function handleUninstall(body, hooks) {
|
|
|
5084
5140
|
try {
|
|
5085
5141
|
const uninstallHook = hooks.uninstall;
|
|
5086
5142
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
5087
|
-
const result = await
|
|
5143
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5088
5144
|
return await runWithConfig(requestConfig, async () => {
|
|
5089
|
-
return await
|
|
5145
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5146
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
5147
|
+
});
|
|
5090
5148
|
});
|
|
5091
5149
|
});
|
|
5092
5150
|
return {
|
|
@@ -5145,9 +5203,11 @@ async function handleProvision(body, hooks) {
|
|
|
5145
5203
|
try {
|
|
5146
5204
|
const provisionHook = hooks.provision;
|
|
5147
5205
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
5148
|
-
const result = await
|
|
5206
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5149
5207
|
return await runWithConfig(requestConfig, async () => {
|
|
5150
|
-
return await
|
|
5208
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5209
|
+
return await provisionHandler(provisionContext);
|
|
5210
|
+
});
|
|
5151
5211
|
});
|
|
5152
5212
|
});
|
|
5153
5213
|
return {
|
|
@@ -5205,14 +5265,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
5205
5265
|
};
|
|
5206
5266
|
try {
|
|
5207
5267
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
5208
|
-
const result = await
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
return await runWithConfig(requestConfig, async () => {
|
|
5268
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5269
|
+
return await runWithConfig(requestConfig, async () => {
|
|
5270
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5212
5271
|
return await handler(ctx);
|
|
5213
5272
|
});
|
|
5214
|
-
}
|
|
5215
|
-
);
|
|
5273
|
+
});
|
|
5274
|
+
});
|
|
5216
5275
|
return {
|
|
5217
5276
|
status: 200,
|
|
5218
5277
|
body: {
|
|
@@ -5233,51 +5292,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
5233
5292
|
}
|
|
5234
5293
|
}
|
|
5235
5294
|
|
|
5236
|
-
// src/server/handler-helpers.ts
|
|
5237
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
5238
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
5239
|
-
return null;
|
|
5240
|
-
}
|
|
5241
|
-
const envelope = parsedBody;
|
|
5242
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
5243
|
-
return null;
|
|
5244
|
-
}
|
|
5245
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
5246
|
-
return null;
|
|
5247
|
-
}
|
|
5248
|
-
return {
|
|
5249
|
-
env: envelope.env,
|
|
5250
|
-
request: envelope.request,
|
|
5251
|
-
context: envelope.context
|
|
5252
|
-
};
|
|
5253
|
-
}
|
|
5254
|
-
function buildRequestFromRaw(raw) {
|
|
5255
|
-
let parsedBody = raw.body;
|
|
5256
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
5257
|
-
if (contentType.includes("application/json")) {
|
|
5258
|
-
try {
|
|
5259
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
5260
|
-
} catch {
|
|
5261
|
-
parsedBody = raw.body;
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
return {
|
|
5265
|
-
method: raw.method,
|
|
5266
|
-
url: raw.url,
|
|
5267
|
-
path: raw.path,
|
|
5268
|
-
headers: raw.headers,
|
|
5269
|
-
query: raw.query,
|
|
5270
|
-
body: parsedBody,
|
|
5271
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
5272
|
-
};
|
|
5273
|
-
}
|
|
5274
|
-
function buildRequestScopedConfig(env) {
|
|
5275
|
-
return {
|
|
5276
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
5277
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
5278
|
-
};
|
|
5279
|
-
}
|
|
5280
|
-
|
|
5281
5295
|
// src/server/handlers/oauth-callback-handler.ts
|
|
5282
5296
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
5283
5297
|
if (!hooks?.oauth_callback) {
|
|
@@ -5310,9 +5324,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
5310
5324
|
try {
|
|
5311
5325
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
5312
5326
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
5313
|
-
const result = await
|
|
5327
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
5314
5328
|
return await runWithConfig(requestConfig, async () => {
|
|
5315
|
-
return await
|
|
5329
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
5330
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
5331
|
+
});
|
|
5316
5332
|
});
|
|
5317
5333
|
});
|
|
5318
5334
|
return {
|
|
@@ -5426,8 +5442,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
5426
5442
|
invocation: data.invocation,
|
|
5427
5443
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
5428
5444
|
};
|
|
5429
|
-
webhookResponse = await
|
|
5430
|
-
return await
|
|
5445
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
5446
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
5431
5447
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
5432
5448
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
5433
5449
|
});
|
|
@@ -22,3 +22,10 @@ export declare function buildRequestScopedConfig(env: Record<string, string>): {
|
|
|
22
22
|
baseUrl: string;
|
|
23
23
|
apiToken: string;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Inject per-request env (e.g. SKEDYUL_API_TOKEN) into process.env for a handler.
|
|
27
|
+
*
|
|
28
|
+
* Lambda tool/webhook paths rely on this because AsyncLocalStorage from runWithConfig
|
|
29
|
+
* can be lost across await boundaries; getEffectiveConfig() falls back to process.env.
|
|
30
|
+
*/
|
|
31
|
+
export declare function withRequestEnv<T>(requestEnv: Record<string, string>, fn: () => Promise<T>): Promise<T>;
|
package/dist/server.js
CHANGED
|
@@ -1038,6 +1038,60 @@ function isProvisionConfig(value) {
|
|
|
1038
1038
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
+
// src/server/handler-helpers.ts
|
|
1042
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
1043
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1046
|
+
const envelope = parsedBody;
|
|
1047
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
return {
|
|
1054
|
+
env: envelope.env,
|
|
1055
|
+
request: envelope.request,
|
|
1056
|
+
context: envelope.context
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
function buildRequestFromRaw(raw) {
|
|
1060
|
+
let parsedBody = raw.body;
|
|
1061
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
1062
|
+
if (contentType.includes("application/json")) {
|
|
1063
|
+
try {
|
|
1064
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1065
|
+
} catch {
|
|
1066
|
+
parsedBody = raw.body;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return {
|
|
1070
|
+
method: raw.method,
|
|
1071
|
+
url: raw.url,
|
|
1072
|
+
path: raw.path,
|
|
1073
|
+
headers: raw.headers,
|
|
1074
|
+
query: raw.query,
|
|
1075
|
+
body: parsedBody,
|
|
1076
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function buildRequestScopedConfig(env) {
|
|
1080
|
+
return {
|
|
1081
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1082
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
1086
|
+
const originalEnv = { ...process.env };
|
|
1087
|
+
Object.assign(process.env, requestEnv);
|
|
1088
|
+
try {
|
|
1089
|
+
return await fn();
|
|
1090
|
+
} finally {
|
|
1091
|
+
process.env = originalEnv;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1041
1095
|
// src/server/handlers/install-handler.ts
|
|
1042
1096
|
async function handleInstall(body, hooks) {
|
|
1043
1097
|
if (!hooks?.install) {
|
|
@@ -1072,9 +1126,11 @@ async function handleInstall(body, hooks) {
|
|
|
1072
1126
|
try {
|
|
1073
1127
|
const installHook = hooks.install;
|
|
1074
1128
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
1075
|
-
const result = await
|
|
1129
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1076
1130
|
return await runWithConfig(requestConfig, async () => {
|
|
1077
|
-
return await
|
|
1131
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1132
|
+
return await installHandler(installContext);
|
|
1133
|
+
});
|
|
1078
1134
|
});
|
|
1079
1135
|
});
|
|
1080
1136
|
return {
|
|
@@ -1140,9 +1196,11 @@ async function handleUninstall(body, hooks) {
|
|
|
1140
1196
|
try {
|
|
1141
1197
|
const uninstallHook = hooks.uninstall;
|
|
1142
1198
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
1143
|
-
const result = await
|
|
1199
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1144
1200
|
return await runWithConfig(requestConfig, async () => {
|
|
1145
|
-
return await
|
|
1201
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1202
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
1203
|
+
});
|
|
1146
1204
|
});
|
|
1147
1205
|
});
|
|
1148
1206
|
return {
|
|
@@ -1201,9 +1259,11 @@ async function handleProvision(body, hooks) {
|
|
|
1201
1259
|
try {
|
|
1202
1260
|
const provisionHook = hooks.provision;
|
|
1203
1261
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
1204
|
-
const result = await
|
|
1262
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1205
1263
|
return await runWithConfig(requestConfig, async () => {
|
|
1206
|
-
return await
|
|
1264
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1265
|
+
return await provisionHandler(provisionContext);
|
|
1266
|
+
});
|
|
1207
1267
|
});
|
|
1208
1268
|
});
|
|
1209
1269
|
return {
|
|
@@ -1261,14 +1321,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1261
1321
|
};
|
|
1262
1322
|
try {
|
|
1263
1323
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
1264
|
-
const result = await
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
return await runWithConfig(requestConfig, async () => {
|
|
1324
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1325
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1326
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1268
1327
|
return await handler(ctx);
|
|
1269
1328
|
});
|
|
1270
|
-
}
|
|
1271
|
-
);
|
|
1329
|
+
});
|
|
1330
|
+
});
|
|
1272
1331
|
return {
|
|
1273
1332
|
status: 200,
|
|
1274
1333
|
body: {
|
|
@@ -1289,51 +1348,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1289
1348
|
}
|
|
1290
1349
|
}
|
|
1291
1350
|
|
|
1292
|
-
// src/server/handler-helpers.ts
|
|
1293
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1294
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1295
|
-
return null;
|
|
1296
|
-
}
|
|
1297
|
-
const envelope = parsedBody;
|
|
1298
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1302
|
-
return null;
|
|
1303
|
-
}
|
|
1304
|
-
return {
|
|
1305
|
-
env: envelope.env,
|
|
1306
|
-
request: envelope.request,
|
|
1307
|
-
context: envelope.context
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
function buildRequestFromRaw(raw) {
|
|
1311
|
-
let parsedBody = raw.body;
|
|
1312
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1313
|
-
if (contentType.includes("application/json")) {
|
|
1314
|
-
try {
|
|
1315
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1316
|
-
} catch {
|
|
1317
|
-
parsedBody = raw.body;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
return {
|
|
1321
|
-
method: raw.method,
|
|
1322
|
-
url: raw.url,
|
|
1323
|
-
path: raw.path,
|
|
1324
|
-
headers: raw.headers,
|
|
1325
|
-
query: raw.query,
|
|
1326
|
-
body: parsedBody,
|
|
1327
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
function buildRequestScopedConfig(env) {
|
|
1331
|
-
return {
|
|
1332
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1333
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
1351
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1338
1352
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1339
1353
|
if (!hooks?.oauth_callback) {
|
|
@@ -1366,9 +1380,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1366
1380
|
try {
|
|
1367
1381
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1368
1382
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1369
|
-
const result = await
|
|
1383
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1370
1384
|
return await runWithConfig(requestConfig, async () => {
|
|
1371
|
-
return await
|
|
1385
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1386
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1387
|
+
});
|
|
1372
1388
|
});
|
|
1373
1389
|
});
|
|
1374
1390
|
return {
|
|
@@ -1487,8 +1503,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
1487
1503
|
invocation: data.invocation,
|
|
1488
1504
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
1489
1505
|
};
|
|
1490
|
-
webhookResponse = await
|
|
1491
|
-
return await
|
|
1506
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
1507
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
1492
1508
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
1493
1509
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
1494
1510
|
});
|
|
@@ -999,6 +999,60 @@ function isProvisionConfig(value) {
|
|
|
999
999
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
1000
1000
|
}
|
|
1001
1001
|
|
|
1002
|
+
// src/server/handler-helpers.ts
|
|
1003
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
1004
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
const envelope = parsedBody;
|
|
1008
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1012
|
+
return null;
|
|
1013
|
+
}
|
|
1014
|
+
return {
|
|
1015
|
+
env: envelope.env,
|
|
1016
|
+
request: envelope.request,
|
|
1017
|
+
context: envelope.context
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
function buildRequestFromRaw(raw) {
|
|
1021
|
+
let parsedBody = raw.body;
|
|
1022
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
1023
|
+
if (contentType.includes("application/json")) {
|
|
1024
|
+
try {
|
|
1025
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1026
|
+
} catch {
|
|
1027
|
+
parsedBody = raw.body;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
method: raw.method,
|
|
1032
|
+
url: raw.url,
|
|
1033
|
+
path: raw.path,
|
|
1034
|
+
headers: raw.headers,
|
|
1035
|
+
query: raw.query,
|
|
1036
|
+
body: parsedBody,
|
|
1037
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
function buildRequestScopedConfig(env) {
|
|
1041
|
+
return {
|
|
1042
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1043
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
1047
|
+
const originalEnv = { ...process.env };
|
|
1048
|
+
Object.assign(process.env, requestEnv);
|
|
1049
|
+
try {
|
|
1050
|
+
return await fn();
|
|
1051
|
+
} finally {
|
|
1052
|
+
process.env = originalEnv;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1002
1056
|
// src/server/handlers/install-handler.ts
|
|
1003
1057
|
async function handleInstall(body, hooks) {
|
|
1004
1058
|
if (!hooks?.install) {
|
|
@@ -1033,9 +1087,11 @@ async function handleInstall(body, hooks) {
|
|
|
1033
1087
|
try {
|
|
1034
1088
|
const installHook = hooks.install;
|
|
1035
1089
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
1036
|
-
const result = await
|
|
1090
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1037
1091
|
return await runWithConfig(requestConfig, async () => {
|
|
1038
|
-
return await
|
|
1092
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1093
|
+
return await installHandler(installContext);
|
|
1094
|
+
});
|
|
1039
1095
|
});
|
|
1040
1096
|
});
|
|
1041
1097
|
return {
|
|
@@ -1101,9 +1157,11 @@ async function handleUninstall(body, hooks) {
|
|
|
1101
1157
|
try {
|
|
1102
1158
|
const uninstallHook = hooks.uninstall;
|
|
1103
1159
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
1104
|
-
const result = await
|
|
1160
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1105
1161
|
return await runWithConfig(requestConfig, async () => {
|
|
1106
|
-
return await
|
|
1162
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1163
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
1164
|
+
});
|
|
1107
1165
|
});
|
|
1108
1166
|
});
|
|
1109
1167
|
return {
|
|
@@ -1162,9 +1220,11 @@ async function handleProvision(body, hooks) {
|
|
|
1162
1220
|
try {
|
|
1163
1221
|
const provisionHook = hooks.provision;
|
|
1164
1222
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
1165
|
-
const result = await
|
|
1223
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1166
1224
|
return await runWithConfig(requestConfig, async () => {
|
|
1167
|
-
return await
|
|
1225
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1226
|
+
return await provisionHandler(provisionContext);
|
|
1227
|
+
});
|
|
1168
1228
|
});
|
|
1169
1229
|
});
|
|
1170
1230
|
return {
|
|
@@ -1222,14 +1282,13 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1222
1282
|
};
|
|
1223
1283
|
try {
|
|
1224
1284
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
1225
|
-
const result = await
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
return await runWithConfig(requestConfig, async () => {
|
|
1285
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1286
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1287
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1229
1288
|
return await handler(ctx);
|
|
1230
1289
|
});
|
|
1231
|
-
}
|
|
1232
|
-
);
|
|
1290
|
+
});
|
|
1291
|
+
});
|
|
1233
1292
|
return {
|
|
1234
1293
|
status: 200,
|
|
1235
1294
|
body: {
|
|
@@ -1250,51 +1309,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1250
1309
|
}
|
|
1251
1310
|
}
|
|
1252
1311
|
|
|
1253
|
-
// src/server/handler-helpers.ts
|
|
1254
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1255
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1256
|
-
return null;
|
|
1257
|
-
}
|
|
1258
|
-
const envelope = parsedBody;
|
|
1259
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1260
|
-
return null;
|
|
1261
|
-
}
|
|
1262
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1263
|
-
return null;
|
|
1264
|
-
}
|
|
1265
|
-
return {
|
|
1266
|
-
env: envelope.env,
|
|
1267
|
-
request: envelope.request,
|
|
1268
|
-
context: envelope.context
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
function buildRequestFromRaw(raw) {
|
|
1272
|
-
let parsedBody = raw.body;
|
|
1273
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1274
|
-
if (contentType.includes("application/json")) {
|
|
1275
|
-
try {
|
|
1276
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1277
|
-
} catch {
|
|
1278
|
-
parsedBody = raw.body;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
return {
|
|
1282
|
-
method: raw.method,
|
|
1283
|
-
url: raw.url,
|
|
1284
|
-
path: raw.path,
|
|
1285
|
-
headers: raw.headers,
|
|
1286
|
-
query: raw.query,
|
|
1287
|
-
body: parsedBody,
|
|
1288
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
function buildRequestScopedConfig(env) {
|
|
1292
|
-
return {
|
|
1293
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1294
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
1312
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1299
1313
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1300
1314
|
if (!hooks?.oauth_callback) {
|
|
@@ -1327,9 +1341,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1327
1341
|
try {
|
|
1328
1342
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1329
1343
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1330
|
-
const result = await
|
|
1344
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1331
1345
|
return await runWithConfig(requestConfig, async () => {
|
|
1332
|
-
return await
|
|
1346
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1347
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1348
|
+
});
|
|
1333
1349
|
});
|
|
1334
1350
|
});
|
|
1335
1351
|
return {
|
|
@@ -1448,8 +1464,8 @@ async function executeWebhookHandler(handle, webhookRegistry, data) {
|
|
|
1448
1464
|
invocation: data.invocation,
|
|
1449
1465
|
isProvisionContext: !isRuntimeWebhookContext(data.webhookContext)
|
|
1450
1466
|
};
|
|
1451
|
-
webhookResponse = await
|
|
1452
|
-
return await
|
|
1467
|
+
webhookResponse = await runWithConfig(requestConfig, async () => {
|
|
1468
|
+
return await runWithLogContext({ invocation: data.invocation }, async () => {
|
|
1453
1469
|
return await runWithRateLimitExecutionContext(rateLimitContext, async () => {
|
|
1454
1470
|
return await webhookDef.handler(data.webhookRequest, data.webhookContext);
|
|
1455
1471
|
});
|