@raisindb/client 0.1.54 → 0.1.56

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.
Files changed (39) hide show
  1. package/dist/{chunk-WFBAWOVM.mjs → chunk-3A3ULBDO.mjs} +3 -3
  2. package/dist/{chunk-JRFBP4WK.mjs → chunk-4D45SBYO.mjs} +2 -2
  3. package/dist/{chunk-VZX3ACSO.mjs → chunk-BGU5L4PF.mjs} +3 -3
  4. package/dist/{chunk-OLJOZIIU.mjs → chunk-GRC5AZMU.mjs} +23 -4
  5. package/dist/chunk-GRC5AZMU.mjs.map +1 -0
  6. package/dist/{chunk-DJDP5CX6.mjs → chunk-T26GAHFZ.mjs} +2 -2
  7. package/dist/{conversation-list-store-CrmmmVKE.d.mts → conversation-list-store-ZtQuHSJ6.d.mts} +188 -4
  8. package/dist/{conversation-list-store-CrmmmVKE.d.ts → conversation-list-store-ZtQuHSJ6.d.ts} +188 -4
  9. package/dist/{index-DkVt51MH.d.mts → index-Dz2KIWoc.d.mts} +1 -1
  10. package/dist/{index-DcJiy1S6.d.ts → index-um2A-Myw.d.ts} +1 -1
  11. package/dist/index.d.mts +4 -4
  12. package/dist/index.d.ts +4 -4
  13. package/dist/index.js +142 -32
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +124 -34
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/react.d.mts +2 -2
  18. package/dist/react.d.ts +2 -2
  19. package/dist/react.js +22 -3
  20. package/dist/react.js.map +1 -1
  21. package/dist/react.mjs +3 -3
  22. package/dist/{svelte-sql-C0CmmhAL.d.ts → svelte-sql-CBExaUVi.d.ts} +1 -1
  23. package/dist/{svelte-sql-RNJfHu0B.d.mts → svelte-sql-i2ZwTvv2.d.mts} +1 -1
  24. package/dist/svelte.d.mts +2 -2
  25. package/dist/svelte.d.ts +2 -2
  26. package/dist/svelte.js +22 -3
  27. package/dist/svelte.js.map +1 -1
  28. package/dist/svelte.mjs +3 -3
  29. package/dist/vue.d.mts +2 -2
  30. package/dist/vue.d.ts +2 -2
  31. package/dist/vue.js +22 -3
  32. package/dist/vue.js.map +1 -1
  33. package/dist/vue.mjs +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-OLJOZIIU.mjs.map +0 -1
  36. /package/dist/{chunk-WFBAWOVM.mjs.map → chunk-3A3ULBDO.mjs.map} +0 -0
  37. /package/dist/{chunk-JRFBP4WK.mjs.map → chunk-4D45SBYO.mjs.map} +0 -0
  38. /package/dist/{chunk-VZX3ACSO.mjs.map → chunk-BGU5L4PF.mjs.map} +0 -0
  39. /package/dist/{chunk-DJDP5CX6.mjs.map → chunk-T26GAHFZ.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  useConversation,
4
4
  useConversationList,
5
5
  useFlow
6
- } from "./chunk-WFBAWOVM.mjs";
6
+ } from "./chunk-3A3ULBDO.mjs";
7
7
  import {
8
8
  RAISIN_CONTEXT_KEY,
9
9
  createConversationAdapter,
10
10
  createConversationListAdapter,
11
11
  createFlowAdapter
12
- } from "./chunk-VZX3ACSO.mjs";
12
+ } from "./chunk-BGU5L4PF.mjs";
13
13
  import {
14
14
  FlowClient,
15
15
  RaisinAbortError,
@@ -20,10 +20,10 @@ import {
20
20
  RaisinTimeoutError,
21
21
  SSEClient,
22
22
  classifyHttpError
23
- } from "./chunk-DJDP5CX6.mjs";
23
+ } from "./chunk-T26GAHFZ.mjs";
24
24
  import {
25
25
  createRaisinVue
26
- } from "./chunk-JRFBP4WK.mjs";
26
+ } from "./chunk-4D45SBYO.mjs";
27
27
  import {
28
28
  createAuthAdapter,
29
29
  createConnectionAdapter,
@@ -45,7 +45,7 @@ import {
45
45
  normalizeHomePath,
46
46
  projectPlansFromMessages,
47
47
  setLogLevel
48
- } from "./chunk-OLJOZIIU.mjs";
48
+ } from "./chunk-GRC5AZMU.mjs";
49
49
 
50
50
  // src/client.ts
51
51
  import { EventEmitter as EventEmitter2 } from "events";
