@particle-academy/fancy-connector-core 0.10.0 → 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/CHANGELOG.md +49 -0
- package/dist/index.cjs +88 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -13
- package/dist/index.d.ts +52 -13
- package/dist/index.js +83 -1
- package/dist/index.js.map +1 -1
- package/package.json +69 -69
package/dist/index.d.cts
CHANGED
|
@@ -1653,18 +1653,6 @@ declare function byteRangeOf(text: string, charIndex: number, substring: string)
|
|
|
1653
1653
|
* exception three frames away.
|
|
1654
1654
|
*/
|
|
1655
1655
|
declare function sliceByteRange(text: string, range: ByteRange): string;
|
|
1656
|
-
/**
|
|
1657
|
-
* Bare URLs in `text`, with their UTF-8 byte ranges.
|
|
1658
|
-
*
|
|
1659
|
-
* Trailing punctuation is excluded: a link at the end of a sentence would
|
|
1660
|
-
* otherwise swallow the full stop and 404. Closing brackets go too, for the same
|
|
1661
|
-
* reason and because a URL in parentheses is common in prose.
|
|
1662
|
-
*
|
|
1663
|
-
* This is the generic half of a "link facet" — a connector maps the ranges into
|
|
1664
|
-
* whatever its provider's rich-text shape is. The package owns the offsets
|
|
1665
|
-
* because the offsets are what people get wrong; it does not own the provider's
|
|
1666
|
-
* schema, because that is the provider's.
|
|
1667
|
-
*/
|
|
1668
1656
|
declare function linkRanges(text: string): Array<ByteRange & {
|
|
1669
1657
|
url: string;
|
|
1670
1658
|
}>;
|
|
@@ -2294,6 +2282,50 @@ type MimeMessage = {
|
|
|
2294
2282
|
};
|
|
2295
2283
|
declare function parseMime(raw: Uint8Array | string): MimeMessage;
|
|
2296
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
|
+
|
|
2297
2329
|
/**
|
|
2298
2330
|
* Dry-verify — proving the transport with a credential that cannot work.
|
|
2299
2331
|
*
|
|
@@ -2616,6 +2648,13 @@ type TriggerDescriptor = {
|
|
|
2616
2648
|
lease?: LeaseDeclaration;
|
|
2617
2649
|
/** For `webhook` / `subscription`: how a delivery is authenticated. */
|
|
2618
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;
|
|
2619
2658
|
/** For `poll`: the provider's smallest sane interval, in seconds. */
|
|
2620
2659
|
minPollSeconds?: number;
|
|
2621
2660
|
/** A faked sample event, so the node is runnable before any of the above. */
|
|
@@ -2689,4 +2728,4 @@ declare function verifyDelivery(trigger: TriggerDescriptor, delivery: InboundDel
|
|
|
2689
2728
|
*/
|
|
2690
2729
|
declare function triggerEvent(trigger: TriggerDescriptor, connection: ResolvedConnection, injected: unknown, config: Record<string, unknown>): unknown;
|
|
2691
2730
|
|
|
2692
|
-
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
|
@@ -1653,18 +1653,6 @@ declare function byteRangeOf(text: string, charIndex: number, substring: string)
|
|
|
1653
1653
|
* exception three frames away.
|
|
1654
1654
|
*/
|
|
1655
1655
|
declare function sliceByteRange(text: string, range: ByteRange): string;
|
|
1656
|
-
/**
|
|
1657
|
-
* Bare URLs in `text`, with their UTF-8 byte ranges.
|
|
1658
|
-
*
|
|
1659
|
-
* Trailing punctuation is excluded: a link at the end of a sentence would
|
|
1660
|
-
* otherwise swallow the full stop and 404. Closing brackets go too, for the same
|
|
1661
|
-
* reason and because a URL in parentheses is common in prose.
|
|
1662
|
-
*
|
|
1663
|
-
* This is the generic half of a "link facet" — a connector maps the ranges into
|
|
1664
|
-
* whatever its provider's rich-text shape is. The package owns the offsets
|
|
1665
|
-
* because the offsets are what people get wrong; it does not own the provider's
|
|
1666
|
-
* schema, because that is the provider's.
|
|
1667
|
-
*/
|
|
1668
1656
|
declare function linkRanges(text: string): Array<ByteRange & {
|
|
1669
1657
|
url: string;
|
|
1670
1658
|
}>;
|
|
@@ -2294,6 +2282,50 @@ type MimeMessage = {
|
|
|
2294
2282
|
};
|
|
2295
2283
|
declare function parseMime(raw: Uint8Array | string): MimeMessage;
|
|
2296
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
|
+
|
|
2297
2329
|
/**
|
|
2298
2330
|
* Dry-verify — proving the transport with a credential that cannot work.
|
|
2299
2331
|
*
|
|
@@ -2616,6 +2648,13 @@ type TriggerDescriptor = {
|
|
|
2616
2648
|
lease?: LeaseDeclaration;
|
|
2617
2649
|
/** For `webhook` / `subscription`: how a delivery is authenticated. */
|
|
2618
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;
|
|
2619
2658
|
/** For `poll`: the provider's smallest sane interval, in seconds. */
|
|
2620
2659
|
minPollSeconds?: number;
|
|
2621
2660
|
/** A faked sample event, so the node is runnable before any of the above. */
|
|
@@ -2689,4 +2728,4 @@ declare function verifyDelivery(trigger: TriggerDescriptor, delivery: InboundDel
|
|
|
2689
2728
|
*/
|
|
2690
2729
|
declare function triggerEvent(trigger: TriggerDescriptor, connection: ResolvedConnection, injected: unknown, config: Record<string, unknown>): unknown;
|
|
2691
2730
|
|
|
2692
|
-
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;
|
|
@@ -1743,11 +1814,17 @@ function sliceByteRange(text, range) {
|
|
|
1743
1814
|
const bytes = encoder.encode(text);
|
|
1744
1815
|
return new TextDecoder().decode(bytes.slice(range.byteStart, range.byteEnd));
|
|
1745
1816
|
}
|
|
1817
|
+
var TRAILING_PUNCTUATION = /* @__PURE__ */ new Set([".", ",", ";", ":", "!", "?", ")", "]", "}", "'", '"']);
|
|
1818
|
+
function trimTrailingPunctuation(raw) {
|
|
1819
|
+
let end = raw.length;
|
|
1820
|
+
while (end > 0 && TRAILING_PUNCTUATION.has(raw[end - 1])) end -= 1;
|
|
1821
|
+
return raw.slice(0, end);
|
|
1822
|
+
}
|
|
1746
1823
|
function linkRanges(text) {
|
|
1747
1824
|
const found = [];
|
|
1748
1825
|
for (const match of text.matchAll(/https?:\/\/[^\s]+/g)) {
|
|
1749
1826
|
if (match.index === void 0) continue;
|
|
1750
|
-
const url = match[0]
|
|
1827
|
+
const url = trimTrailingPunctuation(match[0]);
|
|
1751
1828
|
found.push({ ...byteRangeOf(text, match.index, url), url });
|
|
1752
1829
|
}
|
|
1753
1830
|
return found;
|
|
@@ -2081,8 +2158,11 @@ export {
|
|
|
2081
2158
|
ConnectorUnreachable,
|
|
2082
2159
|
DEFAULT_IDEMPOTENCY_WINDOW_SECONDS,
|
|
2083
2160
|
DEFAULT_RETRY,
|
|
2161
|
+
DELIVERY_DECODE_KINDS,
|
|
2084
2162
|
EXPIRES_AT_UNITS,
|
|
2085
2163
|
FAKE_EPOCH,
|
|
2164
|
+
FORM_FIELD_JSON_REASONS,
|
|
2165
|
+
FormFieldJsonError,
|
|
2086
2166
|
MAX_IDEMPOTENCY_KEY_LENGTH,
|
|
2087
2167
|
NO_IDEMPOTENCY_KEY_WARNING,
|
|
2088
2168
|
PROBLEM_SEVERITIES,
|
|
@@ -2103,6 +2183,8 @@ export {
|
|
|
2103
2183
|
compareShape,
|
|
2104
2184
|
connectionsFor,
|
|
2105
2185
|
constantTimeEquals,
|
|
2186
|
+
decodeDelivery,
|
|
2187
|
+
decodeFormFieldJson,
|
|
2106
2188
|
deliver,
|
|
2107
2189
|
fakeRequest,
|
|
2108
2190
|
fakeValues,
|