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

num-client

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

num-client - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

web/num-client-0.0.12.js

8

dist/client.d.ts

@@ -1,5 +0,5 @@

import { Context, Location } from './context';
import { Context, NumLocation } from './context';
import { DnsClient } from './dnsclient';
import { NumUri } from './numuri';
export declare function createClient(dnsClient?: DnsClient): NumClient;
export declare const createClient: (dnsClient?: DnsClient | undefined) => NumClient;
export interface NumClient {

@@ -11,5 +11,5 @@ createContext(numAddress: NumUri): Context;

export interface CallbackHandler {
setLocation(l: Location): void;
setLocation(l: NumLocation): void;
setResult(r: string): void;
}
export declare function createDefaultCallbackHandler(): CallbackHandler;
export declare const createDefaultCallbackHandler: () => CallbackHandler;

@@ -54,28 +54,32 @@ "use strict";

var MODULE_SUFFIX = '/rcf.txt`';
function createClient(dnsClient) {
return new NumClientImpl(dnsClient);
}
exports.createClient = createClient;
function createDefaultCallbackHandler() {
return new DefaultCallbackHandler();
}
exports.createDefaultCallbackHandler = createDefaultCallbackHandler;
var colors = {
TRACE: chalk_1.default.magenta,
DEBUG: chalk_1.default.cyan,
INFO: chalk_1.default.blue,
WARN: chalk_1.default.yellow,
ERROR: chalk_1.default.red,
exports.createClient = function (dnsClient) { return new NumClientImpl(dnsClient); };
exports.createDefaultCallbackHandler = function () { return new DefaultCallbackHandler(); };
var colors = function (lvl) {
switch (lvl) {
case 'TRACE':
return chalk_1.default.magenta;
case 'DEBUG':
return chalk_1.default.cyan;
case 'INFO':
return chalk_1.default.blue;
case 'WARN':
return chalk_1.default.yellow;
case 'ERROR':
return chalk_1.default.red;
default:
return chalk_1.default.red;
}
};
var levels = {
TRACE: 'TRACE',
DEBUG: 'DEBUG',
INFO: 'INFO ',
WARN: 'WARN ',
ERROR: 'ERROR',
};
loglevel_plugin_prefix_1.default.reg(loglevel_1.default);
loglevel_plugin_prefix_1.default.apply(loglevel_1.default, {
format: function (level, name, timestamp) {
return chalk_1.default.gray("[" + timestamp + "]") + " " + colors[level](levels[level]) + " " + chalk_1.default.green(name + ":");
var levelName = level.toUpperCase();
var levelColour = colors(levelName);
var colouredLevel = levelColour(levelName);
if (name) {
return chalk_1.default.gray("[" + timestamp.toString() + "]") + " " + colouredLevel + " " + chalk_1.default.green(name + ":");
}
else {
return chalk_1.default.gray("[" + timestamp.toString() + "]") + " " + colouredLevel;
}
},

@@ -85,3 +89,3 @@ });

format: function (level, name, timestamp) {
return chalk_1.default.red.bold("[" + timestamp + "] " + level + " " + name + ":");
return name ? chalk_1.default.red.bold("[" + timestamp.toString() + "] " + level + " " + name + ":") : chalk_1.default.red.bold("[" + timestamp.toString() + "] " + level + ":");
},

@@ -145,7 +149,7 @@ });

ctx.result = null;
ctx.location = context_1.Location.NONE;
ctx.location = context_1.NumLocation.none;
return [2, null];
}
else if (e_1 instanceof exceptions_1.NumLookupRedirect) {
ctx.location = context_1.Location.INDEPENDENT;
ctx.location = context_1.NumLocation.independent;
ctx.handleQueryRedirect(e_1.message);

@@ -187,7 +191,7 @@ }

ctx.result = null;
ctx.location = context_1.Location.NONE;
ctx.location = context_1.NumLocation.none;
return [2, null];
}
else if (e_2 instanceof exceptions_1.NumLookupRedirect) {
ctx.location = context_1.Location.INDEPENDENT;
ctx.location = context_1.NumLocation.independent;
ctx.handleQueryRedirect(e_2.message);

@@ -216,6 +220,6 @@ }

switch (_a) {
case context_1.Location.INDEPENDENT: return [3, 1];
case context_1.Location.HOSTED: return [3, 3];
case context_1.Location.POPULATOR: return [3, 5];
case context_1.Location.NONE: return [3, 7];
case context_1.NumLocation.independent: return [3, 1];
case context_1.NumLocation.hosted: return [3, 3];
case context_1.NumLocation.populator: return [3, 5];
case context_1.NumLocation.none: return [3, 7];
}

@@ -247,3 +251,8 @@ return [3, 7];

case 4:
loglevel_1.default.info("Lookup result: '" + ctx.result + "', location: '" + ctx.location + "'");
if (ctx.result) {
loglevel_1.default.info("Lookup result: '" + ctx.result + "', location: '" + ctx.location + "'");
}
else {
loglevel_1.default.info("Lookup result: 'null', location: '" + ctx.location + "'");
}
return [2, ctx.result];

@@ -262,3 +271,3 @@ }

userVariables.forEach(function (v, k) {
uv += k + "=" + v + ";";
uv += k + "=" + v.toString() + ";";
});

@@ -265,0 +274,0 @@ enhancedModl = "" + uv + MODULE_PREFIX + port.n + MODULE_SUFFIX + ";" + modl;

