@adonis-agora/authkit-testing 0.4.0 → 0.5.1

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.
@@ -10,6 +10,11 @@ export interface FakeAuthenticatorLike {
10
10
  check(): Promise<boolean>;
11
11
  hasGlobalRole(role: string): boolean;
12
12
  getUser(): Promise<unknown>;
13
+ getUserOrFail(): Promise<unknown>;
14
+ toSharedProps(): Promise<{
15
+ user: unknown;
16
+ globalRoles: string[];
17
+ } | null>;
13
18
  }
14
19
  export interface FakeAuthenticatorOptions {
15
20
  /** identidade resolvida; default = {@link createTestIdentity}. Passe `null` para simular anônimo. */
@@ -15,7 +15,7 @@ export function fakeAuthenticator(options = {}) {
15
15
  },
16
16
  async authenticate() {
17
17
  if (!identity)
18
- throw new Error('Não autenticado');
18
+ throw new Error('Not authenticated');
19
19
  return identity;
20
20
  },
21
21
  async check() {
@@ -29,5 +29,16 @@ export function fakeAuthenticator(options = {}) {
29
29
  return null;
30
30
  return user;
31
31
  },
32
+ async getUserOrFail() {
33
+ if (!identity || user === null || user === undefined) {
34
+ throw new Error('Not authenticated: no user for the current session');
35
+ }
36
+ return user;
37
+ },
38
+ async toSharedProps() {
39
+ if (!identity)
40
+ return null;
41
+ return { user: user ?? null, globalRoles: identity.globalRoles ?? [] };
42
+ },
32
43
  };
33
44
  }
package/build/src/jwt.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createServer } from 'node:http';
2
1
  import { randomUUID } from 'node:crypto';
3
- import { SignJWT, exportJWK, generateKeyPair, } from 'jose';
2
+ import { createServer } from 'node:http';
3
+ import { SignJWT, exportJWK, generateKeyPair } from 'jose';
4
4
  const ALG = 'RS256';
5
5
  /** Gera um par de chaves RS256 extraível com um `kid` estável, para minting de tokens em testes. */
6
6
  export async function generateTestKeyPair(kid = randomUUID()) {
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-testing",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Test helpers for apps built on AuthKit: mint real signed ID tokens with a local JWKS, fake authenticators and account stores, and build valid identities — so host apps can test auth flows without booting an IdP.",
5
5
  "license": "MIT",
6
6
  "author": "dudousxd",
7
- "homepage": "https://github.com/DavideCarvalho/adonis-authkit/tree/main/packages/authkit-testing#readme",
7
+ "homepage": "https://github.com/DavideCarvalho/adonis-agora-authkit/tree/main/packages/authkit-testing#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/DavideCarvalho/adonis-authkit.git",
10
+ "url": "https://github.com/DavideCarvalho/adonis-agora-authkit.git",
11
11
  "directory": "packages/authkit-testing"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/DavideCarvalho/adonis-authkit/issues"
14
+ "url": "https://github.com/DavideCarvalho/adonis-agora-authkit/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "adonisjs",
@@ -36,8 +36,8 @@
36
36
  "./types": "./build/index.js"
37
37
  },
38
38
  "dependencies": {
39
- "jose": "^5.9.0",
40
- "@adonis-agora/authkit-core": "0.7.0"
39
+ "jose": "5.10.0",
40
+ "@adonis-agora/authkit-core": "0.8.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@adonisjs/tsconfig": "2.0.0",
@@ -46,11 +46,11 @@
46
46
  "@poppinss/ts-exec": "1.4.4",
47
47
  "@types/node": "25.9.1",
48
48
  "typescript": "6.0.3",
49
- "@adonis-agora/authkit-client": "0.11.0"
49
+ "@adonis-agora/authkit-client": "0.18.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsc",
53
- "typecheck": "tsc --noEmit",
53
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",
54
54
  "test": "node --import=@poppinss/ts-exec bin/test.ts"
55
55
  }
56
56
  }