@shopify/app-bridge-types 0.0.11 → 0.0.12

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/shopify.ts +803 -117
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/app-bridge-types",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Companion types library for the Shopify App Bridge script",
5
5
  "license": "ISC",
6
6
  "main": "./index.js",
package/shopify.ts CHANGED
@@ -1,30 +1,110 @@
1
1
  interface Address {
2
+ /**
3
+ * The customer's primary address.
4
+ */
2
5
  address1?: string;
6
+ /**
7
+ * Any extra information associated with the address (Apartment #, Suite #, Unit #, etc.).
8
+ */
3
9
  address2?: string;
10
+ /**
11
+ * The name of the customer's city.
12
+ */
4
13
  city?: string;
14
+ /**
15
+ * The company name associated with address.
16
+ */
5
17
  company?: string;
18
+ /**
19
+ * The first name of the customer.
20
+ */
6
21
  firstName?: string;
22
+ /**
23
+ * The last name of the customer.
24
+ */
7
25
  lastName?: string;
26
+ /**
27
+ * The phone number of the customer.
28
+ */
8
29
  phone?: string;
30
+ /**
31
+ * The province or state of the address.
32
+ */
9
33
  province?: string;
34
+ /**
35
+ * The country of the address.
36
+ */
10
37
  country?: string;
38
+ /**
39
+ * The ZIP or postal code of the address.
40
+ */
11
41
  zip?: string;
42
+ /**
43
+ * The name of the address.
44
+ */
12
45
  name?: string;
46
+ /**
47
+ * The acronym of the province or state.
48
+ */
13
49
  provinceCode?: string;
50
+ /**
51
+ * The Country Code in ISO 3166-1 (alpha-2) format.
52
+ */
14
53
  countryCode?: string;
15
54
  }
16
55
 
56
+ interface AdminUser {
57
+ /**
58
+ * The account access level of the logged-in user
59
+ */
60
+ accountAccess?: string;
61
+ }
62
+
17
63
  export interface AppBridgeAttributes {
18
64
  }
19
65
 
