@slates/provider 1.0.0-rc.12 → 1.0.0-rc.15
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 +26 -14
- package/dist/index.d.cts +38 -11
- package/dist/index.d.ts +38 -11
- package/dist/index.module.js +26 -14
- package/package.json +3 -3
- package/src/action/action.ts +6 -0
- 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 +20 -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/config/config.ts +11 -0
- package/src/context/hook.test.ts +13 -7
- package/src/docs.ts +22 -0
- package/src/error/service.ts +17 -7
- package/src/error/types.ts +1 -1
- package/src/error/utils.ts +1 -1
- package/src/index.ts +1 -0
- package/src/logger/logger.test.ts +1 -1
- package/src/specification/specification.ts +8 -4
package/dist/index.cjs
CHANGED
|
@@ -119,6 +119,9 @@ var SlateAction = class {
|
|
|
119
119
|
get scopes() {
|
|
120
120
|
return this._params.scopes;
|
|
121
121
|
}
|
|
122
|
+
get docs() {
|
|
123
|
+
return this._params.docs;
|
|
124
|
+
}
|
|
122
125
|
};
|
|
123
126
|
|
|
124
127
|
// src/error/axios.ts
|
|
@@ -233,7 +236,7 @@ var normalizeRetryable = (code, retryable) => {
|
|
|
233
236
|
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";
|
|
234
237
|
};
|
|
235
238
|
var getDefaultMessage = (code, message) => {
|
|
236
|
-
if (message
|
|
239
|
+
if (message?.trim()) return message;
|
|
237
240
|
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
238
241
|
};
|
|
239
242
|
var cleanRecord = (value) => {
|
|
@@ -510,7 +513,9 @@ var normalizeServiceErrorIssues = (errors) => {
|
|
|
510
513
|
return issues.length > 0 ? issues : void 0;
|
|
511
514
|
};
|
|
512
515
|
var getServiceErrorBaggage = (data) => {
|
|
513
|
-
let extraEntries = Object.entries(data).filter(
|
|
516
|
+
let extraEntries = Object.entries(data).filter(
|
|
517
|
+
([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key)
|
|
518
|
+
);
|
|
514
519
|
return cleanRecord({
|
|
515
520
|
serviceError: {
|
|
516
521
|
code: data.code,
|
|
@@ -728,7 +733,9 @@ var normalizeClause = (input) => {
|
|
|
728
733
|
};
|
|
729
734
|
var assertScopeValues = (scopes) => {
|
|
730
735
|
if (scopes.length === 0) {
|
|
731
|
-
throw new SlateDeclarationError(
|
|
736
|
+
throw new SlateDeclarationError(
|
|
737
|
+
"Each action scope clause must include at least one OR scope"
|
|
738
|
+
);
|
|
732
739
|
}
|
|
733
740
|
for (let scope of scopes) {
|
|
734
741
|
if (typeof scope !== "string" || scope.trim().length === 0) {
|
|
@@ -1134,15 +1141,9 @@ var CORE_SECRET_KEY_ATOMS = [
|
|
|
1134
1141
|
"license[-_.]?key"
|
|
1135
1142
|
];
|
|
1136
1143
|
var URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, "code"];
|
|
1137
|
-
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(
|
|
1138
|
-
`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`,
|
|
1139
|
-
flags
|
|
1140
|
-
);
|
|
1144
|
+
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`, flags);
|
|
1141
1145
|
var SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, "i");
|
|
1142
|
-
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
1143
|
-
URL_FORM_SECRET_KEY_ATOMS,
|
|
1144
|
-
"i"
|
|
1145
|
-
);
|
|
1146
|
+
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(URL_FORM_SECRET_KEY_ATOMS, "i");
|
|
1146
1147
|
var NON_SECRET_KEY_EXACT = /* @__PURE__ */ new Set([
|
|
1147
1148
|
"token_type",
|
|
1148
1149
|
"token-type",
|
|
@@ -1320,7 +1321,7 @@ var redactStructuredValue = (value, depth = 0) => {
|
|
|
1320
1321
|
var maybeParseJson = (text, contentType) => {
|
|
1321
1322
|
let trimmed = text.trim();
|
|
1322
1323
|
if (!trimmed) return null;
|
|
1323
|
-
if (!contentType?.includes("json") && !/^[
|
|
1324
|
+
if (!contentType?.includes("json") && !/^[[{]/.test(trimmed)) {
|
|
1324
1325
|
return null;
|
|
1325
1326
|
}
|
|
1326
1327
|
try {
|
|
@@ -1380,7 +1381,7 @@ var buildUrl = (baseURL, url) => {
|
|
|
1380
1381
|
var REDACTED_ENCODED = encodeURIComponent(REDACTED_VALUE);
|
|
1381
1382
|
var decodeRedactedMarker = (value) => REDACTED_ENCODED === REDACTED_VALUE ? value : value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
1382
1383
|
var redactHashFragment = (hash) => {
|
|
1383
|
-
if (!hash
|
|
1384
|
+
if (!hash?.includes("=")) return hash;
|
|
1384
1385
|
let withoutHash = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1385
1386
|
let redacted = withoutHash.replace(
|
|
1386
1387
|
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
@@ -1458,7 +1459,7 @@ var takeTraceDraft = (config2) => {
|
|
|
1458
1459
|
var clearTraceDraft = (config2, draft) => {
|
|
1459
1460
|
if (!config2) return;
|
|
1460
1461
|
if (config2.__slatesHttpTraceDraft === draft) {
|
|
1461
|
-
|
|
1462
|
+
config2.__slatesHttpTraceDraft = void 0;
|
|
1462
1463
|
}
|
|
1463
1464
|
if (isObjectLike(config2)) {
|
|
1464
1465
|
traceDraftsByConfig.delete(config2);
|
|
@@ -1587,6 +1588,7 @@ var axios = createAxios();
|
|
|
1587
1588
|
// src/config/config.ts
|
|
1588
1589
|
var SlateConfig = class _SlateConfig {
|
|
1589
1590
|
#configSchema;
|
|
1591
|
+
#docs;
|
|
1590
1592
|
#configChanged = null;
|
|
1591
1593
|
#getDefaultConfig = null;
|
|
1592
1594
|
constructor(schema) {
|
|
@@ -1599,6 +1601,10 @@ var SlateConfig = class _SlateConfig {
|
|
|
1599
1601
|
this.#configSchema = schema;
|
|
1600
1602
|
return this;
|
|
1601
1603
|
}
|
|
1604
|
+
docs(docs) {
|
|
1605
|
+
this.#docs = docs;
|
|
1606
|
+
return this;
|
|
1607
|
+
}
|
|
1602
1608
|
onConfigChanged(handler) {
|
|
1603
1609
|
this.#configChanged = handler;
|
|
1604
1610
|
return this;
|
|
@@ -1610,6 +1616,9 @@ var SlateConfig = class _SlateConfig {
|
|
|
1610
1616
|
get configSchema() {
|
|
1611
1617
|
return this.#configSchema;
|
|
1612
1618
|
}
|
|
1619
|
+
get docsReferences() {
|
|
1620
|
+
return this.#docs;
|
|
1621
|
+
}
|
|
1613
1622
|
get handlers() {
|
|
1614
1623
|
return {
|
|
1615
1624
|
configChanged: this.#configChanged,
|
|
@@ -1842,6 +1851,9 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
1842
1851
|
get description() {
|
|
1843
1852
|
return this._params.description;
|
|
1844
1853
|
}
|
|
1854
|
+
get docs() {
|
|
1855
|
+
return this._params.docs;
|
|
1856
|
+
}
|
|
1845
1857
|
};
|
|
1846
1858
|
var spec = (params) => SlateSpecification.create(params);
|
|
1847
1859
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,19 @@ declare class SlateLogger {
|
|
|
50
50
|
progress(...message: SlateLogMessageInput[]): void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
interface SlateDocsReference {
|
|
54
|
+
name: string;
|
|
55
|
+
url: string;
|
|
56
|
+
}
|
|
57
|
+
interface SlateTypedDocsReference<Type extends string> extends SlateDocsReference {
|
|
58
|
+
type?: Type;
|
|
59
|
+
}
|
|
60
|
+
type SlateProviderDocsReference = SlateDocsReference;
|
|
61
|
+
type SlateConfigDocsReference = SlateTypedDocsReference<'docs.config.general'>;
|
|
62
|
+
type SlateActionDocsReference = SlateTypedDocsReference<'docs.action.general'>;
|
|
63
|
+
type SlateAuthDocsReference = SlateTypedDocsReference<'docs.auth.oauth' | 'docs.auth.oauth_scopes' | 'docs.auth.token' | 'docs.auth.service_account' | 'docs.auth.custom'>;
|
|
64
|
+
|
|
65
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
53
66
|
type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
54
67
|
token: string;
|
|
55
68
|
refreshToken?: string;
|
|
@@ -64,6 +77,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
64
77
|
defaultChecked?: boolean;
|
|
65
78
|
scope: string;
|
|
66
79
|
}[];
|
|
80
|
+
docs?: SlateAuthDocsReference[];
|
|
67
81
|
inputSchema?: z.ZodType<InputType>;
|
|
68
82
|
onInputChanged?: (params: {
|
|
69
83
|
previousInput: InputType | null;
|
|
@@ -79,6 +93,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
79
93
|
clientId: string;
|
|
80
94
|
clientSecret: string;
|
|
81
95
|
scopes: string[];
|
|
96
|
+
config?: SlateAuthCallbackConfig;
|
|
82
97
|
}) => Promise<{
|
|
83
98
|
url: string;
|
|
84
99
|
input?: InputType;
|
|
@@ -94,6 +109,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
94
109
|
scopes: string[];
|
|
95
110
|
callbackParams?: Record<string, string>;
|
|
96
111
|
callbackState: Record<string, any>;
|
|
112
|
+
config?: SlateAuthCallbackConfig;
|
|
97
113
|
}) => Promise<{
|
|
98
114
|
output: OutputType;
|
|
99
115
|
input?: InputType;
|
|
@@ -105,6 +121,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
105
121
|
clientId: string;
|
|
106
122
|
clientSecret: string;
|
|
107
123
|
scopes: string[];
|
|
124
|
+
config?: SlateAuthCallbackConfig;
|
|
108
125
|
}) => Promise<{
|
|
109
126
|
output: OutputType;
|
|
110
127
|
input?: InputType;
|
|
@@ -113,6 +130,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
113
130
|
output: OutputType;
|
|
114
131
|
input: InputType;
|
|
115
132
|
scopes: string[];
|
|
133
|
+
config?: SlateAuthCallbackConfig;
|
|
116
134
|
}) => Promise<{
|
|
117
135
|
profile: Record<string, any>;
|
|
118
136
|
}>;
|
|
@@ -124,6 +142,7 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
|
|
|
124
142
|
name: string;
|
|
125
143
|
key: string;
|
|
126
144
|
inputSchema?: z.ZodType<InputType>;
|
|
145
|
+
docs?: SlateAuthDocsReference[];
|
|
127
146
|
getOutput: (ctx: {
|
|
128
147
|
input: InputType;
|
|
129
148
|
}) => Promise<{
|
|
@@ -148,6 +167,7 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
|
|
|
148
167
|
name: string;
|
|
149
168
|
key: string;
|
|
150
169
|
inputSchema?: z.ZodType<InputType>;
|
|
170
|
+
docs?: SlateAuthDocsReference[];
|
|
151
171
|
getOutput: (ctx: {
|
|
152
172
|
input: InputType;
|
|
153
173
|
}) => Promise<{
|
|
@@ -172,6 +192,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
|
|
|
172
192
|
name: string;
|
|
173
193
|
key: string;
|
|
174
194
|
inputSchema?: z.ZodType<InputType>;
|
|
195
|
+
docs?: SlateAuthDocsReference[];
|
|
175
196
|
getOutput: (ctx: {
|
|
176
197
|
input: InputType;
|
|
177
198
|
}) => Promise<{
|
|
@@ -245,6 +266,7 @@ declare class SlateConfig<ConfigType extends {}> {
|
|
|
245
266
|
private constructor();
|
|
246
267
|
static create<ConfigType extends {}>(schema: z.ZodType<ConfigType>): SlateConfig<ConfigType>;
|
|
247
268
|
config<NewConfigType extends {}>(schema: z.ZodType<NewConfigType>): SlateConfig<NewConfigType>;
|
|
269
|
+
docs(docs: SlateConfigDocsReference[]): SlateConfig<ConfigType>;
|
|
248
270
|
onConfigChanged(handler: (params: {
|
|
249
271
|
previousConfig: ConfigType | null;
|
|
250
272
|
newConfig: ConfigType;
|
|
@@ -253,6 +275,7 @@ declare class SlateConfig<ConfigType extends {}> {
|
|
|
253
275
|
} | undefined): SlateConfig<ConfigType>;
|
|
254
276
|
getDefaultConfig(getter: () => ConfigType): SlateConfig<ConfigType>;
|
|
255
277
|
get configSchema(): z.ZodType<ConfigType, unknown, z.core.$ZodTypeInternals<ConfigType, unknown>>;
|
|
278
|
+
get docsReferences(): SlateConfigDocsReference[] | undefined;
|
|
256
279
|
get handlers(): {
|
|
257
280
|
configChanged: ((params: {
|
|
258
281
|
previousConfig: ConfigType | null;
|
|
@@ -269,6 +292,7 @@ interface SlateSpecificationParameters {
|
|
|
269
292
|
key: string;
|
|
270
293
|
name: string;
|
|
271
294
|
description?: string;
|
|
295
|
+
docs?: SlateProviderDocsReference[];
|
|
272
296
|
metadata?: Record<string, any>;
|
|
273
297
|
}
|
|
274
298
|
interface SlateSpecificationCreateParameters<ConfigType extends {}, AuthType extends {}> extends SlateSpecificationParameters {
|
|
@@ -289,6 +313,7 @@ declare class SlateSpecification<ConfigType extends {}, AuthType extends {}> {
|
|
|
289
313
|
get key(): string;
|
|
290
314
|
get name(): string;
|
|
291
315
|
get description(): string | undefined;
|
|
316
|
+
get docs(): SlateDocsReference[] | undefined;
|
|
292
317
|
}
|
|
293
318
|
declare let spec: <ConfigType extends {}, AuthType extends {}>(params: SlateSpecificationCreateParameters<ConfigType, AuthType>) => SlateSpecification<ConfigType, AuthType>;
|
|
294
319
|
|
|
@@ -371,6 +396,7 @@ interface SlateActionParameters {
|
|
|
371
396
|
};
|
|
372
397
|
metadata?: Record<string, any>;
|
|
373
398
|
scopes?: SlateActionScopes;
|
|
399
|
+
docs?: SlateActionDocsReference[];
|
|
374
400
|
}
|
|
375
401
|
type SlateToolInvocationHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = (context: SlateContext<ConfigType, AuthType, InputType>) => Promise<{
|
|
376
402
|
output: OutputType;
|
|
@@ -453,17 +479,9 @@ declare abstract class SlateAction<Type extends SlateActionType, ConfigType exte
|
|
|
453
479
|
get constraints(): string[] | undefined;
|
|
454
480
|
get metadata(): Record<string, any> | undefined;
|
|
455
481
|
get scopes(): SlateActionScopes | undefined;
|
|
482
|
+
get docs(): SlateActionDocsReference[] | undefined;
|
|
456
483
|
}
|
|
457
484
|
|
|
458
|
-
type SlateActionScopeValue = string;
|
|
459
|
-
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
460
|
-
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
461
|
-
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
462
|
-
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
463
|
-
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
464
|
-
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
465
|
-
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
466
|
-
|
|
467
485
|
declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}, Result extends SlateAction<Type, ConfigType, AuthType, any, any>> {
|
|
468
486
|
#private;
|
|
469
487
|
private readonly type;
|
|
@@ -489,6 +507,15 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
|
|
|
489
507
|
build(): Result;
|
|
490
508
|
}
|
|
491
509
|
|
|
510
|
+
type SlateActionScopeValue = string;
|
|
511
|
+
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
512
|
+
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
513
|
+
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
514
|
+
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
515
|
+
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
516
|
+
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
517
|
+
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
518
|
+
|
|
492
519
|
interface SlateToolParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateActionParameters {
|
|
493
520
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
494
521
|
}
|
|
@@ -585,7 +612,7 @@ interface SlateErrorInput extends Omit<SlateErrorResponse, 'kind'> {
|
|
|
585
612
|
interface SlateAxiosErrorOptions {
|
|
586
613
|
defaults?: Partial<SlateErrorResponse>;
|
|
587
614
|
extractResponseData?: (response: AxiosResponse) => unknown;
|
|
588
|
-
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> |
|
|
615
|
+
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> | undefined;
|
|
589
616
|
}
|
|
590
617
|
interface SlateServiceErrorData {
|
|
591
618
|
status: number;
|
|
@@ -630,4 +657,4 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
|
630
657
|
get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
|
|
631
658
|
}
|
|
632
659
|
|
|
633
|
-
export { Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
|
|
660
|
+
export { Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionDocsReference, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,19 @@ declare class SlateLogger {
|
|
|
50
50
|
progress(...message: SlateLogMessageInput[]): void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
interface SlateDocsReference {
|
|
54
|
+
name: string;
|
|
55
|
+
url: string;
|
|
56
|
+
}
|
|
57
|
+
interface SlateTypedDocsReference<Type extends string> extends SlateDocsReference {
|
|
58
|
+
type?: Type;
|
|
59
|
+
}
|
|
60
|
+
type SlateProviderDocsReference = SlateDocsReference;
|
|
61
|
+
type SlateConfigDocsReference = SlateTypedDocsReference<'docs.config.general'>;
|
|
62
|
+
type SlateActionDocsReference = SlateTypedDocsReference<'docs.action.general'>;
|
|
63
|
+
type SlateAuthDocsReference = SlateTypedDocsReference<'docs.auth.oauth' | 'docs.auth.oauth_scopes' | 'docs.auth.token' | 'docs.auth.service_account' | 'docs.auth.custom'>;
|
|
64
|
+
|
|
65
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
53
66
|
type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
54
67
|
token: string;
|
|
55
68
|
refreshToken?: string;
|
|
@@ -64,6 +77,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
64
77
|
defaultChecked?: boolean;
|
|
65
78
|
scope: string;
|
|
66
79
|
}[];
|
|
80
|
+
docs?: SlateAuthDocsReference[];
|
|
67
81
|
inputSchema?: z.ZodType<InputType>;
|
|
68
82
|
onInputChanged?: (params: {
|
|
69
83
|
previousInput: InputType | null;
|
|
@@ -79,6 +93,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
79
93
|
clientId: string;
|
|
80
94
|
clientSecret: string;
|
|
81
95
|
scopes: string[];
|
|
96
|
+
config?: SlateAuthCallbackConfig;
|
|
82
97
|
}) => Promise<{
|
|
83
98
|
url: string;
|
|
84
99
|
input?: InputType;
|
|
@@ -94,6 +109,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
94
109
|
scopes: string[];
|
|
95
110
|
callbackParams?: Record<string, string>;
|
|
96
111
|
callbackState: Record<string, any>;
|
|
112
|
+
config?: SlateAuthCallbackConfig;
|
|
97
113
|
}) => Promise<{
|
|
98
114
|
output: OutputType;
|
|
99
115
|
input?: InputType;
|
|
@@ -105,6 +121,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
105
121
|
clientId: string;
|
|
106
122
|
clientSecret: string;
|
|
107
123
|
scopes: string[];
|
|
124
|
+
config?: SlateAuthCallbackConfig;
|
|
108
125
|
}) => Promise<{
|
|
109
126
|
output: OutputType;
|
|
110
127
|
input?: InputType;
|
|
@@ -113,6 +130,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
|
113
130
|
output: OutputType;
|
|
114
131
|
input: InputType;
|
|
115
132
|
scopes: string[];
|
|
133
|
+
config?: SlateAuthCallbackConfig;
|
|
116
134
|
}) => Promise<{
|
|
117
135
|
profile: Record<string, any>;
|
|
118
136
|
}>;
|
|
@@ -124,6 +142,7 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
|
|
|
124
142
|
name: string;
|
|
125
143
|
key: string;
|
|
126
144
|
inputSchema?: z.ZodType<InputType>;
|
|
145
|
+
docs?: SlateAuthDocsReference[];
|
|
127
146
|
getOutput: (ctx: {
|
|
128
147
|
input: InputType;
|
|
129
148
|
}) => Promise<{
|
|
@@ -148,6 +167,7 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
|
|
|
148
167
|
name: string;
|
|
149
168
|
key: string;
|
|
150
169
|
inputSchema?: z.ZodType<InputType>;
|
|
170
|
+
docs?: SlateAuthDocsReference[];
|
|
151
171
|
getOutput: (ctx: {
|
|
152
172
|
input: InputType;
|
|
153
173
|
}) => Promise<{
|
|
@@ -172,6 +192,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
|
|
|
172
192
|
name: string;
|
|
173
193
|
key: string;
|
|
174
194
|
inputSchema?: z.ZodType<InputType>;
|
|
195
|
+
docs?: SlateAuthDocsReference[];
|
|
175
196
|
getOutput: (ctx: {
|
|
176
197
|
input: InputType;
|
|
177
198
|
}) => Promise<{
|
|
@@ -245,6 +266,7 @@ declare class SlateConfig<ConfigType extends {}> {
|
|
|
245
266
|
private constructor();
|
|
246
267
|
static create<ConfigType extends {}>(schema: z.ZodType<ConfigType>): SlateConfig<ConfigType>;
|
|
247
268
|
config<NewConfigType extends {}>(schema: z.ZodType<NewConfigType>): SlateConfig<NewConfigType>;
|
|
269
|
+
docs(docs: SlateConfigDocsReference[]): SlateConfig<ConfigType>;
|
|
248
270
|
onConfigChanged(handler: (params: {
|
|
249
271
|
previousConfig: ConfigType | null;
|
|
250
272
|
newConfig: ConfigType;
|
|
@@ -253,6 +275,7 @@ declare class SlateConfig<ConfigType extends {}> {
|
|
|
253
275
|
} | undefined): SlateConfig<ConfigType>;
|
|
254
276
|
getDefaultConfig(getter: () => ConfigType): SlateConfig<ConfigType>;
|
|
255
277
|
get configSchema(): z.ZodType<ConfigType, unknown, z.core.$ZodTypeInternals<ConfigType, unknown>>;
|
|
278
|
+
get docsReferences(): SlateConfigDocsReference[] | undefined;
|
|
256
279
|
get handlers(): {
|
|
257
280
|
configChanged: ((params: {
|
|
258
281
|
previousConfig: ConfigType | null;
|
|
@@ -269,6 +292,7 @@ interface SlateSpecificationParameters {
|
|
|
269
292
|
key: string;
|
|
270
293
|
name: string;
|
|
271
294
|
description?: string;
|
|
295
|
+
docs?: SlateProviderDocsReference[];
|
|
272
296
|
metadata?: Record<string, any>;
|
|
273
297
|
}
|
|
274
298
|
interface SlateSpecificationCreateParameters<ConfigType extends {}, AuthType extends {}> extends SlateSpecificationParameters {
|
|
@@ -289,6 +313,7 @@ declare class SlateSpecification<ConfigType extends {}, AuthType extends {}> {
|
|
|
289
313
|
get key(): string;
|
|
290
314
|
get name(): string;
|
|
291
315
|
get description(): string | undefined;
|
|
316
|
+
get docs(): SlateDocsReference[] | undefined;
|
|
292
317
|
}
|
|
293
318
|
declare let spec: <ConfigType extends {}, AuthType extends {}>(params: SlateSpecificationCreateParameters<ConfigType, AuthType>) => SlateSpecification<ConfigType, AuthType>;
|
|
294
319
|
|
|
@@ -371,6 +396,7 @@ interface SlateActionParameters {
|
|
|
371
396
|
};
|
|
372
397
|
metadata?: Record<string, any>;
|
|
373
398
|
scopes?: SlateActionScopes;
|
|
399
|
+
docs?: SlateActionDocsReference[];
|
|
374
400
|
}
|
|
375
401
|
type SlateToolInvocationHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = (context: SlateContext<ConfigType, AuthType, InputType>) => Promise<{
|
|
376
402
|
output: OutputType;
|
|
@@ -453,17 +479,9 @@ declare abstract class SlateAction<Type extends SlateActionType, ConfigType exte
|
|
|
453
479
|
get constraints(): string[] | undefined;
|
|
454
480
|
get metadata(): Record<string, any> | undefined;
|
|
455
481
|
get scopes(): SlateActionScopes | undefined;
|
|
482
|
+
get docs(): SlateActionDocsReference[] | undefined;
|
|
456
483
|
}
|
|
457
484
|
|
|
458
|
-
type SlateActionScopeValue = string;
|
|
459
|
-
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
460
|
-
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
461
|
-
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
462
|
-
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
463
|
-
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
464
|
-
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
465
|
-
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
466
|
-
|
|
467
485
|
declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}, Result extends SlateAction<Type, ConfigType, AuthType, any, any>> {
|
|
468
486
|
#private;
|
|
469
487
|
private readonly type;
|
|
@@ -489,6 +507,15 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
|
|
|
489
507
|
build(): Result;
|
|
490
508
|
}
|
|
491
509
|
|
|
510
|
+
type SlateActionScopeValue = string;
|
|
511
|
+
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
512
|
+
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
513
|
+
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
514
|
+
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
515
|
+
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
516
|
+
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
517
|
+
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
518
|
+
|
|
492
519
|
interface SlateToolParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateActionParameters {
|
|
493
520
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
494
521
|
}
|
|
@@ -585,7 +612,7 @@ interface SlateErrorInput extends Omit<SlateErrorResponse, 'kind'> {
|
|
|
585
612
|
interface SlateAxiosErrorOptions {
|
|
586
613
|
defaults?: Partial<SlateErrorResponse>;
|
|
587
614
|
extractResponseData?: (response: AxiosResponse) => unknown;
|
|
588
|
-
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> |
|
|
615
|
+
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> | undefined;
|
|
589
616
|
}
|
|
590
617
|
interface SlateServiceErrorData {
|
|
591
618
|
status: number;
|
|
@@ -630,4 +657,4 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
|
630
657
|
get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
|
|
631
658
|
}
|
|
632
659
|
|
|
633
|
-
export { Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
|
|
660
|
+
export { Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionDocsReference, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
|
package/dist/index.module.js
CHANGED
|
@@ -48,6 +48,9 @@ var SlateAction = class {
|
|
|
48
48
|
get scopes() {
|
|
49
49
|
return this._params.scopes;
|
|
50
50
|
}
|
|
51
|
+
get docs() {
|
|
52
|
+
return this._params.docs;
|
|
53
|
+
}
|
|
51
54
|
};
|
|
52
55
|
|
|
53
56
|
// src/error/axios.ts
|
|
@@ -162,7 +165,7 @@ var normalizeRetryable = (code, retryable) => {
|
|
|
162
165
|
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";
|
|
163
166
|
};
|
|
164
167
|
var getDefaultMessage = (code, message) => {
|
|
165
|
-
if (message
|
|
168
|
+
if (message?.trim()) return message;
|
|
166
169
|
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
167
170
|
};
|
|
168
171
|
var cleanRecord = (value) => {
|
|
@@ -439,7 +442,9 @@ var normalizeServiceErrorIssues = (errors) => {
|
|
|
439
442
|
return issues.length > 0 ? issues : void 0;
|
|
440
443
|
};
|
|
441
444
|
var getServiceErrorBaggage = (data) => {
|
|
442
|
-
let extraEntries = Object.entries(data).filter(
|
|
445
|
+
let extraEntries = Object.entries(data).filter(
|
|
446
|
+
([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key)
|
|
447
|
+
);
|
|
443
448
|
return cleanRecord({
|
|
444
449
|
serviceError: {
|
|
445
450
|
code: data.code,
|
|
@@ -657,7 +662,9 @@ var normalizeClause = (input) => {
|
|
|
657
662
|
};
|
|
658
663
|
var assertScopeValues = (scopes) => {
|
|
659
664
|
if (scopes.length === 0) {
|
|
660
|
-
throw new SlateDeclarationError(
|
|
665
|
+
throw new SlateDeclarationError(
|
|
666
|
+
"Each action scope clause must include at least one OR scope"
|
|
667
|
+
);
|
|
661
668
|
}
|
|
662
669
|
for (let scope of scopes) {
|
|
663
670
|
if (typeof scope !== "string" || scope.trim().length === 0) {
|
|
@@ -1063,15 +1070,9 @@ var CORE_SECRET_KEY_ATOMS = [
|
|
|
1063
1070
|
"license[-_.]?key"
|
|
1064
1071
|
];
|
|
1065
1072
|
var URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, "code"];
|
|
1066
|
-
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(
|
|
1067
|
-
`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`,
|
|
1068
|
-
flags
|
|
1069
|
-
);
|
|
1073
|
+
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`, flags);
|
|
1070
1074
|
var SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, "i");
|
|
1071
|
-
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
1072
|
-
URL_FORM_SECRET_KEY_ATOMS,
|
|
1073
|
-
"i"
|
|
1074
|
-
);
|
|
1075
|
+
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(URL_FORM_SECRET_KEY_ATOMS, "i");
|
|
1075
1076
|
var NON_SECRET_KEY_EXACT = /* @__PURE__ */ new Set([
|
|
1076
1077
|
"token_type",
|
|
1077
1078
|
"token-type",
|
|
@@ -1249,7 +1250,7 @@ var redactStructuredValue = (value, depth = 0) => {
|
|
|
1249
1250
|
var maybeParseJson = (text, contentType) => {
|
|
1250
1251
|
let trimmed = text.trim();
|
|
1251
1252
|
if (!trimmed) return null;
|
|
1252
|
-
if (!contentType?.includes("json") && !/^[
|
|
1253
|
+
if (!contentType?.includes("json") && !/^[[{]/.test(trimmed)) {
|
|
1253
1254
|
return null;
|
|
1254
1255
|
}
|
|
1255
1256
|
try {
|
|
@@ -1309,7 +1310,7 @@ var buildUrl = (baseURL, url) => {
|
|
|
1309
1310
|
var REDACTED_ENCODED = encodeURIComponent(REDACTED_VALUE);
|
|
1310
1311
|
var decodeRedactedMarker = (value) => REDACTED_ENCODED === REDACTED_VALUE ? value : value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
1311
1312
|
var redactHashFragment = (hash) => {
|
|
1312
|
-
if (!hash
|
|
1313
|
+
if (!hash?.includes("=")) return hash;
|
|
1313
1314
|
let withoutHash = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1314
1315
|
let redacted = withoutHash.replace(
|
|
1315
1316
|
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
@@ -1387,7 +1388,7 @@ var takeTraceDraft = (config2) => {
|
|
|
1387
1388
|
var clearTraceDraft = (config2, draft) => {
|
|
1388
1389
|
if (!config2) return;
|
|
1389
1390
|
if (config2.__slatesHttpTraceDraft === draft) {
|
|
1390
|
-
|
|
1391
|
+
config2.__slatesHttpTraceDraft = void 0;
|
|
1391
1392
|
}
|
|
1392
1393
|
if (isObjectLike(config2)) {
|
|
1393
1394
|
traceDraftsByConfig.delete(config2);
|
|
@@ -1516,6 +1517,7 @@ var axios = createAxios();
|
|
|
1516
1517
|
// src/config/config.ts
|
|
1517
1518
|
var SlateConfig = class _SlateConfig {
|
|
1518
1519
|
#configSchema;
|
|
1520
|
+
#docs;
|
|
1519
1521
|
#configChanged = null;
|
|
1520
1522
|
#getDefaultConfig = null;
|
|
1521
1523
|
constructor(schema) {
|
|
@@ -1528,6 +1530,10 @@ var SlateConfig = class _SlateConfig {
|
|
|
1528
1530
|
this.#configSchema = schema;
|
|
1529
1531
|
return this;
|
|
1530
1532
|
}
|
|
1533
|
+
docs(docs) {
|
|
1534
|
+
this.#docs = docs;
|
|
1535
|
+
return this;
|
|
1536
|
+
}
|
|
1531
1537
|
onConfigChanged(handler) {
|
|
1532
1538
|
this.#configChanged = handler;
|
|
1533
1539
|
return this;
|
|
@@ -1539,6 +1545,9 @@ var SlateConfig = class _SlateConfig {
|
|
|
1539
1545
|
get configSchema() {
|
|
1540
1546
|
return this.#configSchema;
|
|
1541
1547
|
}
|
|
1548
|
+
get docsReferences() {
|
|
1549
|
+
return this.#docs;
|
|
1550
|
+
}
|
|
1542
1551
|
get handlers() {
|
|
1543
1552
|
return {
|
|
1544
1553
|
configChanged: this.#configChanged,
|
|
@@ -1771,6 +1780,9 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
1771
1780
|
get description() {
|
|
1772
1781
|
return this._params.description;
|
|
1773
1782
|
}
|
|
1783
|
+
get docs() {
|
|
1784
|
+
return this._params.docs;
|
|
1785
|
+
}
|
|
1774
1786
|
};
|
|
1775
1787
|
var spec = (params) => SlateSpecification.create(params);
|
|
1776
1788
|
export {
|
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.15",
|
|
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",
|
package/src/action/action.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { SlateContext } from '../context';
|
|
3
|
+
import type { SlateActionDocsReference } from '../docs';
|
|
3
4
|
import type { SlateSpecification } from '../specification/specification';
|
|
4
5
|
import type { SlateAttachment } from './attachment';
|
|
5
6
|
|
|
@@ -26,6 +27,7 @@ export interface SlateActionParameters {
|
|
|
26
27
|
};
|
|
27
28
|
metadata?: Record<string, any>;
|
|
28
29
|
scopes?: SlateActionScopes;
|
|
30
|
+
docs?: SlateActionDocsReference[];
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export type SlateToolInvocationHandler<
|
|
@@ -203,4 +205,8 @@ export abstract class SlateAction<
|
|
|
203
205
|
get scopes() {
|
|
204
206
|
return this._params.scopes;
|
|
205
207
|
}
|
|
208
|
+
|
|
209
|
+
get docs() {
|
|
210
|
+
return this._params.docs;
|
|
211
|
+
}
|
|
206
212
|
}
|
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,4 +1,7 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
|
+
import type { SlateAuthDocsReference } from '../docs';
|
|
3
|
+
|
|
4
|
+
type SlateAuthCallbackConfig = Record<string, any>;
|
|
2
5
|
|
|
3
6
|
export type SlateAuthWithOauth<
|
|
4
7
|
InputType extends {},
|
|
@@ -20,6 +23,8 @@ export type SlateAuthWithOauth<
|
|
|
20
23
|
scope: string;
|
|
21
24
|
}[];
|
|
22
25
|
|
|
26
|
+
docs?: SlateAuthDocsReference[];
|
|
27
|
+
|
|
23
28
|
inputSchema?: z.ZodType<InputType>;
|
|
24
29
|
|
|
25
30
|
onInputChanged?: (params: {
|
|
@@ -36,6 +41,7 @@ export type SlateAuthWithOauth<
|
|
|
36
41
|
clientId: string;
|
|
37
42
|
clientSecret: string;
|
|
38
43
|
scopes: string[];
|
|
44
|
+
config?: SlateAuthCallbackConfig;
|
|
39
45
|
}) => Promise<{
|
|
40
46
|
url: string;
|
|
41
47
|
input?: InputType;
|
|
@@ -52,6 +58,7 @@ export type SlateAuthWithOauth<
|
|
|
52
58
|
scopes: string[];
|
|
53
59
|
callbackParams?: Record<string, string>;
|
|
54
60
|
callbackState: Record<string, any>;
|
|
61
|
+
config?: SlateAuthCallbackConfig;
|
|
55
62
|
}) => Promise<{
|
|
56
63
|
output: OutputType;
|
|
57
64
|
input?: InputType;
|
|
@@ -64,12 +71,18 @@ export type SlateAuthWithOauth<
|
|
|
64
71
|
clientId: string;
|
|
65
72
|
clientSecret: string;
|
|
66
73
|
scopes: string[];
|
|
74
|
+
config?: SlateAuthCallbackConfig;
|
|
67
75
|
}) => Promise<{
|
|
68
76
|
output: OutputType;
|
|
69
77
|
input?: InputType;
|
|
70
78
|
}>;
|
|
71
79
|
|
|
72
|
-
getProfile?: (ctx: {
|
|
80
|
+
getProfile?: (ctx: {
|
|
81
|
+
output: OutputType;
|
|
82
|
+
input: InputType;
|
|
83
|
+
scopes: string[];
|
|
84
|
+
config?: SlateAuthCallbackConfig;
|
|
85
|
+
}) => Promise<{
|
|
73
86
|
profile: Record<string, any>;
|
|
74
87
|
}>;
|
|
75
88
|
};
|
|
@@ -82,6 +95,8 @@ export type SlateAuthWithToken<InputType extends {}, OutputType extends { token?
|
|
|
82
95
|
|
|
83
96
|
inputSchema?: z.ZodType<InputType>;
|
|
84
97
|
|
|
98
|
+
docs?: SlateAuthDocsReference[];
|
|
99
|
+
|
|
85
100
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
86
101
|
|
|
87
102
|
onInputChanged?: (params: {
|
|
@@ -104,6 +119,8 @@ export type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends
|
|
|
104
119
|
|
|
105
120
|
inputSchema?: z.ZodType<InputType>;
|
|
106
121
|
|
|
122
|
+
docs?: SlateAuthDocsReference[];
|
|
123
|
+
|
|
107
124
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
108
125
|
|
|
109
126
|
onInputChanged?: (params: {
|
|
@@ -126,6 +143,8 @@ export type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}>
|
|
|
126
143
|
|
|
127
144
|
inputSchema?: z.ZodType<InputType>;
|
|
128
145
|
|
|
146
|
+
docs?: SlateAuthDocsReference[];
|
|
147
|
+
|
|
129
148
|
getOutput: (ctx: { input: InputType }) => Promise<{ output: OutputType }>;
|
|
130
149
|
|
|
131
150
|
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)) {
|
package/src/config/config.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
|
+
import type { SlateConfigDocsReference } from '../docs';
|
|
2
3
|
|
|
3
4
|
export class SlateConfig<ConfigType extends {}> {
|
|
4
5
|
#configSchema: z.ZodType<ConfigType>;
|
|
6
|
+
#docs: SlateConfigDocsReference[] | undefined;
|
|
5
7
|
#configChanged:
|
|
6
8
|
| ((params: {
|
|
7
9
|
previousConfig: ConfigType | null;
|
|
@@ -25,6 +27,11 @@ export class SlateConfig<ConfigType extends {}> {
|
|
|
25
27
|
return this as any as SlateConfig<NewConfigType>;
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
docs(docs: SlateConfigDocsReference[]): SlateConfig<ConfigType> {
|
|
31
|
+
this.#docs = docs;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
onConfigChanged(
|
|
29
36
|
handler: (params: {
|
|
30
37
|
previousConfig: ConfigType | null;
|
|
@@ -44,6 +51,10 @@ export class SlateConfig<ConfigType extends {}> {
|
|
|
44
51
|
return this.#configSchema;
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
get docsReferences() {
|
|
55
|
+
return this.#docs;
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
get handlers() {
|
|
48
59
|
return {
|
|
49
60
|
configChanged: this.#configChanged,
|
package/src/context/hook.test.ts
CHANGED
|
@@ -6,13 +6,19 @@ describe('slate context hook', () => {
|
|
|
6
6
|
it('shares context storage across duplicate module instances', async () => {
|
|
7
7
|
// @ts-expect-error Vite treats the query as a distinct module instance.
|
|
8
8
|
let duplicateHook: typeof import('./hook') = await import('./hook?duplicate-instance');
|
|
9
|
-
let context = new SlateContext(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
);
|
|
16
22
|
|
|
17
23
|
let result = await runWithContext(context, async () => duplicateHook.getCurrentContext());
|
|
18
24
|
|
package/src/docs.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SlateDocsReference {
|
|
2
|
+
name: string;
|
|
3
|
+
url: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface SlateTypedDocsReference<Type extends string> extends SlateDocsReference {
|
|
7
|
+
type?: Type;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type SlateProviderDocsReference = SlateDocsReference;
|
|
11
|
+
|
|
12
|
+
export type SlateConfigDocsReference = SlateTypedDocsReference<'docs.config.general'>;
|
|
13
|
+
|
|
14
|
+
export type SlateActionDocsReference = SlateTypedDocsReference<'docs.action.general'>;
|
|
15
|
+
|
|
16
|
+
export type SlateAuthDocsReference = SlateTypedDocsReference<
|
|
17
|
+
| 'docs.auth.oauth'
|
|
18
|
+
| 'docs.auth.oauth_scopes'
|
|
19
|
+
| 'docs.auth.token'
|
|
20
|
+
| 'docs.auth.service_account'
|
|
21
|
+
| 'docs.auth.custom'
|
|
22
|
+
>;
|
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
|
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import type { SlateAuth } from '../auth';
|
|
3
3
|
import type { SlateConfig } from '../config';
|
|
4
|
+
import type { SlateProviderDocsReference } from '../docs';
|
|
4
5
|
|
|
5
6
|
export interface SlateSpecificationParameters {
|
|
6
7
|
key: string;
|
|
7
8
|
name: string;
|
|
8
9
|
description?: string;
|
|
10
|
+
docs?: SlateProviderDocsReference[];
|
|
9
11
|
metadata?: Record<string, any>;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export interface SlateSpecificationCreateParameters<
|
|
13
|
-
|
|
14
|
-
AuthType extends {}
|
|
15
|
-
> extends SlateSpecificationParameters {
|
|
14
|
+
export interface SlateSpecificationCreateParameters<ConfigType extends {}, AuthType extends {}>
|
|
15
|
+
extends SlateSpecificationParameters {
|
|
16
16
|
config: SlateConfig<ConfigType>;
|
|
17
17
|
auth: SlateAuth<AuthType>;
|
|
18
18
|
}
|
|
@@ -63,6 +63,10 @@ export class SlateSpecification<ConfigType extends {}, AuthType extends {}> {
|
|
|
63
63
|
get description() {
|
|
64
64
|
return this._params.description;
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
get docs() {
|
|
68
|
+
return this._params.docs;
|
|
69
|
+
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
export let spec = <ConfigType extends {}, AuthType extends {}>(
|