Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@devts/authjs

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devts/authjs - npm Package Compare versions

Comparing version
0.0.15
to
0.0.16
+4
lib/common/fetch.interface.d.ts
export interface IErrorResponse {
readonly status: number;
readonly rawbody: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+1
-0
export * from "./result.interface";
export * from "./is";
export * from "./fetch.interface";

@@ -19,1 +19,2 @@ "use strict";

__exportStar(require("./is"), exports);
__exportStar(require("./fetch.interface"), exports);

@@ -90,1 +90,6 @@ export interface IOauth2Options {

}
export interface IErrorBody {
error: string;
error_description: string;
error_uri: string;
}
+5
-4

@@ -0,6 +1,7 @@

import { IErrorResponse, IResult } from "../../common";
import { IEmail, IOauth2Options, ITokens, IUser } from "./interface";
export declare const getLoginUri: (options: IOauth2Options) => string;
export declare const getTokens: (options: IOauth2Options) => (code: string) => Promise<import("../..").IResult<ITokens, string>>;
export declare const api: <T>(path: string) => (access_token: string) => Promise<import("../..").IResult<T, string>>;
export declare const getUser: (access_token: string) => Promise<import("../..").IResult<IUser, string>>;
export declare const getEmails: (access_token: string) => Promise<import("../..").IResult<IEmail[], string>>;
export declare const getTokens: (options: IOauth2Options) => (code: string) => Promise<IResult<ITokens, IErrorResponse>>;
export declare const api: <T>(path: string) => (access_token: string) => Promise<IResult<T, IErrorResponse>>;
export declare const getUser: (access_token: string) => Promise<IResult<IUser, IErrorResponse>>;
export declare const getEmails: (access_token: string) => Promise<IResult<IEmail[], IErrorResponse>>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEmails = exports.getUser = exports.api = exports.getTokens = exports.getLoginUri = void 0;
const common_1 = require("../../common");
const fetcher_1 = require("../../utils/fetcher");

@@ -21,14 +22,28 @@ const LOGIN_URL = "https://github.com/login/oauth/authorize";

exports.getLoginUri = getLoginUri;
const getTokens = (options) => (code) => fetcher_1.Fetcher.post({
uri: ACCESS_TOKEN_URL,
body: {
client_id: options.client_id,
client_secret: options.client_secret,
code
},
headers: {
Accept: "application/json",
"Content-Type": "application/json"
const getTokens = (options) => async (code) => {
const response = await fetcher_1.Fetcher.post({
uri: ACCESS_TOKEN_URL,
body: {
client_id: options.client_id,
client_secret: options.client_secret,
code
},
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
status: [200]
});
if ((0, common_1.isError)(response))
return response;
if ("error" in response.result &&
"error_description" in response.result &&
"error_uri" in response.result) {
return {
type: "error",
result: { status: 401, rawbody: JSON.stringify(response.result) }
};
}
});
return { type: "ok", result: response.result };
};
exports.getTokens = getTokens;

@@ -41,3 +56,4 @@ const api = (path) => (access_token) => fetcher_1.Fetcher.get({

"X-Github-Api-Version": "2022-11-28"
}
},
status: [200]
});

@@ -44,0 +60,0 @@ exports.api = api;

@@ -1,4 +0,5 @@

import { IMeRequestParameter, IMeResponse, IOauth2Options, ITokens } from "./interface";
import { IErrorResponse, IResult } from "../../common";
import { IMeResponse, IOauth2Options, ITokens } from "./interface";
export declare const getLoginUri: (options: IOauth2Options) => string;
export declare const getTokens: ({ client_id, client_secret, redirect_uri }: IOauth2Options) => (code: string) => Promise<import("../..").IResult<ITokens, string>>;
export declare const getMe: ({ secure_resource, property_keys }: IMeRequestParameter) => (access_token: string) => Promise<import("../..").IResult<IMeResponse, string>>;
export declare const getTokens: ({ client_id, client_secret, redirect_uri }: IOauth2Options) => (code: string) => Promise<IResult<ITokens, IErrorResponse>>;
export declare const getMe: (access_token: string) => Promise<IResult<IMeResponse, IErrorResponse>>;

