@howuse/feedback 0.1.0 → 0.3.0

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.cjs CHANGED
@@ -21,9 +21,18 @@ function tryLoadNativeLibrary() {
21
21
  } else {
22
22
  throw new Error(`Unsupported platform: ${platform}`);
23
23
  }
24
- const libPath = path.join(packageRoot, "native", libName);
24
+ let libPath = path.join(packageRoot, "native", libName);
25
25
  if (!fs.existsSync(libPath)) {
26
- throw new Error(`Native library not found: ${libPath}. Please run 'npm run build:native' first.`);
26
+ if (libPath.includes(".asar")) {
27
+ const asarPath = libPath.replace(".asar", ".asar.unpacked");
28
+ if (fs.existsSync(asarPath)) {
29
+ libPath = asarPath;
30
+ } else {
31
+ throw new Error(`Native library asarPath not found: ${asarPath}. Please run 'npm run build:native' first.`);
32
+ }
33
+ } else {
34
+ throw new Error(`Native library not found: ${libPath}. Please run 'npm run build:native' first.`);
35
+ }
27
36
  }
28
37
  try {
29
38
  return koffi.load(libPath);
@@ -54,19 +63,20 @@ function createNativeClient() {
54
63
  return JSON.parse(result);
55
64
  },
56
65
  async checkActivation(request, softwareId) {
57
- const json = JSON.stringify({ ...request, softwareId });
66
+ const json = JSON.stringify({ softwareId });
58
67
  const result = CheckActivation(json);
59
68
  return JSON.parse(result);
60
69
  }
61
70
  };
62
71
  }
