Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nats

Package Overview
Dependencies
Maintainers
3
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nats - npm Package Compare versions

Comparing version 2.7.0-1 to 2.7.0

63

lib/nats-base-client/authenticator.d.ts
import type { ConnectionOptions } from "./types";
/**
* @type {}
*/
export declare type NoAuth = void;
/**
* @type {auth_token: string} the user token
*/
export interface TokenAuth {
"auth_token": string;
}
/**
* @type {user: string, pass?: string} the username and
* optional password if the server requires.
*/
export interface UserPass {

@@ -10,2 +20,7 @@ user: string;

}
/**
* @type {nkey: string, sig: string} the public nkey for the user,
* and a base64 encoded string for the calculated signature of the
* challenge nonce.
*/
export interface NKeyAuth {

@@ -15,2 +30,8 @@ nkey: string;

}
/**
* @type {jwt: string, nkey?: string, sig?: string} the user JWT,
* and if not a bearer token also the public nkey for the user,
* and a base64 encoded string for the calculated signature of the
* challenge nonce.
*/
export interface JwtAuth {

@@ -21,5 +42,9 @@ jwt: string;

}
/**
* @type NoAuth|TokenAuth|UserPass|NKeyAuth|JwtAuth
*/
export declare type Auth = NoAuth | TokenAuth | UserPass | NKeyAuth | JwtAuth;
/**
* Authenticator is an interface that returns credentials
* Authenticator is an interface that returns credentials.
* @type function(nonce?: string) => Auth
*/

