@metriport/shared 0.13.3 → 0.13.5-alpha.0

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.
Files changed (137) hide show
  1. package/dist/common/__tests__/npi.d.ts +7 -0
  2. package/dist/common/__tests__/npi.d.ts.map +1 -0
  3. package/dist/common/__tests__/npi.js +32 -0
  4. package/dist/common/__tests__/npi.js.map +1 -0
  5. package/dist/common/__tests__/validate-npi.test.d.ts +2 -0
  6. package/dist/common/__tests__/validate-npi.test.d.ts.map +1 -0
  7. package/dist/common/__tests__/validate-npi.test.js +24 -0
  8. package/dist/common/__tests__/validate-npi.test.js.map +1 -0
  9. package/dist/common/date.d.ts +3 -2
  10. package/dist/common/date.d.ts.map +1 -1
  11. package/dist/common/date.js +11 -5
  12. package/dist/common/date.js.map +1 -1
  13. package/dist/common/error.d.ts +3 -3
  14. package/dist/common/error.js +3 -3
  15. package/dist/common/filter-map.d.ts +11 -0
  16. package/dist/common/filter-map.d.ts.map +1 -0
  17. package/dist/common/filter-map.js +17 -0
  18. package/dist/common/filter-map.js.map +1 -0
  19. package/dist/common/xml-parser.d.ts +3 -0
  20. package/dist/common/xml-parser.d.ts.map +1 -0
  21. package/dist/common/xml-parser.js +17 -0
  22. package/dist/common/xml-parser.js.map +1 -0
  23. package/dist/domain/address/__tests__/normalize-zip.test.js +109 -30
  24. package/dist/domain/address/__tests__/normalize-zip.test.js.map +1 -1
  25. package/dist/domain/address/__tests__/state.test.d.ts +2 -0
  26. package/dist/domain/address/__tests__/state.test.d.ts.map +1 -0
  27. package/dist/domain/address/__tests__/state.test.js +40 -0
  28. package/dist/domain/address/__tests__/state.test.js.map +1 -0
  29. package/dist/domain/address/__tests__/territory.test.d.ts +2 -0
  30. package/dist/domain/address/__tests__/territory.test.d.ts.map +1 -0
  31. package/dist/domain/address/__tests__/territory.test.js +35 -0
  32. package/dist/domain/address/__tests__/territory.test.js.map +1 -0
  33. package/dist/domain/address/index.d.ts +6 -0
  34. package/dist/domain/address/index.d.ts.map +1 -0
  35. package/dist/domain/address/index.js +21 -0
  36. package/dist/domain/address/index.js.map +1 -0
  37. package/dist/domain/address/state.d.ts +1 -3
  38. package/dist/domain/address/state.d.ts.map +1 -1
  39. package/dist/domain/address/state.js +57 -61
  40. package/dist/domain/address/state.js.map +1 -1
  41. package/dist/domain/address/territory.d.ts +10 -0
  42. package/dist/domain/address/territory.d.ts.map +1 -0
  43. package/dist/domain/address/territory.js +32 -0
  44. package/dist/domain/address/territory.js.map +1 -0
  45. package/dist/domain/address/zip.d.ts +5 -2
  46. package/dist/domain/address/zip.d.ts.map +1 -1
  47. package/dist/domain/address/zip.js +45 -5
  48. package/dist/domain/address/zip.js.map +1 -1
  49. package/dist/domain/contact/__tests__/email.test.d.ts +2 -0
  50. package/dist/domain/contact/__tests__/email.test.d.ts.map +1 -0
  51. package/dist/domain/contact/__tests__/email.test.js +39 -0
  52. package/dist/domain/contact/__tests__/email.test.js.map +1 -0
  53. package/dist/domain/contact/__tests__/phone.test.js +28 -0
  54. package/dist/domain/contact/__tests__/phone.test.js.map +1 -1
  55. package/dist/domain/contact/email.d.ts +1 -0
  56. package/dist/domain/contact/email.d.ts.map +1 -1
  57. package/dist/domain/contact/email.js +5 -1
  58. package/dist/domain/contact/email.js.map +1 -1
  59. package/dist/domain/contact/phone.d.ts +2 -0
  60. package/dist/domain/contact/phone.d.ts.map +1 -1
  61. package/dist/domain/contact/phone.js +13 -1
  62. package/dist/domain/contact/phone.js.map +1 -1
  63. package/dist/domain/patient/patient-import.d.ts +131 -0
  64. package/dist/domain/patient/patient-import.d.ts.map +1 -0
  65. package/dist/domain/patient/patient-import.js +32 -0
  66. package/dist/domain/patient/patient-import.js.map +1 -0
  67. package/dist/domain/patient/patient.d.ts +23 -0
  68. package/dist/domain/patient/patient.d.ts.map +1 -0
  69. package/dist/domain/patient/patient.js +14 -0
  70. package/dist/domain/patient/patient.js.map +1 -0
  71. package/dist/error/metriport-error.d.ts +1 -1
  72. package/dist/error/metriport-error.d.ts.map +1 -1
  73. package/dist/index.d.ts +11 -7
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +16 -12
  76. package/dist/index.js.map +1 -1
  77. package/dist/interface/external/athenahealth/appointment.d.ts +50 -0
  78. package/dist/interface/external/athenahealth/appointment.d.ts.map +1 -0
  79. package/dist/interface/external/athenahealth/appointment.js +18 -0
  80. package/dist/interface/external/athenahealth/appointment.js.map +1 -0
  81. package/dist/interface/external/athenahealth/cx-mapping.d.ts +10 -0
  82. package/dist/interface/external/athenahealth/cx-mapping.d.ts.map +1 -0
  83. package/dist/interface/external/athenahealth/cx-mapping.js +8 -0
  84. package/dist/interface/external/athenahealth/cx-mapping.js.map +1 -0
  85. package/dist/interface/external/athenahealth/department.d.ts +27 -0
  86. package/dist/interface/external/athenahealth/department.d.ts.map +1 -0
  87. package/dist/interface/external/athenahealth/department.js +11 -0
  88. package/dist/interface/external/athenahealth/department.js.map +1 -0
  89. package/dist/interface/external/athenahealth/index.d.ts +6 -0
  90. package/dist/interface/external/athenahealth/index.d.ts.map +1 -1
  91. package/dist/interface/external/athenahealth/index.js +6 -0
  92. package/dist/interface/external/athenahealth/index.js.map +1 -1
  93. package/dist/interface/external/athenahealth/jwt-token.d.ts +5 -0
  94. package/dist/interface/external/athenahealth/jwt-token.d.ts.map +1 -0
  95. package/dist/interface/external/athenahealth/jwt-token.js +3 -0
  96. package/dist/interface/external/athenahealth/jwt-token.js.map +1 -0
  97. package/dist/interface/external/athenahealth/medication.d.ts +38 -0
  98. package/dist/interface/external/athenahealth/medication.d.ts.map +1 -0
  99. package/dist/interface/external/athenahealth/medication.js +15 -0
  100. package/dist/interface/external/athenahealth/medication.js.map +1 -0
  101. package/dist/interface/external/athenahealth/patient.d.ts +277 -8
  102. package/dist/interface/external/athenahealth/patient.d.ts.map +1 -1
  103. package/dist/interface/external/athenahealth/patient.js +8 -1
  104. package/dist/interface/external/athenahealth/patient.js.map +1 -1
  105. package/dist/interface/external/athenahealth/subscription.d.ts +10 -0
  106. package/dist/interface/external/athenahealth/subscription.d.ts.map +1 -0
  107. package/dist/interface/external/athenahealth/subscription.js +8 -0
  108. package/dist/interface/external/athenahealth/subscription.js.map +1 -0
  109. package/dist/interface/internal/consolidated.d.ts +2 -2
  110. package/dist/medical/fhir/bundle.d.ts +3 -0
  111. package/dist/medical/fhir/bundle.d.ts.map +1 -1
  112. package/dist/medical/fhir/bundle.js +21 -0
  113. package/dist/medical/fhir/bundle.js.map +1 -1
  114. package/dist/medical/webhook/webhook-request.d.ts +25 -25
  115. package/dist/net/error.d.ts.map +1 -1
  116. package/dist/net/error.js +1 -0
  117. package/dist/net/error.js.map +1 -1
  118. package/dist/net/retry.d.ts.map +1 -1
  119. package/dist/net/retry.js +3 -1
  120. package/dist/net/retry.js.map +1 -1
  121. package/package.json +2 -2
  122. package/dist/common/__tests__/normalize-zip.test.d.ts +0 -2
  123. package/dist/common/__tests__/normalize-zip.test.d.ts.map +0 -1
  124. package/dist/common/__tests__/normalize-zip.test.js +0 -38
  125. package/dist/common/__tests__/normalize-zip.test.js.map +0 -1
  126. package/dist/common/normalize-zip.d.ts +0 -10
  127. package/dist/common/normalize-zip.d.ts.map +0 -1
  128. package/dist/common/normalize-zip.js +0 -30
  129. package/dist/common/normalize-zip.js.map +0 -1
  130. package/dist/net/__tests__/file-downloader.d.ts +0 -2
  131. package/dist/net/__tests__/file-downloader.d.ts.map +0 -1
  132. package/dist/net/__tests__/file-downloader.js +0 -66
  133. package/dist/net/__tests__/file-downloader.js.map +0 -1
  134. package/dist/net/file-downloader.d.ts +0 -22
  135. package/dist/net/file-downloader.d.ts.map +0 -1
  136. package/dist/net/file-downloader.js +0 -67
  137. package/dist/net/file-downloader.js.map +0 -1
