@metriport/commonwell-sdk 4.3.3 → 4.3.5

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 (57) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +40 -40
  3. package/lib/client/commonwell-api.d.ts +49 -49
  4. package/lib/client/commonwell-api.js +2 -2
  5. package/lib/client/commonwell.d.ts +425 -425
  6. package/lib/client/commonwell.js +739 -739
  7. package/lib/client/document.d.ts +7 -7
  8. package/lib/client/document.js +71 -71
  9. package/lib/common/commonwell-error.d.ts +12 -12
  10. package/lib/common/commonwell-error.js +34 -34
  11. package/lib/common/fileDownload.d.ts +11 -11
  12. package/lib/common/fileDownload.js +43 -43
  13. package/lib/common/make-jwt.d.ts +24 -24
  14. package/lib/common/make-jwt.js +90 -90
  15. package/lib/common/metriport-error.d.ts +4 -4
  16. package/lib/common/metriport-error.js +33 -33
  17. package/lib/common/util.d.ts +25 -25
  18. package/lib/common/util.js +70 -70
  19. package/lib/common/validate-npi.d.ts +9 -9
  20. package/lib/common/validate-npi.js +39 -39
  21. package/lib/index.d.ts +20 -20
  22. package/lib/index.js +54 -54
  23. package/lib/models/address.d.ts +50 -50
  24. package/lib/models/address.js +28 -28
  25. package/lib/models/certificates.d.ts +156 -156
  26. package/lib/models/certificates.js +26 -26
  27. package/lib/models/contact.d.ts +50 -50
  28. package/lib/models/contact.js +39 -39
  29. package/lib/models/demographics.d.ts +292 -292
  30. package/lib/models/demographics.js +34 -34
  31. package/lib/models/document.d.ts +4421 -4421
  32. package/lib/models/document.js +151 -151
  33. package/lib/models/enrollment-summary.d.ts +18 -18
  34. package/lib/models/enrollment-summary.js +14 -14
  35. package/lib/models/facility.d.ts +75 -75
  36. package/lib/models/facility.js +10 -10
  37. package/lib/models/human-name.d.ts +53 -53
  38. package/lib/models/human-name.js +37 -37
  39. package/lib/models/identifier.d.ts +79 -79
  40. package/lib/models/identifier.js +36 -36
  41. package/lib/models/iso-date.d.ts +3 -3
  42. package/lib/models/iso-date.js +6 -6
  43. package/lib/models/iso-datetime.d.ts +3 -3
  44. package/lib/models/iso-datetime.js +8 -8
  45. package/lib/models/link.d.ts +642 -642
  46. package/lib/models/link.js +50 -50
  47. package/lib/models/organization.d.ts +763 -763
  48. package/lib/models/organization.js +83 -83
  49. package/lib/models/patient.d.ts +3617 -3617
  50. package/lib/models/patient.js +49 -49
  51. package/lib/models/period.d.ts +12 -12
  52. package/lib/models/period.js +12 -12
  53. package/lib/models/person.d.ts +2440 -2440
  54. package/lib/models/person.js +39 -39
  55. package/lib/models/purpose-of-use.d.ts +29 -29
  56. package/lib/models/purpose-of-use.js +34 -34
  57. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