@@ -35,17 +35,11 @@ "use strict";

"Content-type": "application/x-www-form-urlencoded;charset=utf-8"
}
},
status: [200]
});
exports.getTokens = getTokens;
const getMe = ({ secure_resource, property_keys }) => (access_token) => fetcher_1.Fetcher.post({
const getMe = (access_token) => fetcher_1.Fetcher.get({
uri: API_URL + "/v2/user/me",
body: new URLSearchParams({
grant_type: "authorization_code",
secure_resource: secure_resource ? "true" : "false",
property_keys: JSON.stringify(property_keys)
}).toString(),
headers: {
"Content-type": "application/x-www-form-urlencoded",
Authorization: `Bearer ${access_token}`
}
headers: { Authorization: `Bearer ${access_token}` },
status: [200]
});
exports.getMe = getMe;
import { IResult } from "../common/result.interface";
import { IErrorResponse } from "../common";
export declare namespace Fetcher {
const get: <T>({ uri, headers }: {
const get: <T>({ uri, headers, status }: {
uri: string;
headers?: Record<string, string> | undefined;
}) => Promise<IResult<T, string>>;
const post: <T>({ uri, body, headers }: {
status?: number[] | undefined;
}) => Promise<IResult<T, IErrorResponse>>;
const post: <T>({ uri, body, headers, status }: {
uri: string;
body: object | string;
headers?: Record<string, string> | undefined;
}) => Promise<IResult<T, string>>;
status?: number[] | undefined;
}) => Promise<IResult<T, IErrorResponse>>;
}

@@ -10,3 +10,3 @@ "use strict";

(function (Fetcher) {
Fetcher.get = async ({ uri, headers = {} }) => {
Fetcher.get = async ({ uri, headers = {}, status = [200] }) => {
try {

@@ -20,4 +20,7 @@ const response = await (0, node_fetch_1.default)(uri, {

});
if (response.status !== 200 && response.status !== 201)
return { type: "error", result: await response.text() };
if (!status.includes(response.status))
return {
type: "error",
result: { status: response.status, rawbody: await response.text() }
};
return {

@@ -31,7 +34,10 @@ type: "ok",

type: "error",
result: error instanceof Error ? error.message : ""
result: {
status: 500,
rawbody: error instanceof Error ? error.message : ""
}
};
}
};
Fetcher.post = async ({ uri, body, headers = {} }) => {
Fetcher.post = async ({ uri, body, headers = {}, status = [201] }) => {
try {

@@ -46,4 +52,7 @@ const response = await (0, node_fetch_1.default)(uri, {

});
if (response.status !== 200 && response.status !== 201)
return { type: "error", result: await response.text() };
if (!status.includes(response.status))
return {
type: "error",
result: { status: response.status, rawbody: await response.text() }
};
return {

@@ -57,3 +66,6 @@ type: "ok",

type: "error",
result: error instanceof Error ? error.message : ""
result: {
status: 500,
rawbody: error instanceof Error ? error.message : ""
}
};

@@ -60,0 +72,0 @@ }

{
"name": "@devts/authjs",
"version": "0.0.15",
"version": "0.0.16",
"description": "Oauth2 Library",

@@ -18,6 +18,6 @@ "main": "lib/index.js",

"@types/jsonwebtoken": "^9.0.2",
"@types/node": "^20.2.1",
"@types/node": "^20.2.5",
"@types/node-fetch": "^2.6.4",
"@typescript-eslint/eslint-plugin": "~5.59.6",
"@typescript-eslint/parser": "~5.59.6",
"@typescript-eslint/eslint-plugin": "~5.59.8",
"@typescript-eslint/parser": "~5.59.8",
"eslint": "8.41.0",

@@ -29,3 +29,3 @@ "eslint-config-prettier": "^8.8.0",

"ts-node": "^10.9.1",
"type-coverage": "^2.25.3",
"type-coverage": "^2.26.0",
"typescript": "~5.0.4"

@@ -32,0 +32,0 @@ },