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.
@@ -2452,7 +2452,41 @@ var globalConfig = {
2452
2452
  apiToken: process.env.SKEDYUL_API_TOKEN ?? ""
2453
2453
  };
2454
2454
  function runWithConfig(config, fn) {
2455
- return requestConfigStorage.run(config, fn);
2455
+ const originalApiToken = process.env.SKEDYUL_API_TOKEN;
2456
+ const originalApiUrl = process.env.SKEDYUL_API_URL;
2457
+ if (config.apiToken) {
2458
+ process.env.SKEDYUL_API_TOKEN = config.apiToken;
2459
+ }
2460
+ if (config.baseUrl) {
2461
+ process.env.SKEDYUL_API_URL = config.baseUrl;
2462
+ }
2463
+ const restoreProcessEnv = () => {
2464
+ if (config.apiToken) {
2465
+ if (originalApiToken === void 0) {
2466
+ delete process.env.SKEDYUL_API_TOKEN;
2467
+ } else {
2468
+ process.env.SKEDYUL_API_TOKEN = originalApiToken;
2469
+ }
2470
+ }
2471
+ if (config.baseUrl) {
2472
+ if (originalApiUrl === void 0) {
2473
+ delete process.env.SKEDYUL_API_URL;
2474
+ } else {
2475
+ process.env.SKEDYUL_API_URL = originalApiUrl;
2476
+ }
2477
+ }
2478
+ };
2479
+ try {
2480
+ const result = requestConfigStorage.run(config, fn);
2481
+ if (result instanceof Promise) {
2482
+ return result.finally(restoreProcessEnv);
2483
+ }
2484
+ restoreProcessEnv();
2485
+ return result;
2486
+ } catch (error) {
2487
+ restoreProcessEnv();
2488
+ throw error;
2489
+ }
2456
2490
  }
2457
2491
  function getEffectiveConfig() {
2458
2492
  const requestConfig = requestConfigStorage.getStore();
@@ -4593,6 +4627,60 @@ function isProvisionConfig(value) {
4593
4627
  return value !== void 0 && value !== null && !(value instanceof Promise);
4594
4628
  }
4595
4629
 
4630
+ // src/server/handler-helpers.ts
4631
+ function parseHandlerEnvelope(parsedBody) {
4632
+ if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
4633
+ return null;
4634
+ }
4635
+ const envelope = parsedBody;
4636
+ if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
4637
+ return null;
4638
+ }
4639
+ if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
4640
+ return null;
4641
+ }
4642
+ return {
4643
+ env: envelope.env,
4644
+ request: envelope.request,
4645
+ context: envelope.context
4646
+ };
4647
+ }
4648
+ function buildRequestFromRaw(raw) {
4649
+ let parsedBody = raw.body;
4650
+ const contentType = raw.headers["content-type"] ?? "";
4651
+ if (contentType.includes("application/json")) {
4652
+ try {
4653
+ parsedBody = raw.body ? JSON.parse(raw.body) : {};
4654
+ } catch {
4655
+ parsedBody = raw.body;
4656
+ }
4657
+ }
4658
+ return {
4659
+ method: raw.method,
4660
+ url: raw.url,
4661
+ path: raw.path,
4662
+ headers: raw.headers,
4663
+ query: raw.query,
4664
+ body: parsedBody,
4665
+ rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
4666
+ };
4667
+ }
4668
+ function buildRequestScopedConfig(env) {
4669
+ return {
4670
+ baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
4671
+ apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
4672
+ };
4673
+ }
4674
+ async function withRequestEnv(requestEnv, fn) {
4675
+ const originalEnv = { ...process.env };
4676
+ Object.assign(process.env, requestEnv);
4677
+ try {
4678
+ return await fn();
4679
+ } finally {
4680
+ process.env = originalEnv;
4681
+ }
4682
+ }
4683
+
4596
4684
  // src/server/handlers/install-handler.ts
