@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.js CHANGED
@@ -79,6 +79,7 @@ __export(src_exports, {
79
79
  ResponseStatus: () => ResponseStatus,
80
80
  RetryBuilder: () => RetryBuilder,
81
81
  SSEClient: () => SSEClient,
82
+ SchedulerApi: () => SchedulerApi,
82
83
  SqlQuery: () => SqlQuery,
83
84
  Tags: () => Tags,
84
85
  Transaction: () => Transaction,
@@ -865,6 +866,7 @@ var RequestType = /* @__PURE__ */ ((RequestType2) => {
865
866
  RequestType2["BranchMerge"] = "branch_merge";
866
867
  RequestType2["BranchCompare"] = "branch_compare";
867
868
  RequestType2["BranchDiff"] = "branch_diff";
869
+ RequestType2["BranchCopyNodes"] = "branch_copy_nodes";
868
870
  RequestType2["TagCreate"] = "tag_create";
869
871
  RequestType2["TagGet"] = "tag_get";
870
872
  RequestType2["TagList"] = "tag_list";
@@ -918,6 +920,10 @@ var RequestType = /* @__PURE__ */ ((RequestType2) => {
918
920
  RequestType2["FlowUnsubscribeEvents"] = "flow_unsubscribe_events";
919
921
  RequestType2["FunctionInvoke"] = "function_invoke";
920
922
  RequestType2["FunctionInvokeSync"] = "function_invoke_sync";
923
+ RequestType2["ScheduledInvocationCreate"] = "scheduled_invocation_create";
924
+ RequestType2["ScheduledInvocationCancel"] = "scheduled_invocation_cancel";
925
+ RequestType2["ScheduledInvocationList"] = "scheduled_invocation_list";
926
+ RequestType2["ScheduledInvocationGet"] = "scheduled_invocation_get";
921
927
  return RequestType2;
922
928
  })(RequestType || {});
923
929
  var ResponseStatus = /* @__PURE__ */ ((ResponseStatus2) => {
@@ -3102,6 +3108,87 @@ var Branches = class {
3102
3108
  "branch_diff" /* BranchDiff */
3103
3109
  );
3104
3110
  }
3111
+ /**
3112
+ * Copy a node set from `sourceBranch` onto `targetBranch` (branch
3113
+ * promotion): node ids are preserved, so repeated copies update the same
3114
+ * target nodes; all changes land in ONE atomic commit on the target branch.
3115
+ *
3116
+ * Each root's parent path must already exist on the target branch. With
3117
+ * `deleteMissing`, target nodes under the roots that are absent from the
3118
+ * copied source set are pruned (one-way sync).
3119
+ */
3120
+ async copyNodes(sourceBranch, targetBranch, opts) {
3121
+ return this.sendRequest(
3122
+ {
3123
+ source_branch: sourceBranch,
3124
+ target_branch: targetBranch,
3125
+ workspace: opts.workspace,
3126
+ roots: opts.roots,
3127
+ recursive: opts.recursive ?? true,
3128
+ delete_missing: opts.deleteMissing ?? false
3129
+ },
3130
+ "branch_copy_nodes" /* BranchCopyNodes */
3131
+ );
3132
+ }
3133
+ };
3134
+
3135
+ // src/scheduler.ts
3136
+ var SchedulerApi = class {
3137
+ constructor(_context, sendRequest) {
3138
+ this.sendRequest = sendRequest;
3139
+ }
3140
+ /**
3141
+ * Schedule a one-shot invocation of a function or flow at a fixed time.
3142
+ */
3143
+ async schedule(options) {
3144
+ const runAt = options.runAt instanceof Date ? options.runAt.toISOString() : options.runAt;
3145
+ return this.sendRequest(
3146
+ {
3147
+ target_kind: options.targetKind,
3148
+ target_path: options.targetPath,
3149
+ input: options.input ?? {},
3150
+ run_at: runAt,
3151
+ external_key: options.externalKey,
3152
+ branch: options.branch,
3153
+ workspace: options.workspace,
3154
+ max_retries: options.maxRetries
3155
+ },
3156
+ "scheduled_invocation_create" /* ScheduledInvocationCreate */
3157
+ );
3158
+ }
3159
+ /**
3160
+ * Cancel a pending invocation before it fires, by job id or external key.
3161
+ */
3162
+ async cancel(ref) {
3163
+ const payload = typeof ref === "string" ? { job_id: ref } : { job_id: ref.jobId, external_key: ref.externalKey };
3164
+ return this.sendRequest(
3165
+ payload,
3166
+ "scheduled_invocation_cancel" /* ScheduledInvocationCancel */
3167
+ );
3168
+ }
3169
+ /**
3170
+ * List this repository's scheduled invocations.
3171
+ */
3172
+ async list(filter) {
3173
+ const result = await this.sendRequest(
3174
+ {
3175
+ external_key: filter?.externalKey,
3176
+ status: filter?.status
3177
+ },
3178
+ "scheduled_invocation_list" /* ScheduledInvocationList */
3179
+ );
3180
+ return result?.invocations ?? [];
3181
+ }
3182
+ /**
3183
+ * Fetch a single scheduled invocation, by job id or external key.
3184
+ */
3185
+ async get(ref) {
3186
+ const payload = typeof ref === "string" ? { job_id: ref } : { job_id: ref.jobId, external_key: ref.externalKey };
3187
+ return this.sendRequest(
3188
+ payload,
3189
+ "scheduled_invocation_get" /* ScheduledInvocationGet */
3190
+ );
3191
+ }
3105
3192
  };
3106
3193
 
3107
3194
  // src/tags.ts
@@ -5320,6 +5407,13 @@ var Database = class _Database {
5320
5407
  tags() {
5321
5408
  return new Tags(this._context, this.sendRequest);
5322
5409
  }
5410
+ /**
5411
+ * Get SchedulerApi for one-shot scheduled invocations (time-based
5412
+ * function/flow runs).
5413
+ */
5414
+ scheduler() {
5415
+ return new SchedulerApi(this._context, this.sendRequest);
5416
+ }
5323
5417
  /**
5324
5418
  * Get FlowsApi for running flows via WebSocket
5325
5419
  */
@@ -7819,6 +7913,8 @@ var _RaisinClient = class _RaisinClient extends import_events4.EventEmitter {
7819
7913
  this._restoreRetryDelaysMs = [1e3, 3e3, 9e3];
7820
7914
  // Upload manager (uses HTTP under the hood)
7821
7915
  this._uploadManager = null;
7916
+ /** In-flight refresh shared by concurrent refreshToken() callers. */
7917
+ this._refreshInFlight = null;
7822
7918
  if (options.logLevel !== void 0) {
7823
7919
  setLogLevel(options.logLevel);
7824
7920
  }
@@ -8478,39 +8574,18 @@ var _RaisinClient = class _RaisinClient extends import_events4.EventEmitter {
8478
8574
  if (payload && payload.exp && typeof payload.exp === "number") {
8479
8575
  if (payload.exp * 1e3 < Date.now()) {
8480
8576
  logger.info("[initSession] Token expired, attempting refresh...");
8481
- const refreshToken = this.authManager.storage.getRefreshToken();
8482
- if (refreshToken) {
8483
- try {
8484
- const url = this._repository ? `${this._httpBaseUrl}/auth/${this._repository}/refresh` : `${this._httpBaseUrl}/auth/refresh`;
8485
- const response = await this._fetchWithTimeout(url, {
8486
- method: "POST",
8487
- headers: { "Content-Type": "application/json" },
8488
- body: JSON.stringify({ refresh_token: refreshToken })
8489
- });
8490
- if (response.ok) {
8491
- const tokens = await response.json();
8492
- this.authManager.storage.setAccessToken(tokens.access_token);
8493
- this.authManager.storage.setRefreshToken(tokens.refresh_token);
8494
- const expiresInMs = _RaisinClient.expiresAtToMs(tokens.expires_at) - Date.now() - 5 * 60 * 1e3;
8495
- if (expiresInMs > 0) {
8496
- this.scheduleAutoRefresh(expiresInMs);
8497
- }
8498
- logger.info("[initSession] Token refreshed successfully");
8499
- } else {
8500
- logger.warn("[initSession] Token refresh failed, clearing session");
8501
- this.authManager.clear();
8502
- return null;
8503
- }
8504
- } catch (err) {
8505
- logger.warn("[initSession] Token refresh error:", err);
8506
- this.authManager.clear();
8507
- return null;
8508
- }
8509
- } else {
8577
+ if (!this.authManager.storage.getRefreshToken()) {
8510
8578
  logger.warn("[initSession] No refresh token, clearing session");
8511
8579
  this.authManager.clear();
8512
8580
  return null;
8513
8581
  }
8582
+ const refreshed = await this.refreshToken();
8583
+ if (!refreshed) {
8584
+ logger.warn("[initSession] Token refresh failed, clearing session");
8585
+ this.authManager.clear();
8586
+ return null;
8587
+ }
8588
+ logger.info("[initSession] Token refreshed successfully");
8514
8589
  }
8515
8590
  }
8516
8591
  try {
@@ -8600,6 +8675,16 @@ var _RaisinClient = class _RaisinClient extends import_events4.EventEmitter {
8600
8675
  * @throws Error if no refresh token is stored or refresh fails
8601
8676
  */
8602
8677
  async refreshToken() {
8678
+ if (this._refreshInFlight) {
8679
+ logger.debug("[refreshToken] Refresh already in flight, awaiting it");
8680
+ return this._refreshInFlight;
8681
+ }
8682
+ this._refreshInFlight = this._refreshToken().finally(() => {
8683
+ this._refreshInFlight = null;
8684
+ });
8685
+ return this._refreshInFlight;
8686
+ }
8687
+ async _refreshToken() {
8603
8688
  const refreshToken = this.authManager.storage.getRefreshToken();
8604
8689
  if (!refreshToken) {
8605
8690
  logger.warn("[refreshToken] No refresh token available");
@@ -8616,6 +8701,11 @@ var _RaisinClient = class _RaisinClient extends import_events4.EventEmitter {
8616
8701
  if (!response.ok) {
8617
8702
  const errorText = await response.text();
8618
8703
  logger.error("[refreshToken] Refresh failed:", response.status, errorText);
8704
+ if (/TOKEN_REUSE_DETECTED|TOKEN_FAMILY_MISMATCH/.test(errorText)) {
8705
+ logger.error(
8706
+ "[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."
8707
+ );
8708
+ }
8619
8709
  if (response.status === 401 || response.status === 403) {
8620
8710
  this.authManager.clear();
8621
8711
  this._currentUser = null;
@@ -9896,6 +9986,15 @@ function parsePlanTasks(rawTasks) {
9896
9986
  };
9897
9987
  }).filter((task) => task !== null);
9898
9988
  }
9989
+ var TERMINAL_TASK_STATUSES = /* @__PURE__ */ new Set(["completed", "cancelled"]);
9990
+ var TERMINAL_PLAN_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
9991
+ function setPlanStatus(plan, nextStatus) {
9992
+ if (!nextStatus) return;
9993
+ if (TERMINAL_PLAN_STATUSES.has(plan.status) && !TERMINAL_PLAN_STATUSES.has(nextStatus)) {
9994
+ return;
9995
+ }
9996
+ plan.status = nextStatus;
9997
+ }
9899
9998
  function upsertTask(plan, nextTask) {
9900
9999
  const existingIndex = plan.tasks.findIndex(
9901
10000
  (task) => nextTask.taskId && task.taskId === nextTask.taskId || !nextTask.taskId && task.title === nextTask.title
@@ -9904,8 +10003,12 @@ function upsertTask(plan, nextTask) {
9904
10003
  plan.tasks.push(nextTask);
9905
10004
  return;
9906
10005
  }
10006
+ const existing = plan.tasks[existingIndex];
10007
+ if (TERMINAL_TASK_STATUSES.has(existing.status) && !TERMINAL_TASK_STATUSES.has(nextTask.status)) {
10008
+ return;
10009
+ }
9907
10010
  plan.tasks[existingIndex] = {
9908
- ...plan.tasks[existingIndex],
10011
+ ...existing,
9909
10012
  ...nextTask
9910
10013
  };
9911
10014
  }
@@ -9949,7 +10052,7 @@ function projectPlansFromMessages(messages) {
9949
10052
  plan.planPath = planPath ?? plan.planPath;
9950
10053
  plan.planId = planId ?? plan.planId;
9951
10054
  plan.title = asString(data.title) || plan.title;
9952
- plan.status = asString(data.status) || plan.status;
10055
+ setPlanStatus(plan, asString(data.status));
9953
10056
  plan.requiresApproval = Boolean(data.requires_approval) || plan.status === "pending_approval";
9954
10057
  plan.sourceMessagePath = message.path ?? plan.sourceMessagePath;
9955
10058
  const parsedTasks = parsePlanTasks(data.tasks);
@@ -9965,7 +10068,7 @@ function projectPlansFromMessages(messages) {
9965
10068
  const plan = ensurePlan(plans, key, "Plan", timestamp);
9966
10069
  plan.planPath = planPath ?? plan.planPath;
9967
10070
  plan.planId = planId ?? plan.planId;
9968
- plan.status = asString(data.plan_status) || plan.status;
10071
+ setPlanStatus(plan, asString(data.plan_status));
9969
10072
  plan.requiresApproval = plan.status === "pending_approval";
9970
10073
  const taskUpdate = {
9971
10074
  taskId: asString(data.task_id),
@@ -9992,6 +10095,12 @@ function projectPlansFromMessages(messages) {
9992
10095
  }
9993
10096
  }
9994
10097
  }
10098
+ for (const plan of plans.values()) {
10099
+ if (!TERMINAL_PLAN_STATUSES.has(plan.status) && plan.tasks.length > 0 && plan.tasks.every((task) => TERMINAL_TASK_STATUSES.has(task.status))) {
10100
+ plan.status = "completed";
10101
+ plan.requiresApproval = false;
10102
+ }
10103
+ }
9995
10104
  return [...plans.values()].sort((a, b) => {
9996
10105
  const aTime = Date.parse(a.updatedAt || "");
9997
10106
  const bTime = Date.parse(b.updatedAt || "");
@@ -11952,6 +12061,7 @@ function createRaisinVue(vue) {
11952
12061
  ResponseStatus,
11953
12062
  RetryBuilder,
11954
12063
  SSEClient,
12064
+ SchedulerApi,
11955
12065
  SqlQuery,
11956
12066
  Tags,
11957
12067
  Transaction,