@chrome-stats/app-pass-sdk 1.0.2 → 1.0.4

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 CHANGED
@@ -72,15 +72,3 @@ if (data.status === 'ok') {
72
72
  console.log('User is verified:', data.email);
73
73
  }
74
74
  ```
75
-
76
- ## Permissions
77
-
78
- Ensure your `manifest.json` includes the necessary permissions:
79
-
80
- ```json
81
- {
82
- "optional_host_permissions": [
83
- "https://chrome-stats.com/"
84
- ]
85
- }
86
- ```
package/dist/index.d.mts CHANGED
@@ -3,11 +3,8 @@ interface AppPassResponse {
3
3
  * The status of the App Pass check.
4
4
  * Possible values:
5
5
  * - 'ok': App Pass is valid and active.
6
- * - 'no_perm': Host permission for chrome-stats.com is missing.
7
6
  * - 'no_apppass': User does not have an active App Pass subscription.
8
- * - 'ext_inactive': Extension is not part of App Pass or not active for this user.
9
- * - 'err': Connection error or server failure.
10
- * - 'unknown_error': Unexpected response format.
7
+ * - 'unknown_error': Connection error or server failure.
11
8
  */
12
9
  status: string;
13
10
  /**
@@ -36,5 +33,10 @@ declare function checkAppPass(): Promise<AppPassResponse>;
36
33
  * @returns Promise<AppPassResponse>
37
34
  */
38
35
  declare function activateAppPass(): Promise<AppPassResponse>;
36
+ /**
37
+ * Opens the App Pass management page.
38
+ * @returns Promise<void>
39
+ */
40
+ declare function manageAppPass(): Promise<void>;
39
41
 
40
- export { type AppPassResponse, activateAppPass, checkAppPass };
42
+ export { type AppPassResponse, activateAppPass, checkAppPass, manageAppPass };
package/dist/index.d.ts CHANGED
@@ -3,11 +3,8 @@ interface AppPassResponse {
3
3
  * The status of the App Pass check.
4
4
  * Possible values:
5
5
  * - 'ok': App Pass is valid and active.
6
- * - 'no_perm': Host permission for chrome-stats.com is missing.
7
6
  * - 'no_apppass': User does not have an active App Pass subscription.
8
- * - 'ext_inactive': Extension is not part of App Pass or not active for this user.
9
- * - 'err': Connection error or server failure.
10
- * - 'unknown_error': Unexpected response format.
7
+ * - 'unknown_error': Connection error or server failure.
11
8
  */
12
9
  status: string;
13
10
  /**
@@ -36,5 +33,10 @@ declare function checkAppPass(): Promise<AppPassResponse>;
36
33
  * @returns Promise<AppPassResponse>
37
34
  */
38
35
  declare function activateAppPass(): Promise<AppPassResponse>;
36
+ /**
37
+ * Opens the App Pass management page.
38
+ * @returns Promise<void>
39
+ */
40
+ declare function manageAppPass(): Promise<void>;
39
41
 
40
- export { type AppPassResponse, activateAppPass, checkAppPass };
42
+ export { type AppPassResponse, activateAppPass, checkAppPass, manageAppPass };
package/dist/index.js CHANGED
@@ -21,23 +21,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  activateAppPass: () => activateAppPass,
24
- checkAppPass: () => checkAppPass
24
+ checkAppPass: () => checkAppPass,
25
+ manageAppPass: () => manageAppPass
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
  var urlBase = "https://chrome-stats.com";
28
29
  async function checkStatus() {
29
- const hasPermission = await chrome.permissions.contains({
30
- origins: [`${urlBase}/`]
31
- });
32
- if (!hasPermission) {
33
- console.log("App Pass not activated - skipping status check");
34
- return { status: "no_perm", message: "Permission denied" };
35
- }
36
30
  const maxAttempts = 3;
37
31
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
38
32
  try {
39
33
  const headers = {
40
- extensionId: chrome.runtime.id,
34
+ extensionid: chrome.runtime.id,
41
35
  "Content-Type": "application/json"
42
36
  };
43
37
  const response = await fetch(`${urlBase}/api/check-app-pass`, {
@@ -46,7 +40,7 @@ async function checkStatus() {
46
40
  credentials: "include"
47
41
  // Include cookies for authentication
48
42
  });
49
- if (response.ok) {
43
+ if (response.ok || response.status < 500 && response.status >= 400) {
50
44
  const data = await response.json();
51
45
  console.log("App pass status response:", data);
52
46
  return {
@@ -70,33 +64,27 @@ async function checkStatus() {
70
64
  }
71
65
  }
72
66
  console.error("App pass status check failed after all retry attempts");
73
- return { status: "err", message: "Failed to connect to server" };
67
+ return { status: "unknown_error", message: "Failed to connect to server" };
74
68
  }
75
69
  async function checkAppPass() {
76
- const hasPermission = await chrome.permissions.contains({
77
- origins: [`${urlBase}/`]
78
- });
79
- if (!hasPermission) {
80
- return { status: "no_perm", message: "Permission denied" };
81
- }
82
70
  const res = await checkStatus();
83
71
  return res;
84
72
  }
85
73
  async function activateAppPass() {
86
- const granted = await chrome.permissions.request({
87
- origins: [`${urlBase}/`]
74
+ const res = await checkStatus();
75
+ await chrome.tabs.create({
76
+ url: `${urlBase}/apppass/add/${encodeURIComponent(chrome.runtime.id)}`
77
+ });
78
+ return res;
79
+ }
80
+ async function manageAppPass() {
81
+ await chrome.tabs.create({
82
+ url: `${urlBase}/apppass/mypass`
88
83
  });
89
- if (granted) {
90
- const res = await checkStatus();
91
- await chrome.tabs.create({
92
- url: `${urlBase}/apppass/add/${encodeURIComponent(chrome.runtime.id)}`
93
- });
94
- return res;
95
- }
96
- return { status: "no_perm", message: "Permission denied" };
97
84
  }
98
85
  // Annotate the CommonJS export names for ESM import in node:
99
86
  0 && (module.exports = {
100
87
  activateAppPass,
101
- checkAppPass
88
+ checkAppPass,
89
+ manageAppPass
102
90
  });
package/dist/index.mjs CHANGED
@@ -1,18 +1,11 @@
1
1
  // src/index.ts
2
2
  var urlBase = "https://chrome-stats.com";
3
3
  async function checkStatus() {
4
- const hasPermission = await chrome.permissions.contains({
5
- origins: [`${urlBase}/`]
6
- });
7
- if (!hasPermission) {
8
- console.log("App Pass not activated - skipping status check");
9
- return { status: "no_perm", message: "Permission denied" };
10
- }
11
4
  const maxAttempts = 3;
12
5
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
13
6
  try {
14
7
  const headers = {
15
- extensionId: chrome.runtime.id,
8
+ extensionid: chrome.runtime.id,
16
9
  "Content-Type": "application/json"
17
10
  };
18
11
  const response = await fetch(`${urlBase}/api/check-app-pass`, {
@@ -21,7 +14,7 @@ async function checkStatus() {
21
14
  credentials: "include"
22
15
  // Include cookies for authentication
23
16
  });
24
- if (response.ok) {
17
+ if (response.ok || response.status < 500 && response.status >= 400) {
25
18
  const data = await response.json();
26
19
  console.log("App pass status response:", data);
27
20
  return {
@@ -45,32 +38,26 @@ async function checkStatus() {
45
38
  }
46
39
  }
47
40
  console.error("App pass status check failed after all retry attempts");
48
- return { status: "err", message: "Failed to connect to server" };
41
+ return { status: "unknown_error", message: "Failed to connect to server" };
49
42
  }
50
43
  async function checkAppPass() {
51
- const hasPermission = await chrome.permissions.contains({
52
- origins: [`${urlBase}/`]
53
- });
54
- if (!hasPermission) {
55
- return { status: "no_perm", message: "Permission denied" };
56
- }
57
44
  const res = await checkStatus();
58
45
  return res;
59
46
  }
60
47
  async function activateAppPass() {
61
- const granted = await chrome.permissions.request({
62
- origins: [`${urlBase}/`]
48
+ const res = await checkStatus();
49
+ await chrome.tabs.create({
50
+ url: `${urlBase}/apppass/add/${encodeURIComponent(chrome.runtime.id)}`
51
+ });
52
+ return res;
53
+ }
54
+ async function manageAppPass() {
55
+ await chrome.tabs.create({
56
+ url: `${urlBase}/apppass/mypass`
63
57
  });
64
- if (granted) {
65
- const res = await checkStatus();
66
- await chrome.tabs.create({
67
- url: `${urlBase}/apppass/add/${encodeURIComponent(chrome.runtime.id)}`
68
- });
69
- return res;
70
- }
71
- return { status: "no_perm", message: "Permission denied" };
72
58
  }
73
59
  export {
74
60
  activateAppPass,
75
- checkAppPass
61
+ checkAppPass,
62
+ manageAppPass
76
63
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrome-stats/app-pass-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "SDK for Chrome Stats App Pass integration",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",