@@ -411,6 +411,7 @@ var RequestType = /* @__PURE__ */ ((RequestType2) => {
411
411
  RequestType2["BranchMerge"] = "branch_merge";
412
412
  RequestType2["BranchCompare"] = "branch_compare";
413
413
  RequestType2["BranchDiff"] = "branch_diff";
414
+ RequestType2["BranchCopyNodes"] = "branch_copy_nodes";
414
415
  RequestType2["TagCreate"] = "tag_create";
415
416
  RequestType2["TagGet"] = "tag_get";
416
417
  RequestType2["TagList"] = "tag_list";
@@ -464,6 +465,10 @@ var RequestType = /* @__PURE__ */ ((RequestType2) => {
464
465
  RequestType2["FlowUnsubscribeEvents"] = "flow_unsubscribe_events";
465
466
  RequestType2["FunctionInvoke"] = "function_invoke";
466
467
  RequestType2["FunctionInvokeSync"] = "function_invoke_sync";
468
+ RequestType2["ScheduledInvocationCreate"] = "scheduled_invocation_create";
469
+ RequestType2["ScheduledInvocationCancel"] = "scheduled_invocation_cancel";
470
+ RequestType2["ScheduledInvocationList"] = "scheduled_invocation_list";
471
+ RequestType2["ScheduledInvocationGet"] = "scheduled_invocation_get";
467
472
  return RequestType2;
468
473
  })(RequestType || {});
469
474
  var ResponseStatus = /* @__PURE__ */ ((ResponseStatus2) => {
@@ -2648,6 +2653,87 @@ var Branches = class {
2648
2653
  "branch_diff" /* BranchDiff */
2649
2654
  );
2650
2655
  }
2656
+ /**
2657
+ * Copy a node set from `sourceBranch` onto `targetBranch` (branch
2658
+ * promotion): node ids are preserved, so repeated copies update the same
2659
+ * target nodes; all changes land in ONE atomic commit on the target branch.
2660
+ *
2661
+ * Each root's parent path must already exist on the target branch. With
2662
+ * `deleteMissing`, target nodes under the roots that are absent from the
2663
+ * copied source set are pruned (one-way sync).
2664
+ */
2665
+ async copyNodes(sourceBranch, targetBranch, opts) {
2666
+ return this.sendRequest(
2667
+ {
2668
+ source_branch: sourceBranch,
2669
+ target_branch: targetBranch,
2670
+ workspace: opts.workspace,
2671
+ roots: opts.roots,
2672
+ recursive: opts.recursive ?? true,
2673
+ delete_missing: opts.deleteMissing ?? false
2674
+ },
2675
+ "branch_copy_nodes" /* BranchCopyNodes */
2676
+ );
2677
+ }
2678
+ };
2679
+
2680
+ // src/scheduler.ts
2681
+ var SchedulerApi = class {
2682
+ constructor(_context, sendRequest) {
2683
+ this.sendRequest = sendRequest;
2684
+ }
2685
+ /**
2686
+ * Schedule a one-shot invocation of a function or flow at a fixed time.
2687
+ */
2688
+ async schedule(options) {
2689
+ const runAt = options.runAt instanceof Date ? options.runAt.toISOString() : options.runAt;
2690
+ return this.sendRequest(
2691
+ {
2692
+ target_kind: options.targetKind,
2693
+ target_path: options.targetPath,
2694
+ input: options.input ?? {},
2695
+ run_at: runAt,
2696
+ external_key: options.externalKey,
2697
+ branch: options.branch,
2698
+ workspace: options.workspace,
2699
+ max_retries: options.maxRetries
2700
+ },
2701
+ "scheduled_invocation_create" /* ScheduledInvocationCreate */
2702
+ );
2703
+ }
2704
+ /**
2705
+ * Cancel a pending invocation before it fires, by job id or external key.
2706
+ */
2707
+ async cancel(ref) {
2708
+ const payload = typeof ref === "string" ? { job_id: ref } : { job_id: ref.jobId, external_key: ref.externalKey };
2709
+ return this.sendRequest(
2710
+ payload,
2711
+ "scheduled_invocation_cancel" /* ScheduledInvocationCancel */
2712
+ );
2713
+ }
2714
+ /**
2715
+ * List this repository's scheduled invocations.
2716
+ */
2717
+ async list(filter) {
2718
+ const result = await this.sendRequest(
2719
+ {
2720
+ external_key: filter?.externalKey,
2721
+ status: filter?.status
2722
+ },
2723
+ "scheduled_invocation_list" /* ScheduledInvocationList */
2724
+ );
2725
+ return result?.invocations ?? [];
2726
+ }
2727
+ /**
2728
+ * Fetch a single scheduled invocation, by job id or external key.
2729
+ */
2730
+ async get(ref) {
2731
+ const payload = typeof ref === "string" ? { job_id: ref } : { job_id: ref.jobId, external_key: ref.externalKey };
2732
+ return this.sendRequest(
2733
+ payload,
2734
+ "scheduled_invocation_get" /* ScheduledInvocationGet */
2735
+ );
2736
+ }
2651
2737
  };
2652
2738
 
2653
2739
  // src/tags.ts
@@ -3993,6 +4079,13 @@ var Database = class _Database {
3993
4079
  tags() {
3994
4080
  return new Tags(this._context, this.sendRequest);
3995
4081
  }
4082
+ /**
4083
+ * Get SchedulerApi for one-shot scheduled invocations (time-based
4084
+ * function/flow runs).
4085
+ */
4086
+ scheduler() {
4087
+ return new SchedulerApi(this._context, this.sendRequest);
4088
+ }
3996
4089
  /**
3997
4090
  * Get FlowsApi for running flows via WebSocket
3998
4091
  */
@@ -6492,6 +6585,8 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
6492
6585
  this._restoreRetryDelaysMs = [1e3, 3e3, 9e3];
6493
6586
  // Upload manager (uses HTTP under the hood)
6494
6587
  this._uploadManager = null;
6588
+ /** In-flight refresh shared by concurrent refreshToken() callers. */
6589
+ this._refreshInFlight = null;
6495
6590
  if (options.logLevel !== void 0) {
6496
6591
  setLogLevel(options.logLevel);
6497
6592
  }
@@ -7151,39 +7246,18 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
7151
7246
  if (payload && payload.exp && typeof payload.exp === "number") {
7152
7247
  if (payload.exp * 1e3 < Date.now()) {
7153
7248
  logger.info("[initSession] Token expired, attempting refresh...");
7154
- const refreshToken = this.authManager.storage.getRefreshToken();
7155
- if (refreshToken) {
7156
- try {
7157
- const url = this._repository ? `${this._httpBaseUrl}/auth/${this._repository}/refresh` : `${this._httpBaseUrl}/auth/refresh`;
7158
- const response = await this._fetchWithTimeout(url, {
7159
- method: "POST",
7160
- headers: { "Content-Type": "application/json" },
7161
- body: JSON.stringify({ refresh_token: refreshToken })
7162
- });
7163
- if (response.ok) {
7164
- const tokens = await response.json();
7165
- this.authManager.storage.setAccessToken(tokens.access_token);
7166
- this.authManager.storage.setRefreshToken(tokens.refresh_token);
7167
- const expiresInMs = _RaisinClient.expiresAtToMs(tokens.expires_at) - Date.now() - 5 * 60 * 1e3;
7168
- if (expiresInMs > 0) {
7169
- this.scheduleAutoRefresh(expiresInMs);
7170
- }
7171
- logger.info("[initSession] Token refreshed successfully");
7172
- } else {
7173
- logger.warn("[initSession] Token refresh failed, clearing session");
7174
- this.authManager.clear();
7175
- return null;
7176
- }
7177
- } catch (err) {
7178
- logger.warn("[initSession] Token refresh error:", err);
7179
- this.authManager.clear();
7180
- return null;
7181
- }
7182
- } else {
7249
+ if (!this.authManager.storage.getRefreshToken()) {
7183
7250
  logger.warn("[initSession] No refresh token, clearing session");
7184
7251
  this.authManager.clear();
7185
7252
  return null;
7186
7253
  }
7254
+ const refreshed = await this.refreshToken();
7255
+ if (!refreshed) {
7256
+ logger.warn("[initSession] Token refresh failed, clearing session");
7257
+ this.authManager.clear();
7258
+ return null;
7259
+ }
7260
+ logger.info("[initSession] Token refreshed successfully");
7187
7261
  }
7188
7262
  }
7189
7263
  try {
@@ -7273,6 +7347,16 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
7273
7347
  * @throws Error if no refresh token is stored or refresh fails
7274
7348
  */
7275
7349
  async refreshToken() {
7350
+ if (this._refreshInFlight) {
7351
+ logger.debug("[refreshToken] Refresh already in flight, awaiting it");
7352
+ return this._refreshInFlight;
7353
+ }
7354
+ this._refreshInFlight = this._refreshToken().finally(() => {
7355
+ this._refreshInFlight = null;
7356
+ });
7357
+ return this._refreshInFlight;
7358
+ }
7359
+ async _refreshToken() {
7276
7360
  const refreshToken = this.authManager.storage.getRefreshToken();
7277
7361
  if (!refreshToken) {
7278
7362
  logger.warn("[refreshToken] No refresh token available");
@@ -7289,6 +7373,11 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
7289
7373
  if (!response.ok) {
7290
7374
  const errorText = await response.text();
7291
7375
  logger.error("[refreshToken] Refresh failed:", response.status, errorText);
7376
+ if (/TOKEN_REUSE_DETECTED|TOKEN_FAMILY_MISMATCH/.test(errorText)) {
7377
+ logger.error(
7378
+ "[refreshToken] Session revoked by the server as a suspected token replay. If this happened on a normal page load, two refreshes raced on the same token."
7379
+ );
7380
+ }
7292
7381
  if (response.status === 401 || response.status === 403) {
7293
7382
  this.authManager.clear();
7294
7383
  this._currentUser = null;
@@ -8600,6 +8689,7 @@ export {
8600
8689
  ResponseStatus,
8601
8690
  RetryBuilder,
8602
8691
  SSEClient,
8692
+ SchedulerApi,
8603
8693
  SqlQuery,
8604
8694
  Tags,
8605
8695
  Transaction,