|
| 1 | +/** |
| 2 | + * Union of supported API versions |
| 3 | + */ |
| 4 | +export type ApiVersion = 'unstable'; |
| 5 | + |
| 6 | +export interface Auth { |
| 7 | + /** |
| 8 | + * Retrieves a Shopify OpenID Connect ID token for the current user. |
| 9 | + */ |
| 10 | + idToken: () => Promise<string | null>; |
| 11 | +} |
| 12 | + |
| 13 | +/** |
| 14 | + * GraphQL error returned by the Shopify Admin API. |
| 15 | + */ |
| 16 | +export interface GraphQLError { |
| 17 | + message: string; |
| 18 | + locations: { |
| 19 | + line: number; |
| 20 | + column: string; |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * This defines the i18n.translate() signature. |
| 26 | + */ |
| 27 | +export interface I18nTranslate { |
| 28 | + /** |
| 29 | + * This returns a translated string matching a key in a locale file. |
| 30 | + * |
| 31 | + * @example translate("banner.title") |
| 32 | + */ |
| 33 | + <ReplacementType = string>( |
| 34 | + key: string, |
| 35 | + options?: Record<string, ReplacementType | string | number>, |
| 36 | + ): ReplacementType extends string | number |
| 37 | + ? string |
| 38 | + : (string | ReplacementType)[]; |
| 39 | +} |
| 40 | + |
| 41 | +export interface I18n { |
| 42 | + /** |
| 43 | + * Returns a localized number. |
| 44 | + * |
| 45 | + * This function behaves like the standard `Intl.NumberFormat()` |
| 46 | + * with a style of `decimal` applied. It uses the buyer's locale by default. |
| 47 | + * |
| 48 | + * @param options.inExtensionLocale - if true, use the extension's locale |
| 49 | + */ |
| 50 | + formatNumber: ( |
| 51 | + number: number | bigint, |
| 52 | + options?: {inExtensionLocale?: boolean} & Intl.NumberFormatOptions, |
| 53 | + ) => string; |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns a localized currency value. |
| 57 | + * |
| 58 | + * This function behaves like the standard `Intl.NumberFormat()` |
| 59 | + * with a style of `currency` applied. It uses the buyer's locale by default. |
| 60 | + * |
| 61 | + * @param options.inExtensionLocale - if true, use the extension's locale |
| 62 | + */ |
| 63 | + formatCurrency: ( |
| 64 | + number: number | bigint, |
| 65 | + options?: {inExtensionLocale?: boolean} & Intl.NumberFormatOptions, |
| 66 | + ) => string; |
| 67 | + |
| 68 | + /** |
| 69 | + * Returns a localized date value. |
| 70 | + * |
| 71 | + * This function behaves like the standard `Intl.DateTimeFormatOptions()` and uses |
| 72 | + * the buyer's locale by default. Formatting options can be passed in as |
| 73 | + * options. |
| 74 | + * |
| 75 | + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat0 |
| 76 | + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options |
| 77 | + * |
| 78 | + * @param options.inExtensionLocale - if true, use the extension's locale |
| 79 | + */ |
| 80 | + formatDate: ( |
| 81 | + date: Date, |
| 82 | + options?: {inExtensionLocale?: boolean} & Intl.DateTimeFormatOptions, |
| 83 | + ) => string; |
| 84 | + |
| 85 | + /** |
| 86 | + * Returns translated content in the buyer's locale, |
| 87 | + * as supported by the extension. |
| 88 | + * |
| 89 | + * - `options.count` is a special numeric value used in pluralization. |
| 90 | + * - The other option keys and values are treated as replacements for interpolation. |
| 91 | + * - If the replacements are all primitives, then `translate()` returns a single string. |
| 92 | + * - If replacements contain UI components, then `translate()` returns an array of elements. |
| 93 | + */ |
| 94 | + translate: I18nTranslate; |
| 95 | +} |
0 commit comments