@antelopejs/auth-jwt 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/auth-jwt",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Authentication and authorization module that implements the Auth interface of antelopejs with JWT",
5
5
  "keywords": [
6
6
  "antelope",
@@ -23,7 +23,7 @@
23
23
  "license": "Apache-2.0",
24
24
  "packageManager": "pnpm@10.6.5",
25
25
  "scripts": {
26
- "build": "tsc",
26
+ "build": "rm -rf dist && tsc",
27
27
  "dev:prepare": "cd playground && ajs module imports install",
28
28
  "dev": "ajs project run -w -p playground",
29
29
  "format": "prettier --write .",
@@ -52,7 +52,6 @@
52
52
  "devDependencies": {
53
53
  "@eslint/eslintrc": "^3.3.1",
54
54
  "@eslint/js": "^9.25.0",
55
- "@release-it/conventional-changelog": "^10.0.1",
56
55
  "@types/jsonwebtoken": "^9.0.9",
57
56
  "@types/node": "^22.14.1",
58
57
  "@types/ws": "^8.18.1",
@@ -63,6 +62,7 @@
63
62
  "globals": "^16.0.0",
64
63
  "prettier": "^3.5.3",
65
64
  "release-it": "^19.0.2",
65
+ "release-it-changelogen": "^0.1.0",
66
66
  "typescript": "^5.8.3",
67
67
  "typescript-eslint": "^8.30.1",
68
68
  "ws": "^8.18.1"
@@ -1,10 +0,0 @@
1
- import { SignOptions, VerifyOptions } from 'jsonwebtoken';
2
- import { AuthSource, AuthVerifier, AuthValidator } from '@ajs.local/auth/dev';
3
- export declare const Verify: (data?: string, options?: VerifyOptions) => Promise<any>;
4
- export declare const Sign: (data: any, options?: SignOptions) => Promise<string>;
5
- export declare const AttachAuthDecorator: (target: any, key: PropertyKey | undefined, index: number | PropertyDescriptor | undefined, callbacks: {
6
- source?: AuthSource;
7
- authenticator?: AuthVerifier;
8
- authenticatorOptions?: VerifyOptions;
9
- validator?: AuthValidator;
10
- }, validator?: AuthValidator) => void;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttachAuthDecorator = exports.Sign = exports.Verify = void 0;
4
- const index_1 = require("../../index");
5
- const dev_1 = require("@ajs/api/dev");
6
- const dev_2 = require("@ajs.local/auth/dev");
7
- const Verify = (data, options) => {
8
- return (0, index_1.getJWTHandler)().verify(data, options);
9
- };
10
- exports.Verify = Verify;
11
- const Sign = (data, options) => {
12
- return (0, index_1.getJWTHandler)().sign(data, options);
13
- };
14
- exports.Sign = Sign;
15
- const AttachAuthDecorator = (target, key, index, callbacks, validator) => {
16
- const source = callbacks.source || dev_2.defaultSource;
17
- const authenticator = callbacks.authenticator || dev_2.defaultAuthenticator;
18
- const authenticatorOptions = callbacks.authenticatorOptions || {};
19
- const defaultValidator = callbacks.validator;
20
- if (typeof index === 'object' || key === undefined) {
21
- (0, dev_1.SetParameterProvider)(target, Symbol(''), undefined, (context) => (0, dev_2.CheckAuthentication)(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
22
- }
23
- else {
24
- (0, dev_1.SetParameterProvider)(target, key, index, (context) => (0, dev_2.CheckAuthentication)(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
25
- }
26
- };
27
- exports.AttachAuthDecorator = AttachAuthDecorator;
28
- //# sourceMappingURL=dev.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../src/implementations/auth/dev.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,sCAAoD;AACpD,6CAO6B;AAEtB,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,OAAuB,EAAE,EAAE;IAChE,OAAO,IAAA,qBAAa,GAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,MAAM,IAAI,GA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, res: ServerResponse) => string | undefined;
3
- export type AuthVerifier<T = unknown> = (data?: string, options?: VerifyOptions) => Promise<T> | T;
4
- export type AuthValidator<T = unknown, R = unknown> = (data: T) => Promise<R> | R;
5
- export interface CookieOptions {
6
- maxAge?: number;
7
- signed?: boolean;
8
- expires?: Date;
9
- httpOnly?: boolean;
10
- path?: string;
11
- domain?: string;
12
- secure?: boolean;
13
- }
14
- export interface SignOptions {
15
- expiresIn?: string | number;
16
- notBefore?: string | number;
17
- }
18
- export interface VerifyOptions {
19
- ignoreExpiration?: boolean;
20
- ignoreNotBefore?: boolean;
21
- maxAge?: string | number;
22
- }
23
- export declare const Verify: (data?: string | undefined, options?: VerifyOptions | undefined) => Promise<any>;
24
- export declare const Sign: (data: any, options?: SignOptions | undefined) => Promise<string>;
25
- export declare const AttachAuthDecorator: (target: any, key: PropertyKey | undefined, index: number | PropertyDescriptor | undefined, callbacks: {
26
- source?: AuthSource;
27
- authenticator?: AuthVerifier<any>;
28
- authenticatorOptions?: VerifyOptions;
29
- validator?: AuthValidator<any, any>;
30
- }, validator?: AuthValidator<unknown, unknown> | undefined) => Promise<void>;
31
- export declare function ValidateRaw<T = any>(token: string, options?: VerifyOptions): Promise<T>;
32
- export declare function SignRaw(data: any, options?: SignOptions): Promise<string>;
33
- export declare function defaultSource(req: IncomingMessage): string | undefined;
34
- export declare const defaultAuthenticator: AuthVerifier<any>;
35
- export declare function CheckAuthentication<T = unknown, R = unknown>(req: IncomingMessage, res: ServerResponse, source?: AuthSource | undefined, authenticator?: AuthVerifier<T> | undefined, authenticatorOptions?: VerifyOptions | undefined, validator?: AuthValidator<T, R> | undefined): Promise<any>;
36
- export declare function SignServerResponse(res: ServerResponse, data: any, signOptions?: SignOptions, cookieOptions?: CookieOptions): Promise<ServerResponse<IncomingMessage>>;
37
- export declare function CreateAuthDecorator<R = unknown, T = unknown>(callbacks: {
38
- source?: AuthSource;
39
- authenticator?: AuthVerifier<T>;
40
- authenticatorOptions?: VerifyOptions;
41
- validator?: AuthValidator<T, R>;
42
- }): (validator?: AuthValidator<T, R> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;
43
- export declare const Authentication: (validator?: AuthValidator<unknown, unknown> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Authentication = exports.defaultAuthenticator = exports.AttachAuthDecorator = exports.Sign = exports.Verify = void 0;
4
- exports.ValidateRaw = ValidateRaw;
5
- exports.SignRaw = SignRaw;
6
- exports.defaultSource = defaultSource;
7
- exports.CheckAuthentication = CheckAuthentication;
8
- exports.SignServerResponse = SignServerResponse;
9
- exports.CreateAuthDecorator = CreateAuthDecorator;
10
- const _1_1 = require("@ajs/core/1");
11
- const decorators_1 = require("@ajs/core/1/decorators");
12
- const dev_1 = require("@ajs/api/dev");
13
- exports.Verify = (0, _1_1.InterfaceFunction)();
14
- exports.Sign = (0, _1_1.InterfaceFunction)();
15
- exports.AttachAuthDecorator = (0, _1_1.InterfaceFunction)();
16
- function ValidateRaw(token, options) {
17
- return (0, exports.Verify)(token, options);
18
- }
19
- function SignRaw(data, options) {
20
- return (0, exports.Sign)(data, options);
21
- }
22
- function defaultSource(req) {
23
- if (req.headers['x-antelopejs-auth']) {
24
- return req.headers['x-antelopejs-auth'];
25
- }
26
- if (req.headers['cookie']) {
27
- const match = (' ' + req.headers['cookie']).match(/ ANTELOPEJS_AUTH=([^;]*)/);
28
- if (match) {
29
- return match[1];
30
- }
31
- }
32
- return undefined;
33
- }
34
- exports.defaultAuthenticator = ValidateRaw;
35
- async function CheckAuthentication(req, res, source = undefined, authenticator = undefined, authenticatorOptions = undefined, validator = undefined) {
36
- const data = await (authenticator || exports.defaultAuthenticator)((source || defaultSource)(req, res), authenticatorOptions);
37
- return validator ? await validator(data) : data;
38
- }
39
- function SignServerResponse(res, data, signOptions, cookieOptions) {
40
- const opts = cookieOptions
41
- ? Object.keys(cookieOptions)
42
- .map((key) => `${key}=${cookieOptions[key]}`)
43
- .join('; ')
44
- : '';
45
- return SignRaw(data, signOptions).then((data) => res.setHeader('Set-Cookie', `ANTELOPEJS_AUTH=${data}; ${opts}`));
46
- }
47
- function CreateAuthDecorator(callbacks) {
48
- const source = callbacks.source || defaultSource;
49
- const authenticator = callbacks.authenticator || exports.defaultAuthenticator;
50
- const authenticatorOptions = callbacks.authenticatorOptions || {};
51
- const defaultValidator = callbacks.validator;
52
- return (0, decorators_1.MakeParameterAndMethodAndPropertyAndClassDecorator)((target, key, index, validator) => {
53
- if (typeof index === 'object' || key === undefined) {
54
- (0, dev_1.SetParameterProvider)(target, Symbol(''), undefined, (context) => CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
55
- }
56
- else {
57
- (0, dev_1.SetParameterProvider)(target, key, index, (context) => CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
58
- }
59
- });
60
- }
61
- exports.Authentication = CreateAuthDecorator({});
62
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/interfaces/auth/dev/index.ts"],"names":[],"mappings":";;;AAsLA,kCAEC;AAcD,0BAEC;AAKD,sCAWC;AAqBD,kDAaC;AAqBD,gDAeC;AAuCD,kDAoCC;AAzWD,oCAAgD;AAChD,uDAA4F;AAE5F,sCAAoD;AA4IvC,QAAA,MAAM,GAAG,IAAA,sBAAiB,GAAmD,CAAC;AAK9E,QAAA,IAAI,GAAG,IAAA,sBAAiB,GAAgD,CAAC;A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