Skip to content

feat/dataSync#494

Draft
mohitpubnub wants to merge 4 commits intomasterfrom
CLEN-3287
Draft

feat/dataSync#494
mohitpubnub wants to merge 4 commits intomasterfrom
CLEN-3287

Conversation

@mohitpubnub
Copy link
Copy Markdown
Contributor

@mohitpubnub mohitpubnub commented Mar 30, 2026

initial code readiness for dataSync apis

Summary by CodeRabbit

  • New Features

    • Added support for PUT HTTP method in request operations, enabling request body and form data handling
    • Improved error message formatting to parse structured error responses and display detailed error information
  • Chores

    • Configured automated code review settings with specialized guidelines for different code areas

@pubnub-ops-terraform
Copy link
Copy Markdown

pubnub-ops-terraform commented Mar 30, 2026

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

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mohitpubnub mohitpubnub self-assigned this Mar 30, 2026
@mohitpubnub mohitpubnub added status: in progress This issue is being worked on. priority: low This PR should be reviewed after all high and medium PRs. type: feature This PR contains new feature. type: refactor This PR contains refactored existing features. labels Mar 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'path_filters'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

Adds CodeRabbit configuration file for automated code review with targeted path-based guidelines. Extends the HTTP request handling to support PUT method alongside existing POST and PATCH. Enhances error parsing to recognize and format DataSync-style structured error responses containing error arrays.

Changes

Cohort / File(s) Summary
Configuration
.coderabbit.yaml
New repository configuration enabling automated code review with language, draft PR handling, GitHub checks integration, and path-specific review guidelines for core SDK, REST endpoints, types, event-engine, entity listeners, transport, and platform implementations.
Transport Method Support
src/core/types/transport-request.ts, src/core/components/request.ts
Added PUT enum member to TransportMethod and extended AbstractRequest.request() to set request body/formData for PUT in addition to existing POST and PATCH support.
Error Handling
src/errors/pubnub-api-error.ts
Enhanced createFromServiceResponse() to parse DataSync-style structured error responses with errors array, storing full response in errorData and concatenating error codes and messages. Added new public method toFormattedMessage(operation: RequestOperation) to format error messages with operation context.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'feat/dataSync' is partially related to the changeset but is overly vague and uses a branch-naming convention rather than conveying meaningful details about the main changes. Revise the title to clearly describe the primary changes (e.g., 'Add DataSync API support with PUT request handling and error parsing' or similar) to help reviewers understand the scope at a glance.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CLEN-3287

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/core/components/request.ts (1)

173-180: Consider updating the JSDoc to include PUT.

The JSDoc comment mentions POST or PATCH but the body is now also sent with PUT requests.

