Skip to content

Commit

Permalink
chore: refactor out absolute imports
Browse files Browse the repository at this point in the history
I've tried everything to get absolute imports working, unfortunately they
were more of a pain than they were worth. Maybe one day there will be
better support. For now, they were causing problems for end users

see this issue: jaredpalmer/tsdx#91
  • Loading branch information
jasonraimondi committed Oct 4, 2020
1 parent a8c4f49 commit 92720f3
Show file tree
Hide file tree
Showing 40 changed files with 245 additions and 226 deletions.
10 changes: 5 additions & 5 deletions examples/in_memory/database.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OAuthToken } from "~/entities/token.entity";
import { OAuthAuthCode } from "~/entities/auth_code.entity";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthUser } from "~/entities/user.entity";
import { OAuthAuthCode } from "../../src/entities/auth_code.entity";
import { OAuthClient } from "../../src/entities/client.entity";
import { OAuthScope } from "../../src/entities/scope.entity";
import { OAuthToken } from "../../src/entities/token.entity";
import { OAuthUser } from "../../src/entities/user.entity";

export interface InMemory {
users: { [id: string]: OAuthUser };
Expand Down
6 changes: 3 additions & 3 deletions examples/in_memory/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { json, urlencoded } from "body-parser";
import Express from "express";

import { OAuthException } from "~/exceptions/oauth.exception";
import { OAuthRequest } from "~/requests/request";
import { OAuthResponse } from "~/responses/response";
import { OAuthException } from "../../src/exceptions/oauth.exception";
import { OAuthRequest } from "../../src/requests/request";
import { OAuthResponse } from "../../src/responses/response";
import { inMemoryAuthorizationServer } from "./oauth_authorization_server";

const app = Express();
Expand Down
6 changes: 3 additions & 3 deletions examples/in_memory/oauth_authorization_server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthorizationServer } from "~/authorization_server";
import { DateInterval } from "~/utils/date_interval";
import { JwtService } from "~/utils/jwt";
import { AuthorizationServer } from "../../src/authorization_server";
import { DateInterval } from "../../src/utils/date_interval";
import { JwtService } from "../../src/utils/jwt";
import {
inMemoryAccessTokenRepository,
inMemoryAuthCodeRepository,
Expand Down
24 changes: 12 additions & 12 deletions examples/in_memory/repository.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { OAuthAuthCode } from "~/entities/auth_code.entity";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthToken } from "~/entities/token.entity";
import { OAuthUser } from "~/entities/user.entity";
import { GrantIdentifier } from "~/grants/abstract/grant.interface";
import { OAuthTokenRepository } from "~/repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "~/repositories/auth_code.repository";
import { OAuthClientRepository } from "~/repositories/client.repository";
import { OAuthScopeRepository } from "~/repositories/scope.repository";
import { OAuthUserRepository } from "~/repositories/user.repository";
import { DateInterval } from "~/utils/date_interval";
import { OAuthAuthCode } from "../../src/entities/auth_code.entity";
import { OAuthClient } from "../../src/entities/client.entity";
import { OAuthScope } from "../../src/entities/scope.entity";
import { OAuthToken } from "../../src/entities/token.entity";
import { OAuthUser } from "../../src/entities/user.entity";
import { GrantIdentifier } from "../../src/grants/abstract/grant.interface";
import { OAuthTokenRepository } from "../../src/repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "../../src/repositories/auth_code.repository";
import { OAuthClientRepository } from "../../src/repositories/client.repository";
import { OAuthScopeRepository } from "../../src/repositories/scope.repository";
import { OAuthUserRepository } from "../../src/repositories/user.repository";
import { DateInterval } from "../../src/utils/date_interval";
import { inMemoryDatabase } from "./database";

