Skip to content

Commit

Permalink
Add cookie support (#61)
Browse files Browse the repository at this point in the history
* Add support for cookie based authentication >:[
* Remove support for user token based authentication >:[[[
* Add additional documentation, fix examples, reorg README slightly
* Bump package to 2.0.0 (Breaking change)

Resolves #60
  • Loading branch information
jackellenberger authored Jul 21, 2021
1 parent 0f5f7a3 commit b90507e
Show file tree
Hide file tree
Showing 46 changed files with 1,355 additions and 696 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ node_modules/
package-lock.json
emojme@*

# Moving files around
*.old

# OSX Garb
.DS_Store
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 2.0.0
* Require cookie tokens and cookies >:[
* All operations that previously required a (subdomain, token) tuple now require a (subdomain, token, cookie) tuple.
* This means the addition of a `--cookie` command line argument.
* cookie is also now the third ordered argument in emojme module methods.
* Check the readme for how to collect a cookie.
* alias --subdomain to --domain for kicks
* Reduce adminList request rate slightly to dodge rate limiting.
* AuthPairs are now AuthTuples as they represent subdomain, token, and cookie.

# 1.9.1
* Add Emojme chrome extension to README
* Resolve (#59), sanitizing user names for disk interaction
Expand Down
300 changes: 133 additions & 167 deletions README.md

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Commands
```
Usage: emojme [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
download download all emoji from given subdomain
upload upload source emoji to given subdomain
add upload source emoji to given subdomain
user-stats get emoji statistics for given user on given subdomain
sync get emoji statistics for given user on given subdomain
favorites get favorite emoji and personal emoji usage statistics
help [cmd] display help for [cmd]
```

## emojme download
```
Usage: emojme-download [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--save <user> save all of <user>'s emoji to disk at build/$subdomain/$user (default: [])
--save-all save all emoji from all users to disk at build/$subdomain
--save-all-by-user save all emoji from all users to disk at build/$subdomain/$user
-h, --help output usage information
```

## emojme upload
```
Usage: emojme-upload [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--allow-collisions do not cull collisions ever, upload everything just as it is and accept the collisions. This will be faster for known-good uploads, more rate-limiting prone for untrusted uploads.
--avoid-collisions instead of culling collisions, rename the emoji to be uploaded "intelligently"
--prefix <value> prefix all emoji to be uploaded with <value>
--src <value> source file(s) for emoji json or yaml you'd like to upload
-h, --help output usage information
```

## emojme add
```
Usage: emojme-add [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--allow-collisions do not cull collisions ever, upload everything just as it is and accept the collisions. This will be faster for known-good uploads, more rate-limiting prone for untrusted uploads.
--avoid-collisions instead of culling collisions, rename the emoji to be uploaded "intelligently"
--prefix <value> prefix all emoji to be uploaded with <value>
--src <value> source image/gif/#content for emoji you'd like to upload (default: null)
--name <value> name of the emoji from --src that you'd like to upload (default: null)
--alias-for <value> name of the emoji you'd like --name to be an alias of. Specifying this will negate --src (default: null)
-h, --help output usage information
```

## emojme user-stats
```
Usage: emojme-user-stats [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--user <value> slack user you'd like to get stats on. Can be specified multiple times for multiple users. (default: null)
--top <value> the top n users you'd like user emoji statistics on (default: 10)
-h, --help output usage information
```

## emojme sync
```
Usage: emojme-sync [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--src-subdomain [value] subdomain from which to draw emoji for one way sync (default: null)
--src-token [value] token with which to draw emoji for one way sync (default: null)
--src-cookie [value] cookie with which to draw emoji for one way sync (default: null)
--dst-subdomain [value] subdomain to which to emoji will be added is one way sync (default: null)
--dst-token [value] token with which emoji will be added for one way sync (default: null)
--dst-cookie [value] cookie with which emoji will be added for one way sync (default: null)
--dry-run if set to true, nothing will be uploaded or synced
-h, --help output usage information
```

## emojme favorites
```
Usage: emojme-favorites [options]
Options:
-s, --subdomain <value> slack subdomain. Can be specified multiple times, paired with respective token. (default: [])
-d, --domain <value> alias for --subdomain (default: [])
-t, --token <value> slack cookie token. ususaly starts xoxc-... Can be specified multiple times, paired with respective subdomains. User tokens (xoxs-...) are no longer supported. :( (default: [])
-c, --cookie <value> slack cookie. paired with respective subdomains and tokens. (default: [])
-a --auth-json <value> A json-string containing keys "domain", "token", and "cookie", as generated by the Emojme: Emoji Anywhere Chrome Extension. Can be used as a replacement for or in leu of subdomain, token, and cookie options. (default: [])
--bust-cache force a redownload of all cached info.
--no-output prevent writing of files in build/ and log/
--since <value> only consider emoji since the given epoch timestamp
--verbose log debug messages to console
--top <value> (verbose cli only) the top n favorites you'd like to see (default: 10)
--usage (verbose cli only) print emoji usage of favorites in addition to their names
--lite do not attempt to marry favorites with complete adminlist content. Results will contain only emoji name and usage count.
-h, --help output usage information
```
25 changes: 15 additions & 10 deletions docs/emojme-add.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ <h1 class="page-title">
* Note that options can accept both aliases and original emoji at the same time, but ordering can get complicated and honestly I'd skip it if I were you. For each emoji, make sure that every descriptor (src, name, aliasFor) has a value, using `null`s for fields that are not relevant to the current emoji.
*
* @async
* @param {string|string[]} subdomains a single or list of subdomains to add emoji to. Must match respectively to `tokens`
* @param {string|string[]} tokens a single or list of tokens to add emoji to. Must match respectively to `subdomains`
* @param {string|string[]} subdomains a single or list of subdomains to add emoji to. Must match respectively to `token`s and `cookie`s.
* @param {string|string[]} tokens a single or list of tokens to add emoji to. Must match respectively to `subdomain`s and `cookie`s.
* @param {string|string[]} cookies a single or list of cookies used to authenticate access to the given subdomain. Must match respectively to `subdomain`s and `token`s.
* @param {object} options contains singleton or arrays of emoji descriptors.
* @param {string|string[]} [options.src] source image files for the emoji to be added. If no corresponding `options.name` is given, the filename will be used
* @param {string|string[]} [options.name] names of the emoji to be added, overriding filenames if given, and becoming the alias name if an `options.aliasFor` is given
Expand All @@ -136,7 +137,8 @@ <h1 class="page-title">
};
var subdomains = ['mySubdomain1', 'mySubdomain2'] // can add one or multiple
var tokens = ['myToken1', 'myToken2'] // can add one or multiple
var addResults = await emojme.add(subdomains, tokens, addOptions);
var cookies = ['myCookie1', 'myCookie2'] // can add one or multiple
var addResults = await emojme.add(subdomains, tokens, cookies, addOptions);
console.log(userStatsResults);
// {
// mySubomain1: {
Expand All @@ -155,9 +157,10 @@ <h1 class="page-title">
// }
// }
*/
async function add(subdomains, tokens, options) {
async function add(subdomains, tokens, cookies, options) {
subdomains = Helpers.arrayify(subdomains);
tokens = Helpers.arrayify(tokens);
cookies = Helpers.arrayify(cookies);
options = options || {};
const aliases = Helpers.arrayify(options.aliasFor);
const names = Helpers.arrayify(options.name);
Expand Down Expand Up @@ -187,9 +190,9 @@ <h1 class="page-title">
return Promise.reject(new Error('Invalid input. Either not all inputs have been consumed, or not all emoji are well formed. Consider simplifying input, or padding input with `null` values.'));
}

const [authPairs] = Helpers.zipAuthPairs(subdomains, tokens);
const [authTuples] = Helpers.zipAuthTuples(subdomains, tokens, cookies);

const addPromises = authPairs.map(async (authPair) => {
const addPromises = authTuples.map(async (authTuple) => {
let emojiToUpload = []; let
collisions = [];

Expand All @@ -200,7 +203,7 @@ <h1 class="page-title">
if (options.allowCollisions) {
emojiToUpload = inputEmoji;
} else {
const existingEmojiList = await new EmojiAdminList(...authPair, options.output)
const existingEmojiList = await new EmojiAdminList(...authTuple, options.output)
.get(options.bustCache);
const existingNameList = existingEmojiList.map(e => e.name);

Expand All @@ -212,7 +215,7 @@ <h1 class="page-title">
emoji => existingNameList.includes(emoji.name));
}

const emojiAdd = new EmojiAdd(...authPair);
const emojiAdd = new EmojiAdd(...authTuple);
return emojiAdd.upload(emojiToUpload).then((uploadResult) => {
if (uploadResult.errorList &amp;&amp; uploadResult.errorList.length > 1 &amp;&amp; options.output) {
FileUtils.writeJson(`./build/${this.subdomain}.emojiUploadErrors.json`, uploadResult.errorList);
Expand All @@ -235,7 +238,9 @@ <h1 class="page-title">
.option('--alias-for &lt;value>', 'name of the emoji you\'d like --name to be an alias of. Specifying this will negate --src', Cli.list, null)
.parse(process.argv);

return add(program.subdomain, program.token, {
Cli.unpackAuthJson(program);

return add(program.subdomain, program.token, program.cookie, {
src: program.src,
name: program.name,
aliasFor: program.aliasFor,
Expand Down Expand Up @@ -268,7 +273,7 @@ <h1 class="page-title">
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script src="scripts/linenumber.js"></script>
Expand Down
23 changes: 13 additions & 10 deletions docs/emojme-download.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ <h1 class="page-title">
* Download the list of custom emoji that have been added to the given slack instances, by default saving a json of all available relevant data. Optionally save the source images for a given user.
*
* @async
* @param {string|string[]} subdomains a single or list of subdomains to add emoji to. Must match respectively to `tokens`
* @param {string|string[]} tokens a single or list of tokens to add emoji to. Must match respectively to `subdomains`
* @param {string|string[]} subdomains a single or list of subdomains from which to download emoji. Must match respectively to `token`s and `cookie`s.
* @param {string|string[]} tokens a single or list of tokens with which to authenticate. Must match respectively to `subdomain`s and `cookie`s.
* @param {string|string[]} cookies a single or list of cookies used to authenticate access to the given subdomain. Must match respectively to `subdomain`s and `token`s.
* @param {object} options contains singleton or arrays of emoji descriptors.
* @param {string|string[]} [options.save] A user name or array of user names whose emoji source images will be saved. All emoji source images are linked to in the default adminList, but passing a user name here will save that user's emoji to build/&lt;subdomain>/&lt;username>
* @param {boolean} [options.saveAll] if `true`, download all emoji on slack instance from all users to disk in a single location.
Expand All @@ -125,7 +126,7 @@ <h1 class="page-title">
bustCache: true, // make sure this data is fresh
output: true // download the adminList to ./build
};
var downloadResults = await emojme.download('mySubdomain', 'myToken', downloadOptions);
var downloadResults = await emojme.download('mySubdomain', 'myToken', 'myCookie', downloadOptions);
console.log(downloadResults);
// {
// mySubdomain: {
Expand All @@ -144,18 +145,19 @@ <h1 class="page-title">
// }
// }
*/
async function download(subdomains, tokens, options) {
async function download(subdomains, tokens, cookies, options) {
subdomains = Helpers.arrayify(subdomains);
tokens = Helpers.arrayify(tokens);
cookies = Helpers.arrayify(cookies);
options = options || {};

const [authPairs] = Helpers.zipAuthPairs(subdomains, tokens);
const [authTuples] = Helpers.zipAuthTuples(subdomains, tokens, cookies);

const downloadPromises = authPairs.map(async (authPair) => {
const subdomain = authPair[0];
const downloadPromises = authTuples.map(async (authTuple) => {
const subdomain = authTuple[0];
let saveResults = [];

const adminList = new EmojiAdminList(...authPair, options.output);
const adminList = new EmojiAdminList(...authTuple, options.output);
const emojiList = await adminList.get(options.bustCache, options.since);
if ((options.save &amp;&amp; options.save.length) || options.saveAll || options.saveAllByUser) {
saveResults = saveResults.concat(await EmojiAdminList.save(emojiList, subdomain, {
Expand All @@ -177,8 +179,9 @@ <h1 class="page-title">
.option('--save-all', 'save all emoji from all users to disk at build/$subdomain')
.option('--save-all-by-user', 'save all emoji from all users to disk at build/$subdomain/$user')
.parse(process.argv);
Cli.unpackAuthJson(program);

return download(program.subdomain, program.token, {
return download(program.subdomain, program.token, program.cookie, {
save: program.save,
saveAll: program.saveAll,
saveAllByUser: program.saveAllByUser,
Expand Down Expand Up @@ -208,7 +211,7 @@ <h1 class="page-title">
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script src="scripts/linenumber.js"></script>
Expand Down
Loading

0 comments on commit b90507e

Please sign in to comment.