@oblax/platform-browser 2.0.0 → 2.2.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/README.md +59 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @oblax/platform-browser
|
|
2
|
+
|
|
3
|
+
The platform package for Oblax apps that run in a browser: React, Vue, Svelte, Angular or plain
|
|
4
|
+
JavaScript. Give it to `new Oblax()` with the modules the app uses.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @oblax/core @oblax/platform-browser @oblax/auth
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { Oblax } from '@oblax/core'
|
|
12
|
+
import { PlatformBrowser } from '@oblax/platform-browser'
|
|
13
|
+
import { Auth } from '@oblax/auth'
|
|
14
|
+
|
|
15
|
+
const oblax = new Oblax({
|
|
16
|
+
endpoint: '<api-endpoint>', // the client's endpoint: `obx project clients list`
|
|
17
|
+
clientId: '<client-id>', // a browser client's identifier
|
|
18
|
+
modules: [PlatformBrowser(), Auth({ realm: '<realm>' })],
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Sign-in is cookies
|
|
23
|
+
|
|
24
|
+
The API sets the session as HTTP-only cookies, and the browser sends them on every request
|
|
25
|
+
(`credentials: 'include'`). The app's JavaScript never sees a token, so a script injected into the
|
|
26
|
+
page can't steal one. There's nothing to store or clear: `oblax.auth` signs in and out, and a
|
|
27
|
+
request that comes back 401 refreshes the session once and is sent again.
|
|
28
|
+
|
|
29
|
+
Use it with a `browser` client (`obx project clients list` shows each client's type). A backend
|
|
30
|
+
uses `@oblax/platform-server` with a `service` client instead, and an app on a phone
|
|
31
|
+
`@oblax/platform-mobile`.
|
|
32
|
+
|
|
33
|
+
## The endpoint
|
|
34
|
+
|
|
35
|
+
The API takes a client's requests only on the host in the client's `tld`, so the endpoint is the
|
|
36
|
+
API's address with that host: `obx project clients list` prints it for each client, as does the
|
|
37
|
+
`oblax` MCP server's `project_status` (`obx mcp`).
|
|
38
|
+
|
|
39
|
+
On a local stack, the API answers cross-origin requests only for its own origin. A page on its own
|
|
40
|
+
dev server (`http://localhost:5173`) can't call `http://localhost:8080` directly: proxy `/api` to
|
|
41
|
+
the endpoint in the dev server and give the SDK the page's own origin.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// vite.config.ts
|
|
45
|
+
export default {
|
|
46
|
+
server: { proxy: { '/api': 'http://localhost:8080' } },
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// the app
|
|
50
|
+
const oblax = new Oblax({
|
|
51
|
+
endpoint: window.location.origin,
|
|
52
|
+
clientId: '<client-id>',
|
|
53
|
+
modules: [PlatformBrowser(), Auth({ realm: '<realm>' })],
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Try sign-in in a browser, not only from Node: cookies are what the browser platform depends on.
|
|
58
|
+
|
|
59
|
+
More: [docs.oblax.io](https://docs.oblax.io/docs/getting-started/first-call/).
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { BrowserPlatform } from './platform.js';
|
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
9
|
* const oblax = new Oblax({
|
|
10
|
-
* endpoint: '
|
|
10
|
+
* endpoint: '<api-endpoint>', // the client's endpoint: `obx project clients list`
|
|
11
11
|
* clientId: 'my-web-app',
|
|
12
12
|
* modules: [PlatformBrowser(), Auth()],
|
|
13
13
|
* })
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { BrowserPlatform } from './platform.js';
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
8
|
* const oblax = new Oblax({
|
|
9
|
-
* endpoint: '
|
|
9
|
+
* endpoint: '<api-endpoint>', // the client's endpoint: `obx project clients list`
|
|
10
10
|
* clientId: 'my-web-app',
|
|
11
11
|
* modules: [PlatformBrowser(), Auth()],
|
|
12
12
|
* })
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oblax/platform-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Oblax SDK — browser platform (cookie-based auth)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Oblax SDK for JavaScript Team",
|
|
8
|
-
"url": "https://docs.oblax.io/docs/getting-started/
|
|
8
|
+
"url": "https://docs.oblax.io/docs/getting-started/first-call/"
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
|
|
11
11
|
"repository": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@oblax/core": "^2.
|
|
41
|
+
"@oblax/core": "^2.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.5.0",
|
|
45
|
-
"@oblax/core": "2.
|
|
45
|
+
"@oblax/core": "2.2.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc --build tsconfig.json",
|