- /// <reference types="node" />
2
- import { AxiosInstance } from "axios";
3
- import * as stream from "stream";
4
- import { DocumentQueryFullResponse, DocumentQueryResponse } from "../models/document";
5
- export declare function query(api: AxiosInstance, headers: Record<string, string>, patientId: string): Promise<DocumentQueryResponse>;
6
- export declare function queryFull(api: AxiosInstance, headers: Record<string, string>, patientId: string): Promise<DocumentQueryFullResponse>;
7
- export declare function retrieve(api: AxiosInstance, headers: Record<string, string>, inputUrl: string, outputStream: stream.Writable): Promise<void>;
1
+ /// <reference types="node" />
2
+ import { AxiosInstance } from "axios";
3
+ import * as stream from "stream";
4
+ import { DocumentQueryFullResponse, DocumentQueryResponse } from "../models/document";
5
+ export declare function query(api: AxiosInstance, headers: Record<string, string>, patientId: string): Promise<DocumentQueryResponse>;
6
+ export declare function queryFull(api: AxiosInstance, headers: Record<string, string>, patientId: string): Promise<DocumentQueryFullResponse>;
7
+ export declare function retrieve(api: AxiosInstance, headers: Record<string, string>, inputUrl: string, outputStream: stream.Writable): Promise<void>;
@@ -1,72 +1,72 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retrieve = exports.queryFull = exports.query = void 0;
4
- const commonwell_error_1 = require("../common/commonwell-error");
5
- const fileDownload_1 = require("../common/fileDownload");
6
- const util_1 = require("../common/util");
7
- const document_1 = require("../models/document");
8
- const commonwell_1 = require("./commonwell");
9
- async function initQuery(api, headers, patientId
10
- //eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- ) {
12
- const subjectId = (0, util_1.convertPatientIdToSubjectId)(patientId);
13
- if (!subjectId) {
14
- throw new Error(`Could not determine subject ID for document query`);
15
- }
16
- const url = `${commonwell_1.CommonWell.DOCUMENT_QUERY_ENDPOINT}?subject.id=${subjectId}`;
17
- const additionalInfo = { headers, patientId };
18
- try {
19
- const response = await api.get(url, { headers });
20
- return response;
21
- }
22
- catch (err) {
23
- throw new commonwell_error_1.CommonwellError(`Error querying documents`, err, additionalInfo);
24
- }
25
- }
26
- async function query(api, headers, patientId) {
27
- const response = await initQuery(api, headers, patientId);
28
- try {
29
- return document_1.documentQueryResponseSchema.parse(response.data);
30
- }
31
- catch (err) {
32
- throw new commonwell_error_1.CommonwellError(`Error parsing document query response`, err, {
33
- headers,
34
- patientId,
35
- response,
36
- });
37
- }
38
- }
39
- exports.query = query;
40
- async function queryFull(api, headers, patientId) {
41
- const response = await initQuery(api, headers, patientId);
42
- try {
43
- return document_1.documentQueryFullResponseSchema.parse(response.data);
44
- }
45
- catch (err) {
46
- throw new commonwell_error_1.CommonwellError(`Error parsing document query response`, err, {
47
- headers,
48
- patientId,
49
- response,
50
- });
51
- }
52
- }
53
- exports.queryFull = queryFull;
54
- async function retrieve(api, headers, inputUrl, outputStream) {
55
- try {
56
- await (0, fileDownload_1.downloadFile)({
57
- url: inputUrl,
58
- outputStream,
59
- client: api,
60
- headers,
61
- });
62
- }
63
- catch (err) {
64
- throw new commonwell_error_1.CommonwellError(`Error retrieve document`, err, {
65
- headers,
66
- inputUrl,
67
- outputStream: outputStream ? "[object]" : outputStream,
68
- });
69
- }
70
- }
71
- exports.retrieve = retrieve;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieve = exports.queryFull = exports.query = void 0;
4
+ const commonwell_error_1 = require("../common/commonwell-error");
5
+ const fileDownload_1 = require("../common/fileDownload");
6
+ const util_1 = require("../common/util");
7
+ const document_1 = require("../models/document");
8
+ const commonwell_1 = require("./commonwell");
9
+ async function initQuery(api, headers, patientId
10
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ ) {
12
+ const subjectId = (0, util_1.convertPatientIdToSubjectId)(patientId);
13
+ if (!subjectId) {
14
+ throw new Error(`Could not determine subject ID for document query`);
15
+ }
16
+ const url = `${commonwell_1.CommonWell.DOCUMENT_QUERY_ENDPOINT}?subject.id=${subjectId}`;
17
+ const additionalInfo = { headers, patientId };
18
+ try {
19
+ const response = await api.get(url, { headers });
20
+ return response;
21
+ }
22
+ catch (err) {
23
+ throw new commonwell_error_1.CommonwellError(`Error querying documents`, err, additionalInfo);
24
+ }
25
+ }
26
+ async function query(api, headers, patientId) {
27
+ const response = await initQuery(api, headers, patientId);
28
+ try {
29
+ return document_1.documentQueryResponseSchema.parse(response.data);
30
+ }
31
+ catch (err) {
32
+ throw new commonwell_error_1.CommonwellError(`Error parsing document query response`, err, {
33
+ headers,
34
+ patientId,
35
+ response,
36
+ });
37
+ }
38
+ }
39
+ exports.query = query;
40
+ async function queryFull(api, headers, patientId) {
41
+ const response = await initQuery(api, headers, patientId);
42
+ try {
43
+ return document_1.documentQueryFullResponseSchema.parse(response.data);
44
+ }
45
+ catch (err) {
46
+ throw new commonwell_error_1.CommonwellError(`Error parsing document query response`, err, {
47
+ headers,
48
+ patientId,
49
+ response,
50
+ });
51
+ }
52
+ }
53
+ exports.queryFull = queryFull;
54
+ async function retrieve(api, headers, inputUrl, outputStream) {
55
+ try {
56
+ await (0, fileDownload_1.downloadFile)({
57
+ url: inputUrl,
58
+ outputStream,
59
+ client: api,
60
+ headers,
61
+ });
62
+ }
63
+ catch (err) {
64
+ throw new commonwell_error_1.CommonwellError(`Error retrieve document`, err, {
65
+ headers,
66
+ inputUrl,
67
+ outputStream: outputStream ? "[object]" : outputStream,
68
+ });
69
+ }
70
+ }
71
+ exports.retrieve = retrieve;
72
72
  //# sourceMappingURL=document.js.map
