@pusher/chatkit-server
Advanced tools
Comparing version 0.13.0 to 1.0.0
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
@@ -7,4 +8,36 @@ | ||
## [Unreleased](https://github.com/pusher/chatkit-server-node/compare/0.12.2...HEAD) | ||
## [Unreleased](https://github.com/pusher/chatkit-server-node/compare/1.0.0...HEAD) | ||
## [1.0.0](https://github.com/pusher/chatkit-server-node/compare/0.12.1...1.0.0) | ||
### Breaking Changes | ||
- room IDs are now strings | ||
- `getUsersByIds` is now `getUsersById` | ||
- `GetUsersByIdsOptions` is now `GetUsersByIdOptions` | ||
- Every mention of `roleName` is now just `name` | ||
### Nonbreaking Changes | ||
- `getRoom`, `getRooms` and `getRoomMessages` no longer require a `userId` | ||
- `getRooms` now takes `includePrivate` and `fromID` parameters for looking up private rooms and paginating by ID | ||
### Additions | ||
- The following new methods: | ||
- `getUser` | ||
- `sendMessage` | ||
- `deleteMessage` | ||
- `updateRoom` | ||
- `deleteRoom` | ||
- `addUsersToRoom` | ||
- `removeUsersFromRoom` | ||
- `setReadCursor` | ||
- `getReadCursor` | ||
- `getReadCursorsForUser` | ||
- `getReadCursorsForRoom` | ||
- `cursorsRequest` | ||
See the documentation for details on usage. | ||
## [0.12.2](https://github.com/pusher/chatkit-server-node/compare/0.12.1...0.12.2) - 2018-07-23 | ||
@@ -11,0 +44,0 @@ |
{ | ||
"name": "@pusher/chatkit-server", | ||
"description": "Pusher Chatkit server library", | ||
"version": "0.13.0", | ||
"version": "1.0.0", | ||
"main": "./target/index.js", | ||
@@ -13,5 +13,11 @@ "license": "MIT", | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"trailingComma": "all" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf lib target && tsc", | ||
"test": "echo Testing...\n", | ||
"test": "bash -c 'set -o pipefail; yarn test:build && yarn test:run | tap-colorize'", | ||
"test:build": "tsc -p tests", | ||
"test:run": "node tests/target/tests/main.js", | ||
"install-pkg": "if type yarn &> /dev/null; then yarn; else npm i; fi" | ||
@@ -21,10 +27,13 @@ }, | ||
"jsonwebtoken": "^8.3.0", | ||
"pusher-platform-node": "~0.13.0" | ||
"pusher-platform-node": "~0.14.1", | ||
"tap-colorize": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/tape": "^4.2.32", | ||
"babel-core": "^6.25.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"dts-bundle": "^0.7.3", | ||
"tape": "^4.9.1", | ||
"typescript": "^2.6.1" | ||
} | ||
} |
import { | ||
AuthenticationResponse, | ||
AuthenticateOptions, | ||
AuthenticatePayload, | ||
AuthenticationResponse, | ||
BaseClient, | ||
Instance, | ||
InstanceOptions, | ||
SDKInfo, | ||
TokenWithExpiry, | ||
@@ -12,2 +13,3 @@ } from 'pusher-platform-node'; | ||
import { getCurrentTimeInSeconds } from './utils'; | ||
import packageJSON from '../package.json'; | ||
@@ -23,9 +25,23 @@ export interface AuthenticationOptions { | ||
export interface GetRoomOptions extends UserIdOptions { | ||
roomId: number; | ||
export interface GetRoomOptions { | ||
roomId: string; | ||
} | ||
export interface SendMessageOptions extends UserIdOptions { | ||
roomId: string; | ||
text: string; | ||
attachment?: AttachmentOptions; | ||
} | ||
export interface AttachmentOptions { | ||
resourceLink: string; | ||
type: string; | ||
} | ||
export interface DeleteMessageOptions { | ||
id: string; | ||
} | ||
export interface DeleteUserOptions extends UserIdOptions {} | ||
export interface GetUserRoomOptions extends UserIdOptions {} | ||
export interface GetRoomsOptions extends UserIdOptions {} | ||
export interface GetUserJoinableRoomOptions extends UserIdOptions {} | ||
@@ -35,4 +51,18 @@ export interface GetUserRolesOptions extends UserIdOptions {} | ||
export interface GetRoomsOptions { | ||
fromId?: string; | ||
includePrivate?: boolean | ||
} | ||
export interface GetUserOptions { | ||
id: string; | ||
} | ||
export interface GetUsersOptions { | ||
fromTimestamp?: string; | ||
limit?: number; | ||
} | ||
export interface RemoveRoomRoleForUserOptions extends UserIdOptions { | ||
roomId: number; | ||
roomId: string; | ||
} | ||
@@ -42,3 +72,3 @@ | ||
userId: string; | ||
roleName: string; | ||
name: string; | ||
} | ||
@@ -49,7 +79,7 @@ | ||
export interface AssignRoleToUserOptions extends BasicAssignRoleToUserOptions { | ||
roomId?: number; | ||
roomId?: string; | ||
} | ||
export interface AssignRoomRoleToUserOptions extends BasicAssignRoleToUserOptions { | ||
roomId: number; | ||
roomId: string; | ||
} | ||
@@ -71,3 +101,3 @@ | ||
export interface UpdatePermissionsOptions { | ||
roleName: string; | ||
name: string; | ||
permissionsToAdd?: Array<string>; | ||
@@ -78,3 +108,3 @@ permissionsToRemove?: Array<string>; | ||
export interface GetPermissionsOptions { | ||
roleName: string; | ||
name: string; | ||
} | ||
@@ -103,7 +133,26 @@ | ||
export interface GetRoomMessagesOptions extends UserIdOptions { | ||
export interface SetReadCursorOptions { | ||
userId: string; | ||
roomId: string; | ||
position: number; | ||
} | ||
export interface GetReadCursorOptions { | ||
userId: string; | ||
roomId: string; | ||
} | ||
export interface GetReadCursorsForUserOptions { | ||
userId: string; | ||
} | ||
export interface GetReadCursorsForRoomOptions { | ||
roomId: string; | ||
} | ||
export interface GetRoomMessagesOptions { | ||
direction?: string; | ||
initialId?: string; | ||
limit?: number; | ||
roomId: number; | ||
roomId: string; | ||
} | ||
@@ -138,2 +187,22 @@ | ||
export interface UpdateRoomOptions { | ||
id: string; | ||
name?: string; | ||
isPrivate?: boolean; | ||
} | ||
export interface DeleteRoomOptions { | ||
id: string; | ||
} | ||
export interface AddUsersToRoomOptions { | ||
roomId: string; | ||
userIds: Array<string>; | ||
} | ||
export interface RemoveUsersFromRoomOptions { | ||
roomId: string; | ||
userIds: Array<string>; | ||
} | ||
export interface UpdateRolePermissionsOptions { | ||
@@ -148,3 +217,3 @@ add_permissions?: Array<string>; | ||
export interface GetUsersByIdsOptions { | ||
export interface GetUsersByIdOptions { | ||
userIds: Array<string>; | ||
@@ -165,2 +234,3 @@ } | ||
authorizerInstance: Instance; | ||
cursorsInstance: Instance; | ||
instanceLocator: string; | ||
@@ -173,3 +243,8 @@ | ||
const apiInstanceOptions = ({ | ||
const sdkInfo = new SDKInfo({ | ||
productName: 'chatkit', | ||
version: packageJSON.version, | ||
}); | ||
const instanceOptions = { | ||
locator: instanceLocator, | ||
@@ -180,19 +255,27 @@ key, | ||
client, | ||
sdkInfo, | ||
} | ||
const apiInstanceOptions = { | ||
...instanceOptions, | ||
serviceName: 'chatkit', | ||
serviceVersion: 'v2', | ||
}) | ||
} | ||
const authorizerInstanceOptions = ({ | ||
locator: instanceLocator, | ||
key, | ||
port, | ||
host, | ||
client, | ||
const authorizerInstanceOptions = { | ||
...instanceOptions, | ||
serviceName: 'chatkit_authorizer', | ||
serviceVersion: 'v1', | ||
}) | ||
serviceVersion: 'v2', | ||
} | ||
const cursorsInstanceOptions = { | ||
...instanceOptions, | ||
serviceName: 'chatkit_cursors', | ||
serviceVersion: 'v2', | ||
} | ||
this.instanceLocator = instanceLocator; | ||
this.apiInstance = new Instance(apiInstanceOptions); | ||
this.authorizerInstance = new Instance(authorizerInstanceOptions); | ||
this.cursorsInstance = new Instance(cursorsInstanceOptions); | ||
} | ||
@@ -293,6 +376,18 @@ | ||
getUsers(): Promise<any> { | ||
getUser(options: GetUserOptions): Promise<any> { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
path: `/users/${encodeURIComponent(options.id)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)) | ||
} | ||
getUsers(options: GetUsersOptions = {}): Promise<any> { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
path: `/users`, | ||
qs: { | ||
from_ts: options.fromTimestamp, | ||
limit: options.limit, | ||
}, | ||
jwt: this.getServerToken(), | ||
@@ -304,3 +399,3 @@ }).then((res) => { | ||
getUsersByIds(options: GetUsersByIdsOptions): Promise<any> { | ||
getUsersById(options: GetUsersByIdOptions): Promise<any> { | ||
return this.apiInstance.request({ | ||
@@ -310,4 +405,5 @@ method: 'GET', | ||
qs: { | ||
user_ids: options.userIds.join(','), | ||
id: options.userIds, | ||
}, | ||
useQuerystring: true, | ||
jwt: this.getServerToken(), | ||
@@ -324,3 +420,2 @@ }).then((res) => { | ||
su: true, | ||
userId: options.userId, | ||
}); | ||
@@ -330,3 +425,3 @@ | ||
method: 'GET', | ||
path: `/rooms/${options.roomId}`, | ||
path: `/rooms/${encodeURIComponent(options.roomId)}`, | ||
jwt: jwt.token, | ||
@@ -338,6 +433,34 @@ }).then((res) => { | ||
sendMessage(options: SendMessageOptions): Promise<any> { | ||
let messagePayload: any = { text: options.text }; | ||
if (options.attachment) { | ||
messagePayload.attachment = { | ||
resource_link: options.attachment.resourceLink, | ||
type: options.attachment.type, | ||
} | ||
} | ||
return this.apiInstance.request({ | ||
method: 'POST', | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/messages`, | ||
jwt: this.generateAccessToken({ | ||
su: true, | ||
userId: options.userId, | ||
}).token, | ||
body: messagePayload, | ||
}).then(({ body }) => JSON.parse(body)) | ||
} | ||
deleteMessage(options: DeleteMessageOptions): Promise<void> { | ||
return this.apiInstance.request({ | ||
method: 'DELETE', | ||
path: `/messages/${options.id}`, | ||
jwt: this.getServerToken(), | ||
}).then(() => {}) | ||
} | ||
getRoomMessages(options: GetRoomMessagesOptions): Promise<any> { | ||
const jwt = this.generateAccessToken({ | ||
su: true, | ||
userId: options.userId, | ||
}); | ||
@@ -351,3 +474,3 @@ | ||
method: 'GET', | ||
path: `/rooms/${options.roomId}/messages`, | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/messages`, | ||
jwt: jwt.token, | ||
@@ -360,12 +483,11 @@ qs: qs, | ||
getRooms(options: GetRoomsOptions): Promise<any> { | ||
const jwt = this.generateAccessToken({ | ||
su: true, | ||
userId: options.userId, | ||
}); | ||
getRooms(options: GetRoomsOptions = {}): Promise<any> { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
path: `/rooms`, | ||
jwt: jwt.token, | ||
jwt: this.getServerToken(), | ||
qs: { | ||
from_id: options.fromId, | ||
include_private: options.includePrivate, | ||
} | ||
}).then((res) => { | ||
@@ -434,2 +556,45 @@ return JSON.parse(res.body); | ||
updateRoom(options: UpdateRoomOptions): Promise<void> { | ||
const body: any = {} | ||
if (options.name) { | ||
body.name = options.name | ||
} | ||
if (options.isPrivate) { | ||
body.private = options.isPrivate | ||
} | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
path: `/rooms/${options.id}`, | ||
jwt: this.getServerToken(), | ||
body, | ||
}).then(() => {}) | ||
} | ||
deleteRoom(options: DeleteRoomOptions): Promise<void> { | ||
return this.apiInstance.request({ | ||
method: 'DELETE', | ||
path: `/rooms/${options.id}`, | ||
jwt: this.getServerToken(), | ||
}).then(() => {}) | ||
} | ||
addUsersToRoom(options: AddUsersToRoomOptions): Promise<void> { | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/users/add`, | ||
jwt: this.getServerToken(), | ||
body: { user_ids: options.userIds }, | ||
}).then(() => {}) | ||
} | ||
removeUsersFromRoom(options: RemoveUsersFromRoomOptions): Promise<void> { | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/users/remove`, | ||
jwt: this.getServerToken(), | ||
body: { user_ids: options.userIds }, | ||
}).then(() => {}) | ||
} | ||
// Authorizer interactions | ||
@@ -494,3 +659,3 @@ | ||
}, | ||
body: { name: options.roleName, room_id: options.roomId }, | ||
body: { name: options.name, room_id: options.roomId }, | ||
jwt: this.getServerToken(), | ||
@@ -536,3 +701,3 @@ }).then(() => {}) | ||
method: 'GET', | ||
path: `/roles/${options.roleName}/scope/global/permissions`, | ||
path: `/roles/${options.name}/scope/global/permissions`, | ||
jwt: this.getServerToken(), | ||
@@ -547,3 +712,3 @@ }).then((res) => { | ||
method: 'GET', | ||
path: `/roles/${options.roleName}/scope/room/permissions`, | ||
path: `/roles/${options.name}/scope/room/permissions`, | ||
jwt: this.getServerToken(), | ||
@@ -557,3 +722,3 @@ }).then((res) => { | ||
return this.updatePermissionsForRole( | ||
options.roleName, | ||
options.name, | ||
'global', | ||
@@ -567,3 +732,3 @@ options.permissionsToAdd || [], | ||
return this.updatePermissionsForRole( | ||
options.roleName, | ||
options.name, | ||
'room', | ||
@@ -585,3 +750,37 @@ options.permissionsToAdd || [], | ||
// Cursors | ||
setReadCursor(options: SetReadCursorOptions): Promise<void> { | ||
return this.cursorsInstance.request({ | ||
method: 'PUT', | ||
path: `/cursors/0/rooms/${encodeURIComponent(options.roomId)}/users/${encodeURIComponent(options.userId)}`, | ||
body: { position: options.position }, | ||
jwt: this.getServerToken(), | ||
}).then(() => {}) | ||
} | ||
getReadCursor(options: GetReadCursorOptions): Promise<any> { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
path: `/cursors/0/rooms/${encodeURIComponent(options.roomId)}/users/${encodeURIComponent(options.userId)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)) | ||
} | ||
getReadCursorsForUser(options: GetReadCursorsForUserOptions): Promise<any> { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
path: `/cursors/0/users/${encodeURIComponent(options.userId)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)) | ||
} | ||
getReadCursorsForRoom(options: GetReadCursorsForRoomOptions): Promise<any> { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
path: `/cursors/0/rooms/${encodeURIComponent(options.roomId)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)) | ||
} | ||
// General requests | ||
@@ -596,9 +795,12 @@ | ||
options.jwt = options.jwt || this.getServerToken(); | ||
return this.authorizerInstance.request(options).then((res) => { | ||
return JSON.parse(res.body); | ||
}); | ||
return this.authorizerInstance.request(options); | ||
} | ||
cursorsRequest(options: GeneralRequestOptions): Promise<any> { | ||
options.jwt = options.jwt || this.getServerToken(); | ||
return this.cursorsInstance.request(options); | ||
} | ||
private updatePermissionsForRole( | ||
roleName: string, | ||
name: string, | ||
scope: string, | ||
@@ -623,3 +825,3 @@ permissionsToadd: Array<string> = [], | ||
method: 'PUT', | ||
path: `/roles/${roleName}/scope/${scope}/permissions`, | ||
path: `/roles/${name}/scope/${scope}/permissions`, | ||
headers: { | ||
@@ -626,0 +828,0 @@ 'Content-Type': 'application/json' |
{ | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"target": "ES6", | ||
"sourceMap": true, | ||
"module": "commonjs", | ||
"declaration": true , | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"declaration": true, | ||
"outDir": "target", | ||
@@ -8,0 +10,0 @@ "strict": true |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
302123
41
4517
0
1
3
6
8
1
+ Addedtap-colorize@^1.2.0
+ Addedcolornames@0.0.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedduplexer@0.1.2(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedminimist@0.2.4(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedpusher-platform-node@0.14.1(transitive)
+ Addedquotemeta@0.0.0(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedsplit@0.3.3(transitive)
+ Addedstream-combiner@0.2.2(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedtap-colorize@1.2.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedthrough2@1.0.0(transitive)
+ Addedx256@0.0.2(transitive)
+ Addedxtend@2.1.2(transitive)
- Removedpusher-platform-node@0.13.2(transitive)
Updatedpusher-platform-node@~0.14.1