@asteby/storefront 0.16.1 → 0.17.0

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.
@@ -494,6 +494,10 @@ type Customer = {
494
494
  /** Saved fiscal data; `null`/absent when none. */
495
495
  fiscal?: FiscalIdentity | null;
496
496
  created_at: string;
497
+ /** Preferred language, one of the store's (contract 1.9). Absent on older servers. */
498
+ locale?: string | null;
499
+ /** Notification preferences (contract 1.9). Absent on older servers. */
500
+ preferences?: CustomerPreferences;
497
501
  };
498
502
  type CustomerIdentifier = {
499
503
  email: string;
@@ -531,6 +535,14 @@ type CustomerCapabilities = {
531
535
  fiscal_profiles?: {
532
536
  max: number;
533
537
  };
538
+ /** Channels the notification preferences can use (connector installed). Absent on older servers: no preferences section. */
539
+ notifications?: {
540
+ channels: string[];
541
+ };
542
+ /** The buyer can download their data (`customer.exportData`). Absent on older servers. */
543
+ data_export?: boolean;
544
+ /** The buyer can delete their account (`customer.deleteAccount`). Absent on older servers. */
545
+ account_delete?: boolean;
534
546
  };
535
547
  /** `GET {gateway}/_token`: what the token in use is and what it can do. Needs no scope. */
536
548
  type TokenIntrospection = {
@@ -1385,6 +1397,10 @@ type CustomerUpdateInput = {
1385
1397
  last_name?: string | null;
1386
1398
  phone?: string | null;
1387
1399
  fiscal?: FiscalIdentityInput | null;
1400
+ /** One of the store's languages (`400` with `field: 'locale'` otherwise); `null` clears it. */
1401
+ locale?: string | null;
1402
+ /** Merged by event and channel; `null` restores the defaults. `400` for an event that cannot be turned off. */
1403
+ preferences?: CustomerPreferences | null;
1388
1404
  };
1389
1405
  /** Post-processing: the value must match `pattern`; `group` of it replaces the value. */
1390
1406
  type IdentityCapture = {
@@ -1448,4 +1464,131 @@ type IdentityRulesV1 = {
1448
1464
  fields: IdentityFieldRule[];
1449
1465
  };
1450
1466
 
1451
- export type { IdentityCapture as $, Address as A, CustomerCapabilities as B, Cart as C, CustomerIdentifier as D, CustomerPasswordLoginInput as E, CustomerRegisterInput as F, CustomerRegisterResult as G, CustomerResetPasswordInput as H, CustomerSession as I, CustomerSessionInput as J, CustomerSetPasswordInput as K, CustomerUpdateInput as L, CustomerVerifyRegistrationInput as M, DeclineCode as N, DeliveryInput as O, DeliveryMethod as P, DeliveryOptions as Q, Facet as R, FacetValue as S, FiscalDocumentEvidence as T, FiscalDocumentSource as U, FiscalIdentity as V, FiscalIdentityInput as W, FiscalProfile as X, FiscalProfileInput as Y, FiscalVerification as Z, GeoHint as _, AddressInput as a, ProductOption as a$, IdentityDocumentSpec as a0, IdentityFieldRule as a1, IdentityRulesV1 as a2, IdentityStrategy as a3, Image as a4, InsufficientStockDetails as a5, InsufficientStockLine as a6, InvoiceAction as a7, InvoiceDoc as a8, InvoiceFile as a9, OrderStepKey as aA, OrderStepState as aB, Page as aC, PageInfo as aD, PaymentAction as aE, PaymentAttemptResult as aF, PaymentAttemptStatus as aG, PaymentClient as aH, PaymentClientCsp as aI, PaymentConfig as aJ, PaymentFlow as aK, PaymentInfo as aL, PaymentMethod as aM, PaymentMethods as aN, PaymentNextStep as aO, PaymentOption as aP, PaymentOptionKey as aQ, PaymentPoint as aR, PaymentSubmitInput as aS, PaymentVoucher as aT, PendingPayment as aU, PendingPaymentVoucher as aV, PickupOption as aW, Product as aX, ProductAttributeValue as aY, ProductCategory as aZ, ProductConnection as a_, InvoiceFileKind as aa, InvoiceRequest as ab, InvoiceResult as ac, InvoiceStage as ad, InvoiceSummary as ae, InvoicingCapabilities as af, Location as ag, LocationContacts as ah, LocationKind as ai, LocationListParams as aj, LocationPickup as ak, Menu as al, MenuItem as am, Money as an, MoneyRange as ao, NearestLocation as ap, NextAction as aq, NextActionKind as ar, Order as as, OrderLine as at, OrderPickup as au, OrderProblem as av, OrderProgress as aw, OrderProgressStep as ax, OrderSection as ay, OrderStage as az, Article as b, ProductSort as b0, ProductVariant as b1, PromotionAnnouncement as b2, PromotionReward as b3, PromotionTier as b4, PromotionsList as b5, RecommendationPlacement as b6, Refund as b7, Region as b8, RegionFiscalEntry as b9, UnavailableRateProvider as bA, RegionFiscalId as ba, RegionPaymentMethod as bb, RegionPostalCode as bc, RestockSubscriptionInput as bd, RestockSubscriptionResult as be, ReturnRequest as bf, ReturnRequestInput as bg, SEO as bh, Section as bi, SelectedOption as bj, Shipment as bk, ShipmentEvent as bl, ShipmentKind as bm, ShipmentMap as bn, ShipmentStatus as bo, ShipmentsSummary as bp, ShippingRate as bq, Shop as br, ShopBranch as bs, ShopContact as bt, ShopPolicies as bu, StockLevel as bv, StorefrontErrorBody as bw, StorefrontErrorCode as bx, Theme as by, TokenIntrospection as bz, Availability as c, AvailabilityStatus as d, CartBuyer as e, CartBuyerInput as f, CartCost as g, CartDelivery as h, CartDiscountCode as i, CartDiscountLine as j, CartInvoice as k, CartLine as l, CartLineInput as m, CartLineMerchandise as n, CartLineProblem as o, CartLineUpdateInput as p, CartPromotions as q, CartRecommendation as r, CartRecommendations as s, CheckoutInfo as t, CheckoutInput as u, CheckoutPayment as v, CheckoutResult as w, Collection as x, Connection as y, Customer as z };
1467
+ type StorefrontErrorInit = {
1468
+ status: number;
1469
+ code: StorefrontErrorCode;
1470
+ message: string;
1471
+ field?: string;
1472
+ /** Raw `error.details` from the body (untrusted shape). */
1473
+ details?: unknown;
1474
+ /** Request URL that failed (without credentials). */
1475
+ url?: string;
1476
+ cause?: unknown;
1477
+ /** Scopes named by the gateway on a `403 insufficient_scope`. */
1478
+ requiredScopes?: string[];
1479
+ /** `error.retryable` as OPS declared it (payment failures). `undefined` = OPS did not say. */
1480
+ retryable?: boolean;
1481
+ /** `error.retry_after` in seconds. */
1482
+ retryAfter?: number;
1483
+ /** `error.checkout_id`: the checkout a refused cart write can resume. */
1484
+ checkoutId?: string;
1485
+ /** `error.cost` of a `price_mismatch` (the cart's current cost; untrusted shape). */
1486
+ cost?: unknown;
1487
+ /** `error.message_en`. */
1488
+ messageEn?: string;
1489
+ };
1490
+ /**
1491
+ * Error thrown by the client for any non-2xx response, network failure,
1492
+ * timeout or abort. `status` is `0` when no HTTP response was received.
1493
+ */
1494
+ declare class StorefrontError extends Error {
1495
+ readonly name = "StorefrontError";
1496
+ readonly status: number;
1497
+ readonly code: StorefrontErrorCode;
1498
+ readonly field: string | undefined;
1499
+ readonly details: unknown;
1500
+ readonly url: string | undefined;
1501
+ /** Scopes a `403 insufficient_scope` says the route needs (empty for any other error). */
1502
+ readonly requiredScopes: string[];
1503
+ /** `true`: repeating the request (same idempotency key) can succeed. `false`: not until someone fixes something. `undefined`: OPS did not say. */
1504
+ readonly retryable: boolean | undefined;
1505
+ /** Seconds OPS asks to wait before retrying. */
1506
+ readonly retryAfter: number | undefined;
1507
+ /** Checkout that a refused cart write can resume. */
1508
+ readonly checkoutId: string | undefined;
1509
+ /** Current cart cost sent with a `price_mismatch` (untrusted shape). */
1510
+ readonly cost: unknown;
1511
+ /** English version of `message`, when OPS sent one. */
1512
+ readonly messageEn: string | undefined;
1513
+ constructor(init: StorefrontErrorInit);
1514
+ /**
1515
+ * Affected lines of a `409 insufficient_stock` (empty for any other error or a
1516
+ * server older than contract 1.1). The cart is untouched: show the lines and
1517
+ * let the buyer adjust or remove them.
1518
+ */
1519
+ get stockLines(): InsufficientStockLine[];
1520
+ toJSON(): {
1521
+ checkoutId?: string | undefined;
1522
+ retryAfter?: number | undefined;
1523
+ retryable?: boolean | undefined;
1524
+ requiredScopes?: string[] | undefined;
1525
+ name: string;
1526
+ status: number;
1527
+ code: StorefrontErrorCode;
1528
+ message: string;
1529
+ field: string | undefined;
1530
+ };
1531
+ }
1532
+ declare function isStorefrontError(err: unknown): err is StorefrontError;
1533
+
1534
+ /**
1535
+ * Account settings of the buyer (contract 1.9): active sessions, recent re-authentication, language and
1536
+ * notification preferences, data export and account deletion. Types and small pure helpers; the calls live on
1537
+ * `client.customer`.
1538
+ */
1539
+ /** Notification preferences: event → channel → on. Only optional events can be configured (never the order confirmation or the invoice). */
1540
+ type CustomerPreferences = {
1541
+ notifications?: Record<string, Record<string, boolean>>;
1542
+ };
1543
+ /** One session of the buyer for a «Devices» list. The server never sends an address or a token. */
1544
+ type CustomerSessionInfo = {
1545
+ id: string;
1546
+ /** `true` for the session that made the request. */
1547
+ current: boolean;
1548
+ /** A summary such as «Chrome · Windows». Never a full user agent. */
1549
+ device_label: string;
1550
+ login_method: 'email' | 'phone' | 'password' | (string & {});
1551
+ last_used_at?: string | null;
1552
+ created_at: string;
1553
+ };
1554
+ /** What proves the buyer is who they say: the password, or a sign-in code requested with `customer.requestOtp`. Exactly one. */
1555
+ type ReauthInput = {
1556
+ password: string;
1557
+ otp_code?: never;
1558
+ } | {
1559
+ otp_code: string;
1560
+ password?: never;
1561
+ };
1562
+ type ReauthResult = {
1563
+ reauth_at: string;
1564
+ /** How long the confirmation lasts (seconds). It applies to the session that made the call, nowhere else. */
1565
+ valid_for_seconds?: number;
1566
+ };
1567
+ /** The buyer's data as a JSON file, in memory. `content_base64` is the file; serve it as a download and do not keep it. */
1568
+ type DataExportFile = {
1569
+ filename: string;
1570
+ content_type: string;
1571
+ content_base64: string;
1572
+ };
1573
+ /** `DELETE /customer`. `confirm` is the text your interface asked the buyer to type. */
1574
+ type AccountDeleteInput = {
1575
+ confirm: string;
1576
+ };
1577
+ /**
1578
+ * `true` when a call was refused because the buyer must confirm their password or a code first
1579
+ * (`403` with code `reauth_required`): show your confirmation step, call `customer.reauth`, and repeat the call.
1580
+ */
1581
+ declare function isReauthRequired(error: unknown): error is StorefrontError;
1582
+ /**
1583
+ * `true` when deleting the account was refused because an order is on its way or a payment is still pending
1584
+ * (`409`; `field` says which: `orders` or `pending_payments`).
1585
+ */
1586
+ declare function isAccountDeleteBlocked(error: unknown): error is StorefrontError & {
1587
+ field: 'orders' | 'pending_payments';
1588
+ };
1589
+ /** Decodes `content_base64` of a data export. Throws `TypeError` when it is not valid base64. */
1590
+ declare function dataExportBytes(file: Pick<DataExportFile, 'content_base64'>): Uint8Array;
1591
+ /** A download filename that is safe in a `Content-Disposition` header: no path, quotes, control characters or spaces. */
1592
+ declare function safeExportFilename(name: unknown, fallback?: string): string;
1593
+
1594
+ export { type FiscalProfile as $, type AccountDeleteInput as A, type Customer as B, type Cart as C, type CustomerCapabilities as D, type CustomerIdentifier as E, type CustomerPasswordLoginInput as F, type CustomerPreferences as G, type CustomerRegisterInput as H, type CustomerRegisterResult as I, type CustomerResetPasswordInput as J, type CustomerSession as K, type CustomerSessionInfo as L, type CustomerSessionInput as M, type CustomerSetPasswordInput as N, type CustomerUpdateInput as O, type CustomerVerifyRegistrationInput as P, type DataExportFile as Q, type DeclineCode as R, type DeliveryInput as S, type DeliveryMethod as T, type DeliveryOptions as U, type Facet as V, type FacetValue as W, type FiscalDocumentEvidence as X, type FiscalDocumentSource as Y, type FiscalIdentity as Z, type FiscalIdentityInput as _, type Address as a, type Product as a$, type FiscalProfileInput as a0, type FiscalVerification as a1, type GeoHint as a2, type IdentityCapture as a3, type IdentityDocumentSpec as a4, type IdentityFieldRule as a5, type IdentityRulesV1 as a6, type IdentityStrategy as a7, type Image as a8, type InsufficientStockDetails as a9, type OrderProgress as aA, type OrderProgressStep as aB, type OrderSection as aC, type OrderStage as aD, type OrderStepKey as aE, type OrderStepState as aF, type Page as aG, type PageInfo as aH, type PaymentAction as aI, type PaymentAttemptResult as aJ, type PaymentAttemptStatus as aK, type PaymentClient as aL, type PaymentClientCsp as aM, type PaymentConfig as aN, type PaymentFlow as aO, type PaymentInfo as aP, type PaymentMethod as aQ, type PaymentMethods as aR, type PaymentNextStep as aS, type PaymentOption as aT, type PaymentOptionKey as aU, type PaymentPoint as aV, type PaymentSubmitInput as aW, type PaymentVoucher as aX, type PendingPayment as aY, type PendingPaymentVoucher as aZ, type PickupOption as a_, type InsufficientStockLine as aa, type InvoiceAction as ab, type InvoiceDoc as ac, type InvoiceFile as ad, type InvoiceFileKind as ae, type InvoiceRequest as af, type InvoiceResult as ag, type InvoiceStage as ah, type InvoiceSummary as ai, type InvoicingCapabilities as aj, type Location as ak, type LocationContacts as al, type LocationKind as am, type LocationListParams as an, type LocationPickup as ao, type Menu as ap, type MenuItem as aq, type Money as ar, type MoneyRange as as, type NearestLocation as at, type NextAction as au, type NextActionKind as av, type Order as aw, type OrderLine as ax, type OrderPickup as ay, type OrderProblem as az, type AddressInput as b, type ProductAttributeValue as b0, type ProductCategory as b1, type ProductConnection as b2, type ProductOption as b3, type ProductSort as b4, type ProductVariant as b5, type PromotionAnnouncement as b6, type PromotionReward as b7, type PromotionTier as b8, type PromotionsList as b9, type ShopPolicies as bA, type StockLevel as bB, StorefrontError as bC, type StorefrontErrorBody as bD, type StorefrontErrorCode as bE, type StorefrontErrorInit as bF, type Theme as bG, type TokenIntrospection as bH, type UnavailableRateProvider as bI, dataExportBytes as bJ, isAccountDeleteBlocked as bK, isReauthRequired as bL, isStorefrontError as bM, safeExportFilename as bN, type ReauthInput as ba, type ReauthResult as bb, type RecommendationPlacement as bc, type Refund as bd, type Region as be, type RegionFiscalEntry as bf, type RegionFiscalId as bg, type RegionPaymentMethod as bh, type RegionPostalCode as bi, type RestockSubscriptionInput as bj, type RestockSubscriptionResult as bk, type ReturnRequest as bl, type ReturnRequestInput as bm, type SEO as bn, type Section as bo, type SelectedOption as bp, type Shipment as bq, type ShipmentEvent as br, type ShipmentKind as bs, type ShipmentMap as bt, type ShipmentStatus as bu, type ShipmentsSummary as bv, type ShippingRate as bw, type Shop as bx, type ShopBranch as by, type ShopContact as bz, type Article as c, type Availability as d, type AvailabilityStatus as e, type CartBuyer as f, type CartBuyerInput as g, type CartCost as h, type CartDelivery as i, type CartDiscountCode as j, type CartDiscountLine as k, type CartInvoice as l, type CartLine as m, type CartLineInput as n, type CartLineMerchandise as o, type CartLineProblem as p, type CartLineUpdateInput as q, type CartPromotions as r, type CartRecommendation as s, type CartRecommendations as t, type CheckoutInfo as u, type CheckoutInput as v, type CheckoutPayment as w, type CheckoutResult as x, type Collection as y, type Connection as z };
@@ -494,6 +494,10 @@ type Customer = {
494
494
  /** Saved fiscal data; `null`/absent when none. */
495
495
  fiscal?: FiscalIdentity | null;
496
496
  created_at: string;
497
+ /** Preferred language, one of the store's (contract 1.9). Absent on older servers. */
498
+ locale?: string | null;
499
+ /** Notification preferences (contract 1.9). Absent on older servers. */
500
+ preferences?: CustomerPreferences;
497
501
  };
498
502
  type CustomerIdentifier = {
499
503
  email: string;
@@ -531,6 +535,14 @@ type CustomerCapabilities = {
531
535
  fiscal_profiles?: {
532
536
  max: number;
533
537
  };
538
+ /** Channels the notification preferences can use (connector installed). Absent on older servers: no preferences section. */
539
+ notifications?: {
540
+ channels: string[];
541
+ };
542
+ /** The buyer can download their data (`customer.exportData`). Absent on older servers. */
543
+ data_export?: boolean;
544
+ /** The buyer can delete their account (`customer.deleteAccount`). Absent on older servers. */
545
+ account_delete?: boolean;
534
546
  };
535
547
  /** `GET {gateway}/_token`: what the token in use is and what it can do. Needs no scope. */
536
548
  type TokenIntrospection = {
@@ -1385,6 +1397,10 @@ type CustomerUpdateInput = {
1385
1397
  last_name?: string | null;
1386
1398
  phone?: string | null;
1387
1399
  fiscal?: FiscalIdentityInput | null;
1400
+ /** One of the store's languages (`400` with `field: 'locale'` otherwise); `null` clears it. */
1401
+ locale?: string | null;
1402
+ /** Merged by event and channel; `null` restores the defaults. `400` for an event that cannot be turned off. */
1403
+ preferences?: CustomerPreferences | null;
1388
1404
  };
1389
1405
  /** Post-processing: the value must match `pattern`; `group` of it replaces the value. */
1390
1406
  type IdentityCapture = {
@@ -1448,4 +1464,131 @@ type IdentityRulesV1 = {
1448
1464
  fields: IdentityFieldRule[];
1449
1465
  };
1450
1466
 
1451
- export type { IdentityCapture as $, Address as A, CustomerCapabilities as B, Cart as C, CustomerIdentifier as D, CustomerPasswordLoginInput as E, CustomerRegisterInput as F, CustomerRegisterResult as G, CustomerResetPasswordInput as H, CustomerSession as I, CustomerSessionInput as J, CustomerSetPasswordInput as K, CustomerUpdateInput as L, CustomerVerifyRegistrationInput as M, DeclineCode as N, DeliveryInput as O, DeliveryMethod as P, DeliveryOptions as Q, Facet as R, FacetValue as S, FiscalDocumentEvidence as T, FiscalDocumentSource as U, FiscalIdentity as V, FiscalIdentityInput as W, FiscalProfile as X, FiscalProfileInput as Y, FiscalVerification as Z, GeoHint as _, AddressInput as a, ProductOption as a$, IdentityDocumentSpec as a0, IdentityFieldRule as a1, IdentityRulesV1 as a2, IdentityStrategy as a3, Image as a4, InsufficientStockDetails as a5, InsufficientStockLine as a6, InvoiceAction as a7, InvoiceDoc as a8, InvoiceFile as a9, OrderStepKey as aA, OrderStepState as aB, Page as aC, PageInfo as aD, PaymentAction as aE, PaymentAttemptResult as aF, PaymentAttemptStatus as aG, PaymentClient as aH, PaymentClientCsp as aI, PaymentConfig as aJ, PaymentFlow as aK, PaymentInfo as aL, PaymentMethod as aM, PaymentMethods as aN, PaymentNextStep as aO, PaymentOption as aP, PaymentOptionKey as aQ, PaymentPoint as aR, PaymentSubmitInput as aS, PaymentVoucher as aT, PendingPayment as aU, PendingPaymentVoucher as aV, PickupOption as aW, Product as aX, ProductAttributeValue as aY, ProductCategory as aZ, ProductConnection as a_, InvoiceFileKind as aa, InvoiceRequest as ab, InvoiceResult as ac, InvoiceStage as ad, InvoiceSummary as ae, InvoicingCapabilities as af, Location as ag, LocationContacts as ah, LocationKind as ai, LocationListParams as aj, LocationPickup as ak, Menu as al, MenuItem as am, Money as an, MoneyRange as ao, NearestLocation as ap, NextAction as aq, NextActionKind as ar, Order as as, OrderLine as at, OrderPickup as au, OrderProblem as av, OrderProgress as aw, OrderProgressStep as ax, OrderSection as ay, OrderStage as az, Article as b, ProductSort as b0, ProductVariant as b1, PromotionAnnouncement as b2, PromotionReward as b3, PromotionTier as b4, PromotionsList as b5, RecommendationPlacement as b6, Refund as b7, Region as b8, RegionFiscalEntry as b9, UnavailableRateProvider as bA, RegionFiscalId as ba, RegionPaymentMethod as bb, RegionPostalCode as bc, RestockSubscriptionInput as bd, RestockSubscriptionResult as be, ReturnRequest as bf, ReturnRequestInput as bg, SEO as bh, Section as bi, SelectedOption as bj, Shipment as bk, ShipmentEvent as bl, ShipmentKind as bm, ShipmentMap as bn, ShipmentStatus as bo, ShipmentsSummary as bp, ShippingRate as bq, Shop as br, ShopBranch as bs, ShopContact as bt, ShopPolicies as bu, StockLevel as bv, StorefrontErrorBody as bw, StorefrontErrorCode as bx, Theme as by, TokenIntrospection as bz, Availability as c, AvailabilityStatus as d, CartBuyer as e, CartBuyerInput as f, CartCost as g, CartDelivery as h, CartDiscountCode as i, CartDiscountLine as j, CartInvoice as k, CartLine as l, CartLineInput as m, CartLineMerchandise as n, CartLineProblem as o, CartLineUpdateInput as p, CartPromotions as q, CartRecommendation as r, CartRecommendations as s, CheckoutInfo as t, CheckoutInput as u, CheckoutPayment as v, CheckoutResult as w, Collection as x, Connection as y, Customer as z };
1467
+ type StorefrontErrorInit = {
1468
+ status: number;
1469
+ code: StorefrontErrorCode;
1470
+ message: string;
1471
+ field?: string;
1472
+ /** Raw `error.details` from the body (untrusted shape). */
1473
+ details?: unknown;
1474
+ /** Request URL that failed (without credentials). */
1475
+ url?: string;
1476
+ cause?: unknown;
1477
+ /** Scopes named by the gateway on a `403 insufficient_scope`. */
1478
+ requiredScopes?: string[];
1479
+ /** `error.retryable` as OPS declared it (payment failures). `undefined` = OPS did not say. */
1480
+ retryable?: boolean;
1481
+ /** `error.retry_after` in seconds. */
1482
+ retryAfter?: number;
1483
+ /** `error.checkout_id`: the checkout a refused cart write can resume. */
1484
+ checkoutId?: string;
1485
+ /** `error.cost` of a `price_mismatch` (the cart's current cost; untrusted shape). */
1486
+ cost?: unknown;
1487
+ /** `error.message_en`. */
1488
+ messageEn?: string;
1489
+ };
1490
+ /**
1491
+ * Error thrown by the client for any non-2xx response, network failure,
1492
+ * timeout or abort. `status` is `0` when no HTTP response was received.
1493
+ */
1494
+ declare class StorefrontError extends Error {
1495
+ readonly name = "StorefrontError";
1496
+ readonly status: number;
1497
+ readonly code: StorefrontErrorCode;
1498
+ readonly field: string | undefined;
1499
+ readonly details: unknown;
1500
+ readonly url: string | undefined;
1501
+ /** Scopes a `403 insufficient_scope` says the route needs (empty for any other error). */
1502
+ readonly requiredScopes: string[];
1503
+ /** `true`: repeating the request (same idempotency key) can succeed. `false`: not until someone fixes something. `undefined`: OPS did not say. */
1504
+ readonly retryable: boolean | undefined;
1505
+ /** Seconds OPS asks to wait before retrying. */
1506
+ readonly retryAfter: number | undefined;
1507
+ /** Checkout that a refused cart write can resume. */
1508
+ readonly checkoutId: string | undefined;
1509
+ /** Current cart cost sent with a `price_mismatch` (untrusted shape). */
1510
+ readonly cost: unknown;
1511
+ /** English version of `message`, when OPS sent one. */
1512
+ readonly messageEn: string | undefined;
1513
+ constructor(init: StorefrontErrorInit);
1514
+ /**
1515
+ * Affected lines of a `409 insufficient_stock` (empty for any other error or a
1516
+ * server older than contract 1.1). The cart is untouched: show the lines and
1517
+ * let the buyer adjust or remove them.
1518
+ */
1519
+ get stockLines(): InsufficientStockLine[];
1520
+ toJSON(): {
1521
+ checkoutId?: string | undefined;
1522
+ retryAfter?: number | undefined;
1523
+ retryable?: boolean | undefined;
1524
+ requiredScopes?: string[] | undefined;
1525
+ name: string;
1526
+ status: number;
1527
+ code: StorefrontErrorCode;
1528
+ message: string;
1529
+ field: string | undefined;
1530
+ };
1531
+ }
1532
+ declare function isStorefrontError(err: unknown): err is StorefrontError;
1533
+
1534
+ /**
1535
+ * Account settings of the buyer (contract 1.9): active sessions, recent re-authentication, language and
1536
+ * notification preferences, data export and account deletion. Types and small pure helpers; the calls live on
1537
+ * `client.customer`.
1538
+ */
1539
+ /** Notification preferences: event → channel → on. Only optional events can be configured (never the order confirmation or the invoice). */
1540
+ type CustomerPreferences = {
1541
+ notifications?: Record<string, Record<string, boolean>>;
1542
+ };
1543
+ /** One session of the buyer for a «Devices» list. The server never sends an address or a token. */
1544
+ type CustomerSessionInfo = {
1545
+ id: string;
1546
+ /** `true` for the session that made the request. */
1547
+ current: boolean;
1548
+ /** A summary such as «Chrome · Windows». Never a full user agent. */
1549
+ device_label: string;
1550
+ login_method: 'email' | 'phone' | 'password' | (string & {});
1551
+ last_used_at?: string | null;
1552
+ created_at: string;
1553
+ };
1554
+ /** What proves the buyer is who they say: the password, or a sign-in code requested with `customer.requestOtp`. Exactly one. */
1555
+ type ReauthInput = {
1556
+ password: string;
1557
+ otp_code?: never;
1558
+ } | {
1559
+ otp_code: string;
1560
+ password?: never;
1561
+ };
1562
+ type ReauthResult = {
1563
+ reauth_at: string;
1564
+ /** How long the confirmation lasts (seconds). It applies to the session that made the call, nowhere else. */
1565
+ valid_for_seconds?: number;
1566
+ };
1567
+ /** The buyer's data as a JSON file, in memory. `content_base64` is the file; serve it as a download and do not keep it. */
1568
+ type DataExportFile = {
1569
+ filename: string;
1570
+ content_type: string;
1571
+ content_base64: string;
1572
+ };
1573
+ /** `DELETE /customer`. `confirm` is the text your interface asked the buyer to type. */
1574
+ type AccountDeleteInput = {
1575
+ confirm: string;
1576
+ };
1577
+ /**
1578
+ * `true` when a call was refused because the buyer must confirm their password or a code first
1579
+ * (`403` with code `reauth_required`): show your confirmation step, call `customer.reauth`, and repeat the call.
1580
+ */
1581
+ declare function isReauthRequired(error: unknown): error is StorefrontError;
1582
+ /**
1583
+ * `true` when deleting the account was refused because an order is on its way or a payment is still pending
1584
+ * (`409`; `field` says which: `orders` or `pending_payments`).
1585
+ */
1586
+ declare function isAccountDeleteBlocked(error: unknown): error is StorefrontError & {
1587
+ field: 'orders' | 'pending_payments';
1588
+ };
1589
+ /** Decodes `content_base64` of a data export. Throws `TypeError` when it is not valid base64. */
1590
+ declare function dataExportBytes(file: Pick<DataExportFile, 'content_base64'>): Uint8Array;
1591
+ /** A download filename that is safe in a `Content-Disposition` header: no path, quotes, control characters or spaces. */
1592
+ declare function safeExportFilename(name: unknown, fallback?: string): string;
1593
+
1594
+ export { type FiscalProfile as $, type AccountDeleteInput as A, type Customer as B, type Cart as C, type CustomerCapabilities as D, type CustomerIdentifier as E, type CustomerPasswordLoginInput as F, type CustomerPreferences as G, type CustomerRegisterInput as H, type CustomerRegisterResult as I, type CustomerResetPasswordInput as J, type CustomerSession as K, type CustomerSessionInfo as L, type CustomerSessionInput as M, type CustomerSetPasswordInput as N, type CustomerUpdateInput as O, type CustomerVerifyRegistrationInput as P, type DataExportFile as Q, type DeclineCode as R, type DeliveryInput as S, type DeliveryMethod as T, type DeliveryOptions as U, type Facet as V, type FacetValue as W, type FiscalDocumentEvidence as X, type FiscalDocumentSource as Y, type FiscalIdentity as Z, type FiscalIdentityInput as _, type Address as a, type Product as a$, type FiscalProfileInput as a0, type FiscalVerification as a1, type GeoHint as a2, type IdentityCapture as a3, type IdentityDocumentSpec as a4, type IdentityFieldRule as a5, type IdentityRulesV1 as a6, type IdentityStrategy as a7, type Image as a8, type InsufficientStockDetails as a9, type OrderProgress as aA, type OrderProgressStep as aB, type OrderSection as aC, type OrderStage as aD, type OrderStepKey as aE, type OrderStepState as aF, type Page as aG, type PageInfo as aH, type PaymentAction as aI, type PaymentAttemptResult as aJ, type PaymentAttemptStatus as aK, type PaymentClient as aL, type PaymentClientCsp as aM, type PaymentConfig as aN, type PaymentFlow as aO, type PaymentInfo as aP, type PaymentMethod as aQ, type PaymentMethods as aR, type PaymentNextStep as aS, type PaymentOption as aT, type PaymentOptionKey as aU, type PaymentPoint as aV, type PaymentSubmitInput as aW, type PaymentVoucher as aX, type PendingPayment as aY, type PendingPaymentVoucher as aZ, type PickupOption as a_, type InsufficientStockLine as aa, type InvoiceAction as ab, type InvoiceDoc as ac, type InvoiceFile as ad, type InvoiceFileKind as ae, type InvoiceRequest as af, type InvoiceResult as ag, type InvoiceStage as ah, type InvoiceSummary as ai, type InvoicingCapabilities as aj, type Location as ak, type LocationContacts as al, type LocationKind as am, type LocationListParams as an, type LocationPickup as ao, type Menu as ap, type MenuItem as aq, type Money as ar, type MoneyRange as as, type NearestLocation as at, type NextAction as au, type NextActionKind as av, type Order as aw, type OrderLine as ax, type OrderPickup as ay, type OrderProblem as az, type AddressInput as b, type ProductAttributeValue as b0, type ProductCategory as b1, type ProductConnection as b2, type ProductOption as b3, type ProductSort as b4, type ProductVariant as b5, type PromotionAnnouncement as b6, type PromotionReward as b7, type PromotionTier as b8, type PromotionsList as b9, type ShopPolicies as bA, type StockLevel as bB, StorefrontError as bC, type StorefrontErrorBody as bD, type StorefrontErrorCode as bE, type StorefrontErrorInit as bF, type Theme as bG, type TokenIntrospection as bH, type UnavailableRateProvider as bI, dataExportBytes as bJ, isAccountDeleteBlocked as bK, isReauthRequired as bL, isStorefrontError as bM, safeExportFilename as bN, type ReauthInput as ba, type ReauthResult as bb, type RecommendationPlacement as bc, type Refund as bd, type Region as be, type RegionFiscalEntry as bf, type RegionFiscalId as bg, type RegionPaymentMethod as bh, type RegionPostalCode as bi, type RestockSubscriptionInput as bj, type RestockSubscriptionResult as bk, type ReturnRequest as bl, type ReturnRequestInput as bm, type SEO as bn, type Section as bo, type SelectedOption as bp, type Shipment as bq, type ShipmentEvent as br, type ShipmentKind as bs, type ShipmentMap as bt, type ShipmentStatus as bu, type ShipmentsSummary as bv, type ShippingRate as bw, type Shop as bx, type ShopBranch as by, type ShopContact as bz, type Article as c, type Availability as d, type AvailabilityStatus as e, type CartBuyer as f, type CartBuyerInput as g, type CartCost as h, type CartDelivery as i, type CartDiscountCode as j, type CartDiscountLine as k, type CartInvoice as l, type CartLine as m, type CartLineInput as n, type CartLineMerchandise as o, type CartLineProblem as p, type CartLineUpdateInput as q, type CartPromotions as r, type CartRecommendation as s, type CartRecommendations as t, type CheckoutInfo as u, type CheckoutInput as v, type CheckoutPayment as w, type CheckoutResult as x, type Collection as y, type Connection as z };
package/dist/cli.js CHANGED
@@ -454,6 +454,43 @@ function createStorefrontClient(config) {
454
454
  get: (options) => get("/storefront/customer", void 0, options),
455
455
  /** Updates the profile and the saved fiscal data; `fiscal: null` deletes the latter. `422` with `field: 'fiscal.<field>'`. */
456
456
  update: (input, options) => write("PATCH", "/storefront/customer", input, options),
457
+ /**
458
+ * Active sessions of the buyer («Devices»; contract 1.9). Private, never cached. The list carries no address
459
+ * and no token: only what the buyer needs to recognize their own devices.
460
+ */
461
+ sessions: {
462
+ list: async (options) => (await get("/storefront/customer/sessions", void 0, { ...options, cache: "no-store" })).nodes,
463
+ /** Closes one session. Repeating it is fine. `404` for a session that is not the buyer's. Closing the current one is a sign-out. */
464
+ revoke: (id, options) => write("DELETE", `/storefront/customer/sessions/${enc(id)}`, void 0, options),
465
+ /** Closes every session except the one making the call. */
466
+ revokeOthers: (options) => write("DELETE", "/storefront/customer/sessions/others", void 0, options)
467
+ },
468
+ /**
469
+ * Confirms the buyer's identity again with their password or a sign-in code (`requestOtp` first). The
470
+ * confirmation lasts `valid_for_seconds` (a few minutes) and counts only for the session that made the call;
471
+ * exporting data and deleting the account need it (`403 reauth_required` otherwise, see `isReauthRequired`).
472
+ * A wrong credential is always the same `400`; too many tries is `429` (`StorefrontError.retryAfter`).
473
+ */
474
+ reauth: (input, options) => write("POST", "/storefront/customer/reauth", input, options),
475
+ /**
476
+ * The buyer's data as a JSON file (contract 1.9, `capabilities().data_export`). Needs a recent `reauth`. It is
477
+ * built on request and is neither stored nor emailed: call it from YOUR server, stream the bytes
478
+ * (`dataExportBytes`, `safeExportFilename`) with `Cache-Control: no-store`, and keep nothing. Three a day per account.
479
+ */
480
+ exportData: async (options) => {
481
+ const file = await write("POST", "/storefront/customer/data-export", void 0, { ...options, cache: "no-store" });
482
+ if (!file || typeof file.content_base64 !== "string" || typeof file.filename !== "string" || typeof file.content_type !== "string") {
483
+ throw new StorefrontError({ status: 502, code: "invalid_response", message: "The data export answer is not a file" });
484
+ }
485
+ return { filename: file.filename, content_type: file.content_type, content_base64: file.content_base64 };
486
+ },
487
+ /**
488
+ * Deletes the buyer's account (contract 1.9, `capabilities().account_delete`). Needs a recent `reauth` and the
489
+ * text the buyer typed in `confirm`. Personal data is erased; orders and invoices are kept by the store.
490
+ * `409` (see `isAccountDeleteBlocked`) while an order is on its way or a payment is pending. Idempotent: a
491
+ * repeat after success is also fine. Afterwards the token is dead: drop it.
492
+ */
493
+ deleteAccount: (input, options) => write("DELETE", "/storefront/customer", input, options),
457
494
  orders: (params, options) => get("/storefront/customer/orders", params, options),
458
495
  /** `null` when the order does not exist or belongs to someone else. */
459
496
  order: (id, options) => getOrNull(`/storefront/customer/orders/${enc(id)}`, void 0, options),
@@ -544,7 +581,7 @@ function repairPath(connectionName) {
544
581
  import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeSync } from "fs";
545
582
  import { dirname, join, resolve } from "path";
546
583
  import { hostname } from "os";
547
- var SDK_VERSION = true ? "0.16.1" : "dev";
584
+ var SDK_VERSION = true ? "0.17.0" : "dev";
548
585
  function writeFileAtomic(file, content, mode = 384) {
549
586
  const dir = dirname(file);
550
587
  mkdirSync(dir, { recursive: true });
@@ -1,5 +1,5 @@
1
- import { U as FiscalDocumentSource, b9 as RegionFiscalEntry, a0 as IdentityDocumentSpec, T as FiscalDocumentEvidence, ba as RegionFiscalId, a2 as IdentityRulesV1 } from './types-C5nEQicj.cjs';
2
- export { $ as IdentityCapture, a1 as IdentityFieldRule, a3 as IdentityStrategy } from './types-C5nEQicj.cjs';
1
+ import { Y as FiscalDocumentSource, bf as RegionFiscalEntry, a4 as IdentityDocumentSpec, X as FiscalDocumentEvidence, bg as RegionFiscalId, a6 as IdentityRulesV1 } from './account-settings-H6zuI7iG.cjs';
2
+ export { a3 as IdentityCapture, a5 as IdentityFieldRule, a7 as IdentityStrategy } from './account-settings-H6zuI7iG.cjs';
3
3
  import './geo.cjs';
4
4
 
5
5
  /** A value read from a document: text, or the codes of a catalog (`multiple` fields). */
@@ -1,5 +1,5 @@
1
- import { U as FiscalDocumentSource, b9 as RegionFiscalEntry, a0 as IdentityDocumentSpec, T as FiscalDocumentEvidence, ba as RegionFiscalId, a2 as IdentityRulesV1 } from './types-DSHzYSHU.js';
2
- export { $ as IdentityCapture, a1 as IdentityFieldRule, a3 as IdentityStrategy } from './types-DSHzYSHU.js';
1
+ import { Y as FiscalDocumentSource, bf as RegionFiscalEntry, a4 as IdentityDocumentSpec, X as FiscalDocumentEvidence, bg as RegionFiscalId, a6 as IdentityRulesV1 } from './account-settings-DNcJKOQl.js';
2
+ export { a3 as IdentityCapture, a5 as IdentityFieldRule, a7 as IdentityStrategy } from './account-settings-DNcJKOQl.js';
3
3
  import './geo.js';
4
4
 
5
5
  /** A value read from a document: text, or the codes of a catalog (`multiple` fields). */
package/dist/index.cjs CHANGED
@@ -486,6 +486,43 @@ function createStorefrontClient(config) {
486
486
  get: (options) => get("/storefront/customer", void 0, options),
487
487
  /** Updates the profile and the saved fiscal data; `fiscal: null` deletes the latter. `422` with `field: 'fiscal.<field>'`. */
488
488
  update: (input, options) => write("PATCH", "/storefront/customer", input, options),
489
+ /**
490
+ * Active sessions of the buyer («Devices»; contract 1.9). Private, never cached. The list carries no address
491
+ * and no token: only what the buyer needs to recognize their own devices.
492
+ */
493
+ sessions: {
494
+ list: async (options) => (await get("/storefront/customer/sessions", void 0, { ...options, cache: "no-store" })).nodes,
495
+ /** Closes one session. Repeating it is fine. `404` for a session that is not the buyer's. Closing the current one is a sign-out. */
496
+ revoke: (id, options) => write("DELETE", `/storefront/customer/sessions/${enc(id)}`, void 0, options),
497
+ /** Closes every session except the one making the call. */
498
+ revokeOthers: (options) => write("DELETE", "/storefront/customer/sessions/others", void 0, options)
499
+ },
500
+ /**
501
+ * Confirms the buyer's identity again with their password or a sign-in code (`requestOtp` first). The
502
+ * confirmation lasts `valid_for_seconds` (a few minutes) and counts only for the session that made the call;
503
+ * exporting data and deleting the account need it (`403 reauth_required` otherwise, see `isReauthRequired`).
504
+ * A wrong credential is always the same `400`; too many tries is `429` (`StorefrontError.retryAfter`).
505
+ */
506
+ reauth: (input, options) => write("POST", "/storefront/customer/reauth", input, options),
507
+ /**
508
+ * The buyer's data as a JSON file (contract 1.9, `capabilities().data_export`). Needs a recent `reauth`. It is
509
+ * built on request and is neither stored nor emailed: call it from YOUR server, stream the bytes
510
+ * (`dataExportBytes`, `safeExportFilename`) with `Cache-Control: no-store`, and keep nothing. Three a day per account.
511
+ */
512
+ exportData: async (options) => {
513
+ const file = await write("POST", "/storefront/customer/data-export", void 0, { ...options, cache: "no-store" });
514
+ if (!file || typeof file.content_base64 !== "string" || typeof file.filename !== "string" || typeof file.content_type !== "string") {
515
+ throw new StorefrontError({ status: 502, code: "invalid_response", message: "The data export answer is not a file" });
516
+ }
517
+ return { filename: file.filename, content_type: file.content_type, content_base64: file.content_base64 };
518
+ },
519
+ /**
520
+ * Deletes the buyer's account (contract 1.9, `capabilities().account_delete`). Needs a recent `reauth` and the
521
+ * text the buyer typed in `confirm`. Personal data is erased; orders and invoices are kept by the store.
522
+ * `409` (see `isAccountDeleteBlocked`) while an order is on its way or a payment is pending. Idempotent: a
523
+ * repeat after success is also fine. Afterwards the token is dead: drop it.
524
+ */
525
+ deleteAccount: (input, options) => write("DELETE", "/storefront/customer", input, options),
489
526
  orders: (params, options) => get("/storefront/customer/orders", params, options),
490
527
  /** `null` when the order does not exist or belongs to someone else. */
491
528
  order: (id, options) => getOrNull(`/storefront/customer/orders/${enc(id)}`, void 0, options),
@@ -1451,6 +1488,29 @@ function shipmentsStatus(order) {
1451
1488
  return live.length ? live[0].status : null;
1452
1489
  }
1453
1490
 
1491
+ // src/account-settings.ts
1492
+ function isReauthRequired(error) {
1493
+ const e = error;
1494
+ return !!e && typeof e === "object" && e.status === 403 && e.code === "reauth_required";
1495
+ }
1496
+ function isAccountDeleteBlocked(error) {
1497
+ const e = error;
1498
+ return !!e && typeof e === "object" && e.status === 409 && (e.field === "orders" || e.field === "pending_payments");
1499
+ }
1500
+ function dataExportBytes(file) {
1501
+ const raw = typeof file.content_base64 === "string" ? file.content_base64.replace(/\s+/g, "") : "";
1502
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(raw) || raw.length % 4 === 1) throw new TypeError("data export is not valid base64");
1503
+ const bin = atob(raw);
1504
+ const out = new Uint8Array(bin.length);
1505
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
1506
+ return out;
1507
+ }
1508
+ function safeExportFilename(name, fallback = "account-data.json") {
1509
+ const base = typeof name === "string" ? name.split(/[\\/]/).pop() ?? "" : "";
1510
+ const clean = base.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^\.+/, "").slice(0, 80);
1511
+ return clean || fallback;
1512
+ }
1513
+
1454
1514
  // src/invoice-docs.ts
1455
1515
  function groupInvoiceDocs(docs) {
1456
1516
  const list = Array.isArray(docs) ? docs.filter((d) => !!d && typeof d === "object") : [];
@@ -1520,6 +1580,7 @@ exports.cartLineProblemView = cartLineProblemView;
1520
1580
  exports.clampPercent = clampPercent;
1521
1581
  exports.classifyPaymentError = classifyPaymentError;
1522
1582
  exports.createStorefrontClient = createStorefrontClient;
1583
+ exports.dataExportBytes = dataExportBytes;
1523
1584
  exports.declineMessage = declineMessage;
1524
1585
  exports.declineMessageKey = declineMessageKey;
1525
1586
  exports.deliveryInput = deliveryInput;
@@ -1532,6 +1593,8 @@ exports.generateIdempotencyKey = generateIdempotencyKey;
1532
1593
  exports.groupInvoiceDocs = groupInvoiceDocs;
1533
1594
  exports.hreflangLinks = hreflangLinks;
1534
1595
  exports.invoiceFileBytes = invoiceFileBytes;
1596
+ exports.isAccountDeleteBlocked = isAccountDeleteBlocked;
1597
+ exports.isReauthRequired = isReauthRequired;
1535
1598
  exports.isStorefrontError = isStorefrontError;
1536
1599
  exports.isTestInvoice = isTestInvoice;
1537
1600
  exports.isTestShipment = isTestShipment;
@@ -1559,6 +1622,7 @@ exports.promotionMessages = promotionMessages;
1559
1622
  exports.repairPath = repairPath;
1560
1623
  exports.resolveAvailability = resolveAvailability;
1561
1624
  exports.rewardLabel = rewardLabel;
1625
+ exports.safeExportFilename = safeExportFilename;
1562
1626
  exports.safeHttpsUrl = safeHttpsUrl;
1563
1627
  exports.safeInvoiceFilename = safeInvoiceFilename;
1564
1628
  exports.safeTrackingUrl = safeTrackingUrl;