@metriport/commonwell-sdk 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License Copyright (c) 2022 Metriport Inc.
2
+
3
+ Permission is hereby granted, free of
4
+ charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ (including the next paragraph) shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # `commonwell-sdk`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const commonwellSdk = require('commonwell-sdk');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
12
+
13
+ ```
14
+ ,▄,
15
+ ▄▓███▌
16
+ ▄▀╙ ▀▓▀ ²▄
17
+ ▄└ ╙▌
18
+ ,▀ ╨▄
19
+ ▌ ║
20
+
21
+
22
+ ,▓██▄ ╔███▄
23
+ ╙███▌ ▀███▀
24
+ ▀▄
25
+ ▀╗▄ ,▄
26
+ '╙▀▀▀▀▀╙''
27
+
28
+
29
+ by Metriport Inc.
30
+
31
+ ```
@@ -0,0 +1,2 @@
1
+ import { PurposeOfUse } from "../models/purpose-of-use";
2
+ export declare function makeJwt(rsaPrivateKey: string, role: string, subjectId: string, orgName: string, oid: string, purposeOfUse: PurposeOfUse, npi?: string, payloadHash?: string): Promise<string>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.makeJwt = void 0;
13
+ const jwt = require("jsonwebtoken");
14
+ const validate_npi_1 = require("./validate-npi");
15
+ const roleClaim = "urn:oasis:names:tc:xacml:2.0:subject:role";
16
+ const subjectIdClaim = "urn:oasis:names:tc:xspa:1.0:subject:subject-id";
17
+ const orgNameClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization";
18
+ const oidClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization-id";
19
+ const purposeOfUseClaim = "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse";
20
+ const npiClaim = "urn:oasis:names:tc:xspa:2.0:subject:npi";
21
+ const payloadHashClaim = "urn:commonwell-alliance:payload-hash";
22
+ function makeJwt(rsaPrivateKey, role, subjectId, orgName, oid, purposeOfUse, npi, payloadHash) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (npi && !(0, validate_npi_1.validateNPI)(npi)) {
25
+ throw new Error(`NPI number ${npi} is not valid!`);
26
+ }
27
+ const jwtToken = yield new Promise((res, rej) => {
28
+ jwt.sign(Object.assign(Object.assign({ [roleClaim]: role, [subjectIdClaim]: subjectId, [orgNameClaim]: orgName, [oidClaim]: oid, [purposeOfUseClaim]: purposeOfUse.toString() }, (npi && { [npiClaim]: npi })), (payloadHash && { [payloadHashClaim]: payloadHash })), rsaPrivateKey, {
29
+ algorithm: "RS256",
30
+ issuer: "self",
31
+ notBefore: "0",
32
+ expiresIn: "8h",
33
+ audience: "urn:commonwellalliance.org",
34
+ noTimestamp: true,
35
+ }, function (err, token) {
36
+ if (err) {
37
+ rej(err);
38
+ }
39
+ res(token);
40
+ });
41
+ });
42
+ return jwtToken;
43
+ });
44
+ }
45
+ exports.makeJwt = makeJwt;
46
+ //# sourceMappingURL=make-jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-jwt.js","sourceRoot":"","sources":["../../src/common/make-jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AAEpC,iDAA6C;AAG7C,MAAM,SAAS,GAAG,2CAA2C,CAAC;AAC9D,MAAM,cAAc,GAAG,gDAAgD,CAAC;AACxE,MAAM,YAAY,GAAG,kDAAkD,CAAC;AACxE,MAAM,QAAQ,GAAG,qDAAqD,CAAC;AACvE,MAAM,iBAAiB,GAAG,kDAAkD,CAAC;AAC7E,MAAM,QAAQ,GAAG,yCAAyC,CAAC;AAC3D,MAAM,gBAAgB,GAAG,sCAAsC,CAAC;AAwBhE,SAAsB,OAAO,CAC3B,aAAqB,EACrB,IAAY,EACZ,SAAiB,EACjB,OAAe,EACf,GAAW,EACX,YAA0B,EAC1B,GAAY,EACZ,WAAoB;;QAEpB,IAAI,GAAG,IAAI,CAAC,IAAA,0BAAW,EAAC,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,cAAc,GAAG,gBAAgB,CAAC,CAAC;SACpD;QACD,MAAM,QAAQ,GAAW,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACtD,GAAG,CAAC,IAAI,+BAEJ,CAAC,SAAS,CAAC,EAAE,IAAI,EACjB,CAAC,cAAc,CAAC,EAAE,SAAS,EAC3B,CAAC,YAAY,CAAC,EAAE,OAAO,EACvB,CAAC,QAAQ,CAAC,EAAE,GAAG,EACf,CAAC,iBAAiB,CAAC,EAAE,YAAY,CAAC,QAAQ,EAAE,IACzC,CAAC,GAAG,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,GAC5B,CAAC,WAAW,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAC,GAEzD,aAAa,EACb;gBACE,SAAS,EAAE,OAAO;gBAClB,MAAM,EAAE,MAAM;gBACd,SAAS,EAAE,GAAG;gBAEd,SAAS,EAAE,IAAI;gBACf,QAAQ,EAAE,4BAA4B;gBACtC,WAAW,EAAE,IAAI;aAClB,EACD,UAAU,GAAG,EAAE,KAAK;gBAClB,IAAI,GAAG,EAAE;oBACP,GAAG,CAAC,GAAG,CAAC,CAAC;iBACV;gBACD,GAAG,CAAC,KAAK,CAAC,CAAC;YACb,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AA5CD,0BA4CC"}
@@ -0,0 +1 @@
1
+ export declare function validateNPI(npi: string): boolean;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateNPI = void 0;
4
+ function validateNPI(npi) {
5
+ if (npi.length !== 10) {
6
+ return false;
7
+ }
8
+ let sum = 0;
9
+ let isEven = false;
10
+ for (let i = npi.length - 1; i >= 0; i--) {
11
+ let digit = parseInt(npi.charAt(i), 10);
12
+ if (isEven) {
13
+ digit *= 2;
14
+ if (digit > 9) {
15
+ digit -= 9;
16
+ }
17
+ }
18
+ sum += digit;
19
+ isEven = !isEven;
20
+ }
21
+ return sum % 10 === 0;
22
+ }
23
+ exports.validateNPI = validateNPI;
24
+ //# sourceMappingURL=validate-npi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-npi.js","sourceRoot":"","sources":["../../src/common/validate-npi.ts"],"names":[],"mappings":";;;AAMA,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE;QACrB,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACxC,IAAI,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAExC,IAAI,MAAM,EAAE;YACV,KAAK,IAAI,CAAC,CAAC;YACX,IAAI,KAAK,GAAG,CAAC,EAAE;gBACb,KAAK,IAAI,CAAC,CAAC;aACZ;SACF;QAED,GAAG,IAAI,KAAK,CAAC;QACb,MAAM,GAAG,CAAC,MAAM,CAAC;KAClB;IAED,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC;AAtBD,kCAsBC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { makeJwt } from "./common/make-jwt";
2
+ export { PurposeOfUse } from "./models/purpose-of-use";
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PurposeOfUse = exports.makeJwt = void 0;
4
+ var make_jwt_1 = require("./common/make-jwt");
5
+ Object.defineProperty(exports, "makeJwt", { enumerable: true, get: function () { return make_jwt_1.makeJwt; } });
6
+ var purpose_of_use_1 = require("./models/purpose-of-use");
7
+ Object.defineProperty(exports, "PurposeOfUse", { enumerable: true, get: function () { return purpose_of_use_1.PurposeOfUse; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8CAA4C;AAAnC,mGAAA,OAAO,OAAA;AAChB,0DAAqD;AAA7C,8GAAA,YAAY,OAAA"}
@@ -0,0 +1,29 @@
1
+ export declare enum PurposeOfUse {
2
+ TREATMENT = "TREATMENT",
3
+ PAYMENT = "PAYMENT",
4
+ OPERATIONS = "OPERATIONS",
5
+ SYSADMIN = "SYSADMIN",
6
+ FRAUD = "FRAUD",
7
+ PSYCHOTHERAPY = "PSYCHOTHERAPY",
8
+ TRAINING = "TRAINING",
9
+ LEGAL = "LEGAL",
10
+ MARKETING = "MARKETING",
11
+ DIRECTORY = "DIRECTORY",
12
+ FAMILY = "FAMILY",
13
+ PRESENT = "PRESENT",
14
+ EMERGENCY = "EMERGENCY",
15
+ DISASTER = "DISASTER",
16
+ PUBLICHEALTH = "PUBLICHEALTH",
17
+ ABUSE = "ABUSE",
18
+ OVERSIGHT = "OVERSIGHT",
19
+ JUDICIAL = "JUDICIAL",
20
+ LAW = "LAW",
21
+ DECEASED = "DECEASED",
22
+ DONATION = "DONATION",
23
+ RESEARCH = "RESEARCH",
24
+ THREAT = "THREAT",
25
+ GOVERNMENT = "GOVERNMENT",
26
+ WORKERSCOMP = "WORKERSCOMP",
27
+ COVERAGE = "COVERAGE",
28
+ REQUEST = "REQUEST"
29
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PurposeOfUse = void 0;
4
+ var PurposeOfUse;
5
+ (function (PurposeOfUse) {
6
+ PurposeOfUse["TREATMENT"] = "TREATMENT";
7
+ PurposeOfUse["PAYMENT"] = "PAYMENT";
8
+ PurposeOfUse["OPERATIONS"] = "OPERATIONS";
9
+ PurposeOfUse["SYSADMIN"] = "SYSADMIN";
10
+ PurposeOfUse["FRAUD"] = "FRAUD";
11
+ PurposeOfUse["PSYCHOTHERAPY"] = "PSYCHOTHERAPY";
12
+ PurposeOfUse["TRAINING"] = "TRAINING";
13
+ PurposeOfUse["LEGAL"] = "LEGAL";
14
+ PurposeOfUse["MARKETING"] = "MARKETING";
15
+ PurposeOfUse["DIRECTORY"] = "DIRECTORY";
16
+ PurposeOfUse["FAMILY"] = "FAMILY";
17
+ PurposeOfUse["PRESENT"] = "PRESENT";
18
+ PurposeOfUse["EMERGENCY"] = "EMERGENCY";
19
+ PurposeOfUse["DISASTER"] = "DISASTER";
20
+ PurposeOfUse["PUBLICHEALTH"] = "PUBLICHEALTH";
21
+ PurposeOfUse["ABUSE"] = "ABUSE";
22
+ PurposeOfUse["OVERSIGHT"] = "OVERSIGHT";
23
+ PurposeOfUse["JUDICIAL"] = "JUDICIAL";
24
+ PurposeOfUse["LAW"] = "LAW";
25
+ PurposeOfUse["DECEASED"] = "DECEASED";
26
+ PurposeOfUse["DONATION"] = "DONATION";
27
+ PurposeOfUse["RESEARCH"] = "RESEARCH";
28
+ PurposeOfUse["THREAT"] = "THREAT";
29
+ PurposeOfUse["GOVERNMENT"] = "GOVERNMENT";
30
+ PurposeOfUse["WORKERSCOMP"] = "WORKERSCOMP";
31
+ PurposeOfUse["COVERAGE"] = "COVERAGE";
32
+ PurposeOfUse["REQUEST"] = "REQUEST";
33
+ })(PurposeOfUse = exports.PurposeOfUse || (exports.PurposeOfUse = {}));
34
+ //# sourceMappingURL=purpose-of-use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purpose-of-use.js","sourceRoot":"","sources":["../../src/models/purpose-of-use.ts"],"names":[],"mappings":";;;AACA,IAAY,YA4BX;AA5BD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,mCAAmB,CAAA;IACnB,yCAAyB,CAAA;IACzB,qCAAqB,CAAA;IACrB,+BAAe,CAAA;IACf,+CAA+B,CAAA;IAC/B,qCAAqB,CAAA;IACrB,+BAAe,CAAA;IACf,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;IACvB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,6CAA6B,CAAA;IAC7B,+BAAe,CAAA;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,2BAAW,CAAA;IACX,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,yCAAyB,CAAA;IACzB,2CAA2B,CAAA;IAC3B,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;AACrB,CAAC,EA5BW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA4BvB"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@metriport/commonwell-sdk",
3
+ "version": "1.0.1",
4
+ "description": "> TODO: description",
5
+ "author": "Metriport Inc. <contact@metriport.com>",
6
+ "homepage": "https://metriport.com/",
7
+ "license": "MIT",
8
+ "main": "lib/index.js",
9
+ "typings": "lib/index.d.ts",
10
+ "directories": {
11
+ "lib": "lib",
12
+ "test": "__tests__"
13
+ },
14
+ "files": [
15
+ "lib"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "repository": {
21
+ "url": "https://github.com/metriport/metriport.git",
22
+ "type": "git",
23
+ "directory": "pkgs/packages/commonwell-sdk"
24
+ },
25
+ "scripts": {
26
+ "tsc": "tsc",
27
+ "test": "echo \"Error: run tests from root\" && exit 1"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/metriport/metriport/issues"
31
+ },
32
+ "dependencies": {
33
+ "jsonwebtoken": "^9.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/jsonwebtoken": "^9.0.0",
37
+ "@types/node": "^18.11.18"
38
+ },
39
+ "gitHead": "1efbd81af4541ac7cf3bca7d72ca880fdd91bf9a"
40
+ }