@tencentcloud/web-push 1.0.4 → 1.0.6

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/CHANGELOG.md CHANGED
@@ -1,8 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.6] - 2025-02-11
4
+
5
+ ### Features
6
+
7
+ - Added `showSystemPermissionAlert` parameter to control whether to display system permission alert popup
8
+
9
+ ### Changes
10
+
11
+ - Optimized `serviceWorkerPath` parameter to support same-origin full URLs
12
+
13
+ ## [1.0.5] - 2025-02-02
14
+
15
+ ### Features
16
+
17
+ - Support for webpushInfo ext pass-through fields
18
+
3
19
  ## [1.0.4] - 2025-01-27
4
20
 
5
- ### Added
21
+ ### Features
6
22
 
7
23
  - **Online Push Popup Feature**: Real-time in-app message popup display to enhance user experience
8
24
  - **Multiple Message Type Support**: Standard (standard template), HTML (custom HTML), Custom (fully customizable)
@@ -10,17 +26,21 @@
10
26
 
11
27
  ## [1.0.2] - 2025-01-16
12
28
 
13
- - ✨ Added UMD build support for direct `<script>` tag integration
14
- - 📚 Enhanced UMD usage documentation and examples
29
+ ### Features
30
+
31
+ - Added UMD build support for direct `<script>` tag integration
32
+ - Enhanced UMD usage documentation and examples
15
33
 
16
34
  ## [1.0.1] - 2025-12-19
17
35
 
18
- - Optimize subscription logic
36
+ ### Changes
37
+
38
+ - Optimized subscription logic
19
39
  - Optimized state persistence logic, only persisting VAPID public key while resetting temporary states each session
20
40
 
21
41
  ## [1.0.0] - 2025-12-17
22
42
 
23
- ### Added
43
+ ### Features
24
44
 
25
45
  - 🎉 Initial release
26
46
  - ✨ Service Worker-based push notification support
package/README.md CHANGED
@@ -125,6 +125,38 @@ In your homepage (for example: `index.js`), add `@tencentcloud/web-push` and reg
125
125
 
126
126
  <td rowspan="1" colSpan="1" >Register the userID for push services. User's Unique Identifier, defined by you, can only include uppercase and lowercase letters (a-z, A-Z), numbers (0-9), underscores, and hyphens.</td>
127
127
  </tr>
128
+
129
+ <tr>
130
+ <td rowspan="1" colSpan="1" >serviceWorkerPath</td>
131
+
132
+ <td rowspan="1" colSpan="1" >String</td>
133
+
134
+ <td rowspan="1" colSpan="1" >Optional. Custom Service Worker file path, defaults to '/sw.js'. Supports relative paths (e.g., './sw.js', '../sw.js') or same-origin full URLs (e.g., 'https://example.com/sw.js').</td>
135
+ </tr>
136
+
137
+ <tr>
138
+ <td rowspan="1" colSpan="1" >logLevel</td>
139
+
140
+ <td rowspan="1" colSpan="1" >Number</td>
141
+
142
+ <td rowspan="1" colSpan="1" >Optional. Log level: 0-Normal level, 1-Release level (default), 2-Warning level, 3-Error level, 4-No log level.</td>
143
+ </tr>
144
+
145
+ <tr>
146
+ <td rowspan="1" colSpan="1" >showSystemPermissionAlert</td>
147
+
148
+ <td rowspan="1" colSpan="1" >Boolean</td>
149
+
150
+ <td rowspan="1" colSpan="1" >Optional. Whether to show system permission alert popup, defaults to true. Set to false to disable permission setting prompt.</td>
151
+ </tr>
152
+
153
+ <tr>
154
+ <td rowspan="1" colSpan="1" >chat</td>
155
+
156
+ <td rowspan="1" colSpan="1" >Object</td>
157
+
158
+ <td rowspan="1" colSpan="1" >Optional. Initialized TencentCloudChat SDK instance, will be created automatically if not provided.</td>
159
+ </tr>
128
160
  </table>
129
161
 
