Commit 11b5ca4c authored by timkinnane's avatar timkinnane
Browse files

build(npm): Change package name to org scope

parent b3f6e1bc
......@@ -33,9 +33,9 @@ Currently, there are two modules exported by the SDK:
Access these modules by importing them from SDK, e.g:
ES6 `import { driver, methodCache } from 'rocketchat-sdk'`
ES6 `import { driver, methodCache } from '@rocket.chat/sdk'`
ES5 `const { driver, methodCache } = require('rocketchat-sdk')`
ES5 `const { driver, methodCache } = require('@rocket.chat/sdk')`
See [Asteroid][asteroid] docs for methods that can be called from that API.
......@@ -272,12 +272,12 @@ interactions (i.e. bots) locally while in development.
## Use as Dependency
`yarn add rocketchat-sdk` or `npm install --save rocketchat-sdk`
`yarn add @rocket.chat/sdk` or `npm install --save @rocket.chat/sdk`
ES6 module, using async
```
import * as rocketchat from 'rocketchat-sdk'
import * as rocketchat from '@rocket.chat/sdk'
const asteroid = await rocketchat.driver.connect({ host: 'localhost:3000' })
console.log('connected', asteroid)
......@@ -286,7 +286,7 @@ console.log('connected', asteroid)
ES5 module, using callback
```
const rocketchat = require('rocketchat-sdk')
const rocketchat = require('@rocket.chat/sdk')
rocketchat.driver.connect({ host: 'localhost:3000' }, function (err, asteroid) {
if (err) console.error(err)
......
......@@ -7,7 +7,7 @@ import { IMessage } from '../config/messageInterfaces';
/**
* Event Emitter for listening to connection.
* @example
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect()
* driver.events.on('connected', () => console.log('driver connected'))
*/
......@@ -36,13 +36,13 @@ export declare function useLog(externalLog: ILogger): void;
* error-first-pattern. Error returned or promise rejected on timeout.
* Removes http/s protocol to get connection hostname if taken from URL.
* @example <caption>Use with callback</caption>
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect({}, (err) => {
* if (err) throw err
* else console.log('connected')
* })
* @example <caption>Using promise</caption>
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect()
* .then(() => console.log('connected'))
* .catch((err) => console.error(err))
......
......@@ -52,7 +52,7 @@ const integrationId = process.env.INTEGRATION_ID || 'js.SDK';
/**
* Event Emitter for listening to connection.
* @example
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect()
* driver.events.on('connected', () => console.log('driver connected'))
*/
......@@ -75,13 +75,13 @@ exports.useLog = useLog;
* error-first-pattern. Error returned or promise rejected on timeout.
* Removes http/s protocol to get connection hostname if taken from URL.
* @example <caption>Use with callback</caption>
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect({}, (err) => {
* if (err) throw err
* else console.log('connected')
* })
* @example <caption>Using promise</caption>
* import { driver } from 'rocketchat-sdk'
* import { driver } from '@rocket.chat/sdk'
* driver.connect()
* .then(() => console.log('connected'))
* .catch((err) => console.error(err))
......
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../src/lib/driver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAqC;AACrC,wDAA+B;AAC/B,sBAAsB;AACtB;;;;;EAKE;AACF,2DAA4C;AAC5C,uCAAmC;AAInC,+BAA0C;AAE1C,uBAAuB;AACvB,MAAM,sBAAsB,GAAG,sBAAsB,CAAA;AACrD,MAAM,kBAAkB,GAAG,iBAAiB,CAAA;AAE5C;;;GAGG;AACH;;EAEE;AAEF,iCAAiC;AACjC,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,QAAQ,GAAa;IACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,gBAAgB;IACpD,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3E,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa;CACjC,CAAA;AAED;;;;GAIG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,QAAQ,CAAA;AAE5D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AAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAChD,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AACrE,CAAC;AARD,kDAQC;AAED;;;;GAIG;AACH,2BAAmC,OAAqC,EAAE,IAAY;IACpF,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;AAC/E,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,0BAAkC,OAAqC,EAAE,QAAgB;IACvF,MAAM,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1F,CAAC;AAFD,4CAEC;AAED;;;;;GAKG;AACH,qBAA6B,OAAiB,EAAE,MAAe;IAC7D,EAAE,CAAC,CAAC,MAAM,CAAC;QAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACvD,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC;AAHD,kCAGC;AAED;;;GAGG;AACH,uBAA+B,OAAiB;IAC9C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAFD,sCAEC","sourcesContent":["import { EventEmitter } from 'events'\nimport Asteroid from 'asteroid'\n// Asteroid v2 imports\n/*\nimport { createClass } from 'asteroid'\nimport WebSocket from 'ws'\nimport { Map } from 'immutable'\nimport immutableCollectionMixin from 'asteroid-immutable-collections-mixin'\n*/\nimport * as methodCache from './methodCache'\nimport { Message } from './message'\nimport { IOptions, ICallback, ILogger } from '../config/driverInterfaces'\nimport { IAsteroid, ICredentials, ISubscription, ICollection } from '../config/asteroidInterfaces'\nimport { IMessage } from '../config/messageInterfaces'\nimport { logger, replaceLog } from './log'\n\n/** Collection names */\nconst _messageCollectionName = 'stream-room-messages'\nconst _messageStreamName = '__my_messages__'\n\n/**\n * Asteroid ^v2 interface below, suspended for work on future branch\n * @todo Upgrade to Asteroid v2 or find a better maintained ddp client\n */\n/*\nconst Asteroid: IAsteroid = createClass([immutableCollectionMixin])\n*/\n\n// CONNECTION SETUP AND CONFIGURE\n// -----------------------------------------------------------------------------\n\n/**\n * Define default config as public, allowing overrides from new connection.\n * Enable SSL by default if Rocket.Chat URL contains https.\n */\nconst defaults: IOptions = {\n host: process.env.ROCKETCHAT_URL || 'localhost:3000',\n useSsl: ((process.env.ROCKETCHAT_URL || '').toString().startsWith('https')),\n timeout: 20 * 1000 // 20 seconds\n}\n\n/**\n * The integration property is applied as an ID on sent messages `bot.i` param\n * Should be replaced when connection is invoked by a package using the SDK\n * e.g. The Hubot adapter would pass its integration ID with credentials, like:\n */\nconst integrationId = process.env.INTEGRATION_ID || 'js.SDK'\n\n/**\n * Event Emitter for listening to connection.\n * @example\n * import { driver } from 'rocketchat-sdk'\n * driver.connect()\n * driver.events.on('connected', () => console.log('driver connected'))\n */\nexport const events = new EventEmitter()\n\n/**\n * An Asteroid instance for interacting with Rocket.Chat.\n * Variable not initialised until `connect` called.\n */\nexport let asteroid: IAsteroid\n\n/**\n * Asteroid subscriptions, exported for direct polling by adapters\n * Variable not initialised until `prepMeteorSubscriptions` called.\n */\nexport let subscriptions: ISubscription[] = []\n\n/**\n * Array of messages received from reactive collection\n */\nexport let messages: ICollection\n\n/**\n * Allow override of default logging with adapter's log instance\n */\nexport function useLog (externalLog: ILogger) {\n replaceLog(externalLog)\n}\n\n/**\n * Initialise asteroid instance with given options or defaults.\n * Returns promise, resolved with Asteroid instance. Callback follows\n * error-first-pattern. Error returned or promise rejected on timeout.\n * Removes http/s protocol to get connection hostname if taken from URL.\n * @example <caption>Use with callback</caption>\n * import { driver } from 'rocketchat-sdk'\n * driver.connect({}, (err) => {\n * if (err) throw err\n * else console.log('connected')\n * })\n * @example <caption>Using promise</caption>\n * import { driver } from 'rocketchat-sdk'\n * driver.connect()\n * .then(() => console.log('connected'))\n * .catch((err) => console.error(err))\n */\nexport function connect (options: IOptions = {}, callback?: ICallback): any {\n return new Promise((resolve, reject) => {\n const config = Object.assign({}, defaults, options) // override defaults\n config.host = config.host!.replace(/(^\\w+:|^)\\/\\//, '')\n logger.info('[connect] Connecting', config)\n asteroid = new Asteroid(config.host, config.useSsl)\n // Asteroid ^v2 interface...\n /*\n asteroid = new Asteroid({\n endpoint: `ws://${options.host}/websocket`,\n SocketConstructor: WebSocket\n })\n */\n setupMethodCache(asteroid) // init instance for later caching method calls\n asteroid.on('connected', () => events.emit('connected'))\n asteroid.on('reconnected', () => events.emit('reconnected'))\n // let cancelled = false\n const rejectionTimeout = setTimeout(function () {\n logger.info(`[connect] Timeout (${config.timeout})`)\n // cancelled = true\n const err = new Error('Asteroid connection timeout')\n callback ? callback(err, asteroid) : reject(err)\n }, config.timeout)\n events.once('connected', () => {\n logger.info('[connect] Connected')\n // if (cancelled) return asteroid.ddp.disconnect() // cancel if already rejected\n clearTimeout(rejectionTimeout)\n if (callback) callback(null, asteroid)\n resolve(asteroid)\n })\n })\n}\n\n/**\n * Remove all active subscriptions, logout and disconnect from Rocket.Chat\n */\nexport function disconnect (): Promise<void> {\n logger.info('Unsubscribing, logging out, disconnecting')\n unsubscribeAll()\n return logout().then(() => Promise.resolve()) // asteroid.disconnect()) // v2 only\n}\n\n// ASYNC AND CACHE METHOD UTILS\n// -----------------------------------------------------------------------------\n\n/**\n * Setup method cache configs from env or defaults, before they are called.\n * @param asteroid The asteroid instance to cache method calls\n */\nfunction setupMethodCache (asteroid: IAsteroid): void {\n methodCache.use(asteroid)\n methodCache.create('getRoomIdByNameOrId', {\n max: parseInt(process.env.ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.ROOM_CACHE_MAX_AGE || '300', 10)\n }),\n methodCache.create('getRoomNameById', {\n max: parseInt(process.env.ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.ROOM_CACHE_MAX_AGE || '300', 10)\n })\n methodCache.create('createDirectMessage', {\n max: parseInt(process.env.DM_ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.DM_ROOM_CACHE_MAX_AGE || '100', 10)\n })\n}\n\n/**\n * Wraps method calls to ensure they return a Promise with caught exceptions.\n * @param method The Rocket.Chat server method, to call through Asteroid\n * @param params Single or array of parameters of the method to call\n */\nexport function asyncCall (method: string, params: any | any[]): Promise<any> {\n if (!Array.isArray(params)) params = [params] // cast to array for apply\n logger.info(`[${method}] Calling (async): ${JSON.stringify(params)}`)\n return Promise.resolve(asteroid.apply(method, params).result)\n .catch((err: Error) => {\n logger.error(`[${method}] Error:`, err)\n throw err // throw after log to stop async chain\n })\n .then((result: any) => {\n (result)\n ? logger.debug(`[${method}] Success: ${JSON.stringify(result)}`)\n : logger.debug(`[${method}] Success`)\n return result\n })\n}\n\n/**\n * Call a method as async via Asteroid, or through cache if one is created.\n * @param name The Rocket.Chat server method to call\n * @param params Single or array of parameters of the method to call\n */\nexport function callMethod (name: string, params: any | any[]): Promise<any> {\n return (methodCache.has(name))\n ? asyncCall(name, params)\n : cacheCall(name, params)\n}\n\n/**\n * Wraps Asteroid method calls, passed through method cache if cache is valid.\n * @param method The Rocket.Chat server method, to call through Asteroid\n * @param key Single string parameters only, required to use as cache key\n */\nexport function cacheCall (method: string, key: string): Promise<any> {\n return methodCache.call(method, key)\n .catch((err: Error) => {\n logger.error(`[${method}] Error:`, err)\n throw err // throw after log to stop async chain\n })\n .then((result: any) => {\n (result)\n ? logger.debug(`[${method}] Success: ${JSON.stringify(result)}`)\n : logger.debug(`[${method}] Success`)\n return result\n })\n}\n\n// LOGIN AND SUBSCRIBE TO ROOMS\n// -----------------------------------------------------------------------------\n\n/** Login to Rocket.Chat via Asteroid */\nexport function login (credentials: ICredentials): Promise<any> {\n logger.info(`[login] Logging in ${credentials.username || credentials.email}`)\n let login: Promise<any>\n if (process.env.ROCKETCHAT_AUTH === 'ldap') {\n const params = [\n credentials.username,\n credentials.password,\n { ldap: true, ldapOptions: {} }\n ]\n login = asteroid.loginWithLDAP(...params)\n } else {\n const usernameOrEmail = credentials.username || credentials.email || 'bot'\n login = asteroid.loginWithPassword(usernameOrEmail, credentials.password)\n }\n return login.catch((err: Error) => {\n logger.info('[login] Error:', err)\n throw err // throw after log to stop async chain\n })\n}\n\n/** Logout of Rocket.Chat via Asteroid */\nexport function logout (): Promise<void | null> {\n return asteroid.logout().catch((err: Error) => {\n logger.error('[Logout] Error:', err)\n throw err // throw after log to stop async chain\n })\n}\n\n/**\n * Subscribe to Meteor subscription\n * Resolves with subscription (added to array), with ID property\n * @todo - 3rd param of asteroid.subscribe is deprecated in Rocket.Chat?\n */\nexport function subscribe (topic: string, roomId: string): Promise<ISubscription> {\n return new Promise((resolve, reject) => {\n logger.info(`[subscribe] Preparing subscription: ${topic}: ${roomId}`)\n const subscription = asteroid.subscribe(topic, roomId, true)\n subscriptions.push(subscription)\n return subscription.ready.then((id) => {\n logger.info(`[subscribe] Stream ready: ${id}`)\n resolve(subscription)\n })\n // Asteroid ^v2 interface...\n /*\n subscription.on('ready', () => {\n console.log(`[${topic}] Subscribe ready`)\n events.emit('subscription-ready', subscription)\n subscriptions.push(subscription)\n resolve(subscription)\n })\n subscription.on('error', (err: Error) => {\n console.error(`[${topic}] Subscribe error:`, err)\n events.emit('subscription-error', roomId, err)\n reject(err)\n })\n */\n })\n}\n\n/** Unsubscribe from Meteor subscription */\nexport function unsubscribe (subscription: ISubscription): void {\n const index = subscriptions.indexOf(subscription)\n if (index === -1) return\n subscription.stop()\n // asteroid.unsubscribe(subscription.id) // v2\n subscriptions.splice(index, 1) // remove from collection\n logger.info(`[${subscription.id}] Unsubscribed`)\n}\n\n/** Unsubscribe from all subscriptions in collection */\nexport function unsubscribeAll (): void {\n subscriptions.map((s: ISubscription) => unsubscribe(s))\n}\n\n/**\n * Begin subscription to room events for user.\n * Older adapters used an option for this method but it was always the default.\n */\nexport function subscribeToMessages (): Promise<ISubscription> {\n return subscribe(_messageCollectionName, _messageStreamName)\n .then((subscription) => {\n messages = asteroid.getCollection(_messageCollectionName)\n // v2\n // messages = asteroid.collections.get(_messageCollectionName) || Map()\n return subscription\n })\n}\n\nexport function reactToMessages (callback: ICallback): void {\n logger.info(`[reactive] Listening for change events in collection ${messages.name}`)\n messages.reactiveQuery({}).on('change', (_id: string) => {\n const changedMessageQuery = messages.reactiveQuery({ _id })\n if (changedMessageQuery.result && changedMessageQuery.result.length > 0) {\n const changedMessage = changedMessageQuery.result[0]\n if (Array.isArray(changedMessage.args)) {\n logger.info(`[received] Message in room ${ changedMessage.args[0].rid }`)\n callback(null, changedMessage.args[0], changedMessage.args[1])\n } else {\n logger.debug('[received] Update without message args')\n }\n } else {\n logger.debug('[received] Reactive query at ID ${ _id } without results')\n }\n })\n}\n\n/**\n * Get every new element added to DDP in Asteroid (v2)\n * @todo Resolve this functionality within Rocket.Chat with team\n * @param callback Function to call with element details\n */\n/*\nexport function onAdded (callback: ICallback): void {\n console.log('Setting up reactive message list...')\n try {\n asteroid.ddp.on('added', ({ collection, id, fields }) => {\n console.log(`Element added to collection ${ collection }`)\n console.log(id)\n console.log(fields)\n callback(null, id)\n })\n } catch (err) {\n callback(err)\n }\n}\n*/\n\n// PREPARE AND SEND MESSAGES\n// -----------------------------------------------------------------------------\n\n/** Get ID for a room by name (or ID). */\nexport function getRoomId (name: string): Promise<string> {\n return cacheCall('getRoomIdByNameOrId', name)\n}\n\n/** Get name for a room by ID. */\nexport function getRoomName (id: string): Promise<string> {\n return cacheCall('getRoomNameById', id)\n}\n\n/**\n * Get ID for a DM room by its recipient's name.\n * Will create a DM (with the bot) if it doesn't exist already.\n * @todo test why create resolves with object instead of simply ID\n */\nexport function getDirectMessageRoomId (username: string): Promise<string> {\n return cacheCall('createDirectMessage', username).then((DM) => DM.rid)\n}\n\n/** Join the bot into a room by its name or ID */\nexport function joinRoom (room: string): Promise<void> {\n return getRoomId(room).then((roomId) => asyncCall('joinRoom', roomId))\n}\n\n/** Join a set of rooms by array of names or IDs */\nexport function joinRooms (rooms: string[]): Promise<void[]> {\n return Promise.all(rooms.map((room) => joinRoom(room)))\n}\n\n/**\n * Structure message content, optionally addressing to room ID.\n * Accepts message text string or a structured message object.\n */\nexport function prepareMessage (content: string | IMessage, roomId?: string): Message {\n const message = new Message(content, integrationId)\n if (roomId) message.setRoomId(roomId)\n return message\n}\n\n/**\n * Prepare and send message/s to specified room ID.\n * Accepts message text string, array of strings or a structured message object.\n * Will create one or more send calls collected into promise.\n */\nexport function sendMessageByRoomId (content: string | string[] | IMessage, roomId: string): Promise<any> {\n let messages: Message[] = []\n if (Array.isArray(content)) {\n content.forEach((text) => messages.push(prepareMessage(text, roomId)))\n } else {\n messages.push(prepareMessage(content, roomId))\n }\n return Promise.all(messages.map((message) => sendMessage(message)))\n}\n\n/**\n * Prepare and send message/s to specified room name (or ID).\n * Accepts message text string, array of strings or a structured message object.\n * Will create one or more send calls collected into promise.\n */\nexport function sendMessageByRoom (content: string | string[] | IMessage, room: string): Promise<any> {\n return getRoomId(room).then((roomId) => sendMessageByRoomId(content, roomId))\n}\n\n/**\n * Send a message to a user in a DM.\n */\nexport function sendDirectToUser (message: string | string[] | IMessage, username: string): Promise<any> {\n return getDirectMessageRoomId(username).then((rid) => sendMessageByRoomId(message, rid))\n}\n\n/**\n * Send a prepared message object (with pre-defined room ID).\n * Usually prepared and called by sendMessageByRoomId or sendMessageByRoom.\n * In the Hubot adapter, this method accepted a room ID, which was not semantic,\n * such usage should be replaced by `sendMessageByRoom(content, roomId)`\n */\nexport function sendMessage (message: IMessage, roomId?: string): Promise<any> {\n if (roomId) return sendMessageByRoomId(message, roomId)\n return asyncCall('sendMessage', message)\n}\n\n/**\n * Legacy method for older adapters - sendMessage now accepts all properties\n * @deprecated since 0.0.0\n */\nexport function customMessage (message: IMessage): Promise<any> {\n return sendMessage(message)\n}\n"]}
\ No newline at end of file
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../src/lib/driver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAqC;AACrC,wDAA+B;AAC/B,sBAAsB;AACtB;;;;;EAKE;AACF,2DAA4C;AAC5C,uCAAmC;AAInC,+BAA0C;AAE1C,uBAAuB;AACvB,MAAM,sBAAsB,GAAG,sBAAsB,CAAA;AACrD,MAAM,kBAAkB,GAAG,iBAAiB,CAAA;AAE5C;;;GAGG;AACH;;EAEE;AAEF,iCAAiC;AACjC,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,QAAQ,GAAa;IACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,gBAAgB;IACpD,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3E,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa;CACjC,CAAA;AAED;;;;GAIG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,QAAQ,CAAA;AAE5D;;;;;;GAMG;AACU,QAAA,MAAM,GAAG,IAAI,qBAAY,EAAE,CAAA;AAQxC;;;GAGG;AACQ,QAAA,aAAa,GAAoB,EAAE,CAAA;AAO9C;;GAEG;AACH,gBAAwB,WAAoB;IAC1C,gBAAU,CAAC,WAAW,CAAC,CAAA;AACzB,CAAC;AAFD,wBAEC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAyB,UAAoB,EAAE,EAAE,QAAoB;IACnE,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GA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AC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;AAC/E,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,0BAAkC,OAAqC,EAAE,QAAgB;IACvF,MAAM,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1F,CAAC;AAFD,4CAEC;AAED;;;;;GAKG;AACH,qBAA6B,OAAiB,EAAE,MAAe;IAC7D,EAAE,CAAC,CAAC,MAAM,CAAC;QAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACvD,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC;AAHD,kCAGC;AAED;;;GAGG;AACH,uBAA+B,OAAiB;IAC9C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAFD,sCAEC","sourcesContent":["import { EventEmitter } from 'events'\nimport Asteroid from 'asteroid'\n// Asteroid v2 imports\n/*\nimport { createClass } from 'asteroid'\nimport WebSocket from 'ws'\nimport { Map } from 'immutable'\nimport immutableCollectionMixin from 'asteroid-immutable-collections-mixin'\n*/\nimport * as methodCache from './methodCache'\nimport { Message } from './message'\nimport { IOptions, ICallback, ILogger } from '../config/driverInterfaces'\nimport { IAsteroid, ICredentials, ISubscription, ICollection } from '../config/asteroidInterfaces'\nimport { IMessage } from '../config/messageInterfaces'\nimport { logger, replaceLog } from './log'\n\n/** Collection names */\nconst _messageCollectionName = 'stream-room-messages'\nconst _messageStreamName = '__my_messages__'\n\n/**\n * Asteroid ^v2 interface below, suspended for work on future branch\n * @todo Upgrade to Asteroid v2 or find a better maintained ddp client\n */\n/*\nconst Asteroid: IAsteroid = createClass([immutableCollectionMixin])\n*/\n\n// CONNECTION SETUP AND CONFIGURE\n// -----------------------------------------------------------------------------\n\n/**\n * Define default config as public, allowing overrides from new connection.\n * Enable SSL by default if Rocket.Chat URL contains https.\n */\nconst defaults: IOptions = {\n host: process.env.ROCKETCHAT_URL || 'localhost:3000',\n useSsl: ((process.env.ROCKETCHAT_URL || '').toString().startsWith('https')),\n timeout: 20 * 1000 // 20 seconds\n}\n\n/**\n * The integration property is applied as an ID on sent messages `bot.i` param\n * Should be replaced when connection is invoked by a package using the SDK\n * e.g. The Hubot adapter would pass its integration ID with credentials, like:\n */\nconst integrationId = process.env.INTEGRATION_ID || 'js.SDK'\n\n/**\n * Event Emitter for listening to connection.\n * @example\n * import { driver } from '@rocket.chat/sdk'\n * driver.connect()\n * driver.events.on('connected', () => console.log('driver connected'))\n */\nexport const events = new EventEmitter()\n\n/**\n * An Asteroid instance for interacting with Rocket.Chat.\n * Variable not initialised until `connect` called.\n */\nexport let asteroid: IAsteroid\n\n/**\n * Asteroid subscriptions, exported for direct polling by adapters\n * Variable not initialised until `prepMeteorSubscriptions` called.\n */\nexport let subscriptions: ISubscription[] = []\n\n/**\n * Array of messages received from reactive collection\n */\nexport let messages: ICollection\n\n/**\n * Allow override of default logging with adapter's log instance\n */\nexport function useLog (externalLog: ILogger) {\n replaceLog(externalLog)\n}\n\n/**\n * Initialise asteroid instance with given options or defaults.\n * Returns promise, resolved with Asteroid instance. Callback follows\n * error-first-pattern. Error returned or promise rejected on timeout.\n * Removes http/s protocol to get connection hostname if taken from URL.\n * @example <caption>Use with callback</caption>\n * import { driver } from '@rocket.chat/sdk'\n * driver.connect({}, (err) => {\n * if (err) throw err\n * else console.log('connected')\n * })\n * @example <caption>Using promise</caption>\n * import { driver } from '@rocket.chat/sdk'\n * driver.connect()\n * .then(() => console.log('connected'))\n * .catch((err) => console.error(err))\n */\nexport function connect (options: IOptions = {}, callback?: ICallback): any {\n return new Promise((resolve, reject) => {\n const config = Object.assign({}, defaults, options) // override defaults\n config.host = config.host!.replace(/(^\\w+:|^)\\/\\//, '')\n logger.info('[connect] Connecting', config)\n asteroid = new Asteroid(config.host, config.useSsl)\n // Asteroid ^v2 interface...\n /*\n asteroid = new Asteroid({\n endpoint: `ws://${options.host}/websocket`,\n SocketConstructor: WebSocket\n })\n */\n setupMethodCache(asteroid) // init instance for later caching method calls\n asteroid.on('connected', () => events.emit('connected'))\n asteroid.on('reconnected', () => events.emit('reconnected'))\n // let cancelled = false\n const rejectionTimeout = setTimeout(function () {\n logger.info(`[connect] Timeout (${config.timeout})`)\n // cancelled = true\n const err = new Error('Asteroid connection timeout')\n callback ? callback(err, asteroid) : reject(err)\n }, config.timeout)\n events.once('connected', () => {\n logger.info('[connect] Connected')\n // if (cancelled) return asteroid.ddp.disconnect() // cancel if already rejected\n clearTimeout(rejectionTimeout)\n if (callback) callback(null, asteroid)\n resolve(asteroid)\n })\n })\n}\n\n/**\n * Remove all active subscriptions, logout and disconnect from Rocket.Chat\n */\nexport function disconnect (): Promise<void> {\n logger.info('Unsubscribing, logging out, disconnecting')\n unsubscribeAll()\n return logout().then(() => Promise.resolve()) // asteroid.disconnect()) // v2 only\n}\n\n// ASYNC AND CACHE METHOD UTILS\n// -----------------------------------------------------------------------------\n\n/**\n * Setup method cache configs from env or defaults, before they are called.\n * @param asteroid The asteroid instance to cache method calls\n */\nfunction setupMethodCache (asteroid: IAsteroid): void {\n methodCache.use(asteroid)\n methodCache.create('getRoomIdByNameOrId', {\n max: parseInt(process.env.ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.ROOM_CACHE_MAX_AGE || '300', 10)\n }),\n methodCache.create('getRoomNameById', {\n max: parseInt(process.env.ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.ROOM_CACHE_MAX_AGE || '300', 10)\n })\n methodCache.create('createDirectMessage', {\n max: parseInt(process.env.DM_ROOM_CACHE_SIZE || '10', 10),\n maxAge: 1000 * parseInt(process.env.DM_ROOM_CACHE_MAX_AGE || '100', 10)\n })\n}\n\n/**\n * Wraps method calls to ensure they return a Promise with caught exceptions.\n * @param method The Rocket.Chat server method, to call through Asteroid\n * @param params Single or array of parameters of the method to call\n */\nexport function asyncCall (method: string, params: any | any[]): Promise<any> {\n if (!Array.isArray(params)) params = [params] // cast to array for apply\n logger.info(`[${method}] Calling (async): ${JSON.stringify(params)}`)\n return Promise.resolve(asteroid.apply(method, params).result)\n .catch((err: Error) => {\n logger.error(`[${method}] Error:`, err)\n throw err // throw after log to stop async chain\n })\n .then((result: any) => {\n (result)\n ? logger.debug(`[${method}] Success: ${JSON.stringify(result)}`)\n : logger.debug(`[${method}] Success`)\n return result\n })\n}\n\n/**\n * Call a method as async via Asteroid, or through cache if one is created.\n * @param name The Rocket.Chat server method to call\n * @param params Single or array of parameters of the method to call\n */\nexport function callMethod (name: string, params: any | any[]): Promise<any> {\n return (methodCache.has(name))\n ? asyncCall(name, params)\n : cacheCall(name, params)\n}\n\n/**\n * Wraps Asteroid method calls, passed through method cache if cache is valid.\n * @param method The Rocket.Chat server method, to call through Asteroid\n * @param key Single string parameters only, required to use as cache key\n */\nexport function cacheCall (method: string, key: string): Promise<any> {\n return methodCache.call(method, key)\n .catch((err: Error) => {\n logger.error(`[${method}] Error:`, err)\n throw err // throw after log to stop async chain\n })\n .then((result: any) => {\n (result)\n ? logger.debug(`[${method}] Success: ${JSON.stringify(result)}`)\n : logger.debug(`[${method}] Success`)\n return result\n })\n}\n\n// LOGIN AND SUBSCRIBE TO ROOMS\n// -----------------------------------------------------------------------------\n\n/** Login to Rocket.Chat via Asteroid */\nexport function login (credentials: ICredentials): Promise<any> {\n logger.info(`[login] Logging in ${credentials.username || credentials.email}`)\n let login: Promise<any>\n if (process.env.ROCKETCHAT_AUTH === 'ldap') {\n const params = [\n credentials.username,\n credentials.password,\n { ldap: true, ldapOptions: {} }\n ]\n login = asteroid.loginWithLDAP(...params)\n } else {\n const usernameOrEmail = credentials.username || credentials.email || 'bot'\n login = asteroid.loginWithPassword(usernameOrEmail, credentials.password)\n }\n return login.catch((err: Error) => {\n logger.info('[login] Error:', err)\n throw err // throw after log to stop async chain\n })\n}\n\n/** Logout of Rocket.Chat via Asteroid */\nexport function logout (): Promise<void | null> {\n return asteroid.logout().catch((err: Error) => {\n logger.error('[Logout] Error:', err)\n throw err // throw after log to stop async chain\n })\n}\n\n/**\n * Subscribe to Meteor subscription\n * Resolves with subscription (added to array), with ID property\n * @todo - 3rd param of asteroid.subscribe is deprecated in Rocket.Chat?\n */\nexport function subscribe (topic: string, roomId: string): Promise<ISubscription> {\n return new Promise((resolve, reject) => {\n logger.info(`[subscribe] Preparing subscription: ${topic}: ${roomId}`)\n const subscription = asteroid.subscribe(topic, roomId, true)\n subscriptions.push(subscription)\n return subscription.ready.then((id) => {\n logger.info(`[subscribe] Stream ready: ${id}`)\n resolve(subscription)\n })\n // Asteroid ^v2 interface...\n /*\n subscription.on('ready', () => {\n console.log(`[${topic}] Subscribe ready`)\n events.emit('subscription-ready', subscription)\n subscriptions.push(subscription)\n resolve(subscription)\n })\n subscription.on('error', (err: Error) => {\n console.error(`[${topic}] Subscribe error:`, err)\n events.emit('subscription-error', roomId, err)\n reject(err)\n })\n */\n })\n}\n\n/** Unsubscribe from Meteor subscription */\nexport function unsubscribe (subscription: ISubscription): void {\n const index = subscriptions.indexOf(subscription)\n if (index === -1) return\n subscription.stop()\n // asteroid.unsubscribe(subscription.id) // v2\n subscriptions.splice(index, 1) // remove from collection\n logger.info(`[${subscription.id}] Unsubscribed`)\n}\n\n/** Unsubscribe from all subscriptions in collection */\nexport function unsubscribeAll (): void {\n subscriptions.map((s: ISubscription) => unsubscribe(s))\n}\n\n/**\n * Begin subscription to room events for user.\n * Older adapters used an option for this method but it was always the default.\n */\nexport function subscribeToMessages (): Promise<ISubscription> {\n return subscribe(_messageCollectionName, _messageStreamName)\n .then((subscription) => {\n messages = asteroid.getCollection(_messageCollectionName)\n // v2\n // messages = asteroid.collections.get(_messageCollectionName) || Map()\n return subscription\n })\n}\n\nexport function reactToMessages (callback: ICallback): void {\n logger.info(`[reactive] Listening for change events in collection ${messages.name}`)\n messages.reactiveQuery({}).on('change', (_id: string) => {\n const changedMessageQuery = messages.reactiveQuery({ _id })\n if (changedMessageQuery.result && changedMessageQuery.result.length > 0) {\n const changedMessage = changedMessageQuery.result[0]\n if (Array.isArray(changedMessage.args)) {\n logger.info(`[received] Message in room ${ changedMessage.args[0].rid }`)\n callback(null, changedMessage.args[0], changedMessage.args[1])\n } else {\n logger.debug('[received] Update without message args')\n }\n } else {\n logger.debug('[received] Reactive query at ID ${ _id } without results')\n }\n })\n}\n\n/**\n * Get every new element added to DDP in Asteroid (v2)\n * @todo Resolve this functionality within Rocket.Chat with team\n * @param callback Function to call with element details\n */\n/*\nexport function onAdded (callback: ICallback): void {\n console.log('Setting up reactive message list...')\n try {\n asteroid.ddp.on('added', ({ collection, id, fields }) => {\n console.log(`Element added to collection ${ collection }`)\n console.log(id)\n console.log(fields)\n callback(null, id)\n })\n } catch (err) {\n callback(err)\n }\n}\n*/\n\n// PREPARE AND SEND MESSAGES\n// -----------------------------------------------------------------------------\n\n/** Get ID for a room by name (or ID). */\nexport function getRoomId (name: string): Promise<string> {\n return cacheCall('getRoomIdByNameOrId', name)\n}\n\n/** Get name for a room by ID. */\nexport function getRoomName (id: string): Promise<string> {\n return cacheCall('getRoomNameById', id)\n}\n\n/**\n * Get ID for a DM room by its recipient's name.\n * Will create a DM (with the bot) if it doesn't exist already.\n * @todo test why create resolves with object instead of simply ID\n */\nexport function getDirectMessageRoomId (username: string): Promise<string> {\n return cacheCall('createDirectMessage', username).then((DM) => DM.rid)\n}\n\n/** Join the bot into a room by its name or ID */\nexport function joinRoom (room: string): Promise<void> {\n return getRoomId(room).then((roomId) => asyncCall('joinRoom', roomId))\n}\n\n/** Join a set of rooms by array of names or IDs */\nexport function joinRooms (rooms: string[]): Promise<void[]> {\n return Promise.all(rooms.map((room) => joinRoom(room)))\n}\n\n/**\n * Structure message content, optionally addressing to room ID.\n * Accepts message text string or a structured message object.\n */\nexport function prepareMessage (content: string | IMessage, roomId?: string): Message {\n const message = new Message(content, integrationId)\n if (roomId) message.setRoomId(roomId)\n return message\n}\n\n/**\n * Prepare and send message/s to specified room ID.\n * Accepts message text string, array of strings or a structured message object.\n * Will create one or more send calls collected into promise.\n */\nexport function sendMessageByRoomId (content: string | string[] | IMessage, roomId: string): Promise<any> {\n let messages: Message[] = []\n if (Array.isArray(content)) {\n content.forEach((text) => messages.push(prepareMessage(text, roomId)))\n } else {\n messages.push(prepareMessage(content, roomId))\n }\n return Promise.all(messages.map((message) => sendMessage(message)))\n}\n\n/**\n * Prepare and send message/s to specified room name (or ID).\n * Accepts message text string, array of strings or a structured message object.\n * Will create one or more send calls collected into promise.\n */\nexport function sendMessageByRoom (content: string | string[] | IMessage, room: string): Promise<any> {\n return getRoomId(room).then((roomId) => sendMessageByRoomId(content, roomId))\n}\n\n/**\n * Send a message to a user in a DM.\n */\nexport function sendDirectToUser (message: string | string[] | IMessage, username: string): Promise<any> {\n return getDirectMessageRoomId(username).then((rid) => sendMessageByRoomId(message, rid))\n}\n\n/**\n * Send a prepared message object (with pre-defined room ID).\n * Usually prepared and called by sendMessageByRoomId or sendMessageByRoom.\n * In the Hubot adapter, this method accepted a room ID, which was not semantic,\n * such usage should be replaced by `sendMessageByRoom(content, roomId)`\n */\nexport function sendMessage (message: IMessage, roomId?: string): Promise<any> {\n if (roomId) return sendMessageByRoomId(message, roomId)\n return asyncCall('sendMessage', message)\n}\n\n/**\n * Legacy method for older adapters - sendMessage now accepts all properties\n * @deprecated since 0.0.0\n */\nexport function customMessage (message: IMessage): Promise<any> {\n return sendMessage(message)\n}\n"]}
\ No newline at end of file
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>InternalLog | rocketchat-sdk</title>
<title>InternalLog | @rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">rocketchat-sdk</a>
<a href="../index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -117,7 +117,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/log.ts#L5">lib/log.ts:5</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/log.ts#L5">lib/log.ts:5</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......@@ -140,7 +140,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/log.ts#L17">lib/log.ts:17</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/log.ts#L17">lib/log.ts:17</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......@@ -163,7 +163,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/log.ts#L8">lib/log.ts:8</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/log.ts#L8">lib/log.ts:8</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......@@ -186,7 +186,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/log.ts#L14">lib/log.ts:14</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/log.ts#L14">lib/log.ts:14</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......@@ -209,7 +209,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/log.ts#L11">lib/log.ts:11</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/log.ts#L11">lib/log.ts:11</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Message | rocketchat-sdk</title>
<title>Message | @rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">rocketchat-sdk</a>
<a href="../index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -148,7 +148,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/message.ts#L13">lib/message.ts:13</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/message.ts#L13">lib/message.ts:13</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......@@ -174,7 +174,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#_id">_id</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L5">config/messageInterfaces.ts:5</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L5">config/messageInterfaces.ts:5</a></li>
</ul>
</aside>
</section>
......@@ -185,7 +185,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#alias">alias</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L8">config/messageInterfaces.ts:8</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L8">config/messageInterfaces.ts:8</a></li>
</ul>
</aside>
</section>
......@@ -196,7 +196,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#attachments">attachments</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L20">config/messageInterfaces.ts:20</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L20">config/messageInterfaces.ts:20</a></li>
</ul>
</aside>
</section>
......@@ -207,7 +207,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#avatar">avatar</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L10">config/messageInterfaces.ts:10</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L10">config/messageInterfaces.ts:10</a></li>
</ul>
</aside>
</section>
......@@ -218,7 +218,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#bot">bot</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L12">config/messageInterfaces.ts:12</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L12">config/messageInterfaces.ts:12</a></li>
</ul>
</aside>
</section>
......@@ -229,7 +229,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#editedat">editedAt</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L21">config/messageInterfaces.ts:21</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L21">config/messageInterfaces.ts:21</a></li>
</ul>
</aside>
</section>
......@@ -240,7 +240,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#editedby">editedBy</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L22">config/messageInterfaces.ts:22</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L22">config/messageInterfaces.ts:22</a></li>
</ul>
</aside>
</section>
......@@ -251,7 +251,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#emoji">emoji</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L9">config/messageInterfaces.ts:9</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L9">config/messageInterfaces.ts:9</a></li>
</ul>
</aside>
</section>
......@@ -262,7 +262,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#groupable">groupable</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L11">config/messageInterfaces.ts:11</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L11">config/messageInterfaces.ts:11</a></li>
</ul>
</aside>
</section>
......@@ -273,7 +273,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#location">location</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L16">config/messageInterfaces.ts:16</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L16">config/messageInterfaces.ts:16</a></li>
</ul>
</aside>
</section>
......@@ -284,7 +284,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#mentions">mentions</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L14">config/messageInterfaces.ts:14</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L14">config/messageInterfaces.ts:14</a></li>
</ul>
</aside>
</section>
......@@ -295,7 +295,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#msg">msg</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L7">config/messageInterfaces.ts:7</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L7">config/messageInterfaces.ts:7</a></li>
</ul>
</aside>
</section>
......@@ -306,7 +306,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#reactions">reactions</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L15">config/messageInterfaces.ts:15</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L15">config/messageInterfaces.ts:15</a></li>
</ul>
</aside>
</section>
......@@ -317,7 +317,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#rid">rid</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L4">config/messageInterfaces.ts:4</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L4">config/messageInterfaces.ts:4</a></li>
</ul>
</aside>
</section>
......@@ -328,7 +328,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#t">t</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L6">config/messageInterfaces.ts:6</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L6">config/messageInterfaces.ts:6</a></li>
</ul>
</aside>
</section>
......@@ -339,7 +339,7 @@
<aside class="tsd-sources">
<p>Inherited from <a href="../interfaces/_config_messageinterfaces_.imessage.html">IMessage</a>.<a href="../interfaces/_config_messageinterfaces_.imessage.html#urls">urls</a></p>
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/messageInterfaces.ts#L13">config/messageInterfaces.ts:13</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/messageInterfaces.ts#L13">config/messageInterfaces.ts:13</a></li>
</ul>
</aside>
</section>
......@@ -356,7 +356,7 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/lib/message.ts#L19">lib/message.ts:19</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/lib/message.ts#L19">lib/message.ts:19</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>rocketchat-sdk</title>
<title>@rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">rocketchat-sdk</a>
<a href="index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -54,7 +54,7 @@
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> rocketchat-sdk</h1>
<h1> @rocket.chat/sdk</h1>
</div>
</div>
</header>
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>rocketchat-sdk</title>
<title>@rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">rocketchat-sdk</a>
<a href="index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -54,7 +54,7 @@
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> rocketchat-sdk</h1>
<h1> @rocket.chat/sdk</h1>
</div>
</div>
</header>
......@@ -85,8 +85,8 @@
<li><code>methodCache</code> - Manages results cache for calls to server (via LRU cache)</li>
</ul>
<p>Access these modules by importing them from SDK, e.g:</p>
<p>ES6 <code>import { driver, methodCache } from &#39;rocketchat-sdk&#39;</code></p>
<p>ES5 <code>const { driver, methodCache } = require(&#39;rocketchat-sdk&#39;)</code></p>
<p>ES6 <code>import { driver, methodCache } from &#39;@rocket.chat/sdk&#39;</code></p>
<p>ES5 <code>const { driver, methodCache } = require(&#39;@rocket.chat/sdk&#39;)</code></p>
<p>See <a href="https://www.npmjs.com/package/asteroid">Asteroid</a> docs for methods that can be called from that API.</p>
<p>Any Rocket.Chat server method can be called via <code>driver.callMethod</code>,
<code>driver.cacheCall</code> or <code>driver.asyncCall</code>. Server methods are not fully
......@@ -302,14 +302,14 @@
and subscription methods are functional. And it helps to manually run your SDK
interactions (i.e. bots) locally while in development.</p>
<h2 id="use-as-dependency">Use as Dependency</h2>
<p><code>yarn add rocketchat-sdk</code> or <code>npm install --save rocketchat-sdk</code></p>
<p><code>yarn add @rocket.chat/sdk</code> or <code>npm install --save @rocket.chat/sdk</code></p>
<p>ES6 module, using async</p>
<pre><code><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> rocketchat <span class="hljs-keyword">from</span> <span class="hljs-string">'rocketchat-sdk'</span>
<pre><code><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> rocketchat <span class="hljs-keyword">from</span> <span class="hljs-string">'@rocket.chat/sdk'</span>
<span class="hljs-keyword">const</span> asteroid = <span class="hljs-keyword">await</span> rocketchat.driver.connect({ <span class="hljs-attr">host</span>: <span class="hljs-string">'localhost:3000'</span> })
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'connected'</span>, asteroid)
</code></pre><p>ES5 module, using callback</p>
<pre><code><span class="hljs-keyword">const</span> rocketchat = <span class="hljs-built_in">require</span>(<span class="hljs-string">'rocketchat-sdk'</span>)
<pre><code><span class="hljs-keyword">const</span> rocketchat = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@rocket.chat/sdk'</span>)
rocketchat.driver.connect({ <span class="hljs-attr">host</span>: <span class="hljs-string">'localhost:3000'</span> }, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, asteroid</span>) </span>{
<span class="hljs-keyword">if</span> (err) <span class="hljs-built_in">console</span>.error(err)
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IAsteroid | rocketchat-sdk</title>
<title>IAsteroid | @rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">rocketchat-sdk</a>
<a href="../index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -149,7 +149,7 @@
<div class="tsd-signature tsd-kind-icon">apply<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L22">config/asteroidInterfaces.ts:22</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L22">config/asteroidInterfaces.ts:22</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -183,7 +183,7 @@
<div class="tsd-signature tsd-kind-icon">call<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L21">config/asteroidInterfaces.ts:21</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L21">config/asteroidInterfaces.ts:21</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -217,7 +217,7 @@
<div class="tsd-signature tsd-kind-icon">connect<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L9">config/asteroidInterfaces.ts:9</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L9">config/asteroidInterfaces.ts:9</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -242,7 +242,7 @@
<div class="tsd-signature tsd-kind-icon">create<wbr>User<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L11">config/asteroidInterfaces.ts:11</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L11">config/asteroidInterfaces.ts:11</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -279,7 +279,7 @@
<div class="tsd-signature tsd-kind-icon">ddp<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">EventEmitter</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L24">config/asteroidInterfaces.ts:24</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L24">config/asteroidInterfaces.ts:24</a></li>
</ul>
</aside>
</section>
......@@ -289,7 +289,7 @@
<div class="tsd-signature tsd-kind-icon">disconnect<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L10">config/asteroidInterfaces.ts:10</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L10">config/asteroidInterfaces.ts:10</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -314,7 +314,7 @@
<div class="tsd-signature tsd-kind-icon">get<wbr>Collection<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L23">config/asteroidInterfaces.ts:23</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L23">config/asteroidInterfaces.ts:23</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -345,7 +345,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>With<wbr>Facebook<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L13">config/asteroidInterfaces.ts:13</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L13">config/asteroidInterfaces.ts:13</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -376,7 +376,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>With<wbr>Github<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L16">config/asteroidInterfaces.ts:16</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L16">config/asteroidInterfaces.ts:16</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -407,7 +407,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>With<wbr>Google<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L14">config/asteroidInterfaces.ts:14</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L14">config/asteroidInterfaces.ts:14</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -438,7 +438,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>WithLDAP<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L12">config/asteroidInterfaces.ts:12</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L12">config/asteroidInterfaces.ts:12</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -469,7 +469,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>With<wbr>Password<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L17">config/asteroidInterfaces.ts:17</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L17">config/asteroidInterfaces.ts:17</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -503,7 +503,7 @@
<div class="tsd-signature tsd-kind-icon">login<wbr>With<wbr>Twitter<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L15">config/asteroidInterfaces.ts:15</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L15">config/asteroidInterfaces.ts:15</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -534,7 +534,7 @@
<div class="tsd-signature tsd-kind-icon">logout<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L18">config/asteroidInterfaces.ts:18</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L18">config/asteroidInterfaces.ts:18</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -559,7 +559,7 @@
<div class="tsd-signature tsd-kind-icon">subscribe<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L19">config/asteroidInterfaces.ts:19</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L19">config/asteroidInterfaces.ts:19</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
......@@ -593,7 +593,7 @@
<div class="tsd-signature tsd-kind-icon">subscriptions<span class="tsd-signature-symbol">:</span> <a href="_config_asteroidinterfaces_.isubscription.html" class="tsd-signature-type">ISubscription</a><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/665a0d5/src/config/asteroidInterfaces.ts#L20">config/asteroidInterfaces.ts:20</a></li>
<li>Defined in <a href="https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/b3f6e1b/src/config/asteroidInterfaces.ts#L20">config/asteroidInterfaces.ts:20</a></li>
</ul>
</aside>
</section>
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ICollection | rocketchat-sdk</title>
<title>ICollection | @rocket.chat/sdk</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
......@@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">rocketchat-sdk</a>
<a href="../index.html" class="title">@rocket.chat/sdk</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
......@@ -100,7 +100,7 @@
<div class="tsd-signature tsd-kind-icon">insert<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>