@ledgerhq/domain-service
Advanced tools
Comparing version 1.0.1-nightly.0 to 1.0.1
@@ -37,9 +37,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import axios from "axios"; | ||
import axios, { AxiosError } from "axios"; | ||
import eip55 from "eip55"; | ||
import { log } from "@ledgerhq/logs"; | ||
import { allSettled } from "../utils"; | ||
import { getRegistries, getRegistriesForAddress, getRegistriesForDomain, } from "../registries"; | ||
if (typeof Promise.allSettled === "undefined") { | ||
throw new Error("This lib requires Promise.allSettled in order to work. Please polyfill this method if needed."); | ||
} | ||
/** | ||
@@ -72,3 +70,3 @@ * Get an array of addresses for a domain | ||
registries = _a.sent(); | ||
responses = Promise.allSettled(registries.map(function (registry) { | ||
responses = allSettled(registries.map(function (registry) { | ||
return axios.request({ | ||
@@ -81,5 +79,7 @@ method: "GET", | ||
return promises.reduce(function (result, promise, index) { | ||
var _a; | ||
if (promise.status !== "fulfilled") { | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if (promise.reason instanceof AxiosError && | ||
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) { | ||
log("domain-service", "failed to resolve a domain", { | ||
@@ -149,3 +149,3 @@ domain: domain, | ||
})(); | ||
responses = Promise.allSettled(registries.map(function (registry) { | ||
responses = allSettled(registries.map(function (registry) { | ||
return axios.request({ | ||
@@ -158,5 +158,7 @@ method: "GET", | ||
return promises.reduce(function (result, promise, index) { | ||
var _a; | ||
if (promise.status !== "fulfilled") { | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if (promise.reason instanceof AxiosError && | ||
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) { | ||
log("domain-service", "failed to resolve a address", { | ||
@@ -163,0 +165,0 @@ address: address, |
@@ -19,3 +19,12 @@ import { CoinType } from "@ledgerhq/types-cryptoassets"; | ||
}; | ||
interface PromiseResolution<T> { | ||
status: "fulfilled"; | ||
value: T; | ||
} | ||
interface PromiseRejection<E> { | ||
status: "rejected"; | ||
reason: E; | ||
} | ||
export type PromiseResult<T, E = unknown> = PromiseResolution<T> | PromiseRejection<E>; | ||
export { SupportedRegistries, DomainServiceResolution }; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -0,2 +1,7 @@ | ||
import { PromiseResult } from "../types"; | ||
/** | ||
* Needed polyfill for Promise.allSettled as it doesn't exist on RN. | ||
*/ | ||
export declare const allSettled: <T>(promises: Promise<T>[]) => Promise<PromiseResult<T, unknown>[]>; | ||
/** | ||
* Helper to know in advance if a domain is compatible with the nano | ||
@@ -3,0 +8,0 @@ * |
/** | ||
* Needed polyfill for Promise.allSettled as it doesn't exist on RN. | ||
*/ | ||
export var allSettled = function (promises) { | ||
return Promise.all(promises.map(function (p) { | ||
return p | ||
.then(function (value) { | ||
return { | ||
status: "fulfilled", | ||
value: value | ||
}; | ||
})["catch"](function (reason) { | ||
return { | ||
status: "rejected", | ||
reason: reason | ||
}; | ||
}); | ||
})); | ||
}; | ||
/** | ||
* Helper to know in advance if a domain is compatible with the nano | ||
@@ -3,0 +22,0 @@ * |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = 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) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -43,9 +66,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
exports.resolveAddress = exports.resolveDomain = void 0; | ||
var axios_1 = __importDefault(require("axios")); | ||
var axios_1 = __importStar(require("axios")); | ||
var eip55_1 = __importDefault(require("eip55")); | ||
var logs_1 = require("@ledgerhq/logs"); | ||
var utils_1 = require("../utils"); | ||
var registries_1 = require("../registries"); | ||
if (typeof Promise.allSettled === "undefined") { | ||
throw new Error("This lib requires Promise.allSettled in order to work. Please polyfill this method if needed."); | ||
} | ||
/** | ||
@@ -78,3 +99,3 @@ * Get an array of addresses for a domain | ||
registries = _a.sent(); | ||
responses = Promise.allSettled(registries.map(function (registry) { | ||
responses = (0, utils_1.allSettled)(registries.map(function (registry) { | ||
return axios_1["default"].request({ | ||
@@ -87,5 +108,7 @@ method: "GET", | ||
return promises.reduce(function (result, promise, index) { | ||
var _a; | ||
if (promise.status !== "fulfilled") { | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if (promise.reason instanceof axios_1.AxiosError && | ||
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) { | ||
(0, logs_1.log)("domain-service", "failed to resolve a domain", { | ||
@@ -156,3 +179,3 @@ domain: domain, | ||
})(); | ||
responses = Promise.allSettled(registries.map(function (registry) { | ||
responses = (0, utils_1.allSettled)(registries.map(function (registry) { | ||
return axios_1["default"].request({ | ||
@@ -165,5 +188,7 @@ method: "GET", | ||
return promises.reduce(function (result, promise, index) { | ||
var _a; | ||
if (promise.status !== "fulfilled") { | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if (promise.reason instanceof axios_1.AxiosError && | ||
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) { | ||
(0, logs_1.log)("domain-service", "failed to resolve a address", { | ||
@@ -170,0 +195,0 @@ address: address, |
@@ -19,3 +19,12 @@ import { CoinType } from "@ledgerhq/types-cryptoassets"; | ||
}; | ||
interface PromiseResolution<T> { | ||
status: "fulfilled"; | ||
value: T; | ||
} | ||
interface PromiseRejection<E> { | ||
status: "rejected"; | ||
reason: E; | ||
} | ||
export type PromiseResult<T, E = unknown> = PromiseResolution<T> | PromiseRejection<E>; | ||
export { SupportedRegistries, DomainServiceResolution }; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -0,2 +1,7 @@ | ||
import { PromiseResult } from "../types"; | ||
/** | ||
* Needed polyfill for Promise.allSettled as it doesn't exist on RN. | ||
*/ | ||
export declare const allSettled: <T>(promises: Promise<T>[]) => Promise<PromiseResult<T, unknown>[]>; | ||
/** | ||
* Helper to know in advance if a domain is compatible with the nano | ||
@@ -3,0 +8,0 @@ * |
"use strict"; | ||
exports.__esModule = true; | ||
exports.validateDomain = void 0; | ||
exports.validateDomain = exports.allSettled = void 0; | ||
/** | ||
* Needed polyfill for Promise.allSettled as it doesn't exist on RN. | ||
*/ | ||
var allSettled = function (promises) { | ||
return Promise.all(promises.map(function (p) { | ||
return p | ||
.then(function (value) { | ||
return { | ||
status: "fulfilled", | ||
value: value | ||
}; | ||
})["catch"](function (reason) { | ||
return { | ||
status: "rejected", | ||
reason: reason | ||
}; | ||
}); | ||
})); | ||
}; | ||
exports.allSettled = allSettled; | ||
/** | ||
* Helper to know in advance if a domain is compatible with the nano | ||
@@ -6,0 +26,0 @@ * |
{ | ||
"name": "@ledgerhq/domain-service", | ||
"description": "Ledger service responsible for domain handling", | ||
"version": "1.0.1-nightly.0", | ||
"version": "1.0.1", | ||
"license": "Apache-2.0", | ||
@@ -61,6 +61,6 @@ "repository": { | ||
"react-dom": "^17.0.2", | ||
"@ledgerhq/cryptoassets": "^9.3.0", | ||
"@ledgerhq/cryptoassets": "^9.4.0", | ||
"@ledgerhq/errors": "^6.12.4", | ||
"@ledgerhq/logs": "^6.10.1", | ||
"@ledgerhq/types-live": "^6.32.1-nightly.0" | ||
"@ledgerhq/types-live": "^6.32.1" | ||
}, | ||
@@ -67,0 +67,0 @@ "devDependencies": { |
@@ -1,5 +0,6 @@ | ||
import axios from "axios"; | ||
import axios, { AxiosError } from "axios"; | ||
import eip55 from "eip55"; | ||
import { log } from "@ledgerhq/logs"; | ||
import { DomainServiceResolution, SupportedRegistries } from "../types"; | ||
import { allSettled } from "../utils"; | ||
import { | ||
@@ -11,8 +12,2 @@ getRegistries, | ||
if (typeof Promise.allSettled === "undefined") { | ||
throw new Error( | ||
"This lib requires Promise.allSettled in order to work. Please polyfill this method if needed." | ||
); | ||
} | ||
/** | ||
@@ -39,3 +34,3 @@ * Get an array of addresses for a domain | ||
const responses = Promise.allSettled( | ||
const responses = allSettled( | ||
registries.map((registry) => | ||
@@ -53,3 +48,6 @@ axios.request<string>({ | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if ( | ||
promise.reason instanceof AxiosError && | ||
promise.reason.response?.status !== 404 | ||
) { | ||
log("domain-service", "failed to resolve a domain", { | ||
@@ -113,3 +111,3 @@ domain, | ||
const responses = Promise.allSettled( | ||
const responses = allSettled( | ||
registries.map((registry) => | ||
@@ -127,3 +125,6 @@ axios.request<string>({ | ||
// ignore 404 error | ||
if (promise.reason.response.status !== 404) { | ||
if ( | ||
promise.reason instanceof AxiosError && | ||
promise.reason.response?.status !== 404 | ||
) { | ||
log("domain-service", "failed to resolve a address", { | ||
@@ -130,0 +131,0 @@ address, |
@@ -24,2 +24,14 @@ import { CoinType } from "@ledgerhq/types-cryptoassets"; | ||
interface PromiseResolution<T> { | ||
status: "fulfilled"; | ||
value: T; | ||
} | ||
interface PromiseRejection<E> { | ||
status: "rejected"; | ||
reason: E; | ||
} | ||
export type PromiseResult<T, E = unknown> = | ||
| PromiseResolution<T> | ||
| PromiseRejection<E>; | ||
export { SupportedRegistries, DomainServiceResolution }; |
@@ -0,2 +1,29 @@ | ||
import { PromiseResult } from "../types"; | ||
/** | ||
* Needed polyfill for Promise.allSettled as it doesn't exist on RN. | ||
*/ | ||
export const allSettled = <T>( | ||
promises: Promise<T>[] | ||
): Promise<PromiseResult<T>[]> => { | ||
return Promise.all( | ||
promises.map((p) => { | ||
return p | ||
.then((value) => { | ||
return { | ||
status: "fulfilled" as const, | ||
value, | ||
}; | ||
}) | ||
.catch((reason: unknown) => { | ||
return { | ||
status: "rejected" as const, | ||
reason, | ||
}; | ||
}); | ||
}) | ||
); | ||
}; | ||
/** | ||
* Helper to know in advance if a domain is compatible with the nano | ||
@@ -3,0 +30,0 @@ * |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
155976
2751
0