130
162
  ```javascript
@@ -218,16 +250,10 @@ interface RegisterPushOptions {
218
250
  SDKAppID: number;
219
251
  appKey: string;
220
252
  userID: string;
253
+ serviceWorkerPath?: string;
221
254
  chat?: any;
222
- /**
223
- * Log level:
224
- * 0 - Normal level, more logs, recommended for integration
225
- * 1 - Release level, SDK outputs key information, recommended for production (default)
226
- * 2 - Warning level, SDK only outputs warning and error level logs
227
- * 3 - Error level, SDK only outputs error level logs
228
- * 4 - No log level, SDK will not print any logs
229
- */
230
255
  logLevel?: LogLevel;
256
+ showSystemPermissionAlert?: boolean;
231
257
  }
232
258
 
233
259
  enum EVENT {
package/index.d.ts CHANGED
@@ -152,6 +152,12 @@ export declare interface RegisterPushOptions {
152
152
  * 4 - 无日志级别,SDK 将不打印任何日志
153
153
  */
154
154
  logLevel?: LogLevel;
155
+ /**
156
+ * 是否显示系统权限提示弹窗
157
+ * true - 显示系统权限设置提示(默认)
158
+ * false - 不显示系统权限设置提示
159
+ */
160
+ showSystemPermissionAlert?: boolean;
155
161
  }
156
162
 
157
163
  export declare interface StandardMessage {
@@ -215,6 +221,7 @@ declare class WebPushSDK_2 implements WebPushSDK {
215
221
  private appKey;
216
222
  private vapidPublicKey;
217
223
  private pendingMessages;
224
+ private enableSystemPermissionAlert;
218
225
  EVENT: typeof EVENT;
219
226
  VERSION: string;
220
227
  constructor();
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import ChatSDK from "@tencentcloud/lite-chat/professional";
2
- const version = "1.0.4";
2
+ const version = "1.0.6";
3
3
  var Placement = /* @__PURE__ */ ((Placement2) => {
4
4
  Placement2[Placement2["CENTER"] = 0] = "CENTER";
5
5
  Placement2[Placement2["TOP_LEFT"] = 1] = "TOP_LEFT";
@@ -322,8 +322,37 @@ class Validator {
322
322
  this.validateValue("serviceWorkerPath", path, {
323
323
  required: false,
324
324
  type: "string",
325
- pattern: /^[a-zA-Z0-9_./-]+\.js$/,
326
- message: "serviceWorkerPath must be a valid JavaScript file path"
325
+ custom: (value) => {
326
+ if (!value || typeof value !== "string") {
327
+ return true;
328
+ }
329
+ let pathWithoutQuery = value;
330
+ if (value.includes("?")) {
331
+ pathWithoutQuery = value.split("?")[0];
332
+ }
333
+ if (!pathWithoutQuery.endsWith(".js")) {
334
+ return "serviceWorkerPath must be a JavaScript file (.js)";
335
+ }
336
+ if (value.startsWith("http://") || value.startsWith("https://")) {
337
+ try {
338
+ const url = new URL(value);
339
+ if (typeof window !== "undefined") {
340
+ const currentOrigin = window.location.origin;
341
+ if (url.origin !== currentOrigin) {
342
+ return `serviceWorkerPath URL must be same-origin. Expected: ${currentOrigin}, Got: ${url.origin}`;
343
+ }
344
+ }
345
+ return true;
346
+ } catch {
347
+ return "serviceWorkerPath must be a valid URL";
348
+ }
349
+ }
350
+ if (!/^[a-zA-Z0-9_./-]+\.js$/.test(pathWithoutQuery)) {
351
+ return "serviceWorkerPath must be a valid JavaScript file path or same-origin URL";
352
+ }
353
+ return true;
354
+ },
355
+ message: "serviceWorkerPath must be a valid JavaScript file path or same-origin URL"
327
356
  });
328
357
  }
329
358
  }
@@ -674,6 +703,10 @@ class ServiceWorkerManager {
674
703
  }
675
704
  async autoDetectServiceWorkerUrl() {
676
705
  if (typeof window !== "undefined") {
706
+ if (this.swUrl !== "/sw.js") {
707
+ logger.log("Service Worker path already manually set:", this.swUrl);
708
+ return;
709
+ }
677
710
  const currentPath = window.location.pathname;
678
711
  const basePath = currentPath.endsWith("/") ? currentPath : currentPath + "/";
679
712
  if (basePath !== "/") {
@@ -720,8 +753,8 @@ class ServiceWorkerManager {
720
753
  await this.autoDetectServiceWorkerUrl();
721
754
  const possibleUrls = [
722
755
  this.swUrl,
723
- "./sw.js",
724
756
  "/sw.js",
757
+ "./sw.js",
725
758
  "/dist/sw.js",
726
759
  "/assets/sw.js"
727
760
  ];
@@ -6305,6 +6338,7 @@ class WebPushSDK {
6305
6338
  this.appKey = "";
6306
6339
  this.vapidPublicKey = "";
6307
6340
  this.pendingMessages = [];
6341
+ this.enableSystemPermissionAlert = true;
6308
6342
  this.EVENT = EVENT;
6309
6343
  this.VERSION = version;
6310
6344
  logger.log("version:", version);
@@ -6327,10 +6361,13 @@ class WebPushSDK {
6327
6361
  async registerPush(options) {
6328
6362
  try {
6329
6363
  Validator.validateRegisterPushOptions(options);
6330
- const { SDKAppID, appKey, userID, chat, logLevel } = options;
6364
+ const { SDKAppID, appKey, userID, chat, logLevel, serviceWorkerPath, showSystemPermissionAlert } = options;
6331
6365
  if (logLevel !== void 0) {
6332
6366
  logger.setLogLevel(logLevel);
6333
6367
  }
6368
+ if (showSystemPermissionAlert !== void 0) {
6369
+ this.enableSystemPermissionAlert = showSystemPermissionAlert;
6370
+ }
6334
6371
  if (this.isRegistered) {
6335
6372
  logger.warn(
6336
6373
  "Push service already registered, will unregister first and then re-register"
@@ -6373,6 +6410,9 @@ class WebPushSDK {
6373
6410
  }
6374
6411
  }
6375
6412
  this.addChatListener();
6413
+ if (serviceWorkerPath) {
6414
+ this.serviceWorkerManager.setServiceWorkerUrl(serviceWorkerPath);
6415
+ }
6376
6416
  await this.serviceWorkerManager.register();
6377
6417
  if (logLevel !== void 0) {
6378
6418
  await this.sendLogLevelToServiceWorker(logLevel);
@@ -6510,7 +6550,9 @@ class WebPushSDK {
6510
6550
  `User denied notification permission for ${browserName}`
6511
6551
  );
6512
6552
  } else {
6513
- this.showSystemPermissionAlert(browserName);
6553
+ if (this.enableSystemPermissionAlert) {
6554
+ this.showSystemPermissionAlert(browserName);
6555
+ }
6514
6556
  }
6515
6557
  return permission;
6516
6558
  } catch (error) {
@@ -6798,6 +6840,7 @@ Please refresh the page after enabling notifications.`;
6798
6840
  this.appKey = "";
6799
6841
  this.vapidPublicKey = "";
6800
6842
  this.pendingMessages = [];
6843
+ this.enableSystemPermissionAlert = true;
6801
6844
  if (this.messagePopup) {
6802
6845
  this.messagePopup.destroy();
6803
6846
  this.messagePopup = null;