@eventsdk/sdk 0.0.0-stage → 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/LICENSE +201 -0
- package/NOTICE +9 -0
- package/dist/compatibility-http/bridge/receive.d.ts +3 -0
- package/dist/compatibility-http/bridge/types.d.ts +44 -0
- package/dist/compatibility-http/index.d.ts +4 -0
- package/dist/compatibility-http/index.js +1 -0
- package/dist/compatibility-http/policy/validate-policy.d.ts +3 -0
- package/dist/conformance/admission/harness.d.ts +20 -0
- package/dist/conformance/admission/run-suite.d.ts +2 -0
- package/dist/conformance/consumer/harness.d.ts +24 -0
- package/dist/conformance/consumer/run-apply-suite.d.ts +2 -0
- package/dist/conformance/consumer/run-worker-suite.d.ts +2 -0
- package/dist/conformance/event-link/harness.d.ts +13 -0
- package/dist/conformance/event-link/run-suite.d.ts +2 -0
- package/dist/conformance/fanout/harness.d.ts +39 -0
- package/dist/conformance/fanout/run-suite.d.ts +2 -0
- package/dist/conformance/gap/harness.d.ts +19 -0
- package/dist/conformance/gap/run-suite.d.ts +2 -0
- package/dist/conformance/index.d.ts +22 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/producer/harness.d.ts +21 -0
- package/dist/conformance/producer/run-suite.d.ts +2 -0
- package/dist/conformance/receipt/harness.d.ts +12 -0
- package/dist/conformance/receipt/projection-harness.d.ts +9 -0
- package/dist/conformance/receipt/run-projection-suite.d.ts +2 -0
- package/dist/conformance/receipt/run-suite.d.ts +2 -0
- package/dist/conformance/reliability/checks.d.ts +4 -0
- package/dist/conformance/result/harness.d.ts +15 -0
- package/dist/conformance/result/run-suite.d.ts +2 -0
- package/dist/conformance/version/compatibility.d.ts +13 -0
- package/dist/contracts/canonical/canonical-json.d.ts +1 -0
- package/dist/contracts/contract-types.d.ts +34 -0
- package/dist/contracts/generated/business-receipt.d.ts +21 -0
- package/dist/contracts/generated/cloud-event-context.d.ts +32 -0
- package/dist/contracts/generated/cloud-event-fanout.d.ts +33 -0
- package/dist/contracts/generated/cloud-event.d.ts +24 -0
- package/dist/contracts/generated/event-link-authorization-request.d.ts +22 -0
- package/dist/contracts/generated/event-link-proposal.d.ts +27 -0
- package/dist/contracts/generated/event-link-token-request.d.ts +7 -0
- package/dist/contracts/generated/event-origin-claims.d.ts +13 -0
- package/dist/contracts/generated/exchange-grant.d.ts +11 -0
- package/dist/contracts/generated/exchange-registration.d.ts +24 -0
- package/dist/contracts/generated/fanout-event-draft.d.ts +28 -0
- package/dist/contracts/generated/gap-baseline.d.ts +18 -0
- package/dist/contracts/generated/gap-recovery-command.d.ts +7 -0
- package/dist/contracts/generated/identity-context.d.ts +15 -0
- package/dist/contracts/generated/namespaced-reference.d.ts +4 -0
- package/dist/contracts/generated/native-event-catalog.d.ts +19 -0
- package/dist/contracts/generated/node-connection-profile.d.ts +217 -0
- package/dist/contracts/generated/node-worker-observation.d.ts +7 -0
- package/dist/contracts/generated/outbox-recovery-command.d.ts +8 -0
- package/dist/contracts/generated/portable-event-link-authorization-request.d.ts +98 -0
- package/dist/contracts/generated/portable-event-link-proposal.d.ts +121 -0
- package/dist/contracts/generated/portable-event-link-token-request.d.ts +34 -0
- package/dist/contracts/generated/portable-exchange-registration.d.ts +109 -0
- package/dist/contracts/generated/portable-gap-baseline.d.ts +93 -0
- package/dist/contracts/generated/portable-gap-recovery-command.d.ts +35 -0
- package/dist/contracts/generated/portable-outbox-recovery-command.d.ts +37 -0
- package/dist/contracts/generated/public-jwks-snapshot.d.ts +141 -0
- package/dist/contracts/generated/result-ref.d.ts +8 -0
- package/dist/contracts/generated/supported-profiles.d.ts +3 -0
- package/dist/contracts/generated/tenant-connection.d.ts +13 -0
- package/dist/contracts/generated/tenant-context.d.ts +4 -0
- package/dist/contracts/index.d.ts +31 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/validation/contract-error.d.ts +16 -0
- package/dist/contracts/validation/contracts.d.ts +316 -0
- package/dist/contracts/validation/decode-cloud-event.d.ts +2 -0
- package/dist/contracts/validation/event-link.d.ts +9 -0
- package/dist/contracts/validation/identity-context.d.ts +3 -0
- package/dist/contracts/validation/origin-proof-wire.d.ts +3 -0
- package/dist/contracts/validation/strict-json.d.ts +1 -0
- package/dist/core/inbox/accept-delivery.d.ts +26 -0
- package/dist/core/inbox/apply-delivery.d.ts +29 -0
- package/dist/core/inbox/domain-apply-result.d.ts +13 -0
- package/dist/core/inbox/inbox-worker.d.ts +2 -0
- package/dist/core/inbox/read-result.d.ts +12 -0
- package/dist/core/inbox/worker-types.d.ts +21 -0
- package/dist/core/index.d.ts +50 -0
- package/dist/core/index.js +1 -0
- package/dist/core/outbox/authorize-recovery.d.ts +75 -0
- package/dist/core/outbox/outbox-relay.d.ts +26 -0
- package/dist/core/outbox/record-event.d.ts +10 -0
- package/dist/core/outbox/record-fanout.d.ts +16 -0
- package/dist/core/ports/dead-letter.d.ts +29 -0
- package/dist/core/ports/inbox.d.ts +43 -0
- package/dist/core/ports/observability.d.ts +21 -0
- package/dist/core/ports/origin-refresh.d.ts +5 -0
- package/dist/core/ports/outbox.d.ts +46 -0
- package/dist/core/ports/result-reader.d.ts +14 -0
- package/dist/core/ports/transport.d.ts +13 -0
- package/dist/core/receipt/receipt-state.d.ts +3 -0
- package/dist/core/recovery/event-log.d.ts +28 -0
- package/dist/core/recovery/gap-baseline-binding.d.ts +2 -0
- package/dist/core/recovery/gap-recovery.d.ts +15 -0
- package/dist/core/recovery/receipt-identity-recovery.d.ts +8 -0
- package/dist/core/recovery/receipt-recovery.d.ts +14 -0
- package/dist/core/recovery/replay-dead-letter.d.ts +4 -0
- package/dist/core/runtime/dependencies.d.ts +19 -0
- package/dist/core/runtime/errors.d.ts +6 -0
- package/dist/core/runtime/event-identity.d.ts +14 -0
- package/dist/core/runtime/exchange-connection.d.ts +7 -0
- package/dist/core/runtime/fanout-identity.d.ts +6 -0
- package/dist/core/runtime/lease.d.ts +6 -0
- package/dist/core/runtime/observe-health.d.ts +3 -0
- package/dist/core/runtime/operation.d.ts +2 -0
- package/dist/core/runtime/retry.d.ts +14 -0
- package/dist/event-link/errors.d.ts +5 -0
- package/dist/event-link/exchange.d.ts +9 -0
- package/dist/event-link/index.d.ts +12 -0
- package/dist/event-link/index.js +1 -0
- package/dist/event-link/primitives.d.ts +10 -0
- package/dist/event-link/protocol.d.ts +21 -0
- package/dist/event-link/receiver-ports.d.ts +42 -0
- package/dist/event-link/receiver.d.ts +18 -0
- package/dist/event-link/registration.d.ts +21 -0
- package/dist/event-link/sender.d.ts +22 -0
- package/dist/identity-contracts/authorization/authorization-port.d.ts +35 -0
- package/dist/identity-contracts/index.d.ts +2 -0
- package/dist/identity-contracts/index.js +0 -0
- package/dist/identity-contracts/origin/verified-origin.d.ts +28 -0
- package/dist/identity-verifier/index.d.ts +6 -0
- package/dist/identity-verifier/index.js +1 -0
- package/dist/identity-verifier/jwt/service-token-verifier.d.ts +15 -0
- package/dist/identity-verifier/origin/event-origin-policy.d.ts +36 -0
- package/dist/identity-verifier/origin/event-origin-signer.d.ts +6 -0
- package/dist/identity-verifier/origin/event-origin-verifier.d.ts +6 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +22 -0
- package/dist/node-config/configuration-error.d.ts +4 -0
- package/dist/node-config/diagnostics/check-configuration.d.ts +40 -0
- package/dist/node-config/identity/load-identity.d.ts +14 -0
- package/dist/node-config/identity/local-recovery-origin.d.ts +3 -0
- package/dist/node-config/identity/public-identity.d.ts +87 -0
- package/dist/node-config/identity/public-snapshot.d.ts +2 -0
- package/dist/node-config/identity/signing-identity.d.ts +5 -0
- package/dist/node-config/index.d.ts +12 -0
- package/dist/node-config/index.js +1 -0
- package/dist/node-config/main.js +3 -0
- package/dist/node-config/operations/export-own-public.d.ts +8 -0
- package/dist/node-config/operations/refresh-trust.d.ts +10 -0
- package/dist/node-config/profile/load-profile.d.ts +6 -0
- package/dist/node-config/profile/validate-profile.d.ts +2 -0
- package/dist/node-worker/index.d.ts +3 -0
- package/dist/node-worker/index.js +1 -0
- package/dist/node-worker/lifecycle.d.ts +19 -0
- package/dist/node-worker/route-scheduler.d.ts +17 -0
- package/dist/node-worker/session.d.ts +15 -0
- package/dist/provisioner/application/apply.d.ts +11 -0
- package/dist/provisioner/application/ports.d.ts +44 -0
- package/dist/provisioner/application/verify.d.ts +7 -0
- package/dist/provisioner/cli/arguments.d.ts +9 -0
- package/dist/provisioner/cli/live-command.d.ts +7 -0
- package/dist/provisioner/cli/main.js +2 -0
- package/dist/provisioner/cli/run.d.ts +2 -0
- package/dist/provisioner/cli/session-types.d.ts +26 -0
- package/dist/provisioner/conformance/policy.d.ts +9 -0
- package/dist/provisioner/index.d.ts +17 -0
- package/dist/provisioner/index.js +1 -0
- package/dist/provisioner/manifest/types.d.ts +55 -0
- package/dist/provisioner/manifest/validate.d.ts +3 -0
- package/dist/provisioner/nats/inspector.d.ts +13 -0
- package/dist/provisioner/nats/types.d.ts +38 -0
- package/dist/provisioner/nats/writer-types.d.ts +11 -0
- package/dist/provisioner/nats/writer.d.ts +18 -0
- package/dist/provisioner/planning/digest.d.ts +1 -0
- package/dist/provisioner/planning/plan.d.ts +18 -0
- package/dist/transport-nats/connection/delivery-session.d.ts +10 -0
- package/dist/transport-nats/connection/verified-connection.d.ts +12 -0
- package/dist/transport-nats/consume/delivery-handler.d.ts +34 -0
- package/dist/transport-nats/consume/nats-consumer.d.ts +18 -0
- package/dist/transport-nats/index.d.ts +12 -0
- package/dist/transport-nats/index.js +3 -0
- package/dist/transport-nats/publish/nats-publisher.d.ts +24 -0
- package/dist/transport-nats/transport-error.d.ts +5 -0
- package/licenses/NATS-LICENSE +201 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { SupportedMessagingProfile } from '@eventsdk/sdk/contracts';
|
|
2
|
+
interface ResourceBase {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly owner: string;
|
|
5
|
+
readonly deploymentDomainRef: string;
|
|
6
|
+
readonly subjects: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export interface StreamResourceConfig extends ResourceBase {
|
|
9
|
+
readonly kind: 'stream';
|
|
10
|
+
readonly retentionSeconds: number;
|
|
11
|
+
readonly replicas: number;
|
|
12
|
+
readonly maxBytes: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ConsumerResourceConfig extends ResourceBase {
|
|
15
|
+
readonly kind: 'consumer';
|
|
16
|
+
readonly stream: string;
|
|
17
|
+
readonly ackWaitSeconds: number;
|
|
18
|
+
readonly maxAckPending: number;
|
|
19
|
+
}
|
|
20
|
+
export type ResourceConfig = StreamResourceConfig | ConsumerResourceConfig;
|
|
21
|
+
export interface CapabilityManifest {
|
|
22
|
+
readonly messagingProfile: SupportedMessagingProfile;
|
|
23
|
+
readonly service: string;
|
|
24
|
+
readonly emits: readonly {
|
|
25
|
+
readonly type: string;
|
|
26
|
+
readonly subject: string;
|
|
27
|
+
}[];
|
|
28
|
+
readonly consumes: readonly {
|
|
29
|
+
readonly fromService: string;
|
|
30
|
+
readonly type: string;
|
|
31
|
+
readonly consumerRef: string;
|
|
32
|
+
readonly subject: string;
|
|
33
|
+
}[];
|
|
34
|
+
readonly transport: {
|
|
35
|
+
readonly kind: 'nats-jetstream';
|
|
36
|
+
readonly deploymentDomainRef: string;
|
|
37
|
+
};
|
|
38
|
+
readonly durability: {
|
|
39
|
+
readonly outbox: 'owner-domain-transaction' | 'native-event-log' | 'not-applicable';
|
|
40
|
+
readonly inbox: 'owner-durable' | 'not-applicable';
|
|
41
|
+
};
|
|
42
|
+
readonly resources: readonly ResourceConfig[];
|
|
43
|
+
}
|
|
44
|
+
export interface ResourceSnapshot {
|
|
45
|
+
readonly config: ResourceConfig;
|
|
46
|
+
readonly nativeConfigDigest?: string;
|
|
47
|
+
readonly messages?: number;
|
|
48
|
+
readonly bytes?: number;
|
|
49
|
+
readonly consumerPending?: number;
|
|
50
|
+
}
|
|
51
|
+
export declare class ProvisionerError extends Error {
|
|
52
|
+
readonly code: string;
|
|
53
|
+
constructor(code: string, message: string);
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JetStreamManager } from '@nats-io/jetstream';
|
|
2
|
+
import type { BrokerReadPort } from '../application/ports.js';
|
|
3
|
+
import type { ResourceSnapshot } from '../manifest/types.js';
|
|
4
|
+
import type { NatsInspectionOptions, NatsInspectionStatus } from './types.js';
|
|
5
|
+
export declare class NatsReadOnlyInspector implements BrokerReadPort {
|
|
6
|
+
private readonly manager;
|
|
7
|
+
private readonly options;
|
|
8
|
+
constructor(manager: JetStreamManager, options: NatsInspectionOptions);
|
|
9
|
+
read(signal: AbortSignal): Promise<readonly ResourceSnapshot[]>;
|
|
10
|
+
status(signal: AbortSignal): Promise<NatsInspectionStatus>;
|
|
11
|
+
private account;
|
|
12
|
+
private resource;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface InspectResource {
|
|
2
|
+
readonly kind: 'stream' | 'consumer';
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly stream?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NatsInspectionOptions {
|
|
7
|
+
readonly deploymentDomainRef: string;
|
|
8
|
+
readonly expectedNatsDomain: string | null;
|
|
9
|
+
readonly resources: readonly InspectResource[];
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface NatsResourceStatus {
|
|
13
|
+
readonly kind: 'stream' | 'consumer';
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly stream: string;
|
|
16
|
+
readonly owner: string | null;
|
|
17
|
+
readonly deploymentDomainRef: string | null;
|
|
18
|
+
readonly messages: number;
|
|
19
|
+
readonly bytes: number;
|
|
20
|
+
readonly firstSequence: number;
|
|
21
|
+
readonly lastSequence: number;
|
|
22
|
+
readonly pending: number;
|
|
23
|
+
readonly ackPending: number;
|
|
24
|
+
readonly ackFloor: number | null;
|
|
25
|
+
readonly nativeConfigDigest: string;
|
|
26
|
+
}
|
|
27
|
+
export interface NatsInspectionStatus {
|
|
28
|
+
readonly mode: 'LIVE_READ_ONLY';
|
|
29
|
+
readonly natsDomain: string | null;
|
|
30
|
+
readonly accountIdentity: 'AUTHENTICATED_CONNECTION_NOT_EXPOSED_BY_JS_API';
|
|
31
|
+
readonly storageBytes: number;
|
|
32
|
+
readonly memoryBytes: number;
|
|
33
|
+
readonly maxStorageBytes: number;
|
|
34
|
+
readonly maxMemoryBytes: number;
|
|
35
|
+
readonly streamCount: number;
|
|
36
|
+
readonly consumerCount: number;
|
|
37
|
+
readonly resources: readonly NatsResourceStatus[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DeploymentAuthorization } from '../application/ports.js';
|
|
2
|
+
import type { NatsInspectionOptions } from './types.js';
|
|
3
|
+
export interface NatsExclusiveAccess {
|
|
4
|
+
readonly mode: 'exclusive-session';
|
|
5
|
+
readonly policyRef: string;
|
|
6
|
+
assertHeld(signal: AbortSignal): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface NatsWriterOptions extends NatsInspectionOptions {
|
|
9
|
+
readonly authorization: DeploymentAuthorization;
|
|
10
|
+
readonly exclusiveAccess: NatsExclusiveAccess;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JetStreamManager } from '@nats-io/jetstream';
|
|
2
|
+
import type { BrokerManagementPort, ManagementLease } from '../application/ports.js';
|
|
3
|
+
import type { ResourceConfig, ResourceSnapshot } from '../manifest/types.js';
|
|
4
|
+
import type { NatsWriterOptions } from './writer-types.js';
|
|
5
|
+
import type { NatsInspectionStatus } from './types.js';
|
|
6
|
+
export declare class NatsExclusiveWriter implements BrokerManagementPort {
|
|
7
|
+
#private;
|
|
8
|
+
private readonly manager;
|
|
9
|
+
constructor(manager: JetStreamManager, options: NatsWriterOptions);
|
|
10
|
+
read(signal: AbortSignal): Promise<readonly ResourceSnapshot[]>;
|
|
11
|
+
status(signal: AbortSignal): Promise<NatsInspectionStatus>;
|
|
12
|
+
acquireLease(domain: string, signal: AbortSignal): Promise<ManagementLease>;
|
|
13
|
+
create(config: ResourceConfig, lease: ManagementLease, signal: AbortSignal): Promise<void>;
|
|
14
|
+
update(config: ResourceConfig, expectedDigest: string, lease: ManagementLease, signal: AbortSignal): Promise<void>;
|
|
15
|
+
private mutate;
|
|
16
|
+
private validateObservation;
|
|
17
|
+
private authorize;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function digest(value: unknown): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CapabilityManifest, ResourceConfig, ResourceSnapshot } from '../manifest/types.js';
|
|
2
|
+
export type OperationKind = 'NOOP' | 'CREATE' | 'SAFE_UPDATE' | 'BLOCKED';
|
|
3
|
+
export interface PlanOperation {
|
|
4
|
+
readonly action: OperationKind;
|
|
5
|
+
readonly resource: ResourceConfig;
|
|
6
|
+
readonly beforeDigest: string | null;
|
|
7
|
+
readonly reason: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ProvisioningPlan {
|
|
10
|
+
readonly manifestDigest: string;
|
|
11
|
+
readonly observedConfigDigest: string;
|
|
12
|
+
readonly planRef: string;
|
|
13
|
+
readonly operations: readonly PlanOperation[];
|
|
14
|
+
}
|
|
15
|
+
export declare function resourceKey(r: ResourceConfig): string;
|
|
16
|
+
export declare function configurationDigest(observed: readonly ResourceSnapshot[]): string;
|
|
17
|
+
export declare function planProvisioning(input: unknown, observed: readonly ResourceSnapshot[]): ProvisioningPlan;
|
|
18
|
+
export declare function desiredResources(manifest: CapabilityManifest): readonly ResourceConfig[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type VerifiedNatsOptions } from './verified-connection.js';
|
|
2
|
+
import { NatsPublisher, type NatsPublisherOptions } from '../publish/nats-publisher.js';
|
|
3
|
+
import { NatsConsumer, type NatsConsumerOptions } from '../consume/nats-consumer.js';
|
|
4
|
+
export declare function openNatsDeliverySession(options: VerifiedNatsOptions): Promise<{
|
|
5
|
+
isClosed: () => boolean;
|
|
6
|
+
close: () => Promise<void>;
|
|
7
|
+
publisher: (config: NatsPublisherOptions) => NatsPublisher;
|
|
8
|
+
consumer(stream: string, config: NatsConsumerOptions, signal: AbortSignal): Promise<NatsConsumer>;
|
|
9
|
+
}>;
|
|
10
|
+
export type NatsDeliverySession = Awaited<ReturnType<typeof openNatsDeliverySession>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Authenticator, NatsConnection } from '@nats-io/nats-core';
|
|
2
|
+
export interface VerifiedNatsOptions {
|
|
3
|
+
serverUrl: string;
|
|
4
|
+
expectedDnsName: string;
|
|
5
|
+
timeoutMs: number;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
caPem?: string;
|
|
8
|
+
authenticator?: Authenticator;
|
|
9
|
+
}
|
|
10
|
+
export declare function validateVerifiedNatsOptions(options: VerifiedNatsOptions): void;
|
|
11
|
+
export declare function connectVerifiedNats(input: VerifiedNatsOptions): Promise<NatsConnection>;
|
|
12
|
+
export declare function requireTransportPatch(capability: unknown): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JsMsg } from '@nats-io/jetstream';
|
|
2
|
+
export interface NatsDelivery {
|
|
3
|
+
event: unknown;
|
|
4
|
+
deliveryRef: string;
|
|
5
|
+
subject: string;
|
|
6
|
+
stream: string;
|
|
7
|
+
streamSequence: number;
|
|
8
|
+
redelivered: boolean;
|
|
9
|
+
contentType: string;
|
|
10
|
+
originProof?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface DurableAcceptance {
|
|
13
|
+
kind: 'RECEIVED' | 'DUPLICATE' | 'REJECTED' | 'QUARANTINED';
|
|
14
|
+
}
|
|
15
|
+
export type AcceptDelivery = (delivery: NatsDelivery, signal: AbortSignal) => Promise<DurableAcceptance>;
|
|
16
|
+
export interface InvalidWireMetadata {
|
|
17
|
+
deliveryRef: string;
|
|
18
|
+
stream: string;
|
|
19
|
+
streamSequence: number;
|
|
20
|
+
reason: 'INVALID_WIRE_MESSAGE';
|
|
21
|
+
}
|
|
22
|
+
export type QuarantineInvalidWire = (metadata: InvalidWireMetadata, signal: AbortSignal) => Promise<{
|
|
23
|
+
kind: 'QUARANTINED';
|
|
24
|
+
}>;
|
|
25
|
+
export interface HandlerOptions {
|
|
26
|
+
deploymentDomainRef: string;
|
|
27
|
+
timeoutMs: number;
|
|
28
|
+
maxPayloadBytes: number;
|
|
29
|
+
retryDelayMs: number;
|
|
30
|
+
quarantineInvalidWire?: QuarantineInvalidWire;
|
|
31
|
+
}
|
|
32
|
+
export declare function decodeDelivery(message: JsMsg, maximum: number, deploymentDomainRef: string): NatsDelivery;
|
|
33
|
+
export declare function persistThenAck(message: JsMsg, accept: AcceptDelivery, options: HandlerOptions, signal: AbortSignal): Promise<void>;
|
|
34
|
+
export declare function validateDeploymentDomainRef(value: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Consumer } from '@nats-io/jetstream';
|
|
2
|
+
import { type AcceptDelivery, type HandlerOptions } from './delivery-handler.js';
|
|
3
|
+
export interface NatsConsumerOptions extends HandlerOptions {
|
|
4
|
+
batchSize: number;
|
|
5
|
+
fetchExpiresMs: number;
|
|
6
|
+
consumerName: string;
|
|
7
|
+
expectedStream?: string;
|
|
8
|
+
expectedSubject?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class NatsConsumer {
|
|
11
|
+
private readonly consumer;
|
|
12
|
+
private readonly options;
|
|
13
|
+
private consuming;
|
|
14
|
+
constructor(consumer: Consumer, options: NatsConsumerOptions);
|
|
15
|
+
verify(signal: AbortSignal): Promise<void>;
|
|
16
|
+
consumeBatch(accept: AcceptDelivery, signal: AbortSignal): Promise<number>;
|
|
17
|
+
private processBatch;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { NatsPublisher, natsMessageId, validatePublishSubject } from './publish/nats-publisher.js';
|
|
2
|
+
export type { NatsPublisherOptions } from './publish/nats-publisher.js';
|
|
3
|
+
export { NatsConsumer } from './consume/nats-consumer.js';
|
|
4
|
+
export type { NatsConsumerOptions } from './consume/nats-consumer.js';
|
|
5
|
+
export { decodeDelivery, persistThenAck } from './consume/delivery-handler.js';
|
|
6
|
+
export type { NatsDelivery, DurableAcceptance, AcceptDelivery, HandlerOptions, InvalidWireMetadata, QuarantineInvalidWire, } from './consume/delivery-handler.js';
|
|
7
|
+
export { NatsTransportError } from './transport-error.js';
|
|
8
|
+
export type { NatsTransportCode } from './transport-error.js';
|
|
9
|
+
export { connectVerifiedNats, validateVerifiedNatsOptions, } from './connection/verified-connection.js';
|
|
10
|
+
export type { VerifiedNatsOptions } from './connection/verified-connection.js';
|
|
11
|
+
export { credsAuthenticator, nkeyAuthenticator } from '@nats-io/nats-core';
|
|
12
|
+
export { openNatsDeliverySession, type NatsDeliverySession, } from './connection/delivery-session.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! Includes NATS transport modified for bounded initial socket cleanup; see NOTICE and licenses/NATS-LICENSE. */
|
|
2
|
+
import { createRequire as eventSdkCreateRequire } from "node:module"; const require = eventSdkCreateRequire(import.meta.url);
|
|
3
|
+
var J=Object.create;var A=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var a=(r,e)=>A(r,"name",{value:e,configurable:!0}),N=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var E=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var X=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Q(e))!Y.call(r,o)&&o!==t&&A(r,o,{get:()=>e[o],enumerable:!(i=$(e,o))||i.enumerable});return r};var Z=(r,e,t)=>(t=r!=null?J(K(r)):{},X(e||!r||!r.__esModule?A(t,"default",{value:r,enumerable:!0}):t,r));var b=E(y=>{"use strict";var de=y&&y.__createBinding||(Object.create?(function(r,e,t,i){i===void 0&&(i=t);var o=Object.getOwnPropertyDescriptor(e,t);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:a(function(){return e[t]},"get")}),Object.defineProperty(r,i,o)}):(function(r,e,t,i){i===void 0&&(i=t),r[i]=e[t]})),ue=y&&y.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&de(e,r,t)};Object.defineProperty(y,"__esModule",{value:!0});ue(N("@nats-io/nats-core/internal"),y)});var j=E(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.version=void 0;I.version="3.4.0"});var U=E(p=>{"use strict";var he=p&&p.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(p,"__esModule",{value:!0});p.NodeTransport=p.VERSION=void 0;p.nodeResolveHost=Ee;var l=b(),fe=N("node:net"),O=N("node:tls"),pe=N("node:path"),L=N("node:fs"),me=he(N("node:dns")),ye=j();p.VERSION=ye.version;var Ne="nats.js",S=class{static{a(this,"NodeTransport")}socket;version;lang;yields=[];signal=(0,l.deferred)();closedNotification=(0,l.deferred)();options;connected=!1;tlsName="";done=!1;closeError;constructor(){this.lang=Ne,this.version=p.VERSION}async connect(e,t){if(this.done)throw this.closeError||new l.errors.ConnectionError("connection closed during initialization");this.tlsName=e.tlsName,this.options=t;let{tls:i}=this.options,{handshakeFirst:o}=i||{};try{if(o===!0?this.socket=await this.tlsFirst(e):this.socket=await this.dial(e),this.done)throw this.socket?.destroy(),this.closeError||new l.errors.ConnectionError("connection closed during initialization");let s=await this.peekInfo();(0,l.checkOptions)(s,t);let{tls_required:n,tls_available:d}=s,u=d===!0&&t.tls!==null;if(!o&&(n||u)&&(this.socket=await this.startTLS()),this.done)throw this.socket?.destroy(),this.closeError||new l.errors.ConnectionError("connection closed during initialization");if(n&&this.socket.encrypted!==!0)throw l.errors.InvalidArgumentError.format("tls","is not available on this server");return this.connected=!0,this.setupHandlers(),this.signal.resolve(),Promise.resolve()}catch(s){let n=s;n||(n=new l.errors.ConnectionError("error connecting - node provided an undefined error"));let{code:d}=n,u=d==="ECONNREFUSED"?new l.errors.ConnectionError("connection refused",{cause:n}):n;throw this.socket?.destroy(),u}}dial(e){let t=(0,l.deferred)(),i,o=(0,fe.createConnection)(e.port,e.hostname,()=>{t.resolve(o),o.removeAllListeners()});return this.socket=o,o.on("error",s=>{i=s}),o.on("close",()=>{o.removeAllListeners(),t.reject(i)}),o.setNoDelay(!0),t}get isClosed(){return this.done}close(e){return this._closed(e,!1)}peekInfo(){let e=(0,l.deferred)(),t;return this.socket.on("data",i=>{this.yields.push(i);let o=l.DataBuffer.concat(...this.yields),s=(0,l.extractProtocolMessage)(o);if(s!=="")try{let n=l.INFO.exec(s);if(!n)throw new Error("unexpected response from server");let d=JSON.parse(n[1]);e.resolve(d)}catch(n){e.reject(n)}finally{this.socket.removeAllListeners()}}),this.socket.on("error",i=>{t=i}),this.socket.on("close",()=>{this.socket.removeAllListeners(),e.reject(t)}),e}loadFile(e){if(!e)return Promise.resolve();let t=(0,l.deferred)();try{e=(0,pe.resolve)(e),(0,L.existsSync)(e)||t.reject(new Error(`${e} doesn't exist`)),(0,L.readFile)(e,(i,o)=>{if(i)return t.reject(i);t.resolve(o)})}catch(i){t.reject(i)}return t}async loadClientCerts(){let e={},{certFile:t,cert:i,caFile:o,ca:s,keyFile:n,key:d}=this.options.tls;try{if(t){let u=await this.loadFile(t);u&&(e.cert=u)}else i&&(e.cert=i);if(n){let u=await this.loadFile(n);u&&(e.key=u)}else d&&(e.key=d);if(o){let u=await this.loadFile(o);u&&(e.ca=[u])}else s&&(e.ca=s);return Promise.resolve(e)}catch(u){return Promise.reject(u)}}async tlsFirst(e){let t,i={servername:this.tlsName,rejectUnauthorized:!0};if(this.socket&&(i.socket=this.socket),typeof this.options.tls=="object")try{let s=await this.loadClientCerts()||{};i=(0,l.extend)(i,this.options.tls,s)}catch(s){return Promise.reject(new l.errors.ConnectionError(s.message,{cause:s}))}let o=(0,l.deferred)();try{if(this.done)throw this.closeError||new l.errors.ConnectionError("connection closed during initialization");let s=(0,O.connect)(e.port,e.hostname,i,()=>{s.removeAllListeners(),o.resolve(s)});this.socket=s,s.on("error",n=>{t=n}),s.on("secureConnect",()=>{if(i.rejectUnauthorized!==!1&&!s.authorized)throw s.authorizationError}),s.on("close",()=>{o.reject(t),s.removeAllListeners()}),s.setNoDelay(!0)}catch(s){o.reject(new l.errors.ConnectionError(s.message,{cause:s}))}return o}async startTLS(){let e,t={socket:this.socket,servername:this.tlsName,rejectUnauthorized:!0};if(typeof this.options.tls=="object")try{let o=await this.loadClientCerts()||{};t=(0,l.extend)(t,this.options.tls,o)}catch(o){return Promise.reject(new l.errors.ConnectionError(o.message,{cause:o}))}let i=(0,l.deferred)();try{if(this.done)throw this.closeError||new l.errors.ConnectionError("connection closed during initialization");let o=(0,O.connect)(t,()=>{o.removeAllListeners(),i.resolve(o)});this.socket=o,o.on("error",s=>{e=s}),o.on("secureConnect",()=>{if(t.rejectUnauthorized!==!1&&!o.authorized)throw o.authorizationError}),o.on("close",()=>{i.reject(e),o.removeAllListeners()})}catch(o){i.reject(new l.errors.ConnectionError(o.message,{cause:o}))}return i}setupHandlers(){let e;this.socket.on("data",t=>(this.yields.push(t),this.signal.resolve())),this.socket.on("error",t=>{e=t}),this.socket.on("end",()=>{this.socket?.destroyed||this.socket?.write(new Uint8Array(0),()=>{this.socket?.end()})}),this.socket.on("close",()=>{this._closed(e,!1)})}[Symbol.asyncIterator](){return this.iterate()}async*iterate(){for(;;){this.yields.length===0&&await this.signal;let e=this.yields;this.yields=[];for(let t=0;t<e.length;t++)this.options.debug&&console.info(`> ${(0,l.render)(e[t])}`),yield e[t];if(this.done)break;this.yields.length===0&&(e.length=0,this.yields=e,this.signal=(0,l.deferred)())}}discard(){if(this.done=!0,this.socket)try{this.socket.removeAllListeners(),this.socket.destroy()}catch{}}disconnect(){this._closed(void 0,!0).then().catch()}isEncrypted(){return this.socket instanceof O.TLSSocket}_send(e){if(this.isClosed||this.socket===void 0)return Promise.resolve();this.options.debug&&console.info(`< ${(0,l.render)(e)}`);let t=(0,l.deferred)();try{this.socket.write(e,i=>i?(this.options.debug&&console.error(`!!! ${(0,l.render)(e)}: ${i}`),t.reject(i)):t.resolve())}catch(i){this.options.debug&&console.error(`!!! ${(0,l.render)(e)}: ${i}`),t.reject(i)}return t}send(e){this._send(e).catch(i=>{})}async _closed(e,t=!0){if(!this.connected){this.done=!0,this.closeError=e,this.socket?.destroy(),this.closedNotification.resolve(e);return}if(this.done){this.socket?.destroy();return}if(this.closeError=e,!e&&this.socket&&t)try{await this._send(new TextEncoder().encode(""))}catch(i){this.options.debug&&console.log("transport close terminated with an error",i)}try{this.socket&&(this.socket.removeAllListeners(),this.socket?.destroy(),this.socket=void 0)}catch(i){console.log(i)}this.done=!0,this.closedNotification.resolve(this.closeError)}closed(){return this.closedNotification}};p.NodeTransport=S;function Ee(r){let e=(0,l.deferred)();return me.default.lookup(r,{all:!0},(t,i)=>{if(t){e.reject(t);return}let o=[];for(let s of i)o.push(s.address);o.length===0&&o.push(r),e.resolve(o)}),e}a(Ee,"nodeResolveHost")});var G=E(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.connect=ve;var F=U(),V=b(),q=b();function ve(r={}){return(0,q.hasWsProtocol)(r)?Promise.reject(q.errors.InvalidArgumentError.format("servers","node client doesn't support websockets, use the 'wsconnect' function instead")):((0,V.setTransportFactory)({factory:a(()=>new F.NodeTransport,"factory"),dnsResolveFn:F.nodeResolveHost}),V.NatsConnectionImpl.connect(r))}a(ve,"connect")});var B=E(m=>{"use strict";var _e=m&&m.__createBinding||(Object.create?(function(r,e,t,i){i===void 0&&(i=t);var o=Object.getOwnPropertyDescriptor(e,t);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:a(function(){return e[t]},"get")}),Object.defineProperty(r,i,o)}):(function(r,e,t,i){i===void 0&&(i=t),r[i]=e[t]})),be=m&&m.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&_e(e,r,t)};Object.defineProperty(m,"__esModule",{value:!0});m.eventSdkInitialClosePatch="eventsdk-initial-close-v1";m.connect=void 0;var we=G();Object.defineProperty(m,"connect",{enumerable:!0,get:a(function(){return we.connect},"get")});be(b(),m)});var z=E((at,W)=>{"use strict";W.exports=B()});import{createHash as R}from"node:crypto";import{headers as ee}from"@nats-io/nats-core";import{assertDeliveryIdentity as te}from"@eventsdk/sdk/core";import{canonicalJson as re,parseCloudEvent as oe,EVENTSDK_ORIGIN_PROOF_HEADER as ie,isEventOriginProofWireForm as se}from"@eventsdk/sdk/contracts";var c=class extends Error{constructor(t){super(t);this.code=t;this.name="NatsTransportError"}code;static{a(this,"NatsTransportError")}};function h(r,e=Number.MAX_SAFE_INTEGER){if(!Number.isSafeInteger(r)||r<1||r>e)throw new c("INVALID_TRANSPORT_CONFIG")}a(h,"positiveInteger");async function f(r,e,t){e.throwIfAborted(),h(t);let i,o,s=new Promise((n,d)=>{o=a(()=>d(new c("TRANSPORT_ABORTED")),"abort"),e.addEventListener("abort",o,{once:!0}),i=setTimeout(()=>d(new c("TRANSPORT_TIMEOUT")),t)});try{return await Promise.race([r,s])}finally{i!==void 0&&clearTimeout(i),o!==void 0&&e.removeEventListener("abort",o)}}a(f,"bounded");function D(r){let e=r.deliveryid===void 0?`${r.source}\0${r.id}`:re(["eventsdk-delivery-message/1",r.source,r.id,r.deliveryid]);return R("sha256").update(e).digest("hex")}a(D,"natsMessageId");function k(r){if(!/^[^\s.*>]+(?:\.[^\s.*>]+)*$/u.test(r)||[...r].some(e=>e.charCodeAt(0)<32))throw new c("INVALID_TRANSPORT_CONFIG")}a(k,"validatePublishSubject");var v=class{constructor(e,t){this.client=e;if(this.options={...t},t.replicationMode==="mirror"&&t.expectedStream!==void 0)throw new c("UNSUPPORTED_TOPOLOGY_COMBINATION");k(t.subject),h(t.timeoutMs),h(t.maxPayloadBytes)}client;static{a(this,"NatsPublisher")}options;async publish(e,t){e=structuredClone(e),t={...t},t.signal.throwIfAborted(),oe(e),await te(e,{sha256:a(async n=>R("sha256").update(n).digest("hex"),"sha256")}),t.signal.throwIfAborted();let i=D(e);if(t.messageId!==i)throw new c("INVALID_TRANSPORT_CONFIG");let o=new TextEncoder().encode(JSON.stringify(e));if(o.byteLength>this.options.maxPayloadBytes)throw new c("INVALID_WIRE_MESSAGE");let s=ee();if(s.set("Content-Type","application/cloudevents+json"),this.options.originProof){let n=AbortSignal.any([t.signal,AbortSignal.timeout(this.options.timeoutMs)]),d=await f(this.options.originProof(structuredClone(e),n),n,this.options.timeoutMs);if(!se(d))throw new c("INVALID_WIRE_MESSAGE");s.set(ie,d),t.signal.throwIfAborted()}try{let n=await f(this.client.publish(this.options.subject,o,{msgID:i,headers:s,timeout:this.options.timeoutMs,retries:0,...this.options.expectedStream?{expect:{streamName:this.options.expectedStream}}:{}}),t.signal,this.options.timeoutMs);if(this.options.expectedStream!==void 0&&n.stream!==this.options.expectedStream)throw new c("PUBLISH_UNKNOWN");return{stream:n.stream,sequence:n.seq,duplicate:n.duplicate}}catch{throw new c("PUBLISH_UNKNOWN")}}};import{AckPolicy as le}from"@nats-io/jetstream";import{decodeCloudEvent as ne,EVENTSDK_ORIGIN_PROOF_HEADER as x,isEventOriginProofWireForm as ae}from"@eventsdk/sdk/contracts";function M(r,e,t){w(t);let i=r.headers?.get("Content-Type")??"",o=r.headers?.get(x);if((r.headers?.values(x).length??0)>1)throw new c("INVALID_WIRE_MESSAGE");if(o&&!ae(o))throw new c("INVALID_WIRE_MESSAGE");if(i!=="application/cloudevents+json"||r.data.byteLength>e)throw new c("INVALID_WIRE_MESSAGE");let s;try{s=ne(r.data)}catch{throw new c("INVALID_WIRE_MESSAGE")}return{event:s,contentType:i,subject:r.subject,stream:r.info.stream,streamSequence:r.info.streamSequence,deliveryRef:JSON.stringify([t,r.info.domain,r.info.stream,r.info.streamSequence]),redelivered:r.redelivered,...o?{originProof:o}:{}}}a(M,"decodeDelivery");async function g(r,e,t,i){i.throwIfAborted(),w(t.deploymentDomainRef);let o=AbortSignal.timeout(t.timeoutMs),s=AbortSignal.any([i,o]);try{let n=await f(ce(r,e,t,s),s,t.timeoutMs);if(!["RECEIVED","DUPLICATE","REJECTED","QUARANTINED"].includes(n.kind))throw new c("DURABLE_ACCEPTANCE_REQUIRED");s.throwIfAborted(),r.ack()}catch(n){throw r.nak(t.retryDelayMs),n}}a(g,"persistThenAck");async function ce(r,e,t,i){let o;try{o=M(r,t.maxPayloadBytes,t.deploymentDomainRef)}catch(s){if(!t.quarantineInvalidWire)throw s;return t.quarantineInvalidWire({deliveryRef:JSON.stringify([t.deploymentDomainRef,r.info.domain,r.info.stream,r.info.streamSequence]),stream:r.info.stream,streamSequence:r.info.streamSequence,reason:"INVALID_WIRE_MESSAGE"},i)}return e(o,i)}a(ce,"resolveAcceptance");function w(r){if(typeof r!="string"||r.trim()!==r||r.length<1||r.length>256)throw new c("INVALID_TRANSPORT_CONFIG")}a(w,"validateDeploymentDomainRef");var _=class{constructor(e,t){this.consumer=e;if(this.options={...t},w(t.deploymentDomainRef),h(t.batchSize,1e3),h(t.fetchExpiresMs),h(t.timeoutMs),h(t.maxPayloadBytes),h(t.retryDelayMs),!t.consumerName)throw new c("INVALID_CONSUMER_CONFIG")}consumer;static{a(this,"NatsConsumer")}options;consuming=!1;async verify(e){e.throwIfAborted();let t=await f(this.consumer.info(!1),e,this.options.timeoutMs);if(t.config.durable_name!==this.options.consumerName||t.config.ack_policy!==le.Explicit||t.config.deliver_subject!==void 0||this.options.expectedStream!==void 0&&t.stream_name!==this.options.expectedStream||this.options.expectedSubject!==void 0&&(t.config.filter_subject!==this.options.expectedSubject||(t.config.filter_subjects?.length??0)>0)||(t.config.ack_wait??0)<=this.options.timeoutMs*this.options.batchSize*1e6||(t.config.max_ack_pending??0)<this.options.batchSize)throw new c("INVALID_CONSUMER_CONFIG")}async consumeBatch(e,t){if(this.consuming)throw new c("INVALID_CONSUMER_CONFIG");this.consuming=!0;try{await this.verify(t),t.throwIfAborted();let i=this.consumer.fetch({max_messages:this.options.batchSize,expires:this.options.fetchExpiresMs}),o;try{o=await f(i,t,this.options.timeoutMs)}catch(s){throw i.then(n=>n.close(),()=>{}),s}return await this.processBatch(o,e,t)}finally{this.consuming=!1}}async processBatch(e,t,i){let o=a(()=>{e.close()},"stop");i.addEventListener("abort",o,{once:!0});let s=0;try{i.throwIfAborted();for await(let n of e)await g(n,t,this.options,i),s+=1;return i.throwIfAborted(),s}finally{i.removeEventListener("abort",o),await e.close()}}};var T=Z(z(),1);import{isIP as Ie}from"node:net";function H(r){h(r.timeoutMs,6e4);let e;try{e=new URL(r.serverUrl)}catch{throw new c("TLS_CONFIGURATION_REJECTED")}let t=r.expectedDnsName;if(typeof t!="string")throw new c("TLS_CONFIGURATION_REJECTED");let i=t.split(".");if(e.protocol!=="tls:"||e.username||e.password||e.search||e.hash||e.pathname!==""&&e.pathname!=="/"||Ie(e.hostname.replace(/^\[|\]$/gu,""))||t!==t.toLowerCase()||t!==e.hostname||t.length>253||i.some(o=>!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u.test(o))||r.caPem!==void 0&&!r.caPem.includes("-----BEGIN CERTIFICATE-----"))throw new c("TLS_CONFIGURATION_REJECTED")}a(H,"validateVerifiedNatsOptions");async function C(r){let e={...r};H(e),e.signal.throwIfAborted(),Ae(T.eventSdkInitialClosePatch);let i=T.connect({servers:e.serverUrl,tls:{rejectUnauthorized:!0,...e.caPem?{ca:e.caPem}:{}},timeout:e.timeoutMs,ignoreClusterUpdates:!0,reconnect:!1,resolve:!1,...e.authenticator?{authenticator:e.authenticator}:{}});try{let o=await f(i,e.signal,e.timeoutMs);if(e.signal.aborted)throw await o.close(),new c("TRANSPORT_ABORTED");return o}catch(o){throw i.then(s=>s.close(),()=>{}),o instanceof c?o:new c("TLS_CONNECTION_FAILED")}}a(C,"connectVerifiedNats");function Ae(r){if(r!=="eventsdk-initial-close-v1")throw new c("TRANSPORT_PATCH_REQUIRED")}a(Ae,"requireTransportPatch");import{credsAuthenticator as St,nkeyAuthenticator as Pt}from"@nats-io/nats-core";import{jetstream as ge}from"@nats-io/jetstream";async function Oe(r){let e=await C(r),t=ge(e);return{isClosed:a(()=>e.isClosed(),"isClosed"),close:a(()=>e.close(),"close"),publisher:a(i=>new v(t,i),"publisher"),async consumer(i,o,s){let n=new _(await f(t.consumers.get(i,o.consumerName),s,o.timeoutMs),o);return await n.verify(s),n}}}a(Oe,"openNatsDeliverySession");export{_ as NatsConsumer,v as NatsPublisher,c as NatsTransportError,C as connectVerifiedNats,St as credsAuthenticator,M as decodeDelivery,D as natsMessageId,Pt as nkeyAuthenticator,Oe as openNatsDeliverySession,g as persistThenAck,k as validatePublishSubject,H as validateVerifiedNatsOptions};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JetStreamClient } from '@nats-io/jetstream';
|
|
2
|
+
import { type CloudEvent } from '@eventsdk/sdk/contracts';
|
|
3
|
+
import type { PublishPort, PublishAck } from '@eventsdk/sdk/core';
|
|
4
|
+
export interface NatsPublisherOptions {
|
|
5
|
+
subject: string;
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
maxPayloadBytes: number;
|
|
8
|
+
expectedStream?: string;
|
|
9
|
+
replicationMode?: 'direct' | 'source' | 'mirror';
|
|
10
|
+
originProof?: (event: CloudEvent, signal: AbortSignal) => Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function natsMessageId(event: Pick<CloudEvent, 'source' | 'id'> & {
|
|
13
|
+
readonly deliveryid?: string;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function validatePublishSubject(subject: string): void;
|
|
16
|
+
export declare class NatsPublisher implements PublishPort {
|
|
17
|
+
private readonly client;
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(client: Pick<JetStreamClient, 'publish'>, options: NatsPublisherOptions);
|
|
20
|
+
publish(event: CloudEvent, context: {
|
|
21
|
+
messageId: string;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
}): Promise<PublishAck>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type NatsTransportCode = 'INVALID_TRANSPORT_CONFIG' | 'TRANSPORT_PATCH_REQUIRED' | 'TLS_CONFIGURATION_REJECTED' | 'TLS_CONNECTION_FAILED' | 'UNSUPPORTED_TOPOLOGY_COMBINATION' | 'TRANSPORT_ABORTED' | 'TRANSPORT_TIMEOUT' | 'PUBLISH_UNKNOWN' | 'INVALID_WIRE_MESSAGE' | 'DURABLE_ACCEPTANCE_REQUIRED' | 'INVALID_CONSUMER_CONFIG';
|
|
2
|
+
export declare class NatsTransportError extends Error {
|
|
3
|
+
readonly code: NatsTransportCode;
|
|
4
|
+
constructor(code: NatsTransportCode);
|
|
5
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2013-2018 The NATS Authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventsdk/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24 <25"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./contracts": {
|
|
16
|
+
"types": "./dist/contracts/index.d.ts",
|
|
17
|
+
"import": "./dist/contracts/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./identity-contracts": {
|
|
20
|
+
"types": "./dist/identity-contracts/index.d.ts",
|
|
21
|
+
"import": "./dist/identity-contracts/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./core": {
|
|
24
|
+
"types": "./dist/core/index.d.ts",
|
|
25
|
+
"import": "./dist/core/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./transport-nats": {
|
|
28
|
+
"types": "./dist/transport-nats/index.d.ts",
|
|
29
|
+
"import": "./dist/transport-nats/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./identity-verifier": {
|
|
32
|
+
"types": "./dist/identity-verifier/index.d.ts",
|
|
33
|
+
"import": "./dist/identity-verifier/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./compatibility-http": {
|
|
36
|
+
"types": "./dist/compatibility-http/index.d.ts",
|
|
37
|
+
"import": "./dist/compatibility-http/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./provisioner": {
|
|
40
|
+
"types": "./dist/provisioner/index.d.ts",
|
|
41
|
+
"import": "./dist/provisioner/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./conformance": {
|
|
44
|
+
"types": "./dist/conformance/index.d.ts",
|
|
45
|
+
"import": "./dist/conformance/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./node-config": {
|
|
48
|
+
"types": "./dist/node-config/index.d.ts",
|
|
49
|
+
"import": "./dist/node-config/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./node-worker": {
|
|
52
|
+
"types": "./dist/node-worker/index.d.ts",
|
|
53
|
+
"import": "./dist/node-worker/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./event-link": {
|
|
56
|
+
"types": "./dist/event-link/index.d.ts",
|
|
57
|
+
"import": "./dist/event-link/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"bin": {
|
|
61
|
+
"eventsdk-provisioner": "./dist/provisioner/cli/main.js",
|
|
62
|
+
"eventsdk-config": "./dist/node-config/main.js"
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist/**/*.js",
|
|
66
|
+
"dist/**/*.d.ts",
|
|
67
|
+
"LICENSE",
|
|
68
|
+
"NOTICE",
|
|
69
|
+
"licenses/*"
|
|
70
|
+
],
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public",
|
|
73
|
+
"registry": "https://registry.npmjs.org/"
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"ajv": "8.20.0",
|
|
77
|
+
"ajv-formats": "3.0.1",
|
|
78
|
+
"@nats-io/jetstream": "3.4.0",
|
|
79
|
+
"@nats-io/nats-core": "3.4.0",
|
|
80
|
+
"jose": "6.2.15"
|
|
81
|
+
}
|
|
6
82
|
}
|
package/README.md
DELETED