spiral-sdk 0.1.10

Rust SDK for Spiral resource and table APIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
// Generated by tools/service-contracts/rust.py. Do not edit.
#![doc = "Generated implementation of authenticated SDK resource facades."]
use spiral_contract::call::CallError;

use crate::api::apps::AppsClient;
use crate::api::apps::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
/// Service operations sharing a connection pool and resolving credentials for every request.
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
    http: HttpClient,
    client: AppsClient,
}
impl AuthenticatedClient {
    /// Connect with bounded requests; configure credentials before authenticated calls.
    pub fn new(base: &str) -> Result<Self, CallError<AppsError>> {
        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
    }
    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<AppsError>> {
        let client =
            AppsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
        Ok(Self { http, client })
    }
    /// Reuse a connection pool with redirects disabled to protect bearer credentials.
    pub fn with_client(mut self, client: reqwest::Client) -> Self {
        self.http = self.http.with_client(client);
        self.client = self.client.with_transport(self.http.middleware_client());
        self
    }
    /// Resolve the provider's current credential before each request and pagination fetch.
    pub fn with_token_source(mut self, provider: TokenSource) -> Self {
        self.http = self.http.with_token_source(provider);
        self
    }
    /// Approve the latest request of an installation. Only an Organization owner can approve. The
    /// Application must have a background identity.
    pub async fn approve_installation(
        &self,
        installation_id: String,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .approve_installation_http(auth_header, installation_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Create an active Application in a Project. The service generates the client ID of the
    /// Application. Only a Project administrator can create an Application.
    pub async fn create_application(
        &self,
        project_id: String,
        request: ApplicationConfiguration,
    ) -> Result<Application, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .create_application_http(auth_header, project_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Decide this user authorization. Required installation access must be active before approval.
    /// Return the browser to redirectTo to complete OAuth.
    pub async fn decide_consent(
        &self,
        challenge: String,
        request: ConsentDecision,
    ) -> Result<ConsentRedirect, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .decide_consent_http(auth_header, challenge, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Permanently delete an Application and uninstall it from every Organization. Only a Project
    /// administrator can delete an Application. When the response is `RegistrationUnavailable`,
    /// send the same request again. Access tokens that were issued before the deletion stay valid
    /// until they expire.
    pub async fn delete_application(
        &self,
        application_id: String,
    ) -> Result<Application, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .delete_application_http(auth_header, application_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read an Application. A viewer of the Application's Project can read it.
    pub async fn get_application(
        &self,
        application_id: String,
    ) -> Result<Application, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .get_application_http(auth_header, application_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read the authorization bound to the authenticated first-party user and Organization.
    pub async fn get_consent_request(
        &self,
        challenge: String,
    ) -> Result<ConsentRequest, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.get_consent_request_http(auth_header, challenge),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires an installation token. Returns current metadata even when suspended; this does not
    /// grant project access.
    pub async fn get_current_installation(
        &self,
    ) -> Result<InstallationDetails, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.get_current_installation_http(auth_header),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires an Organization member. Shows a public Application, an Application owned by the
    /// Organization, or one already installed there. Does not grant access or permit viewing the
    /// developer's credentials or callbacks.
    pub async fn get_installable_application(
        &self,
        application_id: String,
    ) -> Result<InstallableApplication, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .get_installable_application_http(auth_header, application_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read an installation in your Organization. Any member of the Organization can read it.
    pub async fn get_installation(
        &self,
        installation_id: String,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .get_installation_http(auth_header, installation_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read which Applications and MCP clients the users of your Organization can sign in to. Only
    /// an Organization owner can read it.
    pub async fn get_organization_app_access(
        &self,
    ) -> Result<OrganizationAppAccess, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.get_organization_app_access_http(auth_header),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires an app token obtained with private-key client authentication or a trusted issuer
    /// JWT-bearer exchange. It grants no customer data access.
    pub async fn get_self(&self) -> Result<Application, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.get_self_http(auth_header),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires an app token. Installations belonging to another app return NotFound.
    pub async fn get_self_installation(
        &self,
        installation_id: String,
    ) -> Result<InstallationDetails, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .get_self_installation_http(auth_header, installation_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires a delegated user token with projects:read and current Organization membership. The
    /// app and Organization come from the credential.
    pub async fn get_user_installation(&self) -> Result<UserInstallation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.get_user_installation_http(auth_header),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// List the Organizations where your Application is installed. A viewer of the Application's
    /// Project can list them.
    pub async fn list_application_installations(
        &self,
        application_id: String,
        request: ListApplicationsRequest,
    ) -> Result<InstallationPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .list_application_installations_http(auth_header, application_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_application_installations_list(
        &self,
        application_id: String,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, Installation> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let application_id = ToOwned::to_owned(&application_id);
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self
                    .list_application_installations(application_id, request)
                    .await?;
                Ok(crate::Page {
                    items: page.installations,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// List the Applications of a Project. The list includes suspended and deleted Applications. A
    /// Project viewer can list them.
    pub async fn list_applications(
        &self,
        project_id: String,
        request: ListApplicationsRequest,
    ) -> Result<ApplicationPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .list_applications_http(auth_header, project_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_applications_list(
        &self,
        project_id: String,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, Application> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let project_id = ToOwned::to_owned(&project_id);
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self.list_applications(project_id, request).await?;
                Ok(crate::Page {
                    items: page.applications,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// Requires an installation token and approved projects:read. Returns only currently authorized
    /// live projects. Pending or inactive grants return no projects.
    pub async fn list_installation_projects(
        &self,
        request: ListApplicationsRequest,
    ) -> Result<InstallationProjectPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .list_installation_projects_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_installation_projects_list(
        &self,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, InstallationProject> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self.list_installation_projects(request).await?;
                Ok(crate::Page {
                    items: page.projects,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// List the installations in your Organization. Any member of the Organization can list them.
    pub async fn list_installations(
        &self,
        request: ListApplicationsRequest,
    ) -> Result<InstallationPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.list_installations_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_installations_list(
        &self,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, Installation> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self.list_installations(request).await?;
                Ok(crate::Page {
                    items: page.installations,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// List the resource scopes that an Application can request. Each scope has a description that
    /// you can show to users.
    pub async fn list_scopes(&self) -> Result<ApplicationScopes, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.list_scopes_http(auth_header),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Requires an app token. Includes only this app's requested, active and suspended
    /// installations.
    pub async fn list_self_installations(
        &self,
        request: ListApplicationsRequest,
    ) -> Result<InstallationPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .list_self_installations_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_self_installations_list(
        &self,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, Installation> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self.list_self_installations(request).await?;
                Ok(crate::Page {
                    items: page.installations,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// Requires a delegated user token with projects:read. The installation must belong to its app
    /// and Organization. Returns the intersection of current user and approved installation project
    /// access.
    pub async fn list_user_installation_projects(
        &self,
        installation_id: String,
        request: ListApplicationsRequest,
    ) -> Result<InstallationProjectPage, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .list_user_installation_projects_http(auth_header, installation_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
    pub fn list_user_installation_projects_list(
        &self,
        installation_id: String,
        request: ListApplicationsRequest,
    ) -> crate::List<'_, InstallationProject> {
        let options = crate::pagination::PageOptions {
            token: request.page_token.clone(),
            size: request.page_size,
        };
        crate::List::new(move |options| {
            let installation_id = ToOwned::to_owned(&installation_id);
            let mut request = request.clone();
            request.page_token = options.token;
            request.page_size = options.size;
            Box::pin(async move {
                let page = self
                    .list_user_installation_projects(installation_id, request)
                    .await?;
                Ok(crate::Page {
                    items: page.projects,
                    next_page_token: page.next_page_token,
                })
            })
        })
        .with_options(options)
    }
    /// Replace the configuration of an Application. The Application stays in its Project. Only a
    /// Project administrator can update an Application. When the response is
    /// `RegistrationUnavailable`, the Application does not change; send the same request again.
    pub async fn put_application(
        &self,
        application_id: String,
        request: ApplicationConfiguration,
    ) -> Result<Application, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .put_application_http(auth_header, application_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Replace which Applications and MCP clients the users of your Organization can sign in to.
    /// Only an Organization owner can set it. Sign-in and refresh apply the new setting from their
    /// next request.
    pub async fn put_organization_app_access(
        &self,
        request: OrganizationAppAccess,
    ) -> Result<OrganizationAppAccess, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .put_organization_app_access_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Request that an Application be installed in your Organization, or request more scopes or
    /// Projects for an existing installation. Any member of the Organization can send a request.
    /// The scopes must be registered on the Application. Until an owner approves the request, the
    /// installation keeps its earlier approval.
    pub async fn request_installation(
        &self,
        request: InstallationRequest,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.request_installation_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Only an Organization owner can approve or decline the displayed request. Returns Conflict if
    /// it changed. Declining an update preserves current access; declining a new installation
    /// removes it. The response describes the reviewed installation.
    pub async fn review_installation(
        &self,
        installation_id: String,
        request: InstallationReview,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .review_installation_http(auth_header, installation_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Suspend or resume an approved installation. Only an Organization owner can change it. A
    /// suspended installation stops at its next request, even with an unexpired token.
    pub async fn set_installation_status(
        &self,
        installation_id: String,
        request: InstallationStatusChange,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .set_installation_status_http(auth_header, installation_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Remove an installation and all of its access. Only an Organization owner can uninstall.
    /// Tokens that were already issued stop working at their next request.
    pub async fn uninstall(
        &self,
        installation_id: String,
    ) -> Result<Installation, CallError<AppsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.uninstall_http(auth_header, installation_id),
        )
        .await
        .map_err(CallError::transport)?
    }
}