@metriport/shared 0.13.3 → 0.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/date.d.ts +3 -2
- package/dist/common/date.d.ts.map +1 -1
- package/dist/common/date.js +11 -5
- package/dist/common/date.js.map +1 -1
- package/dist/common/error.d.ts +3 -3
- package/dist/common/error.js +3 -3
- package/dist/common/filter-map.d.ts +11 -0
- package/dist/common/filter-map.d.ts.map +1 -0
- package/dist/common/filter-map.js +17 -0
- package/dist/common/filter-map.js.map +1 -0
- package/dist/common/xml-parser.d.ts +3 -0
- package/dist/common/xml-parser.d.ts.map +1 -0
- package/dist/common/xml-parser.js +17 -0
- package/dist/common/xml-parser.js.map +1 -0
- package/dist/domain/address/__tests__/normalize-zip.test.js +109 -30
- package/dist/domain/address/__tests__/normalize-zip.test.js.map +1 -1
- package/dist/domain/address/__tests__/state.test.d.ts +2 -0
- package/dist/domain/address/__tests__/state.test.d.ts.map +1 -0
- package/dist/domain/address/__tests__/state.test.js +40 -0
- package/dist/domain/address/__tests__/state.test.js.map +1 -0
- package/dist/domain/address/__tests__/territory.test.d.ts +2 -0
- package/dist/domain/address/__tests__/territory.test.d.ts.map +1 -0
- package/dist/domain/address/__tests__/territory.test.js +35 -0
- package/dist/domain/address/__tests__/territory.test.js.map +1 -0
- package/dist/domain/address/index.d.ts +6 -0
- package/dist/domain/address/index.d.ts.map +1 -0
- package/dist/domain/address/index.js +21 -0
- package/dist/domain/address/index.js.map +1 -0
- package/dist/domain/address/state.d.ts +1 -3
- package/dist/domain/address/state.d.ts.map +1 -1
- package/dist/domain/address/state.js +55 -61
- package/dist/domain/address/state.js.map +1 -1
- package/dist/domain/address/territory.d.ts +10 -0
- package/dist/domain/address/territory.d.ts.map +1 -0
- package/dist/domain/address/territory.js +30 -0
- package/dist/domain/address/territory.js.map +1 -0
- package/dist/domain/address/zip.d.ts +5 -2
- package/dist/domain/address/zip.d.ts.map +1 -1
- package/dist/domain/address/zip.js +45 -5
- package/dist/domain/address/zip.js.map +1 -1
- package/dist/domain/contact/__tests__/email.test.d.ts +2 -0
- package/dist/domain/contact/__tests__/email.test.d.ts.map +1 -0
- package/dist/domain/contact/__tests__/email.test.js +39 -0
- package/dist/domain/contact/__tests__/email.test.js.map +1 -0
- package/dist/domain/contact/__tests__/phone.test.js +28 -0
- package/dist/domain/contact/__tests__/phone.test.js.map +1 -1
- package/dist/domain/contact/email.d.ts +1 -0
- package/dist/domain/contact/email.d.ts.map +1 -1
- package/dist/domain/contact/email.js +5 -1
- package/dist/domain/contact/email.js.map +1 -1
- package/dist/domain/contact/phone.d.ts +1 -0
- package/dist/domain/contact/phone.d.ts.map +1 -1
- package/dist/domain/contact/phone.js +6 -1
- package/dist/domain/contact/phone.js.map +1 -1
- package/dist/domain/patient/patient-import.d.ts +131 -0
- package/dist/domain/patient/patient-import.d.ts.map +1 -0
- package/dist/domain/patient/patient-import.js +32 -0
- package/dist/domain/patient/patient-import.js.map +1 -0
- package/dist/domain/patient/patient.d.ts +23 -0
- package/dist/domain/patient/patient.d.ts.map +1 -0
- package/dist/domain/patient/patient.js +14 -0
- package/dist/domain/patient/patient.js.map +1 -0
- package/dist/error/metriport-error.d.ts +1 -1
- package/dist/error/metriport-error.d.ts.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -12
- package/dist/index.js.map +1 -1
- package/dist/interface/external/athenahealth/appointment.d.ts +50 -0
- package/dist/interface/external/athenahealth/appointment.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/appointment.js +18 -0
- package/dist/interface/external/athenahealth/appointment.js.map +1 -0
- package/dist/interface/external/athenahealth/cx-mapping.d.ts +10 -0
- package/dist/interface/external/athenahealth/cx-mapping.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/cx-mapping.js +8 -0
- package/dist/interface/external/athenahealth/cx-mapping.js.map +1 -0
- package/dist/interface/external/athenahealth/department.d.ts +27 -0
- package/dist/interface/external/athenahealth/department.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/department.js +11 -0
- package/dist/interface/external/athenahealth/department.js.map +1 -0
- package/dist/interface/external/athenahealth/index.d.ts +6 -0
- package/dist/interface/external/athenahealth/index.d.ts.map +1 -1
- package/dist/interface/external/athenahealth/index.js +6 -0
- package/dist/interface/external/athenahealth/index.js.map +1 -1
- package/dist/interface/external/athenahealth/jwt-token.d.ts +5 -0
- package/dist/interface/external/athenahealth/jwt-token.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/jwt-token.js +3 -0
- package/dist/interface/external/athenahealth/jwt-token.js.map +1 -0
- package/dist/interface/external/athenahealth/medication.d.ts +38 -0
- package/dist/interface/external/athenahealth/medication.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/medication.js +15 -0
- package/dist/interface/external/athenahealth/medication.js.map +1 -0
- package/dist/interface/external/athenahealth/patient.d.ts +277 -8
- package/dist/interface/external/athenahealth/patient.d.ts.map +1 -1
- package/dist/interface/external/athenahealth/patient.js +8 -1
- package/dist/interface/external/athenahealth/patient.js.map +1 -1
- package/dist/interface/external/athenahealth/subscription.d.ts +10 -0
- package/dist/interface/external/athenahealth/subscription.d.ts.map +1 -0
- package/dist/interface/external/athenahealth/subscription.js +8 -0
- package/dist/interface/external/athenahealth/subscription.js.map +1 -0
- package/dist/interface/internal/consolidated.d.ts +2 -2
- package/dist/medical/fhir/bundle.d.ts +3 -0
- package/dist/medical/fhir/bundle.d.ts.map +1 -1
- package/dist/medical/fhir/bundle.js +21 -0
- package/dist/medical/fhir/bundle.js.map +1 -1
- package/dist/medical/webhook/webhook-request.d.ts +25 -25
- package/dist/net/error.d.ts.map +1 -1
- package/dist/net/error.js +1 -0
- package/dist/net/error.js.map +1 -1
- package/dist/net/retry.d.ts.map +1 -1
- package/dist/net/retry.js +3 -1
- package/dist/net/retry.js.map +1 -1
- package/package.json +2 -2
package/dist/common/date.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
1
|
+
import dayjs, { ConfigType } from "dayjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export declare const ISO_DATE = "YYYY-MM-DD";
|
|
4
4
|
export declare function isValidISODate(date: string): boolean;
|
|
5
5
|
export declare const optionalDateSchema: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodString>>, string | null | undefined, string | null | undefined>;
|
|
6
6
|
export declare const dateSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
-
export declare
|
|
7
|
+
export declare function elapsedTimeFromNow(date?: Date, format?: dayjs.UnitTypeLong): number;
|
|
8
|
+
export declare function buildDayjs(date?: ConfigType, format?: string, strict?: boolean): dayjs.Dayjs;
|
|
8
9
|
//# sourceMappingURL=date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,EAAqB,CAAC,EAAE,MAAM,KAAK,CAAC;AAI3C,eAAO,MAAM,QAAQ,eAAe,CAAC;AAErC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAOD,eAAO,MAAM,kBAAkB,+GAIiB,CAAC;AAEjD,eAAO,MAAM,UAAU,2CAA0D,CAAC;AAElF,wBAAgB,kBAAkB,CAChC,IAAI,CAAC,EAAE,IAAI,EACX,MAAM,GAAE,KAAK,CAAC,YAA4B,GACzC,MAAM,CAER;AAED,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,KAAK,CAE5F"}
|
package/dist/common/date.js
CHANGED
|
@@ -3,12 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.elapsedTimeFromNow = exports.dateSchema = exports.optionalDateSchema = exports.isValidISODate = exports.ISO_DATE = void 0;
|
|
6
|
+
exports.buildDayjs = exports.elapsedTimeFromNow = exports.dateSchema = exports.optionalDateSchema = exports.isValidISODate = exports.ISO_DATE = void 0;
|
|
7
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
8
9
|
const zod_1 = require("zod");
|
|
10
|
+
dayjs_1.default.extend(utc_1.default);
|
|
9
11
|
exports.ISO_DATE = "YYYY-MM-DD";
|
|
10
12
|
function isValidISODate(date) {
|
|
11
|
-
return (
|
|
13
|
+
return buildDayjs(date, exports.ISO_DATE, true).isValid();
|
|
12
14
|
}
|
|
13
15
|
exports.isValidISODate = isValidISODate;
|
|
14
16
|
const isValidISODateOptional = (date) => date ? isValidISODate(date) : true;
|
|
@@ -19,8 +21,12 @@ exports.optionalDateSchema = zod_1.z
|
|
|
19
21
|
.nullish()
|
|
20
22
|
.refine(isValidISODateOptional, invalidIsoMsg);
|
|
21
23
|
exports.dateSchema = zod_1.z.string().trim().refine(isValidISODate, invalidIsoMsg);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
}
|
|
24
|
+
function elapsedTimeFromNow(date, format = "millisecond") {
|
|
25
|
+
return buildDayjs().diff(buildDayjs(date), format);
|
|
26
|
+
}
|
|
25
27
|
exports.elapsedTimeFromNow = elapsedTimeFromNow;
|
|
28
|
+
function buildDayjs(date, format, strict) {
|
|
29
|
+
return dayjs_1.default.utc(date, format, strict);
|
|
30
|
+
}
|
|
31
|
+
exports.buildDayjs = buildDayjs;
|
|
26
32
|
//# sourceMappingURL=date.js.map
|
package/dist/common/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/common/date.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0C;AAC1C,2DAAmC;AAEnC,6BAA2C;AAE3C,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAEL,QAAA,QAAQ,GAAG,YAAY,CAAC;AAErC,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,UAAU,CAAC,IAAI,EAAE,gBAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AACpD,CAAC;AAFD,wCAEC;AAED,MAAM,sBAAsB,GAAG,CAAC,IAA+B,EAAW,EAAE,CAC1E,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAErC,MAAM,aAAa,GAAsB,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE5D,QAAA,kBAAkB,GAAG,OAAC;KAChC,MAAM,EAAE;KACR,IAAI,EAAE;KACN,OAAO,EAAE;KACT,MAAM,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;AAEpC,QAAA,UAAU,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAElF,SAAgB,kBAAkB,CAChC,IAAW,EACX,SAA6B,aAAa;IAE1C,OAAO,UAAU,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AALD,gDAKC;AAED,SAAgB,UAAU,CAAC,IAAiB,EAAE,MAAe,EAAE,MAAgB;IAC7E,OAAO,eAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC;AAFD,gCAEC"}
|
package/dist/common/error.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ export type ErrorToStringOptions = {
|
|
|
2
2
|
detailed: boolean;
|
|
3
3
|
};
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated
|
|
5
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
6
6
|
*/
|
|
7
7
|
export declare function errorToString(err: unknown, options?: ErrorToStringOptions): string;
|
|
8
8
|
/**
|
|
9
|
-
* @deprecated
|
|
9
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
10
10
|
*/
|
|
11
11
|
export declare function genericErrorToString(err: unknown): string;
|
|
12
12
|
/**
|
|
13
|
-
* @deprecated
|
|
13
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
14
14
|
*/
|
|
15
15
|
export declare function detailedErrorToString(error: any): string;
|
|
16
16
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/common/error.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.detailedErrorToString = exports.genericErrorToString = exports.errorToString = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated
|
|
5
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
6
6
|
*/
|
|
7
7
|
function errorToString(err, options = { detailed: true }) {
|
|
8
8
|
if (options.detailed) {
|
|
@@ -12,14 +12,14 @@ function errorToString(err, options = { detailed: true }) {
|
|
|
12
12
|
}
|
|
13
13
|
exports.errorToString = errorToString;
|
|
14
14
|
/**
|
|
15
|
-
* @deprecated
|
|
15
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
16
16
|
*/
|
|
17
17
|
function genericErrorToString(err) {
|
|
18
18
|
return err["message"] ?? String(err); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
19
19
|
}
|
|
20
20
|
exports.genericErrorToString = genericErrorToString;
|
|
21
21
|
/**
|
|
22
|
-
* @deprecated
|
|
22
|
+
* @deprecated Use `@metriport/shared/error/shared` instead
|
|
23
23
|
*/
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
25
|
function detailedErrorToString(error) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used in .flatMap() to filter out undefined values.
|
|
3
|
+
*
|
|
4
|
+
* Example:
|
|
5
|
+
*
|
|
6
|
+
* const arr = [1, null, 3, undefined, 5];
|
|
7
|
+
* const filtered = arr.flatMap(filterTruthy);
|
|
8
|
+
* // filtered = [1, 3, 5]
|
|
9
|
+
*/
|
|
10
|
+
export declare function filterTruthy<T>(o: T | undefined | null): T | [];
|
|
11
|
+
//# sourceMappingURL=filter-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-map.d.ts","sourceRoot":"","sources":["../../src/common/filter-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,CAE/D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterTruthy = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Used in .flatMap() to filter out undefined values.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
*
|
|
9
|
+
* const arr = [1, null, 3, undefined, 5];
|
|
10
|
+
* const filtered = arr.flatMap(filterTruthy);
|
|
11
|
+
* // filtered = [1, 3, 5]
|
|
12
|
+
*/
|
|
13
|
+
function filterTruthy(o) {
|
|
14
|
+
return o ? o : [];
|
|
15
|
+
}
|
|
16
|
+
exports.filterTruthy = filterTruthy;
|
|
17
|
+
//# sourceMappingURL=filter-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-map.js","sourceRoot":"","sources":["../../src/common/filter-map.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAI,CAAuB;IACrD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpB,CAAC;AAFD,oCAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-parser.d.ts","sourceRoot":"","sources":["../../src/common/xml-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,wBAAgB,eAAe,CAAC,OAAO,GAAE,kBAAuB,GAAG,SAAS,CAY3E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createXMLParser = void 0;
|
|
4
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
5
|
+
function createXMLParser(options = {}) {
|
|
6
|
+
const defaultOptions = {
|
|
7
|
+
numberParseOptions: {
|
|
8
|
+
hex: false,
|
|
9
|
+
leadingZeros: false,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
// Merge the default options with the provided options
|
|
13
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
14
|
+
return new fast_xml_parser_1.XMLParser(mergedOptions);
|
|
15
|
+
}
|
|
16
|
+
exports.createXMLParser = createXMLParser;
|
|
17
|
+
//# sourceMappingURL=xml-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-parser.js","sourceRoot":"","sources":["../../src/common/xml-parser.ts"],"names":[],"mappings":";;;AAAA,qDAAgE;AAEhE,SAAgB,eAAe,CAAC,UAA8B,EAAE;IAC9D,MAAM,cAAc,GAAuB;QACzC,kBAAkB,EAAE;YAClB,GAAG,EAAE,KAAK;YACV,YAAY,EAAE,KAAK;SACpB;KACF,CAAC;IAEF,sDAAsD;IACtD,MAAM,aAAa,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IAExD,OAAO,IAAI,2BAAS,CAAC,aAAa,CAAC,CAAC;AACtC,CAAC;AAZD,0CAYC"}
|
|
@@ -1,38 +1,117 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const faker_1 = require("@faker-js/faker");
|
|
3
4
|
const zip_1 = require("../zip");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function getFiveDigitZip() {
|
|
6
|
+
return faker_1.faker.number.int({ min: 10000, max: 99999 }).toString();
|
|
7
|
+
}
|
|
8
|
+
describe("zip", () => {
|
|
9
|
+
describe("normalizeZipCode", () => {
|
|
10
|
+
test("should handle short zip codes", () => {
|
|
11
|
+
const input = "1234";
|
|
12
|
+
const expectedOutput = "1234";
|
|
13
|
+
expect((0, zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
|
|
14
|
+
});
|
|
15
|
+
test("should return first 4 characters when zip code length is 9", () => {
|
|
16
|
+
const input = "1234-6677";
|
|
17
|
+
const expectedOutput = "1234";
|
|
18
|
+
expect((0, zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
|
|
19
|
+
});
|
|
20
|
+
test("should return first 5 characters when zip code length is 10", () => {
|
|
21
|
+
const input = "12345-6677";
|
|
22
|
+
const expectedOutput = "12345";
|
|
23
|
+
expect((0, zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
|
|
24
|
+
});
|
|
25
|
+
test("should return first 5 characters when zip code length is 5", () => {
|
|
26
|
+
const input = "54321";
|
|
27
|
+
const expectedOutput = "54321";
|
|
28
|
+
expect((0, zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
|
|
29
|
+
});
|
|
30
|
+
test("should throw an error if zip contains non-digit and non-dash characters (length 9)", () => {
|
|
31
|
+
const input = "12345-667a";
|
|
32
|
+
expect(() => (0, zip_1.normalizeZipCode)(input)).toThrow();
|
|
33
|
+
});
|
|
34
|
+
test("should throw an error if zip contains non-digit and non-dash characters (length 5)", () => {
|
|
35
|
+
const input = "1234a";
|
|
36
|
+
expect(() => (0, zip_1.normalizeZipCode)(input)).toThrow();
|
|
37
|
+
});
|
|
38
|
+
test("should throw an error if zip is an empty string", () => {
|
|
39
|
+
const input = "";
|
|
40
|
+
expect(() => (0, zip_1.normalizeZipCode)(input)).toThrow();
|
|
41
|
+
});
|
|
9
42
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
43
|
+
describe("normalizeZipCodeNew", () => {
|
|
44
|
+
it("returns the result of the normalizeFn param", () => {
|
|
45
|
+
const expectedOutput = getFiveDigitZip();
|
|
46
|
+
const normalizeFn = jest.fn(() => expectedOutput);
|
|
47
|
+
expect((0, zip_1.normalizeZipCodeNew)("54321", normalizeFn)).toBe(expectedOutput);
|
|
48
|
+
});
|
|
49
|
+
it("should throw an error if zip is an empty string", () => {
|
|
50
|
+
const normalizeFn = jest.fn(() => undefined);
|
|
51
|
+
expect(() => (0, zip_1.normalizeZipCodeNew)("54321", normalizeFn)).toThrow();
|
|
52
|
+
});
|
|
14
53
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
describe("safe normalizeZipCodeNewSafe", () => {
|
|
55
|
+
it("should return undefined when it gets empty string", () => {
|
|
56
|
+
const input = "";
|
|
57
|
+
const expectedOutput = undefined;
|
|
58
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
59
|
+
});
|
|
60
|
+
it("should return undefined when it gets space", () => {
|
|
61
|
+
const input = " ";
|
|
62
|
+
const expectedOutput = undefined;
|
|
63
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
64
|
+
});
|
|
65
|
+
it("should handle 5 digits", () => {
|
|
66
|
+
const input = getFiveDigitZip();
|
|
67
|
+
const expectedOutput = input;
|
|
68
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
69
|
+
});
|
|
70
|
+
it("should trim input prefix", () => {
|
|
71
|
+
const expectedOutput = getFiveDigitZip();
|
|
72
|
+
const input = " " + expectedOutput;
|
|
73
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
74
|
+
});
|
|
75
|
+
it("should trim input suffix", () => {
|
|
76
|
+
const expectedOutput = getFiveDigitZip();
|
|
77
|
+
const input = expectedOutput + " ";
|
|
78
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
79
|
+
});
|
|
80
|
+
it("should return undefined for zip codes that are too short", () => {
|
|
81
|
+
const input = "12";
|
|
82
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
it("should handle short zip codes", () => {
|
|
85
|
+
const input = "123";
|
|
86
|
+
const expectedOutput = "00123";
|
|
87
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
88
|
+
});
|
|
89
|
+
it("should return padded first 4 characters when contains dash at position 4", () => {
|
|
90
|
+
const input = "1234-6677";
|
|
91
|
+
const expectedOutput = "01234";
|
|
92
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
93
|
+
});
|
|
94
|
+
it("should return first 5 characters when zip code length is 10", () => {
|
|
95
|
+
const input = "12345-6677";
|
|
96
|
+
const expectedOutput = "12345";
|
|
97
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
98
|
+
});
|
|
99
|
+
it("should return undefined if zip contains non-digit and non-dash characters (length 9)", () => {
|
|
100
|
+
const input = "12345-667a";
|
|
101
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
it("should return undefined if zip contains non-digit and non-dash characters (length 5)", () => {
|
|
104
|
+
const input = "1234a";
|
|
105
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
describe("examples from the wild", () => {
|
|
108
|
+
const tests = [{ input: "2468", expectedOutput: "02468" }];
|
|
109
|
+
for (const { input, expectedOutput } of tests) {
|
|
110
|
+
it(`should return ${expectedOutput} when input is ${input}`, () => {
|
|
111
|
+
expect((0, zip_1.normalizeZipCodeNewSafe)(input)).toBe(expectedOutput);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
36
115
|
});
|
|
37
116
|
});
|
|
38
117
|
//# sourceMappingURL=normalize-zip.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-zip.test.js","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/normalize-zip.test.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"normalize-zip.test.js","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/normalize-zip.test.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AACxC,gCAAwF;AAExF,SAAS,eAAe;IACtB,OAAO,aAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjE,CAAC;AAED,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;IACnB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,IAAI,CAAC,+BAA+B,E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BAC7C,EAAE,CAAC,iBAAiB,cAAc,kBAAkB,KAAK,EAAE,EAAE,GAAG,EAAE;oBAChE,MAAM,CAAC,IAAA,6BAAuB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC9D,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.test.d.ts","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/state.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const state_1 = require("../state");
|
|
4
|
+
describe("state", () => {
|
|
5
|
+
describe("normalizeStateSafe", () => {
|
|
6
|
+
it("should convert long name to USState", () => {
|
|
7
|
+
const input = "Arizona";
|
|
8
|
+
const expectedOutput = state_1.USState.AZ;
|
|
9
|
+
expect((0, state_1.normalizeStateSafe)(input)).toEqual(expectedOutput);
|
|
10
|
+
});
|
|
11
|
+
it("should convert long name case insentitive to USState", () => {
|
|
12
|
+
const input = "aRiZonA";
|
|
13
|
+
const expectedOutput = state_1.USState.AZ;
|
|
14
|
+
expect((0, state_1.normalizeStateSafe)(input)).toEqual(expectedOutput);
|
|
15
|
+
});
|
|
16
|
+
it("should convert District of Columbia to DC", () => {
|
|
17
|
+
const input = "District of Columbia";
|
|
18
|
+
const expectedOutput = state_1.USState.DC;
|
|
19
|
+
expect((0, state_1.normalizeStateSafe)(input)).toEqual(expectedOutput);
|
|
20
|
+
});
|
|
21
|
+
describe(`should convert to USState`, () => {
|
|
22
|
+
for (const usState of Object.values(state_1.USState)) {
|
|
23
|
+
it(usState, () => {
|
|
24
|
+
const input = usState;
|
|
25
|
+
const expectedOutput = usState;
|
|
26
|
+
expect((0, state_1.normalizeStateSafe)(input)).toEqual(expectedOutput);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
it("should return undefined if can't match a US state", () => {
|
|
31
|
+
const input = "Ariz";
|
|
32
|
+
expect((0, state_1.normalizeStateSafe)(input)).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
it("should return undefined if gets an empty string", () => {
|
|
35
|
+
const input = "";
|
|
36
|
+
expect((0, state_1.normalizeStateSafe)(input)).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/state.test.ts"],"names":[],"mappings":";;AAAA,oCAAuD;AAEvD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAClC,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;YAC7C,MAAM,KAAK,GAAG,SAAS,CAAC;YACxB,MAAM,cAAc,GAAG,eAAO,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;YAC9D,MAAM,KAAK,GAAG,SAAS,CAAC;YACxB,MAAM,cAAc,GAAG,eAAO,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,KAAK,GAAG,sBAAsB,CAAC;YACrC,MAAM,cAAc,GAAG,eAAO,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACzC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,eAAO,CAAC,EAAE;gBAC5C,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;oBACf,MAAM,KAAK,GAAG,OAAO,CAAC;oBACtB,MAAM,cAAc,GAAG,OAAO,CAAC;oBAC/B,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAC5D,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,KAAK,GAAG,MAAM,CAAC;YACrB,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"territory.test.d.ts","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/territory.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const territory_1 = require("../territory");
|
|
4
|
+
describe("territory", () => {
|
|
5
|
+
describe("normalizeTerritorySafe", () => {
|
|
6
|
+
it("should convert long name to USTerritory", () => {
|
|
7
|
+
const input = "Guam";
|
|
8
|
+
const expectedOutput = territory_1.USTerritory.GU;
|
|
9
|
+
expect((0, territory_1.normalizeTerritorySafe)(input)).toEqual(expectedOutput);
|
|
10
|
+
});
|
|
11
|
+
it("should convert long name case insentitive to USTerritory", () => {
|
|
12
|
+
const input = "GuAm";
|
|
13
|
+
const expectedOutput = territory_1.USTerritory.GU;
|
|
14
|
+
expect((0, territory_1.normalizeTerritorySafe)(input)).toEqual(expectedOutput);
|
|
15
|
+
});
|
|
16
|
+
describe(`should convert to USTerritory`, () => {
|
|
17
|
+
for (const usTerritory of Object.values(territory_1.USTerritory)) {
|
|
18
|
+
it(usTerritory, () => {
|
|
19
|
+
const input = usTerritory;
|
|
20
|
+
const expectedOutput = usTerritory;
|
|
21
|
+
expect((0, territory_1.normalizeTerritorySafe)(input)).toEqual(expectedOutput);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
it("should return undefined if can't match a US territory", () => {
|
|
26
|
+
const input = "Gua";
|
|
27
|
+
expect((0, territory_1.normalizeTerritorySafe)(input)).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
it("should return undefined if gets an empty string", () => {
|
|
30
|
+
const input = "";
|
|
31
|
+
expect((0, territory_1.normalizeTerritorySafe)(input)).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=territory.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"territory.test.js","sourceRoot":"","sources":["../../../../src/domain/address/__tests__/territory.test.ts"],"names":[],"mappings":";;AAAA,4CAAmE;AAEnE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YACjD,MAAM,KAAK,GAAG,MAAM,CAAC;YACrB,MAAM,cAAc,GAAG,uBAAW,CAAC,EA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|
|
2
|
+
import { USTerritory } from "./territory";
|
|
3
|
+
export type USStateForAddress = USState | USTerritory;
|
|
4
|
+
export declare function normalizeUSStateForAddressSafe(value: string): USStateForAddress | undefined;
|
|
5
|
+
export declare function normalizeUSStateForAddress(value: string): USStateForAddress;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/address/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,OAAO,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAA0B,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,WAAW,CAAC;AAEtD,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE3F;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAQ3E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeUSStateForAddress = exports.normalizeUSStateForAddressSafe = void 0;
|
|
4
|
+
const bad_request_1 = require("../../error/bad-request");
|
|
5
|
+
const state_1 = require("./state");
|
|
6
|
+
const territory_1 = require("./territory");
|
|
7
|
+
function normalizeUSStateForAddressSafe(value) {
|
|
8
|
+
return (0, state_1.normalizeStateSafe)(value) ?? (0, territory_1.normalizeTerritorySafe)(value);
|
|
9
|
+
}
|
|
10
|
+
exports.normalizeUSStateForAddressSafe = normalizeUSStateForAddressSafe;
|
|
11
|
+
function normalizeUSStateForAddress(value) {
|
|
12
|
+
const state = (0, state_1.normalizeStateSafe)(value) ?? (0, territory_1.normalizeTerritorySafe)(value);
|
|
13
|
+
if (!state) {
|
|
14
|
+
throw new bad_request_1.BadRequestError("Invalid US state or territory", undefined, {
|
|
15
|
+
stateOrTerritory: value,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
exports.normalizeUSStateForAddress = normalizeUSStateForAddress;
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/address/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0D;AAC1D,mCAAsD;AACtD,2CAAkE;AAIlE,SAAgB,8BAA8B,CAAC,KAAa;IAC1D,OAAO,IAAA,0BAAkB,EAAC,KAAK,CAAC,IAAI,IAAA,kCAAsB,EAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAFD,wEAEC;AAED,SAAgB,0BAA0B,CAAC,KAAa;IACtD,MAAM,KAAK,GAAG,IAAA,0BAAkB,EAAC,KAAK,CAAC,IAAI,IAAA,kCAAsB,EAAC,KAAK,CAAC,CAAC;IACzE,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,6BAAe,CAAC,+BAA+B,EAAE,SAAS,EAAE;YACpE,gBAAgB,EAAE,KAAK;SACxB,CAAC,CAAC;KACJ;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AARD,gEAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/address/state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/domain/address/state.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAKrE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAIrD;AAED,oBAAY,OAAO;IACjB,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;CACV;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAoD1C,CAAC"}
|