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

Add membership type field #426

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
199 changes: 144 additions & 55 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.

29 changes: 18 additions & 11 deletions lib/core/endpoints/objects/member/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ const utils_1 = require("../../../utils");
*/
const INCLUDE_CUSTOM_FIELDS = false;
/**
* Whether member's status field should be included in response or not.
* Whether member's `status` field should be included in response or not.
*/
const INCLUDE_STATUS = false;
/**
* Whether member's `type` field should be included in response or not.
*/
const INCLUDE_TYPE = false;
/**
* Whether total number of members should be included in response or not.
*/
Expand Down Expand Up @@ -67,20 +71,21 @@ const LIMIT = 100;
*/
class GetChannelMembersRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _k, _l, _m, _o, _p, _q, _r;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _l, _m, _o, _p, _q, _r, _s, _t;
super();
this.parameters = parameters;
// Apply default request parameters.
(_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {});
(_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS);
(_e = (_o = parameters.include).UUIDFields) !== null && _e !== void 0 ? _e : (_o.UUIDFields = INCLUDE_UUID_FIELDS);
(_f = (_p = parameters.include).customUUIDFields) !== null && _f !== void 0 ? _f : (_p.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS);
(_g = (_q = parameters.include).UUIDStatusField) !== null && _g !== void 0 ? _g : (_q.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD);
(_h = (_r = parameters.include).UUIDTypeField) !== null && _h !== void 0 ? _h : (_r.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD);
(_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT);
(_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS);
(_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE);
(_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS);
(_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS);
(_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD);
(_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD);
(_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT);
}
operation() {
return operations_1.default.PNSetMembersOperation;
Expand Down Expand Up @@ -114,6 +119,8 @@ class GetChannelMembersRequest extends request_1.AbstractRequest {
const includeFlags = [];
if (include.statusField)
includeFlags.push('status');
if (include.typeField)
includeFlags.push('type');
if (include.customFields)
includeFlags.push('custom');
if (include.UUIDFields)
Expand Down
44 changes: 36 additions & 8 deletions lib/core/endpoints/objects/member/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const utils_1 = require("../../../utils");
* Whether `Member` custom field should be included in response or not.
*/
const INCLUDE_CUSTOM_FIELDS = false;
/**
* Whether member's `status` field should be included in response or not.
*/
const INCLUDE_STATUS = false;
/**
* Whether member's `type` field should be included in response or not.
*/
const INCLUDE_TYPE = false;
/**
* Whether total number of members should be included in response or not.
*/
Expand All @@ -40,6 +48,14 @@ const INCLUDE_TOTAL_COUNT = false;
* Whether `UUID` fields should be included in response or not.
*/
const INCLUDE_UUID_FIELDS = false;
/**
* Whether `UUID` status field should be included in response or not.
*/
const INCLUDE_UUID_STATUS_FIELD = false;
/**
* Whether `UUID` type field should be included in response or not.
*/
const INCLUDE_UUID_TYPE_FIELD = false;
/**
* Whether `UUID` custom field should be included in response or not.
*/
Expand All @@ -56,17 +72,21 @@ const LIMIT = 100;
*/
class SetChannelMembersRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a, _b, _c, _d, _e, _f;
var _g, _h, _j, _k;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _l, _m, _o, _p, _q, _r, _s, _t;
super({ method: transport_request_1.TransportMethod.PATCH });
this.parameters = parameters;
// Apply default request parameters.
(_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {});
(_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_j = parameters.include).UUIDFields) !== null && _d !== void 0 ? _d : (_j.UUIDFields = INCLUDE_UUID_FIELDS);
(_e = (_k = parameters.include).customUUIDFields) !== null && _e !== void 0 ? _e : (_k.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS);
(_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT);
(_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS);
(_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE);
(_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS);
(_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS);
(_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD);
(_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD);
(_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT);
}
operation() {
return operations_1.default.PNSetMembersOperation;
Expand Down Expand Up @@ -101,10 +121,18 @@ class SetChannelMembersRequest extends request_1.AbstractRequest {
else
sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option));
const includeFlags = ['uuid.status', 'uuid.type', 'type'];
if (include.statusField)
includeFlags.push('status');
if (include.typeField)
includeFlags.push('type');
if (include.customFields)
includeFlags.push('custom');
if (include.UUIDFields)
includeFlags.push('uuid');
if (include.UUIDStatusField)
includeFlags.push('uuid.status');
if (include.UUIDTypeField)
includeFlags.push('uuid.type');
if (include.customUUIDFields)
includeFlags.push('uuid.custom');
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {}));
Expand All @@ -117,7 +145,7 @@ class SetChannelMembersRequest extends request_1.AbstractRequest {
return { uuid: { id: uuid } };
}
else {
return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom };
return { uuid: { id: uuid.id }, status: uuid.status, type: uuid.type, custom: uuid.custom };
}
}),
});
Expand Down
29 changes: 18 additions & 11 deletions lib/core/endpoints/objects/membership/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ const utils_1 = require("../../../utils");
*/
const INCLUDE_CUSTOM_FIELDS = false;
/**
* Whether membership's status field should be included in response or not.
* Whether membership's `status` field should be included in response or not.
*/
const INCLUDE_STATUS = false;
/**
* Whether membership's `type` field should be included in response or not.
*/
const INCLUDE_TYPE = false;
/**
* Whether total number of memberships should be included in response or not.
*/
Expand Down Expand Up @@ -67,20 +71,21 @@ const LIMIT = 100;
*/
class GetUUIDMembershipsRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _k, _l, _m, _o, _p, _q, _r;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _l, _m, _o, _p, _q, _r, _s, _t;
super();
this.parameters = parameters;
// Apply default request parameters.
(_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {});
(_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS);
(_e = (_o = parameters.include).channelFields) !== null && _e !== void 0 ? _e : (_o.channelFields = INCLUDE_CHANNEL_FIELDS);
(_f = (_p = parameters.include).customChannelFields) !== null && _f !== void 0 ? _f : (_p.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS);
(_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD);
(_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD);
(_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT);
(_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS);
(_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE);
(_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS);
(_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS);
(_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD);
(_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD);
(_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT);
// Remap for backward compatibility.
if (this.parameters.userId)
this.parameters.uuid = this.parameters.userId;
Expand Down Expand Up @@ -117,6 +122,8 @@ class GetUUIDMembershipsRequest extends request_1.AbstractRequest {
const includeFlags = [];
if (include.statusField)
includeFlags.push('status');
if (include.typeField)
includeFlags.push('type');
if (include.customFields)
includeFlags.push('custom');
if (include.channelFields)
Expand Down
44 changes: 36 additions & 8 deletions lib/core/endpoints/objects/membership/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const utils_1 = require("../../../utils");
* Whether `Membership` custom field should be included in response or not.
*/
const INCLUDE_CUSTOM_FIELDS = false;
/**
* Whether membership's `status` field should be included in response or not.
*/
const INCLUDE_STATUS = false;
/**
* Whether membership's `type` field should be included in response or not.
*/
const INCLUDE_TYPE = false;
/**
* Whether total number of memberships should be included in response or not.
*/
Expand All @@ -40,6 +48,14 @@ const INCLUDE_TOTAL_COUNT = false;
* Whether `Channel` fields should be included in response or not.
*/
const INCLUDE_CHANNEL_FIELDS = false;
/**
* Whether `Channel` status field should be included in response or not.
*/
const INCLUDE_CHANNEL_STATUS_FIELD = false;
/**
* Whether `Channel` type field should be included in response or not.
*/
const INCLUDE_CHANNEL_TYPE_FIELD = false;
/**
* Whether `Channel` custom field should be included in response or not.
*/
Expand All @@ -56,17 +72,21 @@ const LIMIT = 100;
*/
class SetUUIDMembershipsRequest extends request_1.AbstractRequest {
constructor(parameters) {
var _a, _b, _c, _d, _e, _f;
var _g, _h, _j, _k;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _l, _m, _o, _p, _q, _r, _s, _t;
super({ method: transport_request_1.TransportMethod.PATCH });
this.parameters = parameters;
// Apply default request parameters.
(_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {});
(_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS);
(_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS);
(_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT);
(_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS);
(_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT);
(_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS);
(_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE);
(_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS);
(_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS);
(_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD);
(_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD);
(_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT);
// Remap for backward compatibility.
if (this.parameters.userId)
this.parameters.uuid = this.parameters.userId;
Expand Down Expand Up @@ -104,10 +124,18 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest {
else
sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option));
const includeFlags = ['channel.status', 'channel.type', 'status'];
if (include.statusField)
includeFlags.push('status');
if (include.typeField)
includeFlags.push('type');
if (include.customFields)
includeFlags.push('custom');
if (include.channelFields)
includeFlags.push('channel');
if (include.channelStatusField)
includeFlags.push('channel.status');
if (include.channelTypeField)
includeFlags.push('channel.type');
if (include.customChannelFields)
includeFlags.push('channel.custom');
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {}));
Expand All @@ -120,7 +148,7 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest {
return { channel: { id: channel } };
}
else {
return { channel: { id: channel.id }, status: channel.status, custom: channel.custom };
return { channel: { id: channel.id }, status: channel.status, type: channel.type, custom: channel.custom };
}
}),
});
Expand Down
15 changes: 11 additions & 4 deletions lib/core/endpoints/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,24 @@ class BaseSubscribeRequest extends request_1.AbstractRequest {
// --------------------------------------------------------
// region Envelope parsing
presenceEventFromEnvelope(envelope) {
var _a;
const { d: payload } = envelope;
const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope);
// Clean up channel and subscription name from presence suffix.
const trimmedChannel = channel.replace('-pnpres', '');
// Backward compatibility with deprecated properties.
const actualChannel = subscription !== null ? trimmedChannel : null;
const subscribedChannel = subscription !== null ? subscription : trimmedChannel;
if (typeof payload !== 'string' && 'data' in payload) {
// @ts-expect-error This is `state-change` object which should have `state` field.
payload['state'] = payload.data;
delete payload.data;
if (typeof payload !== 'string') {
if ('data' in payload) {
// @ts-expect-error This is `state-change` object which should have `state` field.
payload['state'] = payload.data;
delete payload.data;
}
else if ('action' in payload && payload.action === 'interval') {
payload.hereNowRefresh = (_a = payload.here_now_refresh) !== null && _a !== void 0 ? _a : false;
delete payload.here_now_refresh;
}
}
return Object.assign({ channel: trimmedChannel, subscription,
actualChannel,
Expand Down
7 changes: 3 additions & 4 deletions lib/file/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ class PubNubFile {
let fileName;
if (stream && stream instanceof stream_1.Readable) {
fileData = stream;
if (stream instanceof fs_1.default.ReadStream) {
const streamFilePath = stream.path instanceof buffer_1.Buffer ? new TextDecoder().decode(stream.path) : stream.path;
fileName = (0, path_1.basename)(streamFilePath);
contentLength = fs_1.default.statSync(streamFilePath).size;
if (stream instanceof fs_1.default.ReadStream && !(stream.path instanceof buffer_1.Buffer)) {
fileName = (0, path_1.basename)(stream.path);
contentLength = fs_1.default.statSync(stream.path).size;
}
}
else if (data instanceof buffer_1.Buffer) {
Expand Down
Loading