@clocknext/sdk 0.12.0 → 0.13.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.js CHANGED
@@ -326,7 +326,7 @@ function sleep(ms) {
326
326
  }
327
327
 
328
328
  // src/http.ts
329
- var SDK_VERSION = "0.12.0" ;
329
+ var SDK_VERSION = "0.13.0" ;
330
330
  var Transport = class {
331
331
  constructor(cfg) {
332
332
  this.cfg = cfg;
@@ -702,13 +702,15 @@ var Customers = class {
702
702
  // (PATCH …/:id) — there is no separate currency endpoint. Credit-type
703
703
  // assignment has no public API.
704
704
  // --- Balance adjustments -------------------------------------------------
705
- /** Grant or claw back a credit balance. `POST …/:id/credits/adjust`. */
705
+ /** Grant or claw back a credit balance. Returns the remaining balance.
706
+ * `POST …/:id/credits/adjust`. */
706
707
  async adjustCredit(id, input) {
707
- await this.transport.request({
708
+ const res = await this.transport.request({
708
709
  method: "POST",
709
710
  path: `/api/v1/customers/${encodeURIComponent(id)}/credits/adjust`,
710
711
  body: input
711
712
  });
713
+ return { remaining: res.remaining };
712
714
  }
713
715
  /** Grant or claw back an outcome balance. Returns the remaining balance. */
714
716
  async adjustOutcome(id, input) {
@@ -728,6 +730,19 @@ var Customers = class {
728
730
  });
729
731
  return { remaining: res.remaining };
730
732
  }
733
+ /**
734
+ * Grant or claw back slots on a customer's ADVANCE composite pool for the
735
+ * current billing cycle. Returns the resulting `remaining` slot count.
736
+ * `POST …/:id/composites/adjust`.
737
+ */
738
+ async adjustComposite(id, input) {
739
+ const res = await this.transport.request({
740
+ method: "POST",
741
+ path: `/api/v1/customers/${encodeURIComponent(id)}/composites/adjust`,
742
+ body: input
743
+ });
744
+ return { remaining: res.remaining };
745
+ }
731
746
  };
732
747
 
733
748
  // src/resources/invoices.ts
@@ -1013,6 +1028,7 @@ var SIGNAL_PATHS = {
1013
1028
  };
1014
1029
  var UNIT_PATH = "/api/v1/signal/unit";
1015
1030
  var COMPOSITE_COMPLETE_PATH = "/api/v1/signal/composite/complete";
1031
+ var OUTCOME_COMPLETE_PATH = "/api/v1/signal/outcome/complete";
1016
1032
  function signalToWire(signal) {
1017
1033
  const t = signal.tokens;
1018
1034
  const body = {
@@ -1033,7 +1049,6 @@ function signalToWire(signal) {
1033
1049
  }
1034
1050
  if (signal.type === "outcome") {
1035
1051
  body.runId = signal.runId;
1036
- if (signal.complete != null) body.complete = signal.complete;
1037
1052
  }
1038
1053
  if (signal.type !== "wallet" && signal.composite) {
1039
1054
  body.composite = { [signal.composite.ref]: signal.composite.value };
@@ -1103,6 +1118,48 @@ var Signals = class {
1103
1118
  outcome(input, opts) {
1104
1119
  return this.track({ ...input, type: "outcome" }, opts);
1105
1120
  }
1121
+ /**
1122
+ * Close ONE outcome run — declares the workflow finished and bills it. The
1123
+ * outcome mirror of {@link Signals.completeComposite}, on its own dedicated
1124
+ * route: `POST /api/v1/signal/outcome/complete`.
1125
+ *
1126
+ * An outcome bills per COMPLETION, never per step, and `signals.outcome()`
1127
+ * never closes one — it accepts only the step shape. Declaring the workflow
1128
+ * finished is always this separate, explicit, contentless call.
1129
+ *
1130
+ * This closes the RUN only. If a step of this run also carried a
1131
+ * `composite`, that occurrence stays open and unbilled until you separately
1132
+ * call {@link Signals.completeComposite} — the two completions are
1133
+ * independent, and neither implies the other.
1134
+ *
1135
+ * Sent immediately, never buffered. A genuinely second, independent call for
1136
+ * an already-closed run is a PERMANENT error (it would bill the run twice),
1137
+ * not a safe no-op — see {@link OutcomeCompletionResult}.
1138
+ */
1139
+ async completeOutcome(input) {
1140
+ const idempotencyKey = input.idempotencyKey ?? newKey();
1141
+ const res = await this.transport.request({
1142
+ method: "POST",
1143
+ path: OUTCOME_COMPLETE_PATH,
1144
+ idempotencyKey,
1145
+ body: {
1146
+ customerId: input.customerId,
1147
+ runId: input.runId,
1148
+ complete: true,
1149
+ ...input.member ? { member: input.member } : {},
1150
+ idempotencyKey
1151
+ },
1152
+ retry: true
1153
+ });
1154
+ const queued = res.queued === true;
1155
+ return {
1156
+ delivery: queued ? "accepted" : "recorded",
1157
+ queued,
1158
+ ...res.status != null ? { status: res.status } : {},
1159
+ usageLog: res.usageLog ?? null,
1160
+ ...handles(res)
1161
+ };
1162
+ }
1106
1163
  /**
1107
1164
  * Recent usage logs + totals for a customer. `GET /api/v1/usage`.
1108
1165
  *
@@ -1175,13 +1232,13 @@ var Signals = class {
1175
1232
  * arrive in any order and the occurrence stays open and unbilled until you
1176
1233
  * say otherwise. Put it on the line before your own `return`.
1177
1234
  *
1178
- * EVERY composite needs this, outcome-backed ones included. An outcome's own
1179
- * `complete: true` closes its RUN and nothing else — it does not close the
1180
- * composite occurrence the run was tagged into, whatever mix of credits,
1181
- * outcomes and units that composite wraps. (Earlier versions of this SDK
1182
- * documented the opposite. Believing it means the occurrence stays ONGOING
1183
- * forever and is never billed, so if you tag outcome signals with a
1184
- * `composite`, you must still call this.)
1235
+ * EVERY composite needs this, outcome-backed ones included. `completeOutcome()`
1236
+ * closes its RUN and nothing else — it does not close the composite
1237
+ * occurrence the run was tagged into, whatever mix of credits, outcomes and
1238
+ * units that composite wraps. (Earlier versions of this SDK documented the
1239
+ * opposite. Believing it means the occurrence stays ONGOING forever and is
1240
+ * never billed, so if you tag outcome signals with a `composite`, you must
1241
+ * still call this.)
1185
1242
  *
1186
1243
  * Closing twice is safe: the second call answers `ALREADY_COMPLETED` and
1187
1244
  * cannot bill again. Calling it EARLY is also safe — before every entitlement