@particle-academy/fancy-connector-core 0.10.1 → 0.11.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
@@ -2282,6 +2282,50 @@ type MimeMessage = {
2282
2282
  };
2283
2283
  declare function parseMime(raw: Uint8Array | string): MimeMessage;
2284
2284
 
2285
+ /**
2286
+ * A form-encoded body whose one named field holds JSON, decoded: the payload
2287
+ * TRANSFORM Slack's interactivity callbacks need (`payload=<json>`).
2288
+ *
2289
+ * ONE implementation in two runtimes (`php/src/FormFieldJson.php` is the
2290
+ * twin), held to the authored corpus under `fixtures/form-field-json/`. It
2291
+ * runs AFTER signature verification, over the same raw bytes: the provider
2292
+ * signed the form body as sent, so nothing here may be re-encoded before
2293
+ * verifying.
2294
+ *
2295
+ * The decisions, each pinned by a case:
2296
+ *
2297
+ * - `+` and `%20` are both a space; `%XX` decodes to a byte, and the result
2298
+ * must be valid UTF-8.
2299
+ * - The WHOLE body is decoded strictly. A `%` not followed by two hex digits,
2300
+ * anywhere, is `bad-encoding`. `decodeURIComponent` throws on `%zz` while
2301
+ * PHP's `urldecode` keeps it, so neither built-in is used.
2302
+ * - The field absent is `missing-field`; present twice is `duplicate-field`,
2303
+ * because first-wins and last-wins are both conventions and two runtimes
2304
+ * choosing differently would route one click two ways.
2305
+ * - A value that is not JSON is `not-json`, never the raw string.
2306
+ */
2307
+ declare const FORM_FIELD_JSON_REASONS: readonly ["missing-field", "duplicate-field", "bad-encoding", "not-json"];
2308
+ type FormFieldJsonReason = (typeof FORM_FIELD_JSON_REASONS)[number];
2309
+ /** Refused BY NAME; `reason` is the same string PHP's exception carries. */
2310
+ declare class FormFieldJsonError extends Error {
2311
+ readonly reason: FormFieldJsonReason;
2312
+ readonly field: string;
2313
+ constructor(reason: FormFieldJsonReason, field: string, message: string);
2314
+ }
2315
+ declare function decodeFormFieldJson(raw: Uint8Array | string, field: string): unknown;
2316
+ /**
2317
+ * How a verified delivery is read, when its body is not plain JSON. Declared
2318
+ * on the trigger (`TriggerDescriptor.decode`); a host verifies the raw bytes,
2319
+ * then calls `decodeDelivery` with the declaration, then starts the run.
2320
+ * Shipped as data too, for a host mirroring the union across a JSON boundary.
2321
+ */
2322
+ declare const DELIVERY_DECODE_KINDS: readonly ["form-field-json"];
2323
+ type DeliveryDecode = {
2324
+ kind: (typeof DELIVERY_DECODE_KINDS)[number];
2325
+ field: string;
2326
+ };
2327
+ declare function decodeDelivery(decode: DeliveryDecode, raw: Uint8Array | string): unknown;
2328
+
2285
2329
  /**
2286
2330
  * Dry-verify — proving the transport with a credential that cannot work.
2287
2331
  *
@@ -2604,6 +2648,13 @@ type TriggerDescriptor = {
2604
2648
  lease?: LeaseDeclaration;
2605
2649
  /** For `webhook` / `subscription`: how a delivery is authenticated. */
2606
2650
  verification?: WebhookVerificationSpec;
2651
+ /**
2652
+ * For `webhook`: how the VERIFIED body is read when it is not plain JSON —
2653
+ * Slack's interactivity is `payload=<json>`. Absent means the host reads the
2654
+ * body as it always has. Present means the host calls `decodeDelivery` with
2655
+ * it, over the same raw bytes the signature was checked against.
2656
+ */
2657
+ decode?: DeliveryDecode;
2607
2658
  /** For `poll`: the provider's smallest sane interval, in seconds. */
2608
2659
  minPollSeconds?: number;
2609
2660
  /** A faked sample event, so the node is runnable before any of the above. */
