@pusher/chatkit-server
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -8,4 +8,11 @@ # Changelog | ||
## [Unreleased](https://github.com/pusher/chatkit-server-node/compare/1.0.5...HEAD) | ||
## [Unreleased](https://github.com/pusher/chatkit-server-node/compare/1.1.0...HEAD) | ||
## [1.1.0](https://github.com/pusher/chatkit-server-node/compare/1.0.6...1.1.0) | ||
### Changes | ||
- Multipart message support: `sendSimpleMessage`, `sendMultipartMessage`, | ||
`fetchMultipartMessages` all deal in the multipart message format. | ||
## [1.0.6](https://github.com/pusher/chatkit-server-node/compare/1.0.5...1.0.6) | ||
@@ -12,0 +19,0 @@ |
{ | ||
"name": "@pusher/chatkit-server", | ||
"description": "Pusher Chatkit server SDK", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"main": "target/src/index.js", | ||
@@ -29,2 +29,4 @@ "license": "MIT", | ||
"@pusher/platform-node": "~0.15.0", | ||
"@types/got": "^9.4.0", | ||
"got": "^9.6.0", | ||
"jsonwebtoken": "^8.3.0" | ||
@@ -31,0 +33,0 @@ }, |
{ | ||
"name": "@pusher/chatkit-server", | ||
"description": "Pusher Chatkit server SDK", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"main": "target/src/index.js", | ||
@@ -29,2 +29,4 @@ "license": "MIT", | ||
"@pusher/platform-node": "~0.15.0", | ||
"@types/got": "^9.4.0", | ||
"got": "^9.6.0", | ||
"jsonwebtoken": "^8.3.0" | ||
@@ -31,0 +33,0 @@ }, |
@@ -1,2 +0,3 @@ | ||
import { AuthenticateOptions, AuthenticatePayload, AuthenticationResponse, BaseClient, Instance, TokenWithExpiry } from '@pusher/platform-node'; | ||
/// <reference types="node" /> | ||
import { AuthenticateOptions, AuthenticatePayload, AuthenticationResponse, BaseClient, Instance, TokenWithExpiry } from "@pusher/platform-node"; | ||
export interface AuthenticationOptions { | ||
@@ -17,2 +18,22 @@ userId: string; | ||
} | ||
export interface SendMultipartMessageOptions { | ||
roomId: string; | ||
userId: string; | ||
parts: Array<NewPart>; | ||
} | ||
export declare type NewPart = NewInlinePart | NewURLPart | NewAttachmentPart; | ||
export interface NewInlinePart { | ||
type: string; | ||
content: string; | ||
} | ||
export interface NewURLPart { | ||
type: string; | ||
url: string; | ||
} | ||
export interface NewAttachmentPart { | ||
type: string; | ||
file: Buffer; | ||
name?: string; | ||
customData?: any; | ||
} | ||
export interface AttachmentOptions { | ||
@@ -111,3 +132,4 @@ resourceLink: string; | ||
} | ||
export interface GetRoomMessagesOptions { | ||
export declare type GetRoomMessagesOptions = FetchMultipartMessagesOptions; | ||
export interface FetchMultipartMessagesOptions { | ||
direction?: string; | ||
@@ -118,7 +140,2 @@ initialId?: string; | ||
} | ||
export interface GetRoomMessagesOptionsPayload { | ||
initial_id?: string; | ||
direction?: string; | ||
limit?: number; | ||
} | ||
export interface CreateUserOptions { | ||
@@ -177,3 +194,4 @@ id: string; | ||
export default class Chatkit { | ||
apiInstance: Instance; | ||
serverInstanceV2: Instance; | ||
serverInstanceV3: Instance; | ||
authorizerInstance: Instance; | ||
@@ -195,4 +213,9 @@ cursorsInstance: Instance; | ||
sendMessage(options: SendMessageOptions): Promise<any>; | ||
sendSimpleMessage(options: SendMessageOptions): Promise<any>; | ||
sendMultipartMessage(options: SendMultipartMessageOptions): Promise<any>; | ||
private uploadAttachment; | ||
deleteMessage(options: DeleteMessageOptions): Promise<void>; | ||
getRoomMessages(options: GetRoomMessagesOptions): Promise<any>; | ||
fetchMultipartMessages(options: FetchMultipartMessagesOptions): Promise<any>; | ||
private fetchMessages; | ||
getRooms(options?: GetRoomsOptions): Promise<any>; | ||
@@ -199,0 +222,0 @@ getUserRooms(options: GetUserRoomOptions): Promise<any>; |
@@ -15,7 +15,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const got_1 = require("got"); | ||
const platform_node_1 = require("@pusher/platform-node"); | ||
const utils_1 = require("./utils"); | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
; | ||
; | ||
const TOKEN_EXPIRY_LEEWAY = 30; | ||
@@ -26,3 +25,3 @@ class Chatkit { | ||
const sdkInfo = new platform_node_1.SDKInfo({ | ||
productName: 'chatkit', | ||
productName: "chatkit", | ||
version: package_json_1.default.version, | ||
@@ -38,7 +37,8 @@ }); | ||
}; | ||
const apiInstanceOptions = Object.assign({}, instanceOptions, { serviceName: 'chatkit', serviceVersion: 'v2' }); | ||
const authorizerInstanceOptions = Object.assign({}, instanceOptions, { serviceName: 'chatkit_authorizer', serviceVersion: 'v2' }); | ||
const cursorsInstanceOptions = Object.assign({}, instanceOptions, { serviceName: 'chatkit_cursors', serviceVersion: 'v2' }); | ||
const serverInstanceOptions = (version) => (Object.assign({}, instanceOptions, { serviceName: "chatkit", serviceVersion: version })); | ||
const authorizerInstanceOptions = Object.assign({}, instanceOptions, { serviceName: "chatkit_authorizer", serviceVersion: "v2" }); | ||
const cursorsInstanceOptions = Object.assign({}, instanceOptions, { serviceName: "chatkit_cursors", serviceVersion: "v2" }); | ||
this.instanceLocator = instanceLocator; | ||
this.apiInstance = new platform_node_1.Instance(apiInstanceOptions); | ||
this.serverInstanceV2 = new platform_node_1.Instance(serverInstanceOptions("v2")); | ||
this.serverInstanceV3 = new platform_node_1.Instance(serverInstanceOptions("v3")); | ||
this.authorizerInstance = new platform_node_1.Instance(authorizerInstanceOptions); | ||
@@ -50,7 +50,7 @@ this.cursorsInstance = new platform_node_1.Instance(cursorsInstanceOptions); | ||
const { userId, authPayload } = options; | ||
return this.apiInstance.authenticate(authPayload || { grant_type: 'client_credentials' }, { userId }); | ||
return this.serverInstanceV3.authenticate(authPayload || { grant_type: "client_credentials" }, { userId }); | ||
} | ||
// Used internally - not designed to be used externally | ||
generateAccessToken(options) { | ||
return this.apiInstance.generateAccessToken(options); | ||
return this.serverInstanceV3.generateAccessToken(options); | ||
} | ||
@@ -60,7 +60,8 @@ // User interactions | ||
const { id, name } = options; | ||
return this.apiInstance.request({ | ||
method: 'POST', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "POST", | ||
path: `/users`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
@@ -74,3 +75,4 @@ body: { | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -89,13 +91,15 @@ }); | ||
}); | ||
return this.apiInstance.request({ | ||
method: 'POST', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "POST", | ||
path: `/batch_users`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
body: { | ||
users | ||
users, | ||
}, | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -113,38 +117,42 @@ }); | ||
} | ||
; | ||
if (options.avatarURL) { | ||
updatePayload.avatar_url = options.avatarURL; | ||
} | ||
; | ||
if (options.customData) { | ||
updatePayload.custom_data = options.customData; | ||
} | ||
; | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "PUT", | ||
path: `/users/${options.id}`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
body: updatePayload, | ||
jwt: jwt.token, | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
deleteUser(options) { | ||
return this.apiInstance.request({ | ||
method: 'DELETE', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "DELETE", | ||
path: `/users/${options.userId}`, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
getUser(options) { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/users/${encodeURIComponent(options.id)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)); | ||
}) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
getUsers(options = {}) { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/users`, | ||
@@ -156,3 +164,4 @@ qs: { | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -162,4 +171,5 @@ }); | ||
getUsersById(options) { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/users_by_ids`, | ||
@@ -171,3 +181,4 @@ qs: { | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -181,7 +192,9 @@ }); | ||
}); | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}`, | ||
jwt: jwt.token, | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -198,4 +211,5 @@ }); | ||
} | ||
return this.apiInstance.request({ | ||
method: 'POST', | ||
return this.serverInstanceV2 | ||
.request({ | ||
method: "POST", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/messages`, | ||
@@ -207,12 +221,76 @@ jwt: this.generateAccessToken({ | ||
body: messagePayload, | ||
}).then(({ body }) => JSON.parse(body)); | ||
}) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
sendSimpleMessage(options) { | ||
return this.sendMultipartMessage({ | ||
roomId: options.roomId, | ||
userId: options.userId, | ||
parts: [{ type: "text/plain", content: options.text }], | ||
}); | ||
} | ||
sendMultipartMessage(options) { | ||
if (options.parts.length === 0) { | ||
return Promise.reject(new TypeError("message must contain at least one part")); | ||
} | ||
return Promise.all(options.parts.map((part) => part.file | ||
? this.uploadAttachment({ | ||
userId: options.userId, | ||
roomId: options.roomId, | ||
part, | ||
}) | ||
: part)) | ||
.then(parts => this.serverInstanceV3.request({ | ||
method: "POST", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/messages`, | ||
jwt: this.generateAccessToken({ | ||
su: true, | ||
userId: options.userId, | ||
}).token, | ||
body: { parts }, | ||
})) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
uploadAttachment({ userId, roomId, part: { type, name, customData, file }, }) { | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "POST", | ||
path: `/rooms/${encodeURIComponent(roomId)}/attachments`, | ||
jwt: this.generateAccessToken({ | ||
su: true, | ||
userId, | ||
}).token, | ||
body: { | ||
content_type: type, | ||
content_length: file.length, | ||
name, | ||
custom_data: customData, | ||
}, | ||
}) | ||
.then(({ body }) => { | ||
const { attachment_id: attachmentId, upload_url: uploadURL, } = JSON.parse(body); | ||
return got_1.put(uploadURL, { | ||
body: file, | ||
headers: { | ||
"content-type": type, | ||
}, | ||
}).then(() => ({ type, attachment: { id: attachmentId } })); | ||
}); | ||
} | ||
deleteMessage(options) { | ||
return this.apiInstance.request({ | ||
method: 'DELETE', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "DELETE", | ||
path: `/messages/${options.id}`, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
getRoomMessages(options) { | ||
return this.fetchMessages(Object.assign({}, options, { serverInstance: this.serverInstanceV2 })); | ||
} | ||
fetchMultipartMessages(options) { | ||
return this.fetchMessages(Object.assign({}, options, { serverInstance: this.serverInstanceV3 })); | ||
} | ||
fetchMessages(options) { | ||
const jwt = this.generateAccessToken({ | ||
@@ -224,16 +302,17 @@ su: true, | ||
if (initialId) { | ||
qs['initial_id'] = initialId; | ||
qs["initial_id"] = initialId; | ||
} | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return options.serverInstance | ||
.request({ | ||
method: "GET", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/messages`, | ||
jwt: jwt.token, | ||
qs: qs, | ||
}).then((res) => { | ||
return JSON.parse(res.body); | ||
}); | ||
}) | ||
.then(res => JSON.parse(res.body)); | ||
} | ||
getRooms(options = {}) { | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/rooms`, | ||
@@ -244,4 +323,5 @@ jwt: this.getServerToken(), | ||
include_private: options.includePrivate, | ||
} | ||
}).then((res) => { | ||
}, | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -255,7 +335,9 @@ }); | ||
}); | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/users/${options.userId}/rooms`, | ||
jwt: jwt.token, | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -269,8 +351,10 @@ }); | ||
}); | ||
return this.apiInstance.request({ | ||
method: 'GET', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "GET", | ||
path: `/users/${options.userId}/rooms`, | ||
qs: { joinable: true }, | ||
jwt: jwt.token, | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -290,3 +374,3 @@ }); | ||
if (userIds && userIds.length !== 0) { | ||
roomPayload['user_ids'] = userIds; | ||
roomPayload["user_ids"] = userIds; | ||
} | ||
@@ -296,8 +380,10 @@ if (customData) { | ||
} | ||
return this.apiInstance.request({ | ||
method: 'POST', | ||
path: '/rooms', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "POST", | ||
path: "/rooms", | ||
jwt: jwt.token, | ||
body: roomPayload, | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -317,63 +403,77 @@ }); | ||
} | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "PUT", | ||
path: `/rooms/${options.id}`, | ||
jwt: this.getServerToken(), | ||
body, | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
deleteRoom(options) { | ||
return this.apiInstance.request({ | ||
method: 'DELETE', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "DELETE", | ||
path: `/rooms/${options.id}`, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
addUsersToRoom(options) { | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "PUT", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/users/add`, | ||
jwt: this.getServerToken(), | ||
body: { user_ids: options.userIds }, | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
removeUsersFromRoom(options) { | ||
return this.apiInstance.request({ | ||
method: 'PUT', | ||
return this.serverInstanceV3 | ||
.request({ | ||
method: "PUT", | ||
path: `/rooms/${encodeURIComponent(options.roomId)}/users/remove`, | ||
jwt: this.getServerToken(), | ||
body: { user_ids: options.userIds }, | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
// Authorizer interactions | ||
createRoomRole(options) { | ||
return this.createRole(Object.assign({}, options, { scope: 'room' })); | ||
return this.createRole(Object.assign({}, options, { scope: "room" })); | ||
} | ||
createGlobalRole(options) { | ||
return this.createRole(Object.assign({}, options, { scope: 'global' })); | ||
return this.createRole(Object.assign({}, options, { scope: "global" })); | ||
} | ||
createRole(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'POST', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "POST", | ||
path: `/roles`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
body: options, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
deleteGlobalRole(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'DELETE', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "DELETE", | ||
path: `/roles/${options.name}/scope/global`, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
deleteRoomRole(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'DELETE', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "DELETE", | ||
path: `/roles/${options.name}/scope/room`, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
@@ -387,18 +487,22 @@ assignGlobalRoleToUser(options) { | ||
assignRoleToUser(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'PUT', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "PUT", | ||
path: `/users/${options.userId}/roles`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
body: { name: options.name, room_id: options.roomId }, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
getUserRoles(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'GET', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "GET", | ||
path: `/users/${options.userId}/roles`, | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -408,28 +512,34 @@ }); | ||
removeGlobalRoleForUser(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'DELETE', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "DELETE", | ||
path: `/users/${options.userId}/roles`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
removeRoomRoleForUser(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'DELETE', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "DELETE", | ||
path: `/users/${options.userId}/roles`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
qs: { room_id: options.roomId }, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
getPermissionsForGlobalRole(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'GET', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "GET", | ||
path: `/roles/${options.name}/scope/global/permissions`, | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -439,7 +549,9 @@ }); | ||
getPermissionsForRoomRole(options) { | ||
return this.authorizerInstance.request({ | ||
method: 'GET', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "GET", | ||
path: `/roles/${options.name}/scope/room/permissions`, | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -449,13 +561,15 @@ }); | ||
updatePermissionsForGlobalRole(options) { | ||
return this.updatePermissionsForRole(options.name, 'global', options.permissionsToAdd || [], options.permissionsToRemove || []); | ||
return this.updatePermissionsForRole(options.name, "global", options.permissionsToAdd || [], options.permissionsToRemove || []); | ||
} | ||
updatePermissionsForRoomRole(options) { | ||
return this.updatePermissionsForRole(options.name, 'room', options.permissionsToAdd || [], options.permissionsToRemove || []); | ||
return this.updatePermissionsForRole(options.name, "room", options.permissionsToAdd || [], options.permissionsToRemove || []); | ||
} | ||
getRoles() { | ||
return this.authorizerInstance.request({ | ||
method: 'GET', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "GET", | ||
path: `/roles`, | ||
jwt: this.getServerToken(), | ||
}).then((res) => { | ||
}) | ||
.then(res => { | ||
return JSON.parse(res.body); | ||
@@ -466,29 +580,37 @@ }); | ||
setReadCursor(options) { | ||
return this.cursorsInstance.request({ | ||
method: 'PUT', | ||
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(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
getReadCursor(options) { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
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)); | ||
}) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
getReadCursorsForUser(options) { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
return this.cursorsInstance | ||
.request({ | ||
method: "GET", | ||
path: `/cursors/0/users/${encodeURIComponent(options.userId)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)); | ||
}) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
getReadCursorsForRoom(options) { | ||
return this.cursorsInstance.request({ | ||
method: 'GET', | ||
return this.cursorsInstance | ||
.request({ | ||
method: "GET", | ||
path: `/cursors/0/rooms/${encodeURIComponent(options.roomId)}`, | ||
jwt: this.getServerToken(), | ||
}).then(({ body }) => JSON.parse(body)); | ||
}) | ||
.then(({ body }) => JSON.parse(body)); | ||
} | ||
@@ -498,3 +620,3 @@ // General requests | ||
options.jwt = options.jwt || this.getServerToken(); | ||
return this.apiInstance.request(options); | ||
return this.serverInstanceV3.request(options); | ||
} | ||
@@ -515,16 +637,18 @@ authorizerRequest(options) { | ||
if (permissionsToadd.length > 0) { | ||
body['add_permissions'] = permissionsToadd; | ||
body["add_permissions"] = permissionsToadd; | ||
} | ||
if (permissionsToRemove.length > 0) { | ||
body['remove_permissions'] = permissionsToRemove; | ||
body["remove_permissions"] = permissionsToRemove; | ||
} | ||
return this.authorizerInstance.request({ | ||
method: 'PUT', | ||
return this.authorizerInstance | ||
.request({ | ||
method: "PUT", | ||
path: `/roles/${name}/scope/${scope}/permissions`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
body: body, | ||
jwt: this.getServerToken(), | ||
}).then(() => { }); | ||
}) | ||
.then(() => { }); | ||
} | ||
@@ -536,17 +660,20 @@ /** | ||
getServerToken() { | ||
if (this.tokenWithExpiry && this.tokenWithExpiry.expiresAt > utils_1.getCurrentTimeInSeconds()) { | ||
if (this.tokenWithExpiry && | ||
this.tokenWithExpiry.expiresAt > utils_1.getCurrentTimeInSeconds()) { | ||
return this.tokenWithExpiry.token; | ||
} | ||
// Otherwise generate new token and its expiration time | ||
const tokenWithExpiresIn = this.apiInstance.generateAccessToken({ su: true }); | ||
const tokenWithExpiresIn = this.serverInstanceV3.generateAccessToken({ | ||
su: true, | ||
}); | ||
this.tokenWithExpiry = { | ||
token: tokenWithExpiresIn.token, | ||
expiresAt: utils_1.getCurrentTimeInSeconds() + tokenWithExpiresIn.expires_in - TOKEN_EXPIRY_LEEWAY, | ||
expiresAt: utils_1.getCurrentTimeInSeconds() + | ||
tokenWithExpiresIn.expires_in - | ||
TOKEN_EXPIRY_LEEWAY, | ||
}; | ||
return this.tokenWithExpiry.token; | ||
} | ||
; | ||
} | ||
exports.default = Chatkit; | ||
; | ||
//# sourceMappingURL=chatkit.js.map |
@@ -1,2 +0,2 @@ | ||
export { default as default } from './chatkit'; | ||
export { AuthenticateOptions, AuthenticatePayload, AuthenticationResponse, ErrorResponse, } from '@pusher/platform-node'; | ||
export { default } from "./chatkit"; | ||
export { AuthenticateOptions, AuthenticatePayload, AuthenticationResponse, ErrorResponse, } from "@pusher/platform-node"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62350
915
4
+ Added@types/got@^9.4.0
+ Addedgot@^9.6.0
+ Added@sindresorhus/is@0.14.0(transitive)
+ Added@szmarczak/http-timer@1.1.2(transitive)
+ Added@types/got@9.6.12(transitive)
+ Added@types/node@22.10.5(transitive)
+ Added@types/tough-cookie@4.0.5(transitive)
+ Addedcacheable-request@6.1.0(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddefer-to-connect@1.1.3(transitive)
+ Addedduplexer3@0.1.5(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedget-stream@4.1.05.2.0(transitive)
+ Addedgot@9.6.0(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.1.0(transitive)
+ Addedlowercase-keys@1.0.12.0.0(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addednormalize-url@4.5.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@1.1.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedto-readable-stream@1.0.0(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)