Proposed fix
   /**
    * Target REST API Request body payload getter.
    *
-   * `@returns` Buffer of stringified data which should be sent with `POST` or `PATCH` request.
+   * `@returns` Buffer of stringified data which should be sent with `POST`, `PATCH`, or `PUT` request.
    */
   protected get body(): ArrayBuffer | PubNubFileInterface | string | undefined {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/components/request.ts` around lines 173 - 180, Update the JSDoc for
the protected getter body in the Request class (the get body(): ArrayBuffer |
PubNubFileInterface | string | undefined) to state that the returned
Buffer/string is used for POST, PATCH, and PUT requests; modify the comment text
to explicitly include PUT alongside POST and PATCH so the doc accurately
reflects where the body is sent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.coderabbit.yaml:
- Around line 5-7: The reviews block contains a misplaced property: remove the
top-level drafts entry under reviews (the stray "drafts: true" currently
directly beneath the reviews key) and rely on the existing drafts setting under
reviews.auto_review (auto_review.drafts) instead; specifically delete the
reviews-level "drafts" property so only reviews.auto_review.drafts remains.

In `@src/core/types/transport-request.ts`:
- Around line 22-25: The signature middleware currently only includes request
bodies for POST and PATCH when computing the signature, causing PUT bodies to be
omitted; update the method-check in the signature calculation (the conditional
that compares method to TransportMethod.POST / TransportMethod.PATCH) to also
include TransportMethod.PUT so that requests where method ===
TransportMethod.PUT include the body in the signature input.

In `@src/errors/pubnub-api-error.ts`:
- Around line 146-169: When building the message from the DataSync-style errors
(the block that reads errorResponse.errors and sets message), skip error items
that have neither errorCode nor message so you don't produce empty tokens;
specifically, update the logic around errors (the const errors = ... and the
subsequent message = errors.map(...).join(...)) to either filter out mapped
parts that are empty or filter out error objects where both e.errorCode and
e.message are falsy before mapping, and then join the remaining non-empty
strings into message while leaving errorData assignment unchanged.

---

Nitpick comments:
In `@src/core/components/request.ts`:
- Around line 173-180: Update the JSDoc for the protected getter body in the
Request class (the get body(): ArrayBuffer | PubNubFileInterface | string |
undefined) to state that the returned Buffer/string is used for POST, PATCH, and
PUT requests; modify the comment text to explicitly include PUT alongside POST
and PATCH so the doc accurately reflects where the body is sent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3f679b7e-746a-4687-9eb1-d5419055588d

📥 Commits

Reviewing files that changed from the base of the PR and between 8da3dca and cd73f80.

📒 Files selected for processing (4)
  • .coderabbit.yaml
  • src/core/components/request.ts
  • src/core/types/transport-request.ts
  • src/errors/pubnub-api-error.ts

Comment on lines +5 to +7
reviews:
# Review draft PRs so we get early feedback
drafts: true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Misplaced drafts property at the reviews level.

According to the CodeRabbit configuration schema, the drafts property belongs under reviews.auto_review.drafts, not directly under reviews. The schema specifies "additionalProperties": false for the reviews object, so this property will be ignored.

Since you already have drafts: true correctly placed under auto_review (line 21), you can safely remove line 7.

Proposed fix
 reviews:
-  # Review draft PRs so we get early feedback
-  drafts: true
-
   # Enable high-level summary of changes
   high_level_summary: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
reviews:
# Review draft PRs so we get early feedback
drafts: true
reviews:
# Enable high-level summary of changes
high_level_summary: true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.coderabbit.yaml around lines 5 - 7, The reviews block contains a misplaced
property: remove the top-level drafts entry under reviews (the stray "drafts:
true" currently directly beneath the reviews key) and rely on the existing
drafts setting under reviews.auto_review (auto_review.drafts) instead;
specifically delete the reviews-level "drafts" property so only
reviews.auto_review.drafts remains.

Comment on lines +22 to +25
/**
* Request will be sent using `PUT` method.
*/
PUT = 'PUT',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check signature method in middleware.ts for PUT handling

rg -n -A 15 'signature\(req: TransportRequest\)' src/transport/

Repository: pubnub/javascript

Length of output: 1212


Signature calculation must include PUT request bodies to prevent authentication failures.

The PUT enum addition is correct, but the signature middleware at src/transport/middleware.ts:69-80 only includes request body in signature calculation for POST and PATCH methods. PUT requests with bodies will have their body excluded from the signature input, causing authentication validation failures.

Update the condition to include TransportMethod.PUT:

if (method === TransportMethod.POST || method === TransportMethod.PATCH || method === TransportMethod.PUT) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/types/transport-request.ts` around lines 22 - 25, The signature
middleware currently only includes request bodies for POST and PATCH when
computing the signature, causing PUT bodies to be omitted; update the
method-check in the signature calculation (the conditional that compares method
to TransportMethod.POST / TransportMethod.PATCH) to also include
TransportMethod.PUT so that requests where method === TransportMethod.PUT
include the body in the signature input.

Comment on lines +146 to 169
} else if (
'errors' in errorResponse &&
Array.isArray(errorResponse.errors) &&
errorResponse.errors.length > 0
) {
// Handle DataSync-style structured error responses:
// { errors: [{ errorCode: "SYN-0008", message: "...", path: "/id" }] }
errorData = errorResponse;

const errors = errorResponse.errors as Array<{
errorCode?: string;
message?: string;
path?: string;
}>;

message = errors
.map((e) => {
const parts: string[] = [];
if (e.errorCode) parts.push(e.errorCode);
if (e.message) parts.push(e.message);
return parts.join(': ');
})
.join('; ');
} else errorData = errorResponse;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle edge case where error items lack both errorCode and message.

If all items in the errors array have only path (no errorCode or message), the resulting message would be empty strings joined by '; ', producing unhelpful output like "; " or an empty string.

Consider filtering out empty results:

Proposed fix
                 message = errors
                   .map((e) => {
                     const parts: string[] = [];
                     if (e.errorCode) parts.push(e.errorCode);
                     if (e.message) parts.push(e.message);
                     return parts.join(': ');
                   })
+                  .filter((s) => s.length > 0)
                   .join('; ');
+
+                if (!message) message = 'Unknown error';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/errors/pubnub-api-error.ts` around lines 146 - 169, When building the
message from the DataSync-style errors (the block that reads
errorResponse.errors and sets message), skip error items that have neither
errorCode nor message so you don't produce empty tokens; specifically, update
the logic around errors (the const errors = ... and the subsequent message =
errors.map(...).join(...)) to either filter out mapped parts that are empty or
filter out error objects where both e.errorCode and e.message are falsy before
mapping, and then join the remaining non-empty strings into message while
leaving errorData assignment unchanged.

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

Labels

priority: low This PR should be reviewed after all high and medium PRs. status: in progress This issue is being worked on. type: feature This PR contains new feature. type: refactor This PR contains refactored existing features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants