|
668 | 668 | if (setup.heartbeatInterval != null) {
|
669 | 669 | this.setHeartbeatInterval(setup.heartbeatInterval);
|
670 | 670 | }
|
671 |
| - this.setUUID(setup.uuid); |
| 671 | + if (typeof setup.userId === 'string') { |
| 672 | + if (typeof setup.uuid === 'string') { |
| 673 | + throw new Error('Only one of the following configuration options has to be provided: `uuid` or `userId`'); |
| 674 | + } |
| 675 | + this.setUserId(setup.userId); |
| 676 | + } |
| 677 | + else { |
| 678 | + if (typeof setup.uuid !== 'string') { |
| 679 | + throw new Error('One of the following configuration options has to be provided: `uuid` or `userId`'); |
| 680 | + } |
| 681 | + this.setUUID(setup.uuid); |
| 682 | + } |
672 | 683 | }
|
673 | 684 | // exposed setters
|
674 | 685 | default_1.prototype.getAuthKey = function () {
|
|
692 | 703 | this.UUID = val;
|
693 | 704 | return this;
|
694 | 705 | };
|
| 706 | + default_1.prototype.getUserId = function () { |
| 707 | + return this.UUID; |
| 708 | + }; |
| 709 | + default_1.prototype.setUserId = function (value) { |
| 710 | + if (!value || typeof value !== 'string' || value.trim().length === 0) { |
| 711 | + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); |
| 712 | + } |
| 713 | + this.UUID = value; |
| 714 | + return this; |
| 715 | + }; |
695 | 716 | default_1.prototype.getFilterExpression = function () {
|
696 | 717 | return this.filterExpression;
|
697 | 718 | };
|
|
747 | 768 | return this;
|
748 | 769 | };
|
749 | 770 | default_1.prototype.getVersion = function () {
|
750 |
| - return '7.1.2'; |
| 771 | + return '7.2.0'; |
751 | 772 | };
|
752 | 773 | default_1.prototype._addPnsdkSuffix = function (name, suffix) {
|
753 | 774 | this._PNSDKSuffix[name] = suffix;
|
|
5620 | 5641 | handleResponse: handleResponse$9
|
5621 | 5642 | });
|
5622 | 5643 |
|
5623 |
| - /* */ |
5624 | 5644 | function getOperation$8() {
|
5625 | 5645 | return OPERATIONS.PNAccessManagerGrantToken;
|
5626 | 5646 | }
|
| 5647 | + function hasVspTerms(incomingParams) { |
| 5648 | + var _a, _b, _c, _d; |
| 5649 | + var hasAuthorizedUserId = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorizedUserId) !== undefined; |
| 5650 | + var hasUserResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.users) !== undefined; |
| 5651 | + var hasSpaceResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.spaces) !== undefined; |
| 5652 | + var hasUserPatterns = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _c === void 0 ? void 0 : _c.users) !== undefined; |
| 5653 | + var hasSpacePatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.spaces) !== undefined; |
| 5654 | + return hasUserPatterns || hasUserResources || hasSpacePatterns || hasSpaceResources || hasAuthorizedUserId; |
| 5655 | + } |
5627 | 5656 | function extractPermissions(permissions) {
|
5628 | 5657 | var permissionsResult = 0;
|
5629 |
| - /* eslint-disable */ |
5630 | 5658 | if (permissions.join) {
|
5631 | 5659 | permissionsResult |= 128;
|
5632 | 5660 | }
|
|
5648 | 5676 | if (permissions.read) {
|
5649 | 5677 | permissionsResult |= 1;
|
5650 | 5678 | }
|
5651 |
| - /* eslint-enable */ |
5652 | 5679 | return permissionsResult;
|
5653 | 5680 | }
|
5654 |
| - function prepareMessagePayload$2(modules, incomingParams) { |
| 5681 | + function prepareMessagePayloadVsp(_modules, _a) { |
| 5682 | + var ttl = _a.ttl, resources = _a.resources, patterns = _a.patterns, meta = _a.meta, authorizedUserId = _a.authorizedUserId; |
| 5683 | + var params = { |
| 5684 | + ttl: 0, |
| 5685 | + permissions: { |
| 5686 | + resources: { |
| 5687 | + channels: {}, |
| 5688 | + groups: {}, |
| 5689 | + uuids: {}, |
| 5690 | + users: {}, |
| 5691 | + spaces: {}, // not used, needed for api backward compatibility |
| 5692 | + }, |
| 5693 | + patterns: { |
| 5694 | + channels: {}, |
| 5695 | + groups: {}, |
| 5696 | + uuids: {}, |
| 5697 | + users: {}, |
| 5698 | + spaces: {}, // not used, needed for api backward compatibility |
| 5699 | + }, |
| 5700 | + meta: {}, |
| 5701 | + }, |
| 5702 | + }; |
| 5703 | + if (resources) { |
| 5704 | + var users_1 = resources.users, spaces_1 = resources.spaces, groups_1 = resources.groups; |
| 5705 | + if (users_1) { |
| 5706 | + Object.keys(users_1).forEach(function (userID) { |
| 5707 | + params.permissions.resources.uuids[userID] = extractPermissions(users_1[userID]); |
| 5708 | + }); |
| 5709 | + } |
| 5710 | + if (spaces_1) { |
| 5711 | + Object.keys(spaces_1).forEach(function (spaceId) { |
| 5712 | + params.permissions.resources.channels[spaceId] = extractPermissions(spaces_1[spaceId]); |
| 5713 | + }); |
| 5714 | + } |
| 5715 | + if (groups_1) { |
| 5716 | + Object.keys(groups_1).forEach(function (group) { |
| 5717 | + params.permissions.resources.groups[group] = extractPermissions(groups_1[group]); |
| 5718 | + }); |
| 5719 | + } |
| 5720 | + } |
| 5721 | + if (patterns) { |
| 5722 | + var users_2 = patterns.users, spaces_2 = patterns.spaces, groups_2 = patterns.groups; |
| 5723 | + if (users_2) { |
| 5724 | + Object.keys(users_2).forEach(function (userId) { |
| 5725 | + params.permissions.patterns.uuids[userId] = extractPermissions(users_2[userId]); |
| 5726 | + }); |
| 5727 | + } |
| 5728 | + if (spaces_2) { |
| 5729 | + Object.keys(spaces_2).forEach(function (spaceId) { |
| 5730 | + params.permissions.patterns.channels[spaceId] = extractPermissions(spaces_2[spaceId]); |
| 5731 | + }); |
| 5732 | + } |
| 5733 | + if (groups_2) { |
| 5734 | + Object.keys(groups_2).forEach(function (group) { |
| 5735 | + params.permissions.patterns.groups[group] = extractPermissions(groups_2[group]); |
| 5736 | + }); |
| 5737 | + } |
| 5738 | + } |
| 5739 | + if (ttl || ttl === 0) { |
| 5740 | + params.ttl = ttl; |
| 5741 | + } |
| 5742 | + if (meta) { |
| 5743 | + params.permissions.meta = meta; |
| 5744 | + } |
| 5745 | + if (authorizedUserId) { |
| 5746 | + params.permissions.uuid = "".concat(authorizedUserId); // ensure this is a string |
| 5747 | + } |
| 5748 | + return params; |
| 5749 | + } |
| 5750 | + function prepareMessagePayload$2(_modules, incomingParams) { |
| 5751 | + if (hasVspTerms(incomingParams)) { |
| 5752 | + return prepareMessagePayloadVsp(_modules, incomingParams); |
| 5753 | + } |
5655 | 5754 | var ttl = incomingParams.ttl, resources = incomingParams.resources, patterns = incomingParams.patterns, meta = incomingParams.meta, authorized_uuid = incomingParams.authorized_uuid;
|
5656 | 5755 | var params = {
|
5657 | 5756 | ttl: 0,
|
|
5674 | 5773 | },
|
5675 | 5774 | };
|
5676 | 5775 | if (resources) {
|
5677 |
| - var uuids_1 = resources.uuids, channels_1 = resources.channels, groups_1 = resources.groups; |
| 5776 | + var uuids_1 = resources.uuids, channels_1 = resources.channels, groups_3 = resources.groups; |
5678 | 5777 | if (uuids_1) {
|
5679 | 5778 | Object.keys(uuids_1).forEach(function (uuid) {
|
5680 | 5779 | params.permissions.resources.uuids[uuid] = extractPermissions(uuids_1[uuid]);
|
|
5685 | 5784 | params.permissions.resources.channels[channel] = extractPermissions(channels_1[channel]);
|
5686 | 5785 | });
|
5687 | 5786 | }
|
5688 |
| - if (groups_1) { |
5689 |
| - Object.keys(groups_1).forEach(function (group) { |
5690 |
| - params.permissions.resources.groups[group] = extractPermissions(groups_1[group]); |
| 5787 | + if (groups_3) { |
| 5788 | + Object.keys(groups_3).forEach(function (group) { |
| 5789 | + params.permissions.resources.groups[group] = extractPermissions(groups_3[group]); |
5691 | 5790 | });
|
5692 | 5791 | }
|
5693 | 5792 | }
|
5694 | 5793 | if (patterns) {
|
5695 |
| - var uuids_2 = patterns.uuids, channels_2 = patterns.channels, groups_2 = patterns.groups; |
| 5794 | + var uuids_2 = patterns.uuids, channels_2 = patterns.channels, groups_4 = patterns.groups; |
5696 | 5795 | if (uuids_2) {
|
5697 | 5796 | Object.keys(uuids_2).forEach(function (uuid) {
|
5698 | 5797 | params.permissions.patterns.uuids[uuid] = extractPermissions(uuids_2[uuid]);
|
|
5703 | 5802 | params.permissions.patterns.channels[channel] = extractPermissions(channels_2[channel]);
|
5704 | 5803 | });
|
5705 | 5804 | }
|
5706 |
| - if (groups_2) { |
5707 |
| - Object.keys(groups_2).forEach(function (group) { |
5708 |
| - params.permissions.patterns.groups[group] = extractPermissions(groups_2[group]); |
| 5805 | + if (groups_4) { |
| 5806 | + Object.keys(groups_4).forEach(function (group) { |
| 5807 | + params.permissions.patterns.groups[group] = extractPermissions(groups_4[group]); |
5709 | 5808 | });
|
5710 | 5809 | }
|
5711 | 5810 | }
|
|
5721 | 5820 | return params;
|
5722 | 5821 | }
|
5723 | 5822 | function validateParams$8(modules, incomingParams) {
|
| 5823 | + var _a, _b, _c, _d, _e, _f; |
5724 | 5824 | var config = modules.config;
|
5725 | 5825 | if (!config.subscribeKey)
|
5726 | 5826 | return 'Missing Subscribe Key';
|
|
5730 | 5830 | return 'Missing Secret Key';
|
5731 | 5831 | if (!incomingParams.resources && !incomingParams.patterns)
|
5732 | 5832 | return 'Missing either Resources or Patterns.';
|
| 5833 | + var hasAuthorizedUuid = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorized_uuid) !== undefined; |
| 5834 | + var hasUuidResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.uuids) !== undefined; |
| 5835 | + var hasChannelResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.channels) !== undefined; |
| 5836 | + var hasGroupResources = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _c === void 0 ? void 0 : _c.groups) !== undefined; |
| 5837 | + var hasUuidPatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.uuids) !== undefined; |
| 5838 | + var hasChannelPatterns = ((_e = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _e === void 0 ? void 0 : _e.channels) !== undefined; |
| 5839 | + var hasGroupPatterns = ((_f = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _f === void 0 ? void 0 : _f.groups) !== undefined; |
| 5840 | + var hasLegacyTerms = hasAuthorizedUuid || |
| 5841 | + hasUuidResources || |
| 5842 | + hasUuidPatterns || |
| 5843 | + hasChannelResources || |
| 5844 | + hasChannelPatterns || |
| 5845 | + hasGroupResources || |
| 5846 | + hasGroupPatterns; |
| 5847 | + if (hasVspTerms(incomingParams) && hasLegacyTerms) { |
| 5848 | + return ('Cannot mix `users`, `spaces` and `authorizedUserId` ' + |
| 5849 | + 'with `uuids`, `channels`, `groups` and `authorized_uuid`'); |
| 5850 | + } |
5733 | 5851 | if ((incomingParams.resources &&
|
5734 | 5852 | (!incomingParams.resources.uuids || Object.keys(incomingParams.resources.uuids).length === 0) &&
|
5735 | 5853 | (!incomingParams.resources.channels || Object.keys(incomingParams.resources.channels).length === 0) &&
|
5736 |
| - (!incomingParams.resources.groups || Object.keys(incomingParams.resources.groups).length === 0)) || |
| 5854 | + (!incomingParams.resources.groups || Object.keys(incomingParams.resources.groups).length === 0) && |
| 5855 | + (!incomingParams.resources.users || Object.keys(incomingParams.resources.users).length === 0) && |
| 5856 | + (!incomingParams.resources.spaces || Object.keys(incomingParams.resources.spaces).length === 0)) || |
5737 | 5857 | (incomingParams.patterns &&
|
5738 | 5858 | (!incomingParams.patterns.uuids || Object.keys(incomingParams.patterns.uuids).length === 0) &&
|
5739 | 5859 | (!incomingParams.patterns.channels || Object.keys(incomingParams.patterns.channels).length === 0) &&
|
5740 |
| - (!incomingParams.patterns.groups || Object.keys(incomingParams.patterns.groups).length === 0))) { |
| 5860 | + (!incomingParams.patterns.groups || Object.keys(incomingParams.patterns.groups).length === 0) && |
| 5861 | + (!incomingParams.patterns.users || Object.keys(incomingParams.patterns.users).length === 0) && |
| 5862 | + (!incomingParams.patterns.spaces || Object.keys(incomingParams.patterns.spaces).length === 0))) { |
5741 | 5863 | return 'Missing values for either Resources or Patterns.';
|
5742 | 5864 | }
|
5743 | 5865 | }
|
|
0 commit comments