package/dist/net/error.js CHANGED
@@ -35,6 +35,7 @@ exports.nodeNetworkErrorCodes = [
35
35
  "ENOTFOUND",
36
36
  ];
37
37
  // Axios error codes that are timeout errors
38
+ // https://github.com/axios/axios?tab=readme-ov-file#error-types
38
39
  exports.axiosTimeoutErrorCodes = [axios_1.AxiosError.ECONNABORTED, axios_1.AxiosError.ETIMEDOUT];
39
40
  exports.axiosResponseErrorCodes = [axios_1.AxiosError.ERR_BAD_RESPONSE];
40
41
  exports.axiosNetworkErrors = [...exports.axiosResponseErrorCodes, ...exports.axiosTimeoutErrorCodes];
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/net/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA0C;AAC1C,4CAAgD;AAEhD,4EAA4E;AAC/D,QAAA,yBAAyB,GAAG,CAAC,cAAc,EAAE,YAAY,CAAU,CAAC;AAGpE,QAAA,qBAAqB,GAAG,CAAC,WAAW,CAAU,CAAC;AAG/C,QAAA,qBAAqB,GAAG;IACnC,GAAG,iCAAyB;IAC5B,GAAG,6BAAqB;IACxB,WAAW;CACH,CAAC;AAGX,4CAA4C;AAE/B,QAAA,sBAAsB,GAAG,CAAC,kBAAU,CAAC,YAAY,EAAE,kBAAU,CAAC,SAAS,CAAU,CAAC;AAGlF,QAAA,uBAAuB,GAAG,CAAC,kBAAU,CAAC,gBAAgB,CAAU,CAAC;AAGjE,QAAA,kBAAkB,GAAG,CAAC,GAAG,+BAAuB,EAAE,GAAG,8BAAsB,CAAU,CAAC;AAGnG,yBAAyB;AAEZ,QAAA,oBAAoB,GAAG,CAAC,GAAG,6BAAqB,EAAE,GAAG,8BAAsB,CAAC,CAAC;AAG7E,QAAA,aAAa,GAAG,CAAC,GAAG,6BAAqB,EAAE,GAAG,0BAAkB,CAAU,CAAC;AAGxF,SAAgB,sBAAsB,CAAC,KAAc;IAKnD,MAAM,OAAO,GAAG,IAAA,sBAAa,EAAC,KAAK,CAAC,CAAC;IACrC,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QAC7B,OAAO;YACL,OAAO;YACP,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,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D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACzD,CAAC;AAdD,wDAcC"}
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/net/retry.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,yBAAyB,EAE1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAC;AAK7D,MAAM,MAAM,gCAAgC,GAAG,IAAI,CACjD,yBAAyB,CAAC,OAAO,CAAC,EAClC,aAAa,CACd,GAAG;IACF,2EAA2E;IAC3E,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,4DAA4D;IAC5D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAgBF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAKrE;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAKnE;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE,OAAO,CAAC,gCAAgC,CAAC,GAClD,OAAO,CAAC,CAAC,CAAC,CAwBZ"}
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/net/retry.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,yBAAyB,EAE1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAC;AAM7D,MAAM,MAAM,gCAAgC,GAAG,IAAI,CACjD,yBAAyB,CAAC,OAAO,CAAC,EAClC,aAAa,CACd,GAAG;IACF,2EAA2E;IAC3E,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,4DAA4D;IAC5D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAiBF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAKrE;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAKnE;AA6BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE,OAAO,CAAC,gCAAgC,CAAC,GAClD,OAAO,CAAC,CAAC,CAAC,CAwBZ"}
package/dist/net/retry.js CHANGED
@@ -7,6 +7,7 @@ exports.executeWithNetworkRetries = exports.getHttpCodeFromError = exports.getHt
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const retry_1 = require("../common/retry");
9
9
  const error_1 = require("./error");