4597
4685
  async function handleInstall(body, hooks) {
4598
4686
  if (!hooks?.install) {
@@ -4627,9 +4715,11 @@ async function handleInstall(body, hooks) {
4627
4715
  try {
4628
4716
  const installHook = hooks.install;
4629
4717
  const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
4630
- const result = await runWithConfig(requestConfig, async () => {
4631
- return await runWithLogContext({ invocation: body.invocation }, async () => {
4632
- return await installHandler(installContext);
4718
+ const result = await withRequestEnv(body.env ?? {}, async () => {
4719
+ return await runWithConfig(requestConfig, async () => {
4720
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
4721
+ return await installHandler(installContext);
4722
+ });
4633
4723
  });
4634
4724
  });
4635
4725
  return {
@@ -4695,9 +4785,11 @@ async function handleUninstall(body, hooks) {
4695
4785
  try {
4696
4786
  const uninstallHook = hooks.uninstall;
4697
4787
  const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
4698
- const result = await runWithConfig(requestConfig, async () => {
4699
- return await runWithLogContext({ invocation: body.invocation }, async () => {
4700
- return await uninstallHandlerFn(uninstallContext);
4788
+ const result = await withRequestEnv(body.env ?? {}, async () => {
4789
+ return await runWithConfig(requestConfig, async () => {
4790
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
4791
+ return await uninstallHandlerFn(uninstallContext);
4792
+ });
4701
4793
  });
4702
4794
  });
4703
4795
  return {
@@ -4756,9 +4848,11 @@ async function handleProvision(body, hooks) {
4756
4848
  try {
4757
4849
  const provisionHook = hooks.provision;
4758
4850
  const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
4759
- const result = await runWithConfig(requestConfig, async () => {
4760
- return await runWithLogContext({ invocation: body.invocation }, async () => {
4761
- return await provisionHandler(provisionContext);
4851
+ const result = await withRequestEnv(body.env ?? {}, async () => {
4852
+ return await runWithConfig(requestConfig, async () => {
4853
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
4854
+ return await provisionHandler(provisionContext);
4855
+ });
4762
4856
  });
4763
4857
  });
4764
4858
  return {
@@ -4816,9 +4910,11 @@ async function handleSetupRevalidate(body, hooks) {
4816
4910
  };
4817
4911
  try {
4818
4912
  const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
4819
- const result = await runWithConfig(requestConfig, async () => {
4820
- return await runWithLogContext({ invocation: body.invocation }, async () => {
4821
- return await handler(ctx);
4913
+ const result = await withRequestEnv(body.env ?? {}, async () => {
4914
+ return await runWithConfig(requestConfig, async () => {
4915
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
4916
+ return await handler(ctx);
4917
+ });
4822
4918
  });
4823
4919
  });
4824
4920
  return {
@@ -4841,51 +4937,6 @@ async function handleSetupRevalidate(body, hooks) {
4841
4937
  }
4842
4938
  }
4843
4939
 
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
4940
  // src/server/handlers/oauth-callback-handler.ts
4890
4941
  async function handleOAuthCallback(parsedBody, hooks) {
4891
4942
  if (!hooks?.oauth_callback) {
@@ -4918,9 +4969,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
4918
4969
  try {
4919
4970
  const oauthCallbackHook = hooks.oauth_callback;
4920
4971
  const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
4921
- const result = await runWithConfig(requestConfig, async () => {
4922
- return await runWithLogContext({ invocation }, async () => {
4923
- return await oauthCallbackHandler(oauthCallbackContext);
4972
+ const result = await withRequestEnv(envelope.env, async () => {
4973
+ return await runWithConfig(requestConfig, async () => {
4974
+ return await runWithLogContext({ invocation }, async () => {
4975
+ return await oauthCallbackHandler(oauthCallbackContext);
4976
+ });
4924
4977
  });
4925
4978
  });
4926
4979
  return {
package/dist/index.js CHANGED
@@ -2841,7 +2841,41 @@ var globalConfig = {
2841
2841
  apiToken: process.env.SKEDYUL_API_TOKEN ?? ""
2842
2842
  };
2843
2843
  function runWithConfig(config, fn) {
2844
- return requestConfigStorage.run(config, fn);
2844
+ const originalApiToken = process.env.SKEDYUL_API_TOKEN;
2845
+ const originalApiUrl = process.env.SKEDYUL_API_URL;
2846
+ if (config.apiToken) {
2847
+ process.env.SKEDYUL_API_TOKEN = config.apiToken;
2848
+ }
2849
+ if (config.baseUrl) {
2850
+ process.env.SKEDYUL_API_URL = config.baseUrl;
2851
+ }
2852
+ const restoreProcessEnv = () => {
2853
+ if (config.apiToken) {
2854
+ if (originalApiToken === void 0) {
2855
+ delete process.env.SKEDYUL_API_TOKEN;
2856
+ } else {
2857
+ process.env.SKEDYUL_API_TOKEN = originalApiToken;
2858
+ }
2859
+ }
2860
+ if (config.baseUrl) {
2861
+ if (originalApiUrl === void 0) {
2862
+ delete process.env.SKEDYUL_API_URL;
2863
+ } else {
2864
+ process.env.SKEDYUL_API_URL = originalApiUrl;
2865
+ }
2866
+ }
2867
+ };
2868
+ try {
2869
+ const result = requestConfigStorage.run(config, fn);
2870
+ if (result instanceof Promise) {
2871
+ return result.finally(restoreProcessEnv);
2872
+ }
2873
+ restoreProcessEnv();
2874
+ return result;
2875
+ } catch (error) {
2876
+ restoreProcessEnv();
2877
+ throw error;
2878
+ }
2845
2879
  }
2846
2880
  function getEffectiveConfig() {
2847
2881
  const requestConfig = requestConfigStorage.getStore();
@@ -4982,6 +5016,60 @@ function isProvisionConfig(value) {
4982
5016
  return value !== void 0 && value !== null && !(value instanceof Promise);
4983
5017
  }
4984
5018
 
5019
+ // src/server/handler-helpers.ts
5020
+ function parseHandlerEnvelope(parsedBody) {
5021
+ if (typeof parsedBody !== "object" || parsedBody === null || Array.isArray(parsedBody) || !("env" in parsedBody) || !("request" in parsedBody)) {
5022
+ return null;
5023
+ }
5024
+ const envelope = parsedBody;
5025
+ if (typeof envelope.env !== "object" || envelope.env === null || Array.isArray(envelope.env)) {
5026
+ return null;
5027
+ }
5028
+ if (typeof envelope.request !== "object" || envelope.request === null || Array.isArray(envelope.request)) {
5029
+ return null;
5030
+ }
5031
+ return {
5032
+ env: envelope.env,
5033
+ request: envelope.request,
5034
+ context: envelope.context
5035
+ };
5036
+ }
5037
+ function buildRequestFromRaw(raw) {
5038
+ let parsedBody = raw.body;
5039
+ const contentType = raw.headers["content-type"] ?? "";
5040
+ if (contentType.includes("application/json")) {
5041
+ try {
5042
+ parsedBody = raw.body ? JSON.parse(raw.body) : {};
5043
+ } catch {
5044
+ parsedBody = raw.body;
5045
+ }
5046
+ }
5047
+ return {
5048
+ method: raw.method,
5049
+ url: raw.url,
5050
+ path: raw.path,
5051
+ headers: raw.headers,
5052
+ query: raw.query,
5053
+ body: parsedBody,
5054
+ rawBody: raw.body ? Buffer.from(raw.body, "utf-8") : void 0
5055
+ };
5056
+ }
5057
+ function buildRequestScopedConfig(env) {
5058
+ return {
5059
+ baseUrl: env.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? "",
5060
+ apiToken: env.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? ""
5061
+ };
5062
+ }
5063
+ async function withRequestEnv(requestEnv, fn) {
5064
+ const originalEnv = { ...process.env };
5065
+ Object.assign(process.env, requestEnv);
5066
+ try {
5067
+ return await fn();
5068
+ } finally {
5069
+ process.env = originalEnv;
5070
+ }
5071
+ }
5072
+
4985
5073
  // src/server/handlers/install-handler.ts
4986
5074
  async function handleInstall(body, hooks) {
4987
5075
  if (!hooks?.install) {
@@ -5016,9 +5104,11 @@ async function handleInstall(body, hooks) {
5016
5104
  try {
5017
5105
  const installHook = hooks.install;
5018
5106
  const installHandler = typeof installHook === "function" ? installHook : installHook.handler;
5019
- const result = await runWithConfig(requestConfig, async () => {
5020
- return await runWithLogContext({ invocation: body.invocation }, async () => {
5021
- return await installHandler(installContext);
5107
+ const result = await withRequestEnv(body.env ?? {}, async () => {
5108
+ return await runWithConfig(requestConfig, async () => {
5109
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
5110
+ return await installHandler(installContext);
5111
+ });
5022
5112
  });
5023
5113
  });
5024
5114
  return {
@@ -5084,9 +5174,11 @@ async function handleUninstall(body, hooks) {
5084
5174
  try {
5085
5175
  const uninstallHook = hooks.uninstall;
5086
5176
  const uninstallHandlerFn = typeof uninstallHook === "function" ? uninstallHook : uninstallHook.handler;
5087
- const result = await runWithConfig(requestConfig, async () => {
5088
- return await runWithLogContext({ invocation: body.invocation }, async () => {
5089
- return await uninstallHandlerFn(uninstallContext);
5177
+ const result = await withRequestEnv(body.env ?? {}, async () => {
5178
+ return await runWithConfig(requestConfig, async () => {
5179
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
5180
+ return await uninstallHandlerFn(uninstallContext);
5181
+ });
5090
5182
  });
5091
5183
  });
5092
5184
  return {
@@ -5145,9 +5237,11 @@ async function handleProvision(body, hooks) {
5145
5237
  try {
5146
5238
  const provisionHook = hooks.provision;
5147
5239
  const provisionHandler = typeof provisionHook === "function" ? provisionHook : provisionHook.handler;
5148
- const result = await runWithConfig(requestConfig, async () => {
5149
- return await runWithLogContext({ invocation: body.invocation }, async () => {
5150
- return await provisionHandler(provisionContext);
5240
+ const result = await withRequestEnv(body.env ?? {}, async () => {
5241
+ return await runWithConfig(requestConfig, async () => {
5242
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
5243
+ return await provisionHandler(provisionContext);
5244
+ });
5151
5245
  });
5152
5246
  });
5153
5247
  return {
@@ -5205,9 +5299,11 @@ async function handleSetupRevalidate(body, hooks) {
5205
5299
  };
5206
5300
  try {
5207
5301
  const handler = typeof revalidateHook === "function" ? revalidateHook : revalidateHook.handler;
5208
- const result = await runWithConfig(requestConfig, async () => {
5209
- return await runWithLogContext({ invocation: body.invocation }, async () => {
5210
- return await handler(ctx);
5302
+ const result = await withRequestEnv(body.env ?? {}, async () => {
5303
+ return await runWithConfig(requestConfig, async () => {
5304
+ return await runWithLogContext({ invocation: body.invocation }, async () => {
5305
+ return await handler(ctx);
5306
+ });
5211
5307
  });
5212
5308
  });
5213
5309
  return {
@@ -5230,51 +5326,6 @@ async function handleSetupRevalidate(body, hooks) {
5230
5326
  }
5231
5327
  }
5232
5328
 
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
5329
  // src/server/handlers/oauth-callback-handler.ts
5279
5330
  async function handleOAuthCallback(parsedBody, hooks) {
5280
5331
  if (!hooks?.oauth_callback) {
@@ -5307,9 +5358,11 @@ async function handleOAuthCallback(parsedBody, hooks) {
5307
5358
  try {
5308
5359
  const oauthCallbackHook = hooks.oauth_callback;
5309
5360
  const oauthCallbackHandler = typeof oauthCallbackHook === "function" ? oauthCallbackHook : oauthCallbackHook.handler;
5310
- const result = await runWithConfig(requestConfig, async () => {
5311
- return await runWithLogContext({ invocation }, async () => {
5312
- return await oauthCallbackHandler(oauthCallbackContext);
5361
+ const result = await withRequestEnv(envelope.env, async () => {
5362
+ return await runWithConfig(requestConfig, async () => {
5363
+ return await runWithLogContext({ invocation }, async () => {
5364
+ return await oauthCallbackHandler(oauthCallbackContext);
5365
+ });
5313
5366
  });
5314
5367
  });
5315
5368
  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>;