@gethydra/sdk 0.1.37 → 0.1.38
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 +22 -14
- package/dist/index.js +44 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21674,41 +21674,42 @@ interface CreditBalance {
|
|
|
21674
21674
|
}
|
|
21675
21675
|
/**
|
|
21676
21676
|
* Customer self-service resource for `/v1/me/*` endpoints.
|
|
21677
|
-
*
|
|
21677
|
+
* Methods use the client-level customer token by default.
|
|
21678
|
+
* Pass an explicit `accessToken` to override (useful server-side).
|
|
21678
21679
|
*/
|
|
21679
21680
|
declare class MeResource {
|
|
21680
21681
|
private client;
|
|
21681
21682
|
constructor(client: Hydra);
|
|
21682
21683
|
private opts;
|
|
21683
21684
|
/** Get the authenticated customer's profile. */
|
|
21684
|
-
getProfile(accessToken
|
|
21685
|
+
getProfile(accessToken?: string): Promise<DataResponse<unknown>>;
|
|
21685
21686
|
/** Update profile fields (first_name, last_name, phone, locale). */
|
|
21686
|
-
updateProfile(
|
|
21687
|
+
updateProfile(body: UpdateProfileBody, accessToken?: string): Promise<DataResponse<unknown>>;
|
|
21687
21688
|
/** Change password. Invalidates all sessions and returns new tokens. */
|
|
21688
|
-
changePassword(
|
|
21689
|
+
changePassword(body: ChangePasswordBody, accessToken?: string): Promise<TokenResponse>;
|
|
21689
21690
|
/** List the customer's order history. */
|
|
21690
|
-
listOrders(
|
|
21691
|
+
listOrders(params?: MeOrdersParams, accessToken?: string): Promise<ListResponse<unknown>>;
|
|
21691
21692
|
/** List the customer's addresses. */
|
|
21692
|
-
listAddresses(accessToken
|
|
21693
|
+
listAddresses(accessToken?: string): Promise<DataResponse<unknown[]>>;
|
|
21693
21694
|
/** Create a new address. */
|
|
21694
|
-
createAddress(
|
|
21695
|
+
createAddress(body: CreateAddressBody, accessToken?: string): Promise<DataResponse<unknown>>;
|
|
21695
21696
|
/** Update an existing address. */
|
|
21696
|
-
updateAddress(
|
|
21697
|
+
updateAddress(id: string, body: UpdateAddressBody, accessToken?: string): Promise<DataResponse<unknown>>;
|
|
21697
21698
|
/** Delete an address. */
|
|
21698
|
-
deleteAddress(
|
|
21699
|
+
deleteAddress(id: string, accessToken?: string): Promise<void>;
|
|
21699
21700
|
/** Get store credit balance breakdown. */
|
|
21700
|
-
getCredit(accessToken
|
|
21701
|
+
getCredit(accessToken?: string): Promise<DataResponse<CreditBalance>>;
|
|
21701
21702
|
/** List store credit transactions. */
|
|
21702
|
-
listCreditTransactions(
|
|
21703
|
+
listCreditTransactions(params?: {
|
|
21703
21704
|
limit?: number;
|
|
21704
21705
|
cursor?: string;
|
|
21705
21706
|
sort?: string;
|
|
21706
21707
|
order?: 'asc' | 'desc';
|
|
21707
|
-
}): Promise<ListResponse<unknown>>;
|
|
21708
|
+
}, accessToken?: string): Promise<ListResponse<unknown>>;
|
|
21708
21709
|
/** List the customer's returns. */
|
|
21709
|
-
listReturns(accessToken
|
|
21710
|
+
listReturns(accessToken?: string): Promise<DataResponse<unknown[]>>;
|
|
21710
21711
|
/** Get active membership. */
|
|
21711
|
-
getMembership(accessToken
|
|
21712
|
+
getMembership(accessToken?: string): Promise<DataResponse<unknown>>;
|
|
21712
21713
|
}
|
|
21713
21714
|
|
|
21714
21715
|
interface AppInfo {
|
|
@@ -21750,6 +21751,13 @@ declare class Hydra {
|
|
|
21750
21751
|
readonly timeout: number;
|
|
21751
21752
|
readonly maxNetworkRetries: number;
|
|
21752
21753
|
readonly appInfo?: AppInfo;
|
|
21754
|
+
private _customerToken;
|
|
21755
|
+
/** Current customer access token, or null if not set. */
|
|
21756
|
+
get customerToken(): string | null;
|
|
21757
|
+
/** Set a customer access token (JWT). Subsequent requests include `Authorization: Bearer {token}`. */
|
|
21758
|
+
setCustomerToken(token: string): void;
|
|
21759
|
+
/** Clear the customer access token. */
|
|
21760
|
+
clearCustomerToken(): void;
|
|
21753
21761
|
readonly products: ProductsResource;
|
|
21754
21762
|
readonly variants: VariantsResource;
|
|
21755
21763
|
readonly collections: CollectionsResource;
|
package/dist/index.js
CHANGED
|
@@ -1860,10 +1860,16 @@ var MeResource = class {
|
|
|
1860
1860
|
}
|
|
1861
1861
|
client;
|
|
1862
1862
|
opts(accessToken, extra) {
|
|
1863
|
+
const token = accessToken ?? this.client.customerToken;
|
|
1864
|
+
if (!token) {
|
|
1865
|
+
throw new Error(
|
|
1866
|
+
"Customer access token required. Pass accessToken or call hydra.setCustomerToken()."
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1863
1869
|
return {
|
|
1864
1870
|
...extra,
|
|
1865
1871
|
headers: {
|
|
1866
|
-
Authorization: `Bearer ${
|
|
1872
|
+
Authorization: `Bearer ${token}`,
|
|
1867
1873
|
...extra?.headers
|
|
1868
1874
|
}
|
|
1869
1875
|
};
|
|
@@ -1873,15 +1879,15 @@ var MeResource = class {
|
|
|
1873
1879
|
return this.client.request("GET", "/v1/me", this.opts(accessToken));
|
|
1874
1880
|
}
|
|
1875
1881
|
/** Update profile fields (first_name, last_name, phone, locale). */
|
|
1876
|
-
async updateProfile(
|
|
1882
|
+
async updateProfile(body, accessToken) {
|
|
1877
1883
|
return this.client.request("PATCH", "/v1/me", this.opts(accessToken, { body }));
|
|
1878
1884
|
}
|
|
1879
1885
|
/** Change password. Invalidates all sessions and returns new tokens. */
|
|
1880
|
-
async changePassword(
|
|
1886
|
+
async changePassword(body, accessToken) {
|
|
1881
1887
|
return this.client.request("POST", "/v1/me/password", this.opts(accessToken, { body }));
|
|
1882
1888
|
}
|
|
1883
1889
|
/** List the customer's order history. */
|
|
1884
|
-
async listOrders(
|
|
1890
|
+
async listOrders(params, accessToken) {
|
|
1885
1891
|
return this.client.request("GET", "/v1/me/orders", this.opts(accessToken, {
|
|
1886
1892
|
params
|
|
1887
1893
|
}));
|
|
@@ -1891,11 +1897,11 @@ var MeResource = class {
|
|
|
1891
1897
|
return this.client.request("GET", "/v1/me/addresses", this.opts(accessToken));
|
|
1892
1898
|
}
|
|
1893
1899
|
/** Create a new address. */
|
|
1894
|
-
async createAddress(
|
|
1900
|
+
async createAddress(body, accessToken) {
|
|
1895
1901
|
return this.client.request("POST", "/v1/me/addresses", this.opts(accessToken, { body }));
|
|
1896
1902
|
}
|
|
1897
1903
|
/** Update an existing address. */
|
|
1898
|
-
async updateAddress(
|
|
1904
|
+
async updateAddress(id, body, accessToken) {
|
|
1899
1905
|
return this.client.request(
|
|
1900
1906
|
"PATCH",
|
|
1901
1907
|
`/v1/me/addresses/${id}`,
|
|
@@ -1903,7 +1909,7 @@ var MeResource = class {
|
|
|
1903
1909
|
);
|
|
1904
1910
|
}
|
|
1905
1911
|
/** Delete an address. */
|
|
1906
|
-
async deleteAddress(
|
|
1912
|
+
async deleteAddress(id, accessToken) {
|
|
1907
1913
|
return this.client.request("DELETE", `/v1/me/addresses/${id}`, this.opts(accessToken));
|
|
1908
1914
|
}
|
|
1909
1915
|
/** Get store credit balance breakdown. */
|
|
@@ -1911,7 +1917,7 @@ var MeResource = class {
|
|
|
1911
1917
|
return this.client.request("GET", "/v1/me/credit", this.opts(accessToken));
|
|
1912
1918
|
}
|
|
1913
1919
|
/** List store credit transactions. */
|
|
1914
|
-
async listCreditTransactions(
|
|
1920
|
+
async listCreditTransactions(params, accessToken) {
|
|
1915
1921
|
return this.client.request(
|
|
1916
1922
|
"GET",
|
|
1917
1923
|
"/v1/me/credit/transactions",
|
|
@@ -1958,6 +1964,19 @@ var Hydra = class {
|
|
|
1958
1964
|
timeout;
|
|
1959
1965
|
maxNetworkRetries;
|
|
1960
1966
|
appInfo;
|
|
1967
|
+
_customerToken = null;
|
|
1968
|
+
/** Current customer access token, or null if not set. */
|
|
1969
|
+
get customerToken() {
|
|
1970
|
+
return this._customerToken;
|
|
1971
|
+
}
|
|
1972
|
+
/** Set a customer access token (JWT). Subsequent requests include `Authorization: Bearer {token}`. */
|
|
1973
|
+
setCustomerToken(token) {
|
|
1974
|
+
this._customerToken = token;
|
|
1975
|
+
}
|
|
1976
|
+
/** Clear the customer access token. */
|
|
1977
|
+
clearCustomerToken() {
|
|
1978
|
+
this._customerToken = null;
|
|
1979
|
+
}
|
|
1961
1980
|
// P1: Storefront essentials
|
|
1962
1981
|
products = new ProductsResource(this);
|
|
1963
1982
|
variants = new VariantsResource(this);
|
|
@@ -2113,10 +2132,15 @@ var Hydra = class {
|
|
|
2113
2132
|
}
|
|
2114
2133
|
}
|
|
2115
2134
|
const headers = {
|
|
2116
|
-
|
|
2117
|
-
"User-Agent": this.getUserAgent()
|
|
2118
|
-
...options?.headers
|
|
2135
|
+
"X-API-Key": this.apiKey,
|
|
2136
|
+
"User-Agent": this.getUserAgent()
|
|
2119
2137
|
};
|
|
2138
|
+
if (this._customerToken) {
|
|
2139
|
+
headers["Authorization"] = `Bearer ${this._customerToken}`;
|
|
2140
|
+
}
|
|
2141
|
+
if (options?.headers) {
|
|
2142
|
+
Object.assign(headers, options.headers);
|
|
2143
|
+
}
|
|
2120
2144
|
if (options?.body) {
|
|
2121
2145
|
headers["Content-Type"] = "application/json";
|
|
2122
2146
|
}
|
|
@@ -2134,13 +2158,17 @@ var Hydra = class {
|
|
|
2134
2158
|
executeUpload(path, formData, options) {
|
|
2135
2159
|
const url = new URL(path, this.baseUrl);
|
|
2136
2160
|
const { signal, cleanup } = this.buildSignal(options);
|
|
2161
|
+
const headers = {
|
|
2162
|
+
"X-API-Key": this.apiKey,
|
|
2163
|
+
"User-Agent": this.getUserAgent()
|
|
2164
|
+
// No Content-Type — let the runtime set the multipart boundary
|
|
2165
|
+
};
|
|
2166
|
+
if (this._customerToken) {
|
|
2167
|
+
headers["Authorization"] = `Bearer ${this._customerToken}`;
|
|
2168
|
+
}
|
|
2137
2169
|
return fetch(url.toString(), {
|
|
2138
2170
|
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
|
-
},
|
|
2171
|
+
headers,
|
|
2144
2172
|
body: formData,
|
|
2145
2173
|
signal
|
|
2146
2174
|
}).finally(cleanup);
|