@gethydra/sdk 0.1.37 → 0.1.39

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.
package/dist/index.d.ts CHANGED
@@ -4545,6 +4545,8 @@ interface operations {
4545
4545
  po_prefix?: string;
4546
4546
  /** @example INV */
4547
4547
  invoice_prefix?: string;
4548
+ /** @example false */
4549
+ require_email_verification?: boolean;
4548
4550
  /**
4549
4551
  * @example optional
4550
4552
  * @enum {string}
@@ -21608,8 +21610,12 @@ interface LoginBody {
21608
21610
  declare class AuthResource {
21609
21611
  private client;
21610
21612
  constructor(client: Hydra);
21611
- /** Register a new customer account. Returns access + refresh tokens. */
21612
- register(body: RegisterBody): Promise<TokenResponse>;
21613
+ /**
21614
+ * Register a new customer account.
21615
+ * Returns tokens if the store does not require email verification,
21616
+ * or a message prompting verification if it does.
21617
+ */
21618
+ register(body: RegisterBody): Promise<TokenResponse | MessageResponse>;
21613
21619
  /** Log in with email and password. Returns access + refresh tokens. */
21614
21620
  login(body: LoginBody): Promise<TokenResponse>;
21615
21621
  /** Exchange a refresh token for new access + refresh tokens (single-use rotation). */
@@ -21674,41 +21680,42 @@ interface CreditBalance {
21674
21680
  }
21675
21681
  /**
21676
21682
  * Customer self-service resource for `/v1/me/*` endpoints.
21677
- * Every method requires a customer access token (JWT).
21683
+ * Methods use the client-level customer token by default.
21684
+ * Pass an explicit `accessToken` to override (useful server-side).
21678
21685
  */
21679
21686
  declare class MeResource {
21680
21687
  private client;
21681
21688
  constructor(client: Hydra);
21682
21689
  private opts;
21683
21690
  /** Get the authenticated customer's profile. */
21684
- getProfile(accessToken: string): Promise<DataResponse<unknown>>;
21691
+ getProfile(accessToken?: string): Promise<DataResponse<unknown>>;
21685
21692
  /** Update profile fields (first_name, last_name, phone, locale). */
21686
- updateProfile(accessToken: string, body: UpdateProfileBody): Promise<DataResponse<unknown>>;
21693
+ updateProfile(body: UpdateProfileBody, accessToken?: string): Promise<DataResponse<unknown>>;
21687
21694
  /** Change password. Invalidates all sessions and returns new tokens. */
21688
- changePassword(accessToken: string, body: ChangePasswordBody): Promise<TokenResponse>;
21695
+ changePassword(body: ChangePasswordBody, accessToken?: string): Promise<TokenResponse>;
21689
21696
  /** List the customer's order history. */
21690
- listOrders(accessToken: string, params?: MeOrdersParams): Promise<ListResponse<unknown>>;
21697
+ listOrders(params?: MeOrdersParams, accessToken?: string): Promise<ListResponse<unknown>>;
21691
21698
  /** List the customer's addresses. */
21692
- listAddresses(accessToken: string): Promise<DataResponse<unknown[]>>;
21699
+ listAddresses(accessToken?: string): Promise<DataResponse<unknown[]>>;
21693
21700
  /** Create a new address. */
21694
- createAddress(accessToken: string, body: CreateAddressBody): Promise<DataResponse<unknown>>;
21701
+ createAddress(body: CreateAddressBody, accessToken?: string): Promise<DataResponse<unknown>>;
21695
21702
  /** Update an existing address. */
21696
- updateAddress(accessToken: string, id: string, body: UpdateAddressBody): Promise<DataResponse<unknown>>;
21703
+ updateAddress(id: string, body: UpdateAddressBody, accessToken?: string): Promise<DataResponse<unknown>>;
21697
21704
  /** Delete an address. */
21698
- deleteAddress(accessToken: string, id: string): Promise<void>;
21705
+ deleteAddress(id: string, accessToken?: string): Promise<void>;
21699
21706
  /** Get store credit balance breakdown. */
21700
- getCredit(accessToken: string): Promise<DataResponse<CreditBalance>>;
21707
+ getCredit(accessToken?: string): Promise<DataResponse<CreditBalance>>;
21701
21708
  /** List store credit transactions. */
21702
- listCreditTransactions(accessToken: string, params?: {
21709
+ listCreditTransactions(params?: {
21703
21710
  limit?: number;
21704
21711
  cursor?: string;
21705
21712
  sort?: string;
21706
21713
  order?: 'asc' | 'desc';
21707
- }): Promise<ListResponse<unknown>>;
21714
+ }, accessToken?: string): Promise<ListResponse<unknown>>;
21708
21715
  /** List the customer's returns. */
21709
- listReturns(accessToken: string): Promise<DataResponse<unknown[]>>;
21716
+ listReturns(accessToken?: string): Promise<DataResponse<unknown[]>>;
21710
21717
  /** Get active membership. */
21711
- getMembership(accessToken: string): Promise<DataResponse<unknown>>;
21718
+ getMembership(accessToken?: string): Promise<DataResponse<unknown>>;
21712
21719
  }
21713
21720
 
21714
21721
  interface AppInfo {
@@ -21750,6 +21757,13 @@ declare class Hydra {
21750
21757
  readonly timeout: number;
21751
21758
  readonly maxNetworkRetries: number;
21752
21759
  readonly appInfo?: AppInfo;
21760
+ private _customerToken;
21761
+ /** Current customer access token, or null if not set. */
21762
+ get customerToken(): string | null;
21763
+ /** Set a customer access token (JWT). Subsequent requests include `Authorization: Bearer {token}`. */
21764
+ setCustomerToken(token: string): void;
21765
+ /** Clear the customer access token. */
21766
+ clearCustomerToken(): void;
21753
21767
  readonly products: ProductsResource;
21754
21768
  readonly variants: VariantsResource;
21755
21769
  readonly collections: CollectionsResource;
package/dist/index.js CHANGED
@@ -1813,7 +1813,11 @@ var AuthResource = class {
1813
1813
  this.client = client;
1814
1814
  }
1815
1815
  client;
1816
- /** Register a new customer account. Returns access + refresh tokens. */
1816
+ /**
1817
+ * Register a new customer account.
1818
+ * Returns tokens if the store does not require email verification,
1819
+ * or a message prompting verification if it does.
1820
+ */
1817
1821
  async register(body) {
1818
1822
  return this.client.request("POST", "/v1/auth/register", { body });
1819
1823
  }
@@ -1860,10 +1864,16 @@ var MeResource = class {
1860
1864
  }
1861
1865
  client;
1862
1866
  opts(accessToken, extra) {
1867
+ const token = accessToken ?? this.client.customerToken;
1868
+ if (!token) {
1869
+ throw new Error(
1870
+ "Customer access token required. Pass accessToken or call hydra.setCustomerToken()."
1871
+ );
1872
+ }
1863
1873
  return {
1864
1874
  ...extra,
1865
1875
  headers: {
1866
- Authorization: `Bearer ${accessToken}`,
1876
+ Authorization: `Bearer ${token}`,
1867
1877
  ...extra?.headers
1868
1878
  }
1869
1879
  };
@@ -1873,15 +1883,15 @@ var MeResource = class {
1873
1883
  return this.client.request("GET", "/v1/me", this.opts(accessToken));
1874
1884
  }
1875
1885
  /** Update profile fields (first_name, last_name, phone, locale). */
1876
- async updateProfile(accessToken, body) {
1886
+ async updateProfile(body, accessToken) {
1877
1887
  return this.client.request("PATCH", "/v1/me", this.opts(accessToken, { body }));
1878
1888
  }
1879
1889
  /** Change password. Invalidates all sessions and returns new tokens. */
1880
- async changePassword(accessToken, body) {
1890
+ async changePassword(body, accessToken) {
1881
1891
  return this.client.request("POST", "/v1/me/password", this.opts(accessToken, { body }));
1882
1892
  }
1883
1893
  /** List the customer's order history. */
1884
- async listOrders(accessToken, params) {
1894
+ async listOrders(params, accessToken) {
1885
1895
  return this.client.request("GET", "/v1/me/orders", this.opts(accessToken, {
1886
1896
  params
1887
1897
  }));
@@ -1891,11 +1901,11 @@ var MeResource = class {
1891
1901
  return this.client.request("GET", "/v1/me/addresses", this.opts(accessToken));
1892
1902
  }
1893
1903
  /** Create a new address. */
1894
- async createAddress(accessToken, body) {
1904
+ async createAddress(body, accessToken) {
1895
1905
  return this.client.request("POST", "/v1/me/addresses", this.opts(accessToken, { body }));
1896
1906
  }
1897
1907
  /** Update an existing address. */
1898
- async updateAddress(accessToken, id, body) {
1908
+ async updateAddress(id, body, accessToken) {
1899
1909
  return this.client.request(
1900
1910
  "PATCH",
1901
1911
  `/v1/me/addresses/${id}`,
@@ -1903,7 +1913,7 @@ var MeResource = class {
1903
1913
  );
1904
1914
  }
1905
1915
  /** Delete an address. */
1906
- async deleteAddress(accessToken, id) {
1916
+ async deleteAddress(id, accessToken) {
1907
1917
  return this.client.request("DELETE", `/v1/me/addresses/${id}`, this.opts(accessToken));
1908
1918
  }
1909
1919
  /** Get store credit balance breakdown. */
@@ -1911,7 +1921,7 @@ var MeResource = class {
1911
1921
  return this.client.request("GET", "/v1/me/credit", this.opts(accessToken));
1912
1922
  }
1913
1923
  /** List store credit transactions. */
1914
- async listCreditTransactions(accessToken, params) {
1924
+ async listCreditTransactions(params, accessToken) {
1915
1925
  return this.client.request(
1916
1926
  "GET",
1917
1927
  "/v1/me/credit/transactions",
@@ -1958,6 +1968,19 @@ var Hydra = class {
1958
1968
  timeout;
1959
1969
  maxNetworkRetries;
1960
1970
  appInfo;
1971
+ _customerToken = null;
1972
+ /** Current customer access token, or null if not set. */
1973
+ get customerToken() {
1974
+ return this._customerToken;
1975
+ }
1976
+ /** Set a customer access token (JWT). Subsequent requests include `Authorization: Bearer {token}`. */
1977
+ setCustomerToken(token) {
1978
+ this._customerToken = token;
1979
+ }
1980
+ /** Clear the customer access token. */
1981
+ clearCustomerToken() {
1982
+ this._customerToken = null;
1983
+ }
1961
1984
  // P1: Storefront essentials
1962
1985
  products = new ProductsResource(this);
1963
1986
  variants = new VariantsResource(this);
@@ -2113,10 +2136,15 @@ var Hydra = class {
2113
2136
  }
2114
2137
  }
2115
2138
  const headers = {
2116
- Authorization: `Bearer ${this.apiKey}`,
2117
- "User-Agent": this.getUserAgent(),
2118
- ...options?.headers
2139
+ "X-API-Key": this.apiKey,
2140
+ "User-Agent": this.getUserAgent()
2119
2141
  };
2142
+ if (this._customerToken) {
2143
+ headers["Authorization"] = `Bearer ${this._customerToken}`;
2144
+ }
2145
+ if (options?.headers) {
2146
+ Object.assign(headers, options.headers);
2147
+ }
2120
2148
  if (options?.body) {
2121
2149
  headers["Content-Type"] = "application/json";
2122
2150
  }
@@ -2134,13 +2162,17 @@ var Hydra = class {
2134
2162
  executeUpload(path, formData, options) {
2135
2163
  const url = new URL(path, this.baseUrl);
2136
2164
  const { signal, cleanup } = this.buildSignal(options);
2165
+ const headers = {
2166
+ "X-API-Key": this.apiKey,
2167
+ "User-Agent": this.getUserAgent()
2168
+ // No Content-Type — let the runtime set the multipart boundary
2169
+ };
2170
+ if (this._customerToken) {
2171
+ headers["Authorization"] = `Bearer ${this._customerToken}`;
2172
+ }
2137
2173
  return fetch(url.toString(), {
2138
2174
  method: "POST",
2139
- headers: {
2140
- Authorization: `Bearer ${this.apiKey}`,
2141
- "User-Agent": this.getUserAgent()
2142
- // No Content-Type — let the runtime set the multipart boundary
2143
- },
2175
+ headers,
2144
2176
  body: formData,
2145
2177
  signal
2146
2178
  }).finally(cleanup);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gethydra/sdk",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "description": "Official TypeScript SDK for the Hydra Commerce API",
5
5
  "license": "MIT",
6
6
  "author": "Grant Capital Group",