@slates/client 1.0.0-rc.6 → 1.0.0-rc.8

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/src/client.ts CHANGED
@@ -1,13 +1,30 @@
1
1
  import {
2
2
  SLATES_PROTOCOL_VERSION,
3
- SlateAuthenticationMethod,
4
- SlatesAction,
5
3
  SlatesParticipant,
6
- slatesRequestsByMethod,
7
- slatesResponsesByMethod
4
+ type SlateAuthenticationMethod,
5
+ type SlatesAction,
6
+ type SlatesMessageActionGetResponse,
7
+ type SlatesMessageActionInvokeResponse,
8
+ type SlatesMessageActionsListResponse,
9
+ type SlatesMessageActionTriggerEventMapResponse,
10
+ type SlatesMessageActionTriggerWebhookHandleResponse,
11
+ type SlatesMessageActionTriggerWebhookRegisterResponse,
12
+ type SlatesMessageActionTriggerWebhookUnregisterResponse,
13
+ type SlatesMessageAuthAuthorizationUrlGetResponse,
14
+ type SlatesMessageAuthDefaultInputGetResponse,
15
+ type SlatesMessageAuthInputChangedResponse,
16
+ type SlatesMessageAuthMethodGetResponse,
17
+ type SlatesMessageAuthOutputGetResponse,
18
+ type SlatesMessageAuthProfileGetResponse,
19
+ type SlatesMessageAuthTokenRefreshHandleResponse,
20
+ type SlatesMessageConfigChangedResponse,
21
+ type SlatesMessageConfigDefaultGetResponse,
22
+ type SlatesMessageConfigSchemaGetResponse,
23
+ type SlatesMessageProviderIdentifyResponse,
24
+ type SlatesRequests,
25
+ type SlatesResponsesByMethod
8
26
  } from '@slates/proto';
9
27
  import { randomUUID } from 'crypto';
10
- import z from 'zod';
11
28
  import { SlateProtocolError } from './error';
12
29
  import { SlatesClientState, SlatesProtocolClientOptions } from './types';
13
30
 
@@ -118,10 +135,10 @@ export class SlatesProtocolClient {
118
135
  ];
119
136
  }
120
137
 
