@slates/client 1.0.0-rc.13 → 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 +2 -1
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.module.js +2 -1
- package/package.json +4 -4
- package/src/client.test.ts +140 -2
- package/src/client.ts +3 -1
package/dist/index.cjs
CHANGED
|
@@ -343,7 +343,8 @@ var SlatesProtocolClient = class {
|
|
|
343
343
|
encoding: "base64",
|
|
344
344
|
content: encodedBody
|
|
345
345
|
} : null,
|
|
346
|
-
state: d.state ?? null
|
|
346
|
+
state: d.state ?? null,
|
|
347
|
+
registrationDetails: d.registrationDetails ?? null
|
|
347
348
|
});
|
|
348
349
|
}
|
|
349
350
|
async unregisterTriggerWebhook(d) {
|
package/dist/index.d.cts
CHANGED
|
@@ -95,6 +95,26 @@ declare class SlatesProtocolClient {
|
|
|
95
95
|
type: "webhook";
|
|
96
96
|
autoRegistration: boolean;
|
|
97
97
|
autoUnregistration: boolean;
|
|
98
|
+
http?: {
|
|
99
|
+
methods?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
100
|
+
sync?: {
|
|
101
|
+
mode: "match" | "never" | "always";
|
|
102
|
+
match?: {
|
|
103
|
+
method?: string | undefined;
|
|
104
|
+
hasQueryParam?: string | undefined;
|
|
105
|
+
hasHeader?: string | undefined;
|
|
106
|
+
jsonBodyField?: {
|
|
107
|
+
path: string;
|
|
108
|
+
equals?: string | undefined;
|
|
109
|
+
} | undefined;
|
|
110
|
+
formBodyField?: {
|
|
111
|
+
path: string;
|
|
112
|
+
equals?: string | undefined;
|
|
113
|
+
} | undefined;
|
|
114
|
+
}[] | undefined;
|
|
115
|
+
timeoutMs?: number | undefined;
|
|
116
|
+
} | undefined;
|
|
117
|
+
} | undefined;
|
|
98
118
|
};
|
|
99
119
|
description?: string | undefined;
|
|
100
120
|
instructions?: string[] | undefined;
|
|
@@ -177,6 +197,7 @@ declare class SlatesProtocolClient {
|
|
|
177
197
|
headers?: Record<string, string>;
|
|
178
198
|
body?: string | Uint8Array | null;
|
|
179
199
|
state?: any;
|
|
200
|
+
registrationDetails?: any;
|
|
180
201
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
181
202
|
unregisterTriggerWebhook(d: {
|
|
182
203
|
actionId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -95,6 +95,26 @@ declare class SlatesProtocolClient {
|
|
|
95
95
|
type: "webhook";
|
|
96
96
|
autoRegistration: boolean;
|
|
97
97
|
autoUnregistration: boolean;
|
|
98
|
+
http?: {
|
|
99
|
+
methods?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
100
|
+
sync?: {
|
|
101
|
+
mode: "match" | "never" | "always";
|
|
102
|
+
match?: {
|
|
103
|
+
method?: string | undefined;
|
|
104
|
+
hasQueryParam?: string | undefined;
|
|
105
|
+
hasHeader?: string | undefined;
|
|
106
|
+
jsonBodyField?: {
|
|
107
|
+
path: string;
|
|
108
|
+
equals?: string | undefined;
|
|
109
|
+
} | undefined;
|
|
110
|
+
formBodyField?: {
|
|
111
|
+
path: string;
|
|
112
|
+
equals?: string | undefined;
|
|
113
|
+
} | undefined;
|
|
114
|
+
}[] | undefined;
|
|
115
|
+
timeoutMs?: number | undefined;
|
|
116
|
+
} | undefined;
|
|
117
|
+
} | undefined;
|
|
98
118
|
};
|
|
99
119
|
description?: string | undefined;
|
|
100
120
|
instructions?: string[] | undefined;
|
|
@@ -177,6 +197,7 @@ declare class SlatesProtocolClient {
|
|
|
177
197
|
headers?: Record<string, string>;
|
|
178
198
|
body?: string | Uint8Array | null;
|
|
179
199
|
state?: any;
|
|
200
|
+
registrationDetails?: any;
|
|
180
201
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
181
202
|
unregisterTriggerWebhook(d: {
|
|
182
203
|
actionId: string;
|
package/dist/index.module.js
CHANGED
|
@@ -316,7 +316,8 @@ var SlatesProtocolClient = class {
|
|
|
316
316
|
encoding: "base64",
|
|
317
317
|
content: encodedBody
|
|
318
318
|
} : null,
|
|
319
|
-
state: d.state ?? null
|
|
319
|
+
state: d.state ?? null,
|
|
320
|
+
registrationDetails: d.registrationDetails ?? null
|
|
320
321
|
});
|
|
321
322
|
}
|
|
322
323
|
async unregisterTriggerWebhook(d) {
|
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.14",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"biome:check": "biome check --write src"
|
|
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.13",
|
|
35
|
+
"@slates/provider": "1.0.0-rc.17",
|
|
36
|
+
"@slates/provider-handler": "1.0.0-rc.19"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@slates/tsconfig": "1.0.0-rc.1",
|
package/src/client.test.ts
CHANGED
|
@@ -312,7 +312,14 @@ let createTriggerTraceSlate = () => {
|
|
|
312
312
|
)
|
|
313
313
|
.webhook({
|
|
314
314
|
handleRequest: async () => ({
|
|
315
|
-
inputs: [{ id: 'webhook-1' }, { id: 'webhook-2' }]
|
|
315
|
+
inputs: [{ id: 'webhook-1' }, { id: 'webhook-2' }],
|
|
316
|
+
response: {
|
|
317
|
+
status: 202,
|
|
318
|
+
headers: {
|
|
319
|
+
'x-trigger-result': 'accepted'
|
|
320
|
+
},
|
|
321
|
+
body: 'accepted'
|
|
322
|
+
}
|
|
316
323
|
}),
|
|
317
324
|
handleEvent: async ctx => ({
|
|
318
325
|
id: ctx.input.id,
|
|
@@ -429,6 +436,83 @@ let createOauthConfigSlate = (seenConfig: SeenOAuthConfig) => {
|
|
|
429
436
|
});
|
|
430
437
|
};
|
|
431
438
|
|
|
439
|
+
type TokenConfig = {
|
|
440
|
+
prefix: string;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
type SeenTokenConfig = Partial<Record<'output' | 'profile', TokenConfig>>;
|
|
444
|
+
|
|
445
|
+
let getRequiredTokenConfig = (ctx: { config?: Record<string, unknown> }): TokenConfig => {
|
|
446
|
+
expect(ctx.config).toBeDefined();
|
|
447
|
+
return ctx.config as TokenConfig;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
type TokenAuthOutputContext = {
|
|
451
|
+
input: { token: string };
|
|
452
|
+
config?: Record<string, unknown>;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
type TokenAuthProfileContext = {
|
|
456
|
+
output: { token: string };
|
|
457
|
+
config?: Record<string, unknown>;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
let createTokenConfigSlate = (seenConfig: SeenTokenConfig) => {
|
|
461
|
+
let config = SlateConfig.create(
|
|
462
|
+
z.object({
|
|
463
|
+
prefix: z.string()
|
|
464
|
+
})
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
let auth = SlateAuth.create<{ token: string }>()
|
|
468
|
+
.output(
|
|
469
|
+
z.object({
|
|
470
|
+
token: z.string()
|
|
471
|
+
})
|
|
472
|
+
)
|
|
473
|
+
.addTokenAuth({
|
|
474
|
+
type: 'auth.token',
|
|
475
|
+
key: 'token_auth',
|
|
476
|
+
name: 'Token Auth',
|
|
477
|
+
inputSchema: z.object({
|
|
478
|
+
token: z.string()
|
|
479
|
+
}),
|
|
480
|
+
getOutput: async (ctx: TokenAuthOutputContext) => {
|
|
481
|
+
let currentConfig = getRequiredTokenConfig(ctx);
|
|
482
|
+
seenConfig.output = currentConfig;
|
|
483
|
+
return {
|
|
484
|
+
output: {
|
|
485
|
+
token: `${currentConfig.prefix}:${ctx.input.token}`
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
getProfile: async (ctx: TokenAuthProfileContext) => {
|
|
490
|
+
let currentConfig = getRequiredTokenConfig(ctx);
|
|
491
|
+
seenConfig.profile = currentConfig;
|
|
492
|
+
return {
|
|
493
|
+
profile: {
|
|
494
|
+
prefix: currentConfig.prefix,
|
|
495
|
+
token: ctx.output.token
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
let spec = SlateSpecification.create({
|
|
502
|
+
key: 'token-config-slate',
|
|
503
|
+
name: 'Token Config Slate',
|
|
504
|
+
description: 'A slate that reads config in token auth hooks',
|
|
505
|
+
config,
|
|
506
|
+
auth
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
return Slate.create({
|
|
510
|
+
spec,
|
|
511
|
+
tools: [],
|
|
512
|
+
triggers: []
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
|
|
432
516
|
describe('@slates/client local transport', () => {
|
|
433
517
|
it('discovers auth/config and invokes tools with session state', async () => {
|
|
434
518
|
let slate = createDemoSlate();
|
|
@@ -618,7 +702,7 @@ describe('@slates/client local transport', () => {
|
|
|
618
702
|
state: null
|
|
619
703
|
});
|
|
620
704
|
|
|
621
|
-
await client.request('slates/action.trigger.webhook_handle', {
|
|
705
|
+
let webhookResult = await client.request('slates/action.trigger.webhook_handle', {
|
|
622
706
|
actionId: 'webhook_trigger',
|
|
623
707
|
url: 'https://example.com/webhook',
|
|
624
708
|
method: 'POST',
|
|
@@ -628,6 +712,16 @@ describe('@slates/client local transport', () => {
|
|
|
628
712
|
body: null,
|
|
629
713
|
state: null
|
|
630
714
|
});
|
|
715
|
+
expect(webhookResult.response).toEqual({
|
|
716
|
+
status: 202,
|
|
717
|
+
headers: {
|
|
718
|
+
'x-trigger-result': 'accepted'
|
|
719
|
+
},
|
|
720
|
+
body: {
|
|
721
|
+
encoding: 'base64',
|
|
722
|
+
content: Buffer.from('accepted').toString('base64')
|
|
723
|
+
}
|
|
724
|
+
});
|
|
631
725
|
|
|
632
726
|
await waitForLogs();
|
|
633
727
|
|
|
@@ -651,6 +745,7 @@ describe('@slates/client local transport', () => {
|
|
|
651
745
|
component: 'action',
|
|
652
746
|
functionName: 'handleRequest',
|
|
653
747
|
inputCount: 2,
|
|
748
|
+
hasResponse: true,
|
|
654
749
|
actionId: 'webhook_trigger'
|
|
655
750
|
})
|
|
656
751
|
})
|
|
@@ -732,6 +827,49 @@ describe('@slates/client local transport', () => {
|
|
|
732
827
|
});
|
|
733
828
|
});
|
|
734
829
|
|
|
830
|
+
it('passes current profile config into token auth callbacks', async () => {
|
|
831
|
+
let seenConfig: SeenTokenConfig = {};
|
|
832
|
+
let client = createSlatesClient({
|
|
833
|
+
transport: createLocalSlateTransport({
|
|
834
|
+
slate: createTokenConfigSlate(seenConfig)
|
|
835
|
+
}),
|
|
836
|
+
state: {
|
|
837
|
+
config: {
|
|
838
|
+
prefix: 'configured'
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
let authOutput = await client.getAuthOutput({
|
|
844
|
+
authenticationMethodId: 'token_auth',
|
|
845
|
+
input: {
|
|
846
|
+
token: 'secret-token'
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
expect(authOutput.output).toEqual({
|
|
851
|
+
token: 'configured:secret-token'
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
let profile = await client.getAuthProfile({
|
|
855
|
+
authenticationMethodId: 'token_auth',
|
|
856
|
+
output: authOutput.output,
|
|
857
|
+
input: {
|
|
858
|
+
token: 'secret-token'
|
|
859
|
+
},
|
|
860
|
+
scopes: []
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
expect(profile.profile).toEqual({
|
|
864
|
+
prefix: 'configured',
|
|
865
|
+
token: 'configured:secret-token'
|
|
866
|
+
});
|
|
867
|
+
expect(seenConfig).toEqual({
|
|
868
|
+
output: { prefix: 'configured' },
|
|
869
|
+
profile: { prefix: 'configured' }
|
|
870
|
+
});
|
|
871
|
+
});
|
|
872
|
+
|
|
735
873
|
it('throws structured protocol errors for provider responses', async () => {
|
|
736
874
|
let client = createSlatesClient({
|
|
737
875
|
transport: {
|
package/src/client.ts
CHANGED
|
@@ -356,6 +356,7 @@ export class SlatesProtocolClient {
|
|
|
356
356
|
headers?: Record<string, string>;
|
|
357
357
|
body?: string | Uint8Array | null;
|
|
358
358
|
state?: any;
|
|
359
|
+
registrationDetails?: any;
|
|
359
360
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']> {
|
|
360
361
|
this.ensureSession();
|
|
361
362
|
let encodedBody =
|
|
@@ -376,7 +377,8 @@ export class SlatesProtocolClient {
|
|
|
376
377
|
content: encodedBody
|
|
377
378
|
}
|
|
378
379
|
: null,
|
|
379
|
-
state: d.state ?? null
|
|
380
|
+
state: d.state ?? null,
|
|
381
|
+
registrationDetails: d.registrationDetails ?? null
|
|
380
382
|
});
|
|
381
383
|
}
|
|
382
384
|
|