Skip to content

Commit

Permalink
feat: add optional debugging via the debug module
Browse files Browse the repository at this point in the history
For information on how the `debug` module works see the instructions at
https://npmjs.com/package/debug. snoots uses the `snoots:` namespace for
all logging. To enable all logs, use `DEBUG='snoots:*'`.

This only adds partial logging. Currently only the Gateways are properly
configured for decent logs, but more will be coming in the future.
  • Loading branch information
thislooksfun committed Feb 12, 2022
1 parent d4c8bee commit fbb7bb3
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 47 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rules:
deprecation/deprecation: error
import/first: error
import/no-default-export: error
no-console: error
promise/prefer-await-to-callbacks: error
promise/prefer-await-to-then: error
simple-import-sort/exports: error
Expand Down
155 changes: 115 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"camelcase": "^6.3.0",
"debug": "^4.3.3",
"got": "^11.8.3",
"tslib": "^2.3.1"
},
Expand All @@ -37,6 +38,7 @@
"@semantic-release/github": "^8.0.2",
"@semantic-release/npm": "^9.0.0",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/debug": "^4.1.7",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
Expand All @@ -61,6 +63,7 @@
"npm-run-all": "^4.1.5",
"prettier": "2.5.1",
"semantic-release": "^19.0.2",
"supports-color": "^9.2.1",
"ts-jest": "^27.1.3",
"typedoc": "~0.22.11",
"typescript": "~4.5.5"
Expand Down
13 changes: 13 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
} from "./controls";
import { AnonGateway } from "./gateway/anon";
import { OauthGateway } from "./gateway/oauth";
import { makeDebug } from "./helper/debug";

const debug = makeDebug("class:Client");

/**
* Options for instantiating a Client
Expand Down Expand Up @@ -147,12 +150,21 @@ export class Client {
* @param options The options to configure this client with.
*/
constructor(options: ClientOptions, _gateway?: Gateway) {
debug("Creating new Client from options %O", options);
debug("Has auth = %b; has creds = %b", options.auth, options.creds);

if (_gateway) {
this.gateway = _gateway;
debug("Using given gateway; type = %s", this.gateway.constructor.name);
} else {
this.gateway = options.creds
? new OauthGateway(options.auth, options.creds, options.userAgent)
: new AnonGateway(options.userAgent);

debug(
"Created Gateway for client; type = %s",
this.gateway.constructor.name
);
}

// Set up controls after we have initialized the internal state.
Expand Down Expand Up @@ -209,6 +221,7 @@ export class Client {
code: string,
redirectUri: string
): Promise<InstanceType<Self>> {
debug("Creating client from auth code '%s'", code);
if (!options.creds) throw "No creds";

const gateway = await OauthGateway.fromAuthCode(
Expand Down

0 comments on commit fbb7bb3

Please sign in to comment.