Skip to content

Conversation

@mohitpubnub
Copy link
Contributor

@mohitpubnub mohitpubnub commented Jun 10, 2025

refactor: removed deprecation warning from deleteMessages method.

Removed deprecation warning from deleteMessages method.

docs: code snippets for using pubnub apis.

Added code snippets for docs.

Mohit Tejani added 2 commits June 10, 2025 17:21
…pp-context, mobile-push, access-manager, channel-groups.
@mohitpubnub mohitpubnub self-assigned this Jun 10, 2025
@mohitpubnub mohitpubnub added the status: in progress This issue is being worked on. label Jun 10, 2025
@pubnub-ops-terraform
Copy link

pubnub-ops-terraform commented Jun 10, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@mohitpubnub mohitpubnub marked this pull request as ready for review June 15, 2025 17:12
@mohitpubnub mohitpubnub removed the status: in progress This issue is being worked on. label Jun 16, 2025
@mohitpubnub mohitpubnub added the status: in progress This issue is being worked on. label Jun 23, 2025
Copy link
Contributor

@parfeon parfeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In each file (and sometimes even within the same file) there is a different indention level (or different tab width). Our codebase uses 2 spaces for tab.

I'm leaving early review comments because new files appeared while I was making this one and probably have similar issues + my browser lags with this much change suggestions.

*/
public grantToken(parameters: PAM.GrantTokenParameters, callback: ResultCallback<PAM.GrantTokenResponse>): void;
public grantToken(
parameters: PAM.GrantTokenParameters | PAM.ObjectsGrantTokenParameters,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to have ObjectsGrantTokenParameters? Probably it has been added because I forgot to mark it as deprecated since it uses spaces and users while the new interface uses uuids and confusingly channels (which both regular and App Context metadata).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

"compilerOptions": {
"module": "esnext",
"target": "es2017",
"outDir": "./docs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be careful here because during the release process run all changes added to the git. Should we add the docs folder to the .gitignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since
"noEmit": true,

It won't generate any js files on tsc.

Comment on lines 48 to 50
} catch (status) {
console.log(status);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive error in catch blocks, not status. Though this one is PubNubError which has a status field with State object in it with additional details, so maybe something like this:

Suggested change
} catch (status) {
console.log(status);
}
} catch (error) {
console.error(`Grant token error: ${error}.${
error.status ? ` Additional information: ${error.status}` : '' }`);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all error handling updated as per suggestion.

Comment on lines 66 to 68
} catch (status) {
console.log(status);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive error in catch blocks, not status. Though this one is PubNubError which has a status field with State object in it with additional details, so maybe something like this:

Suggested change
} catch (status) {
console.log(status);
}
} catch (error) {
console.error(`Grant token error: ${error}.${
error.status ? ` Additional information: ${error.status}` : '' }`);
}

Comment on lines 117 to 119
} catch (status) {
console.log(status);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive error in catch blocks, not status. Though this one is PubNubError which has a status field with State object in it with additional details, so maybe something like this:

Suggested change
} catch (status) {
console.log(status);
}
} catch (error) {
console.error(`Grant token error: ${error}.${
error.status ? ` Additional information: ${error.status}` : '' }`);
}

