@slates/provider 1.0.0-rc.10 → 1.0.0-rc.12

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/index.cjs CHANGED
@@ -126,7 +126,10 @@ var import_axios = require("axios");
126
126
 
127
127
  // src/context/hook.ts
128
128
  var import_async_hooks = require("async_hooks");
129
- var asyncLocalStorage = new import_async_hooks.AsyncLocalStorage();
129
+ var slateContextStorageKey = /* @__PURE__ */ Symbol.for("slates.provider.context.asyncLocalStorage");
130
+ var globalWithSlateContext = globalThis;
131
+ var asyncLocalStorage = globalWithSlateContext[slateContextStorageKey] ?? new import_async_hooks.AsyncLocalStorage();
132
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
130
133
  var runWithContext = (context, fn) => {
131
134
  return asyncLocalStorage.run(context, fn);
132
135
  };
@@ -1539,7 +1542,8 @@ var applySlateInterceptors = (instance, errorMapping) => {
1539
1542
  (request) => {
1540
1543
  let ctx = getCurrentContext();
1541
1544
  let spec2 = ctx.specification;
1542
- request.headers.set("User-Agent", `slates.dev@1.0.0/${spec2.key}`);
1545
+ let providerToken = spec2.key.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, "-");
1546
+ request.headers.set("User-Agent", `slates.dev/1.0.0 ${providerToken || "unknown"}`);
1543
1547
  request.headers.set("X-Slates-Provider", spec2.key);
1544
1548
  let tracedRequest = attachHttpTraceDraft(request, ctx);
1545
1549
  if (!tracedRequest.__slatesTraceAdapterWrapped) {
package/dist/index.d.cts CHANGED
@@ -92,6 +92,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
92
92
  clientId: string;
93
93
  clientSecret: string;
94
94
  scopes: string[];
95
+ callbackParams?: Record<string, string>;
95
96
  callbackState: Record<string, any>;
96
97
  }) => Promise<{
97
98
  output: OutputType;
@@ -176,6 +177,16 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
176
177
  }) => Promise<{
177
178
  output: OutputType;
178
179
  }>;
180
+ handleTokenRefresh?: (ctx: {
181
+ output: OutputType;
182
+ input: InputType;
183
+ clientId: string;
184
+ clientSecret: string;
185
+ scopes: string[];
186
+ }) => Promise<{
187
+ output: OutputType;
188
+ input?: InputType;
189
+ }>;
179
190
  onInputChanged?: (params: {
180
191
  previousInput: InputType;
181
192
  newInput: InputType;
package/dist/index.d.ts CHANGED
@@ -92,6 +92,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
92
92
  clientId: string;
93
93
  clientSecret: string;
94
94
  scopes: string[];
95
+ callbackParams?: Record<string, string>;
95
96
  callbackState: Record<string, any>;
96
97
  }) => Promise<{
97
98
  output: OutputType;
@@ -176,6 +177,16 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
176
177
  }) => Promise<{
177
178
  output: OutputType;
178
179
  }>;
