@thorprovider/medusa-extended 1.11.8 → 1.12.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.
- package/dist/index.d.mts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +73 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/dropshipper.live-smoke.test.ts +127 -73
- package/src/dropshipper.test.ts +90 -36
- package/src/dropshipper.ts +11 -14
- package/src/recovery.ts +85 -4
- package/src/request-resilience.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -817,20 +817,18 @@ var DropshipperClient = class {
|
|
|
817
817
|
);
|
|
818
818
|
}
|
|
819
819
|
/**
|
|
820
|
-
* List shipping options for a manual dropshipper order.
|
|
820
|
+
* List shipping groups and their valid options for a manual dropshipper order.
|
|
821
821
|
*
|
|
822
|
-
* `
|
|
822
|
+
* `POST /admin/thor/dropshipper/orders/shipping-options`
|
|
823
823
|
*/
|
|
824
|
-
async getOrderShippingOptions(
|
|
825
|
-
const qs = new URLSearchParams({
|
|
826
|
-
currency_code: params.currency_code.toLowerCase(),
|
|
827
|
-
...params.country_code ? { country_code: params.country_code.toLowerCase() } : {},
|
|
828
|
-
...params.province ? { province: params.province } : {},
|
|
829
|
-
...params.city ? { city: params.city } : {}
|
|
830
|
-
});
|
|
824
|
+
async getOrderShippingOptions(body) {
|
|
831
825
|
return this.request(
|
|
832
|
-
"
|
|
833
|
-
|
|
826
|
+
"POST",
|
|
827
|
+
"/admin/thor/dropshipper/orders/shipping-options",
|
|
828
|
+
{
|
|
829
|
+
...body,
|
|
830
|
+
currency_code: body.currency_code.toLowerCase()
|
|
831
|
+
}
|
|
834
832
|
);
|
|
835
833
|
}
|
|
836
834
|
/**
|
|
@@ -1886,7 +1884,7 @@ var RecoveryClient = class {
|
|
|
1886
1884
|
// -------------------------------------------------------------------------
|
|
1887
1885
|
// Private — HTTP helper
|
|
1888
1886
|
// -------------------------------------------------------------------------
|
|
1889
|
-
async request(method, path, body) {
|
|
1887
|
+
async request(method, path, body, retryConfig) {
|
|
1890
1888
|
const url = `${this.baseUrl}${path}`;
|
|
1891
1889
|
this.logger.debug(`[recovery] ${method} ${path}`);
|
|
1892
1890
|
const headers = {
|
|
@@ -1899,7 +1897,7 @@ var RecoveryClient = class {
|
|
|
1899
1897
|
};
|
|
1900
1898
|
let response;
|
|
1901
1899
|
try {
|
|
1902
|
-
response = await fetchBackendWithResilience(url, init);
|
|
1900
|
+
response = await fetchBackendWithResilience(url, init, retryConfig);
|
|
1903
1901
|
} catch (networkError) {
|
|
1904
1902
|
throw new ProviderAPIError4(
|
|
1905
1903
|
`[recovery] Network error on ${method} ${path}: ${networkError.message}`,
|
|
@@ -1909,15 +1907,18 @@ var RecoveryClient = class {
|
|
|
1909
1907
|
}
|
|
1910
1908
|
if (!response.ok) {
|
|
1911
1909
|
let message = `HTTP ${response.status}`;
|
|
1910
|
+
let details;
|
|
1912
1911
|
try {
|
|
1913
1912
|
const json = await response.json();
|
|
1914
1913
|
message = json?.message ?? message;
|
|
1914
|
+
details = json && typeof json === "object" ? json : void 0;
|
|
1915
1915
|
} catch {
|
|
1916
1916
|
}
|
|
1917
1917
|
throw new ProviderAPIError4(
|
|
1918
1918
|
`[recovery] ${method} ${path} failed: ${message}`,
|
|
1919
1919
|
`RECOVERY_API_${response.status}`,
|
|
1920
|
-
response.status
|
|
1920
|
+
response.status,
|
|
1921
|
+
details
|
|
1921
1922
|
);
|
|
1922
1923
|
}
|
|
1923
1924
|
return response.json();
|
|
@@ -2042,6 +2043,64 @@ var RecoveryClient = class {
|
|
|
2042
2043
|
}
|
|
2043
2044
|
}
|
|
2044
2045
|
}
|
|
2046
|
+
// -------------------------------------------------------------------------
|
|
2047
|
+
// Dropshipper application submission
|
|
2048
|
+
// -------------------------------------------------------------------------
|
|
2049
|
+
/**
|
|
2050
|
+
* Envía una solicitud de acceso dropshipper al endpoint público.
|
|
2051
|
+
*
|
|
2052
|
+
* `POST /public/dropshipper/applications`
|
|
2053
|
+
*
|
|
2054
|
+
* No requiere autenticación. Devuelve un resultado discriminado:
|
|
2055
|
+
* - `{ ok: true }` → 201, solicitud creada (`application.number`).
|
|
2056
|
+
* - `{ ok: false, reason: 'conflict' }` → 409, email ya registrado; la
|
|
2057
|
+
* solicitud existente incluye `status_label`/`reason` para la UI.
|
|
2058
|
+
* - `{ ok: false, reason: 'rate_limited' }` → 429, se respetó el límite del
|
|
2059
|
+
* backend; `retryAfterSeconds` indica cuándo reintentar.
|
|
2060
|
+
* - `{ ok: false, reason: 'invalid_data' }` → 400, validación del backend.
|
|
2061
|
+
*
|
|
2062
|
+
* Los errores de red/5xx se re-lanzan como `ProviderAPIError` para que el
|
|
2063
|
+
* llamador los categorice (p. ej. con `parseError`). El 429 no se reintenta
|
|
2064
|
+
* (`retryableStatusCodes` sin 429) para que el caller reciba de inmediato el
|
|
2065
|
+
* `retry_after_seconds` del backend y pueda bloquear el envío.
|
|
2066
|
+
*/
|
|
2067
|
+
async submitApplication(body) {
|
|
2068
|
+
try {
|
|
2069
|
+
const response = await this.request(
|
|
2070
|
+
"POST",
|
|
2071
|
+
"/public/dropshipper/applications",
|
|
2072
|
+
body,
|
|
2073
|
+
{ retryableStatusCodes: [408, 500, 502, 503, 504] }
|
|
2074
|
+
);
|
|
2075
|
+
return { ok: true, application: response.application };
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
if (error instanceof ProviderAPIError4) {
|
|
2078
|
+
const details = error.details ?? {};
|
|
2079
|
+
if (error.status === 409 && details.application) {
|
|
2080
|
+
return {
|
|
2081
|
+
ok: false,
|
|
2082
|
+
reason: "conflict",
|
|
2083
|
+
application: details.application
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
if (error.status === 429 && typeof details.retry_after_seconds === "number") {
|
|
2087
|
+
return {
|
|
2088
|
+
ok: false,
|
|
2089
|
+
reason: "rate_limited",
|
|
2090
|
+
retryAfterSeconds: details.retry_after_seconds
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
if (error.status === 400) {
|
|
2094
|
+
return {
|
|
2095
|
+
ok: false,
|
|
2096
|
+
reason: "invalid_data",
|
|
2097
|
+
fields: details.fields
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
throw error;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2045
2104
|
};
|
|
2046
2105
|
export {
|
|
2047
2106
|
DropshipperClient,
|