@slates/client 1.0.0-rc.2 → 1.0.0-rc.6
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.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/package.json +4 -4
- package/src/client.test.ts +105 -0
- package/src/error.ts +1 -0
package/dist/index.d.cts
CHANGED
|
@@ -306,6 +306,7 @@ declare class SlatesProtocolClient {
|
|
|
306
306
|
id: string;
|
|
307
307
|
title: string;
|
|
308
308
|
description?: string | undefined;
|
|
309
|
+
defaultChecked?: boolean | undefined;
|
|
309
310
|
}[] | undefined;
|
|
310
311
|
};
|
|
311
312
|
}>;
|
|
@@ -543,6 +544,17 @@ declare class SlatesProtocolClient {
|
|
|
543
544
|
invokeTool(actionId: string, input: Record<string, any>): Promise<{
|
|
544
545
|
output: Record<string, any>;
|
|
545
546
|
message?: string | undefined;
|
|
547
|
+
attachments?: {
|
|
548
|
+
content: {
|
|
549
|
+
type: "url";
|
|
550
|
+
url: string;
|
|
551
|
+
} | {
|
|
552
|
+
type: "content";
|
|
553
|
+
encoding: "base64" | "utf-8";
|
|
554
|
+
content: string;
|
|
555
|
+
};
|
|
556
|
+
mimeType?: string | undefined;
|
|
557
|
+
}[] | undefined;
|
|
546
558
|
requestTraces?: {
|
|
547
559
|
startedAt: string;
|
|
548
560
|
durationMs: number;
|
|
@@ -726,6 +738,7 @@ interface SlateProtocolErrorResponse {
|
|
|
726
738
|
provider?: Record<string, unknown>;
|
|
727
739
|
upstream?: Record<string, unknown>;
|
|
728
740
|
baggage?: Record<string, unknown>;
|
|
741
|
+
requestTraces?: Array<Record<string, unknown>>;
|
|
729
742
|
[key: string]: unknown;
|
|
730
743
|
}
|
|
731
744
|
declare class SlateProtocolError extends Error {
|
|
@@ -748,6 +761,7 @@ declare class SlateProtocolError extends Error {
|
|
|
748
761
|
provider?: Record<string, unknown>;
|
|
749
762
|
upstream?: Record<string, unknown>;
|
|
750
763
|
baggage?: Record<string, unknown>;
|
|
764
|
+
requestTraces?: Array<Record<string, unknown>>;
|
|
751
765
|
};
|
|
752
766
|
static is(error: unknown): error is SlateProtocolError;
|
|
753
767
|
static fromResponse(error: unknown, source?: SlateProtocolErrorSource): SlateProtocolError;
|
package/dist/index.d.ts
CHANGED
|
@@ -306,6 +306,7 @@ declare class SlatesProtocolClient {
|
|
|
306
306
|
id: string;
|
|
307
307
|
title: string;
|
|
308
308
|
description?: string | undefined;
|
|
309
|
+
defaultChecked?: boolean | undefined;
|
|
309
310
|
}[] | undefined;
|
|
310
311
|
};
|
|
311
312
|
}>;
|
|
@@ -543,6 +544,17 @@ declare class SlatesProtocolClient {
|
|
|
543
544
|
invokeTool(actionId: string, input: Record<string, any>): Promise<{
|
|
544
545
|
output: Record<string, any>;
|
|
545
546
|
message?: string | undefined;
|
|
547
|
+
attachments?: {
|
|
548
|
+
content: {
|
|
549
|
+
type: "url";
|
|
550
|
+
url: string;
|
|
551
|
+
} | {
|
|
552
|
+
type: "content";
|
|
553
|
+
encoding: "base64" | "utf-8";
|
|
554
|
+
content: string;
|
|
555
|
+
};
|
|
556
|
+
mimeType?: string | undefined;
|
|
557
|
+
}[] | undefined;
|
|
546
558
|
requestTraces?: {
|
|
547
559
|
startedAt: string;
|
|
548
560
|
durationMs: number;
|
|
@@ -726,6 +738,7 @@ interface SlateProtocolErrorResponse {
|
|
|
726
738
|
provider?: Record<string, unknown>;
|
|
727
739
|
upstream?: Record<string, unknown>;
|
|
728
740
|
baggage?: Record<string, unknown>;
|
|
741
|
+
requestTraces?: Array<Record<string, unknown>>;
|
|
729
742
|
[key: string]: unknown;
|
|
730
743
|
}
|
|
731
744
|
declare class SlateProtocolError extends Error {
|
|
@@ -748,6 +761,7 @@ declare class SlateProtocolError extends Error {
|
|
|
748
761
|
provider?: Record<string, unknown>;
|
|
749
762
|
upstream?: Record<string, unknown>;
|
|
750
763
|
baggage?: Record<string, unknown>;
|
|
764
|
+
requestTraces?: Array<Record<string, unknown>>;
|
|
751
765
|
};
|
|
752
766
|
static is(error: unknown): error is SlateProtocolError;
|
|
753
767
|
static fromResponse(error: unknown, source?: SlateProtocolErrorSource): SlateProtocolError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/client",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@slates/proto": "1.0.0-rc.
|
|
35
|
-
"@slates/provider": "1.0.0-rc.
|
|
36
|
-
"@slates/provider-handler": "1.0.0-rc.
|
|
34
|
+
"@slates/proto": "1.0.0-rc.8",
|
|
35
|
+
"@slates/provider": "1.0.0-rc.10",
|
|
36
|
+
"@slates/provider-handler": "1.0.0-rc.9"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@slates/tsconfig": "1.0.0-rc.1",
|
package/src/client.test.ts
CHANGED
|
@@ -170,6 +170,59 @@ let createTraceSlate = (baseUrl: string) => {
|
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
let createTraceErrorSlate = (baseUrl: string) => {
|
|
174
|
+
let config = SlateConfig.create(z.object({}));
|
|
175
|
+
let auth = SlateAuth.create<{}>().output(z.object({}));
|
|
176
|
+
|
|
177
|
+
let spec = SlateSpecification.create({
|
|
178
|
+
key: 'trace-error-slate',
|
|
179
|
+
name: 'Trace Error Slate',
|
|
180
|
+
description: 'A slate that traces failed HTTP requests',
|
|
181
|
+
config,
|
|
182
|
+
auth
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
let traceTool = SlateTool.create(spec, {
|
|
186
|
+
key: 'trace_http_error',
|
|
187
|
+
name: 'Trace HTTP Error'
|
|
188
|
+
})
|
|
189
|
+
.input(z.object({}))
|
|
190
|
+
.output(
|
|
191
|
+
z.object({
|
|
192
|
+
ok: z.boolean()
|
|
193
|
+
})
|
|
194
|
+
)
|
|
195
|
+
.handleInvocation(async () => {
|
|
196
|
+
await axios.post(
|
|
197
|
+
`${baseUrl}/trace-error?client_secret=request-secret`,
|
|
198
|
+
new URLSearchParams({
|
|
199
|
+
grant_type: 'authorization_code',
|
|
200
|
+
client_secret: 'client-secret'
|
|
201
|
+
}).toString(),
|
|
202
|
+
{
|
|
203
|
+
headers: {
|
|
204
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
205
|
+
Authorization: 'Bearer client-token'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
output: {
|
|
212
|
+
ok: true
|
|
213
|
+
},
|
|
214
|
+
message: 'should not reach'
|
|
215
|
+
};
|
|
216
|
+
})
|
|
217
|
+
.build();
|
|
218
|
+
|
|
219
|
+
return Slate.create({
|
|
220
|
+
spec,
|
|
221
|
+
tools: [traceTool],
|
|
222
|
+
triggers: []
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
173
226
|
let createTriggerTraceSlate = () => {
|
|
174
227
|
let config = SlateConfig.create(z.object({}));
|
|
175
228
|
let auth = SlateAuth.create<{}>().output(z.object({}));
|
|
@@ -566,4 +619,56 @@ describe('@slates/client local transport', () => {
|
|
|
566
619
|
});
|
|
567
620
|
}
|
|
568
621
|
});
|
|
622
|
+
|
|
623
|
+
it('returns sanitized request traces on provider errors', async () => {
|
|
624
|
+
let server = createServer((_req, res) => {
|
|
625
|
+
res.statusCode = 400;
|
|
626
|
+
res.setHeader('Content-Type', 'application/json');
|
|
627
|
+
res.end(
|
|
628
|
+
JSON.stringify({
|
|
629
|
+
error: 'invalid_grant',
|
|
630
|
+
client_secret: 'server-secret'
|
|
631
|
+
})
|
|
632
|
+
);
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
await new Promise<void>((resolve, reject) => {
|
|
636
|
+
server.once('error', reject);
|
|
637
|
+
server.listen(0, '127.0.0.1', () => resolve());
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
try {
|
|
641
|
+
let { port } = server.address() as AddressInfo;
|
|
642
|
+
let client = createSlatesClient({
|
|
643
|
+
transport: createLocalSlateTransport({
|
|
644
|
+
slate: createTraceErrorSlate(`http://127.0.0.1:${port}`)
|
|
645
|
+
}),
|
|
646
|
+
state: {
|
|
647
|
+
config: {}
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
let error = await client
|
|
652
|
+
.invokeTool('trace_http_error', {})
|
|
653
|
+
.then(() => null)
|
|
654
|
+
.catch(err => err as SlateProtocolError);
|
|
655
|
+
|
|
656
|
+
expect(error).toBeInstanceOf(SlateProtocolError);
|
|
657
|
+
expect(error?.data.code).toBe('upstream.invalid_request');
|
|
658
|
+
expect(error?.data.requestTraces).toHaveLength(1);
|
|
659
|
+
|
|
660
|
+
let trace = error?.data.requestTraces?.[0] as Record<string, any> | undefined;
|
|
661
|
+
expect(trace?.request.method).toBe('POST');
|
|
662
|
+
expect(trace?.request.url).not.toContain('request-secret');
|
|
663
|
+
expect(trace?.request.headers).not.toHaveProperty('authorization');
|
|
664
|
+
expect(trace?.request.body?.text).toContain('client_secret=[redacted]');
|
|
665
|
+
expect(trace?.response?.status).toBe(400);
|
|
666
|
+
expect(trace?.response?.body?.text).toContain('"client_secret":"[redacted]"');
|
|
667
|
+
expect(trace?.response?.body?.text).not.toContain('server-secret');
|
|
668
|
+
} finally {
|
|
669
|
+
await new Promise<void>((resolve, reject) => {
|
|
670
|
+
server.close(error => (error ? reject(error) : resolve()));
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
});
|
|
569
674
|
});
|
package/src/error.ts
CHANGED