@howuse/feedback 0.1.0 → 0.2.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
@@ -54,19 +54,20 @@ function createNativeClient() {
54
54
  return JSON.parse(result);
55
55
  },
56
56
  async checkActivation(request, softwareId) {
57
- const json = JSON.stringify({ ...request, softwareId });
57
+ const json = JSON.stringify({ softwareId });
58
58
  const result = CheckActivation(json);
59
59
  return JSON.parse(result);
60
60
  }
61
61
  };
62
62
  }
63
63
  class FeedbackClient {
64
- constructor(enabled, baseUrl, softwareId, version, nativeClient) {
64
+ constructor(enabled, baseUrl, softwareId, version, nativeClient, machineCode) {
65
65
  this.enabled = enabled;
66
66
  this.baseUrl = baseUrl;
67
67
  this.softwareId = softwareId;
68
68
  this.version = version;
69
69
  this.nativeClient = nativeClient;
70
+ this.machineCode = machineCode;
70
71
  }
71
72
  /**
72
73
  * 提交反馈
@@ -93,17 +94,23 @@ class FeedbackClient {
93
94
  return this.nativeClient.activate(data, this.softwareId);
94
95
  }
95
96
  /**
96
- * 检查激活状态
97
+ * 检查激活状态(机器码在内部自动使用)
97
98
  */
98
- async check(data) {
99
+ async check() {
99
100
  if (!this.enabled) {
100
101
  return {
101
102
  expired: true,
102
103
  reason: "sdk_disabled_or_init_failed"
103
104
  };
104
105
  }
106
+ if (!this.machineCode) {
107
+ return {
108
+ expired: true,
109
+ reason: "machine_code_not_found"
110
+ };
111
+ }
105
112
  try {
106
- const result = await this.nativeClient.checkActivation(data, this.softwareId);
113
+ const result = await this.nativeClient.checkActivation({}, this.softwareId);
107
114
  if (!result.expired && !result.activated) {
108
115
  return {
109
116
  expired: true,
@@ -120,8 +127,8 @@ class FeedbackClient {
120
127
  }
121
128
  }
122
129
  async function initFeedbackClient(options) {
123
- if (!options.baseUrl || !options.softwareId || !options.version) {
124
- throw new Error("baseUrl, softwareId, and version are required");
130
+ if (!options.baseUrl || !options.softwareId || !options.version || !options.machineCodePath) {
131
+ throw new Error("baseUrl, softwareId, version, and machineCodePath are required");
125
132
  }
126
133
  const baseUrl = options.baseUrl.replace(/\/$/, "");
127
134
  const nativeClient = createNativeClient();
@@ -139,7 +146,8 @@ async function initFeedbackClient(options) {
139
146
  baseUrl,
140
147
  options.softwareId,
141
148
  options.version,
142
- nativeClient
149
+ nativeClient,
150
+ initResult.machineCode
143
151
  );
144
152
  }
145
153
  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
@@ -52,19 +52,20 @@ function createNativeClient() {
52
52
  return JSON.parse(result);
53
53
  },
54
54
  async checkActivation(request, softwareId) {
55
- const json = JSON.stringify({ ...request, softwareId });
55
+ const json = JSON.stringify({ softwareId });
56
56
  const result = CheckActivation(json);
57
57
  return JSON.parse(result);
58
58
  }
59
59
  };
60
60
  }
61
61
  class FeedbackClient {
62
- constructor(enabled, baseUrl, softwareId, version, nativeClient) {
62
+ constructor(enabled, baseUrl, softwareId, version, nativeClient, machineCode) {
63
63
  this.enabled = enabled;
64
64
  this.baseUrl = baseUrl;
65
65
  this.softwareId = softwareId;
66
66
  this.version = version;
67
67
  this.nativeClient = nativeClient;
68
+ this.machineCode = machineCode;
68
69
  }
69
70
  /**
70
71
  * 提交反馈
@@ -91,17 +92,23 @@ class FeedbackClient {
91
92
  return this.nativeClient.activate(data, this.softwareId);
92
93
  }
93
94
  /**
94
- * 检查激活状态
95
+ * 检查激活状态(机器码在内部自动使用)
95
96
  */
96
- async check(data) {
97
+ async check() {
97
98
  if (!this.enabled) {
98
99
  return {
99
100
  expired: true,
100
101
  reason: "sdk_disabled_or_init_failed"
101
102
  };
102
103
  }
104
+ if (!this.machineCode) {
105
+ return {
106
+ expired: true,
107
+ reason: "machine_code_not_found"
108
+ };
109
+ }
103
110
  try {
104
- const result = await this.nativeClient.checkActivation(data, this.softwareId);
111
+ const result = await this.nativeClient.checkActivation({}, this.softwareId);
105
112
  if (!result.expired && !result.activated) {
106
113
  return {
107
114
  expired: true,
@@ -118,8 +125,8 @@ class FeedbackClient {
118
125
  }
119
126
  }
120
127
  async function initFeedbackClient(options) {
121
- if (!options.baseUrl || !options.softwareId || !options.version) {
122
- throw new Error("baseUrl, softwareId, and version are required");
128
+ if (!options.baseUrl || !options.softwareId || !options.version || !options.machineCodePath) {
129
+ throw new Error("baseUrl, softwareId, version, and machineCodePath are required");
123
130
  }
124
131
  const baseUrl = options.baseUrl.replace(/\/$/, "");
125
132
  const nativeClient = createNativeClient();
@@ -137,7 +144,8 @@ async function initFeedbackClient(options) {
137
144
  baseUrl,
138
145
  options.softwareId,
139
146
  options.version,
140
- nativeClient
147
+ nativeClient,
148
+ initResult.machineCode
141
149
  );
142
150
  }
143
151
  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.2.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",