10
+ const axios_2 = require("axios");
10
11
  const tooManyRequestsStatus = 429;
11
12
  const tooManyRequestsMultiplier = 3;
12
13
  const defaultOptions = {
@@ -16,7 +17,8 @@ const defaultOptions = {
16
17
  // https://nodejs.org/docs/latest-v18.x/api/errors.html#common-system-errors
17
18
  "ECONNREFUSED",
18
19
  "ECONNRESET",
19
- "ENOTFOUND", // (DNS lookup failed): Indicates a DNS failure of either EAI_NODATA or EAI_NONAME. This is not a standard POSIX error.
20
+ "ENOTFOUND",
21
+ axios_2.AxiosError.ERR_BAD_RESPONSE, // Response cannot be parsed properly or is in an unexpected format.
20
22
  ],
21
23
  httpStatusCodesToRetry: [tooManyRequestsStatus],
22
24
  retryOnTimeout: false,
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/net/retry.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,2CAMy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common code shared across packages - by Metriport Inc.",
5
5
  "author": "Metriport Inc. <contact@metriport.com>",
6
6
  "homepage": "https://metriport.com/",
@@ -65,5 +65,5 @@
65
65
  "devDependencies": {
66
66
  "@faker-js/faker": "^8.0.2"
67
67
  },
68
- "gitHead": "59f3d4bf7cdfbdbba37ba87354c930e38ba67c23"
68
+ "gitHead": "32681c706f23218103a3d2f76db6414df51bb81e"
69
69
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=normalize-zip.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalize-zip.test.d.ts","sourceRoot":"","sources":["../../../src/common/__tests__/normalize-zip.test.ts"],"names":[],"mappings":""}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const normalize_zip_1 = require("../normalize-zip");
4
- describe("normalizeZipCode", () => {
5
- test("should handle short zip codes", () => {
6
- const input = "1234";
7
- const expectedOutput = "1234";
8
- expect((0, normalize_zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
9
- });
10
- test("should return first 4 characters when zip code length is 9", () => {
11
- const input = "1234-6677";
12
- const expectedOutput = "1234";
13
- expect((0, normalize_zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
14
- });
15
- test("should return first 5 characters when zip code length is 10", () => {
16
- const input = "12345-6677";
17
- const expectedOutput = "12345";
18
- expect((0, normalize_zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
19
- });
20
- test("should return first 5 characters when zip code length is 5", () => {
21
- const input = "54321";
22
- const expectedOutput = "54321";
23
- expect((0, normalize_zip_1.normalizeZipCode)(input)).toBe(expectedOutput);
24
- });
25
- test("should throw an error if zip contains non-digit and non-dash characters (length 9)", () => {
26
- const input = "12345-667a";
27
- expect(() => (0, normalize_zip_1.normalizeZipCode)(input)).toThrow();
28
- });
29
- test("should throw an error if zip contains non-digit and non-dash characters (length 5)", () => {
30
- const input = "1234a";
31
- expect(() => (0, normalize_zip_1.normalizeZipCode)(input)).toThrow();
32
- });
33
- test("should throw an error if zip is an empty string", () => {
34
- const input = "";
35
- expect(() => (0, normalize_zip_1.normalizeZipCode)(input)).toThrow();
36
- });
37
- });
38
- //# sourceMappingURL=normalize-zip.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalize-zip.test.js","sourceRoot":"","sources":["../../../src/common/__tests__/normalize-zip.test.ts"],"names":[],"mappings":";;AAAA,oDAAoD;AAEpD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACzC,MAAM,KAAK,GAAG,MAAM,CAAC;QACrB,MAAM,cAAc,GAAG,MAAM,CAAC;QAC9B,MAAM,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACtE,MAAM,KAAK,GAAG,WAAW,CAAC;QAC1B,MAAM,cAAc,GAAG,MAAM,CAAC;QAC9B,MAAM,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACvE,MAAM,KAAK,GAAG,YAAY,CAAC;QAC3B,MAAM,cAAc,GAAG,OAAO,CAAC;QAC/B,MAAM,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACtE,MAAM,KAAK,GAAG,OAAO,CAAC;QACtB,MAAM,cAAc,GAAG,OAAO,CAAC;QAC/B,MAAM,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC9F,MAAM,KAAK,GAAG,YAAY,CAAC;QAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC9F,MAAM,KAAK,GAAG,OAAO,CAAC;QACtB,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC3D,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,gCAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Normalizes a zip code by taking the first 4-5 characters.
3
- * @param zipCode - The zip code to be normalized.
4
- * @returns The normalized zip code as a string.
5
- *
6
- * TODO: Refactor, so `normalize` simply returns a zip of a certain format and returns undefined if it cannot,
7
- * while `validate` would throw an error.
8
- */
9
- export declare function normalizeZipCode(zipCode: string): string;
10
- //# sourceMappingURL=normalize-zip.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalize-zip.d.ts","sourceRoot":"","sources":["../../src/common/normalize-zip.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQxD"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeZipCode = void 0;
4
- /**
5
- * Normalizes a zip code by taking the first 4-5 characters.
6
- * @param zipCode - The zip code to be normalized.
7
- * @returns The normalized zip code as a string.
8
- *
9
- * TODO: Refactor, so `normalize` simply returns a zip of a certain format and returns undefined if it cannot,
10
- * while `validate` would throw an error.
11
- */
12
- function normalizeZipCode(zipCode) {
13
- const trimmedZip = zipCode.trim();
14
- if (!isValidZipCode(trimmedZip)) {
15
- throw new Error("Zip codes may only contain numbers (0-9) and a dash (-)");
16
- }
17
- if (trimmedZip.includes("-") && trimmedZip.trim().length === 9)
18
- return trimmedZip.slice(0, 4);
19
- if (trimmedZip.trim().length === 8)
20
- return trimmedZip.slice(0, 4);
21
- return trimmedZip.slice(0, 5);
22
- }
23
- exports.normalizeZipCode = normalizeZipCode;
24
- function isValidZipCode(zipCode) {
25
- if (zipCode.length === 0)
26
- return false;
27
- const regex = /^[0-9-]+$/;
28
- return regex.test(zipCode);
29
- }
30
- //# sourceMappingURL=normalize-zip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalize-zip.js","sourceRoot":"","sources":["../../src/common/normalize-zip.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;KAC5E;IACD,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9F,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC;AARD,4CAQC;AAED,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=file-downloader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-downloader.d.ts","sourceRoot":"","sources":["../../../src/net/__tests__/file-downloader.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs = __importStar(require("fs"));
27
- const file_downloader_1 = require("../file-downloader");
28
- /**
29
- * - Create a temporary folder with files to download
30
- * - Create an HTTP server to serve the files:
31
- * $ python3 -m http.server 8432
32
- * - Update the `url` and `extension` constants with the name of the file to download
33
- */
34
- const url = "http://localhost:8432/file.png";
35
- const extension = "png";
36
- async function main1(fileName) {
37
- console.log(`Downloading file from: ${url} directly into the filesystem...`);
38
- const outputStream = fs.createWriteStream(fileName);
39
- await (0, file_downloader_1.downloadToStream)({
40
- url,
41
- outputStream,
42
- });
43
- console.log(`Done`);
44
- }
45
- async function main2(fileName) {
46
- console.log(`Downloading file from: ${url}...`);
47
- const buf = await (0, file_downloader_1.downloadToMemory)({
48
- url,
49
- });
50
- console.log(`Downloaded to buffer, storing on the filesystem...`);
51
- fs.writeFileSync(fileName, buf);
52
- console.log(`Done`);
53
- }
54
- async function main3(fileName) {
55
- console.log(`Downloading file from: ${url}...`);
56
- await (0, file_downloader_1.downloadToFile)({
57
- url,
58
- filePath: fileName,
59
- });
60
- console.log(`Done`);
61
- }
62
- const getFilename = (suffix) => `file_${suffix}.${extension}`;
63
- main1(getFilename("from_stream"));
64
- main2(getFilename("from_memory"));
65
- main3(getFilename("direct"));
66
- //# sourceMappingURL=file-downloader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-downloader.js","sourceRoot":"","sources":["../../../src/net/__tests__/file-downloader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,wDAAwF;AAExF;;;;;GAKG;AACH,MAAM,GAAG,GAAG,gCAAgC,CAAC;AAC7C,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,KAAK,UAAU,KAAK,CAAC,QAAgB;IACnC,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,kCAAkC,CAAC,CAAC;IAC7E,MAAM,YAAY,GAAG,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,IAAA,kCAAgB,EAAC;QACrB,GAAG;QACH,YAAY;KACb,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,KAAK,UAAU,KAAK,CAAC,QAAgB;IACnC,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,IAAA,kCAAgB,EAAC;QACjC,GAAG;KACJ,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;IAClE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEhC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AACD,KAAK,UAAU,KAAK,CAAC,QAAgB;IACnC,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;IAChD,MAAM,IAAA,gCAAc,EAAC;QACnB,GAAG;QACH,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,QAAQ,MAAM,IAAI,SAAS,EAAE,CAAC;AAEtE,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AAClC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AAClC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC"}
@@ -1,22 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import * as stream from "stream";
4
- type BaseParams = {
5
- headers?: {
6
- [index: string]: string;
7
- };
8
- timeout?: number;
9
- };
10
- export type DownloadToStreamParams = BaseParams & {
11
- url: string;
12
- outputStream: stream.Writable;
13
- };
14
- export type DownloadToMemoryParams = Omit<DownloadToStreamParams, "outputStream">;
15
- export type DownloadToFileParams = Omit<DownloadToStreamParams, "outputStream"> & {
16
- filePath: string;
17
- };
18
- export declare function downloadToStream({ url, outputStream, ...configParams }: DownloadToStreamParams): Promise<boolean>;
19
- export declare function downloadToMemory({ url, ...configParams }: DownloadToMemoryParams): Promise<Buffer>;
20
- export declare function downloadToFile(params: DownloadToFileParams): Promise<void>;
21
- export {};
22
- //# sourceMappingURL=file-downloader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-downloader.d.ts","sourceRoot":"","sources":["../../src/net/file-downloader.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAKjC,KAAK,UAAU,GAAG;IAChB,OAAO,CAAC,EAAE;QACR,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;KACzB,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AAElF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC,GAAG;IAChF,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,EACrC,GAAG,EACH,YAAY,EACZ,GAAG,YAAY,EAChB,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAK3C;AAED,wBAAsB,gBAAgB,CAAC,EACrC,GAAG,EACH,GAAG,YAAY,EAChB,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1C;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhF"}
@@ -1,67 +0,0 @@
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
- exports.downloadToFile = exports.downloadToMemory = exports.downloadToStream = void 0;
30
- const axios_1 = __importDefault(require("axios"));
31
- const fs = __importStar(require("fs"));
32
- const stream = __importStar(require("stream"));
33
- const util = __importStar(require("util"));
34
- const pipeline = util.promisify(stream.pipeline);
35
- async function downloadToStream({ url, outputStream, ...configParams }) {
36
- const requestConfig = buildRequestConfig(configParams, "stream");
37
- const response = await axios_1.default.get(url, requestConfig);
38
- await pipeline(response.data, outputStream);
39
- return true;
40
- }
41
- exports.downloadToStream = downloadToStream;
42
- async function downloadToMemory({ url, ...configParams }) {
43
- const requestConfig = buildRequestConfig(configParams, "arraybuffer");
44
- const response = await axios_1.default.get(url, requestConfig);
45
- return await response.data;
46
- }
47
- exports.downloadToMemory = downloadToMemory;
48
- async function downloadToFile(params) {
49
- const outputStream = fs.createWriteStream(params.filePath);
50
- await downloadToStream({
51
- ...params,
52
- outputStream,
53
- });
54
- }
55
- exports.downloadToFile = downloadToFile;
56
- function buildRequestConfig({ timeout, headers }, responseType) {
57
- const requestConfig = {
58
- responseType,
59
- ...(timeout ? { timeout } : undefined),
60
- transitional: {
61
- clarifyTimeoutError: true,
62
- },
63
- ...(headers && { headers }),
64
- };
65
- return requestConfig;
66
- }
67
- //# sourceMappingURL=file-downloader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-downloader.js","sourceRoot":"","sources":["../../src/net/file-downloader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAgE;AAChE,uCAAyB;AACzB,+CAAiC;AACjC,2CAA6B;AAE7B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAoB1C,KAAK,UAAU,gBAAgB,CAAC,EACrC,GAAG,EACH,YAAY,EACZ,GAAG,YAAY,EACQ;IACvB,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC;AATD,4CASC;AAEM,KAAK,UAAU,gBAAgB,CAAC,EACrC,GAAG,EACH,GAAG,YAAY,EACQ;IACvB,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IACrD,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC;AAC7B,CAAC;AAPD,4CAOC;AAEM,KAAK,UAAU,cAAc,CAAC,MAA4B;IAC/D,MAAM,YAAY,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,gBAAgB,CAAC;QACrB,GAAG,MAAM;QACT,YAAY;KACb,CAAC,CAAC;AACL,CAAC;AAND,wCAMC;AAED,SAAS,kBAAkB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