121
- async request<Key extends keyof typeof slatesRequestsByMethod>(
138
+ async request<Key extends keyof SlatesResponsesByMethod & SlatesRequests['method']>(
122
139
  method: Key,
123
- params: z.infer<(typeof slatesRequestsByMethod)[Key]>['params']
124
- ): Promise<z.infer<(typeof slatesResponsesByMethod)[Key]>['result']> {
140
+ params: Extract<SlatesRequests, { method: Key }>['params']
141
+ ): Promise<SlatesResponsesByMethod[Key]['result']> {
125
142
  let id = randomUUID();
126
143
  let responses = await this.transport.send([
127
144
  ...this.buildStateMessages(),
@@ -130,7 +147,7 @@ export class SlatesProtocolClient {
130
147
  id,
131
148
  method,
132
149
  params
133
- } as z.infer<(typeof slatesRequestsByMethod)[Key]>
150
+ } as Extract<SlatesRequests, { method: Key }>
134
151
  ]);
135
152
 
136
153
  let response = responses.find(message => 'id' in message && message.id === id) as
@@ -148,11 +165,11 @@ export class SlatesProtocolClient {
148
165
  return response.result;
149
166
  }
150
167
 
151
- async identify() {
168
+ async identify(): Promise<SlatesMessageProviderIdentifyResponse['result']> {
152
169
  return this.request('slates/provider.identify', {});
153
170
  }
154
171
 
155
- async listActions() {
172
+ async listActions(): Promise<SlatesMessageActionsListResponse['result']> {
156
173
  return this.request('slates/actions.list', {});
157
174
  }
158
175
 
@@ -166,7 +183,7 @@ export class SlatesProtocolClient {
166
183
  return result.actions.filter(action => action.type === 'action.trigger');
167
184
  }
168
185
 
169
- async getAction(actionId: string) {
186
+ async getAction(actionId: string): Promise<SlatesMessageActionGetResponse['result']> {
170
187
  return this.request('slates/action.get', { actionId });
171
188
  }
172
189
 
@@ -188,18 +205,18 @@ export class SlatesProtocolClient {
188
205
  return result.action;
189
206
  }
190
207
 
191
- async getConfigSchema() {
208
+ async getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']> {
192
209
  return this.request('slates/config.schema.get', {});
193
210
  }
194
211
 
195
- async getDefaultConfig() {
212
+ async getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']> {
196
213
  return this.request('slates/config.get_default', {});
197
214
  }
198
215
 
199
216
  async updateConfig(
200
217
  previousConfig: Record<string, any> | null,
201
218
  newConfig: Record<string, any>
202
- ) {
219
+ ): Promise<SlatesMessageConfigChangedResponse['result']> {
203
220
  return this.request('slates/config.changed', {
204
221
  previousConfig,
205
222
  newConfig
@@ -210,13 +227,17 @@ export class SlatesProtocolClient {
210
227
  return this.request('slates/auth.methods.list', {});
211
228
  }
212
229
 
213
- async getAuthMethod(authenticationMethodId: string) {
230
+ async getAuthMethod(
231
+ authenticationMethodId: string
232
+ ): Promise<SlatesMessageAuthMethodGetResponse['result']> {
214
233
  return this.request('slates/auth.method.get', {
215
234
  authenticationMethodId
216
235
  });
217
236
  }
218
237
 
219
- async getDefaultAuthInput(authenticationMethodId: string) {
238
+ async getDefaultAuthInput(
239
+ authenticationMethodId: string
240
+ ): Promise<SlatesMessageAuthDefaultInputGetResponse['result']> {
220
241
  return this.request('slates/auth.input.get_default', {
221
242
  authenticationMethodId
222
243
  });
@@ -226,7 +247,7 @@ export class SlatesProtocolClient {
226
247
  authenticationMethodId: string;
227
248
  previousInput: Record<string, any> | null;
228
249
  newInput: Record<string, any>;
229
- }) {
250
+ }): Promise<SlatesMessageAuthInputChangedResponse['result']> {
230
251
  return this.request('slates/auth.input.changed', {
231
252
  authenticationMethodId: d.authenticationMethodId,
232
253
  previousInput: d.previousInput,
@@ -234,7 +255,10 @@ export class SlatesProtocolClient {
234
255
  });
235
256
  }
236
257
 
237
- async getAuthOutput(d: { authenticationMethodId: string; input: Record<string, any> }) {
258
+ async getAuthOutput(d: {
259
+ authenticationMethodId: string;
260
+ input: Record<string, any>;
261
+ }): Promise<SlatesMessageAuthOutputGetResponse['result']> {
238
262
  return this.request('slates/auth.output.get', {
239
263
  authenticationMethodId: d.authenticationMethodId,
240
264
  input: d.input
@@ -249,7 +273,7 @@ export class SlatesProtocolClient {
249
273
  clientId: string;
250
274
  clientSecret: string;
251
275
  scopes: string[];
252
- }) {
276
+ }): Promise<SlatesMessageAuthAuthorizationUrlGetResponse['result']> {
253
277
  return this.request('slates/auth.authorization_url.get', d);
254
278
  }
255
279
 
@@ -262,6 +286,7 @@ export class SlatesProtocolClient {
262
286
  clientId: string;
263
287
  clientSecret: string;
264
288
  scopes: string[];
289
+ callbackParams?: Record<string, string>;
265
290
  callbackState?: Record<string, any>;
266
291
  }): Promise<{
267
292
  output: Record<string, any>;
@@ -278,7 +303,7 @@ export class SlatesProtocolClient {
278
303
  clientId: string;
279
304
  clientSecret: string;
280
305
  scopes: string[];
281
- }) {
306
+ }): Promise<SlatesMessageAuthTokenRefreshHandleResponse['result']> {
282
307
  return this.request('slates/auth.token_refresh.handle', d);
283
308
  }
284
309
 
@@ -287,11 +312,14 @@ export class SlatesProtocolClient {
287
312
  output: Record<string, any>;
288
313
  input: Record<string, any>;
289
314
  scopes: string[];
290
- }) {
315
+ }): Promise<SlatesMessageAuthProfileGetResponse['result']> {
291
316
  return this.request('slates/auth.profile.get', d);
292
317
  }
293
318
 
294
- async invokeTool(actionId: string, input: Record<string, any>) {
319
+ async invokeTool(
320
+ actionId: string,
321
+ input: Record<string, any>
322
+ ): Promise<SlatesMessageActionInvokeResponse['result']> {
295
323
  this.ensureSession();
296
324
  return this.request('slates/action.tool.invoke', {
297
325
  actionId,
@@ -299,7 +327,10 @@ export class SlatesProtocolClient {
299
327
  });
300
328
  }
301
329
 
302
- async mapTriggerEvent(actionId: string, input: Record<string, any>) {
330
+ async mapTriggerEvent(
331
+ actionId: string,
332
+ input: Record<string, any>
333
+ ): Promise<SlatesMessageActionTriggerEventMapResponse['result']> {
303
334
  this.ensureSession();
304
335
  return this.request('slates/action.trigger.map_event', {
305
336
  actionId,
@@ -307,7 +338,10 @@ export class SlatesProtocolClient {
307
338
  });
308
339
  }
309
340
 
310
- async registerTriggerWebhook(actionId: string, webhookBaseUrl: string) {
341
+ async registerTriggerWebhook(
342
+ actionId: string,
343
+ webhookBaseUrl: string
344
+ ): Promise<SlatesMessageActionTriggerWebhookRegisterResponse['result']> {
311
345
  this.ensureSession();
312
346
  return this.request('slates/action.trigger.webhook_register', {
313
347
  actionId,
@@ -322,7 +356,7 @@ export class SlatesProtocolClient {
322
356
  headers?: Record<string, string>;
323
357
  body?: string | Uint8Array | null;
324
358
  state?: any;
325
- }) {
359
+ }): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']> {
326
360
  this.ensureSession();
327
361
  let encodedBody =
328
362
  typeof d.body === 'string'
@@ -351,7 +385,7 @@ export class SlatesProtocolClient {
351
385
  webhookBaseUrl: string;
352
386
  registrationDetails: any;
353
387
  state?: any;
354
- }) {
388
+ }): Promise<SlatesMessageActionTriggerWebhookUnregisterResponse['result']> {
355
389
  this.ensureSession();
356
390
  return this.request('slates/action.trigger.webhook_unregister', {
357
391
  actionId: d.actionId,