import { NumUri } from './numuri';
import { ModuleDnsQueries } from './modulednsqueries';
export declare type UserVariable = string | number | boolean;
export declare enum Location {
HOSTED = "HOSTED",
INDEPENDENT = "INDEPENDENT",
POPULATOR = "POPULATOR",
NONE = "NONE"
export declare enum NumLocation {
hosted = "HOSTED",
independent = "INDEPENDENT",
populator = "POPULATOR",
none = "NONE"
}
export declare class Context {
location: Location;
location: NumLocation;
result: string | null;

@@ -13,0 +13,0 @@ readonly numAddress: NumUri;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = exports.Location = void 0;
exports.Context = exports.NumLocation = void 0;
var numuri_1 = require("./numuri");

@@ -14,12 +14,12 @@ var modulednsqueries_1 = require("./modulednsqueries");

var MAX_NUM_REDIRECTS = 3;
var Location;
(function (Location) {
Location["HOSTED"] = "HOSTED";
Location["INDEPENDENT"] = "INDEPENDENT";
Location["POPULATOR"] = "POPULATOR";
Location["NONE"] = "NONE";
})(Location = exports.Location || (exports.Location = {}));
var NumLocation;
(function (NumLocation) {
NumLocation["hosted"] = "HOSTED";
NumLocation["independent"] = "INDEPENDENT";
NumLocation["populator"] = "POPULATOR";
NumLocation["none"] = "NONE";
})(NumLocation = exports.NumLocation || (exports.NumLocation = {}));
var Context = (function () {
function Context(numAddress) {
this.location = Location.INDEPENDENT;
this.location = NumLocation.independent;
this.result = null;

@@ -63,6 +63,6 @@ this.redirectCount = 0;

switch (this.location) {
case Location.INDEPENDENT:
case NumLocation.independent:
this.handleIndependentQueryRedirect(redirect);
break;
case Location.HOSTED:
case NumLocation.hosted:
this.handleHostedQueryRedirect(redirect);

@@ -69,0 +69,0 @@ break;

@@ -15,2 +15,2 @@ export declare class DoHResolver {

}
export declare function createDnsClient(resolver?: DoHResolver): DnsClient;
export declare const createDnsClient: (resolver?: DoHResolver | undefined) => DnsClient;

@@ -68,6 +68,3 @@ "use strict";

exports.Question = Question;
function createDnsClient(resolver) {
return new DnsClientImpl(resolver);
}
exports.createDnsClient = createDnsClient;
exports.createDnsClient = function (resolver) { return new DnsClientImpl(resolver); };
var DEFAULT_RESOLVER = new DoHResolver('Google', 'https://dns.google.com/resolve');

@@ -118,3 +115,3 @@ var DnsClientImpl = (function () {

case 0:
loglevel_1.default.info("Query made using " + resolver.name + " for the DNS " + question.type + " record(s) at " + question.name + " dnssec:" + question.dnssec);
loglevel_1.default.info("Query made using " + resolver.name + " for the DNS " + question.type + " record(s) at " + question.name + " dnssec:" + question.dnssec.toString());
params = "name=" + question.name + "&type=" + question.type + "&dnssec=" + (question.dnssec ? '1' : '0');

@@ -156,3 +153,3 @@ url = resolver.url + "?" + params;

}());
function joinParts(item) {
var joinParts = function (item) {
if (item.type === 5) {

@@ -174,3 +171,3 @@ throw new exceptions_1.InvalidDnsResponseException('Found CNAME');

return joined;
}
};
//# sourceMappingURL=dnsclient.js.map

@@ -5,2 +5,2 @@ import { DnsClient } from './dnsclient';

}
export declare function createDnsServices(dnsClient?: DnsClient): DnsServices;
export declare const createDnsServices: (dnsClient?: DnsClient | undefined) => DnsServices;

@@ -47,6 +47,3 @@ "use strict";

var MATCH_MULTIPART_RECORD_FRAGMENT = /(^\d+\|.*)|(\d+\/\d+\|@n=\d+;.*)/;
function createDnsServices(dnsClient) {
return new DnsServicesImpl(dnsClient);
}
exports.createDnsServices = createDnsServices;
exports.createDnsServices = function (dnsClient) { return new DnsServicesImpl(dnsClient); };
var DnsServicesImpl = (function () {

@@ -53,0 +50,0 @@ function DnsServicesImpl(dnsClient) {

@@ -8,3 +8,4 @@ export declare class NumException extends Error {

export declare class NumBadUrlException extends NumException {
constructor(msg: string, _cause: Error);
readonly cause: Error;
constructor(msg: string, cause: Error);
}

@@ -11,0 +12,0 @@ export declare class NumInvalidDnsQueryException extends NumException {

@@ -35,4 +35,6 @@ "use strict";

__extends(NumBadUrlException, _super);
function NumBadUrlException(msg, _cause) {
return _super.call(this, msg) || this;
function NumBadUrlException(msg, cause) {
var _this = _super.call(this, msg) || this;
_this.cause = cause;
return _this;
}

@@ -39,0 +41,0 @@ return NumBadUrlException;

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

export declare function hashByDepth(normalisedDomain: string, depth: number): string;
export declare const hashByDepth: (normalisedDomain: string, depth: number) => string;

@@ -8,5 +8,5 @@ "use strict";

var crypto_js_1 = __importDefault(require("crypto-js"));
var any_base_1 = __importDefault(require("any-base"));
var hexToBase36 = any_base_1.default(any_base_1.default.HEX, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
function hashByDepth(normalisedDomain, depth) {
var anyBase = require('any-base');
var hexToBase36 = anyBase(anyBase.HEX, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
exports.hashByDepth = function (normalisedDomain, depth) {
var hashed = crypto_js_1.default.SHA1(normalisedDomain).toString();

@@ -19,4 +19,3 @@ var converted = hexToBase36(hashed).toLowerCase();

return dottedHashByDepth;
}
exports.hashByDepth = hashByDepth;
};
//# sourceMappingURL=hashutils.js.map

@@ -16,4 +16,4 @@ import { NumUri, PositiveInteger } from './numuri';

}
export declare function createDomainLookupGenerator(numUri: NumUri): LookupGenerator;
export declare function createEmailLookupGenerator(numUri: NumUri): EmailLookupGenerator;
export declare function createUrlLookupGenerator(numUri: NumUri): LookupGenerator;
export declare const createDomainLookupGenerator: (numUri: NumUri) => LookupGenerator;
export declare const createEmailLookupGenerator: (numUri: NumUri) => EmailLookupGenerator;
export declare const createUrlLookupGenerator: (numUri: NumUri) => LookupGenerator;

@@ -32,14 +32,5 @@ "use strict";

var DEFAULT_DEPTH = 3;
function createDomainLookupGenerator(numUri) {
return new DomainLookupGenerator(numUri);
}
exports.createDomainLookupGenerator = createDomainLookupGenerator;
function createEmailLookupGenerator(numUri) {
return new EmailLookupGeneratorImpl(numUri);
}
exports.createEmailLookupGenerator = createEmailLookupGenerator;
function createUrlLookupGenerator(numUri) {
return new UrlLookupGenerator(numUri);
}
exports.createUrlLookupGenerator = createUrlLookupGenerator;
exports.createDomainLookupGenerator = function (numUri) { return new DomainLookupGenerator(numUri); };
exports.createEmailLookupGenerator = function (numUri) { return new EmailLookupGeneratorImpl(numUri); };
exports.createUrlLookupGenerator = function (numUri) { return new UrlLookupGenerator(numUri); };
var BaseLookupGenerator = (function () {

@@ -86,8 +77,8 @@ function BaseLookupGenerator(numUri) {

};
BaseLookupGenerator.prototype.validate = function (_numId, _moduleId) {
throw new Error('Not implemented');
BaseLookupGenerator.prototype.validate = function (numId, moduleId) {
throw new Error("Not implemented: valdate(" + numId + ", " + moduleId + ")");
};
return BaseLookupGenerator;
}());
function transformBranch(s) {
var transformBranch = function (s) {
if (s === '/') {

@@ -102,4 +93,4 @@ return '';

.join('.');
}
function normaliseDomainName(domainName) {
};
var normaliseDomainName = function (domainName) {
if (!domainName) {

@@ -137,4 +128,4 @@ throw new exceptions_1.NumInvalidParameterException('Null domain name cannot be normalised');

return result;
}
function normalisePath(path) {
};
var normalisePath = function (path) {
var result = '/';

@@ -152,3 +143,3 @@ if (path.length > 0) {

return result;
}
};
var DomainLookupGenerator = (function (_super) {

@@ -155,0 +146,0 @@ __extends(DomainLookupGenerator, _super);

@@ -1,6 +0,6 @@

import { Location } from './context';
import { NumLocation } from './context';
export interface LookupLocationStateMachine {
complete(): boolean;
step(result: boolean | number): Promise<Location>;
step(result: boolean | number): Promise<NumLocation>;
}
export declare function createLookupLocationStateMachine(delays?: number[]): LookupLocationStateMachine;
export declare const createLookupLocationStateMachine: (delays?: number[] | undefined) => LookupLocationStateMachine;

@@ -46,23 +46,20 @@ "use strict";

var delay_1 = __importDefault(require("delay"));
function createLookupLocationStateMachine(delays) {
return new LookupLocationStateMachineImpl(delays);
}
exports.createLookupLocationStateMachine = createLookupLocationStateMachine;
exports.createLookupLocationStateMachine = function (delays) { return new LookupLocationStateMachineImpl(delays); };
var LookupState;
(function (LookupState) {
LookupState["INDY1"] = "INDY1";
LookupState["INDY2"] = "INDY2";
LookupState["HOSTED1"] = "HOSTED1";
LookupState["HOSTED2"] = "HOSTED2";
LookupState["POP0"] = "POP0";
LookupState["POP1"] = "POP1";
LookupState["POP2"] = "POP2";
LookupState["POP3"] = "POP3";
LookupState["POP4"] = "POP4";
LookupState["POP5"] = "POP5";
LookupState["POP6"] = "POP6";
LookupState["POP7"] = "POP7";
LookupState["POP8"] = "POP8";
LookupState["ERROR"] = "ERROR";
LookupState["SUCCESS"] = "SUCCESS";
LookupState["indy1"] = "INDY1";
LookupState["indy2"] = "INDY2";
LookupState["hosted1"] = "HOSTED1";
LookupState["hosted2"] = "HOSTED2";
LookupState["pop0"] = "POP0";
LookupState["pop1"] = "POP1";
LookupState["pop2"] = "POP2";
LookupState["pop3"] = "POP3";
LookupState["pop4"] = "POP4";
LookupState["pop5"] = "POP5";
LookupState["pop6"] = "POP6";
LookupState["pop7"] = "POP7";
LookupState["pop8"] = "POP8";
LookupState["failed"] = "ERROR";
LookupState["success"] = "SUCCESS";
})(LookupState || (LookupState = {}));

@@ -72,7 +69,7 @@ var DEFAULT_DELAYS = [2000, 2000, 2000, 2000, 5000, 5000, 5000, 5000];

function LookupLocationStateMachineImpl(delays) {
this.state = LookupState.INDY1;
this.state = LookupState.indy1;
this.delays = delays ? DEFAULT_DELAYS.map(function (n, i) { return (i < delays.length ? delays[i] : n); }) : DEFAULT_DELAYS;
}
LookupLocationStateMachineImpl.prototype.complete = function () {
return this.state === LookupState.SUCCESS || this.state === LookupState.ERROR;
return this.state === LookupState.success || this.state === LookupState.failed;
};

@@ -104,17 +101,17 @@ LookupLocationStateMachineImpl.prototype.step = function (lookupResult) {

switch (this.state) {
case LookupState.INDY1:
case LookupState.INDY2:
result = context_1.Location.INDEPENDENT;
case LookupState.indy1:
case LookupState.indy2:
result = context_1.NumLocation.independent;
break;
case LookupState.HOSTED1:
case LookupState.HOSTED2:
result = context_1.Location.HOSTED;
case LookupState.hosted1:
case LookupState.hosted2:
result = context_1.NumLocation.hosted;
break;
case LookupState.ERROR:
result = context_1.Location.NONE;
case LookupState.failed:
result = context_1.NumLocation.none;
break;
default:
result = context_1.Location.POPULATOR;
result = context_1.NumLocation.populator;
}
this.state = LookupState.SUCCESS;
this.state = LookupState.success;
return result;

@@ -124,3 +121,3 @@ };

return __awaiter(this, void 0, void 0, function () {
var _a;
var _a, state;
return __generator(this, function (_b) {

@@ -131,77 +128,79 @@ switch (_b.label) {

switch (_a) {
case LookupState.INDY1: return [3, 1];
case LookupState.HOSTED1: return [3, 2];
case LookupState.POP0: return [3, 3];
case LookupState.POP1: return [3, 5];
case LookupState.POP2: return [3, 7];
case LookupState.POP3: return [3, 9];
case LookupState.POP4: return [3, 11];
case LookupState.POP5: return [3, 13];
case LookupState.POP6: return [3, 15];
case LookupState.POP7: return [3, 17];
case LookupState.SUCCESS: return [3, 19];
case LookupState.POP8: return [3, 20];
case LookupState.INDY2: return [3, 20];
case LookupState.HOSTED2: return [3, 20];
case LookupState.ERROR: return [3, 20];
case LookupState.indy1: return [3, 1];
case LookupState.hosted1: return [3, 2];
case LookupState.pop0: return [3, 3];
case LookupState.pop1: return [3, 5];
case LookupState.pop2: return [3, 7];
case LookupState.pop3: return [3, 9];
case LookupState.pop4: return [3, 11];
case LookupState.pop5: return [3, 13];
case LookupState.pop6: return [3, 15];
case LookupState.pop7: return [3, 17];
case LookupState.success: return [3, 19];
case LookupState.pop8: return [3, 20];
case LookupState.indy2: return [3, 20];
case LookupState.hosted2: return [3, 20];
case LookupState.failed: return [3, 20];
}
return [3, 21];
case 1:
this.state = LookupState.HOSTED1;
return [2, context_1.Location.HOSTED];
this.state = LookupState.hosted1;
return [2, context_1.NumLocation.hosted];
case 2:
this.state = LookupState.POP0;
return [2, context_1.Location.POPULATOR];
this.state = LookupState.pop0;
return [2, context_1.NumLocation.populator];
case 3: return [4, this.checkStatus(result)];
case 4:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 5:
this.state = LookupState.POP2;
this.state = LookupState.pop2;
return [4, delay_1.default(this.delays[0])];
case 6:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 7:
this.state = LookupState.POP3;
this.state = LookupState.pop3;
return [4, delay_1.default(this.delays[1])];
case 8:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 9:
this.state = LookupState.POP4;
this.state = LookupState.pop4;
return [4, delay_1.default(this.delays[2])];
case 10:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 11:
this.state = LookupState.POP5;
this.state = LookupState.pop5;
return [4, delay_1.default(this.delays[4])];
case 12:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 13:
this.state = LookupState.POP6;
this.state = LookupState.pop6;
return [4, delay_1.default(this.delays[5])];
case 14:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 15:
this.state = LookupState.POP7;
this.state = LookupState.pop7;
return [4, delay_1.default(this.delays[6])];
case 16:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 17:
this.state = LookupState.POP8;
this.state = LookupState.pop8;
return [4, delay_1.default(this.delays[7])];
case 18:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 19: return [3, 22];
case 20:
this.state = LookupState.ERROR;
return [2, context_1.Location.NONE];
case 21: throw new Error("Invalid LookupState status: " + this.state);
case 22: return [2, context_1.Location.NONE];
this.state = LookupState.failed;
return [2, context_1.NumLocation.none];
case 21:
state = this.state;
throw new Error("Invalid LookupState status: " + state);
case 22: return [2, context_1.NumLocation.none];
}

@@ -227,16 +226,16 @@ });

case 1:
this.state = LookupState.POP1;
this.state = LookupState.pop1;
return [4, delay_1.default(this.delays[3])];
case 2:
_b.sent();
return [2, context_1.Location.POPULATOR];
return [2, context_1.NumLocation.populator];
case 3:
this.state = LookupState.INDY2;
return [2, context_1.Location.INDEPENDENT];
this.state = LookupState.indy2;
return [2, context_1.NumLocation.independent];
case 4:
this.state = LookupState.HOSTED2;
return [2, context_1.Location.HOSTED];
this.state = LookupState.hosted2;
return [2, context_1.NumLocation.hosted];
case 5:
this.state = LookupState.ERROR;
return [2, context_1.Location.NONE];
this.state = LookupState.failed;
return [2, context_1.NumLocation.none];
}

@@ -243,0 +242,0 @@ });

export interface ModlServices {
interpretNumRecord(modl: string, timeout: number): Promise<string>;
}
export declare function createModlServices(): ModlServices;
export declare function checkForRedirection(obj: any): void;
export declare const createModlServices: () => ModlServices;
export declare const checkForRedirection: (obj: any) => void;

@@ -47,7 +47,4 @@ "use strict";

var INTERPRETER_URL = 'https://api.apps.num.uk/v1/mtoj';
function createModlServices() {
return new ModlServicesImpl();
}
exports.createModlServices = createModlServices;
function checkForRedirection(obj) {
exports.createModlServices = function () { return new ModlServicesImpl(); };
exports.checkForRedirection = function (obj) {
if (typeof obj === 'object') {

@@ -62,8 +59,7 @@ for (var key in obj) {

}
checkForRedirection(obj[key]);
exports.checkForRedirection(obj[key]);
}
}
}
}
exports.checkForRedirection = checkForRedirection;
};
var ModlServicesImpl = (function () {

@@ -88,3 +84,3 @@ function ModlServicesImpl() {

if (response.status === 200) {
checkForRedirection(response.data);
exports.checkForRedirection(response.data);
return [2, JSON.stringify(response.data)];

@@ -91,0 +87,0 @@ }

@@ -11,21 +11,2 @@ import { NumUri, PositiveInteger } from './numuri';

}
export declare function createModuleDnsQueries(moduleId: PositiveInteger, numUri: NumUri): ModuleDnsQueriesImpl;
declare class ModuleDnsQueriesImpl implements ModuleDnsQueries {
private readonly moduleId;
private readonly numUri;
private _independentRecordLocation;
private readonly _rootIndependentRecordLocation;
private _hostedRecordLocation;
private readonly _rootHostedRecordLocation;
private readonly _populatorLocation;
constructor(moduleId: PositiveInteger, numUri: NumUri);
get populatorLocation(): string | null;
get independentRecordLocation(): string;
get hostedRecordLocation(): string;
setEmailRecordDistributionLevels(levels: PositiveInteger): void;
getHostedRecordPath(): string;
getIndependentRecordPath(): string;
redirectHostedPath(path: string): void;
redirectIndependentPath(path: string): void;
}
export {};
export declare const createModuleDnsQueries: (moduleId: PositiveInteger, numUri: NumUri) => ModuleDnsQueries;

@@ -11,6 +11,3 @@ "use strict";

var numuri_1 = require("./numuri");
function createModuleDnsQueries(moduleId, numUri) {
return new ModuleDnsQueriesImpl(moduleId, numUri);
}
exports.createModuleDnsQueries = createModuleDnsQueries;
exports.createModuleDnsQueries = function (moduleId, numUri) { return new ModuleDnsQueriesImpl(moduleId, numUri); };
var ModuleDnsQueriesImpl = (function () {

@@ -92,3 +89,3 @@ function ModuleDnsQueriesImpl(moduleId, numUri) {

}());
function toPath(domainPath) {
var toPath = function (domainPath) {
if (domainPath.includes('.')) {

@@ -98,4 +95,4 @@ return '/' + domainPath.split('.').reverse().join('/');

return "/" + domainPath;
}
function fromPath(path) {
};
var fromPath = function (path) {
if (path.includes('/')) {

@@ -109,3 +106,3 @@ return path

return path;
}
};
//# sourceMappingURL=modulednsqueries.js.map

@@ -14,4 +14,4 @@ export declare class NumUri {

}
export declare function buildNumUri(host: string, port?: number, userinfo?: string, path?: string): NumUri;
export declare function parseNumUri(uri: string): NumUri;
export declare const buildNumUri: (host: string, port?: number | undefined, userinfo?: string | undefined, path?: string | undefined) => NumUri;
export declare const parseNumUri: (uri: string) => NumUri;
export declare class PositiveInteger {

@@ -18,0 +18,0 @@ readonly n: number;

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

exports.NumUri = NumUri;
function buildNumUri(host, port, userinfo, path) {
exports.buildNumUri = function (host, port, userinfo, path) {
var thePort = port ? new PositiveInteger(port) : exports.MODULE_0;

@@ -50,5 +50,4 @@ var theUserInfo = userinfo ? new UrlUserInfo(userinfo) : exports.NO_USER_INFO;

return new NumUri(new Hostname(host), thePort, theUserInfo, thePath);
}
exports.buildNumUri = buildNumUri;
function parseNumUri(uri) {
};
exports.parseNumUri = function (uri) {
var u = url_1.parse(uri.includes('://') ? uri : 'num://' + uri);

@@ -62,4 +61,3 @@ var portNumber = notEmpty(u.port) ? Number.parseInt(u.port, 10) : 0;

return new NumUri(host, port, userInfo, path);
}
exports.parseNumUri = parseNumUri;
};
var isPositive = function (n) { return n > -1; };

@@ -101,3 +99,3 @@ var notEmpty = function (s) { return s && s.length > 0; };

Hostname.isValid = function (s) {
var matches = s.match(DOMAIN_REGEX);
var matches = DOMAIN_REGEX.exec(s);
return s.length <= MAX_DOMAIN_NAME_LENGTH && matches !== null && matches.length > 0;

@@ -111,3 +109,3 @@ };

this.s = s;
if (!s.startsWith('/') || !s.match(PATH_REGEX)) {
if (!s.startsWith('/') || !PATH_REGEX.exec(s)) {
throw new Error("Invalid URL path: '" + s + "'");

@@ -153,3 +151,3 @@ }

this.s = s;
if ((notEmpty(s) && !s.match(USERINFO_REGEX)) ||
if ((notEmpty(s) && !USERINFO_REGEX.exec(s)) ||
s.length > MAX_LOCAL_PART_LENGTH ||

@@ -156,0 +154,0 @@ s.startsWith('.') ||

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

export declare function resolvePath(base: string, redirect: string): string;
export declare const resolvePath: (base: string, redirect: string) => string;

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

var exceptions_1 = require("./exceptions");
function resolvePath(base, redirect) {
exports.resolvePath = function (base, redirect) {
var SEP = '/';

@@ -32,4 +32,3 @@ var basePath = base.endsWith(SEP) ? base.substr(0, base.length - 1) : base;

return SEP + pathStack.join(SEP);
}
exports.resolvePath = resolvePath;
};
//# sourceMappingURL=urlrelativepathresolver.js.map

@@ -16,3 +16,3 @@ // Copyright 2020 NUM Technology Ltd

import { createLookupLocationStateMachine } from './lookupstatemachine';
import { Context, Location, UserVariable } from './context';
import { Context, NumLocation, UserVariable } from './context';
import { createDnsServices, DnsServices } from './dnsservices';

@@ -36,7 +36,6 @@ import { DnsClient } from './dnsclient';

* Creates client
*
* @returns client
*/
export function createClient(dnsClient?: DnsClient): NumClient {
return new NumClientImpl(dnsClient);
}
export const createClient = (dnsClient?: DnsClient): NumClient => new NumClientImpl(dnsClient);

@@ -56,2 +55,3 @@ /**

* Returns a fully interpreted NUM record as a JSON string
*
* @param ctx

@@ -65,2 +65,3 @@ * @param handler

* Returns the raw MODL record, after redirection if appropriate
*
* @param ctx

@@ -81,3 +82,3 @@ * @param handler

*/
setLocation(l: Location): void;
setLocation(l: NumLocation): void;

@@ -93,7 +94,7 @@ /**

* Creates default callback handler
*
* @returns default callback handler
*/
export function createDefaultCallbackHandler(): CallbackHandler {
return new DefaultCallbackHandler();
}
export const createDefaultCallbackHandler = (): CallbackHandler => new DefaultCallbackHandler();
//------------------------------------------------------------------------------------------------------------------------

@@ -106,23 +107,31 @@ // Internals

const colors: any = {
TRACE: chalk.magenta,
DEBUG: chalk.cyan,
INFO: chalk.blue,
WARN: chalk.yellow,
ERROR: chalk.red,
const colors = (lvl: string) => {
switch (lvl) {
case 'TRACE':
return chalk.magenta;
case 'DEBUG':
return chalk.cyan;
case 'INFO':
return chalk.blue;
case 'WARN':
return chalk.yellow;
case 'ERROR':
return chalk.red;
default:
return chalk.red;
}
};
const levels: any = {
TRACE: 'TRACE',
DEBUG: 'DEBUG',
INFO: 'INFO ',
WARN: 'WARN ',
ERROR: 'ERROR',
};
prefix.reg(log);
prefix.apply(log, {
format(level, name, timestamp) {
return `${chalk.gray(`[${timestamp}]`)} ${colors[level](levels[level])} ${chalk.green(`${name}:`)}`;
format: (level: string, name: string | undefined, timestamp: Date | string) => {
const levelName = level.toUpperCase();
const levelColour = colors(levelName);
const colouredLevel: string = levelColour(levelName);
if (name) {
return `${chalk.gray(`[${timestamp.toString()}]`)} ${colouredLevel} ${chalk.green(`${name}:`)}`;
} else {
return `${chalk.gray(`[${timestamp.toString()}]`)} ${colouredLevel}`;
}
},

@@ -132,5 +141,4 @@ });

prefix.apply(log.getLogger('critical'), {
format(level, name, timestamp) {
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
},
format: (level: string, name: string | undefined, timestamp: Date | string) =>
name ? chalk.red.bold(`[${timestamp.toString()}] ${level} ${name}:`) : chalk.red.bold(`[${timestamp.toString()}] ${level}:`),
});

@@ -144,3 +152,3 @@

class DefaultCallbackHandler implements CallbackHandler {
private location: Location | null = null;
private location: NumLocation | null = null;
private result: string | null = null;

@@ -150,5 +158,6 @@

* Sets location
*
* @param l
*/
setLocation(l: Location): void {
setLocation(l: NumLocation): void {
this.location = l;

@@ -159,2 +168,3 @@ }

* Sets result
*
* @param r

@@ -168,5 +178,6 @@ */

* Gets location
*
* @returns location
*/
getLocation(): Location | null {
getLocation(): NumLocation | null {
return this.location;

@@ -177,2 +188,3 @@ }

* Gets result
*
* @returns result

@@ -194,2 +206,3 @@ */

* Creates an instance of num client impl.
*
* @param [dnsClient]

@@ -203,2 +216,3 @@ */

* Creates an instance of num client impl.
*
* @param numAddress

@@ -212,2 +226,3 @@ */

* Retrieves num record and interprets it to JSON
*
* @param ctx

@@ -235,6 +250,6 @@ * @param handler

ctx.result = null;
ctx.location = Location.NONE;
ctx.location = NumLocation.none;
return null;
} else if (e instanceof NumLookupRedirect) {
ctx.location = Location.INDEPENDENT;
ctx.location = NumLocation.independent;
ctx.handleQueryRedirect(e.message);

@@ -248,2 +263,3 @@ }

* Retrieves raw MODL record - i.e. not interpreted
*
* @param ctx

@@ -270,6 +286,6 @@ * @param handler

ctx.result = null;
ctx.location = Location.NONE;
ctx.location = NumLocation.none;
return null;
} else if (e instanceof NumLookupRedirect) {
ctx.location = Location.INDEPENDENT;
ctx.location = NumLocation.independent;
ctx.handleQueryRedirect(e.message);

@@ -283,2 +299,3 @@ }

* Retrieves modl record internal
*
* @param ctx

@@ -292,9 +309,9 @@ * @param handler

switch (ctx.location) {
case Location.INDEPENDENT:
case NumLocation.independent:
return await this.dnsQuery(ctx.queries.independentRecordLocation, ctx);
case Location.HOSTED:
case NumLocation.hosted:
return await this.dnsQuery(ctx.queries.hostedRecordLocation, ctx);
case Location.POPULATOR:
case NumLocation.populator:
return await this.populatorQuery(ctx);
case Location.NONE:
case NumLocation.none:
default:

@@ -313,3 +330,7 @@ return false;

log.info(`Lookup result: '${ctx.result}', location: '${ctx.location}'`);
if (ctx.result) {
log.info(`Lookup result: '${ctx.result}', location: '${ctx.location}'`);
} else {
log.info(`Lookup result: 'null', location: '${ctx.location}'`);
}

@@ -321,2 +342,3 @@ return ctx.result;

* Interprets a MODL record for the given module
*
* @param modl

@@ -330,3 +352,3 @@ * @param port

userVariables.forEach((v, k) => {
uv += `${k}=${v};`;
uv += `${k}=${v.toString()};`;
});

@@ -340,2 +362,3 @@

* Independent or Hosted query
*
* @returns

@@ -354,2 +377,3 @@ */

* Populator query
*
* @returns

@@ -356,0 +380,0 @@ */

@@ -31,7 +31,8 @@ // Copyright 2020 NUM Technology Ltd

*/
export enum Location {
HOSTED = 'HOSTED',
INDEPENDENT = 'INDEPENDENT',
POPULATOR = 'POPULATOR',
NONE = 'NONE',
// eslint-disable-next-line no-shadow
export enum NumLocation {
hosted = 'HOSTED',
independent = 'INDEPENDENT',
populator = 'POPULATOR',
none = 'NONE',
}

@@ -43,7 +44,7 @@

export class Context {
public location: Location = Location.INDEPENDENT;
public location = NumLocation.independent;
public result: string | null = null;
public readonly numAddress: NumUri;
_queries: ModuleDnsQueries;
redirectCount: number = 0;
redirectCount = 0;
userVariables: Map<string, UserVariable>;

@@ -53,6 +54,7 @@ /**

*/
dnssec: boolean = false;
dnssec = false;
/**
* Creates an instance of context.
*
* @param numAddress

@@ -68,6 +70,7 @@ */

* Sets user variable
*
* @param name
* @param value
*/
setUserVariable(name: string, value: UserVariable) {
setUserVariable(name: string, value: UserVariable): void {
this.userVariables.set(name, value);

@@ -88,3 +91,3 @@ }

*/
get queries() {
get queries(): ModuleDnsQueries {
return this._queries;

@@ -114,10 +117,10 @@ }

} catch (e) {
throw new NumInvalidRedirectException(e.message);
throw new NumInvalidRedirectException((e as Error).message);
}
} else {
switch (this.location) {
case Location.INDEPENDENT:
case NumLocation.independent:
this.handleIndependentQueryRedirect(redirect);
break;
case Location.HOSTED:
case NumLocation.hosted:
this.handleHostedQueryRedirect(redirect);

@@ -124,0 +127,0 @@ break;

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

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// Copyright 2020 NUM Technology Ltd

@@ -65,8 +66,7 @@ //

* Creates dns client
*
* @param [resolver]
* @returns dns client
*/
export function createDnsClient(resolver?: DoHResolver): DnsClient {
return new DnsClientImpl(resolver);
}
export const createDnsClient = (resolver?: DoHResolver): DnsClient => new DnsClientImpl(resolver);

@@ -83,2 +83,3 @@ //------------------------------------------------------------------------------------------------------------------------

readonly data: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
readonly TTL: number;

@@ -97,2 +98,3 @@ }

* Creates an instance of dns client impl.
*
* @param [resolver]

@@ -107,2 +109,3 @@ */

* Querys dns client impl
*
* @param question

@@ -133,2 +136,3 @@ * @returns query

* Querys using resolver
*
* @param question

@@ -139,3 +143,3 @@ * @param resolver

async queryUsingResolver(question: Question, resolver: DoHResolver): Promise<string[]> {
log.info(`Query made using ${resolver.name} for the DNS ${question.type} record(s) at ${question.name} dnssec:${question.dnssec}`);
log.info(`Query made using ${resolver.name} for the DNS ${question.type} record(s) at ${question.name} dnssec:${question.dnssec.toString()}`);

@@ -172,6 +176,7 @@ const params = `name=${question.name}&type=${question.type}&dnssec=` + (question.dnssec ? '1' : '0');

* Joins parts
*
* @param item
* @returns parts
*/
function joinParts(item: Answer): string {
const joinParts = (item: Answer): string => {
if (item.type === 5) {

@@ -196,2 +201,2 @@ throw new InvalidDnsResponseException('Found CNAME');

return joined;
}
};

@@ -34,8 +34,7 @@ // Copyright 2020 NUM Technology Ltd

* Creates dns services
*
* @param [dnsClient]
* @returns dns services
*/
export function createDnsServices(dnsClient?: DnsClient): DnsServices {
return new DnsServicesImpl(dnsClient);
}
export const createDnsServices = (dnsClient?: DnsClient): DnsServices => new DnsServicesImpl(dnsClient);

@@ -53,2 +52,3 @@ //------------------------------------------------------------------------------------------------------------------------

* Creates an instance of dns services impl.
*
* @param [dnsClient]

@@ -62,2 +62,3 @@ */

* Rebuilds txt record content
*
* @param records

@@ -139,2 +140,3 @@ * @returns txt record content

* Gets record from dns
*
* @param query

@@ -141,0 +143,0 @@ * @param checkDnsSecValidity

@@ -41,4 +41,7 @@ // Copyright 2020 NUM Technology Ltd

export class NumBadUrlException extends NumException {
constructor(msg: string, _cause: Error) {
readonly cause: Error;
constructor(msg: string, cause: Error) {
super(msg);
this.cause = cause;
}

@@ -45,0 +48,0 @@ }

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

/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// Copyright 2020 NUM Technology Ltd

@@ -17,7 +18,8 @@ //

import CryptoJS from 'crypto-js';
// @ts-ignore
import anyBase from 'any-base';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const anyBase = require('any-base');
type AnyBase = (s: string) => string;
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const hexToBase36 = anyBase(anyBase.HEX, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') as AnyBase;

@@ -36,3 +38,3 @@

*/
export function hashByDepth(normalisedDomain: string, depth: number): string {
export const hashByDepth = (normalisedDomain: string, depth: number): string => {
const hashed = CryptoJS.SHA1(normalisedDomain).toString();

@@ -47,2 +49,2 @@ const converted = hexToBase36(hashed).toLowerCase();

return dottedHashByDepth;
}
};

@@ -56,26 +56,23 @@ // Copyright 2020 NUM Technology Ltd

* Creates domain lookup generator
*
* @param numId
* @returns domain lookup generator
*/
export function createDomainLookupGenerator(numUri: NumUri): LookupGenerator {
return new DomainLookupGenerator(numUri);
}
export const createDomainLookupGenerator = (numUri: NumUri): LookupGenerator => new DomainLookupGenerator(numUri);
/**
* Creates email lookup generator
*
* @param numId
* @returns email lookup generator
*/
export function createEmailLookupGenerator(numUri: NumUri): EmailLookupGenerator {
return new EmailLookupGeneratorImpl(numUri);
}
export const createEmailLookupGenerator = (numUri: NumUri): EmailLookupGenerator => new EmailLookupGeneratorImpl(numUri);
/**
* Creates url lookup generator
*
* @param numId
* @returns url lookup generator
*/
export function createUrlLookupGenerator(numUri: NumUri): LookupGenerator {
return new UrlLookupGenerator(numUri);
}
export const createUrlLookupGenerator = (numUri: NumUri): LookupGenerator => new UrlLookupGenerator(numUri);

@@ -94,2 +91,3 @@ //------------------------------------------------------------------------------------------------------------------------

* Creates an instance of base lookup generator.
*
* @param numId

@@ -104,2 +102,3 @@ */

* Gets independent location
*
* @param moduleId

@@ -115,2 +114,3 @@ * @returns

* Gets hosted location
*
* @param moduleId

@@ -126,2 +126,3 @@ * @returns

* Determines whether domain root is
*
* @returns

@@ -135,2 +136,3 @@ */

* Gets populator location
*
* @param moduleId

@@ -145,2 +147,3 @@ * @returns

* Gets root independent location
*
* @param moduleId

@@ -155,2 +158,3 @@ * @returns

* Gets root independent location no module number
*
* @param addTrailingDot

@@ -169,2 +173,3 @@ * @returns

* Gets root hosted location
*
* @param moduleId

@@ -179,2 +184,3 @@ * @returns

* Gets root hosted location no module number
*
* @param addTrailingDot

@@ -193,7 +199,8 @@ * @returns

* Validates base lookup generator
* @param _numId
* @param _moduleId
*
* @param numId
* @param moduleId
*/
validate(_numId: string, _moduleId: number) {
throw new Error('Not implemented');
validate(numId: string, moduleId: number) {
throw new Error(`Not implemented: valdate(${numId}, ${moduleId})`);
}

@@ -204,6 +211,7 @@ }

* Transforms branch
*
* @param s
* @returns branch
*/
function transformBranch(s: string): string {
const transformBranch = (s: string): string => {
if (s === '/') {

@@ -219,10 +227,11 @@ return '';

.join('.');
}
};
/**
* Normalises domain name
*
* @param domainName
* @returns domain name
*/
function normaliseDomainName(domainName: string): string {
const normaliseDomainName = (domainName: string): string => {
if (!domainName) {

@@ -265,10 +274,11 @@ throw new NumInvalidParameterException('Null domain name cannot be normalised');

return result;
}
};
/**
* Normalises path
*
* @param path
* @returns path
*/
function normalisePath(path: string): string {
const normalisePath = (path: string): string => {
let result = '/';

@@ -290,3 +300,3 @@ if (path.length > 0) {

return result;
}
};

@@ -342,2 +352,3 @@ /**

* Gets independent location
*
* @param moduleId

@@ -353,2 +364,3 @@ * @returns independent location

* Gets hosted location
*
* @param moduleId

@@ -364,2 +376,3 @@ * @returns hosted location

* Gets populator location
*
* @param moduleId

@@ -375,2 +388,3 @@ * @returns populator location

* Gets root independent location
*
* @param moduleId

@@ -385,2 +399,3 @@ * @returns root independent location

* Gets root independent location no module number
*
* @param addTrailingDot

@@ -399,2 +414,3 @@ * @returns root independent location no module number

* Gets root hosted location
*
* @param moduleId

@@ -412,2 +428,3 @@ * @returns root hosted location

* Gets root hosted location no module number
*
* @param addTrailingDot

@@ -426,2 +443,3 @@ * @returns root hosted location no module number

* Gets distributed independent location
*
* @param moduleId

@@ -439,2 +457,3 @@ * @param levels

* Gets distributed hosted location
*
* @param moduleId

@@ -441,0 +460,0 @@ * @param levels

@@ -15,3 +15,3 @@ // Copyright 2020 NUM Technology Ltd

//
import { Location } from './context';
import { NumLocation } from './context';
import log from 'loglevel';

@@ -28,3 +28,3 @@ import delay from 'delay';

complete(): boolean;
step(result: boolean | number): Promise<Location>;
step(result: boolean | number): Promise<NumLocation>;
}

@@ -34,7 +34,6 @@

* Creates lookup location state machine
*
* @returns lookup location state machine
*/
export function createLookupLocationStateMachine(delays?: number[]): LookupLocationStateMachine {
return new LookupLocationStateMachineImpl(delays);
}
export const createLookupLocationStateMachine = (delays?: number[]): LookupLocationStateMachine => new LookupLocationStateMachineImpl(delays);

@@ -47,18 +46,19 @@ //------------------------------------------------------------------------------------------------------------------------

*/
// eslint-disable-next-line no-shadow
enum LookupState {
INDY1 = 'INDY1',
INDY2 = 'INDY2',
HOSTED1 = 'HOSTED1',
HOSTED2 = 'HOSTED2',
POP0 = 'POP0',
POP1 = 'POP1',
POP2 = 'POP2',
POP3 = 'POP3',
POP4 = 'POP4',
POP5 = 'POP5',
POP6 = 'POP6',
POP7 = 'POP7',
POP8 = 'POP8',
ERROR = 'ERROR',
SUCCESS = 'SUCCESS',
indy1 = 'INDY1',
indy2 = 'INDY2',
hosted1 = 'HOSTED1',
hosted2 = 'HOSTED2',
pop0 = 'POP0',
pop1 = 'POP1',
pop2 = 'POP2',
pop3 = 'POP3',
pop4 = 'POP4',
pop5 = 'POP5',
pop6 = 'POP6',
pop7 = 'POP7',
pop8 = 'POP8',
failed = 'ERROR',
success = 'SUCCESS',
}

@@ -76,6 +76,7 @@

* Creates an instance of lookup location state machine.
*
* @param delays An array of up to 8 delay values in milliseconds to override DEFAULT_DELAYS
*/
constructor(delays?: number[]) {
this.state = LookupState.INDY1;
this.state = LookupState.indy1;
this.delays = delays ? DEFAULT_DELAYS.map((n, i) => (i < delays.length ? delays[i] : n)) : DEFAULT_DELAYS;

@@ -86,6 +87,7 @@ }

* Completes lookup location state machine
*
* @returns true if complete
*/
complete(): boolean {
return this.state === LookupState.SUCCESS || this.state === LookupState.ERROR;
return this.state === LookupState.success || this.state === LookupState.failed;
}

@@ -95,6 +97,7 @@

* Steps lookup location state machine
*
* @param f
* @param ctx
*/
async step(lookupResult: boolean | number): Promise<Location> {
async step(lookupResult: boolean | number): Promise<NumLocation> {
log.debug('LookupLocationStateMachine - before step: ' + this.state);

@@ -109,20 +112,20 @@ const result = typeof lookupResult === 'boolean' && lookupResult === true ? this.success() : await this.fail(lookupResult);

*/
private success(): Location {
let result: Location;
private success(): NumLocation {
let result: NumLocation;
switch (this.state) {
case LookupState.INDY1:
case LookupState.INDY2:
result = Location.INDEPENDENT;
case LookupState.indy1:
case LookupState.indy2:
result = NumLocation.independent;
break;
case LookupState.HOSTED1:
case LookupState.HOSTED2:
result = Location.HOSTED;
case LookupState.hosted1:
case LookupState.hosted2:
result = NumLocation.hosted;
break;
case LookupState.ERROR:
result = Location.NONE;
case LookupState.failed:
result = NumLocation.none;
break;
default:
result = Location.POPULATOR;
result = NumLocation.populator;
}
this.state = LookupState.SUCCESS;
this.state = LookupState.success;

@@ -134,56 +137,58 @@ return result;

* Fails lookup location state machines
*
* @param result
* @param ctx
*/
private async fail(result: number | false): Promise<Location> {
private async fail(result: number | false): Promise<NumLocation> {
switch (this.state) {
case LookupState.INDY1:
this.state = LookupState.HOSTED1;
return Location.HOSTED;
case LookupState.HOSTED1:
this.state = LookupState.POP0;
return Location.POPULATOR;
case LookupState.POP0:
case LookupState.indy1:
this.state = LookupState.hosted1;
return NumLocation.hosted;
case LookupState.hosted1:
this.state = LookupState.pop0;
return NumLocation.populator;
case LookupState.pop0:
await this.checkStatus(result);
return Location.POPULATOR;
case LookupState.POP1:
this.state = LookupState.POP2;
return NumLocation.populator;
case LookupState.pop1:
this.state = LookupState.pop2;
await delay(this.delays[0]);
return Location.POPULATOR;
case LookupState.POP2:
this.state = LookupState.POP3;
return NumLocation.populator;
case LookupState.pop2:
this.state = LookupState.pop3;
await delay(this.delays[1]);
return Location.POPULATOR;
case LookupState.POP3:
this.state = LookupState.POP4;
return NumLocation.populator;
case LookupState.pop3:
this.state = LookupState.pop4;
await delay(this.delays[2]);
return Location.POPULATOR;
case LookupState.POP4:
this.state = LookupState.POP5;
return NumLocation.populator;
case LookupState.pop4:
this.state = LookupState.pop5;
await delay(this.delays[4]);
return Location.POPULATOR;
case LookupState.POP5:
this.state = LookupState.POP6;
return NumLocation.populator;
case LookupState.pop5:
this.state = LookupState.pop6;
await delay(this.delays[5]);
return Location.POPULATOR;
case LookupState.POP6:
this.state = LookupState.POP7;
return NumLocation.populator;
case LookupState.pop6:
this.state = LookupState.pop7;
await delay(this.delays[6]);
return Location.POPULATOR;
case LookupState.POP7:
this.state = LookupState.POP8;
return NumLocation.populator;
case LookupState.pop7:
this.state = LookupState.pop8;
await delay(this.delays[7]);
return Location.POPULATOR;
case LookupState.SUCCESS:
return NumLocation.populator;
case LookupState.success:
break;
case LookupState.POP8:
case LookupState.INDY2:
case LookupState.HOSTED2:
case LookupState.ERROR:
this.state = LookupState.ERROR;
return Location.NONE;
case LookupState.pop8:
case LookupState.indy2:
case LookupState.hosted2:
case LookupState.failed:
this.state = LookupState.failed;
return NumLocation.none;
default:
throw new Error(`Invalid LookupState status: ${this.state}`);
const state: string = this.state;
throw new Error(`Invalid LookupState status: ${state}`);
}
return Location.NONE;
return NumLocation.none;
}

@@ -193,24 +198,25 @@

* Checks status
*
* @param result
* @param ctx
*/
private async checkStatus(result: number | false): Promise<Location> {
private async checkStatus(result: number | false): Promise<NumLocation> {
switch (result) {
case 1:
this.state = LookupState.POP1;
this.state = LookupState.pop1;
await delay(this.delays[3]);
return Location.POPULATOR;
return NumLocation.populator;
case 2:
this.state = LookupState.INDY2;
return Location.INDEPENDENT;
this.state = LookupState.indy2;
return NumLocation.independent;
case 3:
this.state = LookupState.HOSTED2;
return Location.HOSTED;
this.state = LookupState.hosted2;
return NumLocation.hosted;
case 4:
case false:
default:
this.state = LookupState.ERROR;
return Location.NONE;
this.state = LookupState.failed;
return NumLocation.none;
}
}
}

@@ -33,7 +33,6 @@ // Copyright 2020 NUM Technology Ltd

* Creates modl services
*
* @returns modl services
*/
export function createModlServices(): ModlServices {
return new ModlServicesImpl();
}
export const createModlServices = (): ModlServices => new ModlServicesImpl();

@@ -46,8 +45,11 @@ /**

*/
export function checkForRedirection(obj: any): void {
// Check the pairs in a Map
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const checkForRedirection = (obj: any): void => {
if (typeof obj === 'object') {
// Check the pairs in a Map
for (const key in obj) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
if (obj.hasOwnProperty(key)) {
if ('@R' === key) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
const value = obj[key];

@@ -58,2 +60,3 @@ if (typeof value === 'string') {

}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
checkForRedirection(obj[key]);

@@ -63,3 +66,3 @@ }

}
}
};

@@ -75,2 +78,3 @@ //------------------------------------------------------------------------------------------------------------------------

* Interprets num record
*
* @param modl

@@ -97,3 +101,3 @@ * @param timeout

}
log.warn(e.message);
log.warn((e as Error).message);
}

@@ -100,0 +104,0 @@ return '';

@@ -39,2 +39,3 @@ // Copyright 2020 NUM Technology Ltd

* Creates module dns queries
*
* @param moduleId

@@ -44,5 +45,3 @@ * @param numUri

*/
export function createModuleDnsQueries(moduleId: PositiveInteger, numUri: NumUri) {
return new ModuleDnsQueriesImpl(moduleId, numUri);
}
export const createModuleDnsQueries = (moduleId: PositiveInteger, numUri: NumUri): ModuleDnsQueries => new ModuleDnsQueriesImpl(moduleId, numUri);

@@ -66,2 +65,3 @@ //------------------------------------------------------------------------------------------------------------------------

* Creates an instance of module dns queries.
*
* @param moduleId

@@ -79,4 +79,4 @@ * @param numUri

: this.numUri.protocol.startsWith('http')
? createUrlLookupGenerator(this.numUri)
: createDomainLookupGenerator(this.numUri);
? createUrlLookupGenerator(this.numUri)
: createDomainLookupGenerator(this.numUri);

@@ -191,3 +191,3 @@ this._independentRecordLocation = lookupGenerator.getIndependentLocation(this.moduleId);

*/
function toPath(domainPath: string): string {
const toPath = (domainPath: string): string => {
if (domainPath.includes('.')) {

@@ -197,3 +197,3 @@ return '/' + domainPath.split('.').reverse().join('/');

return `/${domainPath}`;
}
};

@@ -206,3 +206,3 @@ /**

*/
function fromPath(path: string): string {
const fromPath = (path: string): string => {
if (path.includes('/')) {

@@ -217,2 +217,2 @@ return path

return path;
}
};

@@ -38,2 +38,3 @@ // Copyright 2020 NUM Technology Ltd

* Creates an instance of num uri.
*
* @param userinfo

@@ -63,2 +64,3 @@ * @param host

* Withs host
*
* @param host

@@ -73,2 +75,3 @@ * @returns host

* Withs port
*
* @param port

@@ -83,2 +86,3 @@ * @returns port

* Withs path
*
* @param path

@@ -93,2 +97,3 @@ * @returns path

* Withs userinfo
*
* @param userinfo

@@ -104,2 +109,3 @@ * @returns userinfo

* Creates num uri
*
* @param host

@@ -111,3 +117,3 @@ * @param [port]

*/
export function buildNumUri(host: string, port?: number, userinfo?: string, path?: string): NumUri {
export const buildNumUri = (host: string, port?: number, userinfo?: string, path?: string): NumUri => {
const thePort = port ? new PositiveInteger(port) : MODULE_0;

@@ -117,10 +123,11 @@ const theUserInfo = userinfo ? new UrlUserInfo(userinfo) : NO_USER_INFO;

return new NumUri(new Hostname(host), thePort, theUserInfo, thePath);
}
};
/**
* Parses num uri
*
* @param uri
* @returns num uri
*/
export function parseNumUri(uri: string): NumUri {
export const parseNumUri = (uri: string): NumUri => {
const u = parse(uri.includes('://') ? uri : 'num://' + uri);

@@ -136,6 +143,7 @@ const portNumber = notEmpty(u.port) ? Number.parseInt(u.port as string, 10) : 0;

return new NumUri(host, port, userInfo, path);
}
};
/**
* N positive
*
* @param n

@@ -146,2 +154,3 @@ */

* S not empty
*
* @param s

@@ -157,2 +166,3 @@ */

* Creates an instance of positive integer.
*
* @param n

@@ -186,2 +196,3 @@ */

* Creates an instance of hostname.
*
* @param s

@@ -201,3 +212,3 @@ */

static isValid(s: string): boolean {
const matches = s.match(DOMAIN_REGEX);
const matches = DOMAIN_REGEX.exec(s);
return s.length <= MAX_DOMAIN_NAME_LENGTH && matches !== null && matches.length > 0;

@@ -213,6 +224,7 @@ }

* Creates an instance of url path.
*
* @param s
*/
constructor(readonly s: string) {
if (!s.startsWith('/') || !s.match(PATH_REGEX)) {
if (!s.startsWith('/') || !PATH_REGEX.exec(s)) {
throw new Error(`Invalid URL path: '${s}'`);

@@ -262,2 +274,3 @@ }

* Creates an instance of url user info.
*
* @param s

@@ -267,3 +280,3 @@ */

if (
(notEmpty(s) && !s.match(USERINFO_REGEX)) ||
(notEmpty(s) && !USERINFO_REGEX.exec(s)) ||
s.length > MAX_LOCAL_PART_LENGTH ||

@@ -270,0 +283,0 @@ s.startsWith('.') ||

@@ -28,3 +28,3 @@ // Copyright 2020 NUM Technology Ltd

*/
export function resolvePath(base: string, redirect: string): string {
export const resolvePath = (base: string, redirect: string): string => {
const SEP = '/';

@@ -65,2 +65,2 @@

return SEP + pathStack.join(SEP);
}
};
{
"name": "num-client",
"version": "0.0.11",
"version": "0.0.12",
"description": "A NUM Protocol Client in TypeScript",

@@ -23,9 +23,17 @@ "types": "index.d.ts",

"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"browserify": "^17.0.0",
"chai": "^4.2.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-jsdoc": "^30.7.7",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-prettier": "^3.1.4",
"mocha": "^8.1.3",
"prettier": "^2.1.2",
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"tslint": "^6.1.3"
},

@@ -43,3 +51,3 @@ "scripts": {

"format": "prettier --write \"**/*.ts\"",
"lint": "tslint --fix -p tsconfig.json",
"lint": "eslint --fix lib/**",
"prepare": "npm test",

@@ -46,0 +54,0 @@ "publish": "git push && git push --tags --force",

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