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

Preliminary If-Match ETag support for User and Channel #432

Merged
merged 4 commits into from
Jan 21, 2025
Merged
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
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2025-01-21
version: v8.6.0
changes:
- type: feature
text: "A new optional parameter `ifMatchesEtag` is added to `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the ETag on the server and if they don't match a HTTP 412 error is returned."
- date: 2025-01-15
version: v8.5.0
changes:
Expand Down Expand Up @@ -1106,7 +1111,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '8.5.0'
version: '8.6.0'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1122,7 +1127,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.5.0.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v8.6.0.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -1793,7 +1798,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v8.5.0/pubnub.8.5.0.js
location: https://github.com/pubnub/javascript/releases/download/v8.6.0/pubnub.8.6.0.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v8.6.0
January 21 2025

#### Added
- A new optional parameter `ifMatchesEtag` is added to `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the ETag on the server and if they don't match a HTTP 412 error is returned.

## v8.5.0
January 15 2025

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.min.js

2. Configure your keys:

Expand Down
18 changes: 17 additions & 1 deletion dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3974,7 +3974,7 @@
return base.PubNubFile;
},
get version() {
return '8.5.0';
return '8.6.0';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -11553,6 +11553,14 @@
if (!this.parameters.data)
return 'Data cannot be empty';
}
get headers() {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
}
else {
return undefined;
}
}
parse(response) {
return __awaiter(this, void 0, void 0, function* () {
const serviceResponse = this.deserializeResponse(response);
Expand Down Expand Up @@ -11972,6 +11980,14 @@
if (!this.parameters.data)
return 'Data cannot be empty';
}
get headers() {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
}
else {
return undefined;
}
}
parse(response) {
return __awaiter(this, void 0, void 0, function* () {
const serviceResponse = this.deserializeResponse(response);
Expand Down
2 changes: 1 addition & 1 deletion dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
return base.PubNubFile;
},
get version() {
return '8.5.0';
return '8.6.0';
},
getVersion() {
return this.version;
Expand Down
8 changes: 8 additions & 0 deletions lib/core/endpoints/objects/channel/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class SetChannelMetadataRequest extends request_1.AbstractRequest {
if (!this.parameters.data)
return 'Data cannot be empty';
}
get headers() {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
}
else {
return undefined;
}
}
parse(response) {
return __awaiter(this, void 0, void 0, function* () {
const serviceResponse = this.deserializeResponse(response);
Expand Down
8 changes: 8 additions & 0 deletions lib/core/endpoints/objects/uuid/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class SetUUIDMetadataRequest extends request_1.AbstractRequest {
if (!this.parameters.data)
return 'Data cannot be empty';
}
get headers() {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
}
else {
return undefined;
}
}
parse(response) {
return __awaiter(this, void 0, void 0, function* () {
const serviceResponse = this.deserializeResponse(response);
Expand Down
10 changes: 10 additions & 0 deletions lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,11 @@ declare namespace PubNub {
* Fields which can be additionally included into response.
*/
include?: Omit<IncludeOptions, 'totalCount'>;
/**
* Optional entity tag from a previously received `PNUUIDMetadata`. The request
* will fail if this parameter is specified and the ETag value on the server doesn't match.
*/
ifMatchesEtag?: string;
};

/**
Expand Down Expand Up @@ -5752,6 +5757,11 @@ declare namespace PubNub {
* Fields which can be additionally included into response.
*/
include?: Omit<IncludeOptions, 'totalCount'>;
/**
* Optional entity tag from a previously received `PNUUIDMetadata`. The request
* will fail if this parameter is specified and the ETag value on the server doesn't match.
*/
ifMatchesEtag?: string;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "8.5.0",
"version": "8.6.0",
"author": "PubNub <[email protected]>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const makeConfiguration = (
return base.PubNubFile;
},
get version(): string {
return '8.5.0';
return '8.6.0';
},
getVersion(): string {
return this.version;
Expand Down
8 changes: 8 additions & 0 deletions src/core/endpoints/objects/channel/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export class SetChannelMetadataRequest<
if (!this.parameters.data) return 'Data cannot be empty';
}

protected get headers(): Record<string, string> | undefined {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
} else {
return undefined;
}
}

async parse(response: TransportResponse): Promise<Response> {
const serviceResponse = this.deserializeResponse<Response>(response);

Expand Down
8 changes: 8 additions & 0 deletions src/core/endpoints/objects/uuid/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export class SetUUIDMetadataRequest<
if (!this.parameters.data) return 'Data cannot be empty';
}

protected get headers(): Record<string, string> | undefined {
if (this.parameters.ifMatchesEtag) {
return { 'If-Match': this.parameters.ifMatchesEtag };
} else {
return undefined;
}
}

async parse(response: TransportResponse): Promise<Response> {
const serviceResponse = this.deserializeResponse<Response>(response);

Expand Down
12 changes: 12 additions & 0 deletions src/core/types/api/app-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ export type SetUUIDMetadataParameters<Custom extends CustomData> = {
* Fields which can be additionally included into response.
*/
include?: Omit<IncludeOptions, 'totalCount'>;

/**
* Optional entity tag from a previously received `PNUUIDMetadata`. The request
* will fail if this parameter is specified and the ETag value on the server doesn't match.
*/
ifMatchesEtag?: string;
};

/**
Expand Down Expand Up @@ -827,6 +833,12 @@ export type SetChannelMetadataParameters<Custom extends CustomData> = {
* Fields which can be additionally included into response.
*/
include?: Omit<IncludeOptions, 'totalCount'>;

/**
* Optional entity tag from a previously received `PNUUIDMetadata`. The request
* will fail if this parameter is specified and the ETag value on the server doesn't match.
*/
ifMatchesEtag?: string;
};

/**
Expand Down
Loading