@delopay/sdk 0.93.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/index.cjs CHANGED
@@ -2203,6 +2203,7 @@ var Routing = class {
2203
2203
  this.request = request;
2204
2204
  this.decision = new RoutingDecisionManager(request);
2205
2205
  this.surchargeRules = new SurchargeRules(request);
2206
+ this.checkoutThemeRules = new CheckoutThemeRules(request);
2206
2207
  }
2207
2208
  /**
2208
2209
  * Create a new routing algorithm.
@@ -2431,6 +2432,90 @@ var SurchargeRules = class {
2431
2432
  });
2432
2433
  }
2433
2434
  };
2435
+ var CheckoutThemeRules = class {
2436
+ constructor(request) {
2437
+ this.request = request;
2438
+ }
2439
+ /**
2440
+ * Create or replace the theme program for a scope.
2441
+ *
2442
+ * `PUT /routing/checkout-theme/rules`
2443
+ *
2444
+ * Supersedes rather than overwrites: the previous active version is retired
2445
+ * and a new one stored, so the record of which look was live when survives.
2446
+ * Pass `active: false` to store a revision **without** retiring the live one —
2447
+ * that is where a program drafted against a variant you have not built yet
2448
+ * belongs.
2449
+ *
2450
+ * @example A phone in Germany gets the compact look; everyone else the house style.
2451
+ * ```typescript
2452
+ * await delopay.routing.checkoutThemeRules.upsert({
2453
+ * name: 'Autumn targeting',
2454
+ * profile_id: 'pro_...',
2455
+ * algorithm: {
2456
+ * rules: [
2457
+ * {
2458
+ * name: 'German phones',
2459
+ * connectorSelection: { theme: { variant: 'compact' } },
2460
+ * statements: [
2461
+ * {
2462
+ * condition: [
2463
+ * {
2464
+ * lhs: 'device_class',
2465
+ * comparison: 'equal',
2466
+ * value: { type: 'enum_variant', value: 'phone' },
2467
+ * metadata: {},
2468
+ * },
2469
+ * {
2470
+ * lhs: 'browser_language',
2471
+ * comparison: 'equal',
2472
+ * value: { type: 'enum_variant', value: 'de' },
2473
+ * metadata: {},
2474
+ * },
2475
+ * ],
2476
+ * },
2477
+ * ],
2478
+ * },
2479
+ * ],
2480
+ * defaultSelection: { theme: { variant: 'house' } },
2481
+ * metadata: {},
2482
+ * },
2483
+ * });
2484
+ * ```
2485
+ */
2486
+ async upsert(params) {
2487
+ return this.request("PUT", "/routing/checkout-theme/rules", { body: params });
2488
+ }
2489
+ /**
2490
+ * Retrieve the active theme program for a scope, or `null` when none is set.
2491
+ *
2492
+ * `GET /routing/checkout-theme/rules?profile_id={profileId}`
2493
+ *
2494
+ * @param profileId - Shop scope. Omit for the merchant-wide program. A
2495
+ * shop-scoped caller that omits it gets its own shop's program.
2496
+ */
2497
+ async retrieve(profileId) {
2498
+ return this.request("GET", "/routing/checkout-theme/rules", {
2499
+ query: { profile_id: profileId }
2500
+ });
2501
+ }
2502
+ /**
2503
+ * Deactivate the active theme program for a scope. Idempotent.
2504
+ *
2505
+ * `DELETE /routing/checkout-theme/rules?profile_id={profileId}`
2506
+ *
2507
+ * Deactivation, not deletion — the stored row is what says which look was
2508
+ * live when, and that history cannot be reconstructed after the fact. Shops
2509
+ * go back to their default appearance immediately.
2510
+ *
2511
+ * @param profileId - Shop scope. Omit for the merchant-wide program.
2512
+ */
2513
+ async delete(profileId) {
2514
+ return this.request("DELETE", "/routing/checkout-theme/rules", {
2515
+ query: { profile_id: profileId }
2516
+ });
2517
+ }
2518
+ };
2434
2519
 
2435
2520
  // src/resources/search.ts
2436
2521
  var Search = class {
@@ -2706,6 +2791,33 @@ var Users = class {
2706
2791
  async signOut() {
2707
2792
  return this.request("POST", "/user/signout");
2708
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
+ }
2709
2821
  /**
2710
2822
  * Paginated login history for the authenticated user -- IP, User-Agent,
2711
2823
  * country / city / lat-lon (when GeoIP is enabled), success and failure
@@ -3973,6 +4085,41 @@ var Delopay = class {
3973
4085
  clearJwtToken() {
3974
4086
  this.jwtToken = void 0;
3975
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
+ }
3976
4123
  /**
3977
4124
  * Make a raw HTTP request to the Delopay API.
3978
4125
  *