@delopay/sdk 0.94.0 → 0.96.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.
@@ -2677,6 +2677,33 @@ var Users = class {
2677
2677
  async signOut() {
2678
2678
  return this.request("POST", "/user/signout");
2679
2679
  }
2680
+ /**
2681
+ * Sliding-session refresh: exchange the current (still-valid) login JWT
2682
+ * for a fresh one with the same claims and a full lifetime. The backend
2683
+ * keeps the session's identity (`jti`), slides `user_session.expires_at`
2684
+ * forward and re-sets the `login_token` cookie.
2685
+ *
2686
+ * Requires a token backed by a revocable session (a `jti` claim). Signin
2687
+ * and switch-merchant/-profile tokens have one; **session-less tokens do
2688
+ * not and are rejected with 400** — team-impersonation tokens are the
2689
+ * case in practice, and they are deliberately tab-scoped and
2690
+ * time-bounded rather than renewable. A 400 here is not a dead session:
2691
+ * the token remains valid for ordinary calls, it simply cannot slide.
2692
+ *
2693
+ * Rejected (401) for expired, blacklisted or revoked tokens — refresh can
2694
+ * only extend a session that is still alive. Rate-limited server-side
2695
+ * (429) to one mint per session per minute; treat a 429 as "still fresh
2696
+ * enough", not as an error.
2697
+ *
2698
+ * The returned token is NOT applied to this client automatically — pass
2699
+ * it to `setJwtToken()`, or use {@link Delopay.refreshSession} which does
2700
+ * both.
2701
+ *
2702
+ * `POST /user/token/refresh`. Requires a logged-in JWT.
2703
+ */
2704
+ async refreshToken() {
2705
+ return this.request("POST", "/user/token/refresh");
2706
+ }
2680
2707
  /**
2681
2708
  * Paginated login history for the authenticated user -- IP, User-Agent,
2682
2709
  * country / city / lat-lon (when GeoIP is enabled), success and failure
@@ -3190,6 +3217,33 @@ var Analytics = class {
3190
3217
  query: params
3191
3218
  });
3192
3219
  }
3220
+ /**
3221
+ * Device analytics over the canonical client-context observation per
3222
+ * payment (browser/platform families, device classes and models, checkout
3223
+ * channel mix, time-to-pay), pinned server-side to your own merchant and
3224
+ * drillable via `project_id` / `shop_id` exactly like `scope`. Gated on the
3225
+ * client-context optimisation-use switch: when it is off the server answers
3226
+ * 200 with `enabled: false` and a caveat naming the switch.
3227
+ * `GET /analytics/devices`
3228
+ */
3229
+ async devices(params) {
3230
+ return this.request("GET", "/analytics/devices", {
3231
+ query: params
3232
+ });
3233
+ }
3234
+ /**
3235
+ * Geo analytics over the canonical client-context observation per payment:
3236
+ * country totals, city bubbles (IP mode), buyer languages, buyer-local
3237
+ * purchase hours and the IP-vs-billing mismatch share. `mode` selects the
3238
+ * location claim (`ip` default, `billing`); the two are never coalesced.
3239
+ * Same drill, window and gating contract as `devices`.
3240
+ * `GET /analytics/geo`
3241
+ */
3242
+ async geo(params) {
3243
+ return this.request("GET", "/analytics/geo", {
3244
+ query: params
3245
+ });
3246
+ }
3193
3247
  /** Global search. `POST /analytics/search` */
3194
3248
  async search(params) {
3195
3249
  return this.request("POST", "/analytics/search", { body: params });
@@ -3944,6 +3998,41 @@ var Delopay = class {
3944
3998
  clearJwtToken() {
3945
3999
  this.jwtToken = void 0;
3946
4000
  }
4001
+ /**
4002
+ * Refresh the current login JWT (see {@link Users.refreshToken}) and
4003
+ * apply the fresh token to this client, so subsequent requests use it.
4004
+ * Returns the fresh token for the caller to persist (e.g. session
4005
+ * storage) — the backend has already re-set the `login_token` cookie.
4006
+ *
4007
+ * If the client's auth state changes while the refresh is pending —
4008
+ * `clearJwtToken()` on sign-out, or `setJwtToken()` switching to another
4009
+ * session — the stale completion is discarded and this rejects with a
4010
+ * `session_changed` `DelopayError` (status 0), so the explicit change
4011
+ * wins and the caller never persists a token for a session that is gone.
4012
+ *
4013
+ * Otherwise throws like any other request; in particular a 401 means the
4014
+ * session is dead (expired/blacklisted/revoked), a 429 means a refresh
4015
+ * was already minted for this session within the last minute, and a 400
4016
+ * means this token has no revocable session to slide (no `jti` — team
4017
+ * impersonation is the case in practice) and can never be refreshed,
4018
+ * though it stays valid for ordinary calls.
4019
+ */
4020
+ async refreshSession() {
4021
+ const originatingToken = this.jwtToken;
4022
+ const response = await this.users.refreshToken();
4023
+ if (this.jwtToken !== originatingToken) {
4024
+ throw new DelopayError(
4025
+ "Auth state changed while the refresh was pending; refreshed token discarded",
4026
+ {
4027
+ status: 0,
4028
+ code: "session_changed",
4029
+ type: "session_changed"
4030
+ }
4031
+ );
4032
+ }
4033
+ this.setJwtToken(response.token);
4034
+ return response;
4035
+ }
3947
4036
  /**
3948
4037
  * Make a raw HTTP request to the Delopay API.
3949
4038
  *
@@ -5971,4 +6060,4 @@ export {
5971
6060
  focusedCheckoutUrl,
5972
6061
  CHECKOUT_EVENT_KINDS
5973
6062
  };
5974
- //# sourceMappingURL=chunk-TSYU2IQK.js.map
6063
+ //# sourceMappingURL=chunk-MMDPBYRI.js.map