@@ -1,12 +1,12 @@
1
- declare class Response {
2
- status: number | undefined;
3
- }
4
- export declare class CommonwellError extends Error {
5
- readonly cause?: any;
6
- readonly additionalInfo?: any;
7
- private _status;
8
- constructor(message?: string | undefined, cause?: any, additionalInfo?: any);
9
- get status(): number | undefined;
10
- get response(): Response;
11
- }
12
- export {};
1
+ declare class Response {
2
+ status: number | undefined;
3
+ }
4
+ export declare class CommonwellError extends Error {
5
+ readonly cause?: any;
6
+ readonly additionalInfo?: any;
7
+ private _status;
8
+ constructor(message?: string | undefined, cause?: any, additionalInfo?: any);
9
+ get status(): number | undefined;
10
+ get response(): Response;
11
+ }
12
+ export {};
@@ -1,35 +1,35 @@
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.CommonwellError = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class Response {
9
- }
10
- class CommonwellError extends Error {
11
- //eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- constructor(message, cause, additionalInfo) {
13
- super(message);
14
- this.cause = cause;
15
- this.additionalInfo = additionalInfo;
16
- if (cause) {
17
- if (axios_1.default.isAxiosError(cause)) {
18
- this._status = cause.response?.status;
19
- }
20
- else {
21
- this._status = cause.status;
22
- }
23
- }
24
- }
25
- get status() {
26
- return this._status;
27
- }
28
- get response() {
29
- return {
30
- status: this._status,
31
- };
32
- }
33
- }
34
- exports.CommonwellError = CommonwellError;
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.CommonwellError = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class Response {
9
+ }
10
+ class CommonwellError extends Error {
11
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ constructor(message, cause, additionalInfo) {
13
+ super(message);
14
+ this.cause = cause;
15
+ this.additionalInfo = additionalInfo;
16
+ if (cause) {
17
+ if (axios_1.default.isAxiosError(cause)) {
18
+ this._status = cause.response?.status;
19
+ }
20
+ else {
21
+ this._status = cause.status;
22
+ }
23
+ }
24
+ }
25
+ get status() {
26
+ return this._status;
27
+ }
28
+ get response() {
29
+ return {
30
+ status: this._status,
31
+ };
32
+ }
33
+ }
34
+ exports.CommonwellError = CommonwellError;
35
35
  //# sourceMappingURL=commonwell-error.js.map
