Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
311 changes: 152 additions & 159 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.

5 changes: 4 additions & 1 deletion lib/core/components/retry-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const categories_1 = __importDefault(require("../constants/categories"));
/**
* HTTP status codes which represent definitive client-side outcomes and shouldn't be retried.
*
* `412` is a failed `If-Match` / `If-None-Match` precondition: resending the same conditional
* request can never succeed.
*
* @internal
*/
const NON_RETRIABLE_STATUS_CODES = [404, 409];
const NON_RETRIABLE_STATUS_CODES = [404, 409, 412];
// --------------------------------------------------------
// ------------------------ Types -------------------------
// --------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/core/endpoints/data_sync/channel/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class CreateChannelRequest extends request_1.AbstractRequest {
return `/v1/datasync/subkeys/${subscribeKey}/channels`;
}
get body() {
const { id, class: entityClass, classLevel, data } = this.parameters;
const { id, class: entityClass, classLevel, ttl, data } = this.parameters;
return JSON.stringify({
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (id !== undefined ? { id } : {})), (entityClass !== undefined ? { entityClass } : {})), { entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (id !== undefined ? { id } : {})), (entityClass !== undefined ? { entityClass } : {})), { entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (ttl !== undefined ? { entityTtlSec: ttl } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
});
}
}
Expand Down
13 changes: 1 addition & 12 deletions lib/core/endpoints/data_sync/channel/get-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ exports.GetChannelsRequest = void 0;
const request_1 = require("../../../components/request");
const operations_1 = __importDefault(require("../../../constants/operations"));
const DataSync = __importStar(require("../../../types/api/data-sync"));
// --------------------------------------------------------
// ----------------------- Defaults -----------------------
// --------------------------------------------------------
// region Defaults
/**
* Default number of items per page.
*/
const DEFAULT_LIMIT = 20;
// endregion
/**
* Get Channels request.
Expand All @@ -70,11 +62,8 @@ const DEFAULT_LIMIT = 20;
*/
class GetChannelsRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a;
super();
this.parameters = parameters;
// Apply defaults.
(_a = parameters.limit) !== null && _a !== void 0 ? _a : (parameters.limit = DEFAULT_LIMIT);
}
operation() {
return operations_1.default.PNGetDataSyncChannelsOperation;
Expand All @@ -93,7 +82,7 @@ class GetChannelsRequest extends request_1.AbstractRequest {
get queryParameters() {
const { class: entityClass, classVersion, classLevel, cursor, limit, filter, filterFast, sort } = this.parameters;
const sorting = DataSync.serializeDataSyncSort(sort);
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (entityClass ? { entity_class: entityClass } : {})), (classVersion !== undefined ? { entity_class_version: `${classVersion}` } : {})), (classLevel ? { entity_class_level: classLevel } : {})), (cursor ? { cursor } : {})), (limit ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (entityClass !== undefined ? { entity_class: entityClass } : {})), (classVersion !== undefined ? { entity_class_version: `${classVersion}` } : {})), (classLevel ? { entity_class_level: classLevel } : {})), (cursor ? { cursor } : {})), (limit !== undefined ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
}
}
exports.GetChannelsRequest = GetChannelsRequest;
9 changes: 6 additions & 3 deletions lib/core/endpoints/data_sync/channel/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Set Channel REST API module.
*
* Full resource replacement via PUT.
* Create or replace (upsert) via PUT: creates the channel when no live record exists at the path ID
* (HTTP 201), otherwise replaces it (HTTP 200). An omitted class creates a Global `Channel`.
*
* @internal
*/
Expand Down Expand Up @@ -59,16 +60,18 @@ class SetChannelRequest extends request_1.AbstractRequest {
let headers = (_a = super.headers) !== null && _a !== void 0 ? _a : {};
if (this.parameters.ifMatchesEtag)
headers = Object.assign(Object.assign({}, headers), { 'If-Match': this.parameters.ifMatchesEtag });
if (this.parameters.ifNoneMatch)
headers = Object.assign(Object.assign({}, headers), { 'If-None-Match': this.parameters.ifNoneMatch });
return Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/vnd.pubnub.objects.channel+json;version=1' });
}
get path() {
const { keySet: { subscribeKey }, id, } = this.parameters;
return `/v1/datasync/subkeys/${subscribeKey}/channels/${(0, utils_1.encodeString)(id)}`;
}
get body() {
const { data } = this.parameters;
const { class: entityClass, classLevel, ttl, data } = this.parameters;
return JSON.stringify({
data: Object.assign(Object.assign({ entityClassVersion: data.classVersion }, (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (entityClass !== undefined ? { entityClass } : {})), { entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (ttl !== undefined ? { entityTtlSec: ttl } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
});
}
}
Expand Down
15 changes: 4 additions & 11 deletions lib/core/endpoints/data_sync/channel/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Update Channel REST API module.
*
* Partial update via JSON Patch (RFC 6902).
* Pass `operations` to send an ordered list exactly as written. The grouped fields keep a fixed order.
* Accepts `add`/`replace`/`test` (JSON Pointer key-value pairs), `remove`
* (JSON Pointer paths), and `move`/`copy` (JSON Pointer from → path pairs),
* converting them to JSON Patch operations. Paths are sent verbatim.
Expand Down Expand Up @@ -53,15 +54,7 @@ class UpdateChannelRequest extends request_1.AbstractRequest {
validate() {
if (!this.parameters.id)
return 'Channel id cannot be empty';
const { add, replace, remove, move, copy, test } = this.parameters;
const hasAdd = add && Object.keys(add).length > 0;
const hasReplace = replace && Object.keys(replace).length > 0;
const hasRemove = remove && remove.length > 0;
const hasMove = move && move.length > 0;
const hasCopy = copy && copy.length > 0;
const hasTest = test && Object.keys(test).length > 0;
if (!hasAdd && !hasReplace && !hasRemove && !hasMove && !hasCopy && !hasTest)
return 'At least one of add, replace, remove, move, copy, or test must be provided';
return (0, data_sync_1.validateJsonPatchInput)(this.parameters);
}
get headers() {
var _a;
Expand All @@ -75,8 +68,8 @@ class UpdateChannelRequest extends request_1.AbstractRequest {
return `/v1/datasync/subkeys/${subscribeKey}/channels/${(0, utils_1.encodeString)(id)}`;
}
get body() {
const { add, replace, remove, move, copy, test } = this.parameters;
const jsonPatchOps = (0, data_sync_1.toJsonPatchOperations)({ add, replace, remove, move, copy, test });
const { add, replace, remove, move, copy, test, operations } = this.parameters;
const jsonPatchOps = (0, data_sync_1.toJsonPatchOperations)({ add, replace, remove, move, copy, test, operations });
return JSON.stringify(jsonPatchOps);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/endpoints/data_sync/entity/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class CreateEntityRequest extends request_1.AbstractRequest {
return `/v1/datasync/subkeys/${subscribeKey}/entities`;
}
get body() {
const { id, class: entityClass, classLevel, data } = this.parameters;
const { id, class: entityClass, classLevel, ttl, data } = this.parameters;
return JSON.stringify({
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (id !== undefined ? { id } : {})), { entityClass, entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (id !== undefined ? { id } : {})), { entityClass, entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (ttl !== undefined ? { entityTtlSec: ttl } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
});
}
}
Expand Down
13 changes: 1 addition & 12 deletions lib/core/endpoints/data_sync/entity/get-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ exports.GetEntitiesRequest = void 0;
const request_1 = require("../../../components/request");
const operations_1 = __importDefault(require("../../../constants/operations"));
const DataSync = __importStar(require("../../../types/api/data-sync"));
// --------------------------------------------------------
// ----------------------- Defaults -----------------------
// --------------------------------------------------------
// region Defaults
/**
* Default number of items per page.
*/
const DEFAULT_LIMIT = 20;
// endregion
/**
* Get Entities request.
Expand All @@ -70,11 +62,8 @@ const DEFAULT_LIMIT = 20;
*/
class GetEntitiesRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a;
super();
this.parameters = parameters;
// Apply defaults.
(_a = parameters.limit) !== null && _a !== void 0 ? _a : (parameters.limit = DEFAULT_LIMIT);
}
operation() {
return operations_1.default.PNGetDataSyncEntitiesOperation;
Expand All @@ -97,7 +86,7 @@ class GetEntitiesRequest extends request_1.AbstractRequest {
get queryParameters() {
const { class: entityClass, classVersion, classLevel, cursor, limit, filter, filterFast, sort } = this.parameters;
const sorting = DataSync.serializeDataSyncSort(sort);
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ entity_class: entityClass }, (classVersion !== undefined ? { entity_class_version: `${classVersion}` } : {})), (classLevel ? { entity_class_level: classLevel } : {})), (cursor ? { cursor } : {})), (limit ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ entity_class: entityClass }, (classVersion !== undefined ? { entity_class_version: `${classVersion}` } : {})), (classLevel ? { entity_class_level: classLevel } : {})), (cursor ? { cursor } : {})), (limit !== undefined ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
}
}
exports.GetEntitiesRequest = GetEntitiesRequest;
11 changes: 7 additions & 4 deletions lib/core/endpoints/data_sync/entity/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
/**
* Set Entity REST API module.
*
* Full resource replacement via PUT.
* Note: `entityClass` is immutable and cannot be changed via update.
* Create or replace (upsert) via PUT: creates the entity when no live record exists at the path ID
* (HTTP 201), otherwise replaces it (HTTP 200). Creation requires `entityClass`; on replacement a
* supplied class / level is an immutable identity assertion.
*
* @internal
*/
Expand Down Expand Up @@ -60,16 +61,18 @@ class SetEntityRequest extends request_1.AbstractRequest {
let headers = (_a = super.headers) !== null && _a !== void 0 ? _a : {};
if (this.parameters.ifMatchesEtag)
headers = Object.assign(Object.assign({}, headers), { 'If-Match': this.parameters.ifMatchesEtag });
if (this.parameters.ifNoneMatch)
headers = Object.assign(Object.assign({}, headers), { 'If-None-Match': this.parameters.ifNoneMatch });
return Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/vnd.pubnub.objects.entity+json;version=1' });
}
get path() {
const { keySet: { subscribeKey }, id, } = this.parameters;
return `/v1/datasync/subkeys/${subscribeKey}/entities/${(0, utils_1.encodeString)(id)}`;
}
get body() {
const { data } = this.parameters;
const { class: entityClass, classLevel, ttl, data } = this.parameters;
return JSON.stringify({
data: Object.assign(Object.assign({ entityClassVersion: data.classVersion }, (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
data: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (entityClass !== undefined ? { entityClass } : {})), { entityClassVersion: data.classVersion }), (classLevel !== undefined ? { entityClassLevel: classLevel } : {})), (ttl !== undefined ? { entityTtlSec: ttl } : {})), (data.status !== undefined ? { status: data.status } : {})), (data.payload !== undefined ? { payload: data.payload } : {})),
});
}
}
Expand Down
15 changes: 4 additions & 11 deletions lib/core/endpoints/data_sync/entity/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Update Entity REST API module.
*
* Partial update via JSON Patch (RFC 6902).
* Pass `operations` to send an ordered list exactly as written. The grouped fields keep a fixed order.
* Accepts `add`/`replace`/`test` (JSON Pointer key-value pairs), `remove`
* (JSON Pointer paths), and `move`/`copy` (JSON Pointer from/path pairs), and
* converts them to JSON Patch operations. Paths are sent verbatim.
Expand Down Expand Up @@ -53,15 +54,7 @@ class UpdateEntityRequest extends request_1.AbstractRequest {
validate() {
if (!this.parameters.id)
return 'Entity id cannot be empty';
const { add, replace, remove, move, copy, test } = this.parameters;
const hasAdd = add && Object.keys(add).length > 0;
const hasReplace = replace && Object.keys(replace).length > 0;
const hasRemove = remove && remove.length > 0;
const hasMove = move && move.length > 0;
const hasCopy = copy && copy.length > 0;
const hasTest = test && Object.keys(test).length > 0;
if (!hasAdd && !hasReplace && !hasRemove && !hasMove && !hasCopy && !hasTest)
return 'At least one of add, replace, remove, move, copy, or test must be provided';
return (0, data_sync_1.validateJsonPatchInput)(this.parameters);
}
get headers() {
var _a;
Expand All @@ -75,8 +68,8 @@ class UpdateEntityRequest extends request_1.AbstractRequest {
return `/v1/datasync/subkeys/${subscribeKey}/entities/${(0, utils_1.encodeString)(id)}`;
}
get body() {
const { add, replace, remove, move, copy, test } = this.parameters;
const jsonPatchOps = (0, data_sync_1.toJsonPatchOperations)({ add, replace, remove, move, copy, test });
const { add, replace, remove, move, copy, test, operations } = this.parameters;
const jsonPatchOps = (0, data_sync_1.toJsonPatchOperations)({ add, replace, remove, move, copy, test, operations });
return JSON.stringify(jsonPatchOps);
}
}
Expand Down
13 changes: 1 addition & 12 deletions lib/core/endpoints/data_sync/membership/get-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ exports.GetMembershipsRequest = void 0;
const request_1 = require("../../../components/request");
const operations_1 = __importDefault(require("../../../constants/operations"));
const DataSync = __importStar(require("../../../types/api/data-sync"));
// --------------------------------------------------------
// ----------------------- Defaults -----------------------
// --------------------------------------------------------
// region Defaults
/**
* Default number of items per page.
*/
const DEFAULT_LIMIT = 20;
// endregion
/**
* Get Memberships request.
Expand All @@ -70,11 +62,8 @@ const DEFAULT_LIMIT = 20;
*/
class GetMembershipsRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a;
super();
this.parameters = parameters;
// Apply defaults.
(_a = parameters.limit) !== null && _a !== void 0 ? _a : (parameters.limit = DEFAULT_LIMIT);
}
operation() {
return operations_1.default.PNGetDataSyncMembershipsOperation;
Expand All @@ -93,7 +82,7 @@ class GetMembershipsRequest extends request_1.AbstractRequest {
get queryParameters() {
const { userId, channelId, classVersion, cursor, limit, filter, filterFast, sort } = this.parameters;
const sorting = DataSync.serializeDataSyncSort(sort);
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (userId ? { user_id: userId } : {})), (channelId ? { channel_id: channelId } : {})), (classVersion !== undefined ? { relationship_class_version: `${classVersion}` } : {})), (cursor ? { cursor } : {})), (limit ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (userId !== undefined ? { user_id: userId } : {})), (channelId !== undefined ? { channel_id: channelId } : {})), (classVersion !== undefined ? { relationship_class_version: `${classVersion}` } : {})), (cursor ? { cursor } : {})), (limit !== undefined ? { limit: `${limit}` } : {})), (filter ? { filter } : {})), (filterFast ? { filter_fast: filterFast } : {})), (sorting.length ? { sort: sorting } : {}));
}
}
exports.GetMembershipsRequest = GetMembershipsRequest;
Loading
Loading