@ziqx/auth 0.0.2 → 0.0.3

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/index.d.mts CHANGED
@@ -44,4 +44,39 @@ declare class ZAuthClient {
44
44
  login(isDev?: boolean): void;
45
45
  }
46
46
 
47
- export { ZAuthClient };
47
+ /**
48
+ * ZAuthTokenService - A simple token validation service for ZIQX Auth.
49
+ *
50
+ * This class provides a method to validate authentication tokens issued by ZIQX.
51
+ *
52
+ * Example:
53
+ * ```ts
54
+ * import { ZAuthTokenService } from "@ziqx/auth";
55
+ *
56
+ * const tokenService = new ZAuthTokenService();
57
+ * const isValid = await tokenService.validate("your-jwt-token");
58
+ *
59
+ * if (isValid) {
60
+ * console.log("Token is valid");
61
+ * } else {
62
+ * console.log("Invalid or expired token");
63
+ * }
64
+ * ```
65
+ */
66
+ declare class ZAuthTokenService {
67
+ /**
68
+ * Validates a given authentication token with the ZIQX Auth API.
69
+ *
70
+ * @param token - The authentication token (JWT or similar) to validate.
71
+ * @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const tokenService = new ZAuthTokenService();
76
+ * const isValid = await tokenService.validate("your-jwt-token");
77
+ * ```
78
+ */
79
+ validate(token: string): Promise<boolean>;
80
+ }
81
+
82
+ export { ZAuthClient, ZAuthTokenService };
package/dist/index.d.ts CHANGED
@@ -44,4 +44,39 @@ declare class ZAuthClient {
44
44
  login(isDev?: boolean): void;
45
45
  }
46
46
 
47
- export { ZAuthClient };
47
+ /**
48
+ * ZAuthTokenService - A simple token validation service for ZIQX Auth.
49
+ *
50
+ * This class provides a method to validate authentication tokens issued by ZIQX.
51
+ *
52
+ * Example:
53
+ * ```ts
54
+ * import { ZAuthTokenService } from "@ziqx/auth";
55
+ *
56
+ * const tokenService = new ZAuthTokenService();
57
+ * const isValid = await tokenService.validate("your-jwt-token");
58
+ *
59
+ * if (isValid) {
60
+ * console.log("Token is valid");
61
+ * } else {
62
+ * console.log("Invalid or expired token");
63
+ * }
64
+ * ```
65
+ */
66
+ declare class ZAuthTokenService {
67
+ /**
68
+ * Validates a given authentication token with the ZIQX Auth API.
69
+ *
70
+ * @param token - The authentication token (JWT or similar) to validate.
71
+ * @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const tokenService = new ZAuthTokenService();
76
+ * const isValid = await tokenService.validate("your-jwt-token");
77
+ * ```
78
+ */
79
+ validate(token: string): Promise<boolean>;
80
+ }
81
+
82
+ export { ZAuthClient, ZAuthTokenService };
package/dist/index.js CHANGED
@@ -20,12 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- ZAuthClient: () => ZAuthClient
23
+ ZAuthClient: () => ZAuthClient,
24
+ ZAuthTokenService: () => ZAuthTokenService
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
27
 
27
28
  // src/constants.ts
28
29
  var ZAUTH_BASE_URL = "https://ziqx.cc/zauth";
30
+ var VALIDATION_URL = "https://ziqx.cc/api/auth/validate-token";
29
31
 
30
32
  // src/ZAuthClient.ts
31
33
  var ZAuthClient = class {
@@ -60,7 +62,44 @@ var ZAuthClient = class {
60
62
  window.location.href = loginUrl;
61
63
  }
62
64
  };
65
+
66
+ // src/ZAuthTokenService.ts
67
+ var ZAuthTokenService = class {
68
+ /**
69
+ * Validates a given authentication token with the ZIQX Auth API.
70
+ *
71
+ * @param token - The authentication token (JWT or similar) to validate.
72
+ * @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const tokenService = new ZAuthTokenService();
77
+ * const isValid = await tokenService.validate("your-jwt-token");
78
+ * ```
79
+ */
80
+ async validate(token) {
81
+ if (!token) {
82
+ throw new Error("ZAuthTokenService: token is required for validation.");
83
+ }
84
+ try {
85
+ const response = await fetch(VALIDATION_URL, {
86
+ method: "GET",
87
+ headers: {
88
+ Authorization: token
89
+ }
90
+ });
91
+ if (response.status !== 200)
92
+ return false;
93
+ const data = await response.json();
94
+ return data.success === true;
95
+ } catch (error) {
96
+ console.error("ZAuthTokenService: Validation failed:", error);
97
+ return false;
98
+ }
99
+ }
100
+ };
63
101
  // Annotate the CommonJS export names for ESM import in node:
64
102
  0 && (module.exports = {
65
- ZAuthClient
103
+ ZAuthClient,
104
+ ZAuthTokenService
66
105
  });
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/constants.ts
2
2
  var ZAUTH_BASE_URL = "https://ziqx.cc/zauth";
3
+ var VALIDATION_URL = "https://ziqx.cc/api/auth/validate-token";
3
4
 
4
5
  // src/ZAuthClient.ts
5
6
  var ZAuthClient = class {
@@ -34,6 +35,43 @@ var ZAuthClient = class {
34
35
  window.location.href = loginUrl;
35
36
  }
36
37
  };
38
+
39
+ // src/ZAuthTokenService.ts
40
+ var ZAuthTokenService = class {
41
+ /**
42
+ * Validates a given authentication token with the ZIQX Auth API.
43
+ *
44
+ * @param token - The authentication token (JWT or similar) to validate.
45
+ * @returns A Promise that resolves to `true` if the token is valid, otherwise `false`.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const tokenService = new ZAuthTokenService();
50
+ * const isValid = await tokenService.validate("your-jwt-token");
51
+ * ```
52
+ */
53
+ async validate(token) {
54
+ if (!token) {
55
+ throw new Error("ZAuthTokenService: token is required for validation.");
56
+ }
57
+ try {
58
+ const response = await fetch(VALIDATION_URL, {
59
+ method: "GET",
60
+ headers: {
61
+ Authorization: token
62
+ }
63
+ });
64
+ if (response.status !== 200)
65
+ return false;
66
+ const data = await response.json();
67
+ return data.success === true;
68
+ } catch (error) {
69
+ console.error("ZAuthTokenService: Validation failed:", error);
70
+ return false;
71
+ }
72
+ }
73
+ };
37
74
  export {
38
- ZAuthClient
75
+ ZAuthClient,
76
+ ZAuthTokenService
39
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziqx/auth",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "SDK for Ziqx Authentication",
5
5
  "main": "./dist/index.ts",
6
6
  "module": "./dist/index.mjs",