63
72
  class FeedbackClient {
64
- constructor(enabled, baseUrl, softwareId, version, nativeClient) {
73
+ constructor(enabled, baseUrl, softwareId, version, nativeClient, machineCode) {
65
74
  this.enabled = enabled;
66
75
  this.baseUrl = baseUrl;
67
76
  this.softwareId = softwareId;
68
77
  this.version = version;
69
78
  this.nativeClient = nativeClient;
79
+ this.machineCode = machineCode;
70
80
  }
71
81
  /**
72
82
  * 提交反馈
@@ -93,17 +103,23 @@ class FeedbackClient {
93
103
  return this.nativeClient.activate(data, this.softwareId);
94
104
  }
95
105
  /**
96
- * 检查激活状态
106
+ * 检查激活状态(机器码在内部自动使用)
97
107
  */
98
- async check(data) {
108
+ async check() {
99
109
  if (!this.enabled) {
100
110
  return {
101
111
  expired: true,
102
112
  reason: "sdk_disabled_or_init_failed"
103
113
  };
104
114
  }
115
+ if (!this.machineCode) {
116
+ return {
117
+ expired: true,
118
+ reason: "machine_code_not_found"
119
+ };
120
+ }
105
121
  try {
106
- const result = await this.nativeClient.checkActivation(data, this.softwareId);
122
+ const result = await this.nativeClient.checkActivation({}, this.softwareId);
107
123
  if (!result.expired && !result.activated) {
108
124
  return {
109
125
  expired: true,
@@ -120,8 +136,8 @@ class FeedbackClient {
120
136
  }
121
137
  }
122
138
  async function initFeedbackClient(options) {
123
- if (!options.baseUrl || !options.softwareId || !options.version) {
124
- throw new Error("baseUrl, softwareId, and version are required");
139
+ if (!options.baseUrl || !options.softwareId || !options.version || !options.machineCodePath) {
140
+ throw new Error("baseUrl, softwareId, version, and machineCodePath are required");
125
141
  }
126
142
  const baseUrl = options.baseUrl.replace(/\/$/, "");
127
143
  const nativeClient = createNativeClient();
@@ -139,7 +155,8 @@ async function initFeedbackClient(options) {
139
155
  baseUrl,
140
156
  options.softwareId,
141
157
  options.version,
142
- nativeClient
158
+ nativeClient,
159
+ initResult.machineCode
143
160
  );
144
161
  }
145
162
  exports.FeedbackClient = FeedbackClient;
package/dist/index.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import { type NativeClient } from './native';
2
- import type { InitOptions, FeedbackPayload, FeedbackResult, ActivationRequest, ActivationResult, ActivationCheckRequest, ActivationCheckResponse } from './types';
2
+ import type { InitOptions, FeedbackPayload, FeedbackResult, ActivationRequest, ActivationResult, ActivationCheckResponse } from './types';
3
3
  /**
4
4
  * FeedbackClient 类
5
5
  */
6
6
  export declare class FeedbackClient {
7
7
  readonly enabled: boolean;
8
+ readonly machineCode?: string;
8
9
  private readonly baseUrl;
9
10
  private readonly softwareId;
10
11
  private readonly version;
11
12
  private readonly nativeClient;
12
- constructor(enabled: boolean, baseUrl: string, softwareId: number, version: string, nativeClient: NativeClient);
13
+ constructor(enabled: boolean, baseUrl: string, softwareId: number, version: string, nativeClient: NativeClient, machineCode?: string);
13
14
  /**
14
15
  * 提交反馈
15
16
  */
@@ -19,9 +20,9 @@ export declare class FeedbackClient {
19
20
  */
20
21
  activate(data: ActivationRequest): Promise<ActivationResult>;
21
22
  /**
22
- * 检查激活状态
23
+ * 检查激活状态(机器码在内部自动使用)
23
24
  */
24
- check(data: ActivationCheckRequest): Promise<ActivationCheckResponse>;
25
+ check(): Promise<ActivationCheckResponse>;
25
26
  }
26
27
  /**
27
28
  * 初始化 Feedback 客户端
package/dist/index.mjs CHANGED
@@ -19,9 +19,18 @@ function tryLoadNativeLibrary() {
19
19
  } else {
20
20
  throw new Error(`Unsupported platform: ${platform}`);
21
21
  }
22
- const libPath = path.join(packageRoot, "native", libName);
22
+ let libPath = path.join(packageRoot, "native", libName);
23
23
  if (!fs.existsSync(libPath)) {
24
- throw new Error(`Native library not found: ${libPath}. Please run 'npm run build:native' first.`);
24
+ if (libPath.includes(".asar")) {
25
+ const asarPath = libPath.replace(".asar", ".asar.unpacked");
26
+ if (fs.existsSync(asarPath)) {
27
+ libPath = asarPath;
28
+ } else {
29
+ throw new Error(`Native library asarPath not found: ${asarPath}. Please run 'npm run build:native' first.`);
30
+ }
31
+ } else {
32
+ throw new Error(`Native library not found: ${libPath}. Please run 'npm run build:native' first.`);
33
+ }
25
34
  }
26
35
  try {
27
36
  return koffi.load(libPath);
@@ -52,19 +61,20 @@ function createNativeClient() {
52
61
  return JSON.parse(result);
53
62
  },
54
63
  async checkActivation(request, softwareId) {
55
- const json = JSON.stringify({ ...request, softwareId });
64
+ const json = JSON.stringify({ softwareId });
56
65
  const result = CheckActivation(json);
57
66
  return JSON.parse(result);
58
67
  }
59
68
  };
60
69
  }
61
70
  class FeedbackClient {
62
- constructor(enabled, baseUrl, softwareId, version, nativeClient) {
71
+ constructor(enabled, baseUrl, softwareId, version, nativeClient, machineCode) {
63
72
  this.enabled = enabled;
64
73
  this.baseUrl = baseUrl;
65
74
  this.softwareId = softwareId;
66
75
  this.version = version;
67
76
  this.nativeClient = nativeClient;
77
+ this.machineCode = machineCode;
68
78
  }
69
79
  /**
70
80
  * 提交反馈
@@ -91,17 +101,23 @@ class FeedbackClient {
91
101
  return this.nativeClient.activate(data, this.softwareId);
92
102
  }
93
103
  /**
94
- * 检查激活状态
104
+ * 检查激活状态(机器码在内部自动使用)
95
105
  */
96
- async check(data) {
106
+ async check() {
97
107
  if (!this.enabled) {
98
108
  return {
99
109
  expired: true,
100
110
  reason: "sdk_disabled_or_init_failed"
101
111
  };
102
112
  }
113
+ if (!this.machineCode) {
114
+ return {
115
+ expired: true,
116
+ reason: "machine_code_not_found"
117
+ };
118
+ }
103
119
  try {
104
- const result = await this.nativeClient.checkActivation(data, this.softwareId);
120
+ const result = await this.nativeClient.checkActivation({}, this.softwareId);
105
121
  if (!result.expired && !result.activated) {
106
122
  return {
107
123
  expired: true,
@@ -118,8 +134,8 @@ class FeedbackClient {
118
134
  }
119
135
  }
120
136
  async function initFeedbackClient(options) {
121
- if (!options.baseUrl || !options.softwareId || !options.version) {
122
- throw new Error("baseUrl, softwareId, and version are required");
137
+ if (!options.baseUrl || !options.softwareId || !options.version || !options.machineCodePath) {
138
+ throw new Error("baseUrl, softwareId, version, and machineCodePath are required");
123
139
  }
124
140
  const baseUrl = options.baseUrl.replace(/\/$/, "");
125
141
  const nativeClient = createNativeClient();
@@ -137,7 +153,8 @@ async function initFeedbackClient(options) {
137
153
  baseUrl,
138
154
  options.softwareId,
139
155
  options.version,
140
- nativeClient
156
+ nativeClient,
157
+ initResult.machineCode
141
158
  );
142
159
  }
143
160
  export {
package/dist/types.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface InitOptions {
8
8
  softwareId: number;
9
9
  /** 软件版本号 */
10
10
  version: string;
11
+ /** 机器码存放目录路径 */
12
+ machineCodePath: string;
11
13
  /** 请求超时时间(毫秒),可选 */
12
14
  timeoutMs?: number;
13
15
  }
@@ -17,6 +19,8 @@ export interface InitOptions {
17
19
  export interface InitResult {
18
20
  /** 是否启用 */
19
21
  enabled: boolean;
22
+ /** 生成的机器码 */
23
+ machineCode?: string;
20
24
  /** 错误信息(如果初始化失败) */
21
25
  error?: string;
22
26
  }
@@ -70,8 +74,6 @@ export interface FeedbackResult {
70
74
  * 激活请求
71
75
  */
72
76
  export interface ActivationRequest {
73
- /** 机器码 */
74
- machineCode: string;
75
77
  /** 激活码 */
76
78
  code: string;
77
79
  }
@@ -84,11 +86,9 @@ export interface ActivationResult {
84
86
  error?: string;
85
87
  }
86
88
  /**
87
- * 激活检查请求
89
+ * 激活检查请求(无需参数,机器码在内部自动使用)
88
90
  */
89
91
  export interface ActivationCheckRequest {
90
- /** 机器码 */
91
- machineCode: string;
92
92
  }
93
93
  /**
94
94
  * 激活检查响应
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howuse/feedback",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Node.js/Electron SDK for user feedback and activation management",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",