@ankhorage/auth 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/capabilities/index.d.ts +990 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +77 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/features/auth/ports/authPort.d.ts +14 -0
- package/dist/features/auth/ports/authPort.d.ts.map +1 -0
- package/dist/features/auth/ports/authPort.js +2 -0
- package/dist/features/auth/ports/authPort.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +1389 -4
- package/src/capabilities/index.test.ts +80 -0
- package/src/capabilities/index.ts +93 -0
- package/src/features/auth/ports/authPort.ts +27 -0
- package/src/index.test.ts +35 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isCapability } from '@ankhorage/capability';
|
|
2
|
+
import {
|
|
3
|
+
AUTH_EMPTY_INPUT_SCHEMA,
|
|
4
|
+
AUTH_NULLABLE_SESSION_RESULT_SCHEMA,
|
|
5
|
+
AUTH_OAUTH_COMPLETION_RESULT_SCHEMA,
|
|
6
|
+
AUTH_OAUTH_START_RESULT_SCHEMA,
|
|
7
|
+
AUTH_VOID_RESULT_SCHEMA,
|
|
8
|
+
COMPLETE_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
9
|
+
PASSWORD_RESET_INPUT_SCHEMA,
|
|
10
|
+
SIGN_IN_INPUT_SCHEMA,
|
|
11
|
+
SIGN_IN_RESULT_SCHEMA,
|
|
12
|
+
SIGN_OUT_INPUT_SCHEMA,
|
|
13
|
+
SIGN_UP_INPUT_SCHEMA,
|
|
14
|
+
SIGN_UP_RESULT_SCHEMA,
|
|
15
|
+
START_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
16
|
+
VERIFY_OTP_INPUT_SCHEMA,
|
|
17
|
+
} from '@ankhorage/contracts/auth';
|
|
18
|
+
import type { Capability } from '@ankhorage/contracts/capability';
|
|
19
|
+
import { expect, test } from 'bun:test';
|
|
20
|
+
|
|
21
|
+
import { CAPABILITIES } from './index.js';
|
|
22
|
+
|
|
23
|
+
test('publishes only the canonical invocable auth descriptors', () => {
|
|
24
|
+
const capabilities: readonly Capability[] = CAPABILITIES;
|
|
25
|
+
|
|
26
|
+
expect(capabilities.every(isCapability)).toBe(true);
|
|
27
|
+
expect(capabilities.map(({ id }) => id)).toEqual([
|
|
28
|
+
'auth.signIn',
|
|
29
|
+
'auth.signUp',
|
|
30
|
+
'auth.signOut',
|
|
31
|
+
'auth.getSession',
|
|
32
|
+
'auth.refreshSession',
|
|
33
|
+
'auth.requestPasswordReset',
|
|
34
|
+
'auth.verifyOtp',
|
|
35
|
+
'auth.oauth.startAuthorization',
|
|
36
|
+
'auth.oauth.completeAuthorization',
|
|
37
|
+
]);
|
|
38
|
+
expect(
|
|
39
|
+
capabilities.every(
|
|
40
|
+
(capability) =>
|
|
41
|
+
capability.owner === '@ankhorage/auth' &&
|
|
42
|
+
capability.access[0] === 'invoke' &&
|
|
43
|
+
capability.binding.kind === 'auth' &&
|
|
44
|
+
capability.binding.bindableAs[0] === 'target',
|
|
45
|
+
),
|
|
46
|
+
).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('binds every descriptor schema to the released Contracts source', () => {
|
|
50
|
+
expect(CAPABILITIES.map((capability) => capability.input.schema)).toEqual([
|
|
51
|
+
SIGN_IN_INPUT_SCHEMA,
|
|
52
|
+
SIGN_UP_INPUT_SCHEMA,
|
|
53
|
+
SIGN_OUT_INPUT_SCHEMA,
|
|
54
|
+
AUTH_EMPTY_INPUT_SCHEMA,
|
|
55
|
+
AUTH_EMPTY_INPUT_SCHEMA,
|
|
56
|
+
PASSWORD_RESET_INPUT_SCHEMA,
|
|
57
|
+
VERIFY_OTP_INPUT_SCHEMA,
|
|
58
|
+
START_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
59
|
+
COMPLETE_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
60
|
+
]);
|
|
61
|
+
expect(CAPABILITIES.map((capability) => capability.output.schema)).toEqual([
|
|
62
|
+
SIGN_IN_RESULT_SCHEMA,
|
|
63
|
+
SIGN_UP_RESULT_SCHEMA,
|
|
64
|
+
AUTH_VOID_RESULT_SCHEMA,
|
|
65
|
+
AUTH_NULLABLE_SESSION_RESULT_SCHEMA,
|
|
66
|
+
AUTH_NULLABLE_SESSION_RESULT_SCHEMA,
|
|
67
|
+
AUTH_VOID_RESULT_SCHEMA,
|
|
68
|
+
SIGN_IN_RESULT_SCHEMA,
|
|
69
|
+
AUTH_OAUTH_START_RESULT_SCHEMA,
|
|
70
|
+
AUTH_OAUTH_COMPLETION_RESULT_SCHEMA,
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('materializes the package metadata directly from the canonical catalog', async () => {
|
|
75
|
+
const manifest: unknown = JSON.parse(
|
|
76
|
+
await Bun.file(new URL('../../package.json', import.meta.url)).text(),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(manifest).toMatchObject({ ankh: { capabilities: CAPABILITIES } });
|
|
80
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTH_EMPTY_INPUT_SCHEMA,
|
|
3
|
+
AUTH_NULLABLE_SESSION_RESULT_SCHEMA,
|
|
4
|
+
AUTH_OAUTH_COMPLETION_RESULT_SCHEMA,
|
|
5
|
+
AUTH_OAUTH_START_RESULT_SCHEMA,
|
|
6
|
+
AUTH_VOID_RESULT_SCHEMA,
|
|
7
|
+
COMPLETE_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
8
|
+
PASSWORD_RESET_INPUT_SCHEMA,
|
|
9
|
+
SIGN_IN_INPUT_SCHEMA,
|
|
10
|
+
SIGN_IN_RESULT_SCHEMA,
|
|
11
|
+
SIGN_OUT_INPUT_SCHEMA,
|
|
12
|
+
SIGN_UP_INPUT_SCHEMA,
|
|
13
|
+
SIGN_UP_RESULT_SCHEMA,
|
|
14
|
+
START_OAUTH_AUTHORIZATION_INPUT_SCHEMA,
|
|
15
|
+
VERIFY_OTP_INPUT_SCHEMA,
|
|
16
|
+
} from '@ankhorage/contracts/auth';
|
|
17
|
+
import type { Capability } from '@ankhorage/contracts/capability';
|
|
18
|
+
|
|
19
|
+
/*** Define the provider-neutral authentication operations published by this package. */
|
|
20
|
+
export const CAPABILITIES = [
|
|
21
|
+
{
|
|
22
|
+
id: 'auth.signIn',
|
|
23
|
+
owner: '@ankhorage/auth',
|
|
24
|
+
access: ['invoke'],
|
|
25
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
26
|
+
input: { schema: SIGN_IN_INPUT_SCHEMA },
|
|
27
|
+
output: { schema: SIGN_IN_RESULT_SCHEMA },
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'auth.signUp',
|
|
31
|
+
owner: '@ankhorage/auth',
|
|
32
|
+
access: ['invoke'],
|
|
33
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
34
|
+
input: { schema: SIGN_UP_INPUT_SCHEMA },
|
|
35
|
+
output: { schema: SIGN_UP_RESULT_SCHEMA },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'auth.signOut',
|
|
39
|
+
owner: '@ankhorage/auth',
|
|
40
|
+
access: ['invoke'],
|
|
41
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
42
|
+
input: { schema: SIGN_OUT_INPUT_SCHEMA },
|
|
43
|
+
output: { schema: AUTH_VOID_RESULT_SCHEMA },
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'auth.getSession',
|
|
47
|
+
owner: '@ankhorage/auth',
|
|
48
|
+
access: ['invoke'],
|
|
49
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
50
|
+
input: { schema: AUTH_EMPTY_INPUT_SCHEMA },
|
|
51
|
+
output: { schema: AUTH_NULLABLE_SESSION_RESULT_SCHEMA },
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'auth.refreshSession',
|
|
55
|
+
owner: '@ankhorage/auth',
|
|
56
|
+
access: ['invoke'],
|
|
57
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
58
|
+
input: { schema: AUTH_EMPTY_INPUT_SCHEMA },
|
|
59
|
+
output: { schema: AUTH_NULLABLE_SESSION_RESULT_SCHEMA },
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'auth.requestPasswordReset',
|
|
63
|
+
owner: '@ankhorage/auth',
|
|
64
|
+
access: ['invoke'],
|
|
65
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
66
|
+
input: { schema: PASSWORD_RESET_INPUT_SCHEMA },
|
|
67
|
+
output: { schema: AUTH_VOID_RESULT_SCHEMA },
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'auth.verifyOtp',
|
|
71
|
+
owner: '@ankhorage/auth',
|
|
72
|
+
access: ['invoke'],
|
|
73
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
74
|
+
input: { schema: VERIFY_OTP_INPUT_SCHEMA },
|
|
75
|
+
output: { schema: SIGN_IN_RESULT_SCHEMA },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'auth.oauth.startAuthorization',
|
|
79
|
+
owner: '@ankhorage/auth',
|
|
80
|
+
access: ['invoke'],
|
|
81
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
82
|
+
input: { schema: START_OAUTH_AUTHORIZATION_INPUT_SCHEMA },
|
|
83
|
+
output: { schema: AUTH_OAUTH_START_RESULT_SCHEMA },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'auth.oauth.completeAuthorization',
|
|
87
|
+
owner: '@ankhorage/auth',
|
|
88
|
+
access: ['invoke'],
|
|
89
|
+
binding: { kind: 'auth', bindableAs: ['target'] },
|
|
90
|
+
input: { schema: COMPLETE_OAUTH_AUTHORIZATION_INPUT_SCHEMA },
|
|
91
|
+
output: { schema: AUTH_OAUTH_COMPLETION_RESULT_SCHEMA },
|
|
92
|
+
},
|
|
93
|
+
] as const satisfies readonly Capability[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuthOAuthCompletionResult,
|
|
3
|
+
AuthOAuthStartResult,
|
|
4
|
+
AuthResult,
|
|
5
|
+
AuthSession,
|
|
6
|
+
AuthUser,
|
|
7
|
+
CompleteOAuthAuthorizationInput,
|
|
8
|
+
PasswordResetInput,
|
|
9
|
+
SignInInput,
|
|
10
|
+
SignOutInput,
|
|
11
|
+
SignUpInput,
|
|
12
|
+
StartOAuthAuthorizationInput,
|
|
13
|
+
VerifyOtpInput,
|
|
14
|
+
} from '@ankhorage/contracts/auth';
|
|
15
|
+
|
|
16
|
+
/*** Define the provider-neutral executable authentication boundary. */
|
|
17
|
+
export interface AuthPort {
|
|
18
|
+
signIn(input: SignInInput): Promise<AuthResult<AuthSession>>;
|
|
19
|
+
signUp(input: SignUpInput): Promise<AuthResult<AuthSession | AuthUser>>;
|
|
20
|
+
signOut(input?: SignOutInput): Promise<AuthResult>;
|
|
21
|
+
getSession(): Promise<AuthResult<AuthSession | null>>;
|
|
22
|
+
refreshSession(): Promise<AuthResult<AuthSession | null>>;
|
|
23
|
+
requestPasswordReset(input: PasswordResetInput): Promise<AuthResult>;
|
|
24
|
+
verifyOtp(input: VerifyOtpInput): Promise<AuthResult<AuthSession>>;
|
|
25
|
+
startAuthorization(input: StartOAuthAuthorizationInput): Promise<AuthOAuthStartResult>;
|
|
26
|
+
completeAuthorization(input: CompleteOAuthAuthorizationInput): Promise<AuthOAuthCompletionResult>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import type { AuthPort } from './index.js';
|
|
4
|
+
import { CAPABILITIES } from './index.js';
|
|
5
|
+
|
|
6
|
+
const AUTH_PORT_OPERATIONS = [
|
|
7
|
+
'signIn',
|
|
8
|
+
'signUp',
|
|
9
|
+
'signOut',
|
|
10
|
+
'getSession',
|
|
11
|
+
'refreshSession',
|
|
12
|
+
'requestPasswordReset',
|
|
13
|
+
'verifyOtp',
|
|
14
|
+
'startAuthorization',
|
|
15
|
+
'completeAuthorization',
|
|
16
|
+
] as const satisfies readonly (keyof AuthPort)[];
|
|
17
|
+
|
|
18
|
+
test('exports the neutral execution port for every canonical operation', () => {
|
|
19
|
+
expect(AUTH_PORT_OPERATIONS).toEqual([
|
|
20
|
+
'signIn',
|
|
21
|
+
'signUp',
|
|
22
|
+
'signOut',
|
|
23
|
+
'getSession',
|
|
24
|
+
'refreshSession',
|
|
25
|
+
'requestPasswordReset',
|
|
26
|
+
'verifyOtp',
|
|
27
|
+
'startAuthorization',
|
|
28
|
+
'completeAuthorization',
|
|
29
|
+
]);
|
|
30
|
+
expect(CAPABILITIES).toHaveLength(AUTH_PORT_OPERATIONS.length);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('publishes no provider implementation from the JavaScript surface', () => {
|
|
34
|
+
expect(Object.keys({ CAPABILITIES })).toEqual(['CAPABILITIES']);
|
|
35
|
+
});
|
package/src/index.ts
ADDED