@tencentcloud/web-push 1.0.1 → 1.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/README.md +149 -136
- package/dist/index.d.ts +259 -0
- package/dist/index.esm.js +6857 -0
- package/dist/index.umd.js +1 -0
- package/dist/src/components/message-popup.d.ts +63 -0
- package/{src → dist/src}/core/web-push-sdk.d.ts +23 -1
- package/{src → dist/src}/index.d.ts +1 -0
- package/{src → dist/src}/types/inner.d.ts +2 -10
- package/dist/src/types/outer.d.ts +120 -0
- package/{src → dist/src}/utils/logger.d.ts +6 -0
- package/{src → dist/src}/utils/validator.d.ts +0 -13
- package/dist/sw.js +1 -0
- package/package.json +47 -9
- package/src/__tests__/index.test.ts +120 -0
- package/src/__tests__/integration.test.ts +285 -0
- package/src/__tests__/setup.ts +210 -0
- package/src/__tests__/types.test.ts +303 -0
- package/src/__tests__/web-push-sdk.test.ts +257 -0
- package/src/components/message-popup.ts +1007 -0
- package/src/core/event-emitter.ts +61 -0
- package/src/core/service-worker-manager.ts +614 -0
- package/src/core/web-push-sdk.ts +690 -0
- package/src/debug/GenerateTestUserSig.js +37 -0
- package/src/debug/index.d.ts +6 -0
- package/src/debug/index.js +1 -0
- package/src/debug/lib-generate-test-usersig-es.min.js +2 -0
- package/src/index.ts +9 -0
- package/src/service-worker/sw.ts +494 -0
- package/src/types/index.ts +2 -0
- package/src/types/inner.ts +44 -0
- package/src/types/outer.ts +142 -0
- package/src/utils/browser-support.ts +412 -0
- package/src/utils/logger.ts +66 -0
- package/src/utils/storage.ts +51 -0
- package/src/utils/validator.ts +267 -0
- package/CHANGELOG.md +0 -50
- package/index.d.ts +0 -110
- package/index.esm.js +0 -21437
- package/index.umd.js +0 -1
- package/src/types/outer.d.ts +0 -66
- package/sw.js +0 -1
- /package/{src → dist/src}/core/event-emitter.d.ts +0 -0
- /package/{src → dist/src}/core/service-worker-manager.d.ts +0 -0
- /package/{src → dist/src}/service-worker/sw.d.ts +0 -0
- /package/{src → dist/src}/types/index.d.ts +0 -0
- /package/{src → dist/src}/utils/browser-support.d.ts +0 -0
- /package/{src → dist/src}/utils/storage.d.ts +0 -0
package/src/types/outer.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export interface WebPushSDK {
|
|
2
|
-
registerPush(options?: RegisterPushOptions): Promise<any>;
|
|
3
|
-
unRegisterPush(): Promise<any>;
|
|
4
|
-
addPushListener(eventName: EVENT, listener: (data: EventResult) => void): any;
|
|
5
|
-
removePushListener(eventName: EVENT, listener: (data: EventResult) => void): any;
|
|
6
|
-
}
|
|
7
|
-
export interface RegisterPushOptions {
|
|
8
|
-
SDKAppID: number;
|
|
9
|
-
appKey: string;
|
|
10
|
-
userID: string;
|
|
11
|
-
serviceWorkerPath?: string;
|
|
12
|
-
chat?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare enum EVENT {
|
|
15
|
-
MESSAGE_RECEIVED = "message_received",
|
|
16
|
-
MESSAGE_REVOKED = "message_revoked",
|
|
17
|
-
NOTIFICATION_CLICKED = "notification_clicked"
|
|
18
|
-
}
|
|
19
|
-
export interface Message {
|
|
20
|
-
ID: String;
|
|
21
|
-
type: 'TIMTextElem' | 'TIMImageElem' | 'TIMSoundElem' | 'TIMVideoFileElem' | 'TIMFileElem' | 'TIMCustomElem' | 'TIMRelayElem' | 'TIMLocationElem' | 'TIMFaceElem';
|
|
22
|
-
payload: any;
|
|
23
|
-
conversationID: String;
|
|
24
|
-
conversationType: 'C2C' | 'GROUP';
|
|
25
|
-
to: String;
|
|
26
|
-
from: String;
|
|
27
|
-
flow: String;
|
|
28
|
-
time: Number;
|
|
29
|
-
status: String;
|
|
30
|
-
isRevoked: Boolean;
|
|
31
|
-
nick: String;
|
|
32
|
-
avatar: String;
|
|
33
|
-
isPeerRead: Boolean;
|
|
34
|
-
nameCard: String;
|
|
35
|
-
atUserList: String[];
|
|
36
|
-
cloudCustomData: String;
|
|
37
|
-
isDeleted: Boolean;
|
|
38
|
-
isModified: Boolean;
|
|
39
|
-
needReadReceipt: Boolean;
|
|
40
|
-
readReceiptInfo: any;
|
|
41
|
-
isBroadcastMessage: Boolean;
|
|
42
|
-
isSupportExtension: Boolean;
|
|
43
|
-
receiverList?: String[];
|
|
44
|
-
revoker: String;
|
|
45
|
-
sequence: Number;
|
|
46
|
-
progress: Number;
|
|
47
|
-
revokerInfo: {
|
|
48
|
-
userID: String;
|
|
49
|
-
nick: String;
|
|
50
|
-
avatar: String;
|
|
51
|
-
};
|
|
52
|
-
revokeReason: String;
|
|
53
|
-
hasRiskContent: Boolean;
|
|
54
|
-
}
|
|
55
|
-
export interface MessageReceivedResult {
|
|
56
|
-
message: Message;
|
|
57
|
-
}
|
|
58
|
-
export interface MessageRevokedResult {
|
|
59
|
-
messageID: String;
|
|
60
|
-
}
|
|
61
|
-
export interface MessageNotificationClickedResult {
|
|
62
|
-
ext: String;
|
|
63
|
-
}
|
|
64
|
-
export interface EventResult {
|
|
65
|
-
data: MessageReceivedResult | MessageRevokedResult | MessageNotificationClickedResult;
|
|
66
|
-
}
|
package/sw.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){"use strict";function t(t,...e){console.log(`[WebPush SW] ${t}`,...e)}function e(t,...e){console.warn(`[WebPush SW] ${t}`,...e)}function a(t,...e){console.error(`[WebPush SW] ${t}`,...e)}async function i(t){try{(await self.clients.matchAll({includeUncontrolled:!0,type:"window"})).forEach(e=>{e.postMessage(t)})}catch(e){a("Failed to send message to clients",e)}}async function n(i){try{if(!i.rptURL||!i.rptExt)return void e("Missing rptURL or rptExt, skipping report");const a={webpushEvents:[{id:i.id,EventType:i.eventType||1,EventTime:Math.floor(Date.now()/1e3),rptExt:i.rptExt}]};t("Reporting WebPush event",{rptURL:i.rptURL,reportData:a});const n=await fetch(i.rptURL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});n.ok?t("WebPush event reported successfully"):e("Failed to report WebPush event",n.status,n.statusText)}catch(n){a("Error reporting WebPush event",n)}}self.addEventListener("install",e=>{t("Service Worker installing..."),self.skipWaiting()}),self.addEventListener("activate",e=>{t("Service Worker activating..."),e.waitUntil(self.clients.claim())}),self.addEventListener("push",o=>{if(t("Push message received",o),o.data)try{let e;try{e=o.data.json(),t("Push message data (JSON):",e)}catch{const a=o.data.text();t("Push message data (Text):",a),e={id:"",title:"WebPush Notification",desc:a||"You have a new message",url:"/",icon:"",tag:"",image:"",rptExt:"",rptURL:""}}const a={messageID:e.id||Date.now().toString(36)+Math.random().toString(36).substr(2),title:e.title||"New Message",body:e.desc||"You have a new message",icon:e.icon||"",tag:e.tag||e?.id?.slice(-100)||"push-"+Date.now()+"-"+Math.random().toString(36).substr(2,5),data:{url:e.url,image:e.image,rptExt:e.rptExt,rptURL:e.rptURL},timestamp:Date.now()},s=self.registration.showNotification(a.title,{body:a.body,icon:a.icon,image:e.image,tag:a.tag,data:a,requireInteraction:!1}),r=i({type:"MESSAGE_RECEIVED",data:a}),c=e.rptURL&&e.rptExt?n({id:e.id,rptURL:e.rptURL,rptExt:e.rptExt,eventType:1}):Promise.resolve();o.waitUntil(Promise.all([s,r,c]))}catch(s){a("Failed to process push message",s),o.waitUntil(self.registration.showNotification("WebPush Notification",{body:"You have a new message",icon:"/vite.svg",tag:"fallback"}))}else e("Push message has no data")}),self.addEventListener("notificationclick",e=>{t("Notification clicked",e);const o=e.notification,s=e.action,r=o.data;if(o.close(),"close"===s)return;const c=i({type:"NOTIFICATION_CLICKED",data:{notification:r,action:s}}),l=async function(t="/"){try{const e=await self.clients.matchAll({type:"window",includeUncontrolled:!0}),a=new URL(t,self.location.origin).href;for(const t of e)if(t.url===a&&"focus"in t)return void(await t.focus());for(const i of e)if(i.url.startsWith(self.location.origin)&&"focus"in i)return await i.focus(),void i.postMessage({type:"NAVIGATE_TO",url:t});self.clients.openWindow&&await self.clients.openWindow(t)}catch(e){a("Failed to open or focus window",e)}}(r?.data?.url||"/"),d=r?.data?.rptURL&&r?.data?.rptExt?n({id:r.messageID,rptURL:r.data.rptURL,rptExt:r.data.rptExt,eventType:2}):Promise.resolve();e.waitUntil(Promise.all([c,l,d]))}),self.addEventListener("notificationclose",e=>{t("Notification closed",e)}),self.addEventListener("message",e=>{t("Message received from main thread",e.data);const{type:n,payload:o}=e.data;switch(n){case"SHOW_NOTIFICATION":!async function(e){try{const{eventType:a,data:i,options:n}=e;t("Handling show notification request",{eventType:a,data:i,options:n}),await self.registration.showNotification(n.title,{body:n.body,icon:n.icon,badge:n.badge,tag:n.tag,requireInteraction:n.requireInteraction,silent:n.silent,data:n.data}),t("Notification shown successfully",n.title)}catch(i){a("Failed to handle show notification",i)}}(o);break;case"REVOKE_MESSAGE":!async function(t){try{(await self.registration.getNotifications()).forEach(e=>{e.data&&e.data.messageID===t&&e.close()}),await i({type:"MESSAGE_REVOKED",data:{messageID:t}})}catch(e){a("Failed to handle message revocation",e)}}(o.messageID);break;case"UPDATE_CONFIG":t("Updating configuration",o)}}),self.addEventListener("error",t=>{a("Service Worker error",t.error)}),self.addEventListener("unhandledrejection",t=>{a("Service Worker unhandled promise rejection",t.reason)})}();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|