Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types definition issues #417

Merged
merged 10 commits into from
Oct 31, 2024
  •  
  •  
  •  
803 changes: 803 additions & 0 deletions .scripts/types-aggregate.ts

Large diffs are not rendered by default.

1,499 changes: 1,417 additions & 82 deletions dist/web/pubnub.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/web/pubnub.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
var uuidExports = uuid.exports;
var uuidGenerator$1 = /*@__PURE__*/getDefaultExportFromCjs(uuidExports);

/**
* Random identifier generator helper module.
*
* @internal
*/
/** @internal */
var uuidGenerator = {
createUUID() {
if (uuidGenerator$1.uuid) {
Expand All @@ -105,6 +111,8 @@
*
* Service worker provides support for PubNub subscription feature to give better user experience across
* multiple opened pages.
*
* @internal
*/
/**
* How often PING request should be sent to the PubNub clients.
Expand Down
2 changes: 2 additions & 0 deletions lib/cbor/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
/**
* Cbor decoder module.
*
* @internal
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
Expand Down
5 changes: 5 additions & 0 deletions lib/core/components/abort_signal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use strict";
/**
* Event Engine managed effects terminate signal module.
*
* @internal
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbortSignal = exports.AbortError = void 0;
const subject_1 = require("./subject");
Expand Down
5 changes: 5 additions & 0 deletions lib/core/components/base64_codec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use strict";
/**
* Base64 support module.
*
* @internal
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.encode = exports.decode = void 0;
const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
Expand Down
4 changes: 3 additions & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
/**
* {@link PubNub} client configuration module.
*
* @internal
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
Expand All @@ -22,7 +24,7 @@ const USE_RANDOM_INITIALIZATION_VECTOR = true;
* Create {@link PubNub} client private configuration object.
*
* @param base - User- and platform-provided configuration.
* @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block.
* @param setupCryptoModule - Platform-provided {@link ICryptoModule} configuration block.
*
* @returns `PubNub` client private configuration.
*
Expand Down
5 changes: 5 additions & 0 deletions lib/core/components/cryptography/hmac-sha256.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use strict";
/**
* CryptoJS implementation.
*
* @internal
*/
/*eslint-disable */
/*
CryptoJS v3.1.2
Expand Down
9 changes: 9 additions & 0 deletions lib/core/components/cryptography/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
/**
* Legacy cryptography module.
*
* @internal
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
Expand All @@ -14,6 +16,8 @@ const hmac_sha256_1 = __importDefault(require("./hmac-sha256"));
* @param b - Bytes array (buffer) which should be converted.
*
* @returns Word sized array.
*
* @internal
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
function bufferToWordArray(b) {
Expand All @@ -25,6 +29,11 @@ function bufferToWordArray(b) {
// @ts-expect-error Bundled library without types.
return hmac_sha256_1.default.lib.WordArray.create(wa, b.length);
}
/**
* Legacy cryptography module for files and signature.
*
* @internal
*/
class default_1 {
constructor(configuration) {
this.configuration = configuration;
Expand Down
75 changes: 55 additions & 20 deletions lib/core/components/deduping_manager.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,78 @@
"use strict";
/* */
/**
* Messages de-duplication manager module.
*
* @internal
*/
Object.defineProperty(exports, "__esModule", { value: true });
const hashCode = (payload) => {
let hash = 0;
if (payload.length === 0)
return hash;
for (let i = 0; i < payload.length; i += 1) {
const character = payload.charCodeAt(i);
hash = (hash << 5) - hash + character; // eslint-disable-line
hash = hash & hash; // eslint-disable-line
}
return hash;
};
exports.DedupingManager = void 0;
/**
* Real-time events deduplication manager.
*
* @internal
*/
class default_1 {
constructor({ config }) {
class DedupingManager {
/**
* Create and configure real-time events de-duplication manager.
*
* @param config - PubNub client configuration object.
*/
constructor({ maximumCacheSize }) {
this.maximumCacheSize = maximumCacheSize;
this.hashHistory = [];
this._config = config;
}
/**
* Compute unique real-time event payload key.
*
* @param message - Received real-time event payload for which unique key should be computed.
* @returns Unique real-time event payload key in messages cache.
*/
getKey(message) {
const hashedPayload = hashCode(JSON.stringify(message.message)).toString();
const timetoken = message.timetoken;
return `${timetoken}-${hashedPayload}`;
var _a;
return `${message.timetoken}-${this.hashCode(JSON.stringify((_a = message.message) !== null && _a !== void 0 ? _a : '')).toString()}`;
}
/**
* Check whether there is similar message already received or not.
*
* @param message - Received real-time event payload which should be checked for duplicates.
* @returns `true` in case if similar payload already has been received before.
*/
isDuplicate(message) {
return this.hashHistory.includes(this.getKey(message));
}
/**
* Store received message to be used later for duplicate detection.
*
* @param message - Received real-time event payload.
*/
addEntry(message) {
if (this.hashHistory.length >= this._config.maximumCacheSize) {
if (this.hashHistory.length >= this.maximumCacheSize) {
this.hashHistory.shift();
}
this.hashHistory.push(this.getKey(message));
}
/**
* Clean up cached messages.
*/
clearHistory() {
this.hashHistory = [];
}
/**
* Compute message hash sum.
*
* @param payload - Received payload for which hash sum should be computed.
* @returns {number} - Resulting hash sum.
*/
hashCode(payload) {
let hash = 0;
if (payload.length === 0)
return hash;
for (let i = 0; i < payload.length; i += 1) {
const character = payload.charCodeAt(i);
hash = (hash << 5) - hash + character; // eslint-disable-line
hash = hash & hash; // eslint-disable-line
}
return hash;
}
}
exports.default = default_1;
exports.DedupingManager = DedupingManager;
5 changes: 5 additions & 0 deletions lib/core/components/eventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use strict";
/**
* Real-time events emitter module.
*
* @internal
*/
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
Expand Down
73 changes: 71 additions & 2 deletions lib/core/components/push_payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ exports.FCMNotificationPayload = exports.APNSNotificationPayload = void 0;
* Base notification payload object.
*/
class BaseNotificationPayload {
/**
* Base notification provider payload object.
*
* @internal
*
* @param payload - Object which contains vendor-specific preformatted push notification payload.
* @param title - Notification main title.
* @param body - Notification body (main messages).
*/
constructor(payload, title, body) {
this._payload = payload;
this.setDefaultPayloadStructure();
Expand Down Expand Up @@ -78,11 +87,15 @@ class BaseNotificationPayload {
}
/**
* Platform-specific structure initialization.
*
* @internal
*/
setDefaultPayloadStructure() { }
/**
* Translate data object into PubNub push notification payload object.
*
* @internal
*
* @returns Preformatted push notification payload.
*/
toObject() {
Expand All @@ -97,10 +110,14 @@ class APNSNotificationPayload extends BaseNotificationPayload {
super(...arguments);
/**
* Type of push notification service for which payload will be created.
*
* @internal
*/
this._apnsPushType = 'apns';
/**
* Whether resulting payload should trigger silent notification or not.
*
* @internal
*/
this._isSilent = false;
}
Expand Down Expand Up @@ -230,9 +247,21 @@ class APNSNotificationPayload extends BaseNotificationPayload {
set silent(value) {
this._isSilent = value;
}
/**
* Setup push notification payload default content.
*
* @internal
*/
setDefaultPayloadStructure() {
this.payload.aps = { alert: {} };
}
/**
* Translate data object into PubNub push notification payload object.
*
* @internal
*
* @returns Preformatted push notification payload.
*/
toObject() {
const payload = Object.assign({}, this.payload);
const { aps } = payload;
Expand Down Expand Up @@ -262,6 +291,8 @@ class APNSNotificationPayload extends BaseNotificationPayload {
/**
* Create PubNub push notification service APNS2 configuration information object.
*
* @internal
*
* @param configuration - Source user-provided APNS2 configuration.
*
* @returns Preformatted for PubNub service APNS2 configuration information.
Expand All @@ -284,6 +315,8 @@ class APNSNotificationPayload extends BaseNotificationPayload {
/**
* Create PubNub push notification service APNS2 target information object.
*
* @internal
*
* @param target - Source user-provided data.
*
* @returns Preformatted for PubNub service APNS2 target information.
Expand All @@ -300,7 +333,7 @@ class APNSNotificationPayload extends BaseNotificationPayload {
}
exports.APNSNotificationPayload = APNSNotificationPayload;
/**
* Message payload for Firebase Clouse Messaging service.
* Message payload for Firebase Cloud Messaging service.
*/
class FCMNotificationPayload extends BaseNotificationPayload {
get payload() {
Expand Down Expand Up @@ -398,9 +431,19 @@ class FCMNotificationPayload extends BaseNotificationPayload {
this.payload.notification.icon = value;
this._icon = value;
}
/**
* Retrieve notifications grouping tag.
*
* @returns Notifications grouping tag.
*/
get tag() {
return this._tag;
}
/**
* Update notifications grouping tag.
*
* @param value - String which will be used to group similar notifications in notification center.
*/
set tag(value) {
if (!value || !value.length)
return;
Expand All @@ -417,10 +460,22 @@ class FCMNotificationPayload extends BaseNotificationPayload {
set silent(value) {
this._isSilent = value;
}
/**
* Setup push notification payload default content.
*
* @internal
*/
setDefaultPayloadStructure() {
this.payload.notification = {};
this.payload.data = {};
}
/**
* Translate data object into PubNub push notification payload object.
*
* @internal
*
* @returns Preformatted push notification payload.
*/
toObject() {
let data = Object.assign({}, this.payload.data);
let notification = null;
Expand All @@ -443,13 +498,27 @@ class FCMNotificationPayload extends BaseNotificationPayload {
}
exports.FCMNotificationPayload = FCMNotificationPayload;
class NotificationsPayload {
/**
* Create push notification payload holder.
*
* @internal
*
* @param title - String which will be shown at the top of the notification (below app name).
* @param body - String with message which should be shown when user will check notification.
*/
constructor(title, body) {
this._payload = { apns: {}, fcm: {} };
this._title = title;
this._body = body;
this.apns = new APNSNotificationPayload(this._payload.apns, title, body);
this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body);
}
/**
* Enable or disable push notification debugging message.
*
* @param value - Whether debug message from push notification scheduler should be published to the specific
* channel or not.
*/
set debugging(value) {
this._debugging = value;
}
Expand Down Expand Up @@ -527,7 +596,7 @@ class NotificationsPayload {
* Build notifications platform for requested platforms.
*
* @param platforms - List of platforms for which payload should be added to final dictionary. Supported values:
* gcm, apns, and apns2.
* fcm, apns, and apns2.
*
* @returns Object with data, which can be sent with publish method call and trigger remote notifications for
* specified platforms.
Expand Down
Loading
Loading