@@ -32,4 +57,18 @@ export interface Authenticator {

/**
* Returns an nkey authenticator that returns a public key
* @param {Uint8Array | (() => Uint8Array)} seed
* Returns a user/pass authenticator for the specified user and optional password
* @param { string }user
* @param {string } pass
* @return {UserPass}
*/
export declare function usernamePasswordAuthenticator(user: string, pass?: string): Authenticator;
/**
* Returns a token authenticator for the specified token
* @param { string } token
* @return {TokenAuth}
*/
export declare function tokenAuthenticator(token: string): Authenticator;
/**
* Returns an Authenticator that returns a NKeyAuth based that uses the
* specified seed or function returning a seed.
* @param {Uint8Array | (() => Uint8Array)} seed - the nkey seed
* @return {NKeyAuth}

@@ -39,16 +78,18 @@ */

/**
* Returns a jwt authenticator. If a seed is provided, the public
* key, and signature are calculated. Note if a signature is provided
* the returned value should be a base64 encoded string.
* Returns an Authenticator function that returns a JwtAuth.
* If a seed is provided, the public key, and signature are
* calculated.
*
* @return {JwtAuth}
* @param ajwt
* @param seed
* @param {string | ()=>string} ajwt - the jwt
* @param {Uint8Array | ()=> Uint8Array } seed - the optional nkey seed
* @return {Authenticator}
*/
export declare function jwtAuthenticator(ajwt: string | (() => string), seed?: Uint8Array | (() => Uint8Array)): Authenticator;
/**
* Returns a jwt authenticator configured from the specified creds file contents.
* @param creds
* Returns an Authenticator function that returns a JwtAuth.
* This is a convenience Authenticator that parses the
* specifid creds and delegates to the jwtAuthenticator.
* @param {Uint8Array} creds - the contents of a creds file
* @returns {JwtAuth}
*/
export declare function credsAuthenticator(creds: Uint8Array): Authenticator;

43

lib/nats-base-client/authenticator.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.credsAuthenticator = exports.jwtAuthenticator = exports.nkeyAuthenticator = exports.noAuthFn = exports.buildAuthenticator = void 0;
exports.credsAuthenticator = exports.jwtAuthenticator = exports.nkeyAuthenticator = exports.tokenAuthenticator = exports.usernamePasswordAuthenticator = exports.noAuthFn = exports.buildAuthenticator = void 0;
/*
* Copyright 2020 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -29,6 +29,6 @@ * you may not use this file except in compliance with the License.

if (opts.token) {
return tokenFn(opts.token);
return tokenAuthenticator(opts.token);
}
if (opts.user) {
return passFn(opts.user, opts.pass);
return usernamePasswordAuthenticator(opts.user, opts.pass);
}

@@ -45,3 +45,3 @@ return noAuthFn();

/**
* Returns a user/pass authenticator
* Returns a user/pass authenticator for the specified user and optional password
* @param { string }user

@@ -51,3 +51,3 @@ * @param {string } pass

*/
function passFn(user, pass) {
function usernamePasswordAuthenticator(user, pass) {
return () => {

@@ -57,8 +57,9 @@ return { user, pass };

}
exports.usernamePasswordAuthenticator = usernamePasswordAuthenticator;
/**
* Returns a token authenticator
* @param {string } token
* Returns a token authenticator for the specified token
* @param { string } token
* @return {TokenAuth}
*/
function tokenFn(token) {
function tokenAuthenticator(token) {
return () => {

@@ -68,5 +69,7 @@ return { auth_token: token };

}
exports.tokenAuthenticator = tokenAuthenticator;
/**
* Returns an nkey authenticator that returns a public key
* @param {Uint8Array | (() => Uint8Array)} seed
* Returns an Authenticator that returns a NKeyAuth based that uses the
* specified seed or function returning a seed.
* @param {Uint8Array | (() => Uint8Array)} seed - the nkey seed
* @return {NKeyAuth}

@@ -87,9 +90,9 @@ */

/**
* Returns a jwt authenticator. If a seed is provided, the public
* key, and signature are calculated. Note if a signature is provided
* the returned value should be a base64 encoded string.
* Returns an Authenticator function that returns a JwtAuth.
* If a seed is provided, the public key, and signature are
* calculated.
*
* @return {JwtAuth}
* @param ajwt
* @param seed
* @param {string | ()=>string} ajwt - the jwt
* @param {Uint8Array | ()=> Uint8Array } seed - the optional nkey seed
* @return {Authenticator}
*/

@@ -106,4 +109,6 @@ function jwtAuthenticator(ajwt, seed) {

/**
* Returns a jwt authenticator configured from the specified creds file contents.
* @param creds
* Returns an Authenticator function that returns a JwtAuth.
* This is a convenience Authenticator that parses the
* specifid creds and delegates to the jwtAuthenticator.
* @param {Uint8Array} creds - the contents of a creds file
* @returns {JwtAuth}

@@ -110,0 +115,0 @@ */

"use strict";
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -170,3 +170,2 @@ * you may not use this file except in compliance with the License.

jobs.push(d);
// deno-lint-ignore no-unused-vars
const sub = this.nc.subscribe(this.subject, {

@@ -173,0 +172,0 @@ max: this.msgs,

@@ -6,2 +6,2 @@ export interface Codec<T> {

export declare function StringCodec(): Codec<string>;
export declare function JSONCodec<T = unknown>(reviver?: (this: any, key: string, value: any) => any): Codec<T>;
export declare function JSONCodec<T = unknown>(reviver?: (this: unknown, key: string, value: unknown) => unknown): Codec<T>;
"use strict";
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -5,0 +5,0 @@ * you may not use this file except in compliance with the License.

@@ -33,2 +33,3 @@ import { ApiError } from "./types";

JetStream409MaxAckPendingExceeded = "409",
JetStream409 = "409",
JetStreamNotEnabled = "503",

@@ -51,2 +52,6 @@ AuthorizationViolation = "AUTHORIZATION_VIOLATION",

code: string;
permissionContext?: {
operation: string;
subject: string;
};
chainedError?: Error;

@@ -53,0 +58,0 @@ api_error?: ApiError;

@@ -51,3 +51,5 @@ "use strict";

ErrorCode["JetStream408RequestTimeout"] = "408";
//@deprecated: use JetStream409
ErrorCode["JetStream409MaxAckPendingExceeded"] = "409";
ErrorCode["JetStream409"] = "409";
ErrorCode["JetStreamNotEnabled"] = "503";

@@ -54,0 +56,0 @@ // emitted by the server

@@ -26,4 +26,4 @@ export { NatsConnectionImpl } from "./nats";

export { Request } from "./request";
export type { Authenticator } from "./authenticator";
export { credsAuthenticator, jwtAuthenticator, nkeyAuthenticator, } from "./authenticator";
export type { Auth, Authenticator, JwtAuth, NKeyAuth, NoAuth, TokenAuth, UserPass, } from "./authenticator";
export { credsAuthenticator, jwtAuthenticator, nkeyAuthenticator, tokenAuthenticator, usernamePasswordAuthenticator, } from "./authenticator";
export type { Codec } from "./codec";

@@ -30,0 +30,0 @@ export { JSONCodec, StringCodec } from "./codec";

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -13,4 +17,4 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
exports.QueuedIteratorImpl = exports.StringCodec = exports.JSONCodec = exports.nkeyAuthenticator = exports.jwtAuthenticator = exports.credsAuthenticator = exports.Request = exports.checkUnsupportedOption = exports.checkOptions = exports.DataBuffer = exports.MuxSubscription = exports.Heartbeat = exports.MsgHdrsImpl = exports.Match = exports.headers = exports.canonicalMIMEHeaderKey = exports.timeout = exports.render = exports.extractProtocolMessage = exports.extend = exports.delay = exports.deferred = exports.collect = exports.ProtocolHandler = exports.INFO = exports.createInbox = exports.Connect = exports.setTransportFactory = exports.Subscriptions = exports.SubscriptionImpl = exports.MsgImpl = exports.JsHeaders = exports.Events = exports.Empty = exports.DebugEvents = exports.toJsMsg = exports.consumerOpts = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.DiscardPolicy = exports.DeliverPolicy = exports.AdvisoryKind = exports.AckPolicy = exports.NatsError = exports.isNatsError = exports.ErrorCode = exports.nuid = exports.Nuid = exports.NatsConnectionImpl = void 0;
exports.parseSemVer = exports.compare = exports.NoopKvCodecs = exports.defaultBucketOpts = exports.Bucket = exports.Base64KeyCodec = exports.nanos = exports.millis = exports.isHeartbeatMsg = exports.isFlowControlMsg = exports.checkJsError = exports.TypedSubscription = exports.parseIP = exports.isIP = exports.TE = exports.TD = exports.Metric = exports.Bench = exports.writeAll = exports.readAll = exports.MAX_SIZE = exports.DenoBuffer = exports.State = exports.Parser = exports.Kind = void 0;
exports.JSONCodec = exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.nkeyAuthenticator = exports.jwtAuthenticator = exports.credsAuthenticator = exports.Request = exports.checkUnsupportedOption = exports.checkOptions = exports.DataBuffer = exports.MuxSubscription = exports.Heartbeat = exports.MsgHdrsImpl = exports.Match = exports.headers = exports.canonicalMIMEHeaderKey = exports.timeout = exports.render = exports.extractProtocolMessage = exports.extend = exports.delay = exports.deferred = exports.collect = exports.ProtocolHandler = exports.INFO = exports.createInbox = exports.Connect = exports.setTransportFactory = exports.Subscriptions = exports.SubscriptionImpl = exports.MsgImpl = exports.JsHeaders = exports.Events = exports.Empty = exports.DebugEvents = exports.toJsMsg = exports.consumerOpts = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.DiscardPolicy = exports.DeliverPolicy = exports.AdvisoryKind = exports.AckPolicy = exports.NatsError = exports.isNatsError = exports.ErrorCode = exports.nuid = exports.Nuid = exports.NatsConnectionImpl = void 0;
exports.parseSemVer = exports.compare = exports.NoopKvCodecs = exports.defaultBucketOpts = exports.Bucket = exports.Base64KeyCodec = exports.nanos = exports.millis = exports.isHeartbeatMsg = exports.isFlowControlMsg = exports.checkJsError = exports.TypedSubscription = exports.parseIP = exports.isIP = exports.TE = exports.TD = exports.Metric = exports.Bench = exports.writeAll = exports.readAll = exports.MAX_SIZE = exports.DenoBuffer = exports.State = exports.Parser = exports.Kind = exports.QueuedIteratorImpl = exports.StringCodec = void 0;
var nats_1 = require("./nats");

@@ -83,2 +87,4 @@ Object.defineProperty(exports, "NatsConnectionImpl", { enumerable: true, get: function () { return nats_1.NatsConnectionImpl; } });

Object.defineProperty(exports, "nkeyAuthenticator", { enumerable: true, get: function () { return authenticator_1.nkeyAuthenticator; } });
Object.defineProperty(exports, "tokenAuthenticator", { enumerable: true, get: function () { return authenticator_1.tokenAuthenticator; } });
Object.defineProperty(exports, "usernamePasswordAuthenticator", { enumerable: true, get: function () { return authenticator_1.usernamePasswordAuthenticator; } });
var codec_1 = require("./codec");

@@ -85,0 +91,0 @@ Object.defineProperty(exports, "JSONCodec", { enumerable: true, get: function () { return codec_1.JSONCodec; } });

@@ -14,3 +14,3 @@ import type { ConsumerOptsBuilder, Views } from "./types";

publish(subj: string, data?: Uint8Array, opts?: Partial<JetStreamPublishOptions>): Promise<PubAck>;
pull(stream: string, durable: string): Promise<JsMsg>;
pull(stream: string, durable: string, expires?: number): Promise<JsMsg>;
fetch(stream: string, durable: string, opts?: Partial<PullOptions>): QueuedIterator<JsMsg>;

@@ -17,0 +17,0 @@ pullSubscribe(subject: string, opts?: ConsumerOptsBuilder | Partial<ConsumerOpts>): Promise<JetStreamPullSubscription>;

"use strict";
/*
* Copyright 2021 The NATS Authors
* Copyright 2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -54,2 +54,5 @@ * you may not use this file except in compliance with the License.

kv(name, opts = {}) {
if (opts.bindOnly) {
return kv_1.Bucket.bind(this.js, name);
}
return kv_1.Bucket.create(this.js, name, opts);

@@ -105,9 +108,17 @@ }

}
pull(stream, durable) {
pull(stream, durable, expires = 0) {
return __awaiter(this, void 0, void 0, function* () {
(0, jsutil_1.validateStreamName)(stream);
(0, jsutil_1.validateDurableName)(durable);
const msg = yield this.nc.request(
// FIXME: specify expires
`${this.prefix}.CONSUMER.MSG.NEXT.${stream}.${durable}`, this.jc.encode({ no_wait: true, batch: 1, expires: 0 }), { noMux: true, timeout: this.timeout });
let timeout = this.timeout;
if (expires > timeout) {
timeout = expires;
}
expires = expires < 0 ? 0 : (0, jsutil_1.nanos)(expires);
const pullOpts = {
batch: 1,
no_wait: expires === 0,
expires,
};
const msg = yield this.nc.request(`${this.prefix}.CONSUMER.MSG.NEXT.${stream}.${durable}`, this.jc.encode(pullOpts), { noMux: true, timeout });
const err = (0, jsutil_1.checkJsError)(msg);

@@ -250,4 +261,4 @@ if (err) {

// as an option otherwise we have a pull consumer
if (!cso.config.deliver_subject) {
throw new Error("consumer info specifies a pull consumer - deliver_subject is required");
if (!cso.isBind && !cso.config.deliver_subject) {
throw new Error("push consumer requires deliver_subject");
}

@@ -318,3 +329,7 @@ const so = this._buildTypedSubscriptionOpts(cso);

}
// check if server returned push_bound, but there's no qn
const qn = (_a = jsi.config.deliver_group) !== null && _a !== void 0 ? _a : "";
if (qn === "" && info.push_bound === true) {
throw new Error(`duplicate subscription`);
}
const rqn = (_b = info.config.deliver_group) !== null && _b !== void 0 ? _b : "";

@@ -554,3 +569,3 @@ if (qn !== rqn) {

case error_1.ErrorCode.JetStream408RequestTimeout:
case error_1.ErrorCode.JetStream409MaxAckPendingExceeded:
case error_1.ErrorCode.JetStream409:
return [null, null];

@@ -557,0 +572,0 @@ default:

@@ -14,38 +14,38 @@ import { ConsumerConfig, ConsumerOpts, ConsumerOptsBuilder, JsMsgCallback } from "./types";

getOpts(): ConsumerOpts;
description(description: string): void;
deliverTo(subject: string): void;
durable(name: string): void;
startSequence(seq: number): void;
startTime(time: Date): void;
deliverAll(): void;
deliverLastPerSubject(): void;
deliverLast(): void;
deliverNew(): void;
startAtTimeDelta(millis: number): void;
headersOnly(): void;
ackNone(): void;
ackAll(): void;
ackExplicit(): void;
ackWait(millis: number): void;
maxDeliver(max: number): void;
filterSubject(s: string): void;
replayInstantly(): void;
replayOriginal(): void;
sample(n: number): void;
limit(n: number): void;
maxWaiting(max: number): void;
maxAckPending(max: number): void;
idleHeartbeat(millis: number): void;
flowControl(): void;
deliverGroup(name: string): void;
manualAck(): void;
maxMessages(max: number): void;
callback(fn: JsMsgCallback): void;
queue(n: string): void;
orderedConsumer(): void;
bind(stream: string, durable: string): void;
inactiveEphemeralThreshold(millis: number): void;
maxPullBatch(n: number): void;
maxPullRequestExpires(millis: number): void;
description(description: string): this;
deliverTo(subject: string): this;
durable(name: string): this;
startSequence(seq: number): this;
startTime(time: Date): this;
deliverAll(): this;
deliverLastPerSubject(): this;
deliverLast(): this;
deliverNew(): this;
startAtTimeDelta(millis: number): this;
headersOnly(): this;
ackNone(): this;
ackAll(): this;
ackExplicit(): this;
ackWait(millis: number): this;
maxDeliver(max: number): this;
filterSubject(s: string): this;
replayInstantly(): this;
replayOriginal(): this;
sample(n: number): this;
limit(n: number): this;
maxWaiting(max: number): this;
maxAckPending(max: number): this;
idleHeartbeat(millis: number): this;
flowControl(): this;
deliverGroup(name: string): this;
manualAck(): this;
maxMessages(max: number): this;
callback(fn: JsMsgCallback): this;
queue(n: string): this;
orderedConsumer(): this;
bind(stream: string, durable: string): this;
inactiveEphemeralThreshold(millis: number): this;
maxPullBatch(n: number): this;
maxPullRequestExpires(millis: number): this;
}
export declare function isConsumerOptsBuilder(o: ConsumerOptsBuilder | Partial<ConsumerOpts>): o is ConsumerOptsBuilderImpl;

@@ -53,5 +53,7 @@ "use strict";

this.config.description = description;
return this;
}
deliverTo(subject) {
this.config.deliver_subject = subject;
return this;
}

@@ -61,2 +63,3 @@ durable(name) {

this.config.durable_name = name;
return this;
}

@@ -69,2 +72,3 @@ startSequence(seq) {

this.config.opt_start_seq = seq;
return this;
}

@@ -74,44 +78,59 @@ startTime(time) {

this.config.opt_start_time = time.toISOString();
return this;
}
deliverAll() {
this.config.deliver_policy = types_1.DeliverPolicy.All;
return this;
}
deliverLastPerSubject() {
this.config.deliver_policy = types_1.DeliverPolicy.LastPerSubject;
return this;
}
deliverLast() {
this.config.deliver_policy = types_1.DeliverPolicy.Last;
return this;
}
deliverNew() {
this.config.deliver_policy = types_1.DeliverPolicy.New;
return this;
}
startAtTimeDelta(millis) {
this.startTime(new Date(Date.now() - millis));
return this;
}
headersOnly() {
this.config.headers_only = true;
return this;
}
ackNone() {
this.config.ack_policy = types_1.AckPolicy.None;
return this;
}
ackAll() {
this.config.ack_policy = types_1.AckPolicy.All;
return this;
}
ackExplicit() {
this.config.ack_policy = types_1.AckPolicy.Explicit;
return this;
}
ackWait(millis) {
this.config.ack_wait = (0, jsutil_1.nanos)(millis);
return this;
}
maxDeliver(max) {
this.config.max_deliver = max;
return this;
}
filterSubject(s) {
this.config.filter_subject = s;
return this;
}
replayInstantly() {
this.config.replay_policy = types_1.ReplayPolicy.Instant;
return this;
}
replayOriginal() {
this.config.replay_policy = types_1.ReplayPolicy.Original;
return this;
}

@@ -124,29 +143,39 @@ sample(n) {

this.config.sample_freq = `${n}%`;
return this;
}
limit(n) {
this.config.rate_limit_bps = n;
return this;
}
maxWaiting(max) {
this.config.max_waiting = max;
return this;
}
maxAckPending(max) {
this.config.max_ack_pending = max;
return this;
}
idleHeartbeat(millis) {
this.config.idle_heartbeat = (0, jsutil_1.nanos)(millis);
return this;
}
flowControl() {
this.config.flow_control = true;
return this;
}
deliverGroup(name) {
this.queue(name);
return this;
}
manualAck() {
this.mack = true;
return this;
}
maxMessages(max) {
this.max = max;
return this;
}
callback(fn) {
this.callbackFn = fn;
return this;
}

@@ -156,5 +185,7 @@ queue(n) {

this.config.deliver_group = n;
return this;
}
orderedConsumer() {
this.ordered = true;
return this;
}

@@ -165,11 +196,15 @@ bind(stream, durable) {

this.isBind = true;
return this;
}
inactiveEphemeralThreshold(millis) {
this.config.inactive_threshold = (0, jsutil_1.nanos)(millis);
return this;
}
maxPullBatch(n) {
this.config.max_batch = n;
return this;
}
maxPullRequestExpires(millis) {
this.config.max_expires = (0, jsutil_1.nanos)(millis);
return this;
}

@@ -176,0 +211,0 @@ }

@@ -25,4 +25,4 @@ import { DeliveryInfo, JsMsg, Msg, NextRequest } from "./types";

working(): void;
next(subj?: string, ro?: Partial<NextRequest>): void;
next(subj: string, opts?: Partial<NextRequest>): void;
term(): void;
}

@@ -106,3 +106,3 @@ "use strict";

const proto = mi.publisher;
const r = new request_1.Request(proto.muxSubscriptions);
const r = new request_1.Request(proto.muxSubscriptions, this.msg.reply);
proto.request(r);

@@ -142,10 +142,13 @@ try {

}
next(subj, ro) {
let payload = NXT;
if (ro) {
const data = (0, codec_1.JSONCodec)().encode(ro);
payload = databuffer_1.DataBuffer.concat(NXT, SPACE, data);
next(subj, opts = { batch: 1 }) {
const args = {};
args.batch = opts.batch || 1;
args.no_wait = opts.no_wait || false;
if (opts.expires && opts.expires > 0) {
args.expires = (0, jsutil_1.nanos)(opts.expires);
}
const opts = subj ? { reply: subj } : undefined;
this.msg.respond(payload, opts);
const data = (0, codec_1.JSONCodec)().encode(args);
const payload = databuffer_1.DataBuffer.concat(NXT, SPACE, data);
const reqOpts = subj ? { reply: subj } : undefined;
this.msg.respond(payload, reqOpts);
}

@@ -152,0 +155,0 @@ term() {

@@ -55,6 +55,9 @@ "use strict";

function millis(ns) {
return ns / 1000000;
return Math.floor(ns / 1000000);
}
exports.millis = millis;
function isFlowControlMsg(msg) {
if (msg.data.length > 0) {
return false;
}
const h = msg.headers;

@@ -73,2 +76,6 @@ if (!h) {

function checkJsError(msg) {
// JS error only if no payload - otherwise assume it is application data
if (msg.data.length !== 0) {
return null;
}
const h = msg.headers;

@@ -87,4 +94,11 @@ if (!h) {

switch (code) {
case 404:
// 404 for jetstream will provide different messages ensure we
// keep whatever the server returned
return new error_1.NatsError(description, error_1.ErrorCode.JetStream404NoMessages);
case 408:
return error_1.NatsError.errorForCode(error_1.ErrorCode.JetStream408RequestTimeout, new Error(description));
return new error_1.NatsError(description, error_1.ErrorCode.JetStream408RequestTimeout);
case 409:
// the description can be exceeded max waiting or max ack pending
return new error_1.NatsError(description, error_1.ErrorCode.JetStream409);
case 503:

@@ -91,0 +105,0 @@ return error_1.NatsError.errorForCode(error_1.ErrorCode.JetStreamNotEnabled, new Error(description));

@@ -22,2 +22,5 @@ import { callbackFn, ConsumerConfig, JetStreamClient, JetStreamManager, JsMsg, KV, KvCodec, KvCodecs, KvEntry, KvOptions, KvPutOptions, KvRemove, KvStatus, PurgeOpts, PurgeResponse, StoredMsg } from "./types";

static create(js: JetStreamClient, name: string, opts?: Partial<KvOptions>): Promise<KV>;
static bind(js: JetStreamClient, name: string, opts?: Partial<{
codec: KvCodecs;
}>): Promise<KV>;
init(opts?: Partial<KvOptions>): Promise<void>;

@@ -36,10 +39,13 @@ bucketName(): string;

dataLen(data: Uint8Array, h?: MsgHdrs): number;
smToEntry(key: string, sm: StoredMsg): KvEntry;
jmToEntry(k: string, jm: JsMsg): KvEntry;
smToEntry(sm: StoredMsg): KvEntry;
jmToEntry(jm: JsMsg): KvEntry;
create(k: string, data: Uint8Array): Promise<number>;
update(k: string, data: Uint8Array, version: number): Promise<number>;
put(k: string, data: Uint8Array, opts?: Partial<KvPutOptions>): Promise<number>;
get(k: string): Promise<KvEntry | null>;
get(k: string, opts?: {
revision: number;
}): Promise<KvEntry | null>;
purge(k: string): Promise<void>;
delete(k: string): Promise<void>;
purgeDeletes(olderMillis?: number): Promise<PurgeResponse>;
_deleteOrPurge(k: string, op: "DEL" | "PURGE"): Promise<void>;

@@ -46,0 +52,0 @@ _doDeleteOrPurge(k: string, op: "DEL" | "PURGE"): Promise<void>;

@@ -37,3 +37,2 @@ "use strict";

const queued_iterator_1 = require("./queued_iterator");
const util_1 = require("./util");
const headers_1 = require("./headers");

@@ -166,2 +165,14 @@ const mod_1 = require("./mod");

}
static bind(js, name, opts = {}) {
return __awaiter(this, void 0, void 0, function* () {
const jsi = js;
const jsm = yield jsi.nc.jetstreamManager();
const info = yield jsm.streams.info(`${kvPrefix}${name}`);
validateBucket(info.config.name);
const bucket = new Bucket(name, jsm, js);
Object.assign(bucket, info);
bucket.codec = opts.codec || NoopKvCodecs();
return bucket;
});
}
init(opts = {}) {

@@ -182,3 +193,3 @@ var _a;

const have = nci.getServerVersion();
const discardNew = have ? (0, semver_1.compare)((0, semver_1.parseSemVer)("2.7.2"), have) >= 0 : false;
const discardNew = have ? (0, semver_1.compare)(have, (0, semver_1.parseSemVer)("2.7.2")) >= 0 : false;
sc.discard = discardNew ? types_1.DiscardPolicy.New : types_1.DiscardPolicy.Old;

@@ -259,6 +270,6 @@ sc.num_replicas = bo.replicas;

}
smToEntry(key, sm) {
smToEntry(sm) {
return {
bucket: this.bucket,
key: key,
key: sm.subject.substring(this.prefixLen),
value: sm.data,

@@ -272,3 +283,3 @@ delta: 0,

}
jmToEntry(k, jm) {
jmToEntry(jm) {
var _a;

@@ -310,11 +321,17 @@ const key = this.decodeKey(jm.subject.substring(this.prefixLen));

}
get(k) {
get(k, opts) {
return __awaiter(this, void 0, void 0, function* () {
const ek = this.encodeKey(k);
this.validateKey(ek);
let arg = { last_by_subj: this.fullKeyName(ek) };
if (opts && opts.revision > 0) {
arg = { seq: opts.revision };
}
try {
const sm = yield this.jsm.streams.getMessage(this.bucketName(), {
last_by_subj: this.fullKeyName(ek),
});
return this.smToEntry(k, sm);
const sm = yield this.jsm.streams.getMessage(this.bucketName(), arg);
const ke = this.smToEntry(sm);
if (ke.key !== ek) {
return null;
}
return ke;
}

@@ -335,4 +352,52 @@ catch (err) {

}
purgeDeletes(olderMillis = 30 * 60 * 1000) {
return __awaiter(this, void 0, void 0, function* () {
const done = (0, mod_1.deferred)();
const buf = [];
const i = yield this.watch({
key: ">",
initializedFn: () => {
done.resolve();
},
});
(() => __awaiter(this, void 0, void 0, function* () {
var e_1, _a;
try {
for (var i_1 = __asyncValues(i), i_1_1; i_1_1 = yield i_1.next(), !i_1_1.done;) {
const e = i_1_1.value;
if (e.operation === "DEL" || e.operation === "PURGE") {
buf.push(e);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (i_1_1 && !i_1_1.done && (_a = i_1.return)) yield _a.call(i_1);
}
finally { if (e_1) throw e_1.error; }
}
}))().then();
yield done;
i.stop();
const min = Date.now() - olderMillis;
const proms = buf.map((e) => {
const subj = this.subjectForKey(e.key);
if (e.created.getTime() >= min) {
return this.jsm.streams.purge(this.stream, { filter: subj, keep: 1 });
}
else {
return this.jsm.streams.purge(this.stream, { filter: subj, keep: 0 });
}
});
const purged = yield Promise.all(proms);
purged.unshift({ success: true, purged: 0 });
return purged.reduce((pv, cv) => {
pv.purged += cv.purged;
return pv;
});
});
}
_deleteOrPurge(k, op) {
var e_1, _a;
var e_2, _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -354,3 +419,3 @@ if (!this.hasWildcards(k)) {

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {

@@ -360,3 +425,3 @@ try {

}
finally { if (e_1) throw e_1.error; }
finally { if (e_2) throw e_2.error; }
}

@@ -401,5 +466,9 @@ if (buf.length > 0) {

const qi = new queued_iterator_1.QueuedIteratorImpl();
const done = (0, util_1.deferred)();
const co = {};
co.headers_only = opts.headers_only || false;
let fn;
fn = () => {
qi.stop();
};
let count = 0;
const cc = this._buildCC(k, true, co);

@@ -416,7 +485,10 @@ const subj = cc.filter_subject;

if (jm) {
const e = this.jmToEntry(k, jm);
const e = this.jmToEntry(jm);
qi.push(e);
qi.received++;
if (jm.info.pending === 0) {
done.resolve();
//@ts-ignore - function will be removed
if (fn && count > 0 && qi.received >= count || jm.info.pending === 0) {
//@ts-ignore: we are injecting an unexpected type
qi.push(fn);
fn = undefined;
}

@@ -426,8 +498,29 @@ }

const sub = yield this.js.subscribe(subj, copts);
done.then(() => {
sub.unsubscribe();
});
done.catch((_err) => {
sub.unsubscribe();
});
// by the time we are here, likely the subscription got messages
if (fn) {
const { info: { last } } = sub;
// this doesn't sound correct - we should be looking for a seq number instead
// then if we see a greater one, we are done.
const expect = last.num_pending + last.delivered.consumer_seq;
// if the iterator already queued - the only issue is other modifications
// did happen like stream was pruned, and the ordered consumer reset, etc
// we won't get what we are expecting - so the notification will never fire
// the sentinel ought to be coming from the server
if (expect === 0 || qi.received >= expect) {
try {
fn();
}
catch (err) {
// fail it - there's something wrong in the user callback
qi.stop(err);
}
finally {
fn = undefined;
}
}
else {
count = expect;
}
}
qi._data = sub;
qi.iterClosed.then(() => {

@@ -441,8 +534,2 @@ sub.unsubscribe();

});
this.jsm.streams.getMessage(this.stream, {
"last_by_subj": subj,
}).catch(() => {
// we don't have a value for this
done.resolve();
});
return qi;

@@ -460,3 +547,2 @@ });

let count = 0;
let initialized = false;
const cc = this._buildCC(k, false, co);

@@ -473,3 +559,3 @@ const subj = cc.filter_subject;

if (jm) {
const e = this.jmToEntry(k, jm);
const e = this.jmToEntry(jm);
qi.push(e);

@@ -479,3 +565,2 @@ qi.received++;

if (fn && (count > 0 && qi.received >= count || jm.info.pending === 0)) {
initialized = true;
//@ts-ignore: we are injecting an unexpected type

@@ -535,3 +620,3 @@ qi.push(fn);

(() => __awaiter(this, void 0, void 0, function* () {
var e_2, _a;
var e_3, _a;
var _b;

@@ -551,3 +636,3 @@ try {

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -557,3 +642,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -560,0 +645,0 @@ }))()

@@ -1,2 +0,2 @@

export { AckPolicy, AdvisoryKind, Bench, canonicalMIMEHeaderKey, checkJsError, consumerOpts, createInbox, credsAuthenticator, DebugEvents, deferred, DeliverPolicy, DiscardPolicy, Empty, ErrorCode, Events, headers, isFlowControlMsg, isHeartbeatMsg, JsHeaders, JSONCodec, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, NatsError, nkeyAuthenticator, Nuid, nuid, ReplayPolicy, RetentionPolicy, StorageType, StringCodec, toJsMsg, } from "./internal_mod";
export type { AccountLimits, Authenticator, ClusterInfo, Codec, ConnectionOptions, Consumer, ConsumerConfig, ConsumerInfo, ConsumerOpts, ConsumerOptsBuilder, Deferred, DeliveryInfo, JetStreamAccountStats, JetStreamApiStats, JetStreamClient, JetStreamManager, JetStreamOptions, JetStreamPublishOptions, JetStreamPullSubscription, JetStreamSubscription, JetStreamSubscriptionOptions, JsMsg, JsMsgCallback, LastForMsgRequest, Lister, LostStreamData, Msg, MsgDeleteRequest, MsgHdrs, MsgRequest, Nanos, NatsConnection, PeerInfo, Placement, PubAck, PublishOptions, PullOptions, RequestOptions, SeqMsgRequest, SequenceInfo, ServerInfo, ServersChanged, Stats, Status, StoredMsg, StreamConfig, StreamInfo, StreamNames, StreamSource, StreamSourceInfo, StreamState, Sub, SubOpts, Subscription, SubscriptionOptions, } from "./internal_mod";
export { AckPolicy, AdvisoryKind, Bench, canonicalMIMEHeaderKey, checkJsError, consumerOpts, createInbox, credsAuthenticator, DebugEvents, deferred, DeliverPolicy, DiscardPolicy, Empty, ErrorCode, Events, headers, isFlowControlMsg, isHeartbeatMsg, JsHeaders, JSONCodec, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, NatsError, nkeyAuthenticator, Nuid, nuid, ReplayPolicy, RetentionPolicy, StorageType, StringCodec, toJsMsg, tokenAuthenticator, usernamePasswordAuthenticator, } from "./internal_mod";
export type { AccountLimits, Auth, Authenticator, ClusterInfo, Codec, ConnectionOptions, Consumer, ConsumerConfig, ConsumerInfo, ConsumerOpts, ConsumerOptsBuilder, Deferred, DeliveryInfo, JetStreamAccountStats, JetStreamApiStats, JetStreamClient, JetStreamManager, JetStreamOptions, JetStreamPublishOptions, JetStreamPullSubscription, JetStreamSubscription, JetStreamSubscriptionOptions, JsMsg, JsMsgCallback, JwtAuth, LastForMsgRequest, Lister, LostStreamData, Msg, MsgDeleteRequest, MsgHdrs, MsgRequest, Nanos, NatsConnection, NKeyAuth, NoAuth, PeerInfo, Placement, PubAck, PublishOptions, PullOptions, RequestOptions, SeqMsgRequest, SequenceInfo, ServerInfo, ServersChanged, Stats, Status, StoredMsg, StreamConfig, StreamInfo, StreamNames, StreamSource, StreamSourceInfo, StreamState, Sub, SubOpts, Subscription, SubscriptionOptions, TokenAuth, UserPass, } from "./internal_mod";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toJsMsg = exports.StringCodec = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.nuid = exports.Nuid = exports.nkeyAuthenticator = exports.NatsError = exports.nanos = exports.MsgHdrsImpl = exports.millis = exports.Metric = exports.Match = exports.jwtAuthenticator = exports.JSONCodec = exports.JsHeaders = exports.isHeartbeatMsg = exports.isFlowControlMsg = exports.headers = exports.Events = exports.ErrorCode = exports.Empty = exports.DiscardPolicy = exports.DeliverPolicy = exports.deferred = exports.DebugEvents = exports.credsAuthenticator = exports.createInbox = exports.consumerOpts = exports.checkJsError = exports.canonicalMIMEHeaderKey = exports.Bench = exports.AdvisoryKind = exports.AckPolicy = void 0;
exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.toJsMsg = exports.StringCodec = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.nuid = exports.Nuid = exports.nkeyAuthenticator = exports.NatsError = exports.nanos = exports.MsgHdrsImpl = exports.millis = exports.Metric = exports.Match = exports.jwtAuthenticator = exports.JSONCodec = exports.JsHeaders = exports.isHeartbeatMsg = exports.isFlowControlMsg = exports.headers = exports.Events = exports.ErrorCode = exports.Empty = exports.DiscardPolicy = exports.DeliverPolicy = exports.deferred = exports.DebugEvents = exports.credsAuthenticator = exports.createInbox = exports.consumerOpts = exports.checkJsError = exports.canonicalMIMEHeaderKey = exports.Bench = exports.AdvisoryKind = exports.AckPolicy = void 0;
var internal_mod_1 = require("./internal_mod");

@@ -40,2 +40,4 @@ Object.defineProperty(exports, "AckPolicy", { enumerable: true, get: function () { return internal_mod_1.AckPolicy; } });

Object.defineProperty(exports, "toJsMsg", { enumerable: true, get: function () { return internal_mod_1.toJsMsg; } });
Object.defineProperty(exports, "tokenAuthenticator", { enumerable: true, get: function () { return internal_mod_1.tokenAuthenticator; } });
Object.defineProperty(exports, "usernamePasswordAuthenticator", { enumerable: true, get: function () { return internal_mod_1.usernamePasswordAuthenticator; } });
//# sourceMappingURL=mod.js.map

@@ -23,16 +23,10 @@ "use strict";

function isRequestError(msg) {
if (msg && msg.headers) {
// to consider an error from the server we expect no payload
if (msg && msg.data.length === 0 && msg.headers) {
const headers = msg.headers;
if (headers.hasError) {
// only 503s are expected from core NATS (404/408/409s are JetStream)
if (headers.code === 503) {
return error_1.NatsError.errorForCode(error_1.ErrorCode.NoResponders);
}
else {
let desc = headers.description;
if (desc === "") {
desc = error_1.ErrorCode.RequestError;
}
desc = desc.toLowerCase();
return new error_1.NatsError(desc, headers.status);
}
}

@@ -39,0 +33,0 @@ }

@@ -14,4 +14,6 @@ import type { Request } from "./request";

getToken(m: Msg): string | null;
all(): Request[];
handleError(isMuxPermissionError: boolean, err?: NatsError): boolean;
dispatcher(): (err: NatsError | null, m: Msg) => void;
close(): void;
}

@@ -37,2 +37,27 @@ "use strict";

}
all() {
return Array.from(this.reqs.values());
}
handleError(isMuxPermissionError, err) {
if (err && err.permissionContext) {
if (isMuxPermissionError) {
// one or more requests queued but mux cannot process them
this.all().forEach((r) => {
r.resolver(err, {});
});
return true;
}
const ctx = err.permissionContext;
if (ctx.operation === "publish") {
const req = this.all().find((s) => {
return s.requestSubject === ctx.subject;
});
if (req) {
req.resolver(err, {});
return true;
}
}
}
return false;
}
dispatcher() {

@@ -39,0 +64,0 @@ return (err, m) => {

@@ -34,2 +34,3 @@ import { ProtocolHandler } from "./protocol";

getServerVersion(): SemVer | undefined;
rtt(): Promise<number>;
}

@@ -161,3 +161,3 @@ "use strict";

const errCtx = new Error();
this.subscribe(inbox, {
const sub = this.subscribe(inbox, {
max: 1,

@@ -186,7 +186,11 @@ timeout: opts.timeout,

});
this.protocol.publish(subject, data, { reply: inbox });
sub.requestSubject = subject;
this.protocol.publish(subject, data, {
reply: inbox,
headers: opts.headers,
});
return d;
}
else {
const r = new request_1.Request(this.protocol.muxSubscriptions, opts);
const r = new request_1.Request(this.protocol.muxSubscriptions, subject, opts);
this.protocol.request(r);

@@ -262,3 +266,3 @@ try {

catch (err) {
let ne = err;
const ne = err;
if (ne.code === error_1.ErrorCode.NoResponders) {

@@ -279,4 +283,14 @@ ne.code = error_1.ErrorCode.JetStreamNotEnabled;

}
rtt() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.protocol._closed && !this.protocol.connected) {
throw error_1.NatsError.errorForCode(error_1.ErrorCode.Disconnect);
}
const start = Date.now();
yield this.flush();
return Date.now() - start;
});
}
}
exports.NatsConnectionImpl = NatsConnectionImpl;
//# sourceMappingURL=nats.js.map

@@ -21,3 +21,3 @@ "use strict";

/*
* Copyright 2018-2021 The NATS Authors
* Copyright 2018-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -266,3 +266,11 @@ * you may not use this file except in compliance with the License.

if (!srv || this.abortReconnect) {
throw lastError || error_1.NatsError.errorForCode(error_1.ErrorCode.ConnectionRefused);
if (lastError) {
throw lastError;
}
else if (this.lastError) {
throw this.lastError;
}
else {
throw error_1.NatsError.errorForCode(error_1.ErrorCode.ConnectionRefused);
}
}

@@ -308,3 +316,11 @@ const now = Date.now();

if (t.indexOf("permissions violation") !== -1) {
return new error_1.NatsError(s, error_1.ErrorCode.PermissionsViolation);
const err = new error_1.NatsError(s, error_1.ErrorCode.PermissionsViolation);
const m = s.match(/(Publish|Subscription) to "(\S+)"/);
if (m) {
err.permissionContext = {
operation: m[1].toLowerCase(),
subject: m[2],
};
}
return err;
}

@@ -343,4 +359,16 @@ else if (t.indexOf("authorization violation") !== -1) {

const err = ProtocolHandler.toError(s);
let isMuxPermissionError = false;
const status = { type: types_1.Events.Error, data: err.code };
if (err.permissionContext) {
status.permissionContext = err.permissionContext;
const mux = this.subscriptions.getMux();
isMuxPermissionError = (mux === null || mux === void 0 ? void 0 : mux.subject) === err.permissionContext.subject;
}
this.subscriptions.handleError(err);
this.dispatchStatus({ type: types_1.Events.Error, data: err.code });
this.muxSubscriptions.handleError(isMuxPermissionError, err);
if (isMuxPermissionError) {
// remove the permission - enable it to be recreated
this.subscriptions.setMux(null);
}
this.dispatchStatus(status);
yield this.handleError(err);

@@ -372,3 +400,3 @@ });

processPing() {
this.transport.send(PONG_CMD);
this.transport.send(PONG_CMD).catch(() => { });
}

@@ -574,3 +602,3 @@ processPong() {

if (cmds.length) {
this.transport.send((0, encoders_1.encode)(cmds.join("")));
this.transport.send((0, encoders_1.encode)(cmds.join(""))).catch(() => { });
}

@@ -626,3 +654,3 @@ }

const d = this.outbound.drain();
this.transport.send(d);
this.transport.send(d).catch(() => { });
}

@@ -629,0 +657,0 @@ }

@@ -11,6 +11,7 @@ import { Deferred, Timeout } from "./util";

ctx: Error;
requestSubject: string;
private mux;
constructor(mux: MuxSubscription, opts?: RequestOptions);
constructor(mux: MuxSubscription, requestSubject: string, opts?: RequestOptions);
resolver(err: Error | null, msg: Msg): void;
cancel(err?: NatsError): void;
}

@@ -22,4 +22,5 @@ "use strict";

class Request {
constructor(mux, opts = { timeout: 1000 }) {
constructor(mux, requestSubject, opts = { timeout: 1000 }) {
this.mux = mux;
this.requestSubject = requestSubject;
this.received = 0;

@@ -26,0 +27,0 @@ this.deferred = (0, util_1.deferred)();

@@ -14,3 +14,3 @@ "use strict";

/*
* Copyright 2018-2021 The NATS Authors
* Copyright 2018-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -121,3 +121,3 @@ * you may not use this file except in compliance with the License.

const ips = yield opts.fn(this.hostname);
for (let ip of ips) {
for (const ip of ips) {
// letting URL handle the details of representing IPV6 ip with a port, etc

@@ -124,0 +124,0 @@ // careful to make sure the protocol doesn't line with standard ports or they

@@ -18,2 +18,3 @@ import { DispatchedFn, IngestionFilterFn, ProtocolFilterFn, QueuedIteratorImpl } from "./queued_iterator";

closed: Deferred<void>;
requestSubject?: string;
constructor(protocol: ProtocolHandler, subject: string, opts?: SubscriptionOptions);

@@ -20,0 +21,0 @@ setPrePostHandlers(opts: {

import type { SubscriptionImpl } from "./subscription";
import type { NatsError } from "./error";
export declare class Subscriptions {
mux: SubscriptionImpl;
mux: SubscriptionImpl | null;
subs: Map<number, SubscriptionImpl>;

@@ -10,3 +10,3 @@ sidCounter: number;

add(s: SubscriptionImpl): SubscriptionImpl;
setMux(s: SubscriptionImpl): SubscriptionImpl;
setMux(s: SubscriptionImpl | null): SubscriptionImpl | null;
getMux(): SubscriptionImpl | null;

@@ -13,0 +13,0 @@ get(sid: number): (SubscriptionImpl | undefined);

@@ -7,2 +7,3 @@ "use strict";

this.sidCounter = 0;
this.mux = null;
this.subs = new Map();

@@ -37,7 +38,3 @@ }

all() {
const buf = [];
for (const s of this.subs.values()) {
buf.push(s);
}
return buf;
return Array.from(this.subs.values());
}

@@ -51,18 +48,24 @@ cancel(s) {

handleError(err) {
let handled = false;
if (err) {
const re = /^'Permissions Violation for Subscription to "(\S+)"'/i;
const ma = re.exec(err.message);
if (ma) {
const subj = ma[1];
this.subs.forEach((sub) => {
if (subj == sub.subject) {
sub.callback(err, {});
sub.close();
handled = sub !== this.mux;
}
if (err && err.permissionContext) {
const ctx = err.permissionContext;
const subs = this.all();
let sub;
if (ctx.operation === "subscription") {
sub = subs.find((s) => {
return s.subject === ctx.subject;
});
}
if (ctx.operation === "publish") {
// we have a no mux subscription
sub = subs.find((s) => {
return s.requestSubject === ctx.subject;
});
}
if (sub) {
sub.callback(err, {});
sub.close();
return sub !== this.mux;
}
}
return handled;
return false;
}

@@ -69,0 +72,0 @@ close() {

@@ -17,2 +17,6 @@ import { NatsError } from "./error";

data: string | ServersChanged | number;
permissionContext?: {
operation: string;
subject: string;
};
}

@@ -51,2 +55,3 @@ export declare enum DebugEvents {

jetstream(opts?: JetStreamOptions): JetStreamClient;
rtt(): Promise<number>;
}

@@ -242,3 +247,3 @@ export interface ConnectionOptions {

publish(subj: string, data?: Uint8Array, options?: Partial<JetStreamPublishOptions>): Promise<PubAck>;
pull(stream: string, durable: string): Promise<JsMsg>;
pull(stream: string, durable: string, expires?: number): Promise<JsMsg>;
fetch(stream: string, durable: string, opts?: Partial<PullOptions>): QueuedIterator<JsMsg>;

@@ -262,37 +267,37 @@ pullSubscribe(subject: string, opts: ConsumerOptsBuilder | Partial<ConsumerOpts>): Promise<JetStreamPullSubscription>;

export interface ConsumerOptsBuilder {
description(description: string): void;
deliverTo(subject: string): void;
durable(name: string): void;
startSequence(seq: number): void;
startTime(time: Date): void;
deliverAll(): void;
deliverLastPerSubject(): void;
deliverLast(): void;
deliverNew(): void;
startAtTimeDelta(millis: number): void;
headersOnly(): void;
ackNone(): void;
ackAll(): void;
ackExplicit(): void;
ackWait(millis: number): void;
maxDeliver(max: number): void;
filterSubject(s: string): void;
replayInstantly(): void;
replayOriginal(): void;
sample(n: number): void;
limit(bps: number): void;
maxWaiting(max: number): void;
maxAckPending(max: number): void;
idleHeartbeat(millis: number): void;
flowControl(): void;
deliverGroup(name: string): void;
manualAck(): void;
maxMessages(max: number): void;
queue(n: string): void;
callback(fn: JsMsgCallback): void;
orderedConsumer(): void;
bind(stream: string, durable: string): void;
maxPullBatch(n: number): void;
maxPullRequestExpires(millis: number): void;
inactiveEphemeralThreshold(millis: number): void;
description(description: string): this;
deliverTo(subject: string): this;
durable(name: string): this;
startSequence(seq: number): this;
startTime(time: Date): this;
deliverAll(): this;
deliverLastPerSubject(): this;
deliverLast(): this;
deliverNew(): this;
startAtTimeDelta(millis: number): this;
headersOnly(): this;
ackNone(): this;
ackAll(): this;
ackExplicit(): this;
ackWait(millis: number): this;
maxDeliver(max: number): this;
filterSubject(s: string): this;
replayInstantly(): this;
replayOriginal(): this;
sample(n: number): this;
limit(bps: number): this;
maxWaiting(max: number): this;
maxAckPending(max: number): this;
idleHeartbeat(millis: number): this;
flowControl(): this;
deliverGroup(name: string): this;
manualAck(): this;
maxMessages(max: number): this;
queue(n: string): this;
callback(fn: JsMsgCallback): this;
orderedConsumer(): this;
bind(stream: string, durable: string): this;
maxPullBatch(n: number): this;
maxPullRequestExpires(millis: number): this;
inactiveEphemeralThreshold(millis: number): this;
}

@@ -311,2 +316,3 @@ export interface Lister<T> {

"deleted_details": boolean;
"subjects_filter": string;
};

@@ -335,2 +341,13 @@ export interface StreamAPI {

working(): void;
/**
* next() combines ack() and pull(), requires the subject for a
* subscription processing to process a message is provided
* (can be the same) however, because the ability to specify
* how long to keep the request open can be specified, this
* functionality doesn't work well with iterators, as an error
* (408s) are expected and needed to re-trigger a pull in case
* there was a timeout. In an iterator, the error will close
* the iterator, requiring a subscription to be reset.
*/
next(subj: string, ro?: Partial<NextRequest>): void;
term(): void;

@@ -396,2 +413,6 @@ ackAck(): Promise<boolean>;

}
export interface StreamAlternate {
name: string;
cluster: string;
}
export interface StreamInfo {

@@ -404,2 +425,3 @@ config: StreamConfig;

sources?: StreamSourceInfo[];
alternates?: StreamAlternate[];
}

@@ -485,2 +507,4 @@ export interface StreamConfig extends StreamUpdateConfig {

"consumer_count": number;
num_subjects?: number;
subjects?: Record<string, number>;
}

@@ -554,2 +578,3 @@ export interface LostStreamData {

cluster?: ClusterInfo;
"push_bound": boolean;
}

@@ -576,3 +601,12 @@ export interface ConsumerListResponse extends ApiResponse, ApiPaged {

}
export interface JetStreamAccountStats {
export interface AccountLimits {
"max_memory": number;
"max_storage": number;
"max_streams": number;
"max_consumers": number;
"memory_max_stream_bytes": number;
"storage_max_stream_bytes": number;
"max_bytes_required": number;
}
export interface JetStreamUsage {
memory: number;

@@ -582,5 +616,13 @@ storage: number;

consumers: number;
}
export interface JetStreamUsageAccountLimits extends JetStreamUsage {
limits: AccountLimits;
}
export interface JetStreamAccountStats extends JetStreamUsageAccountLimits {
api: JetStreamApiStats;
limits: AccountLimits;
domain?: string;
tiers?: {
R1?: JetStreamUsageAccountLimits;
R3?: JetStreamUsageAccountLimits;
};
}

@@ -593,8 +635,2 @@ export interface JetStreamApiStats {

}
export interface AccountLimits {
"max_memory": number;
"max_storage": number;
"max_streams": number;
"max_consumers": number;
}
export interface ConsumerConfig extends ConsumerUpdateConfig {

@@ -625,2 +661,3 @@ "ack_policy": AckPolicy;

"inactive_threshold"?: Nanos;
"backoff"?: Nanos[];
}

@@ -689,2 +726,3 @@ export interface Consumer {

storage: StorageType;
bindOnly: boolean;
}

@@ -698,3 +736,5 @@ /**

export interface RoKV {
get(k: string): Promise<KvEntry | null>;
get(k: string, opts?: {
revision: number;
}): Promise<KvEntry | null>;
history(opts?: {

@@ -701,0 +741,0 @@ key?: string;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -46,3 +46,3 @@ "use strict";

const dns = require("dns");
const VERSION = "2.7.0-1";
const VERSION = "2.7.0";
const LANG = "nats.js";

@@ -49,0 +49,0 @@ class NodeTransport {

{
"name": "nats",
"version": "2.7.0-1",
"version": "2.7.0",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",

@@ -43,3 +43,3 @@ "keywords": [

"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch main https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.7.0 https://github.com/nats-io/nats.deno.git",
"fmt": "deno fmt ./src/ ./examples/ ./test/",

@@ -64,5 +64,6 @@ "prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build",

"devDependencies": {
"@types/node": "^16.11.6",
"ava": "^3.15.0",
"@types/node": "^17.0.27",
"ava": "^4.2.0",
"minimist": "^1.2.5",
"nats-jwt": "^0.0.1",
"nyc": "^15.1.0",

@@ -69,0 +70,0 @@ "shx": "^0.3.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc