skedyul 1.7.19 → 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 +79 -60
- package/dist/dedicated/server.js +79 -60
- package/dist/esm/index.mjs +79 -60
- package/dist/index.js +79 -60
- package/dist/server/handler-helpers.d.ts +7 -0
- package/dist/server.js +79 -60
- package/dist/serverless/server.mjs +79 -60
- 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
|
|
3767
|
-
return await
|
|
3768
|
-
return await
|
|
3820
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3821
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
3835
|
-
return await
|
|
3836
|
-
return await
|
|
3890
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3891
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
3896
|
-
return await
|
|
3897
|
-
return await
|
|
3953
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3954
|
+
return await runWithConfig(requestConfig, async () => {
|
|
3955
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3956
|
+
return await provisionHandler(provisionContext);
|
|
3957
|
+
});
|
|
3898
3958
|
});
|
|
3899
3959
|
});
|
|
3900
3960
|
return {
|
|
@@ -3952,9 +4012,11 @@ 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
|
-
return await
|
|
3957
|
-
return await
|
|
4015
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4016
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4017
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4018
|
+
return await handler(ctx);
|
|
4019
|
+
});
|
|
3958
4020
|
});
|
|
3959
4021
|
});
|
|
3960
4022
|
return {
|
|
@@ -3977,51 +4039,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
3977
4039
|
}
|
|
3978
4040
|
}
|
|
3979
4041
|
|
|
3980
|
-
// src/server/handler-helpers.ts
|
|
3981
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
3982
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
3983
|
-
return null;
|
|
3984
|
-
}
|
|
3985
|
-
const envelope = parsedBody;
|
|
3986
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
3987
|
-
return null;
|
|
3988
|
-
}
|
|
3989
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
3990
|
-
return null;
|
|
3991
|
-
}
|
|
3992
|
-
return {
|
|
3993
|
-
env: envelope.env,
|
|
3994
|
-
request: envelope.request,
|
|
3995
|
-
context: envelope.context
|
|
3996
|
-
};
|
|
3997
|
-
}
|
|
3998
|
-
function buildRequestFromRaw(raw) {
|
|
3999
|
-
let parsedBody = raw.body;
|
|
4000
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
4001
|
-
if (contentType.includes("application/json")) {
|
|
4002
|
-
try {
|
|
4003
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
4004
|
-
} catch {
|
|
4005
|
-
parsedBody = raw.body;
|
|
4006
|
-
}
|
|
4007
|
-
}
|
|
4008
|
-
return {
|
|
4009
|
-
method: raw.method,
|
|
4010
|
-
url: raw.url,
|
|
4011
|
-
path: raw.path,
|
|
4012
|
-
headers: raw.headers,
|
|
4013
|
-
query: raw.query,
|
|
4014
|
-
body: parsedBody,
|
|
4015
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
4016
|
-
};
|
|
4017
|
-
}
|
|
4018
|
-
function buildRequestScopedConfig(env) {
|
|
4019
|
-
return {
|
|
4020
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
4021
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
4022
|
-
};
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
4042
|
// src/server/handlers/oauth-callback-handler.ts
|
|
4026
4043
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
4027
4044
|
if (!hooks?.oauth_callback) {
|
|
@@ -4054,9 +4071,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
4054
4071
|
try {
|
|
4055
4072
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
4056
4073
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
4057
|
-
const result = await
|
|
4058
|
-
return await
|
|
4059
|
-
return await
|
|
4074
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
4075
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4076
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
4077
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
4078
|
+
});
|
|
4060
4079
|
});
|
|
4061
4080
|
});
|
|
4062
4081
|
return {
|
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
|
|
1076
|
-
return await
|
|
1077
|
-
return await
|
|
1129
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1130
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1144
|
-
return await
|
|
1145
|
-
return await
|
|
1199
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1200
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1205
|
-
return await
|
|
1206
|
-
return await
|
|
1262
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1263
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1264
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1265
|
+
return await provisionHandler(provisionContext);
|
|
1266
|
+
});
|
|
1207
1267
|
});
|
|
1208
1268
|
});
|
|
1209
1269
|
return {
|
|
@@ -1261,9 +1321,11 @@ 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
|
-
return await
|
|
1266
|
-
return await
|
|
1324
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1325
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1326
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1327
|
+
return await handler(ctx);
|
|
1328
|
+
});
|
|
1267
1329
|
});
|
|
1268
1330
|
});
|
|
1269
1331
|
return {
|
|
@@ -1286,51 +1348,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1286
1348
|
}
|
|
1287
1349
|
}
|
|
1288
1350
|
|
|
1289
|
-
// src/server/handler-helpers.ts
|
|
1290
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1291
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1292
|
-
return null;
|
|
1293
|
-
}
|
|
1294
|
-
const envelope = parsedBody;
|
|
1295
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1296
|
-
return null;
|
|
1297
|
-
}
|
|
1298
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
return {
|
|
1302
|
-
env: envelope.env,
|
|
1303
|
-
request: envelope.request,
|
|
1304
|
-
context: envelope.context
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
function buildRequestFromRaw(raw) {
|
|
1308
|
-
let parsedBody = raw.body;
|
|
1309
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1310
|
-
if (contentType.includes("application/json")) {
|
|
1311
|
-
try {
|
|
1312
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1313
|
-
} catch {
|
|
1314
|
-
parsedBody = raw.body;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
return {
|
|
1318
|
-
method: raw.method,
|
|
1319
|
-
url: raw.url,
|
|
1320
|
-
path: raw.path,
|
|
1321
|
-
headers: raw.headers,
|
|
1322
|
-
query: raw.query,
|
|
1323
|
-
body: parsedBody,
|
|
1324
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1325
|
-
};
|
|
1326
|
-
}
|
|
1327
|
-
function buildRequestScopedConfig(env) {
|
|
1328
|
-
return {
|
|
1329
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1330
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
1351
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1335
1352
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1336
1353
|
if (!hooks?.oauth_callback) {
|
|
@@ -1363,9 +1380,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1363
1380
|
try {
|
|
1364
1381
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1365
1382
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1366
|
-
const result = await
|
|
1367
|
-
return await
|
|
1368
|
-
return await
|
|
1383
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1384
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1385
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1386
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1387
|
+
});
|
|
1369
1388
|
});
|
|
1370
1389
|
});
|
|
1371
1390
|
return {
|
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
|
|
4631
|
-
return await
|
|
4632
|
-
return await
|
|
4684
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4685
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
4699
|
-
return await
|
|
4700
|
-
return await
|
|
4754
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4755
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
4760
|
-
return await
|
|
4761
|
-
return await
|
|
4817
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4818
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4819
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4820
|
+
return await provisionHandler(provisionContext);
|
|
4821
|
+
});
|
|
4762
4822
|
});
|
|
4763
4823
|
});
|
|
4764
4824
|
return {
|
|
@@ -4816,9 +4876,11 @@ 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
|
-
return await
|
|
4821
|
-
return await
|
|
4879
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4880
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4881
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4882
|
+
return await handler(ctx);
|
|
4883
|
+
});
|
|
4822
4884
|
});
|
|
4823
4885
|
});
|
|
4824
4886
|
return {
|
|
@@ -4841,51 +4903,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
4841
4903
|
}
|
|
4842
4904
|
}
|
|
4843
4905
|
|
|
4844
|
-
// src/server/handler-helpers.ts
|
|
4845
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
4846
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
4847
|
-
return null;
|
|
4848
|
-
}
|
|
4849
|
-
const envelope = parsedBody;
|
|
4850
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
4851
|
-
return null;
|
|
4852
|
-
}
|
|
4853
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
4854
|
-
return null;
|
|
4855
|
-
}
|
|
4856
|
-
return {
|
|
4857
|
-
env: envelope.env,
|
|
4858
|
-
request: envelope.request,
|
|
4859
|
-
context: envelope.context
|
|
4860
|
-
};
|
|
4861
|
-
}
|
|
4862
|
-
function buildRequestFromRaw(raw) {
|
|
4863
|
-
let parsedBody = raw.body;
|
|
4864
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
4865
|
-
if (contentType.includes("application/json")) {
|
|
4866
|
-
try {
|
|
4867
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
4868
|
-
} catch {
|
|
4869
|
-
parsedBody = raw.body;
|
|
4870
|
-
}
|
|
4871
|
-
}
|
|
4872
|
-
return {
|
|
4873
|
-
method: raw.method,
|
|
4874
|
-
url: raw.url,
|
|
4875
|
-
path: raw.path,
|
|
4876
|
-
headers: raw.headers,
|
|
4877
|
-
query: raw.query,
|
|
4878
|
-
body: parsedBody,
|
|
4879
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
4880
|
-
};
|
|
4881
|
-
}
|
|
4882
|
-
function buildRequestScopedConfig(env) {
|
|
4883
|
-
return {
|
|
4884
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
4885
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
4886
|
-
};
|
|
4887
|
-
}
|
|
4888
|
-
|
|
4889
4906
|
// src/server/handlers/oauth-callback-handler.ts
|
|
4890
4907
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
4891
4908
|
if (!hooks?.oauth_callback) {
|
|
@@ -4918,9 +4935,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
4918
4935
|
try {
|
|
4919
4936
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
4920
4937
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
4921
|
-
const result = await
|
|
4922
|
-
return await
|
|
4923
|
-
return await
|
|
4938
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
4939
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4940
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
4941
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
4942
|
+
});
|
|
4924
4943
|
});
|
|
4925
4944
|
});
|
|
4926
4945
|
return {
|
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
|
|
5020
|
-
return await
|
|
5021
|
-
return await
|
|
5073
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5074
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
5088
|
-
return await
|
|
5089
|
-
return await
|
|
5143
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5144
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
5149
|
-
return await
|
|
5150
|
-
return await
|
|
5206
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5207
|
+
return await runWithConfig(requestConfig, async () => {
|
|
5208
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5209
|
+
return await provisionHandler(provisionContext);
|
|
5210
|
+
});
|
|
5151
5211
|
});
|
|
5152
5212
|
});
|
|
5153
5213
|
return {
|
|
@@ -5205,9 +5265,11 @@ 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
|
-
return await
|
|
5210
|
-
return await
|
|
5268
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
5269
|
+
return await runWithConfig(requestConfig, async () => {
|
|
5270
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
5271
|
+
return await handler(ctx);
|
|
5272
|
+
});
|
|
5211
5273
|
});
|
|
5212
5274
|
});
|
|
5213
5275
|
return {
|
|
@@ -5230,51 +5292,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
5230
5292
|
}
|
|
5231
5293
|
}
|
|
5232
5294
|
|
|
5233
|
-
// src/server/handler-helpers.ts
|
|
5234
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
5235
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
5236
|
-
return null;
|
|
5237
|
-
}
|
|
5238
|
-
const envelope = parsedBody;
|
|
5239
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
5240
|
-
return null;
|
|
5241
|
-
}
|
|
5242
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
5243
|
-
return null;
|
|
5244
|
-
}
|
|
5245
|
-
return {
|
|
5246
|
-
env: envelope.env,
|
|
5247
|
-
request: envelope.request,
|
|
5248
|
-
context: envelope.context
|
|
5249
|
-
};
|
|
5250
|
-
}
|
|
5251
|
-
function buildRequestFromRaw(raw) {
|
|
5252
|
-
let parsedBody = raw.body;
|
|
5253
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
5254
|
-
if (contentType.includes("application/json")) {
|
|
5255
|
-
try {
|
|
5256
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
5257
|
-
} catch {
|
|
5258
|
-
parsedBody = raw.body;
|
|
5259
|
-
}
|
|
5260
|
-
}
|
|
5261
|
-
return {
|
|
5262
|
-
method: raw.method,
|
|
5263
|
-
url: raw.url,
|
|
5264
|
-
path: raw.path,
|
|
5265
|
-
headers: raw.headers,
|
|
5266
|
-
query: raw.query,
|
|
5267
|
-
body: parsedBody,
|
|
5268
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
5269
|
-
};
|
|
5270
|
-
}
|
|
5271
|
-
function buildRequestScopedConfig(env) {
|
|
5272
|
-
return {
|
|
5273
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
5274
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
5275
|
-
};
|
|
5276
|
-
}
|
|
5277
|
-
|
|
5278
5295
|
// src/server/handlers/oauth-callback-handler.ts
|
|
5279
5296
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
5280
5297
|
if (!hooks?.oauth_callback) {
|
|
@@ -5307,9 +5324,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
5307
5324
|
try {
|
|
5308
5325
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
5309
5326
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
5310
|
-
const result = await
|
|
5311
|
-
return await
|
|
5312
|
-
return await
|
|
5327
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
5328
|
+
return await runWithConfig(requestConfig, async () => {
|
|
5329
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
5330
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
5331
|
+
});
|
|
5313
5332
|
});
|
|
5314
5333
|
});
|
|
5315
5334
|
return {
|
|
@@ -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
|
|
1076
|
-
return await
|
|
1077
|
-
return await
|
|
1129
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1130
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1144
|
-
return await
|
|
1145
|
-
return await
|
|
1199
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1200
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1205
|
-
return await
|
|
1206
|
-
return await
|
|
1262
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1263
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1264
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1265
|
+
return await provisionHandler(provisionContext);
|
|
1266
|
+
});
|
|
1207
1267
|
});
|
|
1208
1268
|
});
|
|
1209
1269
|
return {
|
|
@@ -1261,9 +1321,11 @@ 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
|
-
return await
|
|
1266
|
-
return await
|
|
1324
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1325
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1326
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1327
|
+
return await handler(ctx);
|
|
1328
|
+
});
|
|
1267
1329
|
});
|
|
1268
1330
|
});
|
|
1269
1331
|
return {
|
|
@@ -1286,51 +1348,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1286
1348
|
}
|
|
1287
1349
|
}
|
|
1288
1350
|
|
|
1289
|
-
// src/server/handler-helpers.ts
|
|
1290
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1291
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1292
|
-
return null;
|
|
1293
|
-
}
|
|
1294
|
-
const envelope = parsedBody;
|
|
1295
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1296
|
-
return null;
|
|
1297
|
-
}
|
|
1298
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
return {
|
|
1302
|
-
env: envelope.env,
|
|
1303
|
-
request: envelope.request,
|
|
1304
|
-
context: envelope.context
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
function buildRequestFromRaw(raw) {
|
|
1308
|
-
let parsedBody = raw.body;
|
|
1309
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1310
|
-
if (contentType.includes("application/json")) {
|
|
1311
|
-
try {
|
|
1312
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1313
|
-
} catch {
|
|
1314
|
-
parsedBody = raw.body;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
return {
|
|
1318
|
-
method: raw.method,
|
|
1319
|
-
url: raw.url,
|
|
1320
|
-
path: raw.path,
|
|
1321
|
-
headers: raw.headers,
|
|
1322
|
-
query: raw.query,
|
|
1323
|
-
body: parsedBody,
|
|
1324
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1325
|
-
};
|
|
1326
|
-
}
|
|
1327
|
-
function buildRequestScopedConfig(env) {
|
|
1328
|
-
return {
|
|
1329
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1330
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
1351
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1335
1352
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1336
1353
|
if (!hooks?.oauth_callback) {
|
|
@@ -1363,9 +1380,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1363
1380
|
try {
|
|
1364
1381
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1365
1382
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1366
|
-
const result = await
|
|
1367
|
-
return await
|
|
1368
|
-
return await
|
|
1383
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1384
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1385
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1386
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1387
|
+
});
|
|
1369
1388
|
});
|
|
1370
1389
|
});
|
|
1371
1390
|
return {
|
|
@@ -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
|
|
1037
|
-
return await
|
|
1038
|
-
return await
|
|
1090
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1091
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1105
|
-
return await
|
|
1106
|
-
return await
|
|
1160
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1161
|
+
return await runWithConfig(requestConfig, async () => {
|
|
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
|
|
1166
|
-
return await
|
|
1167
|
-
return await
|
|
1223
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1224
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1225
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1226
|
+
return await provisionHandler(provisionContext);
|
|
1227
|
+
});
|
|
1168
1228
|
});
|
|
1169
1229
|
});
|
|
1170
1230
|
return {
|
|
@@ -1222,9 +1282,11 @@ 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
|
-
return await
|
|
1227
|
-
return await
|
|
1285
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1286
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1287
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1288
|
+
return await handler(ctx);
|
|
1289
|
+
});
|
|
1228
1290
|
});
|
|
1229
1291
|
});
|
|
1230
1292
|
return {
|
|
@@ -1247,51 +1309,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1247
1309
|
}
|
|
1248
1310
|
}
|
|
1249
1311
|
|
|
1250
|
-
// src/server/handler-helpers.ts
|
|
1251
|
-
function parseHandlerEnvelope(parsedBody) {
|
|
1252
|
-
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1253
|
-
return null;
|
|
1254
|
-
}
|
|
1255
|
-
const envelope = parsedBody;
|
|
1256
|
-
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1257
|
-
return null;
|
|
1258
|
-
}
|
|
1259
|
-
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1260
|
-
return null;
|
|
1261
|
-
}
|
|
1262
|
-
return {
|
|
1263
|
-
env: envelope.env,
|
|
1264
|
-
request: envelope.request,
|
|
1265
|
-
context: envelope.context
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
function buildRequestFromRaw(raw) {
|
|
1269
|
-
let parsedBody = raw.body;
|
|
1270
|
-
const contentType = raw.headers["content-type"] ?? "";
|
|
1271
|
-
if (contentType.includes("application/json")) {
|
|
1272
|
-
try {
|
|
1273
|
-
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1274
|
-
} catch {
|
|
1275
|
-
parsedBody = raw.body;
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
return {
|
|
1279
|
-
method: raw.method,
|
|
1280
|
-
url: raw.url,
|
|
1281
|
-
path: raw.path,
|
|
1282
|
-
headers: raw.headers,
|
|
1283
|
-
query: raw.query,
|
|
1284
|
-
body: parsedBody,
|
|
1285
|
-
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
function buildRequestScopedConfig(env) {
|
|
1289
|
-
return {
|
|
1290
|
-
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1291
|
-
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1292
|
-
};
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
1312
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1296
1313
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1297
1314
|
if (!hooks?.oauth_callback) {
|
|
@@ -1324,9 +1341,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1324
1341
|
try {
|
|
1325
1342
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1326
1343
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1327
|
-
const result = await
|
|
1328
|
-
return await
|
|
1329
|
-
return await
|
|
1344
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1345
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1346
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1347
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1348
|
+
});
|
|
1330
1349
|
});
|
|
1331
1350
|
});
|
|
1332
1351
|
return {
|