@delopay/sdk 0.94.0 → 0.95.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/{chunk-TSYU2IQK.js → chunk-6BVLBNEZ.js} +63 -1
- package/dist/chunk-6BVLBNEZ.js.map +1 -0
- package/dist/index.cjs +62 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +1 -1
- package/dist/internal.cjs +62 -0
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +1 -1
- package/package.json +17 -18
- package/dist/chunk-TSYU2IQK.js.map +0 -1
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
|
|
@@ -4058,6 +4085,41 @@ var Delopay = class {
|
|
|
4058
4085
|
clearJwtToken() {
|
|
4059
4086
|
this.jwtToken = void 0;
|
|
4060
4087
|
}
|
|
4088
|
+
/**
|
|
4089
|
+
* Refresh the current login JWT (see {@link Users.refreshToken}) and
|
|
4090
|
+
* apply the fresh token to this client, so subsequent requests use it.
|
|
4091
|
+
* Returns the fresh token for the caller to persist (e.g. session
|
|
4092
|
+
* storage) — the backend has already re-set the `login_token` cookie.
|
|
4093
|
+
*
|
|
4094
|
+
* If the client's auth state changes while the refresh is pending —
|
|
4095
|
+
* `clearJwtToken()` on sign-out, or `setJwtToken()` switching to another
|
|
4096
|
+
* session — the stale completion is discarded and this rejects with a
|
|
4097
|
+
* `session_changed` `DelopayError` (status 0), so the explicit change
|
|
4098
|
+
* wins and the caller never persists a token for a session that is gone.
|
|
4099
|
+
*
|
|
4100
|
+
* Otherwise throws like any other request; in particular a 401 means the
|
|
4101
|
+
* session is dead (expired/blacklisted/revoked), a 429 means a refresh
|
|
4102
|
+
* was already minted for this session within the last minute, and a 400
|
|
4103
|
+
* means this token has no revocable session to slide (no `jti` — team
|
|
4104
|
+
* impersonation is the case in practice) and can never be refreshed,
|
|
4105
|
+
* though it stays valid for ordinary calls.
|
|
4106
|
+
*/
|
|
4107
|
+
async refreshSession() {
|
|
4108
|
+
const originatingToken = this.jwtToken;
|
|
4109
|
+
const response = await this.users.refreshToken();
|
|
4110
|
+
if (this.jwtToken !== originatingToken) {
|
|
4111
|
+
throw new DelopayError(
|
|
4112
|
+
"Auth state changed while the refresh was pending; refreshed token discarded",
|
|
4113
|
+
{
|
|
4114
|
+
status: 0,
|
|
4115
|
+
code: "session_changed",
|
|
4116
|
+
type: "session_changed"
|
|
4117
|
+
}
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
4120
|
+
this.setJwtToken(response.token);
|
|
4121
|
+
return response;
|
|
4122
|
+
}
|
|
4061
4123
|
/**
|
|
4062
4124
|
* Make a raw HTTP request to the Delopay API.
|
|
4063
4125
|
*
|