@slates/provider 1.0.0-rc.11 → 1.0.0-rc.14
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 +16 -15
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.module.js +16 -15
- package/package.json +4 -4
- package/src/action/builder.ts +1 -1
- package/src/action/index.ts +1 -1
- package/src/action/scopes.test.ts +4 -5
- package/src/action/scopes.ts +3 -1
- package/src/auth/types.ts +29 -1
- package/src/axios/index.ts +1 -1
- package/src/axios/trace.test.ts +6 -7
- package/src/axios/trace.ts +8 -15
- package/src/context/hook.test.ts +27 -0
- package/src/context/hook.ts +10 -1
- package/src/error/service.ts +17 -7
- package/src/error/types.ts +1 -1
- package/src/error/utils.ts +1 -1
- package/src/logger/logger.test.ts +1 -1
- package/src/specification/specification.ts +2 -4
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
|
|
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
|
};
|
|
@@ -230,7 +233,7 @@ var normalizeRetryable = (code, retryable) => {
|
|
|
230
233
|
return code === "request.rate_limited" || code === "upstream.rate_limited" || code === "upstream.timeout" || code === "upstream.network_error" || code === "upstream.unavailable" || code === "upstream.error" || code === "transport.invoke_failed" || code === "internal.timeout";
|
|
231
234
|
};
|
|
232
235
|
var getDefaultMessage = (code, message) => {
|
|
233
|
-
if (message
|
|
236
|
+
if (message?.trim()) return message;
|
|
234
237
|
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
235
238
|
};
|
|
236
239
|
var cleanRecord = (value) => {
|
|
@@ -507,7 +510,9 @@ var normalizeServiceErrorIssues = (errors) => {
|
|
|
507
510
|
return issues.length > 0 ? issues : void 0;
|
|
508
511
|
};
|
|
509
512
|
var getServiceErrorBaggage = (data) => {
|
|
510
|
-
let extraEntries = Object.entries(data).filter(
|
|
513
|
+
let extraEntries = Object.entries(data).filter(
|
|
514
|
+
([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key)
|
|
515
|
+
);
|
|
511
516
|
return cleanRecord({
|
|
512
517
|
serviceError: {
|
|
513
518
|
code: data.code,
|
|
@@ -725,7 +730,9 @@ var normalizeClause = (input) => {
|
|
|
725
730
|
};
|
|
726
731
|
var assertScopeValues = (scopes) => {
|
|
727
732
|
if (scopes.length === 0) {
|
|
728
|
-
throw new SlateDeclarationError(
|
|
733
|
+
throw new SlateDeclarationError(
|
|
734
|
+
"Each action scope clause must include at least one OR scope"
|
|
735
|
+
);
|
|
729
736
|
}
|
|
730
737
|
for (let scope of scopes) {
|
|
731
738
|
if (typeof scope !== "string" || scope.trim().length === 0) {
|
|
@@ -1131,15 +1138,9 @@ var CORE_SECRET_KEY_ATOMS = [
|
|
|
1131
1138
|
"license[-_.]?key"
|
|
1132
1139
|
];
|
|
1133
1140
|
var URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, "code"];
|
|
1134
|
-
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(
|
|
1135
|
-
`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`,
|
|
1136
|
-
flags
|
|
1137
|
-
);
|
|
1141
|
+
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`, flags);
|
|
1138
1142
|
var SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, "i");
|
|
1139
|
-
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
1140
|
-
URL_FORM_SECRET_KEY_ATOMS,
|
|
1141
|
-
"i"
|
|
1142
|
-
);
|
|
1143
|
+
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(URL_FORM_SECRET_KEY_ATOMS, "i");
|
|
1143
1144
|
var NON_SECRET_KEY_EXACT = /* @__PURE__ */ new Set([
|
|
1144
1145
|
"token_type",
|
|
1145
1146
|
"token-type",
|
|
@@ -1317,7 +1318,7 @@ var redactStructuredValue = (value, depth = 0) => {
|
|
|
1317
1318
|
var maybeParseJson = (text, contentType) => {
|
|
1318
1319
|
let trimmed = text.trim();
|
|
1319
1320
|
if (!trimmed) return null;
|
|
1320
|
-
if (!contentType?.includes("json") && !/^[
|
|
1321
|
+
if (!contentType?.includes("json") && !/^[[{]/.test(trimmed)) {
|
|
1321
1322
|
return null;
|
|
1322
1323
|
}
|
|
1323
1324
|
try {
|
|
@@ -1377,7 +1378,7 @@ var buildUrl = (baseURL, url) => {
|
|
|
1377
1378
|
var REDACTED_ENCODED = encodeURIComponent(REDACTED_VALUE);
|
|
1378
1379
|
var decodeRedactedMarker = (value) => REDACTED_ENCODED === REDACTED_VALUE ? value : value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
1379
1380
|
var redactHashFragment = (hash) => {
|
|
1380
|
-
if (!hash
|
|
1381
|
+
if (!hash?.includes("=")) return hash;
|
|
1381
1382
|
let withoutHash = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1382
1383
|
let redacted = withoutHash.replace(
|
|
1383
1384
|
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
@@ -1455,7 +1456,7 @@ var takeTraceDraft = (config2) => {
|
|
|
1455
1456
|
var clearTraceDraft = (config2, draft) => {
|
|
1456
1457
|
if (!config2) return;
|
|
1457
1458
|
if (config2.__slatesHttpTraceDraft === draft) {
|
|
1458
|
-
|
|
1459
|
+
config2.__slatesHttpTraceDraft = void 0;
|
|
1459
1460
|
}
|
|
1460
1461
|
if (isObjectLike(config2)) {
|
|
1461
1462
|
traceDraftsByConfig.delete(config2);
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,7 @@ declare class SlateLogger {
|
|
|
50
50
|
progress(...message: SlateLogMessageInput[]): void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
53
54
|
type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
54
55
|
token: string;
|
|
55
56
|
refreshToken?: string;
|
|
@@ -64,6 +65,10 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
64
65
|
defaultChecked?: boolean;
|
|
65
66
|
scope: string;
|
|
66
67
|
}[];
|
|
68
|
+
docs?: {
|
|
69
|
+
oauthDocsLink?: string;
|
|
70
|
+
oauthScopesLink?: string;
|
|
71
|
+
};
|
|
67
72
|
inputSchema?: z.ZodType<InputType>;
|
|
68
73
|
onInputChanged?: (params: {
|
|
69
74
|
previousInput: InputType | null;
|
|
@@ -79,6 +84,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
79
84
|
clientId: string;
|
|
80
85
|
clientSecret: string;
|
|
81
86
|
scopes: string[];
|
|
87
|
+
config?: SlateAuthCallbackConfig;
|
|
82
88
|
}) => Promise<{
|
|
83
89
|
url: string;
|
|
84
90
|
input?: InputType;
|
|
@@ -92,7 +98,9 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
92
98
|
clientId: string;
|
|
93
99
|
clientSecret: string;
|
|
94
100
|
scopes: string[];
|
|
101
|
+
callbackParams?: Record<string, string>;
|
|
95
102
|
callbackState: Record<string, any>;
|
|
103
|
+
config?: SlateAuthCallbackConfig;
|
|
96
104
|
}) => Promise<{
|
|
97
105
|
output: OutputType;
|
|
98
106
|
input?: InputType;
|
|
@@ -104,6 +112,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
104
112
|
clientId: string;
|
|
105
113
|
clientSecret: string;
|
|
106
114
|
scopes: string[];
|
|
115
|
+
config?: SlateAuthCallbackConfig;
|
|
107
116
|
}) => Promise<{
|
|
108
117
|
output: OutputType;
|
|
109
118
|
input?: InputType;
|
|
@@ -112,6 +121,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
112
121
|
output: OutputType;
|
|
113
122
|
input: InputType;
|
|
114
123
|
scopes: string[];
|
|
124
|
+
config?: SlateAuthCallbackConfig;
|
|
115
125
|
}) => Promise<{
|
|
116
126
|
profile: Record<string, any>;
|
|
117
127
|
}>;
|
|
@@ -123,6 +133,9 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
|
|
|
123
133
|
name: string;
|
|
124
134
|
key: string;
|
|
125
135
|
inputSchema?: z.ZodType<InputType>;
|
|
136
|
+
docs?: {
|
|
137
|
+
tokenDocsLink?: string;
|
|
138
|
+
};
|
|
126
139
|
getOutput: (ctx: {
|
|
127
140
|
input: InputType;
|
|
128
141
|
}) => Promise<{
|
|
@@ -147,6 +160,9 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
|
|
|
147
160
|
name: string;
|
|
148
161
|
key: string;
|
|
149
162
|
inputSchema?: z.ZodType<InputType>;
|
|
163
|
+
docs?: {
|
|
164
|
+
serviceAccountDocsLink?: string;
|
|
165
|
+
};
|
|
150
166
|
getOutput: (ctx: {
|
|
151
167
|
input: InputType;
|
|
152
168
|
}) => Promise<{
|
|
@@ -171,6 +187,9 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
|
|
|
171
187
|
name: string;
|
|
172
188
|
key: string;
|
|
173
189
|
inputSchema?: z.ZodType<InputType>;
|
|
190
|
+
docs?: {
|
|
191
|
+
customAuthDocsLink?: string;
|
|
192
|
+
};
|
|
174
193
|
getOutput: (ctx: {
|
|
175
194
|
input: InputType;
|
|
176
195
|
}) => Promise<{
|
|
@@ -454,15 +473,6 @@ declare abstract class SlateAction<Type extends SlateActionType, ConfigType exte
|
|
|
454
473
|
get scopes(): SlateActionScopes | undefined;
|
|
455
474
|
}
|
|
456
475
|
|
|
457
|
-
type SlateActionScopeValue = string;
|
|
458
|
-
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
459
|
-
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
460
|
-
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
461
|
-
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
462
|
-
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
463
|
-
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
464
|
-
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
465
|
-
|
|
466
476
|
declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}, Result extends SlateAction<Type, ConfigType, AuthType, any, any>> {
|
|
467
477
|
#private;
|
|
468
478
|
private readonly type;
|
|
@@ -488,6 +498,15 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
|
|
|
488
498
|
build(): Result;
|
|
489
499
|
}
|
|
490
500
|
|
|
501
|
+
type SlateActionScopeValue = string;
|
|
502
|
+
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
503
|
+
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
504
|
+
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
505
|
+
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
506
|
+
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
507
|
+
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
508
|
+
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
509
|
+
|
|
491
510
|
interface SlateToolParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateActionParameters {
|
|
492
511
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
493
512
|
}
|
|
@@ -584,7 +603,7 @@ interface SlateErrorInput extends Omit<SlateErrorResponse, 'kind'> {
|
|
|
584
603
|
interface SlateAxiosErrorOptions {
|
|
585
604
|
defaults?: Partial<SlateErrorResponse>;
|
|
586
605
|
extractResponseData?: (response: AxiosResponse) => unknown;
|
|
587
|
-
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> |
|
|
606
|
+
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> | undefined;
|
|
588
607
|
}
|
|
589
608
|
interface SlateServiceErrorData {
|
|
590
609
|
status: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ declare class SlateLogger {
|
|
|
50
50
|
progress(...message: SlateLogMessageInput[]): void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
53
54
|
type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
54
55
|
token: string;
|
|
55
56
|
refreshToken?: string;
|
|
@@ -64,6 +65,10 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
64
65
|
defaultChecked?: boolean;
|
|
65
66
|
scope: string;
|
|
66
67
|
}[];
|
|
68
|
+
docs?: {
|
|
69
|
+
oauthDocsLink?: string;
|
|
70
|
+
oauthScopesLink?: string;
|
|
71
|
+
};
|
|
67
72
|
inputSchema?: z.ZodType<InputType>;
|
|
68
73
|
onInputChanged?: (params: {
|
|
69
74
|
previousInput: InputType | null;
|
|
@@ -79,6 +84,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
79
84
|
clientId: string;
|
|
80
85
|
clientSecret: string;
|
|
81
86
|
scopes: string[];
|
|
87
|
+
config?: SlateAuthCallbackConfig;
|
|
82
88
|
}) => Promise<{
|
|
83
89
|
url: string;
|
|
84
90
|
input?: InputType;
|
|
@@ -92,7 +98,9 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
92
98
|
clientId: string;
|
|
93
99
|
clientSecret: string;
|
|
94
100
|
scopes: string[];
|
|
101
|
+
callbackParams?: Record<string, string>;
|
|
95
102
|
callbackState: Record<string, any>;
|
|
103
|
+
config?: SlateAuthCallbackConfig;
|
|
96
104
|
}) => Promise<{
|
|
97
105
|
output: OutputType;
|
|
98
106
|
input?: InputType;
|
|
@@ -104,6 +112,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
104
112
|
clientId: string;
|
|
105
113
|
clientSecret: string;
|
|
106
114
|
scopes: string[];
|
|
115
|
+
config?: SlateAuthCallbackConfig;
|
|
107
116
|
}) => Promise<{
|
|
108
117
|
output: OutputType;
|
|
109
118
|
input?: InputType;
|
|
@@ -112,6 +121,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
112
121
|
output: OutputType;
|
|
113
122
|
input: InputType;
|
|
114
123
|
scopes: string[];
|
|
124
|
+
config?: SlateAuthCallbackConfig;
|
|
115
125
|
}) => Promise<{
|
|
116
126
|
profile: Record<string, any>;
|
|
117
127
|
}>;
|
|
@@ -123,6 +133,9 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
|
|
|
123
133
|
name: string;
|
|
124
134
|
key: string;
|
|
125
135
|
inputSchema?: z.ZodType<InputType>;
|
|
136
|
+
docs?: {
|
|
137
|
+
tokenDocsLink?: string;
|
|
138
|
+
};
|
|
126
139
|
getOutput: (ctx: {
|
|
127
140
|
input: InputType;
|
|
128
141
|
}) => Promise<{
|
|
@@ -147,6 +160,9 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
|
|
|
147
160
|
name: string;
|
|
148
161
|
key: string;
|
|
149
162
|
inputSchema?: z.ZodType<InputType>;
|
|
163
|
+
docs?: {
|
|
164
|
+
serviceAccountDocsLink?: string;
|
|
165
|
+
};
|
|
150
166
|
getOutput: (ctx: {
|
|
151
167
|
input: InputType;
|
|
152
168
|
}) => Promise<{
|
|
@@ -171,6 +187,9 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
|
|
|
171
187
|
name: string;
|
|
172
188
|
key: string;
|
|
173
189
|
inputSchema?: z.ZodType<InputType>;
|
|
190
|
+
docs?: {
|
|
191
|
+
customAuthDocsLink?: string;
|
|
192
|
+
};
|
|
174
193
|
getOutput: (ctx: {
|
|
175
194
|
input: InputType;
|
|
176
195
|
}) => Promise<{
|
|
@@ -454,15 +473,6 @@ declare abstract class SlateAction<Type extends SlateActionType, ConfigType exte
|
|
|
454
473
|
get scopes(): SlateActionScopes | undefined;
|
|
455
474
|
}
|
|
456
475
|
|
|
457
|
-
type SlateActionScopeValue = string;
|
|
458
|
-
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
459
|
-
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
460
|
-
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
461
|
-
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
462
|
-
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
463
|
-
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
464
|
-
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
465
|
-
|
|
466
476
|
declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}, Result extends SlateAction<Type, ConfigType, AuthType, any, any>> {
|
|
467
477
|
#private;
|
|
468
478
|
private readonly type;
|
|
@@ -488,6 +498,15 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
|
|
|
488
498
|
build(): Result;
|
|
489
499
|
}
|
|
490
500
|
|
|
501
|
+
type SlateActionScopeValue = string;
|
|
502
|
+
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
503
|
+
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
504
|
+
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
505
|
+
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
506
|
+
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
507
|
+
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
508
|
+
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
509
|
+
|
|
491
510
|
interface SlateToolParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateActionParameters {
|
|
492
511
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
493
512
|
}
|
|
@@ -584,7 +603,7 @@ interface SlateErrorInput extends Omit<SlateErrorResponse, 'kind'> {
|
|
|
584
603
|
interface SlateAxiosErrorOptions {
|
|
585
604
|
defaults?: Partial<SlateErrorResponse>;
|
|
586
605
|
extractResponseData?: (response: AxiosResponse) => unknown;
|
|
587
|
-
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> |
|
|
606
|
+
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> | undefined;
|
|
588
607
|
}
|
|
589
608
|
interface SlateServiceErrorData {
|
|
590
609
|
status: number;
|
package/dist/index.module.js
CHANGED
|
@@ -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
|
|
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
|
};
|
|
@@ -159,7 +162,7 @@ var normalizeRetryable = (code, retryable) => {
|
|
|
159
162
|
return code === "request.rate_limited" || code === "upstream.rate_limited" || code === "upstream.timeout" || code === "upstream.network_error" || code === "upstream.unavailable" || code === "upstream.error" || code === "transport.invoke_failed" || code === "internal.timeout";
|
|
160
163
|
};
|
|
161
164
|
var getDefaultMessage = (code, message) => {
|
|
162
|
-
if (message
|
|
165
|
+
if (message?.trim()) return message;
|
|
163
166
|
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
164
167
|
};
|
|
165
168
|
var cleanRecord = (value) => {
|
|
@@ -436,7 +439,9 @@ var normalizeServiceErrorIssues = (errors) => {
|
|
|
436
439
|
return issues.length > 0 ? issues : void 0;
|
|
437
440
|
};
|
|
438
441
|
var getServiceErrorBaggage = (data) => {
|
|
439
|
-
let extraEntries = Object.entries(data).filter(
|
|
442
|
+
let extraEntries = Object.entries(data).filter(
|
|
443
|
+
([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key)
|
|
444
|
+
);
|
|
440
445
|
return cleanRecord({
|
|
441
446
|
serviceError: {
|
|
442
447
|
code: data.code,
|
|
@@ -654,7 +659,9 @@ var normalizeClause = (input) => {
|
|
|
654
659
|
};
|
|
655
660
|
var assertScopeValues = (scopes) => {
|
|
656
661
|
if (scopes.length === 0) {
|
|
657
|
-
throw new SlateDeclarationError(
|
|
662
|
+
throw new SlateDeclarationError(
|
|
663
|
+
"Each action scope clause must include at least one OR scope"
|
|
664
|
+
);
|
|
658
665
|
}
|
|
659
666
|
for (let scope of scopes) {
|
|
660
667
|
if (typeof scope !== "string" || scope.trim().length === 0) {
|
|
@@ -1060,15 +1067,9 @@ var CORE_SECRET_KEY_ATOMS = [
|
|
|
1060
1067
|
"license[-_.]?key"
|
|
1061
1068
|
];
|
|
1062
1069
|
var URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, "code"];
|
|
1063
|
-
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(
|
|
1064
|
-
`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`,
|
|
1065
|
-
flags
|
|
1066
|
-
);
|
|
1070
|
+
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`, flags);
|
|
1067
1071
|
var SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, "i");
|
|
1068
|
-
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
1069
|
-
URL_FORM_SECRET_KEY_ATOMS,
|
|
1070
|
-
"i"
|
|
1071
|
-
);
|
|
1072
|
+
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(URL_FORM_SECRET_KEY_ATOMS, "i");
|
|
1072
1073
|
var NON_SECRET_KEY_EXACT = /* @__PURE__ */ new Set([
|
|
1073
1074
|
"token_type",
|
|
1074
1075
|
"token-type",
|
|
@@ -1246,7 +1247,7 @@ var redactStructuredValue = (value, depth = 0) => {
|
|
|
1246
1247
|
var maybeParseJson = (text, contentType) => {
|
|
1247
1248
|
let trimmed = text.trim();
|
|
1248
1249
|
if (!trimmed) return null;
|
|
1249
|
-
if (!contentType?.includes("json") && !/^[
|
|
1250
|
+
if (!contentType?.includes("json") && !/^[[{]/.test(trimmed)) {
|
|
1250
1251
|
return null;
|
|
1251
1252
|
}
|
|
1252
1253
|
try {
|
|
@@ -1306,7 +1307,7 @@ var buildUrl = (baseURL, url) => {
|
|
|
1306
1307
|
var REDACTED_ENCODED = encodeURIComponent(REDACTED_VALUE);
|
|
1307
1308
|
var decodeRedactedMarker = (value) => REDACTED_ENCODED === REDACTED_VALUE ? value : value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
1308
1309
|
var redactHashFragment = (hash) => {
|
|
1309
|
-
if (!hash
|
|
1310
|
+
if (!hash?.includes("=")) return hash;
|
|
1310
1311
|
let withoutHash = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1311
1312
|
let redacted = withoutHash.replace(
|
|
1312
1313
|
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
@@ -1384,7 +1385,7 @@ var takeTraceDraft = (config2) => {
|
|
|
1384
1385
|
var clearTraceDraft = (config2, draft) => {
|
|
1385
1386
|
if (!config2) return;
|
|
1386
1387
|
if (config2.__slatesHttpTraceDraft === draft) {
|
|
1387
|
-
|
|
1388
|
+
config2.__slatesHttpTraceDraft = void 0;
|
|
1388
1389
|
}
|
|
1389
1390
|
if (isObjectLike(config2)) {
|
|
1390
1391
|
traceDraftsByConfig.delete(config2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/provider",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.14",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"unpkg": "./dist/index.module.js",
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "vitest run --passWithNoTests",
|
|
29
|
-
"lint": "prettier src/**/*.ts --check",
|
|
30
29
|
"build": "tsup --config ../../tsup.packages.config.ts --external async_hooks",
|
|
31
|
-
"typecheck": "tsc --noEmit"
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"biome:check": "biome check --write src"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@lowerdeck/error": "^1.1.0",
|
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
"typescript": "5.8.2",
|
|
43
43
|
"vitest": "^3.1.2"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
package/src/action/builder.ts
CHANGED
|
@@ -4,10 +4,10 @@ import type { SlateSpecification } from '../specification/specification';
|
|
|
4
4
|
import type {
|
|
5
5
|
SlateAction,
|
|
6
6
|
SlateActionCreateParameters,
|
|
7
|
-
SlateActionScopes,
|
|
8
7
|
SlateActionParameters,
|
|
9
8
|
SlateActionParametersTool,
|
|
10
9
|
SlateActionParametersTrigger,
|
|
10
|
+
SlateActionScopes,
|
|
11
11
|
SlateActionType,
|
|
12
12
|
SlatePollingOptions,
|
|
13
13
|
SlateToolInvocationHandler,
|
package/src/action/index.ts
CHANGED
|
@@ -12,10 +12,7 @@ describe('action scope helpers', () => {
|
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
expect(allOf(['scope:calendar'], ['scope:sharing', 'scope:sharing:admin'])).toEqual({
|
|
15
|
-
AND: [
|
|
16
|
-
{ OR: ['scope:calendar'] },
|
|
17
|
-
{ OR: ['scope:sharing', 'scope:sharing:admin'] }
|
|
18
|
-
]
|
|
15
|
+
AND: [{ OR: ['scope:calendar'] }, { OR: ['scope:sharing', 'scope:sharing:admin'] }]
|
|
19
16
|
});
|
|
20
17
|
});
|
|
21
18
|
|
|
@@ -68,7 +65,9 @@ describe('action scope helpers', () => {
|
|
|
68
65
|
});
|
|
69
66
|
|
|
70
67
|
it('throws helpful errors for invalid scope definitions', () => {
|
|
71
|
-
expect(() => scopeClause()).toThrow(
|
|
68
|
+
expect(() => scopeClause()).toThrow(
|
|
69
|
+
'Each action scope clause must include at least one OR scope'
|
|
70
|
+
);
|
|
72
71
|
expect(() => scopeClause('')).toThrow('Action scopes must be non-empty strings');
|
|
73
72
|
expect(() => validateScopes({ AND: [] })).toThrow(
|
|
74
73
|
'Action scopes must include at least one AND clause'
|
package/src/action/scopes.ts
CHANGED
|
@@ -78,7 +78,9 @@ let normalizeClause = (input: SlateActionScopeClauseInput): SlateActionScopeClau
|
|
|
78
78
|
|
|
79
79
|
let assertScopeValues = (scopes: readonly SlateActionScopeValue[]) => {
|
|
80
80
|
if (scopes.length === 0) {
|
|
81
|
-
throw new SlateDeclarationError(
|
|
81
|
+
throw new SlateDeclarationError(
|
|
82
|
+
'Each action scope clause must include at least one OR scope'
|
|
83
|
+
);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
for (let scope of scopes) {
|
package/src/auth/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
2
|
|
|
3
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
4
|
+
|
|
3
5
|
export type SlateAuthWithOauth<
|
|
4
6
|
InputType extends {},
|
|
5
7
|
OutputType extends {
|
|
@@ -20,6 +22,11 @@ export type SlateAuthWithOauth<
|
|
|
20
22
|
scope: string;
|
|
21
23
|
}[];
|
|
22
24
|
|
|
25
|
+
docs?: {
|
|
26
|
+
oauthDocsLink?: string;
|
|
27
|
+
oauthScopesLink?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
23
30
|
inputSchema?: z.ZodType<InputType>;
|
|
24
31
|
|
|
25
32
|
onInputChanged?: (params: {
|
|
@@ -36,6 +43,7 @@ export type SlateAuthWithOauth<
|
|
|
36
43
|
clientId: string;
|
|
37
44
|
clientSecret: string;
|
|
38
45
|
scopes: string[];
|
|
46
|
+
config?: SlateAuthCallbackConfig;
|
|
39
47
|
}) => Promise<{
|
|
40
48
|
url: string;
|
|
41
49
|
input?: InputType;
|
|
@@ -50,7 +58,9 @@ export type SlateAuthWithOauth<
|
|
|
50
58
|
clientId: string;
|
|
51
59
|
clientSecret: string;
|
|
52
60
|
scopes: string[];
|
|
61
|
+
callbackParams?: Record<string, string>;
|
|
53
62
|
callbackState: Record<string, any>;
|
|
63
|
+
config?: SlateAuthCallbackConfig;
|
|
54
64
|
}) => Promise<{
|
|
55
65
|
output: OutputType;
|
|
56
66
|
input?: InputType;
|
|
@@ -63,12 +73,18 @@ export type SlateAuthWithOauth<
|
|
|
63
73
|
clientId: string;
|
|
64
74
|
clientSecret: string;
|
|
65
75
|
scopes: string[];
|
|
76
|
+
config?: SlateAuthCallbackConfig;
|
|
66
77
|
}) => Promise<{
|
|
67
78
|
output: OutputType;
|
|
68
79
|
input?: InputType;
|
|
69
80
|
}>;
|
|
70
81
|
|
|
71
|
-
getProfile?: (ctx: {
|
|
82
|
+
getProfile?: (ctx: {
|
|
83
|
+
output: OutputType;
|
|
84
|
+
input: InputType;
|
|
85
|
+
scopes: string[];
|
|
86
|
+
config?: SlateAuthCallbackConfig;
|
|
87
|
+
}) => Promise<{
|
|
72
88
|
profile: Record<string, any>;
|
|
73
89
|
}>;
|
|
74
90
|
};
|
|
@@ -81,6 +97,10 @@ export type SlateAuthWithToken<InputType extends {}, OutputType extends { token?
|
|
|
81
97
|
|
|
82
98
|
inputSchema?: z.ZodType<InputType>;
|
|
83
99
|
|
|
100
|
+
docs?: {
|
|
101
|
+
tokenDocsLink?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
84
104
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
85
105
|
|
|
86
106
|
onInputChanged?: (params: {
|
|
@@ -103,6 +123,10 @@ export type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends
|
|
|
103
123
|
|
|
104
124
|
inputSchema?: z.ZodType<InputType>;
|
|
105
125
|
|
|
126
|
+
docs?: {
|
|
127
|
+
serviceAccountDocsLink?: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
106
130
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
107
131
|
|
|
108
132
|
onInputChanged?: (params: {
|
|
@@ -125,6 +149,10 @@ export type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}>
|
|
|
125
149
|
|
|
126
150
|
inputSchema?: z.ZodType<InputType>;
|
|
127
151
|
|
|
152
|
+
docs?: {
|
|
153
|
+
customAuthDocsLink?: string;
|
|
154
|
+
};
|
|
155
|
+
|
|
128
156
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
129
157
|
|
|
130
158
|
handleTokenRefresh?: (ctx: {
|
package/src/axios/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ let applySlateInterceptors = (
|
|
|
19
19
|
) => {
|
|
20
20
|
instance.interceptors.request.use(
|
|
21
21
|
request => {
|
|
22
|
-
|
|
22
|
+
// Has to be called in the context of an action execution
|
|
23
23
|
let ctx = getCurrentContext();
|
|
24
24
|
let spec = ctx.specification;
|
|
25
25
|
let providerToken = spec.key.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, '-');
|
package/src/axios/trace.test.ts
CHANGED
|
@@ -174,7 +174,7 @@ describe('sanitizeFreeText', () => {
|
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
it('redacts GitHub tokens', () => {
|
|
177
|
-
let token =
|
|
177
|
+
let token = `ghp_${'a'.repeat(40)}`;
|
|
178
178
|
expect(sanitizeFreeText(token)).toBe('[redacted]');
|
|
179
179
|
});
|
|
180
180
|
|
|
@@ -184,22 +184,22 @@ describe('sanitizeFreeText', () => {
|
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
it('redacts Stripe secret keys', () => {
|
|
187
|
-
let key =
|
|
187
|
+
let key = `sk_live_${'a'.repeat(24)}`;
|
|
188
188
|
expect(sanitizeFreeText(`{"key":"${key}"}`)).not.toContain(key);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
it('redacts OpenAI API keys', () => {
|
|
192
|
-
let key =
|
|
192
|
+
let key = `sk-proj-${'a'.repeat(40)}`;
|
|
193
193
|
expect(sanitizeFreeText(key)).toBe('[redacted]');
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
it('redacts Anthropic API keys', () => {
|
|
197
|
-
let key =
|
|
197
|
+
let key = `sk-ant-${'a'.repeat(40)}`;
|
|
198
198
|
expect(sanitizeFreeText(key)).toBe('[redacted]');
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
it('redacts Google API keys', () => {
|
|
202
|
-
let key =
|
|
202
|
+
let key = `AIza${'a'.repeat(35)}`;
|
|
203
203
|
expect(sanitizeFreeText(key)).toBe('[redacted]');
|
|
204
204
|
});
|
|
205
205
|
|
|
@@ -265,8 +265,7 @@ describe('sanitizeUrl', () => {
|
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
it('redacts secrets embedded in URL fragment (OAuth implicit flow)', () => {
|
|
268
|
-
let input =
|
|
269
|
-
'https://example.com/cb#access_token=xyz&token_type=bearer&expires_in=3600';
|
|
268
|
+
let input = 'https://example.com/cb#access_token=xyz&token_type=bearer&expires_in=3600';
|
|
270
269
|
let out = sanitizeUrl(input);
|
|
271
270
|
expect(out).toContain('access_token=[redacted]');
|
|
272
271
|
expect(out).toContain('token_type=bearer');
|
package/src/axios/trace.ts
CHANGED
|
@@ -205,16 +205,10 @@ let CORE_SECRET_KEY_ATOMS = [
|
|
|
205
205
|
let URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, 'code'];
|
|
206
206
|
|
|
207
207
|
let buildKeyBoundaryPattern = (atoms: string[], flags: string) =>
|
|
208
|
-
new RegExp(
|
|
209
|
-
`(?:^|[^A-Za-z0-9])(?:${atoms.join('|')})(?=[^A-Za-z0-9]|$)`,
|
|
210
|
-
flags
|
|
211
|
-
);
|
|
208
|
+
new RegExp(`(?:^|[^A-Za-z0-9])(?:${atoms.join('|')})(?=[^A-Za-z0-9]|$)`, flags);
|
|
212
209
|
|
|
213
210
|
let SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, 'i');
|
|
214
|
-
let URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
215
|
-
URL_FORM_SECRET_KEY_ATOMS,
|
|
216
|
-
'i'
|
|
217
|
-
);
|
|
211
|
+
let URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(URL_FORM_SECRET_KEY_ATOMS, 'i');
|
|
218
212
|
|
|
219
213
|
// Explicit non-secret keys that would otherwise trip the patterns above because
|
|
220
214
|
// they embed a secret-sounding token (e.g. `token_type` contains `token`).
|
|
@@ -307,7 +301,8 @@ let HTTP_AUTH_SCHEME_PATTERN =
|
|
|
307
301
|
|
|
308
302
|
// Generic `key=value` scan; the key is filtered via isUrlFormSecretKeyName at replace time
|
|
309
303
|
// so we can apply a deny-list for compound keys like `token_type` or `grant_type`.
|
|
310
|
-
let GENERIC_KEY_VALUE_PATTERN =
|
|
304
|
+
let GENERIC_KEY_VALUE_PATTERN =
|
|
305
|
+
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)(\s*=\s*)([^&#\s;]+)/g;
|
|
311
306
|
|
|
312
307
|
// Generic `"key": "value"` scan; the key is filtered via isSecretKeyName at replace time.
|
|
313
308
|
let GENERIC_JSON_KEY_VALUE_PATTERN =
|
|
@@ -438,9 +433,7 @@ let redactStructuredValue = (value: unknown, depth = 0): unknown => {
|
|
|
438
433
|
.slice(0, STRUCTURED_ENTRY_LIMIT)
|
|
439
434
|
.map(([key, entry]) => [
|
|
440
435
|
key,
|
|
441
|
-
isSecretKeyName(key)
|
|
442
|
-
? REDACTED_VALUE
|
|
443
|
-
: redactStructuredValue(entry, depth + 1)
|
|
436
|
+
isSecretKeyName(key) ? REDACTED_VALUE : redactStructuredValue(entry, depth + 1)
|
|
444
437
|
])
|
|
445
438
|
);
|
|
446
439
|
}
|
|
@@ -451,7 +444,7 @@ let redactStructuredValue = (value: unknown, depth = 0): unknown => {
|
|
|
451
444
|
let maybeParseJson = (text: string, contentType?: string) => {
|
|
452
445
|
let trimmed = text.trim();
|
|
453
446
|
if (!trimmed) return null;
|
|
454
|
-
if (!contentType?.includes('json') && !/^[
|
|
447
|
+
if (!contentType?.includes('json') && !/^[[{]/.test(trimmed)) {
|
|
455
448
|
return null;
|
|
456
449
|
}
|
|
457
450
|
|
|
@@ -541,7 +534,7 @@ let decodeRedactedMarker = (value: string) =>
|
|
|
541
534
|
: value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
542
535
|
|
|
543
536
|
let redactHashFragment = (hash: string) => {
|
|
544
|
-
if (!hash
|
|
537
|
+
if (!hash?.includes('=')) return hash;
|
|
545
538
|
let withoutHash = hash.startsWith('#') ? hash.slice(1) : hash;
|
|
546
539
|
let redacted = withoutHash.replace(
|
|
547
540
|
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
@@ -657,7 +650,7 @@ let clearTraceDraft = (
|
|
|
657
650
|
if (!config) return;
|
|
658
651
|
|
|
659
652
|
if (config.__slatesHttpTraceDraft === draft) {
|
|
660
|
-
|
|
653
|
+
config.__slatesHttpTraceDraft = undefined;
|
|
661
654
|
}
|
|
662
655
|
|
|
663
656
|
if (isObjectLike(config)) {
|
|
@@ -0,0 +1,27 @@
|
|
|
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(
|
|
10
|
+
{},
|
|
11
|
+
{},
|
|
12
|
+
{},
|
|
13
|
+
{} as any,
|
|
14
|
+
{
|
|
15
|
+
debug: () => {},
|
|
16
|
+
error: () => {},
|
|
17
|
+
info: () => {},
|
|
18
|
+
progress: () => {},
|
|
19
|
+
warn: () => {}
|
|
20
|
+
} as any
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
let result = await runWithContext(context, async () => duplicateHook.getCurrentContext());
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(context);
|
|
26
|
+
});
|
|
27
|
+
});
|
package/src/context/hook.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
2
|
import type { SlateContext } from './context';
|
|
3
3
|
|
|
4
|
-
let
|
|
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 {},
|
package/src/error/service.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { isServiceError } from '@lowerdeck/error';
|
|
2
1
|
import type { ErrorData, ErrorRecord, ServiceError } from '@lowerdeck/error';
|
|
2
|
+
import { isServiceError } from '@lowerdeck/error';
|
|
3
3
|
import { DEFAULT_CODE, SERVICE_ERROR_CODE_MAP } from './defaults';
|
|
4
4
|
import type { SlateErrorInput, SlateErrorIssue, SlateServiceErrorData } from './types';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
cleanRecord,
|
|
7
|
+
isRecord,
|
|
8
|
+
normalizeKind,
|
|
9
|
+
normalizeRetryable,
|
|
10
|
+
sanitizeForBaggage
|
|
11
|
+
} from './utils';
|
|
6
12
|
|
|
7
13
|
let SERVICE_ERROR_DATA_RESERVED_KEYS = new Set([
|
|
8
14
|
'status',
|
|
@@ -46,9 +52,7 @@ let normalizeServiceErrorIssues = (errors: unknown): SlateErrorIssue[] | undefin
|
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
let path = Array.isArray(error.path)
|
|
50
|
-
? error.path.map(entry => String(entry))
|
|
51
|
-
: undefined;
|
|
55
|
+
let path = Array.isArray(error.path) ? error.path.map(entry => String(entry)) : undefined;
|
|
52
56
|
|
|
53
57
|
return {
|
|
54
58
|
...error,
|
|
@@ -67,7 +71,9 @@ let normalizeServiceErrorIssues = (errors: unknown): SlateErrorIssue[] | undefin
|
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
let getServiceErrorBaggage = (data: SlateServiceErrorData) => {
|
|
70
|
-
let extraEntries = Object.entries(data).filter(
|
|
74
|
+
let extraEntries = Object.entries(data).filter(
|
|
75
|
+
([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key)
|
|
76
|
+
);
|
|
71
77
|
|
|
72
78
|
return cleanRecord({
|
|
73
79
|
serviceError: {
|
|
@@ -111,7 +117,11 @@ export let getServiceErrorData = (error: unknown): SlateServiceErrorData | null
|
|
|
111
117
|
return error.data;
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
if (
|
|
120
|
+
if (
|
|
121
|
+
isStructuredValue(error) &&
|
|
122
|
+
'toResponse' in error &&
|
|
123
|
+
typeof error.toResponse === 'function'
|
|
124
|
+
) {
|
|
115
125
|
let response = error.toResponse();
|
|
116
126
|
return isServiceErrorData(response) ? response : null;
|
|
117
127
|
}
|
package/src/error/types.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface SlateAxiosErrorOptions {
|
|
|
60
60
|
mapAxiosError?: (
|
|
61
61
|
error: AxiosError,
|
|
62
62
|
inferred: SlateErrorResponse
|
|
63
|
-
) => SlateError | Partial<SlateErrorResponse> |
|
|
63
|
+
) => SlateError | Partial<SlateErrorResponse> | undefined;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface SlateServiceErrorData {
|
package/src/error/utils.ts
CHANGED
|
@@ -62,7 +62,7 @@ export let normalizeRetryable = (code: string, retryable?: boolean) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export let getDefaultMessage = (code: string, message?: string) => {
|
|
65
|
-
if (message
|
|
65
|
+
if (message?.trim()) return message;
|
|
66
66
|
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -9,10 +9,8 @@ export interface SlateSpecificationParameters {
|
|
|
9
9
|
metadata?: Record<string, any>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface SlateSpecificationCreateParameters<
|
|
13
|
-
|
|
14
|
-
AuthType extends {}
|
|
15
|
-
> extends SlateSpecificationParameters {
|
|
12
|
+
export interface SlateSpecificationCreateParameters<ConfigType extends {}, AuthType extends {}>
|
|
13
|
+
extends SlateSpecificationParameters {
|
|
16
14
|
config: SlateConfig<ConfigType>;
|
|
17
15
|
auth: SlateAuth<AuthType>;
|
|
18
16
|
}
|