@slates/client 1.0.0-rc.12 → 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 +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.module.js +2 -1
- package/package.json +4 -4
- package/src/client.test.ts +156 -12
- 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
|
@@ -74,6 +74,7 @@ declare class SlatesProtocolClient {
|
|
|
74
74
|
OR: string[];
|
|
75
75
|
}[];
|
|
76
76
|
} | undefined;
|
|
77
|
+
authMethods?: string[] | undefined;
|
|
77
78
|
}>;
|
|
78
79
|
getTrigger(actionId: string): Promise<{
|
|
79
80
|
id: string;
|
|
@@ -94,6 +95,26 @@ declare class SlatesProtocolClient {
|
|
|
94
95
|
type: "webhook";
|
|
95
96
|
autoRegistration: boolean;
|
|
96
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;
|
|
97
118
|
};
|
|
98
119
|
description?: string | undefined;
|
|
99
120
|
instructions?: string[] | undefined;
|
|
@@ -108,6 +129,7 @@ declare class SlatesProtocolClient {
|
|
|
108
129
|
OR: string[];
|
|
109
130
|
}[];
|
|
110
131
|
} | undefined;
|
|
132
|
+
authMethods?: string[] | undefined;
|
|
111
133
|
}>;
|
|
112
134
|
getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']>;
|
|
113
135
|
getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']>;
|
|
@@ -175,6 +197,7 @@ declare class SlatesProtocolClient {
|
|
|
175
197
|
headers?: Record<string, string>;
|
|
176
198
|
body?: string | Uint8Array | null;
|
|
177
199
|
state?: any;
|
|
200
|
+
registrationDetails?: any;
|
|
178
201
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
179
202
|
unregisterTriggerWebhook(d: {
|
|
180
203
|
actionId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ declare class SlatesProtocolClient {
|
|
|
74
74
|
OR: string[];
|
|
75
75
|
}[];
|
|
76
76
|
} | undefined;
|
|
77
|
+
authMethods?: string[] | undefined;
|
|
77
78
|
}>;
|
|
78
79
|
getTrigger(actionId: string): Promise<{
|
|
79
80
|
id: string;
|
|
@@ -94,6 +95,26 @@ declare class SlatesProtocolClient {
|
|
|
94
95
|
type: "webhook";
|
|
95
96
|
autoRegistration: boolean;
|
|
96
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;
|
|
97
118
|
};
|
|
98
119
|
description?: string | undefined;
|
|
99
120
|
instructions?: string[] | undefined;
|
|
@@ -108,6 +129,7 @@ declare class SlatesProtocolClient {
|
|
|
108
129
|
OR: string[];
|
|
109
130
|
}[];
|
|
110
131
|
} | undefined;
|
|
132
|
+
authMethods?: string[] | undefined;
|
|
111
133
|
}>;
|
|
112
134
|
getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']>;
|
|
113
135
|
getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']>;
|
|
@@ -175,6 +197,7 @@ declare class SlatesProtocolClient {
|
|
|
175
197
|
headers?: Record<string, string>;
|
|
176
198
|
body?: string | Uint8Array | null;
|
|
177
199
|
state?: any;
|
|
200
|
+
registrationDetails?: any;
|
|
178
201
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
179
202
|
unregisterTriggerWebhook(d: {
|
|
180
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
|
@@ -30,15 +30,17 @@ let createDemoSlate = () => {
|
|
|
30
30
|
z.object({
|
|
31
31
|
prefix: z.string()
|
|
32
32
|
})
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
)
|
|
34
|
+
.getDefaultConfig(() => ({
|
|
35
|
+
prefix: 'Hello'
|
|
36
|
+
}))
|
|
37
|
+
.docs([
|
|
38
|
+
{
|
|
39
|
+
type: 'docs.config.general',
|
|
40
|
+
name: 'Demo config docs',
|
|
41
|
+
url: 'https://example.com/docs/config'
|
|
42
|
+
}
|
|
43
|
+
]);
|
|
42
44
|
|
|
43
45
|
let demoAuth = SlateAuth.create<{ token: string }>()
|
|
44
46
|
.output(
|
|
@@ -71,7 +73,8 @@ let createDemoSlate = () => {
|
|
|
71
73
|
getOutput: async (ctx: { input: { token: string } }) => ({
|
|
72
74
|
output: {
|
|
73
75
|
token: ctx.input.token
|
|
74
|
-
}
|
|
76
|
+
},
|
|
77
|
+
scopes: [`scope:${ctx.input.token}`]
|
|
75
78
|
}),
|
|
76
79
|
getProfile: async (ctx: { output: { token: string } }) => ({
|
|
77
80
|
profile: {
|
|
@@ -123,6 +126,7 @@ let createDemoSlate = () => {
|
|
|
123
126
|
}
|
|
124
127
|
]
|
|
125
128
|
})
|
|
129
|
+
.authMethods(['token_auth'])
|
|
126
130
|
.handleInvocation(async ctx => ({
|
|
127
131
|
output: {
|
|
128
132
|
greeting: `${ctx.config.prefix} ${ctx.input.name}`,
|
|
@@ -308,7 +312,14 @@ let createTriggerTraceSlate = () => {
|
|
|
308
312
|
)
|
|
309
313
|
.webhook({
|
|
310
314
|
handleRequest: async () => ({
|
|
311
|
-
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
|
+
}
|
|
312
323
|
}),
|
|
313
324
|
handleEvent: async ctx => ({
|
|
314
325
|
id: ctx.input.id,
|
|
@@ -425,6 +436,83 @@ let createOauthConfigSlate = (seenConfig: SeenOAuthConfig) => {
|
|
|
425
436
|
});
|
|
426
437
|
};
|
|
427
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
|
+
|
|
428
516
|
describe('@slates/client local transport', () => {
|
|
429
517
|
it('discovers auth/config and invokes tools with session state', async () => {
|
|
430
518
|
let slate = createDemoSlate();
|
|
@@ -458,6 +546,7 @@ describe('@slates/client local transport', () => {
|
|
|
458
546
|
}
|
|
459
547
|
]
|
|
460
548
|
});
|
|
549
|
+
expect(actions[0]!.authMethods).toEqual(['token_auth']);
|
|
461
550
|
|
|
462
551
|
let configSchema = await client.getConfigSchema();
|
|
463
552
|
expect(configSchema.schema.properties.prefix.type).toBe('string');
|
|
@@ -498,6 +587,7 @@ describe('@slates/client local transport', () => {
|
|
|
498
587
|
input: changedInput.input ?? { token: '' }
|
|
499
588
|
});
|
|
500
589
|
expect(authOutput.output).toEqual({ token: 'trimmed-token' });
|
|
590
|
+
expect(authOutput.scopes).toEqual(['scope:trimmed-token']);
|
|
501
591
|
|
|
502
592
|
client.setConfig({ prefix: 'Hi' });
|
|
503
593
|
client.setAuth({
|
|
@@ -612,7 +702,7 @@ describe('@slates/client local transport', () => {
|
|
|
612
702
|
state: null
|
|
613
703
|
});
|
|
614
704
|
|
|
615
|
-
await client.request('slates/action.trigger.webhook_handle', {
|
|
705
|
+
let webhookResult = await client.request('slates/action.trigger.webhook_handle', {
|
|
616
706
|
actionId: 'webhook_trigger',
|
|
617
707
|
url: 'https://example.com/webhook',
|
|
618
708
|
method: 'POST',
|
|
@@ -622,6 +712,16 @@ describe('@slates/client local transport', () => {
|
|
|
622
712
|
body: null,
|
|
623
713
|
state: null
|
|
624
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
|
+
});
|
|
625
725
|
|
|
626
726
|
await waitForLogs();
|
|
627
727
|
|
|
@@ -645,6 +745,7 @@ describe('@slates/client local transport', () => {
|
|
|
645
745
|
component: 'action',
|
|
646
746
|
functionName: 'handleRequest',
|
|
647
747
|
inputCount: 2,
|
|
748
|
+
hasResponse: true,
|
|
648
749
|
actionId: 'webhook_trigger'
|
|
649
750
|
})
|
|
650
751
|
})
|
|
@@ -726,6 +827,49 @@ describe('@slates/client local transport', () => {
|
|
|
726
827
|
});
|
|
727
828
|
});
|
|
728
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
|
+
|
|
729
873
|
it('throws structured protocol errors for provider responses', async () => {
|
|
730
874
|
let client = createSlatesClient({
|
|
731
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
|
|