@metriport/shared 0.1.10 → 0.1.11-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ export declare function logDuration<T>(fn: () => Promise<T>, options?: {
2
+ log?: typeof console.log;
3
+ withMinutes?: boolean;
4
+ }): Promise<T>;
5
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/common/duration.ts"],"names":[],"mappings":"AAMA,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,OAAO,CAAC,GAAG,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5D,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logDuration = void 0;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ const duration_1 = __importDefault(require("dayjs/plugin/duration"));
9
+ const numbers_1 = require("./numbers");
10
+ dayjs_1.default.extend(duration_1.default);
11
+ async function logDuration(fn, options) {
12
+ const { log = console.log, withMinutes = true } = options ?? {};
13
+ const startedAt = Date.now();
14
+ let success = false;
15
+ try {
16
+ const res = await fn();
17
+ success = true;
18
+ return res;
19
+ }
20
+ finally {
21
+ const duration = Date.now() - startedAt;
22
+ const durationMin = withMinutes
23
+ ? ` / ${(0, numbers_1.formatNumber)(dayjs_1.default.duration(duration).asMinutes())} min`
24
+ : "";
25
+ const successMsg = success ? "" : " (with errors)";
26
+ log(`It took ${duration} ms${durationMin} to execute${successMsg}`);
27
+ }
28
+ }
29
+ exports.logDuration = logDuration;
30
+ //# sourceMappingURL=duration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.js","sourceRoot":"","sources":["../../src/common/duration.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,qEAA6C;AAC7C,uCAAyC;AAEzC,eAAK,CAAC,MAAM,CAAC,kBAAQ,CAAC,CAAC;AAEhB,KAAK,UAAU,WAAW,CAC/B,EAAoB,EACpB,OAA6D;IAE7D,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAChE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI;QACF,MAAM,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC;QACvB,OAAO,GAAG,IAAI,CAAC;QACf,OAAO,GAAG,CAAC;KACZ;YAAS;QACR,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QACxC,MAAM,WAAW,GAAG,WAAW;YAC7B,CAAC,CAAC,MAAM,IAAA,sBAAY,EAAC,eAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM;YAChE,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC;QACnD,GAAG,CAAC,WAAW,QAAQ,MAAM,WAAW,cAAc,UAAU,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AApBD,kCAoBC"}
@@ -0,0 +1,4 @@
1
+ export declare function getFloatValue(value: string | number): number;
2
+ export declare function formatNumber(num: number): number;
3
+ export declare function randomInt(maxDigits?: number): number;
4
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/common/numbers.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5D;AAGD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,SAAS,CAAC,SAAS,SAAI,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomInt = exports.formatNumber = exports.getFloatValue = void 0;
4
+ function getFloatValue(value) {
5
+ return typeof value === "string" ? parseFloat(value) : value;
6
+ }
7
+ exports.getFloatValue = getFloatValue;
8
+ // Truncate the number to 2 decimal places
9
+ function formatNumber(num) {
10
+ return Math.floor(num * 100) / 100;
11
+ }
12
+ exports.formatNumber = formatNumber;
13
+ function randomInt(maxDigits = 2) {
14
+ return Math.floor(Math.random() * Math.pow(10, maxDigits));
15
+ }
16
+ exports.randomInt = randomInt;
17
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/common/numbers.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa,CAAC,KAAsB;IAClD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/D,CAAC;AAFD,sCAEC;AAED,0CAA0C;AAC1C,SAAgB,YAAY,CAAC,GAAW;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC;AAFD,oCAEC;AAED,SAAgB,SAAS,CAAC,SAAS,GAAG,CAAC;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;AAC7D,CAAC;AAFD,8BAEC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=env-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-setup.d.ts","sourceRoot":"","sources":["../../../src/__tests__/env-setup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const dotenv = __importStar(require("dotenv"));
30
+ const path_1 = __importDefault(require("path"));
31
+ const cwd = process.cwd();
32
+ const paths = [cwd, ...(cwd.includes("packages") ? [] : ["packages", "shared"])];
33
+ dotenv.config({ path: path_1.default.resolve(...paths, ".env.test") });
34
+ // Keep dotenv import and config before everything else
35
+ //# sourceMappingURL=env-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-setup.js","sourceRoot":"","sources":["../../../src/__tests__/env-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,gDAAwB;AACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;AAC7D,uDAAuD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=normalize-oid.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.test.d.ts","sourceRoot":"","sources":["../../../../src/common/__tests__/normalize-oid.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const normalize_oid_1 = require("../normalize-oid");
4
+ const shorterValidOid = "1";
5
+ const validOid = "1.22.333.444";
6
+ const longerValidOid = "1.22.33.444.555.6677.889999.0001";
7
+ const validOidWithPrefix = "urn:oid:1.22.333.444";
8
+ const invalidOid = "notAnOid";
9
+ const consecutiveDotsInvalidOid = "1.22.333..444";
10
+ describe("normalizeOid", () => {
11
+ it("should return the same oid if it is already valid", () => {
12
+ expect((0, normalize_oid_1.normalizeOid)(validOid)).toBe(validOid);
13
+ expect((0, normalize_oid_1.normalizeOid)(shorterValidOid)).toBe(shorterValidOid);
14
+ expect((0, normalize_oid_1.normalizeOid)(longerValidOid)).toBe(longerValidOid);
15
+ });
16
+ it("should return the oid without the urn:oid: prefix", () => {
17
+ expect((0, normalize_oid_1.normalizeOid)(validOidWithPrefix)).toBe(validOid);
18
+ });
19
+ it("should throw an error if oid does not conform to the format", () => {
20
+ expect(() => (0, normalize_oid_1.normalizeOid)(invalidOid)).toThrow("OID is not valid");
21
+ expect(() => (0, normalize_oid_1.normalizeOid)(consecutiveDotsInvalidOid)).toThrow("OID is not valid");
22
+ });
23
+ });
24
+ //# sourceMappingURL=normalize-oid.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.test.js","sourceRoot":"","sources":["../../../../src/common/__tests__/normalize-oid.test.ts"],"names":[],"mappings":";;AAAA,oDAAgD;AAEhD,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,QAAQ,GAAG,cAAc,CAAC;AAChC,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAC1D,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,MAAM,yBAAyB,GAAG,eAAe,CAAC;AAElD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CAAC,IAAA,4BAAY,EAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAA,4BAAY,EAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,MAAM,CAAC,IAAA,4BAAY,EAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CAAC,IAAA,4BAAY,EAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4BAAY,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACnE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4BAAY,EAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function normalizeOid(oid: string): string;
2
+ //# sourceMappingURL=normalize-oid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.d.ts","sourceRoot":"","sources":["../../../src/common/normalize-oid.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOhD"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOid = void 0;
4
+ const OID_REGEX = /^(urn:oid:)?([0-9]+(\.[0-9]+)*)$/;
5
+ function normalizeOid(oid) {
6
+ const match = OID_REGEX.exec(oid);
7
+ if (match && match[2]) {
8
+ return match[2];
9
+ }
10
+ throw new Error("OID is not valid");
11
+ }
12
+ exports.normalizeOid = normalizeOid;
13
+ //# sourceMappingURL=normalize-oid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.js","sourceRoot":"","sources":["../../../src/common/normalize-oid.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,kCAAkC,CAAC;AAErD,SAAgB,YAAY,CAAC,GAAW;IACtC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;QACrB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACtC,CAAC;AAPD,oCAOC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if the specified 10 digit NPI is valid as per ISO standard mod 10 Luhn algorithm.
3
+ *
4
+ * See: https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
5
+ *
6
+ * @param npi The npi number to validate, must be 10 digits.
7
+ * @returns true if valid; false otherwise.
8
+ */
9
+ export declare function validateNPI(npi: string): boolean;
10
+ //# sourceMappingURL=validate-npi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-npi.d.ts","sourceRoot":"","sources":["../../../src/common/validate-npi.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAiChD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateNPI = void 0;
4
+ /**
5
+ * Checks if the specified 10 digit NPI is valid as per ISO standard mod 10 Luhn algorithm.
6
+ *
7
+ * See: https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
8
+ *
9
+ * @param npi The npi number to validate, must be 10 digits.
10
+ * @returns true if valid; false otherwise.
11
+ */
12
+ function validateNPI(npi) {
13
+ if (!npi || npi.length !== 10) {
14
+ return false;
15
+ }
16
+ const firstNPIDigit = parseInt(npi.charAt(0), 10);
17
+ if (firstNPIDigit !== 1 && firstNPIDigit !== 2) {
18
+ return false;
19
+ }
20
+ let sum = 0;
21
+ let shouldDouble = true;
22
+ for (let i = 0; i < npi.length - 1; i++) {
23
+ let digit = parseInt(npi.charAt(i), 10);
24
+ if (shouldDouble) {
25
+ digit *= 2;
26
+ if (digit > 9) {
27
+ digit -= 9;
28
+ }
29
+ }
30
+ sum += digit;
31
+ shouldDouble = !shouldDouble;
32
+ }
33
+ // account for NPI prefix
34
+ sum += 24;
35
+ const diffFromNextTens = 10 - (sum % 10);
36
+ const checkDigit = diffFromNextTens % 10;
37
+ const lastNPIDigit = parseInt(npi.charAt(npi.length - 1), 10);
38
+ return checkDigit === lastNPIDigit;
39
+ }
40
+ exports.validateNPI = validateNPI;
41
+ //# sourceMappingURL=validate-npi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-npi.js","sourceRoot":"","sources":["../../../src/common/validate-npi.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;QAC9C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACvC,IAAI,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAExC,IAAI,YAAY,EAAE;YAChB,KAAK,IAAI,CAAC,CAAC;YACX,IAAI,KAAK,GAAG,CAAC,EAAE;gBACb,KAAK,IAAI,CAAC,CAAC;aACZ;SACF;QAED,GAAG,IAAI,KAAK,CAAC;QACb,YAAY,GAAG,CAAC,YAAY,CAAC;KAC9B;IAED,yBAAyB;IACzB,GAAG,IAAI,EAAE,CAAC;IAEV,MAAM,gBAAgB,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,gBAAgB,GAAG,EAAE,CAAC;IAEzC,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,OAAO,UAAU,KAAK,YAAY,CAAC;AACrC,CAAC;AAjCD,kCAiCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metriport/shared",
3
- "version": "0.1.10",
3
+ "version": "0.1.11-alpha.1",
4
4
  "description": "Common code shared across packages - by Metriport Inc.",
5
5
  "author": "Metriport Inc. <contact@metriport.com>",
6
6
  "homepage": "https://metriport.com/",
@@ -51,5 +51,5 @@
51
51
  "test": "jest --runInBand --detectOpenHandles --passWithNoTests",
52
52
  "test:e2e": "E2E=true jest --runInBand --detectOpenHandles --passWithNoTests"
53
53
  },
54
- "gitHead": "da4fc3fb6b7b13b91d25fde0fd89f79603f8af97"
54
+ "gitHead": "56bf237be2396082c39ad942e5f4e5e7546d4d7c"
55
55
  }