authula 0.7.10 → 0.7.11

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.
@@ -17,16 +17,26 @@ function wrapGenerated(mod, client) {
17
17
  wrapped[key] = value;
18
18
  continue;
19
19
  }
20
- if (isHookKey(key)) wrapped[key] = (options, ...rest) => value({
21
- ...options,
22
- request: {
23
- ...options?.request,
20
+ if (isHookKey(key)) wrapped[key] = (...args) => {
21
+ const ctx = {
24
22
  baseUrl,
25
23
  cookies,
26
24
  onBeforeFetch,
27
25
  onAfterFetch
28
- }
29
- }, ...rest);
26
+ };
27
+ let optionsIdx = Math.max(0, value.length - 2);
28
+ if (args[optionsIdx] != null && typeof args[optionsIdx] !== "object") optionsIdx = Math.max(0, value.length - 1);
29
+ while (args.length <= optionsIdx) args.push(void 0);
30
+ const existing = args[optionsIdx] ?? {};
31
+ args[optionsIdx] = {
32
+ ...typeof existing === "object" && existing !== null ? existing : {},
33
+ request: {
34
+ ...existing?.request ?? {},
35
+ ...ctx
36
+ }
37
+ };
38
+ return value(...args);
39
+ };
30
40
  else wrapped[key] = (...args) => {
31
41
  const ctx = {
32
42
  baseUrl,