@auditauth/node 0.2.0-beta.2 → 0.2.0-beta.4

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/README.md CHANGED
@@ -12,6 +12,17 @@ Install the package in your Node.js service.
12
12
  npm install @auditauth/node
13
13
  ```
14
14
 
15
+ ## TypeScript import compatibility
16
+
17
+ `@auditauth/node` ships dual module output (ESM + CJS) with declaration files.
18
+ You can import it in TypeScript projects with standard syntax:
19
+
20
+ ```ts
21
+ import { verifyAccessToken } from '@auditauth/node'
22
+ ```
23
+
24
+ You do not need to append `.js` in consumer imports.
25
+
15
26
  ## Verify a bearer token
16
27
 
17
28
  Use `verifyAccessToken()` when you already have a raw JWT string.
package/dist/index.cjs ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ verifyAccessToken: () => verifyAccessToken,
22
+ verifyRequest: () => verifyRequest
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+ var import_jose = require("jose");
26
+ var import_core = require("@auditauth/core");
27
+ let cachedKey = null;
28
+ const verifyAccessToken = async ({ token, appId }) => {
29
+ if (!token) {
30
+ throw new Error("Missing token");
31
+ }
32
+ if (!cachedKey) {
33
+ cachedKey = await (0, import_jose.importSPKI)(
34
+ import_core.CORE_SETTINGS.jwt_public_key,
35
+ "RS256"
36
+ );
37
+ }
38
+ const { payload } = await (0, import_jose.jwtVerify)(token, cachedKey, {
39
+ issuer: import_core.CORE_SETTINGS.jwt_issuer,
40
+ audience: appId
41
+ });
42
+ return payload;
43
+ };
44
+ const verifyRequest = async ({ request, appId }) => {
45
+ const authHeader = request.headers instanceof Headers ? request.headers.get("authorization") : request.headers["authorization"] || request.headers["Authorization"];
46
+ if (!authHeader || !authHeader?.startsWith("Bearer ")) {
47
+ throw new Error("Missing or invalid Authorization header");
48
+ }
49
+ const token = authHeader.replace("Bearer ", "").trim();
50
+ return verifyAccessToken({ token, appId });
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ verifyAccessToken,
55
+ verifyRequest
56
+ });
@@ -0,0 +1,19 @@
1
+ import { AuditAuthTokenPayload } from './types.cjs';
2
+ import 'jose';
3
+
4
+ type VerifyAccessTokenPayload = {
5
+ token: string;
6
+ appId: string;
7
+ };
8
+ declare const verifyAccessToken: ({ token, appId }: VerifyAccessTokenPayload) => Promise<AuditAuthTokenPayload>;
9
+ type VerifyRequestParams = {
10
+ request: Request | {
11
+ headers: Headers;
12
+ } | {
13
+ headers: Record<string, string>;
14
+ };
15
+ appId: string;
16
+ };
17
+ declare const verifyRequest: ({ request, appId }: VerifyRequestParams) => Promise<AuditAuthTokenPayload>;
18
+
19
+ export { AuditAuthTokenPayload, type VerifyAccessTokenPayload, type VerifyRequestParams, verifyAccessToken, verifyRequest };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { AuditAuthTokenPayload } from './types.js';
1
+ import { AuditAuthTokenPayload } from './types.js';
2
+ import 'jose';
3
+
2
4
  type VerifyAccessTokenPayload = {
3
5
  token: string;
4
6
  appId: string;
@@ -13,5 +15,5 @@ type VerifyRequestParams = {
13
15
  appId: string;
14
16
  };
15
17
  declare const verifyRequest: ({ request, appId }: VerifyRequestParams) => Promise<AuditAuthTokenPayload>;
16
- export { verifyAccessToken, verifyRequest };
17
- export type { VerifyRequestParams, VerifyAccessTokenPayload, AuditAuthTokenPayload };
18
+
19
+ export { AuditAuthTokenPayload, type VerifyAccessTokenPayload, type VerifyRequestParams, verifyAccessToken, verifyRequest };
package/dist/index.js CHANGED
@@ -1,27 +1,31 @@
1
- import { importSPKI, jwtVerify } from 'jose';
2
- import { CORE_SETTINGS } from '@auditauth/core';
1
+ import { importSPKI, jwtVerify } from "jose";
2
+ import { CORE_SETTINGS } from "@auditauth/core";
3
3
  let cachedKey = null;
4
4
  const verifyAccessToken = async ({ token, appId }) => {
5
- if (!token) {
6
- throw new Error('Missing token');
7
- }
8
- if (!cachedKey) {
9
- cachedKey = await importSPKI(CORE_SETTINGS.jwt_public_key, 'RS256');
10
- }
11
- const { payload } = await jwtVerify(token, cachedKey, {
12
- issuer: CORE_SETTINGS.jwt_issuer,
13
- audience: appId,
14
- });
15
- return payload;
5
+ if (!token) {
6
+ throw new Error("Missing token");
7
+ }
8
+ if (!cachedKey) {
9
+ cachedKey = await importSPKI(
10
+ CORE_SETTINGS.jwt_public_key,
11
+ "RS256"
12
+ );
13
+ }
14
+ const { payload } = await jwtVerify(token, cachedKey, {
15
+ issuer: CORE_SETTINGS.jwt_issuer,
16
+ audience: appId
17
+ });
18
+ return payload;
16
19
  };
17
20
  const verifyRequest = async ({ request, appId }) => {
18
- const authHeader = request.headers instanceof Headers
19
- ? request.headers.get('authorization')
20
- : request.headers['authorization'] || request.headers['Authorization'];
21
- if (!authHeader || !authHeader?.startsWith('Bearer ')) {
22
- throw new Error('Missing or invalid Authorization header');
23
- }
24
- const token = authHeader.replace('Bearer ', '').trim();
25
- return verifyAccessToken({ token, appId });
21
+ const authHeader = request.headers instanceof Headers ? request.headers.get("authorization") : request.headers["authorization"] || request.headers["Authorization"];
22
+ if (!authHeader || !authHeader?.startsWith("Bearer ")) {
23
+ throw new Error("Missing or invalid Authorization header");
24
+ }
25
+ const token = authHeader.replace("Bearer ", "").trim();
26
+ return verifyAccessToken({ token, appId });
27
+ };
28
+ export {
29
+ verifyAccessToken,
30
+ verifyRequest
26
31
  };
27
- export { verifyAccessToken, verifyRequest };
package/dist/types.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,11 @@
1
+ import { JWTPayload } from 'jose';
2
+
3
+ type AuditAuthTokenPayload = JWTPayload & {
4
+ sub: string;
5
+ email: string;
6
+ aud: string;
7
+ account_id: string;
8
+ app_id: string;
9
+ };
10
+
11
+ export type { AuditAuthTokenPayload };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { JWTPayload } from "jose";
1
+ import { JWTPayload } from 'jose';
2
+
2
3
  type AuditAuthTokenPayload = JWTPayload & {
3
4
  sub: string;
4
5
  email: string;
@@ -6,4 +7,5 @@ type AuditAuthTokenPayload = JWTPayload & {
6
7
  account_id: string;
7
8
  app_id: string;
8
9
  };
10
+
9
11
  export type { AuditAuthTokenPayload };
package/dist/types.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auditauth/node",
3
- "version": "0.2.0-beta.2",
3
+ "version": "0.2.0-beta.4",
4
4
  "description": "AuditAuth Node SDK - JWT verification",
5
5
  "license": "MIT",
6
6
  "author": "Nimibyte",
@@ -24,26 +24,30 @@
24
24
  "security",
25
25
  "auditauth"
26
26
  ],
27
- "module": "dist/index.js",
27
+ "module": "./dist/index.js",
28
28
  "type": "module",
29
- "main": "dist/index.js",
30
- "types": "dist/index.d.ts",
29
+ "main": "./dist/index.cjs",
30
+ "types": "./dist/index.d.ts",
31
31
  "files": ["dist"],
32
32
  "sideEffects": false,
33
33
  "exports": {
34
34
  ".": {
35
35
  "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js",
37
+ "require": "./dist/index.cjs",
36
38
  "default": "./dist/index.js"
37
- }
39
+ },
40
+ "./package.json": "./package.json"
38
41
  },
39
42
  "scripts": {
40
- "build": "tsc -p tsconfig.build.json",
41
- "dev": "tsc -p tsconfig.build.json --watch",
42
- "clean": "rm -rf dist"
43
+ "build": "tsup && node ../../scripts/fix-cjs-relative-imports.mjs dist",
44
+ "dev": "tsup --watch",
45
+ "clean": "rm -rf dist",
46
+ "prepack": "npm run build"
43
47
  },
44
48
  "dependencies": {
45
49
  "jose": "^5.2.0",
46
- "@auditauth/core": "^0.2.0-beta.2"
50
+ "@auditauth/core": "^0.2.0-beta.4"
47
51
  },
48
52
  "devDependencies": {
49
53
  "@types/node": "^20.11.30",