skedyul 1.7.19 → 1.7.23
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 +114 -61
- package/dist/core/client.d.ts +4 -0
- package/dist/dedicated/server.js +114 -61
- package/dist/esm/index.mjs +114 -61
- package/dist/index.js +114 -61
- package/dist/server/handler-helpers.d.ts +7 -0
- package/dist/server.js +114 -61
- package/dist/serverless/server.mjs +114 -61
- package/package.json +1 -1
package/dist/.build-stamp
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1786335411516
|
package/dist/cli/index.js
CHANGED
|
@@ -1390,7 +1390,41 @@ var globalConfig = {
|
|
|
1390
1390
|
apiToken: process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1391
1391
|
};
|
|
1392
1392
|
function runWithConfig(config, fn) {
|
|
1393
|
-
|
|
1393
|
+
const originalApiToken = process.env.SKEDYUL_API_TOKEN;
|
|
1394
|
+
const originalApiUrl = process.env.SKEDYUL_API_URL;
|
|
1395
|
+
if (config.apiToken) {
|
|
1396
|
+
process.env.SKEDYUL_API_TOKEN = config.apiToken;
|
|
1397
|
+
}
|
|
1398
|
+
if (config.baseUrl) {
|
|
1399
|
+
process.env.SKEDYUL_API_URL = config.baseUrl;
|
|
1400
|
+
}
|
|
1401
|
+
const restoreProcessEnv = () => {
|
|
1402
|
+
if (config.apiToken) {
|
|
1403
|
+
if (originalApiToken === void 0) {
|
|
1404
|
+
delete process.env.SKEDYUL_API_TOKEN;
|
|
1405
|
+
} else {
|
|
1406
|
+
process.env.SKEDYUL_API_TOKEN = originalApiToken;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (config.baseUrl) {
|
|
1410
|
+
if (originalApiUrl === void 0) {
|
|
1411
|
+
delete process.env.SKEDYUL_API_URL;
|
|
1412
|
+
} else {
|
|
1413
|
+
process.env.SKEDYUL_API_URL = originalApiUrl;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
try {
|
|
1418
|
+
const result = requestConfigStorage.run(config, fn);
|
|
1419
|
+
if (result instanceof Promise) {
|
|
1420
|
+
return result.finally(restoreProcessEnv);
|
|
1421
|
+
}
|
|
1422
|
+
restoreProcessEnv();
|
|
1423
|
+
return result;
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
restoreProcessEnv();
|
|
1426
|
+
throw error;
|
|
1427
|
+
}
|
|
1394
1428
|
}
|
|
1395
1429
|
function getEffectiveConfig() {
|
|
1396
1430
|
const requestConfig = requestConfigStorage.getStore();
|
|
@@ -3729,6 +3763,60 @@ function isProvisionConfig(value) {
|
|
|
3729
3763
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
3730
3764
|
}
|
|
3731
3765
|
|
|
3766
|
+
// src/server/handler-helpers.ts
|
|
3767
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
3768
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
3769
|
+
return null;
|
|
3770
|
+
}
|
|
3771
|
+
const envelope = parsedBody;
|
|
3772
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
3773
|
+
return null;
|
|
3774
|
+
}
|
|
3775
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
3776
|
+
return null;
|
|
3777
|
+
}
|
|
3778
|
+
return {
|
|
3779
|
+
env: envelope.env,
|
|
3780
|
+
request: envelope.request,
|
|
3781
|
+
context: envelope.context
|
|
3782
|
+
};
|
|
3783
|
+
}
|
|
3784
|
+
function buildRequestFromRaw(raw) {
|
|
3785
|
+
let parsedBody = raw.body;
|
|
3786
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
3787
|
+
if (contentType.includes("application/json")) {
|
|
3788
|
+
try {
|
|
3789
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
3790
|
+
} catch {
|
|
3791
|
+
parsedBody = raw.body;
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
return {
|
|
3795
|
+
method: raw.method,
|
|
3796
|
+
url: raw.url,
|
|
3797
|
+
path: raw.path,
|
|
3798
|
+
headers: raw.headers,
|
|
3799
|
+
query: raw.query,
|
|
3800
|
+
body: parsedBody,
|
|
3801
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
3802
|
+
};
|
|
3803
|
+
}
|
|
3804
|
+
function buildRequestScopedConfig(env) {
|
|
3805
|
+
return {
|
|
3806
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
3807
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3810
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
3811
|
+
const originalEnv = { ...process.env };
|
|
3812
|
+
Object.assign(process.env, requestEnv);
|
|
3813
|
+
try {
|
|
3814
|
+
return await fn();
|
|
3815
|
+
} finally {
|
|
3816
|
+
process.env = originalEnv;
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3732
3820
|
// src/server/handlers/install-handler.ts
|
|
3733
3821
|
async function handleInstall(body, hooks) {
|
|
3734
3822
|
if (!hooks?.install) {
|
|
@@ -3763,9 +3851,11 @@ async function handleInstall(body, hooks) {
|
|
|
3763
3851
|
try {
|
|
3764
3852
|
const installHook = hooks.install;
|
|
3765
3853
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
3766
|
-
const result = await
|
|
3767
|
-
return await
|
|
3768
|
-
return await
|
|
3854
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3855
|
+
return await runWithConfig(requestConfig, async () => {
|
|
3856
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3857
|
+
return await installHandler(installContext);
|
|
3858
|
+
});
|
|
3769
3859
|
});
|
|
3770
3860
|
});
|
|
3771
3861
|
return {
|
|
@@ -3831,9 +3921,11 @@ async function handleUninstall(body, hooks) {
|
|
|
3831
3921
|
try {
|
|
3832
3922
|
const uninstallHook = hooks.uninstall;
|
|
3833
3923
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
3834
|
-
const result = await
|
|
3835
|
-
return await
|
|
3836
|
-
return await
|
|
3924
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3925
|
+
return await runWithConfig(requestConfig, async () => {
|
|
3926
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3927
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
3928
|
+
});
|
|
3837
3929
|
});
|
|
3838
3930
|
});
|
|
3839
3931
|
return {
|
|
@@ -3892,9 +3984,11 @@ async function handleProvision(body, hooks) {
|
|
|
3892
3984
|
try {
|
|
3893
3985
|
const provisionHook = hooks.provision;
|
|
3894
3986
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
3895
|
-
const result = await
|
|
3896
|
-
return await
|
|
3897
|
-
return await
|
|
3987
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
3988
|
+
return await runWithConfig(requestConfig, async () => {
|
|
3989
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
3990
|
+
return await provisionHandler(provisionContext);
|
|
3991
|
+
});
|
|
3898
3992
|
});
|
|
3899
3993
|
});
|
|
3900
3994
|
return {
|
|
@@ -3952,9 +4046,11 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
3952
4046
|
};
|
|
3953
4047
|
try {
|
|
3954
4048
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
3955
|
-
const result = await
|
|
3956
|
-
return await
|
|
3957
|
-
return await
|
|
4049
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
4050
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4051
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
4052
|
+
return await handler(ctx);
|
|
4053
|
+
});
|
|
3958
4054
|
});
|
|
3959
4055
|
});
|
|
3960
4056
|
return {
|
|
@@ -3977,51 +4073,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
3977
4073
|
}
|
|
3978
4074
|
}
|
|
3979
4075
|
|
|
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
4076
|
// src/server/handlers/oauth-callback-handler.ts
|
|
4026
4077
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
4027
4078
|
if (!hooks?.oauth_callback) {
|
|
@@ -4054,9 +4105,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
4054
4105
|
try {
|
|
4055
4106
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
4056
4107
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
4057
|
-
const result = await
|
|
4058
|
-
return await
|
|
4059
|
-
return await
|
|
4108
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
4109
|
+
return await runWithConfig(requestConfig, async () => {
|
|
4110
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
4111
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
4112
|
+
});
|
|
4060
4113
|
});
|
|
4061
4114
|
});
|
|
4062
4115
|
return {
|
package/dist/core/client.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ type ClientConfig = {
|
|
|
28
28
|
* Run a function with request-scoped configuration.
|
|
29
29
|
* The configuration is isolated to this async context and won't affect other requests.
|
|
30
30
|
*
|
|
31
|
+
* Also mirrors apiToken/baseUrl into process.env for the duration of the call so
|
|
32
|
+
* Lambda handlers still resolve the right token when AsyncLocalStorage is lost
|
|
33
|
+
* across await boundaries (same pattern as withRequestEnv in server hooks).
|
|
34
|
+
*
|
|
31
35
|
* @example
|
|
32
36
|
* ```ts
|
|
33
37
|
* const result = await runWithConfig(
|
package/dist/dedicated/server.js
CHANGED
|
@@ -291,7 +291,41 @@ var globalConfig = {
|
|
|
291
291
|
apiToken: process.env.SKEDYUL_API_TOKEN ?? ""
|
|
292
292
|
};
|
|
293
293
|
function runWithConfig(config, fn) {
|
|
294
|
-
|
|
294
|
+
const originalApiToken = process.env.SKEDYUL_API_TOKEN;
|
|
295
|
+
const originalApiUrl = process.env.SKEDYUL_API_URL;
|
|
296
|
+
if (config.apiToken) {
|
|
297
|
+
process.env.SKEDYUL_API_TOKEN = config.apiToken;
|
|
298
|
+
}
|
|
299
|
+
if (config.baseUrl) {
|
|
300
|
+
process.env.SKEDYUL_API_URL = config.baseUrl;
|
|
301
|
+
}
|
|
302
|
+
const restoreProcessEnv = () => {
|
|
303
|
+
if (config.apiToken) {
|
|
304
|
+
if (originalApiToken === void 0) {
|
|
305
|
+
delete process.env.SKEDYUL_API_TOKEN;
|
|
306
|
+
} else {
|
|
307
|
+
process.env.SKEDYUL_API_TOKEN = originalApiToken;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (config.baseUrl) {
|
|
311
|
+
if (originalApiUrl === void 0) {
|
|
312
|
+
delete process.env.SKEDYUL_API_URL;
|
|
313
|
+
} else {
|
|
314
|
+
process.env.SKEDYUL_API_URL = originalApiUrl;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
try {
|
|
319
|
+
const result = requestConfigStorage.run(config, fn);
|
|
320
|
+
if (result instanceof Promise) {
|
|
321
|
+
return result.finally(restoreProcessEnv);
|
|
322
|
+
}
|
|
323
|
+
restoreProcessEnv();
|
|
324
|
+
return result;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
restoreProcessEnv();
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
295
329
|
}
|
|
296
330
|
|
|
297
331
|
// src/ratelimit/context.ts
|
|
@@ -1038,6 +1072,60 @@ function isProvisionConfig(value) {
|
|
|
1038
1072
|
return value !== void 0 && value !== null && !(value instanceof Promise);
|
|
1039
1073
|
}
|
|
1040
1074
|
|
|
1075
|
+
// src/server/handler-helpers.ts
|
|
1076
|
+
function parseHandlerEnvelope(parsedBody) {
|
|
1077
|
+
if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
const envelope = parsedBody;
|
|
1081
|
+
if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
|
|
1082
|
+
return null;
|
|
1083
|
+
}
|
|
1084
|
+
if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
env: envelope.env,
|
|
1089
|
+
request: envelope.request,
|
|
1090
|
+
context: envelope.context
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
function buildRequestFromRaw(raw) {
|
|
1094
|
+
let parsedBody = raw.body;
|
|
1095
|
+
const contentType = raw.headers["content-type"] ?? "";
|
|
1096
|
+
if (contentType.includes("application/json")) {
|
|
1097
|
+
try {
|
|
1098
|
+
parsedBody = raw.body ? JSON.parse(raw.body) : {};
|
|
1099
|
+
} catch {
|
|
1100
|
+
parsedBody = raw.body;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return {
|
|
1104
|
+
method: raw.method,
|
|
1105
|
+
url: raw.url,
|
|
1106
|
+
path: raw.path,
|
|
1107
|
+
headers: raw.headers,
|
|
1108
|
+
query: raw.query,
|
|
1109
|
+
body: parsedBody,
|
|
1110
|
+
rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
function buildRequestScopedConfig(env) {
|
|
1114
|
+
return {
|
|
1115
|
+
baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
|
|
1116
|
+
apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
async function withRequestEnv(requestEnv, fn) {
|
|
1120
|
+
const originalEnv = { ...process.env };
|
|
1121
|
+
Object.assign(process.env, requestEnv);
|
|
1122
|
+
try {
|
|
1123
|
+
return await fn();
|
|
1124
|
+
} finally {
|
|
1125
|
+
process.env = originalEnv;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1041
1129
|
// src/server/handlers/install-handler.ts
|
|
1042
1130
|
async function handleInstall(body, hooks) {
|
|
1043
1131
|
if (!hooks?.install) {
|
|
@@ -1072,9 +1160,11 @@ async function handleInstall(body, hooks) {
|
|
|
1072
1160
|
try {
|
|
1073
1161
|
const installHook = hooks.install;
|
|
1074
1162
|
const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
|
|
1075
|
-
const result = await
|
|
1076
|
-
return await
|
|
1077
|
-
return await
|
|
1163
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1164
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1165
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1166
|
+
return await installHandler(installContext);
|
|
1167
|
+
});
|
|
1078
1168
|
});
|
|
1079
1169
|
});
|
|
1080
1170
|
return {
|
|
@@ -1140,9 +1230,11 @@ async function handleUninstall(body, hooks) {
|
|
|
1140
1230
|
try {
|
|
1141
1231
|
const uninstallHook = hooks.uninstall;
|
|
1142
1232
|
const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
|
|
1143
|
-
const result = await
|
|
1144
|
-
return await
|
|
1145
|
-
return await
|
|
1233
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1234
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1235
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1236
|
+
return await uninstallHandlerFn(uninstallContext);
|
|
1237
|
+
});
|
|
1146
1238
|
});
|
|
1147
1239
|
});
|
|
1148
1240
|
return {
|
|
@@ -1201,9 +1293,11 @@ async function handleProvision(body, hooks) {
|
|
|
1201
1293
|
try {
|
|
1202
1294
|
const provisionHook = hooks.provision;
|
|
1203
1295
|
const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
|
|
1204
|
-
const result = await
|
|
1205
|
-
return await
|
|
1206
|
-
return await
|
|
1296
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1297
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1298
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1299
|
+
return await provisionHandler(provisionContext);
|
|
1300
|
+
});
|
|
1207
1301
|
});
|
|
1208
1302
|
});
|
|
1209
1303
|
return {
|
|
@@ -1261,9 +1355,11 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1261
1355
|
};
|
|
1262
1356
|
try {
|
|
1263
1357
|
const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
|
|
1264
|
-
const result = await
|
|
1265
|
-
return await
|
|
1266
|
-
return await
|
|
1358
|
+
const result = await withRequestEnv(body.env ?? {}, async () => {
|
|
1359
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1360
|
+
return await runWithLogContext({ invocation: body.invocation }, async () => {
|
|
1361
|
+
return await handler(ctx);
|
|
1362
|
+
});
|
|
1267
1363
|
});
|
|
1268
1364
|
});
|
|
1269
1365
|
return {
|
|
@@ -1286,51 +1382,6 @@ async function handleSetupRevalidate(body, hooks) {
|
|
|
1286
1382
|
}
|
|
1287
1383
|
}
|
|
1288
1384
|
|
|
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
1385
|
// src/server/handlers/oauth-callback-handler.ts
|
|
1335
1386
|
async function handleOAuthCallback(parsedBody, hooks) {
|
|
1336
1387
|
if (!hooks?.oauth_callback) {
|
|
@@ -1363,9 +1414,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
|
|
|
1363
1414
|
try {
|
|
1364
1415
|
const oauthCallbackHook = hooks.oauth_callback;
|
|
1365
1416
|
const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
|
|
1366
|
-
const result = await
|
|
1367
|
-
return await
|
|
1368
|
-
return await
|
|
1417
|
+
const result = await withRequestEnv(envelope.env, async () => {
|
|
1418
|
+
return await runWithConfig(requestConfig, async () => {
|
|
1419
|
+
return await runWithLogContext({ invocation }, async () => {
|
|
1420
|
+
return await oauthCallbackHandler(oauthCallbackContext);
|
|
1421
|
+
});
|
|
1369
1422
|
});
|
|
1370
1423
|
});
|
|
1371
1424
|
return {
|