Comment on lines 22 to 24
} catch (status) {
console.log(`publishing failed with status: ${status}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive error in catch blocks, not status. Though this one is PubNubError which has a status field with State object in it with additional details, so maybe something like this:

Suggested change
} catch (status) {
console.log(`publishing failed with status: ${status}`);
}
} catch (error) {
console.error(`Message publish error: ${error}.${
error.status ? ` Additional information: ${error.status}` : '' }`);
}

Comment on lines 53 to 55
} catch (error) {
console.error(error);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PubNubError has a status field with State object in it with additional details, so maybe something like this:

Suggested change
} catch (error) {
console.error(error);
}
} catch (error) {
console.error(`Set channel metadata error: ${error}.${
error.status ? ` Additional information: ${error.status}` : '' }`);
}

// Using UUID from the config - default when uuid is not passed in the method
try {
const response = await pubnub.objects.getUUIDMetadata();
console.log(`getUUIDMetadata response: ${response}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give output like this:

getUUIDMetadata response: [object Object]

not really informative.
But it could be better this way:

Suggested change
console.log(`getUUIDMetadata response: ${response}`);
console.log('getUUIDMetadata response:', response);

const response = await pubnub.objects.getAllChannelMetadata({
filter: 'name LIKE "*Team"',
});
console.log(`getAllChannelMetadata response: ${response}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give output like this:

getAllChannelMetadata response: [object Object]

not really informative.
But it could be better this way:

Suggested change
console.log(`getAllChannelMetadata response: ${response}`);
console.log('getAllChannelMetadata response:', response);

Copy link
Contributor Author

@mohitpubnub mohitpubnub Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All response output updated.

const response = await pubnub.objects.setMemberships({
uuid: "my-uuid",
channels: [
"my-channel",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the formatter really align this line that far and not four spaces from the channels work start on the previous line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied formatting to all files.

Not sure why, I see sometimes git doesn't show the same indentation as I see in my IDE!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration is 2 spaces Tab.

@mohitpubnub mohitpubnub requested a review from parfeon June 25, 2025 13:12
@mohitpubnub mohitpubnub added status: done This issue is considered resolved. and removed status: in progress This issue is being worked on. labels Jun 26, 2025
const decrypted = pubnub.decrypt(encrypted); // Pass the encrypted data as the first parameter in decrypt Method
// snippet.end

// snippet.decryptFileBasicUsage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// snippet.decryptFileBasicUsage
// snippet.decryptFileBasicUsage
// Node.js example
// import fs from 'fs';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// snippet.end

// snippet.setProxyBasicUsage
pubnub.setProxy({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention here that this is only Node.js stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in docs already here.

Still no harm adding into example again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment.


// snippet.addDeciveToChannelBasicUsage
// Function to add a device to a channel for APNs2
async function addDeviceToChannelAPNs2() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we don't need functions (there were few before this file as well).

console.log('Operation done for APNs2!');
console.log('Response:', result);
} catch (error) {
console.log('Operation failed with error for APNs2:', error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to have similar output as in snippets above?

In previous review summary, I've left, that because new files appeared I've stopped. Same issues as I marked in previous files were in the rest (status in catch block instead of error and more detailed output).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanning files which did not have comments earlier ⏳

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log(response);
})
.catch((error) => {
console.log(error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want more detailed output here like this:

Suggested change
console.log(error);
console.error(
`State set failed: ${error}.${
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
}`,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in presence.ts

);
}
// snippet.end
// *********** Compilation Error due to wrong code *****************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this one in final document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines 27 to 29
console.log(`hereNow response: ${response}`);
} catch (status) {
console.log(`hereNow failed with error: ${status}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issues in this file as in previous with how object will be printed in formatted string and status instead of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

covered in presence.ts file

Comment on lines 18 to 20
console.log(`fetch messages response: ${response}`);
} catch (status) {
console.log(`fetch messages failed with error: ${status}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issues in this file as in previous with how object will be printed in formatted string and status instead of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log(`Message published with timetoken: ${result.timetoken}`);
console.log(`You: ${text}`);
} catch (error) {
console.error(`Publish failed: ${error}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More detailed output with status?

if (event.category === 'PNConnectedCategory') {
console.log('Connected to PubNub chat!');
} else if (event.category === 'PNNetworkIssuesCategory') {
console.log('Connection lost. Attempting to reconnect...');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one depending on from settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description updated

@mohitpubnub mohitpubnub removed the status: done This issue is considered resolved. label Jun 26, 2025
@mohitpubnub mohitpubnub requested a review from parfeon June 27, 2025 05:57
@mohitpubnub mohitpubnub added the status: done This issue is considered resolved. label Jun 27, 2025
Copy link
Contributor

@parfeon parfeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note, but in general looks good! :)

console.log(`\nMessage sent successfully!`);
} catch (error) {
// Handle publish errors
console.error(`\n❌ Failed to send message: ${error}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add more info :)

@mohitpubnub
Copy link
Contributor Author

@pubnub-release-bot release

@mohitpubnub mohitpubnub merged commit 8bf31a4 into master Jun 30, 2025
11 of 13 checks passed
@mohitpubnub mohitpubnub deleted the docs-snippets branch June 30, 2025 06:06
@pubnub-release-bot
Copy link
Contributor

🚀 Release successfully completed 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: done This issue is considered resolved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants