Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: PR Checks

on:
pull_request:
branches:
- master

jobs:
test:
name: Test
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install dependencies
run: yarn install
- name: Run tests
run: yarn run test
env:
CI: true
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install dependencies
run: yarn install
- name: Run lint
run: yarn run lint
dtslint:
name: Lint Typings
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 12
- name: Install dependencies
run: yarn install
- name: Run dtslint
run: yarn run dtslint
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"source": "twitter.js",
"main": "dist/twitter.js",
"module": "dist/twitter.m.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"files": [
"dist",
"index.d.ts"
"types/index.d.ts"
],
"repository": "draftbit/twitter-lite",
"homepage": "https://github.com/draftbit/twitter-lite",
Expand Down Expand Up @@ -36,6 +36,7 @@
"@types/node": "^13.13.4",
"bundlesize": "^0.18.0",
"dotenv": "^8.2.0",
"dtslint": "^4.0.6",
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.8.2",
"flow-bin": "^0.123.0",
Expand All @@ -46,6 +47,7 @@
},
"scripts": {
"lint": "eslint --fix ./",
"dtslint": "dtslint types",
"prepare": "microbundle {stream,twitter}.js && bundlesize",
"test": "eslint --fix . && jest --detectOpenHandles",
"release": "npm run -s prepare && npm test && git tag $npm_package_version && git push && git push --tags && npm publish"
Expand All @@ -56,15 +58,16 @@
}
},
"jest": {
"testEnvironment": "node"
"testEnvironment": "node",
"testRegex": "/test/.*\\.test\\.js"
},
"bundlesize": [
{
"path": "dist/**.js",
"maxSize": "3 kB"
},
{
"path": "index.d.ts",
"path": "types/index.d.ts",
"maxSize": "3 kB"
}
]
Expand Down
19 changes: 0 additions & 19 deletions tsconfig.json

This file was deleted.

74 changes: 39 additions & 35 deletions index.d.ts → types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Minimum TypeScript Version: 3.8

/**
* Typings for twitter-lite
*
Expand Down Expand Up @@ -56,8 +58,8 @@ export default class Twitter {

/**
* Construct the data and headers for an authenticated HTTP request to the Twitter API
* @param {'GET | 'POST' | 'PUT'}
* @param {string} resource - the API endpoint
* @param method HTTP method to use when calling this endpoint
* @param resource The API endpoint to be called
*/
private _makeRequest(
method: 'GET' | 'POST' | 'PUT',
Expand All @@ -70,34 +72,34 @@ export default class Twitter {

/**
* Send a GET request
* @type {T = any} Expected type for the response from this request, generally `object` or `array`.
* @param {string} resource - endpoint, e.g. `followers/ids`
* @param {object} [parameters] - optional parameters
* @returns {Promise<T>} Promise resolving to the response from the Twitter API.
* @type Expected type for the response from this request, generally `object` or `array`.
* @param resource Endpoint, e.g. `followers/ids`
* @param [parameters] Optional parameters
* @returns Promise resolving to the response from the Twitter API.
* The `_header` property will be set to the Response headers (useful for checking rate limits)
*/
public get<T = any>(resource: string, parameters?: object): Promise<T>;
get<T = any>(resource: string, parameters?: object): Promise<T>;

/**
* Send a POST request
* @type {T = any} Expected type for the response from this request, generally `object` or `array`.
* @param {string} resource - endpoint, e.g. `users/lookup`
* @param {object} body - POST parameters object.
* @type Expected type for the response from this request, generally `object` or `array`.
* @param resource Endpoint, e.g. `users/lookup`
* @param body POST parameters object.
* Will be encoded appropriately (JSON or urlencoded) based on the resource
* @returns {Promise<any>} Promise resolving to the response from the Twitter API.
* @returns Promise resolving to the response from the Twitter API.
* The `_header` property will be set to the Response headers (useful for checking rate limits)
*/
public post<T = any>(resource: string, body: object): Promise<T>;
post<T = any>(resource: string, body: object): Promise<T>;

/**
* Send a PUT request
* @type {T = any} Expected type for the response from this request, generally `object` or `array`.
* @param {string} resource - endpoint e.g. `direct_messages/welcome_messages/update`
* @param {object} parameters - required or optional query parameters
* @param {object} body - PUT request body
* @returns {Promise<any>} Promise resolving to the response from the Twitter API.
* @type Expected type for the response from this request, generally `object` or `array`.
* @param resource Endpoint e.g. `direct_messages/welcome_messages/update`
* @param parameters Required or optional query parameters
* @param body PUT request body
* @returns Promise resolving to the response from the Twitter API.
*/
public put<T = any>(
put<T = any>(
resource: string,
parameters: object,
body: object
Expand All @@ -106,18 +108,18 @@ export default class Twitter {
/**
* Open a stream to a specified endpoint
*
* @param {string} resource - endpoint, e.g. `statuses/filter`
* @param {object} parameters
* @returns {Stream}
* @param resource Endpoint, e.g. `statuses/filter`
* @param parameters Parameters for this endpoint
* @returns Resulting stream
*/
public stream(resource: string, parameters: object): Stream;
stream(resource: string, parameters: object): Stream;
}

/* In reality snowflakes are BigInts. Once BigInt is supported by browsers and Node per default, we could adjust this type.
Currently Twitter themselves convert it to strings for the API though, so this change will come some time in the far future. */
type snowflake = string;
export type snowflake = string;

interface TwitterOptions {
export interface TwitterOptions {
/** "api" is the default (change for other subdomains) */
subdomain?: string;
/** version "1.1" is the default (change for other subdomains) */
Expand All @@ -136,43 +138,45 @@ interface TwitterOptions {
bearer_token?: string;
}

type OauthToken = string;
type OauthTokenSecret = string;
type AuthType = 'App' | 'User';
export type OauthToken = string;
export type OauthTokenSecret = string;
export type AuthType = 'App' | 'User';

interface KeySecret {
export interface KeySecret {
key: string;
secret: string;
}

interface AccessTokenOptions {
/** If using the OAuth web-flow, set these parameters to the values returned in the callback URL. If you are using out-of-band OAuth, set the value of oauth_verifier to the pin-code.
* The oauth_token here must be the same as the oauth_token returned in the request_token step.*/
export interface AccessTokenOptions {
/**
* If using the OAuth web-flow, set these parameters to the values returned in the callback URL. If you are using out-of-band OAuth, set the value of oauth_verifier to the pin-code.
* The oauth_token here must be the same as the oauth_token returned in the request_token step.
*/
oauth_verifier: string | number;
oauth_token: string;
}

interface BearerResponse {
export interface BearerResponse {
token_type: 'bearer';
access_token: string;
}

type TokenResponse =
export type TokenResponse =
| {
oauth_token: OauthToken;
oauth_token_secret: OauthTokenSecret;
oauth_callback_confirmed: 'true';
}
| { oauth_callback_confirmed: 'false' };

interface AccessTokenResponse {
export interface AccessTokenResponse {
oauth_token: string;
oauth_token_secret: string;
user_id: snowflake;
screen_name: string;
}

declare class Stream extends EventEmitter {
export class Stream extends EventEmitter {
constructor();

parse(buffer: Buffer): void;
Expand Down
Loading