@oblax/platform-server 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/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +35 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +60 -0
- package/dist/platform.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { ServerPlatform } from './platform.js';
|
|
3
|
+
export { ServerPlatform } from './platform.js';
|
|
4
|
+
/**
|
|
5
|
+
* Server platform factory.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const oblax = new Oblax({
|
|
10
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
11
|
+
* clientId: 'my-service',
|
|
12
|
+
* modules: [PlatformServer(), Auth()],
|
|
13
|
+
* })
|
|
14
|
+
* await oblax.auth.session.create({ username: 'svc', password: 'secret' })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function PlatformServer(): OblaxModulePlugin<'platform', ServerPlatform>;
|
|
18
|
+
//# 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,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,IAAI,iBAAiB,CAAC,UAAU,EAAE,cAAc,CAAC,CAK9E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ServerPlatform } from './platform.js';
|
|
2
|
+
export { ServerPlatform } from './platform.js';
|
|
3
|
+
/**
|
|
4
|
+
* Server platform factory.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const oblax = new Oblax({
|
|
9
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
10
|
+
* clientId: 'my-service',
|
|
11
|
+
* modules: [PlatformServer(), Auth()],
|
|
12
|
+
* })
|
|
13
|
+
* await oblax.auth.session.create({ username: 'svc', password: 'secret' })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function PlatformServer() {
|
|
17
|
+
return {
|
|
18
|
+
name: 'platform',
|
|
19
|
+
create: () => new ServerPlatform(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,cAAc,EAAE;KACnC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AuthPayload, CredentialDelivery, OblaxPlatform } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Server platform.
|
|
4
|
+
*
|
|
5
|
+
* Auth strategy: `Authorization: Bearer <token>` header.
|
|
6
|
+
* Both the access token and refresh token are stored in process memory after
|
|
7
|
+
* a successful login. The access token is sent on every request; the refresh
|
|
8
|
+
* token is kept so `session.refresh()` can obtain a new pair.
|
|
9
|
+
*
|
|
10
|
+
* Suitable for: Node.js, Bun, Deno, SSR frameworks, React Native, CLI tools.
|
|
11
|
+
*
|
|
12
|
+
* Security note: tokens live in process memory. For per-request isolation
|
|
13
|
+
* in multi-tenant SSR, create a fresh `ServerPlatform` instance per request.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ServerPlatform implements OblaxPlatform {
|
|
16
|
+
private accessToken;
|
|
17
|
+
private refreshToken;
|
|
18
|
+
/** Credentials are returned in the JSON body and stored in memory. */
|
|
19
|
+
readonly credentialDelivery: CredentialDelivery;
|
|
20
|
+
/**
|
|
21
|
+
* Called by the HTTP client when a 401 is received.
|
|
22
|
+
* The auth module overwrites this after initialization to wire in
|
|
23
|
+
* `session.refresh()`. Default: no-op (returns false).
|
|
24
|
+
*/
|
|
25
|
+
onTokenExpired: () => Promise<boolean>;
|
|
26
|
+
prepareRequest(init: RequestInit): Promise<RequestInit>;
|
|
27
|
+
onAuthSuccess(payload: AuthPayload): Promise<void>;
|
|
28
|
+
onAuthClear(): Promise<void>;
|
|
29
|
+
/** `true` when an access token is held in memory. */
|
|
30
|
+
get isAuthenticated(): boolean;
|
|
31
|
+
/** The stored refresh token, or `null` if not available. */
|
|
32
|
+
get storedRefreshToken(): string | null;
|
|
33
|
+
getRefreshToken(): Promise<string | null>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjF;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,aAAa;IAClD,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,YAAY,CAAsB;IAE1C,sEAAsE;IACtE,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAU;IAEzD;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAA+B;IAE/D,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IASlD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAKlC,qDAAqD;IACrD,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,4DAA4D;IAC5D,IAAI,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAEtC;IAEK,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAGhD"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server platform.
|
|
3
|
+
*
|
|
4
|
+
* Auth strategy: `Authorization: Bearer <token>` header.
|
|
5
|
+
* Both the access token and refresh token are stored in process memory after
|
|
6
|
+
* a successful login. The access token is sent on every request; the refresh
|
|
7
|
+
* token is kept so `session.refresh()` can obtain a new pair.
|
|
8
|
+
*
|
|
9
|
+
* Suitable for: Node.js, Bun, Deno, SSR frameworks, React Native, CLI tools.
|
|
10
|
+
*
|
|
11
|
+
* Security note: tokens live in process memory. For per-request isolation
|
|
12
|
+
* in multi-tenant SSR, create a fresh `ServerPlatform` instance per request.
|
|
13
|
+
*/
|
|
14
|
+
export class ServerPlatform {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.accessToken = null;
|
|
17
|
+
this.refreshToken = null;
|
|
18
|
+
/** Credentials are returned in the JSON body and stored in memory. */
|
|
19
|
+
this.credentialDelivery = 'token';
|
|
20
|
+
/**
|
|
21
|
+
* Called by the HTTP client when a 401 is received.
|
|
22
|
+
* The auth module overwrites this after initialization to wire in
|
|
23
|
+
* `session.refresh()`. Default: no-op (returns false).
|
|
24
|
+
*/
|
|
25
|
+
this.onTokenExpired = () => Promise.resolve(false);
|
|
26
|
+
}
|
|
27
|
+
async prepareRequest(init) {
|
|
28
|
+
if (!this.accessToken)
|
|
29
|
+
return init;
|
|
30
|
+
const existing = (init.headers ?? {});
|
|
31
|
+
return {
|
|
32
|
+
...init,
|
|
33
|
+
headers: { ...existing, Authorization: `Bearer ${this.accessToken}` },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async onAuthSuccess(payload) {
|
|
37
|
+
if (payload.oblax_access_token !== undefined) {
|
|
38
|
+
this.accessToken = payload.oblax_access_token;
|
|
39
|
+
}
|
|
40
|
+
if (payload.oblax_refresh_token !== undefined) {
|
|
41
|
+
this.refreshToken = payload.oblax_refresh_token;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async onAuthClear() {
|
|
45
|
+
this.accessToken = null;
|
|
46
|
+
this.refreshToken = null;
|
|
47
|
+
}
|
|
48
|
+
/** `true` when an access token is held in memory. */
|
|
49
|
+
get isAuthenticated() {
|
|
50
|
+
return this.accessToken !== null;
|
|
51
|
+
}
|
|
52
|
+
/** The stored refresh token, or `null` if not available. */
|
|
53
|
+
get storedRefreshToken() {
|
|
54
|
+
return this.refreshToken;
|
|
55
|
+
}
|
|
56
|
+
async getRefreshToken() {
|
|
57
|
+
return this.refreshToken;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IAA3B;QACU,gBAAW,GAAkB,IAAI,CAAA;QACjC,iBAAY,GAAkB,IAAI,CAAA;QAE1C,sEAAsE;QAC7D,uBAAkB,GAAuB,OAAO,CAAA;QAEzD;;;;WAIG;QACH,mBAAc,GAA2B,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAuCvE,CAAC;IArCC,KAAK,CAAC,cAAc,CAAC,IAAiB;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAA;QAElC,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAA2B,CAAA;QAC/D,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE,EAAE;SACtE,CAAA;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAoB;QACtC,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAA;QAC/C,CAAC;QACD,IAAI,OAAO,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC9C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAA;QACjD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;IAC1B,CAAC;IAED,qDAAqD;IACrD,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,CAAA;IAClC,CAAC;IAED,4DAA4D;IAC5D,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oblax/platform-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Oblax SDK — server platform (Bearer token auth)",
|
|
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/platform-server"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/oblaxio/oblax-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oblax",
|
|
21
|
+
"sdk",
|
|
22
|
+
"platform",
|
|
23
|
+
"server"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@oblax/core": "1.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.5.0",
|
|
45
|
+
"@oblax/core": "1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc --build tsconfig.json",
|
|
49
|
+
"typecheck": "tsc --build tsconfig.json --dry",
|
|
50
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
51
|
+
}
|
|
52
|
+
}
|