@@ -2677,4 +2728,4 @@ declare function verifyDelivery(trigger: TriggerDescriptor, delivery: InboundDel
2677
2728
  */
2678
2729
  declare function triggerEvent(trigger: TriggerDescriptor, connection: ResolvedConnection, injected: unknown, config: Record<string, unknown>): unknown;
2679
2730
 
2680
- export { AMBIGUOUS_REFUSAL, type ApiContract, type Attempt, type Attendee, type ByteRange, CANONICAL_METRICS, CONNECTOR_API_VERSION, CONNECTOR_MODES, CREDENTIAL_SCOPES, type CallOptions, type CallResult, type Capabilities, type Catalogue, type ChainLinks, type ChainOutcome, type ChainRef, type ChallengeHandshake, type Citation, type Classified, type ConnectionCredentials, type ConnectionHost, type ConnectionSpec, type Connector, ConnectorAmbiguous, ConnectorApiMismatch, ConnectorAuthError, ConnectorConfigError, ConnectorError, type ConnectorErrorContext, type ConnectorFaker, ConnectorIdempotencyExpiredError, type ConnectorMode, ConnectorModeError, ConnectorRateLimited, type ConnectorRequest, ConnectorRequestError, type ConnectorResult, ConnectorTransient, ConnectorUnreachable, type ContractOperation, type CredentialField, type CredentialScope, DEFAULT_IDEMPOTENCY_WINDOW_SECONDS, DEFAULT_RETRY, type DeliveryDeclaration, type DeliveryMechanism, type DeliveryOutcome, type DriftFinding, type DriftReport, EXPIRES_AT_UNITS, type ExpiresAtUnit, FAKE_EPOCH, type FailureKind, type FakeRequest, type FakeValues, type HmacScheme, type HmacVerificationSpec, type HostEnvironment, type IdempotencyOptions, type InboundDelivery, type Invite, type InviteMethod, type JoinTarget, type JoinTargetKind, type LeaseAction, type LeaseDeclaration, type LeaseState, MAX_IDEMPOTENCY_KEY_LENGTH, type MetricDescriptor, type MetricSample, type MimeAttachment, type MimeHeader, type MimeMessage, type MimePart, type ModeInputs, NO_IDEMPOTENCY_KEY_WARNING, PROBLEM_SEVERITIES, type PreparedRequest, type ProbeOutcome, type ProbeReport, type ProbeResult, type ProbeSpec, type Problem, type ProviderAdapter, RENDERER_VERSION, REVIEW_STALE_DAYS, type RecordedShape, type RecurrenceRule, type RenderRules, type RenderedPayload, type RequestedMode, type ResolveOptions, type ResolvedConnection, type RetryPolicy, type RunIdentity, SANDBOX_KINDS, SUPPORTED_CONNECTOR_API, type SandboxKind, type Segment, type ServiceDescriptor, type SetupStep, type ShapeMismatch, type SharedTokenScheme, type SharedTokenVerificationSpec, type SpecSource, type SubscriptionLease, type TextUnit, type Transport, type TransportResponse, type TriggerDescriptor, type VerifyResult, type WebhookVerification, type WebhookVerificationSpec, assertConnectorApi, byteRangeOf, callConnector, capabilityProblems, checkAgainstOpenApi, checkAgainstRecordedShape, classifyError, classifyHttp, classifyStatus, classifyThrown, compareShape, connectionsFor, constantTimeEquals, deliver, fakeRequest, fakeValues, getConnectionHost, graphemes, handshakeResponse, header, hmac, httpFailure, idempotencyKeyFor, isEmptyPayload, isRemote, isSharedTokenScheme, isSharedTokenSpec, isUnconditionallyRetryable, joinTargets, leaseAction, leaseFromResponse, leaseRenewAt, leaseState, linkRanges, measure, nextOccurrence, parseInvite, parseMime, payloadHash, postChain, probe, providerProblems, providerSandboxIsSelectable, registerConnectionHost, registerTransport, render, reported, resetRateState, resolveConnection, resolveConnectorMode, respectRate, runIdentityFrom, runKeyFrom, runProbes, sandboxIsSelectable, sandboxRefusal, satisfiesMinimum, secretKeyBytes, seedFrom, shapeOf, shouldRetry, sliceByteRange, splitToFit, subscriptionLease, triggerEvent, unchecked, utf8Length, verifyDelivery, verifyHmac, verifySharedToken, withResolvedLimit };
2731
+ export { AMBIGUOUS_REFUSAL, type ApiContract, type Attempt, type Attendee, type ByteRange, CANONICAL_METRICS, CONNECTOR_API_VERSION, CONNECTOR_MODES, CREDENTIAL_SCOPES, type CallOptions, type CallResult, type Capabilities, type Catalogue, type ChainLinks, type ChainOutcome, type ChainRef, type ChallengeHandshake, type Citation, type Classified, type ConnectionCredentials, type ConnectionHost, type ConnectionSpec, type Connector, ConnectorAmbiguous, ConnectorApiMismatch, ConnectorAuthError, ConnectorConfigError, ConnectorError, type ConnectorErrorContext, type ConnectorFaker, ConnectorIdempotencyExpiredError, type ConnectorMode, ConnectorModeError, ConnectorRateLimited, type ConnectorRequest, ConnectorRequestError, type ConnectorResult, ConnectorTransient, ConnectorUnreachable, type ContractOperation, type CredentialField, type CredentialScope, DEFAULT_IDEMPOTENCY_WINDOW_SECONDS, DEFAULT_RETRY, DELIVERY_DECODE_KINDS, type DeliveryDeclaration, type DeliveryDecode, type DeliveryMechanism, type DeliveryOutcome, type DriftFinding, type DriftReport, EXPIRES_AT_UNITS, type ExpiresAtUnit, FAKE_EPOCH, FORM_FIELD_JSON_REASONS, type FailureKind, type FakeRequest, type FakeValues, FormFieldJsonError, type FormFieldJsonReason, type HmacScheme, type HmacVerificationSpec, type HostEnvironment, type IdempotencyOptions, type InboundDelivery, type Invite, type InviteMethod, type JoinTarget, type JoinTargetKind, type LeaseAction, type LeaseDeclaration, type LeaseState, MAX_IDEMPOTENCY_KEY_LENGTH, type MetricDescriptor, type MetricSample, type MimeAttachment, type MimeHeader, type MimeMessage, type MimePart, type ModeInputs, NO_IDEMPOTENCY_KEY_WARNING, PROBLEM_SEVERITIES, type PreparedRequest, type ProbeOutcome, type ProbeReport, type ProbeResult, type ProbeSpec, type Problem, type ProviderAdapter, RENDERER_VERSION, REVIEW_STALE_DAYS, type RecordedShape, type RecurrenceRule, type RenderRules, type RenderedPayload, type RequestedMode, type ResolveOptions, type ResolvedConnection, type RetryPolicy, type RunIdentity, SANDBOX_KINDS, SUPPORTED_CONNECTOR_API, type SandboxKind, type Segment, type ServiceDescriptor, type SetupStep, type ShapeMismatch, type SharedTokenScheme, type SharedTokenVerificationSpec, type SpecSource, type SubscriptionLease, type TextUnit, type Transport, type TransportResponse, type TriggerDescriptor, type VerifyResult, type WebhookVerification, type WebhookVerificationSpec, assertConnectorApi, byteRangeOf, callConnector, capabilityProblems, checkAgainstOpenApi, checkAgainstRecordedShape, classifyError, classifyHttp, classifyStatus, classifyThrown, compareShape, connectionsFor, constantTimeEquals, decodeDelivery, decodeFormFieldJson, deliver, fakeRequest, fakeValues, getConnectionHost, graphemes, handshakeResponse, header, hmac, httpFailure, idempotencyKeyFor, isEmptyPayload, isRemote, isSharedTokenScheme, isSharedTokenSpec, isUnconditionallyRetryable, joinTargets, leaseAction, leaseFromResponse, leaseRenewAt, leaseState, linkRanges, measure, nextOccurrence, parseInvite, parseMime, payloadHash, postChain, probe, providerProblems, providerSandboxIsSelectable, registerConnectionHost, registerTransport, render, reported, resetRateState, resolveConnection, resolveConnectorMode, respectRate, runIdentityFrom, runKeyFrom, runProbes, sandboxIsSelectable, sandboxRefusal, satisfiesMinimum, secretKeyBytes, seedFrom, shapeOf, shouldRetry, sliceByteRange, splitToFit, subscriptionLease, triggerEvent, unchecked, utf8Length, verifyDelivery, verifyHmac, verifySharedToken, withResolvedLimit };
package/dist/index.d.ts CHANGED
@@ -2282,6 +2282,50 @@ type MimeMessage = {
2282
2282
  };
2283
2283
  declare function parseMime(raw: Uint8Array | string): MimeMessage;
2284
2284
 
2285
+ /**
2286
+ * A form-encoded body whose one named field holds JSON, decoded: the payload
2287
+ * TRANSFORM Slack's interactivity callbacks need (`payload=<json>`).
2288
+ *
2289
+ * ONE implementation in two runtimes (`php/src/FormFieldJson.php` is the
2290
+ * twin), held to the authored corpus under `fixtures/form-field-json/`. It
2291
+ * runs AFTER signature verification, over the same raw bytes: the provider
2292
+ * signed the form body as sent, so nothing here may be re-encoded before
2293
+ * verifying.
2294
+ *
2295
+ * The decisions, each pinned by a case:
2296
+ *
2297
+ * - `+` and `%20` are both a space; `%XX` decodes to a byte, and the result
2298
+ * must be valid UTF-8.
2299
+ * - The WHOLE body is decoded strictly. A `%` not followed by two hex digits,
2300
+ * anywhere, is `bad-encoding`. `decodeURIComponent` throws on `%zz` while
2301
+ * PHP's `urldecode` keeps it, so neither built-in is used.
2302
+ * - The field absent is `missing-field`; present twice is `duplicate-field`,
2303
+ * because first-wins and last-wins are both conventions and two runtimes
2304
+ * choosing differently would route one click two ways.
2305
+ * - A value that is not JSON is `not-json`, never the raw string.
2306
+ */
2307
+ declare const FORM_FIELD_JSON_REASONS: readonly ["missing-field", "duplicate-field", "bad-encoding", "not-json"];
2308
+ type FormFieldJsonReason = (typeof FORM_FIELD_JSON_REASONS)[number];
2309
+ /** Refused BY NAME; `reason` is the same string PHP's exception carries. */
2310
+ declare class FormFieldJsonError extends Error {
2311
+ readonly reason: FormFieldJsonReason;
2312
+ readonly field: string;
2313
+ constructor(reason: FormFieldJsonReason, field: string, message: string);
2314
+ }
2315
+ declare function decodeFormFieldJson(raw: Uint8Array | string, field: string): unknown;
2316
+ /**
2317
+ * How a verified delivery is read, when its body is not plain JSON. Declared
2318
+ * on the trigger (`TriggerDescriptor.decode`); a host verifies the raw bytes,
2319
+ * then calls `decodeDelivery` with the declaration, then starts the run.
2320
+ * Shipped as data too, for a host mirroring the union across a JSON boundary.
2321
+ */
2322
+ declare const DELIVERY_DECODE_KINDS: readonly ["form-field-json"];
2323
+ type DeliveryDecode = {
2324
+ kind: (typeof DELIVERY_DECODE_KINDS)[number];
2325
+ field: string;
2326
+ };
2327
+ declare function decodeDelivery(decode: DeliveryDecode, raw: Uint8Array | string): unknown;
2328
+
2285
2329
  /**
2286
2330
  * Dry-verify — proving the transport with a credential that cannot work.
2287
2331
  *
@@ -2604,6 +2648,13 @@ type TriggerDescriptor = {
2604
2648
  lease?: LeaseDeclaration;
2605
2649
  /** For `webhook` / `subscription`: how a delivery is authenticated. */
2606
2650
  verification?: WebhookVerificationSpec;
2651
+ /**
2652
+ * For `webhook`: how the VERIFIED body is read when it is not plain JSON —
2653
+ * Slack's interactivity is `payload=<json>`. Absent means the host reads the
2654
+ * body as it always has. Present means the host calls `decodeDelivery` with
2655
+ * it, over the same raw bytes the signature was checked against.
2656
+ */
2657
+ decode?: DeliveryDecode;
2607
2658
  /** For `poll`: the provider's smallest sane interval, in seconds. */
2608
2659
  minPollSeconds?: number;
2609
2660
  /** A faked sample event, so the node is runnable before any of the above. */
@@ -2677,4 +2728,4 @@ declare function verifyDelivery(trigger: TriggerDescriptor, delivery: InboundDel
2677
2728
  */
2678
2729
  declare function triggerEvent(trigger: TriggerDescriptor, connection: ResolvedConnection, injected: unknown, config: Record<string, unknown>): unknown;
2679
2730
 
2680
- export { AMBIGUOUS_REFUSAL, type ApiContract, type Attempt, type Attendee, type ByteRange, CANONICAL_METRICS, CONNECTOR_API_VERSION, CONNECTOR_MODES, CREDENTIAL_SCOPES, type CallOptions, type CallResult, type Capabilities, type Catalogue, type ChainLinks, type ChainOutcome, type ChainRef, type ChallengeHandshake, type Citation, type Classified, type ConnectionCredentials, type ConnectionHost, type ConnectionSpec, type Connector, ConnectorAmbiguous, ConnectorApiMismatch, ConnectorAuthError, ConnectorConfigError, ConnectorError, type ConnectorErrorContext, type ConnectorFaker, ConnectorIdempotencyExpiredError, type ConnectorMode, ConnectorModeError, ConnectorRateLimited, type ConnectorRequest, ConnectorRequestError, type ConnectorResult, ConnectorTransient, ConnectorUnreachable, type ContractOperation, type CredentialField, type CredentialScope, DEFAULT_IDEMPOTENCY_WINDOW_SECONDS, DEFAULT_RETRY, type DeliveryDeclaration, type DeliveryMechanism, type DeliveryOutcome, type DriftFinding, type DriftReport, EXPIRES_AT_UNITS, type ExpiresAtUnit, FAKE_EPOCH, type FailureKind, type FakeRequest, type FakeValues, type HmacScheme, type HmacVerificationSpec, type HostEnvironment, type IdempotencyOptions, type InboundDelivery, type Invite, type InviteMethod, type JoinTarget, type JoinTargetKind, type LeaseAction, type LeaseDeclaration, type LeaseState, MAX_IDEMPOTENCY_KEY_LENGTH, type MetricDescriptor, type MetricSample, type MimeAttachment, type MimeHeader, type MimeMessage, type MimePart, type ModeInputs, NO_IDEMPOTENCY_KEY_WARNING, PROBLEM_SEVERITIES, type PreparedRequest, type ProbeOutcome, type ProbeReport, type ProbeResult, type ProbeSpec, type Problem, type ProviderAdapter, RENDERER_VERSION, REVIEW_STALE_DAYS, type RecordedShape, type RecurrenceRule, type RenderRules, type RenderedPayload, type RequestedMode, type ResolveOptions, type ResolvedConnection, type RetryPolicy, type RunIdentity, SANDBOX_KINDS, SUPPORTED_CONNECTOR_API, type SandboxKind, type Segment, type ServiceDescriptor, type SetupStep, type ShapeMismatch, type SharedTokenScheme, type SharedTokenVerificationSpec, type SpecSource, type SubscriptionLease, type TextUnit, type Transport, type TransportResponse, type TriggerDescriptor, type VerifyResult, type WebhookVerification, type WebhookVerificationSpec, assertConnectorApi, byteRangeOf, callConnector, capabilityProblems, checkAgainstOpenApi, checkAgainstRecordedShape, classifyError, classifyHttp, classifyStatus, classifyThrown, compareShape, connectionsFor, constantTimeEquals, deliver, fakeRequest, fakeValues, getConnectionHost, graphemes, handshakeResponse, header, hmac, httpFailure, idempotencyKeyFor, isEmptyPayload, isRemote, isSharedTokenScheme, isSharedTokenSpec, isUnconditionallyRetryable, joinTargets, leaseAction, leaseFromResponse, leaseRenewAt, leaseState, linkRanges, measure, nextOccurrence, parseInvite, parseMime, payloadHash, postChain, probe, providerProblems, providerSandboxIsSelectable, registerConnectionHost, registerTransport, render, reported, resetRateState, resolveConnection, resolveConnectorMode, respectRate, runIdentityFrom, runKeyFrom, runProbes, sandboxIsSelectable, sandboxRefusal, satisfiesMinimum, secretKeyBytes, seedFrom, shapeOf, shouldRetry, sliceByteRange, splitToFit, subscriptionLease, triggerEvent, unchecked, utf8Length, verifyDelivery, verifyHmac, verifySharedToken, withResolvedLimit };
2731
+ export { AMBIGUOUS_REFUSAL, type ApiContract, type Attempt, type Attendee, type ByteRange, CANONICAL_METRICS, CONNECTOR_API_VERSION, CONNECTOR_MODES, CREDENTIAL_SCOPES, type CallOptions, type CallResult, type Capabilities, type Catalogue, type ChainLinks, type ChainOutcome, type ChainRef, type ChallengeHandshake, type Citation, type Classified, type ConnectionCredentials, type ConnectionHost, type ConnectionSpec, type Connector, ConnectorAmbiguous, ConnectorApiMismatch, ConnectorAuthError, ConnectorConfigError, ConnectorError, type ConnectorErrorContext, type ConnectorFaker, ConnectorIdempotencyExpiredError, type ConnectorMode, ConnectorModeError, ConnectorRateLimited, type ConnectorRequest, ConnectorRequestError, type ConnectorResult, ConnectorTransient, ConnectorUnreachable, type ContractOperation, type CredentialField, type CredentialScope, DEFAULT_IDEMPOTENCY_WINDOW_SECONDS, DEFAULT_RETRY, DELIVERY_DECODE_KINDS, type DeliveryDeclaration, type DeliveryDecode, type DeliveryMechanism, type DeliveryOutcome, type DriftFinding, type DriftReport, EXPIRES_AT_UNITS, type ExpiresAtUnit, FAKE_EPOCH, FORM_FIELD_JSON_REASONS, type FailureKind, type FakeRequest, type FakeValues, FormFieldJsonError, type FormFieldJsonReason, type HmacScheme, type HmacVerificationSpec, type HostEnvironment, type IdempotencyOptions, type InboundDelivery, type Invite, type InviteMethod, type JoinTarget, type JoinTargetKind, type LeaseAction, type LeaseDeclaration, type LeaseState, MAX_IDEMPOTENCY_KEY_LENGTH, type MetricDescriptor, type MetricSample, type MimeAttachment, type MimeHeader, type MimeMessage, type MimePart, type ModeInputs, NO_IDEMPOTENCY_KEY_WARNING, PROBLEM_SEVERITIES, type PreparedRequest, type ProbeOutcome, type ProbeReport, type ProbeResult, type ProbeSpec, type Problem, type ProviderAdapter, RENDERER_VERSION, REVIEW_STALE_DAYS, type RecordedShape, type RecurrenceRule, type RenderRules, type RenderedPayload, type RequestedMode, type ResolveOptions, type ResolvedConnection, type RetryPolicy, type RunIdentity, SANDBOX_KINDS, SUPPORTED_CONNECTOR_API, type SandboxKind, type Segment, type ServiceDescriptor, type SetupStep, type ShapeMismatch, type SharedTokenScheme, type SharedTokenVerificationSpec, type SpecSource, type SubscriptionLease, type TextUnit, type Transport, type TransportResponse, type TriggerDescriptor, type VerifyResult, type WebhookVerification, type WebhookVerificationSpec, assertConnectorApi, byteRangeOf, callConnector, capabilityProblems, checkAgainstOpenApi, checkAgainstRecordedShape, classifyError, classifyHttp, classifyStatus, classifyThrown, compareShape, connectionsFor, constantTimeEquals, decodeDelivery, decodeFormFieldJson, deliver, fakeRequest, fakeValues, getConnectionHost, graphemes, handshakeResponse, header, hmac, httpFailure, idempotencyKeyFor, isEmptyPayload, isRemote, isSharedTokenScheme, isSharedTokenSpec, isUnconditionallyRetryable, joinTargets, leaseAction, leaseFromResponse, leaseRenewAt, leaseState, linkRanges, measure, nextOccurrence, parseInvite, parseMime, payloadHash, postChain, probe, providerProblems, providerSandboxIsSelectable, registerConnectionHost, registerTransport, render, reported, resetRateState, resolveConnection, resolveConnectorMode, respectRate, runIdentityFrom, runKeyFrom, runProbes, sandboxIsSelectable, sandboxRefusal, satisfiesMinimum, secretKeyBytes, seedFrom, shapeOf, shouldRetry, sliceByteRange, splitToFit, subscriptionLease, triggerEvent, unchecked, utf8Length, verifyDelivery, verifyHmac, verifySharedToken, withResolvedLimit };
package/dist/index.js CHANGED
@@ -1666,6 +1666,77 @@ function parseMime(raw) {
1666
1666
  };
1667
1667
  }
1668
1668
 
1669
+ // src/form-field-json.ts
1670
+ var FORM_FIELD_JSON_REASONS = ["missing-field", "duplicate-field", "bad-encoding", "not-json"];
1671
+ var FormFieldJsonError = class extends Error {
1672
+ constructor(reason, field, message) {
1673
+ super(message);
1674
+ this.reason = reason;
1675
+ this.field = field;
1676
+ this.name = "FormFieldJsonError";
1677
+ }
1678
+ reason;
1679
+ field;
1680
+ };
1681
+ var UTF8 = new TextDecoder("utf-8", { fatal: true });
1682
+ var HEX = /^[0-9A-Fa-f]{2}$/;
1683
+ function decodeFormFieldJson(raw, field) {
1684
+ const text = typeof raw === "string" ? raw : latin12(raw);
1685
+ const found = [];
1686
+ for (const pair of text.split("&")) {
1687
+ if (pair === "") continue;
1688
+ const eq = pair.indexOf("=");
1689
+ const name = component(eq === -1 ? pair : pair.slice(0, eq), field);
1690
+ const value2 = component(eq === -1 ? "" : pair.slice(eq + 1), field);
1691
+ if (name === field) found.push(value2);
1692
+ }
1693
+ if (found.length === 0) {
1694
+ throw new FormFieldJsonError("missing-field", field, `the body has no "${field}" field`);
1695
+ }
1696
+ if (found.length > 1) {
1697
+ throw new FormFieldJsonError("duplicate-field", field, `the body has "${field}" ${found.length} times`);
1698
+ }
1699
+ const [value] = found;
1700
+ try {
1701
+ return JSON.parse(value);
1702
+ } catch (error) {
1703
+ throw new FormFieldJsonError("not-json", field, `"${field}" is not JSON: ${error.message}`);
1704
+ }
1705
+ }
1706
+ function component(encoded, field) {
1707
+ const bytes = [];
1708
+ for (let i = 0; i < encoded.length; i++) {
1709
+ const char = encoded[i];
1710
+ if (char === "+") {
1711
+ bytes.push(32);
1712
+ } else if (char === "%") {
1713
+ const hex = encoded.slice(i + 1, i + 3);
1714
+ if (!HEX.test(hex)) {
1715
+ throw new FormFieldJsonError("bad-encoding", field, `a "%" at byte ${i} is not followed by two hex digits`);
1716
+ }
1717
+ bytes.push(parseInt(hex, 16));
1718
+ i += 2;
1719
+ } else {
1720
+ bytes.push(encoded.charCodeAt(i) & 255);
1721
+ }
1722
+ }
1723
+ try {
1724
+ return UTF8.decode(new Uint8Array(bytes));
1725
+ } catch {
1726
+ throw new FormFieldJsonError("bad-encoding", field, "the decoded bytes are not valid UTF-8");
1727
+ }
1728
+ }
1729
+ var DELIVERY_DECODE_KINDS = ["form-field-json"];
1730
+ function decodeDelivery(decode, raw) {
1731
+ if (decode.kind === "form-field-json") return decodeFormFieldJson(raw, decode.field);
1732
+ throw new Error(`unknown decode kind ${JSON.stringify(decode.kind)}`);
1733
+ }
1734
+ function latin12(bytes) {
1735
+ let out = "";
1736
+ for (const byte of bytes) out += String.fromCharCode(byte);
1737
+ return out;
1738
+ }
1739
+
1669
1740
  // src/probe.ts
1670
1741
  async function probe(spec) {
1671
1742
  let response;
@@ -2087,8 +2158,11 @@ export {
2087
2158
  ConnectorUnreachable,
2088
2159
  DEFAULT_IDEMPOTENCY_WINDOW_SECONDS,
2089
2160
  DEFAULT_RETRY,
2161
+ DELIVERY_DECODE_KINDS,
2090
2162
  EXPIRES_AT_UNITS,
2091
2163
  FAKE_EPOCH,
2164
+ FORM_FIELD_JSON_REASONS,
2165
+ FormFieldJsonError,
2092
2166
  MAX_IDEMPOTENCY_KEY_LENGTH,
2093
2167
  NO_IDEMPOTENCY_KEY_WARNING,
2094
2168
  PROBLEM_SEVERITIES,
@@ -2109,6 +2183,8 @@ export {
2109
2183
  compareShape,
2110
2184
  connectionsFor,
2111
2185
  constantTimeEquals,
2186
+ decodeDelivery,
2187
+ decodeFormFieldJson,
2112
2188
  deliver,
2113
2189
  fakeRequest,
2114
2190
  fakeValues,