const oneHourInFuture = new DateInterval("1h").getEndDate();
Expand Down
10 changes: 5 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ module.exports = {
"json",
"ts",
],
modulePathIgnorePatterns: ['<rootDir>/dist'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: "<rootDir>/",
}),
rootDir: "./",
// modulePathIgnorePatterns: ['<rootDir>/dist'],
// moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
// prefix: "<rootDir>/",
// }),
// rootDir: "./",
testRegex: ".spec.ts$",
transform: {
"^.+\\.(t|j)s$": "ts-jest",
Expand Down
32 changes: 30 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0-beta.0",
"version": "1.0.0-beta.1",
"name": "@jmondi/oauth2-server",
"author": "Jason Raimondi <[email protected]>",
"module": "dist/oauth2-server.esm.js",
Expand Down
34 changes: 17 additions & 17 deletions src/authorization_server.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { OAuthException } from "~/exceptions/oauth.exception";
import { GrantIdentifier, GrantInterface } from "~/grants/abstract/grant.interface";
import { AuthCodeGrant } from "~/grants/auth_code.grant";
import { ClientCredentialsGrant } from "~/grants/client_credentials.grant";
import { ImplicitGrant } from "~/grants/implicit.grant";
import { PasswordGrant } from "~/grants/password.grant";
import { RefreshTokenGrant } from "~/grants/refresh_token.grant";
import { OAuthTokenRepository } from "~/repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "~/repositories/auth_code.repository";
import { OAuthClientRepository } from "~/repositories/client.repository";
import { OAuthScopeRepository } from "~/repositories/scope.repository";
import { OAuthUserRepository } from "~/repositories/user.repository";
import { AuthorizationRequest } from "~/requests/authorization.request";
import { RequestInterface } from "~/requests/request";
import { ResponseInterface } from "~/responses/response";
import { DateInterval } from "~/utils/date_interval";
import { JwtInterface } from "~/utils/jwt";
import { OAuthException } from "./exceptions/oauth.exception";
import { GrantIdentifier, GrantInterface } from "./grants/abstract/grant.interface";
import { AuthCodeGrant } from "./grants/auth_code.grant";
import { ClientCredentialsGrant } from "./grants/client_credentials.grant";
import { ImplicitGrant } from "./grants/implicit.grant";
import { PasswordGrant } from "./grants/password.grant";
import { RefreshTokenGrant } from "./grants/refresh_token.grant";
import { OAuthTokenRepository } from "./repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "./repositories/auth_code.repository";
import { OAuthClientRepository } from "./repositories/client.repository";
import { OAuthScopeRepository } from "./repositories/scope.repository";
import { OAuthUserRepository } from "./repositories/user.repository";
import { AuthorizationRequest } from "./requests/authorization.request";
import { RequestInterface } from "./requests/request";
import { ResponseInterface } from "./responses/response";
import { DateInterval } from "./utils/date_interval";
import { JwtInterface } from "./utils/jwt";

export class AuthorizationServer {
private readonly enabledGrantTypes: { [key: string]: GrantInterface } = {};
Expand Down
2 changes: 1 addition & 1 deletion src/code_verifiers/plain.verifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICodeChallenge } from "~/code_verifiers/verifier";
import { ICodeChallenge } from "./verifier";

export class PlainVerifier implements ICodeChallenge {
public readonly method = "plain";
Expand Down
4 changes: 2 additions & 2 deletions src/code_verifiers/s256.verifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from "crypto";

import { base64urlencode } from "~/utils/base64";
import { ICodeChallenge } from "~/code_verifiers/verifier";
import { base64urlencode } from "../utils/base64";
import { ICodeChallenge } from "./verifier";

export class S256Verifier implements ICodeChallenge {
public readonly method = "S256";
Expand Down
6 changes: 3 additions & 3 deletions src/entities/auth_code.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthUser } from "~/entities/user.entity";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthClient } from "./client.entity";
import { OAuthScope } from "./scope.entity";
import { OAuthUser } from "./user.entity";

export interface OAuthAuthCode {
code: string;
Expand Down
4 changes: 2 additions & 2 deletions src/entities/client.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OAuthScope } from "~/entities/scope.entity";
import { GrantIdentifier } from "~/grants/abstract/grant.interface";
import { GrantIdentifier } from "../grants/abstract/grant.interface";
import { OAuthScope } from "./scope.entity";

export interface OAuthClient {
id: string;
Expand Down
6 changes: 3 additions & 3 deletions src/entities/token.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthUser } from "~/entities/user.entity";
import { OAuthClient } from "./client.entity";
import { OAuthScope } from "./scope.entity";
import { OAuthUser } from "./user.entity";

export interface OAuthToken {
accessToken: string;
Expand Down
41 changes: 20 additions & 21 deletions src/grants/abstract/abstract.grant.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { OAuthAuthCode } from "~/entities/auth_code.entity";
import { isClientConfidential, OAuthClient } from "~/entities/client.entity";
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthToken } from "~/entities/token.entity";
import { OAuthUser } from "~/entities/user.entity";
import { OAuthException } from "~/exceptions/oauth.exception";
import { GrantIdentifier, GrantInterface } from "~/grants/abstract/grant.interface";
import { OAuthTokenRepository } from "~/repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "~/repositories/auth_code.repository";
import { OAuthClientRepository } from "~/repositories/client.repository";
import { OAuthScopeRepository } from "~/repositories/scope.repository";
import { OAuthUserRepository } from "~/repositories/user.repository";
import { AuthorizationRequest } from "~/requests/authorization.request";
import { RequestInterface } from "~/requests/request";
import { BearerTokenResponse } from "~/responses/bearer_token.response";
import { ResponseInterface } from "~/responses/response";
import { arrayDiff } from "~/utils/array";
import { base64decode } from "~/utils/base64";
import { DateInterval } from "~/utils/date_interval";
import { JwtInterface } from "~/utils/jwt";
import { getSecondsUntil, roundToSeconds } from "~/utils/time";
import { isClientConfidential, OAuthClient } from "../../entities/client.entity";
import { OAuthScope } from "../../entities/scope.entity";
import { OAuthToken } from "../../entities/token.entity";
import { OAuthUser } from "../../entities/user.entity";
import { OAuthException } from "../../exceptions/oauth.exception";
import { OAuthTokenRepository } from "../../repositories/access_token.repository";
import { OAuthAuthCodeRepository } from "../../repositories/auth_code.repository";
import { OAuthClientRepository } from "../../repositories/client.repository";
import { OAuthScopeRepository } from "../../repositories/scope.repository";
import { OAuthUserRepository } from "../../repositories/user.repository";
import { AuthorizationRequest } from "../../requests/authorization.request";
import { RequestInterface } from "../../requests/request";
import { BearerTokenResponse } from "../../responses/bearer_token.response";
import { ResponseInterface } from "../../responses/response";
import { arrayDiff } from "../../utils/array";
import { base64decode } from "../../utils/base64";
import { DateInterval } from "../../utils/date_interval";
import { JwtInterface } from "../../utils/jwt";
import { getSecondsUntil, roundToSeconds } from "../../utils/time";
import { GrantIdentifier, GrantInterface } from "./grant.interface";

export interface ITokenData {
iss: undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/grants/abstract/abstract_authorized.grant.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import querystring, { ParsedUrlQueryInput } from "querystring";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthException } from "~/exceptions/oauth.exception";

import { AbstractGrant } from "~/grants/abstract/abstract.grant";
import { OAuthClient } from "../../entities/client.entity";
import { OAuthException } from "../../exceptions/oauth.exception";
import { AbstractGrant } from "./abstract.grant";

export abstract class AbstractAuthorizedGrant extends AbstractGrant {
protected makeRedirectUrl(uri: string, params: ParsedUrlQueryInput, queryDelimiter = "?") {
Expand Down
8 changes: 4 additions & 4 deletions src/grants/abstract/grant.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AuthorizationRequest } from "~/requests/authorization.request";
import { RequestInterface } from "~/requests/request";
import { ResponseInterface } from "~/responses/response";
import { DateInterval } from "~/utils/date_interval";
import { AuthorizationRequest } from "../../requests/authorization.request";
import { RequestInterface } from "../../requests/request";
import { ResponseInterface } from "../../responses/response";
import { DateInterval } from "../../utils/date_interval";

export type GrantIdentifier = "authorization_code" | "client_credentials" | "refresh_token" | "password" | "implicit";

Expand Down
30 changes: 15 additions & 15 deletions src/grants/auth_code.grant.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { PlainVerifier } from "~/code_verifiers/plain.verifier";
import { S256Verifier } from "~/code_verifiers/s256.verifier";
import { CodeChallengeMethod, ICodeChallenge } from "~/code_verifiers/verifier";
import { OAuthAuthCode } from "~/entities/auth_code.entity";
import { OAuthClient } from "~/entities/client.entity";
import { OAuthScope } from "~/entities/scope.entity";
import { OAuthException } from "~/exceptions/oauth.exception";
import { AbstractAuthorizedGrant } from "~/grants/abstract/abstract_authorized.grant";
import { GrantIdentifier } from "~/grants/abstract/grant.interface";
import { AuthorizationRequest } from "~/requests/authorization.request";
import { RequestInterface } from "~/requests/request";
import { RedirectResponse } from "~/responses/redirect.response";
import { ResponseInterface } from "~/responses/response";
import { base64decode } from "~/utils/base64";
import { DateInterval } from "~/utils/date_interval";
import { PlainVerifier } from "../code_verifiers/plain.verifier";
import { S256Verifier } from "../code_verifiers/s256.verifier";
import { CodeChallengeMethod, ICodeChallenge } from "../code_verifiers/verifier";
import { OAuthAuthCode } from "../entities/auth_code.entity";
import { OAuthClient } from "../entities/client.entity";
import { OAuthScope } from "../entities/scope.entity";
import { OAuthException } from "../exceptions/oauth.exception";
import { AuthorizationRequest } from "../requests/authorization.request";
import { RequestInterface } from "../requests/request";
import { RedirectResponse } from "../responses/redirect.response";
import { ResponseInterface } from "../responses/response";
import { base64decode } from "../utils/base64";
import { DateInterval } from "../utils/date_interval";
import { AbstractAuthorizedGrant } from "./abstract/abstract_authorized.grant";
import { GrantIdentifier } from "./abstract/grant.interface";

export interface IAuthCodePayload {
client_id: string;
Expand Down
8 changes: 4 additions & 4 deletions src/grants/client_credentials.grant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbstractGrant } from "~/grants/abstract/abstract.grant";
import { RequestInterface } from "~/requests/request";
import { ResponseInterface } from "~/responses/response";
import { DateInterval } from "~/utils/date_interval";
import { RequestInterface } from "../requests/request";
import { ResponseInterface } from "../responses/response";
import { DateInterval } from "../utils/date_interval";
import { AbstractGrant } from "./abstract/abstract.grant";

export class ClientCredentialsGrant extends AbstractGrant {
readonly identifier = "client_credentials";
Expand Down
16 changes: 8 additions & 8 deletions src/grants/implicit.grant.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { OAuthException } from "~/exceptions/oauth.exception";
import { AbstractAuthorizedGrant } from "~/grants/abstract/abstract_authorized.grant";
import { AuthorizationRequest } from "~/requests/authorization.request";
import { RequestInterface } from "~/requests/request";
import { RedirectResponse } from "~/responses/redirect.response";
import { ResponseInterface } from "~/responses/response";
import { DateInterval } from "~/utils/date_interval";
import { getSecondsUntil } from "~/utils/time";
import { OAuthException } from "../exceptions/oauth.exception";
import { AuthorizationRequest } from "../requests/authorization.request";
import { RequestInterface } from "../requests/request";
import { RedirectResponse } from "../responses/redirect.response";
import { ResponseInterface } from "../responses/response";
import { DateInterval } from "../utils/date_interval";
import { getSecondsUntil } from "../utils/time";
import { AbstractAuthorizedGrant } from "./abstract/abstract_authorized.grant";

export class ImplicitGrant extends AbstractAuthorizedGrant {
readonly identifier = "implicit";
Expand Down
14 changes: 7 additions & 7 deletions src/grants/password.grant.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OAuthClient } from "~/entities/client.entity";
import { OAuthUser } from "~/entities/user.entity";
import { OAuthException } from "~/exceptions/oauth.exception";
import { AbstractGrant } from "~/grants/abstract/abstract.grant";
import { RequestInterface } from "~/requests/request";
import { ResponseInterface } from "~/responses/response";
import { DateInterval } from "~/utils/date_interval";
import { OAuthClient } from "../entities/client.entity";
import { OAuthUser } from "../entities/user.entity";
import { OAuthException } from "../exceptions/oauth.exception";
import { RequestInterface } from "../requests/request";
import { ResponseInterface } from "../responses/response";
import { DateInterval } from "../utils/date_interval";
import { AbstractGrant } from "./abstract/abstract.grant";

export class PasswordGrant extends AbstractGrant {
readonly identifier = "password";
Expand Down
Loading

0 comments on commit 92720f3

Please sign in to comment.