@healthcloudai/hc-login-connector 0.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/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Healthcheck Login API Connector
2
+
3
+ This library provides convenient access to the Healthcheck REST API from TypeScript or JavaScript.
4
+
5
+ ## Features:
6
+
7
+ 1. Patient Login to Healthcheck Tenant
8
+ 2. Patient Password Reset
9
+ 3. Patient Token Refresh
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install @healthcheck/hc-login-connector @healthcheck/hc-http
15
+
16
+
17
+ ```
18
+
19
+ ## Import
20
+
21
+ ```sh
22
+ import { HCLoginClient } from "@healthcheck/hc-login-connector";
23
+ import { FetchClient } from "@healthcheck/hc-http";
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Configuration:
29
+
30
+ ```ts
31
+
32
+ const httpClient = new FetchClient();
33
+ const client = new HCLoginClient(httpClient);
34
+
35
+ client.configure("tenant-id", "dev");
36
+
37
+ await client.login("john.doe@test.com", "password");
38
+ await client.refreshToken();
39
+
40
+
41
+ ```
42
+
43
+ Login:
44
+
45
+ ```ts
46
+
47
+ await client.login("john.doe@test.com", "password");
48
+
49
+ ```
50
+
51
+ Reset Password:
52
+
53
+ ```ts
54
+
55
+ await client.resetPassword();
56
+
57
+ ```
58
+
59
+ Refresh Token:
60
+
61
+ ```ts
62
+
63
+ await client.refreshToken();
64
+
65
+ ```
66
+
67
+
package/dist/index.cjs ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AuthError: () => AuthError,
24
+ ConfigError: () => ConfigError,
25
+ HCLoginClient: () => HCLoginClient,
26
+ HttpError: () => HttpError
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/errors.ts
31
+ var ConfigError = class extends Error {
32
+ constructor(message) {
33
+ super(message);
34
+ this.name = "ConfigError";
35
+ }
36
+ };
37
+ var AuthError = class extends Error {
38
+ constructor(message) {
39
+ super(message);
40
+ this.name = "AuthError";
41
+ }
42
+ };
43
+ var HttpError = class extends Error {
44
+ constructor(status, message) {
45
+ super(message);
46
+ this.name = "HttpError";
47
+ this.status = status;
48
+ }
49
+ };
50
+
51
+ // src/client.ts
52
+ var ENV_PREFIX = {
53
+ dev: "dev-api-safe",
54
+ uat: "uat-api-safe",
55
+ prod: "api-safe"
56
+ };
57
+ function buildBaseUrl(tenantID, environment) {
58
+ return `https://${ENV_PREFIX[environment]}-${tenantID}.healthcloud-services.com`;
59
+ }
60
+ var HCLoginClient = class {
61
+ constructor(httpClient) {
62
+ this.http = httpClient;
63
+ }
64
+ configure(tenantID, environment) {
65
+ if (!tenantID) throw new ConfigError("tenantID is required");
66
+ this.config = {
67
+ tenantID,
68
+ environment,
69
+ baseUrl: buildBaseUrl(tenantID, environment)
70
+ };
71
+ }
72
+ async login(email, password) {
73
+ var _a;
74
+ this.ensureConfigured();
75
+ const resp = await this.http.post(
76
+ `${this.config.baseUrl}/login`,
77
+ { email, password },
78
+ { "X-Tenant-ID": this.config.tenantID }
79
+ );
80
+ const data = (_a = resp.Data) != null ? _a : resp;
81
+ const tokens = {
82
+ accessToken: data.AccessToken,
83
+ refreshToken: data.RefreshToken,
84
+ idToken: data.IDToken,
85
+ expiresIn: new Date(data.Expiration).getTime()
86
+ };
87
+ this.tokens = tokens;
88
+ return tokens;
89
+ }
90
+ // async refreshToken(): Promise<AuthTokens> {
91
+ // this.ensureConfigured();
92
+ // if (!this.tokens?.refreshToken) {
93
+ // throw new AuthError("No refresh token available");
94
+ // }
95
+ // const tokens = await this.http.post<AuthTokens>(
96
+ // `${this.config!.baseUrl}/refresh`,
97
+ // {
98
+ // refreshToken: this.tokens.refreshToken,
99
+ // tenantID: this.config!.tenantID,
100
+ // type: 0
101
+ // },
102
+ // { "X-Tenant-ID": this.config!.tenantID }
103
+ // );
104
+ // this.tokens = tokens;
105
+ // return tokens;
106
+ // }
107
+ async resetPassword(email) {
108
+ this.ensureConfigured();
109
+ await this.http.post(
110
+ `${this.config.baseUrl}/reset/password`,
111
+ { email, tenantID: this.config.tenantID },
112
+ { "X-Tenant-ID": this.config.tenantID }
113
+ );
114
+ }
115
+ getAccessToken() {
116
+ var _a;
117
+ return (_a = this.tokens) == null ? void 0 : _a.accessToken;
118
+ }
119
+ getIDToken() {
120
+ var _a;
121
+ return (_a = this.tokens) == null ? void 0 : _a.idToken;
122
+ }
123
+ async getUserInfo() {
124
+ var _a;
125
+ this.ensureConfigured();
126
+ if (!((_a = this.tokens) == null ? void 0 : _a.idToken)) {
127
+ throw new AuthError("No ID token available");
128
+ }
129
+ return this.http.get(
130
+ `${this.config.baseUrl}/user/info`,
131
+ {
132
+ "Authorization": `Bearer ${this.tokens.idToken}`,
133
+ "X-Tenant-ID": this.config.tenantID
134
+ }
135
+ );
136
+ }
137
+ ensureConfigured() {
138
+ if (!this.config) {
139
+ throw new ConfigError("HCLogin is not configured. Call configure() first.");
140
+ }
141
+ }
142
+ getAuthHeader() {
143
+ var _a;
144
+ if (!((_a = this.tokens) == null ? void 0 : _a.idToken)) {
145
+ throw new AuthError("No ID token available");
146
+ }
147
+ return {
148
+ Authorization: `Bearer ${this.tokens.idToken}`,
149
+ "X-Tenant-ID": this.config.tenantID
150
+ };
151
+ }
152
+ getBaseUrl() {
153
+ if (!this.config) {
154
+ throw new ConfigError("Not configured");
155
+ }
156
+ return this.config.baseUrl;
157
+ }
158
+ };
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ AuthError,
162
+ ConfigError,
163
+ HCLoginClient,
164
+ HttpError
165
+ });
@@ -0,0 +1,55 @@
1
+ import { HttpClient } from '@healthcloudai/hc-http';
2
+
3
+ type Environment = "dev" | "uat" | "prod";
4
+ interface HCLoginConfig {
5
+ tenantID: string;
6
+ environment: Environment;
7
+ baseUrl: string;
8
+ }
9
+ interface AuthTokens {
10
+ accessToken: string;
11
+ refreshToken: string;
12
+ idToken: string;
13
+ expiresIn: number;
14
+ }
15
+ interface HCUserInfo {
16
+ ID?: string;
17
+ Email?: string;
18
+ TenantID?: string;
19
+ HasInsurance?: boolean;
20
+ HasIDCard?: boolean;
21
+ HasSelfie?: boolean;
22
+ Attributes?: Record<string, any>;
23
+ }
24
+
25
+ declare class HCLoginClient {
26
+ private config?;
27
+ private http;
28
+ private tokens?;
29
+ constructor(httpClient: HttpClient);
30
+ configure(tenantID: string, environment: Environment): void;
31
+ login(email: string, password: string): Promise<AuthTokens>;
32
+ resetPassword(email: string): Promise<void>;
33
+ getAccessToken(): string | undefined;
34
+ getIDToken(): string | undefined;
35
+ getUserInfo(): Promise<unknown>;
36
+ private ensureConfigured;
37
+ getAuthHeader(): {
38
+ Authorization: string;
39
+ "X-Tenant-ID": string;
40
+ };
41
+ getBaseUrl(): string;
42
+ }
43
+
44
+ declare class ConfigError extends Error {
45
+ constructor(message: string);
46
+ }
47
+ declare class AuthError extends Error {
48
+ constructor(message: string);
49
+ }
50
+ declare class HttpError extends Error {
51
+ status: number;
52
+ constructor(status: number, message: string);
53
+ }
54
+
55
+ export { AuthError, type AuthTokens, ConfigError, type Environment, HCLoginClient, type HCLoginConfig, type HCUserInfo, HttpError };
@@ -0,0 +1,55 @@
1
+ import { HttpClient } from '@healthcloudai/hc-http';
2
+
3
+ type Environment = "dev" | "uat" | "prod";
4
+ interface HCLoginConfig {
5
+ tenantID: string;
6
+ environment: Environment;
7
+ baseUrl: string;
8
+ }
9
+ interface AuthTokens {
10
+ accessToken: string;
11
+ refreshToken: string;
12
+ idToken: string;
13
+ expiresIn: number;
14
+ }
15
+ interface HCUserInfo {
16
+ ID?: string;
17
+ Email?: string;
18
+ TenantID?: string;
19
+ HasInsurance?: boolean;
20
+ HasIDCard?: boolean;
21
+ HasSelfie?: boolean;
22
+ Attributes?: Record<string, any>;
23
+ }
24
+
25
+ declare class HCLoginClient {
26
+ private config?;
27
+ private http;
28
+ private tokens?;
29
+ constructor(httpClient: HttpClient);
30
+ configure(tenantID: string, environment: Environment): void;
31
+ login(email: string, password: string): Promise<AuthTokens>;
32
+ resetPassword(email: string): Promise<void>;
33
+ getAccessToken(): string | undefined;
34
+ getIDToken(): string | undefined;
35
+ getUserInfo(): Promise<unknown>;
36
+ private ensureConfigured;
37
+ getAuthHeader(): {
38
+ Authorization: string;
39
+ "X-Tenant-ID": string;
40
+ };
41
+ getBaseUrl(): string;
42
+ }
43
+
44
+ declare class ConfigError extends Error {
45
+ constructor(message: string);
46
+ }
47
+ declare class AuthError extends Error {
48
+ constructor(message: string);
49
+ }
50
+ declare class HttpError extends Error {
51
+ status: number;
52
+ constructor(status: number, message: string);
53
+ }
54
+
55
+ export { AuthError, type AuthTokens, ConfigError, type Environment, HCLoginClient, type HCLoginConfig, type HCUserInfo, HttpError };
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ // src/errors.ts
2
+ var ConfigError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "ConfigError";
6
+ }
7
+ };
8
+ var AuthError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "AuthError";
12
+ }
13
+ };
14
+ var HttpError = class extends Error {
15
+ constructor(status, message) {
16
+ super(message);
17
+ this.name = "HttpError";
18
+ this.status = status;
19
+ }
20
+ };
21
+
22
+ // src/client.ts
23
+ var ENV_PREFIX = {
24
+ dev: "dev-api-safe",
25
+ uat: "uat-api-safe",
26
+ prod: "api-safe"
27
+ };
28
+ function buildBaseUrl(tenantID, environment) {
29
+ return `https://${ENV_PREFIX[environment]}-${tenantID}.healthcloud-services.com`;
30
+ }
31
+ var HCLoginClient = class {
32
+ constructor(httpClient) {
33
+ this.http = httpClient;
34
+ }
35
+ configure(tenantID, environment) {
36
+ if (!tenantID) throw new ConfigError("tenantID is required");
37
+ this.config = {
38
+ tenantID,
39
+ environment,
40
+ baseUrl: buildBaseUrl(tenantID, environment)
41
+ };
42
+ }
43
+ async login(email, password) {
44
+ var _a;
45
+ this.ensureConfigured();
46
+ const resp = await this.http.post(
47
+ `${this.config.baseUrl}/login`,
48
+ { email, password },
49
+ { "X-Tenant-ID": this.config.tenantID }
50
+ );
51
+ const data = (_a = resp.Data) != null ? _a : resp;
52
+ const tokens = {
53
+ accessToken: data.AccessToken,
54
+ refreshToken: data.RefreshToken,
55
+ idToken: data.IDToken,
56
+ expiresIn: new Date(data.Expiration).getTime()
57
+ };
58
+ this.tokens = tokens;
59
+ return tokens;
60
+ }
61
+ // async refreshToken(): Promise<AuthTokens> {
62
+ // this.ensureConfigured();
63
+ // if (!this.tokens?.refreshToken) {
64
+ // throw new AuthError("No refresh token available");
65
+ // }
66
+ // const tokens = await this.http.post<AuthTokens>(
67
+ // `${this.config!.baseUrl}/refresh`,
68
+ // {
69
+ // refreshToken: this.tokens.refreshToken,
70
+ // tenantID: this.config!.tenantID,
71
+ // type: 0
72
+ // },
73
+ // { "X-Tenant-ID": this.config!.tenantID }
74
+ // );
75
+ // this.tokens = tokens;
76
+ // return tokens;
77
+ // }
78
+ async resetPassword(email) {
79
+ this.ensureConfigured();
80
+ await this.http.post(
81
+ `${this.config.baseUrl}/reset/password`,
82
+ { email, tenantID: this.config.tenantID },
83
+ { "X-Tenant-ID": this.config.tenantID }
84
+ );
85
+ }
86
+ getAccessToken() {
87
+ var _a;
88
+ return (_a = this.tokens) == null ? void 0 : _a.accessToken;
89
+ }
90
+ getIDToken() {
91
+ var _a;
92
+ return (_a = this.tokens) == null ? void 0 : _a.idToken;
93
+ }
94
+ async getUserInfo() {
95
+ var _a;
96
+ this.ensureConfigured();
97
+ if (!((_a = this.tokens) == null ? void 0 : _a.idToken)) {
98
+ throw new AuthError("No ID token available");
99
+ }
100
+ return this.http.get(
101
+ `${this.config.baseUrl}/user/info`,
102
+ {
103
+ "Authorization": `Bearer ${this.tokens.idToken}`,
104
+ "X-Tenant-ID": this.config.tenantID
105
+ }
106
+ );
107
+ }
108
+ ensureConfigured() {
109
+ if (!this.config) {
110
+ throw new ConfigError("HCLogin is not configured. Call configure() first.");
111
+ }
112
+ }
113
+ getAuthHeader() {
114
+ var _a;
115
+ if (!((_a = this.tokens) == null ? void 0 : _a.idToken)) {
116
+ throw new AuthError("No ID token available");
117
+ }
118
+ return {
119
+ Authorization: `Bearer ${this.tokens.idToken}`,
120
+ "X-Tenant-ID": this.config.tenantID
121
+ };
122
+ }
123
+ getBaseUrl() {
124
+ if (!this.config) {
125
+ throw new ConfigError("Not configured");
126
+ }
127
+ return this.config.baseUrl;
128
+ }
129
+ };
130
+ export {
131
+ AuthError,
132
+ ConfigError,
133
+ HCLoginClient,
134
+ HttpError
135
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@healthcloudai/hc-login-connector",
3
+ "version": "0.0.1",
4
+ "description": "Healthcheck Login authentication SDK with TypeScrip and token refresh",
5
+ "author": "Healthcheck Systems Inc",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "health-cloud",
9
+ "authentication",
10
+ "login",
11
+ "react-native",
12
+ "typescript",
13
+ "sdk",
14
+ "auth",
15
+ "fetch",
16
+ "axios"
17
+ ],
18
+ "type": "module",
19
+ "main": "dist/index.cjs.js",
20
+ "module": "dist/index.esm.js",
21
+ "types": "dist/index.d.ts",
22
+ "react-native": "dist/index.esm.js",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.esm.js",
27
+ "require": "./dist/index.cjs.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
35
+ "dev": "tsup src/index.ts --watch",
36
+ "lint": "eslint src --ext .ts",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "dependencies": {
40
+ "@healthcloudai/hc-http": "^0.0.1",
41
+ "axios": "^1.13.4"
42
+ },
43
+ "peerDependencies": {
44
+ "react-native": ">=0.70.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "react-native": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^20.19.30",
53
+ "eslint": "^8.56.0",
54
+ "tsup": "^8.0.0",
55
+ "typescript": "^5.3.0"
56
+ },
57
+ "engines": {
58
+ "node": ">=18"
59
+ }
60
+ }