@thorprovider/medusa-extended 1.13.1 → 1.13.3

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.mjs CHANGED
@@ -1227,6 +1227,31 @@ var DropshipperClient = class {
1227
1227
  "/admin/thor/dropshipper/account"
1228
1228
  );
1229
1229
  }
1230
+ /**
1231
+ * Get the authenticated dropshipper's business policy text.
1232
+ * Returns an empty string when no policy is set.
1233
+ *
1234
+ * `GET /admin/thor/dropshipper/account/policies`
1235
+ */
1236
+ async getBusinessPolicy() {
1237
+ return this.request(
1238
+ "GET",
1239
+ "/admin/thor/dropshipper/account/policies"
1240
+ );
1241
+ }
1242
+ /**
1243
+ * Update the authenticated dropshipper's business policy text.
1244
+ * The value is trimmed server-side before being persisted.
1245
+ *
1246
+ * `PATCH /admin/thor/dropshipper/account/policies`
1247
+ */
1248
+ async updateBusinessPolicy(body) {
1249
+ return this.request(
1250
+ "PATCH",
1251
+ "/admin/thor/dropshipper/account/policies",
1252
+ body
1253
+ );
1254
+ }
1230
1255
  /**
1231
1256
  * Orders where Y owes money to X (Y collected payment, needs to pay costs).
1232
1257
  *
@@ -1944,27 +1969,14 @@ var RecoveryClient = class {
1944
1969
  details
1945
1970
  );
1946
1971
  }
1947
- return response.json();
1948
- }
1949
- // -------------------------------------------------------------------------
1950
- // Private — reset token helpers
1951
- // -------------------------------------------------------------------------
1952
- /**
1953
- * Decodes the `entity_id` (email) claim from a Medusa reset-password JWT.
1954
- *
1955
- * The JWT is unsigned-trust for this claim: the email is later sent to
1956
- * `POST /auth/user/emailpass/update`, where Medusa itself re-validates the
1957
- * token signature and payload before applying the change.
1958
- */
1959
- decodeResetTokenEmail(token) {
1960
- const parts = token.split(".");
1961
- if (parts.length !== 3) return null;
1962
- try {
1963
- const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
1964
- return typeof payload.entity_id === "string" && payload.entity_id.length > 0 ? payload.entity_id : null;
1965
- } catch {
1966
- return null;
1972
+ if ((response.headers.get("content-type") ?? "").includes("application/json")) {
1973
+ try {
1974
+ return await response.json();
1975
+ } catch {
1976
+ return {};
1977
+ }
1967
1978
  }
1979
+ return {};
1968
1980
  }
1969
1981
  // -------------------------------------------------------------------------
1970
1982
  // Password reset
@@ -1974,49 +1986,46 @@ var RecoveryClient = class {
1974
1986
  * (dropshippers). El backend responde de forma uniforme exista o no la
1975
1987
  * cuenta (anti enumeración).
1976
1988
  *
1977
- * `POST /auth/user/emailpass/reset-password`
1989
+ * `POST /dropshipper/auth/emailpass/reset-password`
1978
1990
  */
1979
1991
  async requestUserPasswordReset(email) {
1980
- await this.request("POST", "/auth/user/emailpass/reset-password", {
1981
- identifier: email
1992
+ await this.request("POST", "/dropshipper/auth/emailpass/reset-password", {
1993
+ email
1982
1994
  });
1983
1995
  }
1984
1996
  /**
1985
1997
  * Verifica un token de reset de contraseña sin consumirlo. Devuelve el
1986
1998
  * email enmascarado (p. ej. `j***@ejemplo.com`) solo cuando `status === 'valid'`.
1987
1999
  *
1988
- * `GET /store/dropshipper/auth/reset-password/verify`
2000
+ * `GET /dropshipper/auth/emailpass/reset-password/verify`
1989
2001
  */
1990
2002
  async verifyUserPasswordResetToken(token) {
1991
- return this.request("GET", `/store/dropshipper/auth/reset-password/verify?token=${encodeURIComponent(token)}`);
2003
+ return this.request("GET", `/dropshipper/auth/emailpass/reset-password/verify?token=${encodeURIComponent(token)}`);
1992
2004
  }
1993
2005
  /**
1994
2006
  * Confirma el reset: re-verifica el token (sin consumir), luego consume el
1995
- * token vía `POST /auth/user/emailpass/update`. El email se deriva del
1996
- * propio JWT. Nunca devuelve auto-login: al éxito, la UI redirige a /login.
2007
+ * token vía `POST /dropshipper/auth/emailpass/update`. El email se deriva del
2008
+ * propio JWT en el backend; aquí solo se envía la nueva contraseña. Nunca
2009
+ * devuelve auto-login: al éxito, la UI redirige a /login.
1997
2010
  */
1998
2011
  async confirmUserPasswordReset(token, password) {
1999
2012
  const verify = await this.verifyUserPasswordResetToken(token);
2000
2013
  if (verify.status !== "valid") {
2001
2014
  return { ok: false, status: verify.status };
2002
2015
  }
2003
- const email = this.decodeResetTokenEmail(token);
2004
- if (!email) {
2005
- return { ok: false, status: "invalid" };
2006
- }
2007
2016
  try {
2008
2017
  const headers = {
2009
2018
  Authorization: `Bearer ${token}`,
2010
2019
  "Content-Type": "application/json"
2011
2020
  };
2012
- const response = await fetchBackendWithResilience(`${this.baseUrl}/auth/user/emailpass/update`, {
2021
+ const response = await fetchBackendWithResilience(`${this.baseUrl}/dropshipper/auth/emailpass/update`, {
2013
2022
  method: "POST",
2014
2023
  headers,
2015
- body: JSON.stringify({ email, password })
2024
+ body: JSON.stringify({ password })
2016
2025
  });
2017
2026
  if (!response.ok) {
2018
2027
  throw new ProviderAPIError4(
2019
- `[recovery] POST /auth/user/emailpass/update failed: HTTP ${response.status}`,
2028
+ `[recovery] POST /dropshipper/auth/emailpass/update failed: HTTP ${response.status}`,
2020
2029
  "RECOVERY_API_" + response.status,
2021
2030
  response.status
2022
2031
  );
@@ -2113,6 +2122,13 @@ var RecoveryClient = class {
2113
2122
  retryAfterSeconds: details.retry_after_seconds
2114
2123
  };
2115
2124
  }
2125
+ if (error.status === 400 && details?.type === "challenge_failed") {
2126
+ return {
2127
+ ok: false,
2128
+ reason: "challenge_failed",
2129
+ ...typeof details.message === "string" ? { message: details.message } : {}
2130
+ };
2131
+ }
2116
2132
  if (error.status === 400) {
2117
2133
  return {
2118
2134
  ok: false,