@@ -1,11 +1,11 @@
1
- /// <reference types="node" />
2
- import { AxiosInstance } from "axios";
3
- import * as stream from "stream";
4
- export declare function downloadFile({ url, outputStream, client, headers, }: {
5
- url: string;
6
- outputStream: stream.Writable;
7
- client?: AxiosInstance;
8
- headers?: {
9
- [index: string]: string;
10
- };
11
- }): Promise<boolean>;
1
+ /// <reference types="node" />
2
+ import { AxiosInstance } from "axios";
3
+ import * as stream from "stream";
4
+ export declare function downloadFile({ url, outputStream, client, headers, }: {
5
+ url: string;
6
+ outputStream: stream.Writable;
7
+ client?: AxiosInstance;
8
+ headers?: {
9
+ [index: string]: string;
10
+ };
11
+ }): Promise<boolean>;
@@ -1,44 +1,44 @@
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.downloadFile = void 0;
30
- const axios_1 = __importDefault(require("axios"));
31
- const stream = __importStar(require("stream"));
32
- const util = __importStar(require("util"));
33
- const pipeline = util.promisify(stream.pipeline);
34
- async function downloadFile({ url, outputStream, client, headers, }) {
35
- const config = {
36
- responseType: "stream",
37
- ...(headers && { headers }),
38
- };
39
- const response = await (client ?? axios_1.default).get(url, config);
40
- await pipeline(response.data, outputStream);
41
- return true;
42
- }
43
- exports.downloadFile = downloadFile;
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.downloadFile = void 0;
30
+ const axios_1 = __importDefault(require("axios"));
31
+ const stream = __importStar(require("stream"));
32
+ const util = __importStar(require("util"));
33
+ const pipeline = util.promisify(stream.pipeline);
34
+ async function downloadFile({ url, outputStream, client, headers, }) {
35
+ const config = {
36
+ responseType: "stream",
37
+ ...(headers && { headers }),
38
+ };
39
+ const response = await (client ?? axios_1.default).get(url, config);
40
+ await pipeline(response.data, outputStream);
41
+ return true;
42
+ }
43
+ exports.downloadFile = downloadFile;
44
44
  //# sourceMappingURL=fileDownload.js.map