20
- interface AppBridgeConfig {
21
- host?: string;
22
- apiKey: string;
23
- shop: string;
24
- locale: string;
25
- disabledFeatures?: string[];
66
+ interface AppBridgeConfig extends Required<Omit<_AppBridgeConfig, 'disabledFeatures' | 'appOrigins'>>, Pick<_AppBridgeConfig, 'disabledFeatures' | 'appOrigins'> {
26
67
  experimentalFeatures?: string[];
68
+ }
69
+
70
+ interface _AppBridgeConfig {
71
+ /**
72
+ * The client ID provided for your application in the Partner Dashboard.
73
+ *
74
+ * This needs to be provided by the app developer.
75
+ */
76
+ apiKey: string;
77
+ /**
78
+ * An allowlist of origins that your app can send authenticated fetch requests to.
79
+ *
80
+ * This is useful if your app needs to make authenticated requests to a different domain that you control.
81
+ */
27
82
  appOrigins?: string[];
83
+ /**
84
+ * The features to disable in your app.
85
+ *
86
+ * This allows app developers to opt-out of features such as <code>fetch</code>.
87
+ */
88
+ disabledFeatures?: string[];
89
+ /**
90
+ * The base64-encoded host of the shop that's embedding your app.
91
+ *
92
+ * This does not need to be provided by the app developer.
93
+ */
94
+ host?: string;
95
+ /**
96
+ * The locale of the shop that's embedding your app.
97
+ *
98
+ * This does not need to be provided by the app developer.
99
+ * @defaultValue 'en-US'
100
+ */
101
+ locale?: string;
102
+ /**
103
+ * The shop origin of the shop that's embedding your app.
104
+ *
105
+ * This does not need to be provided by the app developer.
106
+ */
107
+ shop?: string;
28
108
  }
29
109
 
30
110
  export interface AppBridgeElements {
@@ -41,24 +121,59 @@ export interface AugmentedElements {
41
121
  a: MenuItemProperties;
42
122
  }
43
123
 
124
+ interface BaseElementAttributes {
125
+ id?: string;
126
+ name?: string;
127
+ class?: string;
128
+ href?: string;
129
+ rel?: string;
130
+ target?: string;
131
+ onclick?: string;
132
+ children?: string;
133
+ }
134
+
44
135
  interface BaseResource extends Resource {
45
136
  variants?: Resource[];
46
137
  }
47
138
 
48
139
  interface Cart {
140
+ /**
141
+ * The total cost of the current cart including discounts, but before taxes and shipping. Value is based on the shop's existing currency settings.
142
+ */
49
143
  subtotal: string;
144
+ /**
145
+ * The sum of taxes for the current cart. Value is based on the shop's existing currency settings.
146
+ */
50
147
  taxTotal: string;
148
+ /**
149
+ * The total cost of the current cart, after taxes and discounts have been applied. Value is based on the shop's existing currency settings.
150
+ */
51
151
  grandTotal: string;
52
- note?: string;
152
+ /**
153
+ * The current discount applied to the entire cart.
154
+ */
53
155
  cartDiscount?: Discount;
54
- cartDiscounts: Discount[];
156
+ /**
157
+ * All current discounts applied to the entire cart and line items.
158
+ */
159
+ cartDiscounts?: Discount[];
160
+ /**
161
+ * The customer associated to the current cart.
162
+ */
55
163
  customer?: Customer;
164
+ /**
165
+ * A list of lineItem objects.
166
+ */
56
167
  lineItems: LineItem[];
168
+ /**
169
+ * A list of objects containing cart properties.
170
+ */
57
171
  properties: Record<string, string>;
58
172
  }
59
173
 
60
- type CartDiscountType = 'Percentage' | 'FixedAmount';
61
-
174
+ /**
175
+ * Callback to execute when cart updates.
176
+ */
62
177
  type CartSubscriber = (cart: Cart) => void;
63
178
 
64
179
  interface Collection extends Resource {
@@ -103,77 +218,272 @@ enum CollectionSortOrder {
103
218
  }
104
219
 
105
220
  interface Customer {
106
- id?: number;
221
+ /**
222
+ * The ID of existing customer.
223
+ */
224
+ id: number;
225
+ /**
226
+ * The email for a new customer.
227
+ */
107
228
  email?: string;
229
+ /**
230
+ * The first name for new customer.
231
+ */
108
232
  firstName?: string;
233
+ /**
234
+ * The last name for new customer.
235
+ */
109
236
  lastName?: string;
237
+ /**
238
+ * The note for new customer.
239
+ */
110
240
  note?: string;
111
241
  }
112
242
 
243
+ interface CustomSale {
244
+ /**
245
+ * Price of line item
246
+ */
247
+ price: number;
248
+ /**
249
+ * Quantity of line item.
250
+ */
251
+ quantity: number;
252
+ /**
253
+ * Title of line item.
254
+ */
255
+ title: string;
256
+ /**
257
+ * If line item charges tax.
258
+ */
259
+ taxable: boolean;
260
+ }
261
+
113
262
  interface Device {
263
+ /**
264
+ * The name of the device.
265
+ */
114
266
  name: string;
267
+ /**
268
+ * The unique ID associated device ID and app ID..
269
+ */
115
270
  serialNumber: string;
116
271
  }
117
272
 
118
273
  interface Discount {
274
+ /**
275
+ * Amount of discount. Only for fixed or percentage discounts.
276
+ */
119
277
  amount: number;
120
- title?: string;
121
- type?: CartDiscountType;
278
+ /**
279
+ * Description of discount.
280
+ */
281
+ discountDescription?: string;
282
+ /**
283
+ * Type of discount.
284
+ */
285
+ type: DiscountType;
286
+ }
287
+
288
+ type DiscountType = 'Percentage' | 'FixedAmount';
289
+
290
+ interface EnvironmentApi extends Required<_EnvironmentApi> {
291
+ }
292
+
293
+ interface _EnvironmentApi {
294
+ /**
295
+ * Whether the app is running on Shopify Mobile.
296
+ */
297
+ mobile?: boolean;
298
+ /**
299
+ * Whether the app is embedded in the Shopify admin.
300
+ */
301
+ embedded?: boolean;
302
+ /**
303
+ * Whether the app is running on Shopify POS.
304
+ */
305
+ pos?: boolean;
122
306
  }
123
307
 
124
- interface Environment {
125
- mobile: boolean;
126
- embedded: boolean;
127
- pos: boolean;
308
+ interface Filters {
309
+ /**
310
+ * Whether to show hidden resources, referring to products that are not published on any sales channels.
311
+ * @defaultValue true
312
+ */
313
+ hidden?: boolean;
314
+ /**
315
+ * Whether to show product variants. Only applies to the Product resource type picker.
316
+ * @defaultValue true
317
+ */
318
+ variants?: boolean;
319
+ /**
320
+ * Whether to show [draft products](https://help.shopify.com/en/manual/products/details?shpxid=70af7d87-E0F2-4973-8B09-B972AAF0ADFD#product-availability).
321
+ * Only applies to the Product resource type picker.
322
+ * Setting this to undefined will show a badge on draft products.
323
+ * @defaultValue true
324
+ */
325
+ draft?: boolean | undefined;
326
+ /**
327
+ * Whether to show [archived products](https://help.shopify.com/en/manual/products/details?shpxid=70af7d87-E0F2-4973-8B09-B972AAF0ADFD#product-availability).
328
+ * Only applies to the Product resource type picker.
329
+ * Setting this to undefined will show a badge on draft products.
330
+ * @defaultValue true
331
+ */
332
+ archived?: boolean | undefined;
333
+ /**
334
+ * GraphQL initial search query for filtering resources available in the picker.
335
+ * See [search syntax](https://shopify.dev/docs/api/usage/search-syntax) for more information.
336
+ * This is not displayed in the search bar when the picker is opened.
337
+ */
338
+ query?: string;
128
339
  }
129
340
 
341
+ const FINISH: unique symbol;
342
+
343
+ type Finish = (data?: any) => void;
344
+
130
345
  enum FulfillmentServiceType {
131
346
  GiftCard = "GIFT_CARD",
132
347
  Manual = "MANUAL",
133
348
  ThirdParty = "THIRD_PARTY"
134
349
  }
135
350
 
351
+ /**
352
+ * Asynchronously returns an ID token.
353
+ * @returns A Promise that resolves to an ID token.
354
+ */
355
+ type IdTokenApi = () => Promise<string>;
356
+
136
357
  interface Image_2 {
137
358
  id: string;
138
359
  altText?: string;
139
360
  originalSrc: string;
140
361
  }
141
362
 
363
+ class Intent {
364
+ action: string;
365
+ type: string;
366
+ data: {
367
+ [key: string]: any;
368
+ };
369
+ private [FINISH];
370
+ constructor(action: string, type: string, data: {
371
+ [key: string]: any;
372
+ }, finish: Finish);
373
+ finish(): void;
374
+ }
375
+
376
+ interface IntentsApi {
377
+ register(callback: (intent: Intent) => void): () => void;
378
+ }
379
+
142
380
  interface LineItem {
381
+ /**
382
+ * Unique id of line item
383
+ */
143
384
  uuid: string;
385
+ /**
386
+ * Price of line item
387
+ */
144
388
  price?: number;
389
+ /**
390
+ * Quantity of line item.
391
+ */
145
392
  quantity: number;
393
+ /**
394
+ * Title of line item.
395
+ */
146
396
  title?: string;
397
+ /**
398
+ * Variant identifier for line item.
399
+ */
147
400
  variantId?: number;
401
+ /**
402
+ * Product identifier for line item.
403
+ */
148
404
  productId?: number;
405
+ /**
406
+ * Discount applied to line item.
407
+ */
149
408
  discounts: Discount[];
409
+ /**
410
+ * If line item charges tax.
411
+ */
150
412
  taxable: boolean;
413
+ /**
414
+ * Stock keeping unit of the line item.
415
+ */
151
416
  sku?: string;
417
+ /**
418
+ * Vendor of line item.
419
+ */
152
420
  vendor?: string;
421
+ /**
422
+ * Properties of the line item.
423
+ */
153
424
  properties: {
154
425
  [key: string]: string;
155
426
  };
427
+ /**
428
+ * If the line item is a gift card.
429
+ */
156
430
  isGiftCard: boolean;
157
431
  }
158
432
 
159
- interface LineItemDiscount {
160
- title: string;
161
- type: CartDiscountType;
162
- amount: string;
163
- }
433
+ /**
434
+ * The `Loading` API provides a method to toggle the loading indicator in the Shopify admin.
435
+ * @param isLoading - An optional boolean parameter. If `true`, the loading indicator is shown. If `false` or omitted, the loading indicator is hidden.
436
+ */
437
+ type LoadingApi = (isLoading?: boolean) => void;
164
438
 
165
439
  interface Location_2 {
440
+ /**
441
+ * The ID of current location.
442
+ */
166
443
  id: number;
444
+ /**
445
+ * The status of current location.
446
+ */
167
447
  active: boolean;
448
+ /**
449
+ * The name of current location.
450
+ */
168
451
  name: string;
452
+ /**
453
+ * The type of current location.
454
+ */
169
455
  locationType?: string;
456
+ /**
457
+ * The primary address of current location.
458
+ */
170
459
  address1?: string;
460
+ /**
461
+ * Any extra information associated with the address (Apartment #, Suite #, Unit #, etc.).
462
+ */
171
463
  address2?: string;
464
+ /**
465
+ * The ZIP or postal code of the address.
466
+ */
172
467
  zip?: string;
468
+ /**
469
+ * The name of the city.
470
+ */
173
471
  city?: string;
472
+ /**
473
+ * TThe province or state of the address.
474
+ */
174
475
  province?: string;
476
+ /**
477
+ * The Country Code in ISO 3166-1 (alpha-2) format.
478
+ */
175
479
  countryCode?: string;
480
+ /**
481
+ * The country of the address.
482
+ */
176
483
  countryName?: string;
484
+ /**
485
+ * The phone number of the location.
486
+ */
177
487
  phone?: string;
178
488
  }
179
489
 
@@ -184,34 +494,162 @@ export interface MenuItemProperties {
184
494
  loading?: boolean | string;
185
495
  }
186
496
 
497
+ interface ModalApi extends Required<_ModalApi> {
498
+ }
499
+
500
+ interface _ModalApi {
501
+ /**
502
+ * Shows the modal element. An alternative to the `show` instance method on the `ui-modal` element.
503
+ * @param id A unique identifier for the Modal
504
+ */
505
+ show?(id: string): Promise<void>;
506
+ /**
507
+ * Hides the modal element. An alternative to the `hide` instance method on the `ui-modal` element.
508
+ * @param id A unique identifier for the Modal
509
+ */
510
+ hide?(id: string): Promise<void>;
511
+ /**
512
+ * Toggles the modal element visibility. An alternative to the `toggle` instance method on the `ui-modal` element.
513
+ * @param id A unique identifier for the Modal
514
+ */
515
+ toggle?(id: string): Promise<void>;
516
+ }
517
+
187
518
  type Money = string;
188
519
 
189
- interface Pos {
190
- cart: {
191
- fetch(): Promise<Cart>;
192
- subscribe(onSubscribe: CartSubscriber): Unsubscribe;
193
- setCustomer(customer: Customer): Promise<void>;
194
- removeCustomer(): Promise<void>;
195
- addAddress(address: Address): Promise<void>;
196
- updateAddress(index: number, address: Address): Promise<void>;
197
- applyCartDiscount(discount: Discount): Promise<void>;
198
- applyCartCodeDiscount(code: string): Promise<void>;
199
- removeCartDiscount(): Promise<void>;
200
- removeAllDiscounts(disableAutomaticDiscounts: boolean): Promise<void>;
201
- addCartProperties(properties: Record<string, string>): Promise<void>;
202
- removeCartProperties(properties: string[]): Promise<void>;
203
- clear(): Promise<void>;
204
- addLineItem(variantId: number, quantity: number): Promise<void>;
205
- updateLineItem(index: string, quantity: number): Promise<void>;
206
- removeLineItem(index: string): Promise<void>;
207
- setLineItemDiscount(index: number, discount: LineItemDiscount): Promise<void>;
208
- removeLineItemDiscount(index: number): Promise<void>;
209
- addLineItemProperties(index: number, properties: Record<string, string>): Promise<void>;
210
- removeLineItemProperties(index: number, properties: string[]): Promise<void>;
211
- };
212
- close(): Promise<void>;
213
- device(): Promise<Device>;
214
- location(): Promise<Location_2>;
520
+ interface PosApi {
521
+ cart: PosCart;
522
+ close: PosClose;
523
+ device: PosDevice;
524
+ location: PosLocation;
525
+ }
526
+
527
+ type PosCart = Required<_PosCart>;
528
+
529
+ interface _PosCart {
530
+ /**
531
+ * Fetch the current cart.
532
+ */
533
+ fetch?(): Promise<Cart>;
534
+ /**
535
+ * Subscribe the cart changes.
536
+ */
537
+ subscribe?(onSubscribe: CartSubscriber): Unsubscribe;
538
+ /**
539
+ * Add a new or existing customer to the cart.
540
+ */
541
+ setCustomer?(customer: Customer): Promise<void>;
542
+ /**
543
+ * Remove the current customer from the cart.
544
+ */
545
+ removeCustomer?(): Promise<void>;
546
+ /**
547
+ * Add a new address to a customer.
548
+ */
549
+ addAddress?(address: Address): Promise<void>;
550
+ /**
551
+ * Update an address for a customer.
552
+ */
553
+ updateAddress?(index: number, address: Address): Promise<void>;
554
+ /**
555
+ * Apply a percentage or fixed amount discount to the whole cart.
556
+ */
557
+ applyCartDiscount?(type: DiscountType, discountDescription: string, amount: string): Promise<void>;
558
+ /**
559
+ * Apply a code discount to the whole cart.
560
+ */
561
+ applyCartCodeDiscount?(code: string): Promise<void>;
562
+ /**
563
+ * Remove the discount applied to the whole cart.
564
+ */
565
+ removeCartDiscount?(): Promise<void>;
566
+ /**
567
+ * Clears all applied discounts from the cart and optionally disables automatic discounts.
568
+ */
569
+ removeAllDiscounts?(disableAutomaticDiscounts: boolean): Promise<void>;
570
+ /**
571
+ * Add properties for the cart.
572
+ */
573
+ addCartProperties?(properties: Record<string, string>): Promise<void>;
574
+ /**
575
+ * Remove properties from the cart.
576
+ */
577
+ removeCartProperties?(keys: string[]): Promise<void>;
578
+ /**
579
+ * Add custom sale for the cart.
580
+ */
581
+ addCustomSale?(customSale: CustomSale): Promise<void>;
582
+ /**
583
+ * Clear all contents from the cart.
584
+ */
585
+ clear?(): Promise<void>;
586
+ /**
587
+ * Add a product to the cart.
588
+ */
589
+ addLineItem?(variantId: number, quantity: number): Promise<void>;
590
+ /**
591
+ * Make changes to a line item in the cart.
592
+ */
593
+ updateLineItem?(uuid: string, quantity: number): Promise<void>;
594
+ /**
595
+ * Remove a line item in the cart.
596
+ */
597
+ removeLineItem?(uuid: string): Promise<void>;
598
+ /**
599
+ * Apply a discount to a line item.
600
+ */
601
+ setLineItemDiscount?(uuid: string, type: DiscountType, discountDescription: string, amount: string): Promise<void>;
602
+ /**
603
+ * Remove a discount from a line item.
604
+ */
605
+ removeLineItemDiscount?(uuid: string): Promise<void>;
606
+ /**
607
+ * Add properties to a line item.
608
+ */
609
+ addLineItemProperties?(uuid: string, properties: Record<string, string>): Promise<void>;
610
+ /**
611
+ * Remove properties from a line item.
612
+ */
613
+ removeLineItemProperties?(uuid: string, properties: string[]): Promise<void>;
614
+ }
615
+
616
+ type PosClose = () => Promise<void>;
617
+
618
+ type PosDevice = () => Promise<Device>;
619
+
620
+ type PosLocation = () => Promise<Location_2>;
621
+
622
+ interface POSUser {
623
+ /**
624
+ * The ID of the user's staff.
625
+ */
626
+ id?: number;
627
+ /**
628
+ * The user's first name.
629
+ */
630
+ firstName?: string;
631
+ /**
632
+ * The user's last name.
633
+ */
634
+ lastName?: string;
635
+ /**
636
+ * The user's email address.
637
+ */
638
+ email?: string;
639
+ /**
640
+ * The account access level of the logged-in user
641
+ */
642
+ accountAccess?: string;
643
+ /**
644
+ * The user's account type.
645
+ */
646
+ accountType?: string;
647
+ }
648
+
649
+ interface PrivilegedAdminUser extends AdminUser {
650
+ id?: number;
651
+ name?: string;
652
+ email?: string;
215
653
  }
216
654
 
217
655
  interface Product extends Resource {
@@ -298,19 +736,39 @@ interface Resource {
298
736
  id: string;
299
737
  }
300
738
 
739
+ type ResourcePickerApi = (options: ResourcePickerOptions) => Promise<SelectPayload<ResourcePickerOptions['type']> | undefined>;
740
+
301
741
  interface ResourcePickerOptions {
742
+ /**
743
+ * The type of resource you want to pick.
744
+ */
302
745
  type: 'product' | 'variant' | 'collection';
303
- query?: string;
304
- selectionIds?: BaseResource[];
746
+ /**
747
+ * The action verb appears in the title and as the primary action of the Resource Picker.
748
+ * @defaultValue 'add'
749
+ */
305
750
  action?: 'add' | 'select';
751
+ /**
752
+ * Filters for what resource to show.
753
+ */
754
+ filter?: Filters;
755
+ /**
756
+ * Whether to allow selecting multiple items of a specific type or not. If a number is provided, then limit the selections to a maximum of that number of items. When type is Product, the user may still select multiple variants of a single product, even if multiple is false.
757
+ * @defaultValue false
758
+ */
306
759
  multiple?: boolean | number;
307
- filter?: {
308
- hidden?: boolean;
309
- variants?: boolean;
310
- draft?: boolean | undefined;
311
- archived?: boolean | undefined;
312
- query?: string;
313
- };
760
+ /**
761
+ * GraphQL initial search query for filtering resources available in the picker. See [search syntax](https://shopify.dev/docs/api/usage/search-syntax) for more information.
762
+ * This is displayed in the search bar when the picker is opened and can be edited by users.
763
+ * For most use cases, you should use the `filter.query` option instead which doesn't show the query in the UI.
764
+ * @defaultValue ''
765
+ */
766
+ query?: string;
767
+ /**
768
+ * Resources that should be preselected when the picker is opened.
769
+ * @defaultValue []
770
+ */
771
+ selectionIds?: BaseResource[];
314
772
  }
315
773
 
316
774
  type ResourceSelection<Type extends keyof ResourceTypes> = ResourceTypes[Type];
@@ -326,6 +784,35 @@ interface RuleSet {
326
784
  rules: CollectionRule[];
327
785
  }
328
786
 
787
+ interface SaveBarApi extends Required<_SaveBarApi> {
788
+ }
789
+
790
+ interface _SaveBarApi {
791
+ /**
792
+ * Shows the save bar element. An alternative to the `show` instance method on the `ui-save-bar` element.
793
+ * @param id A unique identifier for the save bar
794
+ */
795
+ show?(id: string): Promise<void>;
796
+ /**
797
+ * Hides the save bar element. An alternative to the `hide` instance method on the `ui-save-bar` element.
798
+ * @param id A unique identifier for the save bar
799
+ */
800
+ hide?(id: string): Promise<void>;
801
+ /**
802
+ * Toggles the save bar element visibility. An alternative to the `toggle` instance method on the `ui-save-bar` element.
803
+ * @param id A unique identifier for the save bar
804
+ */
805
+ toggle?(id: string): Promise<void>;
806
+ /**
807
+ * Show leave confirmation dialog if necessary. This promise is resolved when there is no visible save bar or user confirms to leave.
808
+ */
809
+ leaveConfirmation?(): Promise<void>;
810
+ }
811
+
812
+ interface ScannerApi {
813
+ capture(): Promise<ScannerPayload>;
814
+ }
815
+
329
816
  interface ScannerPayload {
330
817
  data: string;
331
818
  }
@@ -336,106 +823,305 @@ export interface ShopifyGlobal {
336
823
  config: AppBridgeConfig;
337
824
  origin: string;
338
825
  ready: Promise<void>;
339
- environment: Environment;
340
- loading(isLoading?: boolean): void;
341
- idToken(): Promise<string>;
342
- user(): Promise<User>;
343
- toast: {
344
- show(message: string, opts?: Partial<ToastOptions>): string;
345
- hide(id: string): void;
346
- };
347
- resourcePicker<Options extends ResourcePickerOptions>(options: Options): Promise<SelectPayload<Options['type']> | undefined>;
348
- scanner: {
349
- capture(): Promise<ScannerPayload>;
350
- };
351
- modal: {
352
- show(id: string): Promise<void>;
353
- hide(id: string): Promise<void>;
354
- toggle(id: string): Promise<void>;
355
- };
356
- saveBar: {
357
- show(id: string): Promise<void>;
358
- hide(id: string): Promise<void>;
359
- toggle(id: string): Promise<void>;
360
- leaveConfirmation(): Promise<void>;
361
- };
362
- pos: Pos;
826
+ environment: EnvironmentApi;
827
+ loading: LoadingApi;
828
+ idToken: IdTokenApi;
829
+ user: UserApi;
830
+ toast: ToastApi;
831
+ resourcePicker: ResourcePickerApi;
832
+ scanner: ScannerApi;
833
+ modal: ModalApi;
834
+ saveBar: SaveBarApi;
835
+ pos: PosApi;
836
+ intents: IntentsApi;
363
837
  }
364
838
 
839
+ /**
840
+ * The Toast API provides methods to display Toast notifications in the Shopify admin.
841
+ */
842
+ interface ToastApi {
843
+ /**
844
+ * Displays a Toast notification in the Shopify admin.
845
+ *
846
+ * @param message - The message to be displayed in the Toast notification.
847
+ * @param opts - Options for the Toast notification.
848
+ *
849
+ * @returns The ID of the Toast notification.
850
+ */
851
+ show: ToastShow;
852
+ /**
853
+ * Hides a Toast notification in the Shopify admin.
854
+ *
855
+ * @param id - The ID of the Toast notification to be hidden.
856
+ */
857
+ hide: ToastHide;
858
+ }
859
+
860
+ type ToastHide = (id: string) => void;
861
+
365
862
  interface ToastOptions {
366
- duration: number;
367
- isError: boolean;
368
- action: string;
369
- onAction: () => void;
370
- onDismiss: () => void;
863
+ /**
864
+ * The length of time in milliseconds the toast message should persist.
865
+ * @defaultValue 5000
866
+ */
867
+ duration?: number;
868
+ /**
869
+ * Display an error-styled toast.
870
+ * @defaultValue false
871
+ */
872
+ isError?: boolean;
873
+ /**
874
+ * Content of an action button.
875
+ */
876
+ action?: string;
877
+ /**
878
+ * Callback fired when the action button is clicked.
879
+ */
880
+ onAction?: () => void;
881
+ /**
882
+ * Callback fired when the dismiss icon is clicked
883
+ */
884
+ onDismiss?: () => void;
885
+ }
886
+
887
+ type ToastShow = (message: string, opts?: ToastOptions) => string;
888
+
889
+ export interface UIModalAttributes extends _UIModalAttributes {
890
+ children?: any;
371
891
  }
372
892
 
373
- export interface UIModalAttributes {
893
+ interface _UIModalAttributes {
894
+ /**
895
+ * A unique identifier for the Modal
896
+ */
374
897
  id?: string;
375
- variant?: Variant;
898
+ /**
899
+ * The size of the modal.
900
+ *
901
+ * Before the Modal is shown, this can be changed to any of the provided values.
902
+ * After the Modal is shown, this can can only be changed between `small`, `base`, and `large`.
903
+ *
904
+ * @defaultValue "base"
905
+ */
906
+ variant?: 'small' | 'base' | 'large' | 'max';
907
+ /**
908
+ * The URL of the content to display within a Modal.
909
+ * If provided, the Modal will display the content from the provided URL
910
+ * and any children other than the [ui-title-bar](/docs/api/app-bridge-library/web-components/ui-title-bar)
911
+ * and [ui-save-bar](/docs/api/app-bridge-library/web-components/ui-save-bar) elements will be ignored.
912
+ */
376
913
  src?: string;
377
- children?: any;
914
+ /**
915
+ * The content to display within a Modal.
916
+ * You can provide a single HTML element with children
917
+ * and the [ui-title-bar](/docs/api/app-bridge-library/web-components/ui-title-bar)
918
+ * element to configure the Modal title bar.
919
+ */
920
+ children?: HTMLCollection & UITitleBarAttributes;
378
921
  }
379
922
 
380
- interface UIModalElement_2 extends Omit<HTMLElement, 'addEventListener' | 'removeEventListener'> {
381
- variant: Variant;
923
+ interface _UIModalElement {
924
+ /**
925
+ * A getter/setter that is used to set modal variant.
926
+ */
927
+ variant?: Variant;
928
+ /**
929
+ * A getter/setter that is used to get the DOM content of the modal
930
+ * element and update the content after the modal has been opened.
931
+ */
382
932
  content?: HTMLElement;
933
+ /**
934
+ * A getter/setter that is used to set modal src.
935
+ */
383
936
  src?: string;
937
+ /**
938
+ * A getter that is used to get the Window object of the modal iframe
939
+ * when the modal is used with a `src` attribute. This can only be
940
+ * accessed when the modal is open, so it is recommended to use `await modal.show()`
941
+ * before accessing this property.
942
+ */
384
943
  readonly contentWindow?: Window | null;
385
- show(): Promise<void>;
386
- hide(): Promise<void>;
387
- toggle(): Promise<void>;
388
- addEventListener(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
389
- removeEventListener(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
944
+ /**
945
+ * Shows the save bar element
946
+ */
947
+ show?(): Promise<void>;
948
+ /**
949
+ * Hides the save bar element
950
+ */
951
+ hide?(): Promise<void>;
952
+ /**
953
+ * Toggles the save bar element between the showing and hidden states
954
+ */
955
+ toggle?(): Promise<void>;
956
+ /**
957
+ * Add 'show' | 'hide' event listeners.
958
+ * @param type An event name
959
+ * @param listener A callback triggered when the event name happens
960
+ */
961
+ addEventListener?(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
962
+ /**
963
+ * Remove 'show' | 'hide' event listeners.
964
+ * @param type An event name
965
+ * @param listener A callback to be removed
966
+ */
967
+ removeEventListener?(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
968
+ }
969
+
970
+ interface UIModalElement_2 extends Omit<HTMLElement, 'addEventListener' | 'removeEventListener'>, Required<Omit<_UIModalElement, 'content' | 'src' | 'contentWindow'>>, Pick<_UIModalElement, 'content' | 'src' | 'contentWindow'> {
390
971
  }
391
972
  export type { UIModalElement_2 as UIModalElement }
392
973
 
393
- export interface UINavMenuAttributes {
974
+ export interface UINavMenuAttributes extends _UINavMenuAttributes {
394
975
  children?: any;
395
976
  }
396
977
 
978
+ interface _UINavMenuAttributes {
979
+ children?: [UINavMenuFirstChild, ...UINavMenuChildren[]];
980
+ }
981
+
982
+ interface UINavMenuChildren {
983
+ a?: {
984
+ href: string;
985
+ children: string;
986
+ };
987
+ }
988
+
397
989
  interface UINavMenuElement_2 extends HTMLElement {
398
990
  }
399
991
  export type { UINavMenuElement_2 as UINavMenuElement }
400
992
 
401
- export interface UISaveBarAttributes {
993
+ interface UINavMenuFirstChild {
994
+ a: {
995
+ rel: 'home';
996
+ href: string;
997
+ children?: string;
998
+ };
999
+ }
1000
+
1001
+ export interface UISaveBarAttributes extends _UISaveBarAttributes {
1002
+ children?: any;
1003
+ }
1004
+
1005
+ interface _UISaveBarAttributes {
1006
+ /**
1007
+ * A unique identifier for the save bar
1008
+ */
402
1009
  id?: string;
1010
+ /**
1011
+ * Whether to show a confirmation dialog when the discard button is clicked
1012
+ */
403
1013
  discardConfirmation?: boolean;
404
- children?: any;
1014
+ /**
1015
+ * HTML `<button>` elements to hook into the Save
1016
+ * and Discard buttons of the contextual save bar.
1017
+ *
1018
+ * The button with variant `primary` is the Save button
1019
+ * and the button without a variant is the Discard button.
1020
+ */
1021
+ children?: UISaveBarChildren;
1022
+ }
1023
+
1024
+ interface UISaveBarChildren {
1025
+ button?: {
1026
+ id?: string;
1027
+ class?: string;
1028
+ children?: string;
1029
+ disabled?: boolean;
1030
+ loading?: boolean;
1031
+ name?: string;
1032
+ onclick?: string;
1033
+ variant?: 'primary';
1034
+ };
405
1035
  }
406
1036
 
407
- interface UISaveBarElement_2 extends Omit<HTMLElement, 'addEventListener' | 'removeEventListener'> {
1037
+ interface _UISaveBarElement {
1038
+ /**
1039
+ * A getter/setter that is used to set discard confirmation.
1040
+ */
408
1041
  discardConfirmation?: boolean;
409
- show(): Promise<void>;
410
- hide(): Promise<void>;
411
- toggle(): Promise<void>;
412
- addEventListener(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
413
- removeEventListener(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
1042
+ /**
1043
+ * A getter that is used to check if save bar is showing.
1044
+ */
1045
+ readonly showing?: boolean;
1046
+ /**
1047
+ * Shows the save bar element.
1048
+ */
1049
+ show?(): Promise<void>;
1050
+ /**
1051
+ * Hides the save bar element.
1052
+ */
1053
+ hide?(): Promise<void>;
1054
+ /**
1055
+ * Toggles the save bar element between the showing and hidden states.
1056
+ */
1057
+ toggle?(): Promise<void>;
1058
+ /**
1059
+ * Add 'show' | 'hide' event listeners.
1060
+ * @param type An event name
1061
+ * @param listener A callback triggered when the event name happens
1062
+ */
1063
+ addEventListener?(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
1064
+ /**
1065
+ * Remove 'show' | 'hide' event listeners.
1066
+ * @param type An event name
1067
+ * @param listener A callback to be removed
1068
+ */
1069
+ removeEventListener?(type: 'show' | 'hide', listener: EventListenerOrEventListenerObject): void;
1070
+ }
1071
+
1072
+ interface UISaveBarElement_2 extends Omit<HTMLElement, 'addEventListener' | 'removeEventListener'>, Required<_UISaveBarElement> {
414
1073
  }
415
1074
  export type { UISaveBarElement_2 as UISaveBarElement }
416
1075
 
417
- export interface UITitleBarAttributes {
418
- title?: string;
1076
+ export interface UITitleBarAttributes extends _UITitleBarAttributes {
419
1077
  children?: any;
420
1078
  }
421
1079
 
422
- interface UITitleBarElement_2 extends HTMLElement {
423
- title: string;
1080
+ interface _UITitleBarAttributes {
1081
+ /**
1082
+ * The title of the title bar. Can also be set via <code>document.title</code>.
1083
+ */
1084
+ title?: string;
1085
+ /**
1086
+ * The children of the title bar.
1087
+ */
1088
+ children?: UITitleBarChildren;
1089
+ }
1090
+
1091
+ interface UITitleBarChildren {
1092
+ a?: BaseElementAttributes & {
1093
+ variant?: 'breadcrumb' | 'primary';
1094
+ };
1095
+ button?: BaseElementAttributes & {
1096
+ variant?: 'breadcrumb' | 'primary';
1097
+ tone?: 'critical' | 'default';
1098
+ };
1099
+ section?: {
1100
+ label?: string;
1101
+ children?: {
1102
+ a?: BaseElementAttributes;
1103
+ button?: BaseElementAttributes;
1104
+ };
1105
+ };
1106
+ }
1107
+
1108
+ interface UITitleBarElement_2 extends Omit<HTMLElement, 'title'> {
424
1109
  }
425
1110
  export type { UITitleBarElement_2 as UITitleBarElement }
426
1111
 
1112
+ /**
1113
+ * Callback to unsubscribe
1114
+ */
427
1115
  type Unsubscribe = () => void;
428
1116
 
429
- interface User {
430
- id: string;
431
- name: string;
432
- firstName?: string;
433
- lastName?: string;
434
- email: string;
435
- accountAccess: string;
436
- accountType: string;
1117
+ export interface UseAppBridge {
437
1118
  }
438
1119
 
1120
+ interface User extends PrivilegedAdminUser, AdminUser, POSUser {
1121
+ }
1122
+
1123
+ type UserApi = () => Promise<User>;
1124
+
439
1125
  type Variant = 'small' | 'base' | 'large' | 'max';
440
1126
 
441
1127
  enum WeightUnit {