@oblax/auth 1.0.0
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/dist/accounts.d.ts +71 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +97 -0
- package/dist/accounts.js.map +1 -0
- package/dist/auth.d.ts +52 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +54 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/realms.d.ts +52 -0
- package/dist/realms.d.ts.map +1 -0
- package/dist/realms.js +65 -0
- package/dist/realms.js.map +1 -0
- package/dist/roles.d.ts +42 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +59 -0
- package/dist/roles.js.map +1 -0
- package/dist/session.d.ts +78 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +137 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { Account, ConfirmAccountParams, CreateAccountParams, EnableAccountParams, RequestPasswordResetParams, ResetPasswordParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages user accounts.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Register a new user
|
|
9
|
+
* const account = await oblax.auth.accounts.create({
|
|
10
|
+
* firstName: 'Alice',
|
|
11
|
+
* lastName: 'Smith',
|
|
12
|
+
* email: 'alice@example.com',
|
|
13
|
+
* password: 'secret',
|
|
14
|
+
* role: 'user',
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* // Confirm the registration email
|
|
18
|
+
* await oblax.auth.accounts.confirm({ confirmationToken: account.confirmation_token })
|
|
19
|
+
*
|
|
20
|
+
* // Admin: list all accounts
|
|
21
|
+
* const all = await oblax.auth.accounts.list()
|
|
22
|
+
*
|
|
23
|
+
* // Admin: activate an account
|
|
24
|
+
* await oblax.auth.accounts.enable({ id: account.id, enabled: true })
|
|
25
|
+
*
|
|
26
|
+
* // Trigger a password-reset email
|
|
27
|
+
* await oblax.auth.accounts.requestPasswordReset({ email: 'alice@example.com' })
|
|
28
|
+
*
|
|
29
|
+
* // Complete the password reset using the token from the email
|
|
30
|
+
* await oblax.auth.accounts.resetPassword({ token: '...', password: 'new-secret' })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class AccountsSubmodule {
|
|
34
|
+
private readonly ctx;
|
|
35
|
+
constructor(ctx: OblaxContext);
|
|
36
|
+
/**
|
|
37
|
+
* Registers a new account.
|
|
38
|
+
*
|
|
39
|
+
* The returned `confirmation_token` should be passed to `confirm()` or sent
|
|
40
|
+
* to the user via email to activate the account. The account is inactive
|
|
41
|
+
* (`active: false`) until both confirmed and enabled.
|
|
42
|
+
*/
|
|
43
|
+
create(params: CreateAccountParams): Promise<Account>;
|
|
44
|
+
/**
|
|
45
|
+
* Confirms account registration using the token from the sign-up email.
|
|
46
|
+
*/
|
|
47
|
+
confirm(params: ConfirmAccountParams): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns all accounts. Requires admin privileges.
|
|
50
|
+
*/
|
|
51
|
+
list(): Promise<Account[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Activates or deactivates an account. Requires admin privileges.
|
|
54
|
+
*
|
|
55
|
+
* @returns `true` on success.
|
|
56
|
+
*/
|
|
57
|
+
enable(params: EnableAccountParams): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Sends a password-reset link to the given email address.
|
|
60
|
+
*
|
|
61
|
+
* @returns The reset link URL (useful in server-side flows where the link
|
|
62
|
+
* is delivered by the calling service rather than by the backend).
|
|
63
|
+
*/
|
|
64
|
+
requestPasswordReset(params: RequestPasswordResetParams): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Sets a new password using the token from a password-reset email.
|
|
67
|
+
* Call `requestPasswordReset` first to obtain the token.
|
|
68
|
+
*/
|
|
69
|
+
resetPassword(params: ResetPasswordParams): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,OAAO,EACP,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C;;;;;;OAMG;IACG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3D;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1D;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIhC;;;;OAIG;IACG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3D;;;;;OAKG;IACG,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC;IAM/E;;;OAGG;IACG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAMhE"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages user accounts.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Register a new user
|
|
7
|
+
* const account = await oblax.auth.accounts.create({
|
|
8
|
+
* firstName: 'Alice',
|
|
9
|
+
* lastName: 'Smith',
|
|
10
|
+
* email: 'alice@example.com',
|
|
11
|
+
* password: 'secret',
|
|
12
|
+
* role: 'user',
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* // Confirm the registration email
|
|
16
|
+
* await oblax.auth.accounts.confirm({ confirmationToken: account.confirmation_token })
|
|
17
|
+
*
|
|
18
|
+
* // Admin: list all accounts
|
|
19
|
+
* const all = await oblax.auth.accounts.list()
|
|
20
|
+
*
|
|
21
|
+
* // Admin: activate an account
|
|
22
|
+
* await oblax.auth.accounts.enable({ id: account.id, enabled: true })
|
|
23
|
+
*
|
|
24
|
+
* // Trigger a password-reset email
|
|
25
|
+
* await oblax.auth.accounts.requestPasswordReset({ email: 'alice@example.com' })
|
|
26
|
+
*
|
|
27
|
+
* // Complete the password reset using the token from the email
|
|
28
|
+
* await oblax.auth.accounts.resetPassword({ token: '...', password: 'new-secret' })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class AccountsSubmodule {
|
|
32
|
+
constructor(ctx) {
|
|
33
|
+
this.ctx = ctx;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Registers a new account.
|
|
37
|
+
*
|
|
38
|
+
* The returned `confirmation_token` should be passed to `confirm()` or sent
|
|
39
|
+
* to the user via email to activate the account. The account is inactive
|
|
40
|
+
* (`active: false`) until both confirmed and enabled.
|
|
41
|
+
*/
|
|
42
|
+
async create(params) {
|
|
43
|
+
return this.ctx.http.post('/auth/accounts', {
|
|
44
|
+
first_name: params.firstName,
|
|
45
|
+
last_name: params.lastName,
|
|
46
|
+
email: params.email,
|
|
47
|
+
password: params.password,
|
|
48
|
+
role: params.role,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Confirms account registration using the token from the sign-up email.
|
|
53
|
+
*/
|
|
54
|
+
async confirm(params) {
|
|
55
|
+
return this.ctx.http.post('/auth/accounts/confirmation', {
|
|
56
|
+
confirmation_token: params.confirmationToken,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns all accounts. Requires admin privileges.
|
|
61
|
+
*/
|
|
62
|
+
async list() {
|
|
63
|
+
return this.ctx.http.get('/auth/accounts');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Activates or deactivates an account. Requires admin privileges.
|
|
67
|
+
*
|
|
68
|
+
* @returns `true` on success.
|
|
69
|
+
*/
|
|
70
|
+
async enable(params) {
|
|
71
|
+
return this.ctx.http.patch(`/auth/accounts/${params.id}/enabled`, {
|
|
72
|
+
enabled: params.enabled,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sends a password-reset link to the given email address.
|
|
77
|
+
*
|
|
78
|
+
* @returns The reset link URL (useful in server-side flows where the link
|
|
79
|
+
* is delivered by the calling service rather than by the backend).
|
|
80
|
+
*/
|
|
81
|
+
async requestPasswordReset(params) {
|
|
82
|
+
return this.ctx.http.post('/auth/accounts/reset-password-link', {
|
|
83
|
+
email: params.email,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sets a new password using the token from a password-reset email.
|
|
88
|
+
* Call `requestPasswordReset` first to obtain the token.
|
|
89
|
+
*/
|
|
90
|
+
async resetPassword(params) {
|
|
91
|
+
return this.ctx.http.put('/auth/accounts/reset-password', {
|
|
92
|
+
token: params.token,
|
|
93
|
+
password: params.password,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AA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H,KAAK,CAAC,aAAa,CAAC,MAA2B;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAO,+BAA+B,EAAE;YAC9D,KAAK,EAAK,MAAM,CAAC,KAAK;YACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import { SessionSubmodule } from './session.js';
|
|
3
|
+
import { AccountsSubmodule } from './accounts.js';
|
|
4
|
+
import { RealmsSubmodule } from './realms.js';
|
|
5
|
+
import { RolesSubmodule } from './roles.js';
|
|
6
|
+
/**
|
|
7
|
+
* Auth module configuration.
|
|
8
|
+
*/
|
|
9
|
+
export interface AuthConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The realm to authenticate against.
|
|
12
|
+
*
|
|
13
|
+
* All session operations (`session.create`, `session.refresh`, etc.) are
|
|
14
|
+
* scoped to this realm. The realm name must match a realm registered in
|
|
15
|
+
* your Oblax backend.
|
|
16
|
+
*
|
|
17
|
+
* @example 'webapp'
|
|
18
|
+
*/
|
|
19
|
+
realm: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The Auth module.
|
|
23
|
+
*
|
|
24
|
+
* Exposes four sub-modules:
|
|
25
|
+
*
|
|
26
|
+
* - `session` — create (authenticated or anonymous), refresh, destroy sessions.
|
|
27
|
+
* - `accounts` — register users, confirm emails, manage passwords.
|
|
28
|
+
* - `realms` — manage authentication realms (multi-tenancy).
|
|
29
|
+
* - `roles` — manage access-level roles within realms.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const oblax = new Oblax({
|
|
34
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
35
|
+
* clientId: 'my-web-app',
|
|
36
|
+
* modules: [PlatformBrowser(), Auth({ realm: 'webapp' })],
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
40
|
+
* await oblax.auth.accounts.create({ firstName: 'Bob', lastName: 'Jones', email: 'bob@example.com', password: 'pw', role: 'user' })
|
|
41
|
+
* const realms = await oblax.auth.realms.list()
|
|
42
|
+
* const roles = await oblax.auth.roles.list()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class AuthModule {
|
|
46
|
+
readonly session: SessionSubmodule;
|
|
47
|
+
readonly accounts: AccountsSubmodule;
|
|
48
|
+
readonly realms: RealmsSubmodule;
|
|
49
|
+
readonly roles: RolesSubmodule;
|
|
50
|
+
constructor(ctx: OblaxContext, config: AuthConfig);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;;OAQG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,UAAU;IACrB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;gBAElB,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU;CAyBlD"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OblaxError } from '@oblax/core';
|
|
2
|
+
import { SessionSubmodule } from './session.js';
|
|
3
|
+
import { AccountsSubmodule } from './accounts.js';
|
|
4
|
+
import { RealmsSubmodule } from './realms.js';
|
|
5
|
+
import { RolesSubmodule } from './roles.js';
|
|
6
|
+
/**
|
|
7
|
+
* The Auth module.
|
|
8
|
+
*
|
|
9
|
+
* Exposes four sub-modules:
|
|
10
|
+
*
|
|
11
|
+
* - `session` — create (authenticated or anonymous), refresh, destroy sessions.
|
|
12
|
+
* - `accounts` — register users, confirm emails, manage passwords.
|
|
13
|
+
* - `realms` — manage authentication realms (multi-tenancy).
|
|
14
|
+
* - `roles` — manage access-level roles within realms.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const oblax = new Oblax({
|
|
19
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
20
|
+
* clientId: 'my-web-app',
|
|
21
|
+
* modules: [PlatformBrowser(), Auth({ realm: 'webapp' })],
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
25
|
+
* await oblax.auth.accounts.create({ firstName: 'Bob', lastName: 'Jones', email: 'bob@example.com', password: 'pw', role: 'user' })
|
|
26
|
+
* const realms = await oblax.auth.realms.list()
|
|
27
|
+
* const roles = await oblax.auth.roles.list()
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class AuthModule {
|
|
31
|
+
constructor(ctx, config) {
|
|
32
|
+
if (!config.realm || config.realm.trim() === '') {
|
|
33
|
+
throw new OblaxError('Auth module: `realm` is required and must not be empty. ' +
|
|
34
|
+
"Pass the realm name when registering the module: Auth({ realm: 'your-realm' })");
|
|
35
|
+
}
|
|
36
|
+
this.session = new SessionSubmodule(ctx, config.realm);
|
|
37
|
+
this.accounts = new AccountsSubmodule(ctx);
|
|
38
|
+
this.realms = new RealmsSubmodule(ctx);
|
|
39
|
+
this.roles = new RolesSubmodule(ctx);
|
|
40
|
+
// Wire up automatic token refresh. The HTTP client will call this on every
|
|
41
|
+
// 401 response. session.refresh() updates the platform's stored token, so
|
|
42
|
+
// the retried request will carry the new credentials.
|
|
43
|
+
ctx.platform.onTokenExpired = async () => {
|
|
44
|
+
try {
|
|
45
|
+
await this.session.refresh();
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAkB3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,UAAU;IAMrB,YAAY,GAAiB,EAAE,MAAkB;QAC/C,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAChD,MAAM,IAAI,UAAU,CAClB,0DAA0D;gBACxD,gFAAgF,CACnF,CAAA;QACH,CAAC;QAED,IAAI,CAAC,OAAO,GAAI,IAAI,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC1C,IAAI,CAAC,MAAM,GAAK,IAAI,eAAe,CAAC,GAAG,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,GAAM,IAAI,cAAc,CAAC,GAAG,CAAC,CAAA;QAEvC,2EAA2E;QAC3E,0EAA0E;QAC1E,sDAAsD;QACtD,GAAG,CAAC,QAAQ,CAAC,cAAc,GAAG,KAAK,IAAI,EAAE;YACvC,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;gBAC5B,OAAO,IAAI,CAAA;YACb,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC,CAAA;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { AuthModule } from './auth.js';
|
|
3
|
+
import type { AuthConfig } from './auth.js';
|
|
4
|
+
export { AuthModule } from './auth.js';
|
|
5
|
+
export type { AuthConfig } from './auth.js';
|
|
6
|
+
export { SessionSubmodule } from './session.js';
|
|
7
|
+
export { AccountsSubmodule } from './accounts.js';
|
|
8
|
+
export { RealmsSubmodule } from './realms.js';
|
|
9
|
+
export { RolesSubmodule } from './roles.js';
|
|
10
|
+
export type { SessionTokens, CreateSessionParams, Account, CreateAccountParams, ConfirmAccountParams, EnableAccountParams, RequestPasswordResetParams, ResetPasswordParams, Realm, ArchivedRealm, CreateRealmParams, UpdateRealmParams, RealmIdParams, RoleType, Role, CreateRoleParams, UpdateRoleParams, RoleIdParams, } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Auth module factory.
|
|
13
|
+
*
|
|
14
|
+
* @param config - `realm` is required; it scopes all session operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Oblax } from '@oblax/core'
|
|
19
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
20
|
+
* import { Auth } from '@oblax/auth'
|
|
21
|
+
*
|
|
22
|
+
* const oblax = new Oblax({
|
|
23
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
24
|
+
* clientId: 'my-web-app',
|
|
25
|
+
* modules: [PlatformBrowser(), Auth({ realm: 'webapp' })],
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Authenticate
|
|
29
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
30
|
+
*
|
|
31
|
+
* // Anonymous session (guest access)
|
|
32
|
+
* await oblax.auth.session.createAnonymous()
|
|
33
|
+
*
|
|
34
|
+
* // Account management
|
|
35
|
+
* const account = await oblax.auth.accounts.create({
|
|
36
|
+
* firstName: 'Bob', lastName: 'Jones',
|
|
37
|
+
* email: 'bob@example.com', password: 'pw', role: 'user',
|
|
38
|
+
* })
|
|
39
|
+
* await oblax.auth.accounts.confirm({ confirmationToken: account.confirmation_token })
|
|
40
|
+
*
|
|
41
|
+
* // Realm & role management (admin)
|
|
42
|
+
* const realms = await oblax.auth.realms.list()
|
|
43
|
+
* const roles = await oblax.auth.roles.list()
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function Auth(config: AuthConfig): OblaxModulePlugin<'auth', AuthModule>;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,YAAY,EAEV,aAAa,EACb,mBAAmB,EAEnB,OAAO,EACP,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EAEnB,KAAK,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EAEb,QAAQ,EACR,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,GACb,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAO9E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AuthModule } from './auth.js';
|
|
2
|
+
export { AuthModule } from './auth.js';
|
|
3
|
+
export { SessionSubmodule } from './session.js';
|
|
4
|
+
export { AccountsSubmodule } from './accounts.js';
|
|
5
|
+
export { RealmsSubmodule } from './realms.js';
|
|
6
|
+
export { RolesSubmodule } from './roles.js';
|
|
7
|
+
/**
|
|
8
|
+
* Auth module factory.
|
|
9
|
+
*
|
|
10
|
+
* @param config - `realm` is required; it scopes all session operations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Oblax } from '@oblax/core'
|
|
15
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
16
|
+
* import { Auth } from '@oblax/auth'
|
|
17
|
+
*
|
|
18
|
+
* const oblax = new Oblax({
|
|
19
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
20
|
+
* clientId: 'my-web-app',
|
|
21
|
+
* modules: [PlatformBrowser(), Auth({ realm: 'webapp' })],
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // Authenticate
|
|
25
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
26
|
+
*
|
|
27
|
+
* // Anonymous session (guest access)
|
|
28
|
+
* await oblax.auth.session.createAnonymous()
|
|
29
|
+
*
|
|
30
|
+
* // Account management
|
|
31
|
+
* const account = await oblax.auth.accounts.create({
|
|
32
|
+
* firstName: 'Bob', lastName: 'Jones',
|
|
33
|
+
* email: 'bob@example.com', password: 'pw', role: 'user',
|
|
34
|
+
* })
|
|
35
|
+
* await oblax.auth.accounts.confirm({ confirmationToken: account.confirmation_token })
|
|
36
|
+
*
|
|
37
|
+
* // Realm & role management (admin)
|
|
38
|
+
* const realms = await oblax.auth.realms.list()
|
|
39
|
+
* const roles = await oblax.auth.roles.list()
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function Auth(config) {
|
|
43
|
+
return {
|
|
44
|
+
name: 'auth',
|
|
45
|
+
create(ctx) {
|
|
46
|
+
return new AuthModule(ctx, config);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA2B3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,IAAI,CAAC,MAAkB;IACrC,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,MAAM,CAAC,GAAiB;YACtB,OAAO,IAAI,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACpC,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/realms.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { ArchivedRealm, CreateRealmParams, Realm, RealmIdParams, UpdateRealmParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages authentication realms.
|
|
5
|
+
*
|
|
6
|
+
* A realm is an isolated namespace for users and roles. Multi-tenant apps
|
|
7
|
+
* typically create one realm per tenant. Deleting a realm is a soft-delete —
|
|
8
|
+
* the realm is archived and can be restored with `unarchive()`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const realms = await oblax.auth.realms.list()
|
|
13
|
+
* const realm = await oblax.auth.realms.get({ id: 'realm-id' })
|
|
14
|
+
*
|
|
15
|
+
* await oblax.auth.realms.update({ id: realm.id, name: 'new-name' })
|
|
16
|
+
* await oblax.auth.realms.delete({ id: realm.id })
|
|
17
|
+
*
|
|
18
|
+
* const archived = await oblax.auth.realms.listArchived()
|
|
19
|
+
* await oblax.auth.realms.unarchive({ id: realm.id })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class RealmsSubmodule {
|
|
23
|
+
private readonly ctx;
|
|
24
|
+
constructor(ctx: OblaxContext);
|
|
25
|
+
/** Returns all active realms. */
|
|
26
|
+
list(): Promise<Realm[]>;
|
|
27
|
+
/** Fetches a single realm by ID. */
|
|
28
|
+
get(params: RealmIdParams): Promise<Realm>;
|
|
29
|
+
/** Creates a new realm. Requires admin privileges. */
|
|
30
|
+
create(params: CreateRealmParams): Promise<Realm>;
|
|
31
|
+
/**
|
|
32
|
+
* Updates a realm's name. Requires admin privileges.
|
|
33
|
+
* Returns `void` (HTTP 204).
|
|
34
|
+
*/
|
|
35
|
+
update(params: UpdateRealmParams): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Soft-deletes (archives) a realm. Requires admin privileges.
|
|
38
|
+
* The realm can be restored with `unarchive()`.
|
|
39
|
+
*/
|
|
40
|
+
delete(params: RealmIdParams): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns all archived (soft-deleted) realms.
|
|
43
|
+
* Each entry includes a `_deleted` flag indicating whether it has been
|
|
44
|
+
* fully marked for deletion.
|
|
45
|
+
*/
|
|
46
|
+
listArchived(): Promise<ArchivedRealm[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Restores an archived realm. Requires admin privileges.
|
|
49
|
+
*/
|
|
50
|
+
unarchive(params: RealmIdParams): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=realms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realms.d.ts","sourceRoot":"","sources":["../src/realms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,aAAa,EACb,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C,iCAAiC;IAC3B,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAI9B,oCAAoC;IAC9B,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IAIhD,sDAAsD;IAChD,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;IAIvD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI9C;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAGtD"}
|
package/dist/realms.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages authentication realms.
|
|
3
|
+
*
|
|
4
|
+
* A realm is an isolated namespace for users and roles. Multi-tenant apps
|
|
5
|
+
* typically create one realm per tenant. Deleting a realm is a soft-delete —
|
|
6
|
+
* the realm is archived and can be restored with `unarchive()`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const realms = await oblax.auth.realms.list()
|
|
11
|
+
* const realm = await oblax.auth.realms.get({ id: 'realm-id' })
|
|
12
|
+
*
|
|
13
|
+
* await oblax.auth.realms.update({ id: realm.id, name: 'new-name' })
|
|
14
|
+
* await oblax.auth.realms.delete({ id: realm.id })
|
|
15
|
+
*
|
|
16
|
+
* const archived = await oblax.auth.realms.listArchived()
|
|
17
|
+
* await oblax.auth.realms.unarchive({ id: realm.id })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class RealmsSubmodule {
|
|
21
|
+
constructor(ctx) {
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
}
|
|
24
|
+
/** Returns all active realms. */
|
|
25
|
+
async list() {
|
|
26
|
+
return this.ctx.http.get('/auth/realms');
|
|
27
|
+
}
|
|
28
|
+
/** Fetches a single realm by ID. */
|
|
29
|
+
async get(params) {
|
|
30
|
+
return this.ctx.http.get(`/auth/realms/${params.id}`);
|
|
31
|
+
}
|
|
32
|
+
/** Creates a new realm. Requires admin privileges. */
|
|
33
|
+
async create(params) {
|
|
34
|
+
return this.ctx.http.post('/auth/realms', params);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Updates a realm's name. Requires admin privileges.
|
|
38
|
+
* Returns `void` (HTTP 204).
|
|
39
|
+
*/
|
|
40
|
+
async update(params) {
|
|
41
|
+
return this.ctx.http.put(`/auth/realms/${params.id}`, { name: params.name });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Soft-deletes (archives) a realm. Requires admin privileges.
|
|
45
|
+
* The realm can be restored with `unarchive()`.
|
|
46
|
+
*/
|
|
47
|
+
async delete(params) {
|
|
48
|
+
return this.ctx.http.delete(`/auth/realms/${params.id}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns all archived (soft-deleted) realms.
|
|
52
|
+
* Each entry includes a `_deleted` flag indicating whether it has been
|
|
53
|
+
* fully marked for deletion.
|
|
54
|
+
*/
|
|
55
|
+
async listArchived() {
|
|
56
|
+
return this.ctx.http.get('/auth/realms:archived');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Restores an archived realm. Requires admin privileges.
|
|
60
|
+
*/
|
|
61
|
+
async unarchive(params) {
|
|
62
|
+
return this.ctx.http.patch(`/auth/realms/${params.id}/unarchive`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=realms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realms.js","sourceRoot":"","sources":["../src/realms.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,eAAe;IAC1B,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD,iCAAiC;IACjC,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAU,cAAc,CAAC,CAAA;IACnD,CAAC;IAED,oCAAoC;IACpC,KAAK,CAAC,GAAG,CAAC,MAAqB;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAQ,gBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9D,CAAC;IAED,sDAAsD;IACtD,KAAK,CAAC,MAAM,CAAC,MAAyB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAQ,cAAc,EAAE,MAAM,CAAC,CAAA;IAC1D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAAyB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAO,gBAAgB,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;IACpF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAAqB;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,gBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAChE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAkB,uBAAuB,CAAC,CAAA;IACpE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,MAAqB;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAO,gBAAgB,MAAM,CAAC,EAAE,YAAY,CAAC,CAAA;IACzE,CAAC;CACF"}
|
package/dist/roles.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CreateRoleParams, Role, RoleIdParams, UpdateRoleParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages roles across all realms.
|
|
5
|
+
*
|
|
6
|
+
* Roles define an access level (`ADMIN`, `MANAGER`, or `USER`) within a realm
|
|
7
|
+
* and are assigned to accounts at registration time. The list endpoint returns
|
|
8
|
+
* all roles regardless of realm; filter by `realm_id` client-side if needed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const roles = await oblax.auth.roles.list()
|
|
13
|
+
* const role = await oblax.auth.roles.get({ id: 'role-id' })
|
|
14
|
+
*
|
|
15
|
+
* const created = await oblax.auth.roles.create({
|
|
16
|
+
* name: 'editor',
|
|
17
|
+
* type: 'MANAGER',
|
|
18
|
+
* realmId: 'realm-id',
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* await oblax.auth.roles.update({ id: created.id, name: 'senior-editor', type: 'MANAGER', realmId: 'realm-id' })
|
|
22
|
+
* await oblax.auth.roles.delete({ id: created.id })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class RolesSubmodule {
|
|
26
|
+
private readonly ctx;
|
|
27
|
+
constructor(ctx: OblaxContext);
|
|
28
|
+
/** Returns all roles across all realms. */
|
|
29
|
+
list(): Promise<Role[]>;
|
|
30
|
+
/** Fetches a single role by ID. */
|
|
31
|
+
get(params: RoleIdParams): Promise<Role>;
|
|
32
|
+
/** Creates a new role in the given realm. Requires admin privileges. */
|
|
33
|
+
create(params: CreateRoleParams): Promise<Role>;
|
|
34
|
+
/**
|
|
35
|
+
* Replaces all editable fields of a role. Requires admin privileges.
|
|
36
|
+
* Returns `void` (HTTP 204).
|
|
37
|
+
*/
|
|
38
|
+
update(params: UpdateRoleParams): Promise<void>;
|
|
39
|
+
/** Deletes a role by ID. Requires admin privileges. */
|
|
40
|
+
delete(params: RoleIdParams): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,YAAY,EACZ,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C,2CAA2C;IACrC,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI7B,mCAAmC;IAC7B,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,wEAAwE;IAClE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD,uDAAuD;IACjD,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
|
package/dist/roles.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages roles across all realms.
|
|
3
|
+
*
|
|
4
|
+
* Roles define an access level (`ADMIN`, `MANAGER`, or `USER`) within a realm
|
|
5
|
+
* and are assigned to accounts at registration time. The list endpoint returns
|
|
6
|
+
* all roles regardless of realm; filter by `realm_id` client-side if needed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const roles = await oblax.auth.roles.list()
|
|
11
|
+
* const role = await oblax.auth.roles.get({ id: 'role-id' })
|
|
12
|
+
*
|
|
13
|
+
* const created = await oblax.auth.roles.create({
|
|
14
|
+
* name: 'editor',
|
|
15
|
+
* type: 'MANAGER',
|
|
16
|
+
* realmId: 'realm-id',
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* await oblax.auth.roles.update({ id: created.id, name: 'senior-editor', type: 'MANAGER', realmId: 'realm-id' })
|
|
20
|
+
* await oblax.auth.roles.delete({ id: created.id })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class RolesSubmodule {
|
|
24
|
+
constructor(ctx) {
|
|
25
|
+
this.ctx = ctx;
|
|
26
|
+
}
|
|
27
|
+
/** Returns all roles across all realms. */
|
|
28
|
+
async list() {
|
|
29
|
+
return this.ctx.http.get('/auth/roles');
|
|
30
|
+
}
|
|
31
|
+
/** Fetches a single role by ID. */
|
|
32
|
+
async get(params) {
|
|
33
|
+
return this.ctx.http.get(`/auth/roles/${params.id}`);
|
|
34
|
+
}
|
|
35
|
+
/** Creates a new role in the given realm. Requires admin privileges. */
|
|
36
|
+
async create(params) {
|
|
37
|
+
return this.ctx.http.post('/auth/roles', {
|
|
38
|
+
name: params.name,
|
|
39
|
+
type: params.type,
|
|
40
|
+
realm_id: params.realmId,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Replaces all editable fields of a role. Requires admin privileges.
|
|
45
|
+
* Returns `void` (HTTP 204).
|
|
46
|
+
*/
|
|
47
|
+
async update(params) {
|
|
48
|
+
return this.ctx.http.put(`/auth/roles/${params.id}`, {
|
|
49
|
+
name: params.name,
|
|
50
|
+
type: params.type,
|
|
51
|
+
realm_id: params.realmId,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Deletes a role by ID. Requires admin privileges. */
|
|
55
|
+
async delete(params) {
|
|
56
|
+
return this.ctx.http.delete(`/auth/roles/${params.id}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,cAAc;IACzB,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD,2CAA2C;IAC3C,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAS,aAAa,CAAC,CAAA;IACjD,CAAC;IAED,mCAAmC;IACnC,KAAK,CAAC,GAAG,CAAC,MAAoB;QAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAO,eAAe,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC5D,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,MAAM,CAAC,MAAwB;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAO,aAAa,EAAE;YAC7C,IAAI,EAAM,MAAM,CAAC,IAAI;YACrB,IAAI,EAAM,MAAM,CAAC,IAAI;YACrB,QAAQ,EAAE,MAAM,CAAC,OAAO;SACzB,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAAwB;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAO,eAAe,MAAM,CAAC,EAAE,EAAE,EAAE;YACzD,IAAI,EAAM,MAAM,CAAC,IAAI;YACrB,IAAI,EAAM,MAAM,CAAC,IAAI;YACrB,QAAQ,EAAE,MAAM,CAAC,OAAO;SACzB,CAAC,CAAA;IACJ,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,MAAM,CAAC,MAAoB;QAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,eAAe,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CreateSessionParams, SessionTokens } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages the authenticated session for a specific realm.
|
|
5
|
+
*
|
|
6
|
+
* The `realm` is fixed at module initialisation time via `AuthConfig.realm`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Authenticate. On token-based platforms this returns the token pair; on
|
|
11
|
+
* // browser platforms credentials arrive as HTTP-only cookies (void return).
|
|
12
|
+
* await oblax.auth.session.create({
|
|
13
|
+
* email: 'alice@example.com',
|
|
14
|
+
* password: 'secret',
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* // Start an anonymous (guest) session
|
|
18
|
+
* await oblax.auth.session.createAnonymous()
|
|
19
|
+
*
|
|
20
|
+
* // Renew before expiry
|
|
21
|
+
* await oblax.auth.session.refresh()
|
|
22
|
+
*
|
|
23
|
+
* // Log out
|
|
24
|
+
* await oblax.auth.session.destroy()
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class SessionSubmodule {
|
|
28
|
+
private readonly ctx;
|
|
29
|
+
private readonly realm;
|
|
30
|
+
constructor(ctx: OblaxContext, realm: string);
|
|
31
|
+
/**
|
|
32
|
+
* Authenticates the user and starts a new session.
|
|
33
|
+
*
|
|
34
|
+
* - On token-based platforms the returned token pair is stored by the
|
|
35
|
+
* platform (via `onAuthSuccess`) and returned to the caller.
|
|
36
|
+
* - On cookie-based (browser) platforms the server sets HTTP-only cookies
|
|
37
|
+
* (`oblax_access_token`, `oblax_refresh_token`) and the response body is
|
|
38
|
+
* plain text (`"OK"`), carrying no JS-readable credentials; this resolves
|
|
39
|
+
* to `undefined` and `onAuthSuccess` is called with an empty payload.
|
|
40
|
+
*/
|
|
41
|
+
create(params: CreateSessionParams): Promise<SessionTokens | void>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an anonymous (guest) session for the configured realm.
|
|
44
|
+
* Useful for accessing public resources that still require a session context.
|
|
45
|
+
*
|
|
46
|
+
* Like `create`, credentials are returned only on token-based platforms; on
|
|
47
|
+
* cookie-based (browser) platforms the server sets cookies and this resolves
|
|
48
|
+
* to `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
createAnonymous(): Promise<SessionTokens | void>;
|
|
51
|
+
/**
|
|
52
|
+
* Extends the current session and returns a fresh token pair.
|
|
53
|
+
*
|
|
54
|
+
* - On browser (cookie) platforms the server reads the `oblax_refresh_token`
|
|
55
|
+
* cookie and re-sets both cookies; the body is plain text and this resolves
|
|
56
|
+
* to `undefined`.
|
|
57
|
+
* - On other (token) platforms the stored refresh token is sent in the
|
|
58
|
+
* request body (`{ oblax_refresh_token }`) and the server issues a new
|
|
59
|
+
* pair in the JSON body, which the platform stores (via `onAuthSuccess`)
|
|
60
|
+
* and this method returns.
|
|
61
|
+
*/
|
|
62
|
+
refresh(): Promise<SessionTokens | void>;
|
|
63
|
+
/**
|
|
64
|
+
* Destroys the current session.
|
|
65
|
+
*
|
|
66
|
+
* Credentials are cleared via `platform.onAuthClear()` even if the API
|
|
67
|
+
* call fails, so the user is always considered logged out after this call.
|
|
68
|
+
*/
|
|
69
|
+
destroy(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the active session, or `null` when the user is not authenticated.
|
|
72
|
+
*
|
|
73
|
+
* Only 401 and 403 responses are treated as "no session". Network errors
|
|
74
|
+
* and server errors (5xx) are re-thrown so callers can handle them.
|
|
75
|
+
*/
|
|
76
|
+
get(): Promise<SessionTokens | null>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEpE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM;IAGhC;;;;;;;;;OASG;IACG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAqBxE;;;;;;;OAOG;IACG,eAAe,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAkBtD;;;;;;;;;;OAUG;IACG,OAAO,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAoB9C;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;;;;OAKG;IACG,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAU3C"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { OblaxHttpError } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Manages the authenticated session for a specific realm.
|
|
4
|
+
*
|
|
5
|
+
* The `realm` is fixed at module initialisation time via `AuthConfig.realm`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Authenticate. On token-based platforms this returns the token pair; on
|
|
10
|
+
* // browser platforms credentials arrive as HTTP-only cookies (void return).
|
|
11
|
+
* await oblax.auth.session.create({
|
|
12
|
+
* email: 'alice@example.com',
|
|
13
|
+
* password: 'secret',
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* // Start an anonymous (guest) session
|
|
17
|
+
* await oblax.auth.session.createAnonymous()
|
|
18
|
+
*
|
|
19
|
+
* // Renew before expiry
|
|
20
|
+
* await oblax.auth.session.refresh()
|
|
21
|
+
*
|
|
22
|
+
* // Log out
|
|
23
|
+
* await oblax.auth.session.destroy()
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class SessionSubmodule {
|
|
27
|
+
constructor(ctx, realm) {
|
|
28
|
+
this.ctx = ctx;
|
|
29
|
+
this.realm = realm;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Authenticates the user and starts a new session.
|
|
33
|
+
*
|
|
34
|
+
* - On token-based platforms the returned token pair is stored by the
|
|
35
|
+
* platform (via `onAuthSuccess`) and returned to the caller.
|
|
36
|
+
* - On cookie-based (browser) platforms the server sets HTTP-only cookies
|
|
37
|
+
* (`oblax_access_token`, `oblax_refresh_token`) and the response body is
|
|
38
|
+
* plain text (`"OK"`), carrying no JS-readable credentials; this resolves
|
|
39
|
+
* to `undefined` and `onAuthSuccess` is called with an empty payload.
|
|
40
|
+
*/
|
|
41
|
+
async create(params) {
|
|
42
|
+
if (this.ctx.platform.credentialDelivery === 'cookie') {
|
|
43
|
+
// Credentials arrive as HTTP-only cookies via Set-Cookie; the body is
|
|
44
|
+
// plain text and holds nothing the platform can persist or return.
|
|
45
|
+
await this.ctx.http.post(`/auth/session/${this.realm}`, params);
|
|
46
|
+
await this.ctx.platform.onAuthSuccess({});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const tokens = await this.ctx.http.post(`/auth/session/${this.realm}`, params);
|
|
50
|
+
await this.ctx.platform.onAuthSuccess({
|
|
51
|
+
oblax_access_token: tokens.oblax_access_token,
|
|
52
|
+
oblax_refresh_token: tokens.oblax_refresh_token,
|
|
53
|
+
expiration: tokens.expiration,
|
|
54
|
+
});
|
|
55
|
+
return tokens;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates an anonymous (guest) session for the configured realm.
|
|
59
|
+
* Useful for accessing public resources that still require a session context.
|
|
60
|
+
*
|
|
61
|
+
* Like `create`, credentials are returned only on token-based platforms; on
|
|
62
|
+
* cookie-based (browser) platforms the server sets cookies and this resolves
|
|
63
|
+
* to `undefined`.
|
|
64
|
+
*/
|
|
65
|
+
async createAnonymous() {
|
|
66
|
+
if (this.ctx.platform.credentialDelivery === 'cookie') {
|
|
67
|
+
await this.ctx.http.get(`/auth/session/${this.realm}/anonymous`);
|
|
68
|
+
await this.ctx.platform.onAuthSuccess({});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const tokens = await this.ctx.http.get(`/auth/session/${this.realm}/anonymous`);
|
|
72
|
+
await this.ctx.platform.onAuthSuccess({
|
|
73
|
+
oblax_access_token: tokens.oblax_access_token,
|
|
74
|
+
oblax_refresh_token: tokens.oblax_refresh_token,
|
|
75
|
+
expiration: tokens.expiration,
|
|
76
|
+
});
|
|
77
|
+
return tokens;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extends the current session and returns a fresh token pair.
|
|
81
|
+
*
|
|
82
|
+
* - On browser (cookie) platforms the server reads the `oblax_refresh_token`
|
|
83
|
+
* cookie and re-sets both cookies; the body is plain text and this resolves
|
|
84
|
+
* to `undefined`.
|
|
85
|
+
* - On other (token) platforms the stored refresh token is sent in the
|
|
86
|
+
* request body (`{ oblax_refresh_token }`) and the server issues a new
|
|
87
|
+
* pair in the JSON body, which the platform stores (via `onAuthSuccess`)
|
|
88
|
+
* and this method returns.
|
|
89
|
+
*/
|
|
90
|
+
async refresh() {
|
|
91
|
+
if (this.ctx.platform.credentialDelivery === 'cookie') {
|
|
92
|
+
await this.ctx.http.put(`/auth/session/${this.realm}`);
|
|
93
|
+
await this.ctx.platform.onAuthSuccess({});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const refreshToken = await this.ctx.platform.getRefreshToken();
|
|
97
|
+
const tokens = await this.ctx.http.put(`/auth/session/${this.realm}`, refreshToken ? { oblax_refresh_token: refreshToken } : undefined);
|
|
98
|
+
await this.ctx.platform.onAuthSuccess({
|
|
99
|
+
oblax_access_token: tokens.oblax_access_token,
|
|
100
|
+
oblax_refresh_token: tokens.oblax_refresh_token,
|
|
101
|
+
expiration: tokens.expiration,
|
|
102
|
+
});
|
|
103
|
+
return tokens;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Destroys the current session.
|
|
107
|
+
*
|
|
108
|
+
* Credentials are cleared via `platform.onAuthClear()` even if the API
|
|
109
|
+
* call fails, so the user is always considered logged out after this call.
|
|
110
|
+
*/
|
|
111
|
+
async destroy() {
|
|
112
|
+
try {
|
|
113
|
+
await this.ctx.http.delete(`/auth/session/${this.realm}`);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await this.ctx.platform.onAuthClear();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the active session, or `null` when the user is not authenticated.
|
|
121
|
+
*
|
|
122
|
+
* Only 401 and 403 responses are treated as "no session". Network errors
|
|
123
|
+
* and server errors (5xx) are re-thrown so callers can handle them.
|
|
124
|
+
*/
|
|
125
|
+
async get() {
|
|
126
|
+
try {
|
|
127
|
+
return await this.ctx.http.get(`/auth/session/${this.realm}`);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
if (err instanceof OblaxHttpError && (err.status === 401 || err.status === 403)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAI5C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,YACmB,GAAiB,EACjB,KAAa;QADb,QAAG,GAAH,GAAG,CAAc;QACjB,UAAK,GAAL,KAAK,CAAQ;IAC7B,CAAC;IAEJ;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,MAA2B;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,KAAK,QAAQ,EAAE,CAAC;YACtD,sEAAsE;YACtE,mEAAmE;YACnE,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAO,iBAAiB,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAA;YACrE,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,a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AG,YAAY,cAAc,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,EAAE,CAAC;gBAChF,OAAO,IAAI,CAAA;YACb,CAAC;YACD,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokens returned by the backend on a successful authentication.
|
|
3
|
+
*
|
|
4
|
+
* On browser platforms the server also sets HTTP-only cookies
|
|
5
|
+
* (`oblax_access_token` and `oblax_refresh_token`), but the JSON body is
|
|
6
|
+
* always present and is the primary credential source for non-browser
|
|
7
|
+
* platforms (desktop, mobile, service).
|
|
8
|
+
*/
|
|
9
|
+
export interface SessionTokens {
|
|
10
|
+
/** Short-lived JWT access token. */
|
|
11
|
+
oblax_access_token: string;
|
|
12
|
+
/** Long-lived token used to obtain a new access token via `session.refresh()`. */
|
|
13
|
+
oblax_refresh_token: string;
|
|
14
|
+
/** Unix timestamp (seconds) when the access token expires. */
|
|
15
|
+
expiration: number;
|
|
16
|
+
}
|
|
17
|
+
export interface CreateSessionParams {
|
|
18
|
+
/** User's email address. */
|
|
19
|
+
email: string;
|
|
20
|
+
/** User's password. */
|
|
21
|
+
password: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Account {
|
|
24
|
+
id: string;
|
|
25
|
+
owner_id: string;
|
|
26
|
+
/** Authentication provider, e.g. `"OBLAX"`. */
|
|
27
|
+
provider: string;
|
|
28
|
+
email: string;
|
|
29
|
+
auth_token: string;
|
|
30
|
+
refresh_token: string;
|
|
31
|
+
confirmed: boolean;
|
|
32
|
+
active: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* One-time token sent to the user's email address.
|
|
35
|
+
* Present only on the `create` response; empty string after confirmation.
|
|
36
|
+
*/
|
|
37
|
+
confirmation_token: string;
|
|
38
|
+
}
|
|
39
|
+
export interface CreateAccountParams {
|
|
40
|
+
firstName: string;
|
|
41
|
+
lastName: string;
|
|
42
|
+
email: string;
|
|
43
|
+
password: string;
|
|
44
|
+
/**
|
|
45
|
+
* Name of the role to assign to the new account.
|
|
46
|
+
* Must match a role that exists in the target realm.
|
|
47
|
+
*/
|
|
48
|
+
role: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ConfirmAccountParams {
|
|
51
|
+
/** Token from the confirmation email sent after `accounts.create()`. */
|
|
52
|
+
confirmationToken: string;
|
|
53
|
+
}
|
|
54
|
+
export interface EnableAccountParams {
|
|
55
|
+
/** Account ID. */
|
|
56
|
+
id: string;
|
|
57
|
+
/** `true` to activate the account, `false` to deactivate it. */
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface RequestPasswordResetParams {
|
|
61
|
+
email: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ResetPasswordParams {
|
|
64
|
+
/** Reset token received via email after calling `accounts.requestPasswordReset()`. */
|
|
65
|
+
token: string;
|
|
66
|
+
/** The new password to set. */
|
|
67
|
+
password: string;
|
|
68
|
+
}
|
|
69
|
+
export interface Realm {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
}
|
|
73
|
+
/** Realm entry returned by the archived-realms list. */
|
|
74
|
+
export interface ArchivedRealm {
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
/** `true` when the realm has been soft-deleted. */
|
|
78
|
+
_deleted: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface CreateRealmParams {
|
|
81
|
+
name: string;
|
|
82
|
+
}
|
|
83
|
+
export interface UpdateRealmParams {
|
|
84
|
+
/** ID of the realm to update. */
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
}
|
|
88
|
+
export interface RealmIdParams {
|
|
89
|
+
id: string;
|
|
90
|
+
}
|
|
91
|
+
/** Access level of a role. */
|
|
92
|
+
export type RoleType = 'ADMIN' | 'MANAGER' | 'USER';
|
|
93
|
+
export interface Role {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
type: RoleType;
|
|
97
|
+
realm_id: string;
|
|
98
|
+
}
|
|
99
|
+
export interface CreateRoleParams {
|
|
100
|
+
name: string;
|
|
101
|
+
type: RoleType;
|
|
102
|
+
/** ID of the realm this role belongs to. */
|
|
103
|
+
realmId: string;
|
|
104
|
+
}
|
|
105
|
+
export interface UpdateRoleParams {
|
|
106
|
+
/** ID of the role to update. */
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
type: RoleType;
|
|
110
|
+
/** ID of the realm this role belongs to. */
|
|
111
|
+
realmId: string;
|
|
112
|
+
}
|
|
113
|
+
export interface RoleIdParams {
|
|
114
|
+
id: string;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,kFAAkF;IAClF,mBAAmB,EAAE,MAAM,CAAA;IAC3B,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAID,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,kBAAkB,EAAE,MA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E,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;CACX"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oblax/auth",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Oblax SDK — auth module (session, realms, roles)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Oblax SDK for JavaScript Team",
|
|
8
|
+
"url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/oblaxio/oblax-sdk-js.git",
|
|
14
|
+
"directory": "packages/auth"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/oblaxio/oblax-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oblax",
|
|
21
|
+
"sdk",
|
|
22
|
+
"auth"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@oblax/core": "1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.5.0",
|
|
44
|
+
"@oblax/core": "1.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc --build tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --build tsconfig.json --dry",
|
|
49
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
50
|
+
}
|
|
51
|
+
}
|