@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.
package/dist/index.cjs CHANGED
@@ -2791,6 +2791,33 @@ var Users = class {
2791
2791
  async signOut() {
2792
2792
  return this.request("POST", "/user/signout");
2793
2793
  }
2794
+ /**
2795
+ * Sliding-session refresh: exchange the current (still-valid) login JWT
2796
+ * for a fresh one with the same claims and a full lifetime. The backend
2797
+ * keeps the session's identity (`jti`), slides `user_session.expires_at`
2798
+ * forward and re-sets the `login_token` cookie.
2799
+ *
2800
+ * Requires a token backed by a revocable session (a `jti` claim). Signin
2801
+ * and switch-merchant/-profile tokens have one; **session-less tokens do
2802
+ * not and are rejected with 400** — team-impersonation tokens are the
2803
+ * case in practice, and they are deliberately tab-scoped and
2804
+ * time-bounded rather than renewable. A 400 here is not a dead session:
2805
+ * the token remains valid for ordinary calls, it simply cannot slide.
2806
+ *
2807
+ * Rejected (401) for expired, blacklisted or revoked tokens — refresh can
2808
+ * only extend a session that is still alive. Rate-limited server-side
2809
+ * (429) to one mint per session per minute; treat a 429 as "still fresh
2810
+ * enough", not as an error.
2811
+ *
2812
+ * The returned token is NOT applied to this client automatically — pass
2813
+ * it to `setJwtToken()`, or use {@link Delopay.refreshSession} which does
2814
+ * both.
2815
+ *
2816
+ * `POST /user/token/refresh`. Requires a logged-in JWT.
2817
+ */
2818
+ async refreshToken() {
2819
+ return this.request("POST", "/user/token/refresh");
2820
+ }
2794
2821
  /**
2795
2822
  * Paginated login history for the authenticated user -- IP, User-Agent,
2796
2823
  * country / city / lat-lon (when GeoIP is enabled), success and failure
@@ -3304,6 +3331,33 @@ var Analytics = class {
3304
3331
  query: params
3305
3332
  });
3306
3333
  }
3334
+ /**
3335
+ * Device analytics over the canonical client-context observation per
3336
+ * payment (browser/platform families, device classes and models, checkout
3337
+ * channel mix, time-to-pay), pinned server-side to your own merchant and
3338
+ * drillable via `project_id` / `shop_id` exactly like `scope`. Gated on the
3339
+ * client-context optimisation-use switch: when it is off the server answers
3340
+ * 200 with `enabled: false` and a caveat naming the switch.
3341
+ * `GET /analytics/devices`
3342
+ */
3343
+ async devices(params) {
3344
+ return this.request("GET", "/analytics/devices", {
3345
+ query: params
3346
+ });
3347
+ }
3348
+ /**
3349
+ * Geo analytics over the canonical client-context observation per payment:
3350
+ * country totals, city bubbles (IP mode), buyer languages, buyer-local
3351
+ * purchase hours and the IP-vs-billing mismatch share. `mode` selects the
3352
+ * location claim (`ip` default, `billing`); the two are never coalesced.
3353
+ * Same drill, window and gating contract as `devices`.
3354
+ * `GET /analytics/geo`
3355
+ */
3356
+ async geo(params) {
3357
+ return this.request("GET", "/analytics/geo", {
3358
+ query: params
3359
+ });
3360
+ }
3307
3361
  /** Global search. `POST /analytics/search` */
3308
3362
  async search(params) {
3309
3363
  return this.request("POST", "/analytics/search", { body: params });
@@ -4058,6 +4112,41 @@ var Delopay = class {
4058
4112
  clearJwtToken() {
4059
4113
  this.jwtToken = void 0;
4060
4114
  }
4115
+ /**
4116
+ * Refresh the current login JWT (see {@link Users.refreshToken}) and
4117
+ * apply the fresh token to this client, so subsequent requests use it.
4118
+ * Returns the fresh token for the caller to persist (e.g. session
4119
+ * storage) — the backend has already re-set the `login_token` cookie.
4120
+ *
4121
+ * If the client's auth state changes while the refresh is pending —
4122
+ * `clearJwtToken()` on sign-out, or `setJwtToken()` switching to another
4123
+ * session — the stale completion is discarded and this rejects with a
4124
+ * `session_changed` `DelopayError` (status 0), so the explicit change
4125
+ * wins and the caller never persists a token for a session that is gone.
4126
+ *
4127
+ * Otherwise throws like any other request; in particular a 401 means the
4128
+ * session is dead (expired/blacklisted/revoked), a 429 means a refresh
4129
+ * was already minted for this session within the last minute, and a 400
4130
+ * means this token has no revocable session to slide (no `jti` — team
4131
+ * impersonation is the case in practice) and can never be refreshed,
4132
+ * though it stays valid for ordinary calls.
4133
+ */
4134
+ async refreshSession() {
4135
+ const originatingToken = this.jwtToken;
4136
+ const response = await this.users.refreshToken();
4137
+ if (this.jwtToken !== originatingToken) {
4138
+ throw new DelopayError(
4139
+ "Auth state changed while the refresh was pending; refreshed token discarded",
4140
+ {
4141
+ status: 0,
4142
+ code: "session_changed",
4143
+ type: "session_changed"
4144
+ }
4145
+ );
4146
+ }
4147
+ this.setJwtToken(response.token);
4148
+ return response;
4149
+ }
4061
4150
  /**
4062
4151
  * Make a raw HTTP request to the Delopay API.
4063
4152
  *