180
+ handleTokenRefresh?: (ctx: {
181
+ output: OutputType;
182
+ input: InputType;
183
+ clientId: string;
184
+ clientSecret: string;
185
+ scopes: string[];
186
+ }) => Promise<{
187
+ output: OutputType;
188
+ input?: InputType;
189
+ }>;
179
190
  onInputChanged?: (params: {
180
191
  previousInput: InputType;
181
192
  newInput: InputType;
@@ -55,7 +55,10 @@ import { isAxiosError } from "axios";
55
55
 
56
56
  // src/context/hook.ts
57
57
  import { AsyncLocalStorage } from "async_hooks";
58
- var asyncLocalStorage = new AsyncLocalStorage();
58
+ var slateContextStorageKey = /* @__PURE__ */ Symbol.for("slates.provider.context.asyncLocalStorage");
59
+ var globalWithSlateContext = globalThis;
60
+ var asyncLocalStorage = globalWithSlateContext[slateContextStorageKey] ?? new AsyncLocalStorage();
61
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
59
62
  var runWithContext = (context, fn) => {
60
63
  return asyncLocalStorage.run(context, fn);
61
64
  };
@@ -1468,7 +1471,8 @@ var applySlateInterceptors = (instance, errorMapping) => {
1468
1471
  (request) => {
1469
1472
  let ctx = getCurrentContext();
1470
1473
  let spec2 = ctx.specification;
1471
- request.headers.set("User-Agent", `slates.dev@1.0.0/${spec2.key}`);
1474
+ let providerToken = spec2.key.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, "-");
1475
+ request.headers.set("User-Agent", `slates.dev/1.0.0 ${providerToken || "unknown"}`);
1472
1476
  request.headers.set("X-Slates-Provider", spec2.key);
1473
1477
  let tracedRequest = attachHttpTraceDraft(request, ctx);
1474
1478
  if (!tracedRequest.__slatesTraceAdapterWrapped) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider",
3
- "version": "1.0.0-rc.10",
3
+ "version": "1.0.0-rc.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/auth/types.ts CHANGED
@@ -50,6 +50,7 @@ export type SlateAuthWithOauth<
50
50
  clientId: string;
51
51
  clientSecret: string;
52
52
  scopes: string[];
53
+ callbackParams?: Record<string, string>;
53
54
  callbackState: Record<string, any>;
54
55
  }) => Promise<{
55
56
  output: OutputType;
@@ -127,6 +128,17 @@ export type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}>
127
128
 
128
129
  getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
129
130
 
131
+ handleTokenRefresh?: (ctx: {
132
+ output: OutputType;
133
+ input: InputType;
134
+ clientId: string;
135
+ clientSecret: string;
136
+ scopes: string[];
137
+ }) => Promise<{
138
+ output: OutputType;
139
+ input?: InputType;
140
+ }>;
141
+
130
142
  onInputChanged?: (params: {
131
143
  previousInput: InputType;
132
144
  newInput: InputType;
@@ -19,11 +19,12 @@ let applySlateInterceptors = (
19
19
  ) => {
20
20
  instance.interceptors.request.use(
21
21
  request => {
22
- // Has to be called in the context of an action execution
22
+ // Has to be called in the context of an action execution
23
23
  let ctx = getCurrentContext();
24
24
  let spec = ctx.specification;
25
+ let providerToken = spec.key.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, '-');
25
26
 
26
- request.headers.set('User-Agent', `slates.dev@1.0.0/${spec.key}`);
27
+ request.headers.set('User-Agent', `slates.dev/1.0.0 ${providerToken || 'unknown'}`);
27
28
  request.headers.set('X-Slates-Provider', spec.key);
28
29
 
29
30
  let tracedRequest = attachHttpTraceDraft(request, ctx) as InternalAxiosRequestConfig & {
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { SlateContext } from './context';
3
+ import { runWithContext } from './hook';
4
+
5
+ describe('slate context hook', () => {
6
+ it('shares context storage across duplicate module instances', async () => {
7
+ // @ts-expect-error Vite treats the query as a distinct module instance.
8
+ let duplicateHook: typeof import('./hook') = await import('./hook?duplicate-instance');
9
+ let context = new SlateContext({}, {}, {}, {} as any, {
10
+ debug: () => {},
11
+ error: () => {},
12
+ info: () => {},
13
+ progress: () => {},
14
+ warn: () => {}
15
+ } as any);
16
+
17
+ let result = await runWithContext(context, async () => duplicateHook.getCurrentContext());
18
+
19
+ expect(result).toBe(context);
20
+ });
21
+ });
@@ -1,7 +1,16 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
2
  import type { SlateContext } from './context';
3
3
 
4
- let asyncLocalStorage = new AsyncLocalStorage<SlateContext<any, any, any>>();
4
+ let slateContextStorageKey = Symbol.for('slates.provider.context.asyncLocalStorage');
5
+ let globalWithSlateContext = globalThis as typeof globalThis & {
6
+ [key: symbol]: AsyncLocalStorage<SlateContext<any, any, any>> | undefined;
7
+ };
8
+
9
+ let asyncLocalStorage =
10
+ globalWithSlateContext[slateContextStorageKey] ??
11
+ new AsyncLocalStorage<SlateContext<any, any, any>>();
12
+
13
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
5
14
 
6
15
  export let runWithContext = <
7
16
  ConfigType extends {},