-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathitems.ts
More file actions
2118 lines (1766 loc) · 68.5 KB
/
Copy pathitems.ts
File metadata and controls
2118 lines (1766 loc) · 68.5 KB
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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import * as ItemsAPI from './items';
import { APIPromise } from '../../core/api-promise';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class Items extends APIResource {
/**
* The response advertises operations that are valid in the item's current state
* and live data that can be requested through `expand`. Read each operation's
* description before using it. Expanded data is fetched from the provider and is
* not persisted in the vault item. Requesting an unavailable expansion returns 409
* instead of a partial item. Pending credential items return a collection action.
* Kernel-hosted active collection links are renewed atomically on expiry for ready
* or pending items without changing the item version. Invoke collect to open a
* form for a ready item without clearing values. Sensitive credential values are
* never returned.
*
* @example
* ```ts
* const vaultItem = await client.vaults.items.retrieve('x', {
* id_or_name: 'id_or_name',
* });
* ```
*/
retrieve(key: string, params: ItemRetrieveParams, options?: RequestOptions): APIPromise<VaultItem> {
const { id_or_name, ...query } = params;
return this._client.get(path`/vaults/${id_or_name}/items/${key}`, { query, ...options });
}
/**
* Credential updates require type credential and the current version, and change
* only values or description; omitted values are preserved, nonempty strings
* replace, and null or empty strings clear supported fields. Clearing required
* text/email/password values returns pending_collection; browser forms still
* require nonempty required inputs. Card updates may omit type for compatibility
* with legacy requests. Requested cards accept a replacement specification.
* Pending issuance requests may update provider-supported fields on their existing
* request, subject to atomic provider approval checks; omitted optional fields
* remain unchanged and explicit empty lists clear them. Wallet/provider binding
* and unsupported fields cannot change after authorization starts. An uncertain
* update enters recovery_required and must not be retried. Checkout cards may be
* edited between authorizations.
*
* @example
* ```ts
* const vaultItem = await client.vaults.items.update('x', {
* id_or_name: 'id_or_name',
* spec: {
* provider: 'link',
* wallet: 'link-wallet',
* payment_method_id: 'pm_example',
* amount: 3000,
* currency: 'usd',
* merchant_name: 'Example Store',
* merchant_url: 'https://store.example.com',
* context:
* 'The order total changed to USD 30.00 including shipping and taxes for one notebook. Update this unapproved request rather than creating a second payment.',
* },
* type: 'card',
* });
* ```
*/
update(key: string, params: ItemUpdateParams, options?: RequestOptions): APIPromise<VaultItem> {
const { id_or_name, ...body } = params;
return this._client.patch(path`/vaults/${id_or_name}/items/${key}`, { body, ...options });
}
/**
* Credential entries include safe field metadata and non-sensitive values. Listing
* never creates or renews collection sessions; only an existing unexpired active
* session is included. Use single-item GET or collect to obtain a fresh link.
*
* @example
* ```ts
* const vaultItems = await client.vaults.items.list(
* 'id_or_name',
* );
* ```
*/
list(idOrName: string, options?: RequestOptions): APIPromise<ItemListResponse> {
return this._client.get(path`/vaults/${idOrName}/items`, options);
}
/**
* Unresolved payment operations normally block deletion, including operations on
* child cards of a wallet. An AgentCard card in recovery_required whose checkout
* create response returned no authorization ID may be explicitly abandoned by
* deleting that card directly; deleting its wallet or vault remains blocked.
* Deleting or recreating an item is not proof that a payment did not occur.
*
* @example
* ```ts
* await client.vaults.items.delete('x', {
* id_or_name: 'id_or_name',
* });
* ```
*/
delete(key: string, params: ItemDeleteParams, options?: RequestOptions): APIPromise<void> {
const { id_or_name } = params;
return this._client.delete(path`/vaults/${id_or_name}/items/${key}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* List immutable audit events for a vault item
*
* @example
* ```ts
* const vaultItemEvents = await client.vaults.items.events(
* 'key',
* { id_or_name: 'id_or_name' },
* );
* ```
*/
events(key: string, params: ItemEventsParams, options?: RequestOptions): APIPromise<ItemEventsResponse> {
const { id_or_name, ...query } = params;
return this._client.get(path`/vaults/${id_or_name}/items/${key}/events`, { query, ...options });
}
/**
* Retrieve the item first and invoke only an operation listed in
* `available_operations`, following its natural-language description. Availability
* is rechecked at execution time; unavailable operations return 409. Authorization
* and preparation may call an external provider and return updated state. Link
* cards advertise authorize without checkout context. Eligible unused AgentCard
* cards advertise prepare_checkout, which requires checkout context and obtains
* device approval before native Square Pay. Keep the returned approval page open,
* poll until ready_to_submit, then submit before preparation.expires_at. Unused
* preparations expire automatically and cannot be reused. If spend-request
* creation is rejected with a non-retryable provider error, the card item is
* deleted and the provider's error code and message are returned. Rate limits
* return HTTP 429 and retain the card item; stop, back off, and retry the same
* authorize operation.
*
* Fill returns a value-free execution result. Validation failures before writing
* return 400 (invalid request or targets), 403 (access or destination denied), 404
* (resource not found), or 409 (item or browser not ready). Once writing starts,
* known partial failures and indeterminate field outcomes return 200 with status
* `failed` or `unknown`, not an automatic-retry signal. A transport error may
* leave the outcome unknown; do not automatically retry.
*
* @example
* ```ts
* const vaultItemOperationResponse =
* await client.vaults.items.performOperation('key', {
* id_or_name: 'id_or_name',
* type: 'authorize',
* });
* ```
*/
performOperation(
key: string,
params: ItemPerformOperationParams,
options?: RequestOptions,
): APIPromise<VaultItemOperationResponse> {
const { id_or_name, ...body } = params;
return this._client.post(path`/vaults/${id_or_name}/items/${key}/operations`, {
body,
maxRetries: 0,
...options,
});
}
/**
* Create an item under a key unique within its vault, or retrieve the existing
* item when its specification matches. An identical card PUT returns the existing
* card in any lifecycle state without polling the provider, reauthorizing,
* replacing aliases, or resetting recovery. Conflicting specifications return 409.
* Provider-specific authorization requirements and retry behavior are described in
* the item's request schema. Do not use credential items to store, collect, or
* fill credit card data, including card numbers (PANs), security codes (CVV/CVC),
* or expiration dates. Use wallet and card item types for credit cards and payment
* checkout instead.
*
* @example
* ```ts
* const vaultItem = await client.vaults.items.upsert('x', {
* id_or_name: 'id_or_name',
* spec: { provider: 'link' },
* type: 'card',
* });
* ```
*/
upsert(key: string, params: ItemUpsertParams, options?: RequestOptions): APIPromise<VaultItem> {
const { id_or_name, ...body } = params;
return this._client.put(path`/vaults/${id_or_name}/items/${key}`, { body, ...options });
}
}
/**
* The in-flight or most recent checkout authorization. Present while a checkout is
* pending approval and after it settles.
*/
export interface AgentcardCheckoutAuthorization {
id: string;
amount_cents: number;
created_at: string;
currency: string;
merchant: string;
psp: string;
status: 'awaiting_approval' | 'approved' | 'declined' | 'expired';
actual_cents?: number;
/**
* Display amount shown on the approval screen.
*/
amount?: string;
amount_authority?: 'display_only' | 'stripe_payment_intent';
amount_verified?: boolean;
approval_url?: string;
/**
* Browser session that submitted the checkout.
*/
browser_id?: string;
charged_amount_cents?: number;
charged_currency?: string;
charged_kind?: 'captured' | 'authorized' | 'none';
expected_cents?: number;
expires_at?: string;
psp_error_code?: string;
reason?: string;
replay_attempted?: boolean;
/**
* Whether the processor response was delivered to the browser.
*/
replay_delivered?: boolean;
/**
* HTTP status of the replayed processor response.
*/
replay_status?: number;
}
/**
* One-use processor-bound checkout preparation. Keep the approval page open
* through device handoff, including Adyen encryption. The amount is declared by
* the caller and does not constrain the merchant's eventual charge. Adyen device
* approval and browser Authorised responses are not capture or fulfillment
* evidence.
*/
export interface AgentcardCheckoutPreparation {
browser_id: string;
created_at: string;
environment: 'production' | 'sandbox' | 'shared';
merchant_origin: string;
psp: AgentcardPreparedProcessor;
/**
* Preparation consumed means egress claimed the preparation and it cannot be
* reused. It does not mean the attempt settled. Use the enclosing item's status as
* the lifecycle indicator; item consumed means the attempt settled, not that an
* order or charge succeeded.
*/
status: 'creating' | 'awaiting_approval' | 'ready' | 'consumed' | 'cancelled' | 'expired' | 'unknown';
id?: string;
approval_url?: string;
/**
* When ready, the absolute deadline to submit the first native request; no later
* than provider readiness expiry or 30 seconds after Kernel first observes
* readiness. Polling never extends this deadline.
*/
expires_at?: string;
}
export type AgentcardPreparedProcessor =
| 'square'
| 'braintree'
| 'worldpay'
| 'bambora'
| 'mercado_pago'
| 'adyen';
/**
* Authorize a Link card using its existing purchase specification. Use only after
* explicit user approval and when the item advertises authorize. Do not
* automatically retry provider failures or indeterminate outcomes. Checkout
* context is not accepted.
*/
export interface AuthorizeVaultItemOperationRequest {
type: 'authorize';
}
/**
* Live payment card. Test-mode card creation is not supported.
*/
export type CardVaultItemSpec =
| CardVaultItemSpec.LinkCardVaultItemSpec
| CardVaultItemSpec.AgentCardCardVaultItemSpec;
export namespace CardVaultItemSpec {
/**
* Live payment card. Test-mode card creation is not supported.
*/
export interface LinkCardVaultItemSpec {
/**
* Integer amount in minor currency units. Link permits at most 50000 per spend
* request.
*/
amount: number;
context: string;
currency: string;
merchant_name: string;
merchant_url: string;
/**
* Payment-method ID returned by the referenced wallet's payment-method listing.
* The provider decides whether the selected funding method can satisfy the card
* request.
*/
payment_method_id: string;
provider: 'link';
/**
* Wallet item key used to mint this card.
*/
wallet: string;
expires_at?: number;
line_items?: Array<LinkCardVaultItemSpec.LineItem>;
metadata?: { [key: string]: string };
totals?: Array<LinkCardVaultItemSpec.Total>;
}
export namespace LinkCardVaultItemSpec {
export interface LineItem {
name: string;
description?: string;
image_url?: string;
product_url?: string;
quantity?: number;
sku?: string;
totals?: Array<LineItem.Total>;
/**
* Unit amount in minor currency units.
*/
unit_amount?: number;
url?: string;
}
export namespace LineItem {
export interface Total {
/**
* Total amount in minor currency units.
*/
amount: number;
display_text: string;
type: string;
}
}
export interface Total {
/**
* Total amount in minor currency units.
*/
amount: number;
display_text: string;
type: string;
}
}
/**
* AgentCard reusable live payment card. Test-mode card creation is not supported.
* Each checkout creates an approval-gated authorization for spec.merchant /
* spec.amount. The card stays ready after each authorization.
*/
export interface AgentCardCardVaultItemSpec {
/**
* Integer amount in minor currency units.
*/
amount: number;
currency: string;
/**
* Merchant name shown on the cardholder's approval screen.
*/
merchant: string;
provider: 'agentcard';
/**
* Wallet item key used to authorize checkouts.
*/
wallet: string;
/**
* Opaque card ID returned by AgentCard for a card in the connected wallet. Pass it
* through unchanged without assuming a prefix or format. Omitted, the cardholder
* picks on the approval screen.
*/
card_id?: string;
}
}
/**
* Issued Link cards retain encrypted card material for the fill operation. Link
* cards do not expose aliases or support egress substitution.
*/
export type CardVaultItemState = CardVaultItemState.LinkCardState | CardVaultItemState.AgentCardCardState;
export namespace CardVaultItemState {
/**
* Issued Link cards retain encrypted card material for the fill operation. Link
* cards do not expose aliases or support egress substitution.
*/
export interface LinkCardState {
provider: 'link';
/**
* recovery_required means an original provider operation has an unresolved
* outcome. Do not retry, delete, or replace it. Known references may be observed
* safely, but unknown creation without an ID and uncertain card-material retrieval
* require manual reconciliation with the provider or support. There is no reset or
* caller-asserted reconciliation operation.
*/
status:
| 'requested'
| 'pending_authorization'
| 'ready'
| 'consumed'
| 'expired'
| 'declined'
| 'recovery_required';
domains?: Array<string>;
masks?: LinkCardState.Masks;
status_reason?: string;
}
export namespace LinkCardState {
export interface Masks {
brand?: string;
last4?: string;
[k: string]: string | undefined;
}
}
export interface AgentCardCardState {
provider: 'agentcard';
/**
* ready_to_submit is device readiness for at most 30 seconds. consumed means the
* prepared attempt has settled, not that an order succeeded. stopped cannot be
* reused. outcome_unknown requires merchant reconciliation and blocks new
* requests. recovery_required means the original checkout outcome is unresolved.
* Automatic reuse is blocked. Known authorization IDs must be reconciled through
* provider observations or support. When no authorization ID was returned, an
* explicitly confirmed item deletion may abandon the unresolved attempt so the
* caller can create a replacement; deletion does not prove that the original
* attempt failed. It does not mean declined or expired.
*/
status:
| 'requested'
| 'ready'
| 'preparing'
| 'ready_to_submit'
| 'pending_approval'
| 'consumed'
| 'stopped'
| 'outcome_unknown'
| 'degraded'
| 'recovery_required';
aliases?: ItemsAPI.VaultCardAliases;
/**
* The in-flight or most recent checkout authorization. Present while a checkout is
* pending approval and after it settles.
*/
authorization?: ItemsAPI.AgentcardCheckoutAuthorization;
masks?: AgentCardCardState.Masks;
/**
* One-use processor-bound checkout preparation. Keep the approval page open
* through device handoff, including Adyen encryption. The amount is declared by
* the caller and does not constrain the merchant's eventual charge. Adyen device
* approval and browser Authorised responses are not capture or fulfillment
* evidence.
*/
preparation?: ItemsAPI.AgentcardCheckoutPreparation;
status_reason?: string;
}
export namespace AgentCardCardState {
export interface Masks {
brand?: string;
last4?: string;
[k: string]: string | undefined;
}
}
}
/**
* Return the credential item with its collection action. Supported for ready and
* pending_collection credential items. Always render the same form from every
* form-supported field; totp fields have no form input and are omitted. No
* caller-selected field subsets or form overrides are accepted. Reuse an active
* Kernel-hosted session or renew an expired session atomically. Customer-hosted
* forms use their own backend and ordinary item GET/PATCH. Opening the form does
* not clear values or change readiness or item version. To observe edits on a
* ready item, record its version and poll GET without wait until the version
* changes, then reconcile the returned state. Version changes may also come from
* PATCH; they do not identify a particular form submission. Customer-hosted apps
* use their own submission callback, including for unchanged forms. The wait
* parameter waits for readiness, not edits.
*/
export interface CollectVaultItemOperationRequest {
type: 'collect';
}
/**
* One schema-derived form for the item, available in ready or pending_collection
* state. Render every form-supported field as editable; omit totp fields and
* preserve their stored seeds. Prefill non-sensitive values, and allow existing
* sensitive values to be preserved or replaced without ever revealing them. No
* field subsets or per-request form configuration exist. Validate required fields
* against the resulting values, including preserved secrets. Submit changed values
* only, using the version used to render the form. Scoped hosted submission
* rejects totp edits; seed writes require the ordinary authenticated item API.
* Customer forms likewise omit totp from their payloads. Save edits atomically. A
* successful hosted submission increments the version, marks ready, and consumes
* the session; an empty edit may complete collection while preserving values. A
* customer form uses PATCH for changed values and does not send an empty PATCH
* when nothing changed. Kernel-hosted bearer sessions require no Kernel account
* and are bound to the item version. Expired, superseded, consumed, or
* deleted-item sessions cannot submit. Authenticated item GET renews expired
* active sessions for ready or pending items; pending items always receive an
* action. A ready item with no active session omits the action until collect is
* invoked. Concurrent renewals return the same link. Renewal changes neither
* values nor item version. An expired link cannot renew itself. The hosted form
* handles its collection protocol; callers only open the returned URL and do not
* extract or submit its token through the public API. For customer-hosted forms,
* use @onkernel/vault-react and an authenticated customer backend calling the
* ordinary item GET/PATCH API. Kernel does not store customer collection URLs or
* authenticate the customer's end users. Treat URLs and submitted values as
* secrets and exclude them from logs, traces, and errors.
*/
export interface CredentialCollectionAction {
/**
* Expiry of the Kernel-hosted collection link (30 minutes after issuance).
*/
expires_at: string;
name: 'collect';
/**
* Time-scoped hosted form URL (vault.kernel.sh in production). Open this URL as
* returned; treat it as a secret.
*/
url: string;
}
export interface CredentialVaultFieldDefinition {
/**
* Stable field name used to key values, updates, and browser fills.
*/
name: string;
/**
* Whether a nonempty value is required for readiness and form submission.
*/
required: boolean;
/**
* Whether the value is omitted from every item response. Reserve true for secrets
* such as passwords, API tokens, and TOTP seeds. Ordinary usernames and email
* addresses should be false so the form can display and prefill them.
*/
sensitive: boolean;
/**
* Text, email, and password have form inputs; totp does not and is omitted from
* both Kernel-hosted and customer React forms. Password and totp must be
* sensitive. A totp value is an RFC 4648 Base32 generator seed (case-insensitive,
* optional trailing padding), not an otpauth URI or current code. Reject invalid
* or empty decoded seeds. Browser fill generates an RFC 6238 code at execution
* time using HMAC-SHA1, 6 digits, and a 30-second period. Preserve leading zeros;
* never fill the seed. Custom algorithms, digits, periods, and form enrollment are
* unsupported.
*/
type: CredentialVaultFieldType;
/**
* Optional human-readable display label. It is returned as non-secret metadata and
* never affects value keys, updates, or browser fills. Use single-line, trimmed
* display text without control or formatting characters. The server enforces a
* 128-byte UTF-8 limit.
*/
label?: string;
}
export interface CredentialVaultFieldInput {
/**
* Unique stable field name used to key values, updates, and browser fills.
*/
name: string;
/**
* Text, email, and password have form inputs; totp does not and is omitted from
* both Kernel-hosted and customer React forms. Password and totp must be
* sensitive. A totp value is an RFC 4648 Base32 generator seed (case-insensitive,
* optional trailing padding), not an otpauth URI or current code. Reject invalid
* or empty decoded seeds. Browser fill generates an RFC 6238 code at execution
* time using HMAC-SHA1, 6 digits, and a 30-second period. Preserve leading zeros;
* never fill the seed. Custom algorithms, digits, periods, and form enrollment are
* unsupported.
*/
type: CredentialVaultFieldType;
/**
* Optional human-readable display label. It is returned as non-secret metadata and
* never affects value keys, updates, or browser fills. Use single-line, trimmed
* display text without control or formatting characters. The server enforces a
* 128-byte UTF-8 limit.
*/
label?: string;
required?: boolean;
/**
* Set false explicitly for ordinary usernames, email addresses, and other
* non-secret identifiers. Reserve true for secrets such as passwords, API tokens,
* and TOTP seeds. Password and totp fields must be true. Omission defaults to true
* for safety; do not rely on that default for every field. False permits API reads
* and form prefilling.
*/
sensitive?: boolean;
/**
* Optional initial value satisfying the declared type, at most 16 KiB in UTF-8
* bytes. Omit to leave unset; null and empty strings are rejected on creation.
* Sensitive values are encrypted and never copied into the returned spec.
*/
value?: string;
}
export interface CredentialVaultFieldState {
has_value: boolean;
/**
* Present exactly when has_value is true and the field is not sensitive. Reflects
* the latest developer or human edit. For totp, has_value indicates a stored seed;
* neither the seed nor a generated code is returned.
*/
value?: string;
}
/**
* Text, email, and password have form inputs; totp does not and is omitted from
* both Kernel-hosted and customer React forms. Password and totp must be
* sensitive. A totp value is an RFC 4648 Base32 generator seed (case-insensitive,
* optional trailing padding), not an otpauth URI or current code. Reject invalid
* or empty decoded seeds. Browser fill generates an RFC 6238 code at execution
* time using HMAC-SHA1, 6 digits, and a 30-second period. Preserve leading zeros;
* never fill the seed. Custom algorithms, digits, periods, and form enrollment are
* unsupported.
*/
export type CredentialVaultFieldType = 'text' | 'email' | 'password' | 'totp';
export interface CredentialVaultFieldUpdate {
/**
* Replacement value (at most 16 KiB in UTF-8 bytes), or null or an empty string to
* immediately clear the stored value. Clearing a required form-supported field
* reopens collection; clearing an optional field does not prevent readiness.
* Values must satisfy the declared field type. For totp, value is the generator
* seed, never a current code. Clearing a required totp field returns 400 because
* it cannot be collected in a form.
*/
value: string | null;
}
export interface CredentialVaultItem {
id: string;
available_expansions: Array<CredentialVaultItem.AvailableExpansion>;
/**
* Advertises collect for ready and pending_collection items. Browser fill is
* advertised only when separately implemented and eligible.
*/
available_operations: Array<CredentialVaultItem.AvailableOperation>;
created_at: string;
/**
* Immutable item key assigned when the item is created.
*/
key: string;
spec: CredentialVaultItemSpec;
state: CredentialVaultItemState;
type: 'credential';
updated_at: string;
/**
* Starts at 1 and increments on PATCH and successful hosted submission, but not
* collection-link renewal.
*/
version: number;
/**
* One schema-derived form for the item, available in ready or pending_collection
* state. Render every form-supported field as editable; omit totp fields and
* preserve their stored seeds. Prefill non-sensitive values, and allow existing
* sensitive values to be preserved or replaced without ever revealing them. No
* field subsets or per-request form configuration exist. Validate required fields
* against the resulting values, including preserved secrets. Submit changed values
* only, using the version used to render the form. Scoped hosted submission
* rejects totp edits; seed writes require the ordinary authenticated item API.
* Customer forms likewise omit totp from their payloads. Save edits atomically. A
* successful hosted submission increments the version, marks ready, and consumes
* the session; an empty edit may complete collection while preserving values. A
* customer form uses PATCH for changed values and does not send an empty PATCH
* when nothing changed. Kernel-hosted bearer sessions require no Kernel account
* and are bound to the item version. Expired, superseded, consumed, or
* deleted-item sessions cannot submit. Authenticated item GET renews expired
* active sessions for ready or pending items; pending items always receive an
* action. A ready item with no active session omits the action until collect is
* invoked. Concurrent renewals return the same link. Renewal changes neither
* values nor item version. An expired link cannot renew itself. The hosted form
* handles its collection protocol; callers only open the returned URL and do not
* extract or submit its token through the public API. For customer-hosted forms,
* use @onkernel/vault-react and an authenticated customer backend calling the
* ordinary item GET/PATCH API. Kernel does not store customer collection URLs or
* authenticate the customer's end users. Treat URLs and submitted values as
* secrets and exclude them from logs, traces, and errors.
*/
action?: CredentialCollectionAction;
}
export namespace CredentialVaultItem {
/**
* Live data that can currently be requested by passing its type to the item GET
* expand parameter.
*/
export interface AvailableExpansion {
description: string;
type: 'payment_methods';
}
/**
* An operation that is currently valid for this item. Read the description before
* invoking it through the item operations endpoint.
*/
export interface AvailableOperation {
description: string;
type: 'authorize' | 'collect' | 'prepare_checkout' | 'fill';
}
}
/**
* Create a credential item without a wallet or external provider. Do not use
* credential items to store, collect, or fill credit card data, including card
* numbers (PANs), security codes (CVV/CVC), or expiration dates. Use wallet and
* card item types for credit cards and payment checkout instead. If all required
* fields have values, return ready without a collection action; collect can still
* open its form. Otherwise return pending_collection with a time-scoped
* Kernel-hosted collection action. Missing optional fields alone do not trigger
* collection. Repeating the original creation request returns the current item
* without overwriting later edits; a different request at the same key
* returns 409. Use PATCH for updates. Required totp fields must include a valid
* seed on creation; otherwise return 400 rather than opening a form that cannot
* collect it. Optional totp fields may be unset and populated later through PATCH.
*/
export interface CredentialVaultItemRequest {
/**
* Credential fields are for login and other non-payment credentials. Do not store,
* collect, or fill credit card data in credential items. Use wallet and card item
* types for credit cards and payment checkout instead. Field order is preserved in
* the user-facing collection form, so list fields in the same top-to-bottom order
* as the website.
*/
spec: CredentialVaultItemSpecInput;
type: 'credential';
}
export interface CredentialVaultItemSpec {
/**
* Ordered field definitions rendered in this order by credential collection forms.
*/
fields: Array<CredentialVaultFieldDefinition>;
/**
* Recognizable site or service name displayed verbatim as the form title, without
* suffixes such as sign-in credentials. Display text only, not an enforced
* destination policy.
*/
description?: string;
}
/**
* Credential fields are for login and other non-payment credentials. Do not store,
* collect, or fill credit card data in credential items. Use wallet and card item
* types for credit cards and payment checkout instead. Field order is preserved in
* the user-facing collection form, so list fields in the same top-to-bottom order
* as the website.
*/
export interface CredentialVaultItemSpecInput {
/**
* Ordered field definitions. Use the website's top-to-bottom field order; the
* collection form renders this order unchanged.
*/
fields: Array<CredentialVaultFieldInput>;
/**
* The site's recognizable display name, used verbatim as the user-facing form
* title (for example, Hacker News). Use only the site or service name; do not
* append sign-in, login, credentials, or task instructions. This is display text,
* not an enforced destination policy. At most 16 KiB in UTF-8 bytes.
*/
description?: string;
}
export interface CredentialVaultItemSpecUpdate {
/**
* Recognizable site or service name used as the form title, without suffixes such
* as sign-in credentials. An empty string clears it. Display text only, not an
* enforced destination policy. The server also enforces a 16 KiB UTF-8 byte limit.
*/
description?: string;
fields?: { [key: string]: CredentialVaultFieldUpdate };
}
export interface CredentialVaultItemState {
/**
* Exactly one entry for each declared field.
*/
fields: { [key: string]: CredentialVaultFieldState };
/**
* Ready means all required fields have values, not that a login succeeded.
* Optional fields may remain unset.
*/
status: 'pending_collection' | 'ready';
}
/**
* Atomically update description and selected values. Omitted properties are
* preserved. Field names, types, required flags, and sensitivity cannot change.
* Unknown field names return 400; stale versions or mismatched item types return
* 409 without changing the item. A successful update increments version and
* invalidates outstanding Kernel-hosted collection sessions. If required values
* remain missing, return pending_collection and a fresh collection action.
* Otherwise return ready without an action; collect can open the form again
* without clearing values. Customer URLs have no Kernel-managed expiry.
*/
export interface CredentialVaultItemUpdateRequest {
spec: CredentialVaultItemSpecUpdate;
type: 'credential';
/**
* Expected current item version from the latest read.
*/
version: number;
/**
* Optional immutable item ID precondition. Returns 409 if the key now identifies a
* different item. Accepted writes target this immutable ID, preventing
* replacement-key races. Supply this when submitting a form bound to a previously
* read item.
*/
expected_item_id?: string;
}
/**
* Fill selected fields from one ready credential or ready, unexpired Link card
* into a browser linked to its vault. Only invoke when the item advertises `fill`.
* Browser and vault must belong to the same project. Kernel checks access and
* allowed destinations before filling; providing a page URL does not authorize a
* destination.
*
* Find exactly one open page matching `page_url`. Credential items may omit
* `page_url` to require exactly one open page; cards require an HTTPS page URL.
* Credentials have no destination allowlist. TOTP fields generate a current code
* immediately before writing; their seeds never enter the browser. For each
* selector, search the main frame and all descendant frames for editable inputs or
* selects matched directly or contained within matching elements. Each selector
* must resolve to one unique editable element across all frames; zero or multiple
* candidates fail. Count each element once, even if multiple matching containers
* contain it. Validate all bindings before filling. Select elements match an
* option by its value, not its label. If the page navigates or a target disappears
* during filling, stop rather than selecting a different page or element.
*
* Fill in request order and stop on the first failure. This operation is not
* atomic: previously filled fields are not rolled back. Never submit the form or
* click buttons, though input/change events may trigger site behavior. Link cards
* use fill for browser checkout and do not expose aliases or support egress
* substitution. Do not automatically retry a failed or indeterminate operation.
*
* Secret values are never returned or included in operation logs, traces, audit
* events, or error details. This does not prevent an agent with unrestricted
* browser access from reading values from the page or other browser observation
* surfaces.
*/
export interface FillVaultItemOperationRequest {
/**
* Browser session ID, not a reusable browser name.
*/
browser_id: string;
/**
* Field bindings for this step. No two bindings may resolve to the same element.
*/
fields: Array<VaultFillField>;
type: 'fill';
/**
* Exact current top-level page URL, including path, query, and fragment. Must
* match exactly one open page in the browser; zero or multiple matches fail. No
* prefix or glob matching. Required for cards, which must use HTTPS without
* embedded credentials. Optional for credentials, where omission requires exactly
* one open page.
*/
page_url?: string;
/**
* Total operation deadline in milliseconds, not a per-field timeout.
*/
timeout_ms?: number;
}
export interface FillVaultItemOperationResult {
/**
* Exactly one result per request binding, in request order. After the first failed
* or unknown field, all remaining fields are not_attempted.
*/
fields: Array<VaultFillFieldResult>;
/**
* Completed only when all fields were filled. Failed when execution stopped with