@particle-academy/fancy-connector-core 0.3.0 → 0.4.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.d.cts CHANGED
@@ -814,7 +814,7 @@ type CallOptions = {
814
814
  */
815
815
  credentials?: ConnectionCredentials;
816
816
  /** Which estate to use. Resolved from the connection host when omitted. */
817
- mode?: ConnectorMode;
817
+ mode?: RequestedMode;
818
818
  /** Connection id, for the registered-host path. */
819
819
  connectionId?: string | null;
820
820
  /**
@@ -1305,6 +1305,17 @@ type IdempotencyOptions = {
1305
1305
  now?: Date;
1306
1306
  /** For the error message when a key cannot be made safe. */
1307
1307
  context?: Partial<ConnectorErrorContext>;
1308
+ /**
1309
+ * The PROVIDER'S own limit, when it declares one — `idempotencyMaxLength` in
1310
+ * the connector index. Omitted uses {@link MAX_IDEMPOTENCY_KEY_LENGTH}, which
1311
+ * is the catalogue CEILING rather than any one provider's limit.
1312
+ *
1313
+ * Discord's `discord_message` declares 25, and for years only the ceiling was
1314
+ * applied — so a legitimate engine-derived key came back at 29 characters and
1315
+ * the connector's own validation refused it, failing the run at a node the
1316
+ * host had no way to fix.
1317
+ */
1318
+ maxLength?: number | null;
1308
1319
  };
1309
1320
  /**
1310
1321
  * The idempotency key for this execution of this node, or `null`.
package/dist/index.d.ts CHANGED
@@ -814,7 +814,7 @@ type CallOptions = {
814
814
  */
815
815
  credentials?: ConnectionCredentials;
816
816
  /** Which estate to use. Resolved from the connection host when omitted. */
817
- mode?: ConnectorMode;
817
+ mode?: RequestedMode;
818
818
  /** Connection id, for the registered-host path. */
819
819
  connectionId?: string | null;
820
820
  /**
@@ -1305,6 +1305,17 @@ type IdempotencyOptions = {
1305
1305
  now?: Date;
1306
1306
  /** For the error message when a key cannot be made safe. */
1307
1307
  context?: Partial<ConnectorErrorContext>;
1308
+ /**
1309
+ * The PROVIDER'S own limit, when it declares one — `idempotencyMaxLength` in
1310
+ * the connector index. Omitted uses {@link MAX_IDEMPOTENCY_KEY_LENGTH}, which
1311
+ * is the catalogue CEILING rather than any one provider's limit.
1312
+ *
1313
+ * Discord's `discord_message` declares 25, and for years only the ceiling was
1314
+ * applied — so a legitimate engine-derived key came back at 29 characters and
1315
+ * the connector's own validation refused it, failing the run at a node the
1316
+ * host had no way to fix.
1317
+ */
1318
+ maxLength?: number | null;
1308
1319
  };
1309
1320
  /**
1310
1321
  * The idempotency key for this execution of this node, or `null`.
package/dist/index.js CHANGED
@@ -829,7 +829,7 @@ function idempotencyKeyFor(ctx, nodeId, options = {}) {
829
829
  const windowSeconds = options.windowSeconds === void 0 ? DEFAULT_IDEMPOTENCY_WINDOW_SECONDS : options.windowSeconds;
830
830
  if (!identity) {
831
831
  const runKey = runKeyFrom(ctx);
832
- return runKey === null ? null : fit(`${runKey}:${nodeId}`);
832
+ return runKey === null ? null : fit(`${runKey}:${nodeId}`, options.maxLength);
833
833
  }
834
834
  if (!identity.isReplaySafe(windowSeconds, options.now ?? /* @__PURE__ */ new Date())) {
835
835
  throw new ConnectorIdempotencyExpiredError(
@@ -841,13 +841,15 @@ function idempotencyKeyFor(ctx, nodeId, options = {}) {
841
841
  }
842
842
  );
843
843
  }
844
- return fit(identity.stepKey(nodeId, options.occurrence));
844
+ return fit(identity.stepKey(nodeId, options.occurrence), options.maxLength);
845
845
  }
846
846
  var NO_IDEMPOTENCY_KEY_WARNING = "no run identity available, so this write is being sent WITHOUT an idempotency key. A retry would repeat the effect rather than recover from it \u2014 the node is marked unsafe-to-replay, so a durable runner will give it one attempt. Durable runs supply an identity automatically; for a synchronous run, pass `run` in RunOptions.";
847
- function fit(key) {
848
- if (key.length <= MAX_IDEMPOTENCY_KEY_LENGTH) return key;
847
+ function fit(key, maxLength) {
848
+ const limit = maxLength === void 0 || maxLength === null ? MAX_IDEMPOTENCY_KEY_LENGTH : Math.max(1, Math.min(maxLength, MAX_IDEMPOTENCY_KEY_LENGTH));
849
+ if (key.length <= limit) return key;
849
850
  const digest = fnv1a(key);
850
- const head = key.slice(0, MAX_IDEMPOTENCY_KEY_LENGTH - digest.length - 1);
851
+ if (limit <= digest.length + 1) return digest.slice(0, limit);
852
+ const head = key.slice(0, limit - digest.length - 1);
851
853
  return `${head}~${digest}`;
852
854
  }
853
855
  function fnv1a(value) {