@@ -1,24 +1,24 @@
1
- import { PurposeOfUse } from "../models/purpose-of-use";
2
- /**
3
- * Creates a JWT Based on the specified parameters as per the CommonWell spec:
4
- * https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/JWT-Token.aspx
5
- *
6
- * @param rsaPrivateKey The RSA256 private key corresponding to the specified organization's
7
- * public key (certificate) - used for signing the JWT.
8
- * @param role The practitioner role of the entity making this request. Valid role
9
- * values: https://hl7.org/fhir/R4/valueset-practitioner-role.html
10
- * @param subjectId Free text field used for audit purposes. The value should be user ID or
11
- * user name of staff using the CommonWell enabled system. Can be a system
12
- * user if the API call is generated from an automated process instead
13
- * of an actual user.
14
- * @param orgName The organization name for the request, should match the OID in the
15
- * claims.
16
- * @param oid OID of the org making the request. CW uses this ID to certificate in
17
- * order to validate the signature on the token.
18
- * @param purposeOfUse The purpose of use (POU) for this request.
19
- * @param npi Ten digit National Provider Identifier (optional).
20
- * @param payloadHash Only required for Patient IDLink - MurmurHash2 calculation of HTTP POST
21
- * body (optional).
22
- * @returns The JWT token.
23
- */
24
- export declare function makeJwt(rsaPrivateKey: string, role: string, subjectId: string, orgName: string, oid: string, purposeOfUse: PurposeOfUse, npi?: string, payloadHash?: string): Promise<string>;
1
+ import { PurposeOfUse } from "../models/purpose-of-use";
2
+ /**
3
+ * Creates a JWT Based on the specified parameters as per the CommonWell spec:
4
+ * https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/JWT-Token.aspx
5
+ *
6
+ * @param rsaPrivateKey The RSA256 private key corresponding to the specified organization's
7
+ * public key (certificate) - used for signing the JWT.
8
+ * @param role The practitioner role of the entity making this request. Valid role
9
+ * values: https://hl7.org/fhir/R4/valueset-practitioner-role.html
10
+ * @param subjectId Free text field used for audit purposes. The value should be user ID or
11
+ * user name of staff using the CommonWell enabled system. Can be a system
12
+ * user if the API call is generated from an automated process instead
13
+ * of an actual user.
14
+ * @param orgName The organization name for the request, should match the OID in the
15
+ * claims.
16
+ * @param oid OID of the org making the request. CW uses this ID to certificate in
17
+ * order to validate the signature on the token.
18
+ * @param purposeOfUse The purpose of use (POU) for this request.
19
+ * @param npi Ten digit National Provider Identifier (optional).
20
+ * @param payloadHash Only required for Patient IDLink - MurmurHash2 calculation of HTTP POST
21
+ * body (optional).
22
+ * @returns The JWT token.
23
+ */
24
+ export declare function makeJwt(rsaPrivateKey: string, role: string, subjectId: string, orgName: string, oid: string, purposeOfUse: PurposeOfUse, npi?: string, payloadHash?: string): Promise<string>;
@@ -1,91 +1,91 @@
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
- exports.makeJwt = void 0;
27
- const jwt = __importStar(require("jsonwebtoken"));
28
- const validate_npi_1 = require("./validate-npi");
29
- // The parameterized JWT claims
30
- const roleClaim = "urn:oasis:names:tc:xacml:2.0:subject:role";
31
- const subjectIdClaim = "urn:oasis:names:tc:xspa:1.0:subject:subject-id";
32
- const orgNameClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization";
33
- const oidClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization-id";
34
- const purposeOfUseClaim = "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse";
35
- const npiClaim = "urn:oasis:names:tc:xspa:2.0:subject:npi";
36
- const payloadHashClaim = "urn:commonwell-alliance:payload-hash";
37
- /**
38
- * Creates a JWT Based on the specified parameters as per the CommonWell spec:
39
- * https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/JWT-Token.aspx
40
- *
41
- * @param rsaPrivateKey The RSA256 private key corresponding to the specified organization's
42
- * public key (certificate) - used for signing the JWT.
43
- * @param role The practitioner role of the entity making this request. Valid role
44
- * values: https://hl7.org/fhir/R4/valueset-practitioner-role.html
45
- * @param subjectId Free text field used for audit purposes. The value should be user ID or
46
- * user name of staff using the CommonWell enabled system. Can be a system
47
- * user if the API call is generated from an automated process instead
48
- * of an actual user.
49
- * @param orgName The organization name for the request, should match the OID in the
50
- * claims.
51
- * @param oid OID of the org making the request. CW uses this ID to certificate in
52
- * order to validate the signature on the token.
53
- * @param purposeOfUse The purpose of use (POU) for this request.
54
- * @param npi Ten digit National Provider Identifier (optional).
55
- * @param payloadHash Only required for Patient IDLink - MurmurHash2 calculation of HTTP POST
56
- * body (optional).
57
- * @returns The JWT token.
58
- */
59
- async function makeJwt(rsaPrivateKey, role, subjectId, orgName, oid, purposeOfUse, npi, payloadHash) {
60
- if (npi && !(0, validate_npi_1.validateNPI)(npi)) {
61
- throw new Error(`NPI number ${npi} is not valid!`);
62
- }
63
- const jwtToken = await new Promise((resolve, reject) => {
64
- jwt.sign({
65
- [roleClaim]: role,
66
- [subjectIdClaim]: subjectId,
67
- [orgNameClaim]: orgName,
68
- [oidClaim]: oid,
69
- [purposeOfUseClaim]: purposeOfUse.toString(),
70
- ...(npi && { [npiClaim]: npi }),
71
- ...(payloadHash && { [payloadHashClaim]: payloadHash }),
72
- }, rsaPrivateKey, {
73
- algorithm: "RS256",
74
- issuer: "self",
75
- notBefore: "0",
76
- // Max duration between Not Before and Expiration claims cannot exceed 8 hours.
77
- expiresIn: "8h",
78
- audience: "urn:commonwellalliance.org",
79
- noTimestamp: true,
80
- }, function (err, token) {
81
- if (err || !token) {
82
- reject(err);
83
- return;
84
- }
85
- resolve(token);
86
- });
87
- });
88
- return jwtToken;
89
- }
90
- exports.makeJwt = makeJwt;
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
+ exports.makeJwt = void 0;
27
+ const jwt = __importStar(require("jsonwebtoken"));
28
+ const validate_npi_1 = require("./validate-npi");
29
+ // The parameterized JWT claims
30
+ const roleClaim = "urn:oasis:names:tc:xacml:2.0:subject:role";
31
+ const subjectIdClaim = "urn:oasis:names:tc:xspa:1.0:subject:subject-id";
32
+ const orgNameClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization";
33
+ const oidClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization-id";
34
+ const purposeOfUseClaim = "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse";
35
+ const npiClaim = "urn:oasis:names:tc:xspa:2.0:subject:npi";
36
+ const payloadHashClaim = "urn:commonwell-alliance:payload-hash";
37
+ /**
38
+ * Creates a JWT Based on the specified parameters as per the CommonWell spec:
39
+ * https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/JWT-Token.aspx
40
+ *
41
+ * @param rsaPrivateKey The RSA256 private key corresponding to the specified organization's
42
+ * public key (certificate) - used for signing the JWT.
43
+ * @param role The practitioner role of the entity making this request. Valid role
44
+ * values: https://hl7.org/fhir/R4/valueset-practitioner-role.html
45
+ * @param subjectId Free text field used for audit purposes. The value should be user ID or
46
+ * user name of staff using the CommonWell enabled system. Can be a system
47
+ * user if the API call is generated from an automated process instead
48
+ * of an actual user.
49
+ * @param orgName The organization name for the request, should match the OID in the
50
+ * claims.
51
+ * @param oid OID of the org making the request. CW uses this ID to certificate in
52
+ * order to validate the signature on the token.
53
+ * @param purposeOfUse The purpose of use (POU) for this request.
54
+ * @param npi Ten digit National Provider Identifier (optional).
55
+ * @param payloadHash Only required for Patient IDLink - MurmurHash2 calculation of HTTP POST
56
+ * body (optional).
57
+ * @returns The JWT token.
58
+ */
59
+ async function makeJwt(rsaPrivateKey, role, subjectId, orgName, oid, purposeOfUse, npi, payloadHash) {
60
+ if (npi && !(0, validate_npi_1.validateNPI)(npi)) {
61
+ throw new Error(`NPI number ${npi} is not valid!`);
62
+ }
63
+ const jwtToken = await new Promise((resolve, reject) => {
64
+ jwt.sign({
65
+ [roleClaim]: role,
66
+ [subjectIdClaim]: subjectId,
67
+ [orgNameClaim]: orgName,
68
+ [oidClaim]: oid,
69
+ [purposeOfUseClaim]: purposeOfUse.toString(),
70
+ ...(npi && { [npiClaim]: npi }),
71
+ ...(payloadHash && { [payloadHashClaim]: payloadHash }),
72
+ }, rsaPrivateKey, {
73
+ algorithm: "RS256",
74
+ issuer: "self",
75
+ notBefore: "0",
76
+ // Max duration between Not Before and Expiration claims cannot exceed 8 hours.
77
+ expiresIn: "8h",
78
+ audience: "urn:commonwellalliance.org",
79
+ noTimestamp: true,
80
+ }, function (err, token) {
81
+ if (err || !token) {
82
+ reject(err);
83
+ return;
84
+ }
85
+ resolve(token);
86
+ });
87
+ });
88
+ return jwtToken;
89
+ }
90
+ exports.makeJwt = makeJwt;
91
91
  //# sourceMappingURL=make-jwt.js.map
@@ -1,4 +1,4 @@
1
- export default class MetriportError extends Error {
2
- status: number;
3
- constructor(message: string, status?: number);
4
- }
1
+ export default class MetriportError extends Error {
2
+ status: number;
3
+ constructor(message: string, status?: number);
4
+ }