Socket
Socket
Sign inDemoInstall

github-profile-status

Package Overview
Dependencies
41
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

dist/commands/clearCommand.d.ts

37

dist/index.d.ts

@@ -1,34 +0,21 @@

import { Emoji } from './Emoji';
import { BasicLoginOptions } from './login/BasicLoginProvider';
import { SessionLoginOptions } from './login/SessionLoginProvider';
interface Status {
message: string;
emoji: Emoji;
busy: boolean;
}
interface ConstructorOptions {
debug?: boolean;
}
export declare class GithubProfileStatus {
import * as Login from './login/login';
import { Status } from './types';
export declare class GitHubProfileStatus {
private options;
private loginProvider;
constructor(options: ConstructorOptions & BasicLoginOptions);
constructor(options: ConstructorOptions & SessionLoginOptions);
constructor(options: Login.BasicLoginOptions);
constructor(options: Login.SessionLoginOptions);
/**
* Gets the current user profile status
* Clears the user profile status
*/
clear(): Promise<boolean>;
/**
* Gets the user profile status
*/
get(): Promise<Status>;
/**
* Sets the user profile status
* Updates the user profile status
*/
set(status: Partial<Status>): Promise<boolean>;
/**
* Returns references for the element handlers of user profile status fields
*/
private getFormFields;
/**
* Fetches a single property of an element handle as JSON
*/
private getPropertyAsJSON;
private execCommand;
}
export {};

@@ -37,13 +37,20 @@ "use strict";

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var BasicLoginProvider_1 = require("./login/BasicLoginProvider");
var SessionLoginProvider_1 = require("./login/SessionLoginProvider");
var GithubProfileStatus = /** @class */ (function () {
function GithubProfileStatus(options) {
var Commands = __importStar(require("./commands/commands"));
var Login = __importStar(require("./login/login"));
var GitHubProfileStatus = /** @class */ (function () {
function GitHubProfileStatus(options) {
this.options = options;
if (SessionLoginProvider_1.SessionLoginProvider.validateOptions(options)) {
this.loginProvider = new SessionLoginProvider_1.SessionLoginProvider(options);
if (Login.SessionLoginProvider.validateOptions(options)) {
this.loginProvider = new Login.SessionLoginProvider(options);
}
else if (BasicLoginProvider_1.BasicLoginProvider.validateOptions(options)) {
this.loginProvider = new BasicLoginProvider_1.BasicLoginProvider(options);
else if (Login.BasicLoginProvider.validateOptions(options)) {
this.loginProvider = new Login.BasicLoginProvider(options);
}

@@ -55,31 +62,8 @@ else {

/**
* Gets the current user profile status
* Clears the user profile status
*/
GithubProfileStatus.prototype.get = function () {
GitHubProfileStatus.prototype.clear = function () {
return __awaiter(this, void 0, void 0, function () {
var homePage, _a, emoji, message, busy, _b, emojiValue, messageValue, busyValue;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this.loginProvider.login()];
case 1:
homePage = _c.sent();
return [4 /*yield*/, this.getFormFields(homePage)];
case 2:
_a = _c.sent(), emoji = _a.emoji, message = _a.message, busy = _a.busy;
return [4 /*yield*/, Promise.all([
this.getPropertyAsJSON(emoji, 'value'),
this.getPropertyAsJSON(message, 'value'),
this.getPropertyAsJSON(busy, 'checked'),
])];
case 3:
_b = _c.sent(), emojiValue = _b[0], messageValue = _b[1], busyValue = _b[2];
return [4 /*yield*/, homePage.browser().close()];
case 4:
_c.sent();
return [2 /*return*/, {
busy: busyValue,
emoji: emojiValue,
message: messageValue,
}];
}
return __generator(this, function (_a) {
return [2 /*return*/, this.execCommand(Commands.ClearCommand)];
});

@@ -89,43 +73,8 @@ });

/**
* Sets the user profile status
* Gets the user profile status
*/
GithubProfileStatus.prototype.set = function (status) {
GitHubProfileStatus.prototype.get = function () {
return __awaiter(this, void 0, void 0, function () {
var homePage, fields;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.loginProvider.login()];
case 1:
homePage = _a.sent();
return [4 /*yield*/, this.getFormFields(homePage)];
case 2:
fields = _a.sent();
if (!status.message) return [3 /*break*/, 4];
return [4 /*yield*/, homePage.evaluate(function (el, emoji) { return (el.value = emoji); }, fields.message, status.message)];
case 3:
_a.sent();
_a.label = 4;
case 4:
if (!status.emoji) return [3 /*break*/, 6];
return [4 /*yield*/, homePage.evaluate(function (el, emoji) { return (el.value = emoji); }, fields.emoji, status.emoji)];
case 5:
_a.sent();
_a.label = 6;
case 6:
if (status.busy !== undefined) {
homePage.evaluate(function (el, isBusy) {
el.checked = isBusy;
}, fields.busy, status.busy);
}
return [4 /*yield*/, homePage.evaluate(function (el) { return el.submit(); }, fields.form)];
case 7:
_a.sent();
return [4 /*yield*/, homePage.waitForResponse(function (response) { return response.url().includes('/users/status') && response.status() === 200; })];
case 8:
_a.sent();
return [4 /*yield*/, homePage.browser().close()];
case 9:
_a.sent();
return [2 /*return*/, true];
}
return [2 /*return*/, this.execCommand(Commands.GetCommand)];
});

@@ -135,42 +84,24 @@ });

/**
* Returns references for the element handlers of user profile status fields
* Updates the user profile status
*/
GithubProfileStatus.prototype.getFormFields = function (page) {
GitHubProfileStatus.prototype.set = function (status) {
return __awaiter(this, void 0, void 0, function () {
var form, _a, message, emoji, busy;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, page.$('form[action^="/users/status"]')];
case 1:
form = _b.sent();
if (!form) {
throw new Error('Could find status form');
}
return [4 /*yield*/, Promise.all([
form.$('input[name="message"]'),
form.$('input[name="emoji"]'),
form.$('input[name="limited_availability"]'),
])];
case 2:
_a = _b.sent(), message = _a[0], emoji = _a[1], busy = _a[2];
if (!(message && emoji && busy)) {
throw new Error('Could not find status form inputs');
}
return [2 /*return*/, { busy: busy, emoji: emoji, form: form, message: message }];
}
return __generator(this, function (_a) {
return [2 /*return*/, this.execCommand(Commands.SetCommand, status)];
});
});
};
/**
* Fetches a single property of an element handle as JSON
*/
GithubProfileStatus.prototype.getPropertyAsJSON = function (element, propertyName) {
GitHubProfileStatus.prototype.execCommand = function (command) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
return __awaiter(this, void 0, void 0, function () {
var property;
var page;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, element.getProperty(propertyName)];
case 0: return [4 /*yield*/, this.loginProvider.login()];
case 1:
property = _a.sent();
return [2 /*return*/, property.jsonValue()];
page = _a.sent();
return [2 /*return*/, new (command.bind.apply(command, [void 0, page].concat(args)))().exec()];
}

@@ -180,4 +111,4 @@ });

};
return GithubProfileStatus;
return GitHubProfileStatus;
}());
exports.GithubProfileStatus = GithubProfileStatus;
exports.GitHubProfileStatus = GitHubProfileStatus;
{
"name": "github-profile-status",
"version": "0.2.0",
"version": "0.3.0",
"description": "Update the status of your GitHub profile programmatically",
"main": "dist/index.js",
"repository": "https://github.com/wsmd/github-status-updater",
"homepage": "https://github.com/wsmd/github-status-updater",
"bugs": "https://github.com/wsmd/github-status-updater/issues",
"types": "dist/index.d.ts",
"repository": "https://github.com/wsmd/github-profile-status",
"homepage": "https://github.com/wsmd/github-profile-status",
"bugs": "https://github.com/wsmd/github-profile-status/issues",
"author": "Waseem Dahman <dwaseem@icloud.com>",

@@ -24,3 +25,8 @@ "license": "MIT",

"build": "tsc",
"prepack": "rm -rf dist && yarn build"
"prepack": "rm -rf dist && yarn build",
"lint": "tslint --project .",
"test": "yarn typecheck && yarn lint && yarn test:headless",
"test:build": "yarn test:cleanup && tsc --build test/tsconfig.json",
"test:cleanup": "rm -rf test/tmp",
"test:headless": "yarn test:build && node -r dotenv/config test/tmp/test"
},

@@ -31,3 +37,6 @@ "dependencies": {

"devDependencies": {
"@types/dotenv": "^6.1.1",
"@types/puppeteer": "^1.12.3",
"dotenv": "^7.0.0",
"tslint": "^5.14.0",
"typescript": "^3.3.4000"

@@ -34,0 +43,0 @@ },

@@ -6,2 +6,3 @@ <div align="center">

[![Current Release](https://img.shields.io/npm/v/github-profile-status.svg)](https://www.npmjs.com/package/github-profile-status)
[![CI Build](https://travis-ci.org/wsmd/github-profile-status.svg?branch=master)](https://travis-ci.org/wsmd/github-profile-status)
[![Licence](https://img.shields.io/github/license/wsmd/github-profile-status.svg)](https://github.com/wsmd/github-profile-status/blob/master/LICENSE)

@@ -20,7 +21,8 @@

- [Constructor](#constructor)
- [`new GithubProfileStatus(options: ConstructorOptions)`](#new-githubprofilestatusoptions-constructoroptions)
- [`new GitHubProfileStatus(options: ConstructorOptions)`](#new-githubprofilestatusoptions-constructoroptions)
- [Constructor Options](#constructor-options)
- [Methods](#methods)
- [`GithubProfileStatus.get(): Promise<Status>`](#githubprofilestatusget-promisestatus)
- [`GithubProfileStatus.set(status: Status): Promise<boolean>`](#githubprofilestatussetstatus-status-promiseboolean)
- [`GitHubProfileStatus.get(): Promise<Status>`](#githubprofilestatusget-promisestatus)
- [`GitHubProfileStatus.set(status: Status): Promise<boolean>`](#githubprofilestatussetstatus-status-promiseboolean)
- [`GitHubProfileStatus.clear(): Promise<boolean>`](#githubprofilestatusclear-promiseboolean)
- [Status Object](#status-object)

@@ -35,3 +37,3 @@ - [Authentication & Security Disclaimer](#authentication--security-disclaimer)

Github recently added a cool [new feature](https://github.blog/changelog/2019-01-09-set-your-status/) that allows users to set a status on their Github profile!
GitHub recently added a cool [new feature](https://github.blog/changelog/2019-01-09-set-your-status/) that allows users to set a status on their GitHub profile!

@@ -47,5 +49,5 @@ > You can now set your status on GitHub! Use your status to share specific information with only your organization, or share a status with all of GitHub! Optionally, you can indicate that you’re busy so your collaborators can determine whether to mention someone else for a quicker response.

Unfortunately, at the time of writing this, this feature is only available via the Github web interface, and it is not possible to update the profile status via the API.
Unfortunately, at the time of writing this, this feature is only available via the GitHub web interface, and it is not possible to update the profile status via the API.
Therefore, I built this tool to set the status of my Github profile programmatically.
Therefore, I built this tool to update the status of my GitHub profile programmatically.

@@ -61,11 +63,8 @@ ## Installation

```js
import { GithubProfileStatus } from 'github-profile-status';
import { GitHubProfileStatus } from 'github-profile-status';
async function main() {
const profileStatus = new GithubProfileStatus({
const profileStatus = new GitHubProfileStatus({
// login using a user_session cookie
userSession: process.env.USER_SESSION,
// or by using username/password
username: process.env.GITHUB_USERNAME,
password: process.env.GITHUB_PASSWORD,
});

@@ -82,2 +81,5 @@

const status = await profileStatus.get();
// clears your github profile status
const cleared = await profileStatus.clear();
}

@@ -90,3 +92,3 @@ ```

#### `new GithubProfileStatus(options: ConstructorOptions)`
#### `new GitHubProfileStatus(options: ConstructorOptions)`

@@ -107,10 +109,14 @@ Creates a new github profile status object using the [provided options](#constructor-options).

#### `GithubProfileStatus.get(): Promise<Status>`
#### `GitHubProfileStatus.get(): Promise<Status>`
Retrieves the user profile status. Returns a Promise that resolves with the [status object](#status-object).
#### `GithubProfileStatus.set(status: Status): Promise<boolean>`
#### `GitHubProfileStatus.set(status: Status): Promise<boolean>`
Updates the user profile status using the provided [status parameters](#status-object). All parameters are optional. If you omit certain parameters, they will remain as they are.
Updates the user profile status using the provided [status parameters](#status-object). All parameters are optional. If you omit certain parameters, they will remain as they are. Returns a Promise that resolves to a boolean indicating a successful operation
#### `GitHubProfileStatus.clear(): Promise<boolean>`
Clears the user profile status. Returns a Promise that resolves to a boolean indicating a successful operation.
### Status Object

@@ -122,14 +128,16 @@

- `message: string`: The status message.
- `emoji: string`: The emoji alias that will be displayed on the status. The emoji alias should be provided in this format `:emoji_name:`. The list of all possible emojis is [available here](https://github.com/wsmd/github-profile-status/blob/master/lib/Emoji.d.ts).
- `emoji: string`: The emoji alias that will be displayed on the status. The emoji alias should be provided in this format `:emoji_name:`. The list of all possible emojis is [available here](https://github.com/wsmd/github-profile-status/blob/master/lib/types.ts#L7).
## Authentication & Security Disclaimer
I built this tool for my own personal use. Since the functionality is not provided by the Github API, this tool **does not use any of GitHub's official authentication methods**.
I built this tool for my own personal use. Since this functionality is not provided by the GitHub API, there are a few points to highlight regarding authentication and security:
This tool requires either the `user_session` cookie from an active login session of the user account or the user basic login information: username and password. This tool will use this information to connect to the user account via `https://github.com` and perform a status update/check. **I highly encourage providing this information using environment variables**.
- This tool **does not use any of GitHub's official authentication methods**.
- This tool requires either the `user_session` cookie from an active login session of the user account or the user basic login information: username and password.
- This tool uses this information to imitate a user login via `https://github.com` and perform a status update/check.
- **It is highly encouraged that you provide this information using environment variables**, and not include them in your code.
- While this tool **does not persist or share** any of the information provided, it is very important that you are aware of this limitation. Please use at your own risk.
While this tool **does not persist or share** any information provided, it is very important that you are aware of the limitation. Please use at your own risk.
## Licence
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc