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
34 changes: 17 additions & 17 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7049,31 +7049,31 @@
const parsedVersion = metadata.classVersion !== undefined ? Number.parseInt(`${metadata.classVersion}`, 10) : NaN;
const classVersion = Number.isNaN(parsedVersion) ? undefined : parsedVersion;
const raw = ((_a = payload.data) !== null && _a !== void 0 ? _a : {});
// `data` mirrors the object as sent by the service; class identity is reported once, on the event.
let data;
// Class identity is reported once, on the event, so it is shared by every event shape.
const common = {
version: payload.version,
source: metadata.source,
type: metadata.type,
className,
classLevel,
classVersion,
};
// `data` mirrors the object as sent by the service, and its shape is tied to `event` /
// `objectType` — which is what makes `message` a discriminated union for the consumer.
let message;
if (metadata.event === 'delete')
data = { id: raw.id, deletedAt: raw.deletedAt };
message = Object.assign(Object.assign({}, common), { event: metadata.event, objectType, data: { id: raw.id, deletedAt: raw.deletedAt } });
else if (objectType === 'membership')
data = Object.assign({}, raw);
message = Object.assign(Object.assign({}, common), { event: metadata.event, objectType, data: Object.assign({}, raw) });
else if (objectType === 'relationship')
data = Object.assign({}, raw);
message = Object.assign(Object.assign({}, common), { event: metadata.event, objectType, data: Object.assign({}, raw) });
else
data = Object.assign({}, raw);
message = Object.assign(Object.assign({}, common), { event: metadata.event, objectType, data: Object.assign({}, raw) });
return {
channel,
subscription,
timetoken: envelope.p.t,
message: {
version: payload.version,
event: metadata.event,
source: metadata.source,
type: metadata.type,
objectType,
className,
classLevel,
classVersion,
data,
},
message,
};
}
fileFromEnvelope(envelope) {
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions docs-snippets/access-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,107 @@ try {
}
// snippet.end

// snippet.grantTokenDataSyncResources
// Grants `user-alice`:
// - Get access to the entity `product-sneaker-42`, and to all entities matching the
// `product-.*` RegEx pattern.
// - Get access to the DataSync user `user-bob` through the top-level `users` scope, because
// DataSync users are not permissioned under `dataSync`.
try {
const token = await pubnub.grantToken({
ttl: 15,
authorized_uuid: 'user-alice',
resources: {
users: {
'user-bob': {
get: true,
},
},
dataSync: {
entities: {
'product-sneaker-42': {
get: true,
},
},
},
},
patterns: {
dataSync: {
entities: {
'product-.*': {
get: true,
},
},
},
},
});
console.log('Granted Token:', token);
} catch (error) {
console.error(
`Grant token error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
}
// snippet.end

// snippet.grantTokenWithProjection
// Grants `user-alice` the same access as above and assigns the `public` projection to the entity
// `product-sneaker-42` and to the user `user-bob`. With those projections, Alice reads and writes
// only the fields that the `public` projection exposes on each object.
try {
const token = await pubnub.grantToken({
ttl: 15,
authorized_uuid: 'user-alice',
resources: {
users: {
'user-bob': {
get: true,
},
},
dataSync: {
entities: {
'product-sneaker-42': {
get: true,
},
},
},
},
patterns: {
dataSync: {
entities: {
'product-.*': {
get: true,
},
},
},
},
dataSyncProjections: {
resources: {
entities: {
'product-sneaker-42': 'public',
},
users: {
'user-bob': 'public',
},
},
patterns: {
entities: {
'product-.*': 'public',
},
},
},
});
console.log('Granted Token:', token);
} catch (error) {
console.error(
`Grant token error: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);
}
// snippet.end

// snippet.grantTokenRegExAndResources
try {
const token = await pubnub.grantToken({
Expand Down
Loading
Loading