@object-ui/auth 16.0.0 → 16.1.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @object-ui/auth
|
|
2
2
|
|
|
3
|
+
## 16.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 803558e: feat(data): thread the host's authenticated fetch into `provider: 'api'` data sources (#2725)
|
|
8
|
+
|
|
9
|
+
`provider: 'api'` view data sources went through a bare `globalThis.fetch`, so
|
|
10
|
+
custom endpoints (gantt composite trees, report aggregates) carried only
|
|
11
|
+
same-origin cookies while every native `/api/v1/*` request carried
|
|
12
|
+
`Authorization: Bearer` — the moment cookie HMAC verification failed (dev
|
|
13
|
+
restart rotating the fallback auth secret, cookie expiry/rotation in prod)
|
|
14
|
+
those views 401'd while the rest of the app kept working.
|
|
15
|
+
|
|
16
|
+
- **`@object-ui/react`** — `SchemaRendererProvider` accepts an optional
|
|
17
|
+
`apiFetch`; nested providers inherit it from their parent so re-wrapped
|
|
18
|
+
subtrees (react pages, preview surfaces) keep the host's authentication.
|
|
19
|
+
`useViewData` defaults the api-provider adapter's fetch to the context
|
|
20
|
+
`apiFetch` (explicit `adapterOptions.fetch` still wins).
|
|
21
|
+
- **`@object-ui/auth`** — `createAuthenticatedFetch` gains a
|
|
22
|
+
`sameOriginOnly` option: cross-origin URLs pass through to the bare fetch
|
|
23
|
+
with no `Authorization` / `X-Tenant-ID` / `Accept-Language`, so metadata-
|
|
24
|
+
supplied third-party URLs never see the platform token.
|
|
25
|
+
- **`@object-ui/app-shell`** — the console wires
|
|
26
|
+
`createAuthenticatedFetch({ sameOriginOnly: true })` (settle-signal wrapped)
|
|
27
|
+
as `apiFetch` on the root `SchemaRendererProvider`.
|
|
28
|
+
- **`@object-ui/plugin-gantt`** — `ObjectGantt` resolves its api-provider
|
|
29
|
+
DataSource with the context `apiFetch`, covering reads and write-backs.
|
|
30
|
+
|
|
31
|
+
Behaviour is unchanged for hosts that don't provide `apiFetch` (bare fetch +
|
|
32
|
+
cookies, as before).
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [7cf4051]
|
|
37
|
+
- Updated dependencies [94d4876]
|
|
38
|
+
- Updated dependencies [2b17339]
|
|
39
|
+
- Updated dependencies [31b77d4]
|
|
40
|
+
- Updated dependencies [6d4fbe6]
|
|
41
|
+
- Updated dependencies [62b9ab5]
|
|
42
|
+
- Updated dependencies [29c6040]
|
|
43
|
+
- Updated dependencies [faebac3]
|
|
44
|
+
- Updated dependencies [199fa83]
|
|
45
|
+
- @object-ui/types@16.1.0
|
|
46
|
+
|
|
3
47
|
## 16.0.0
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -126,10 +126,16 @@ Displays current user info with avatar and sign-out:
|
|
|
126
126
|
|
|
127
127
|
### createAuthenticatedFetch
|
|
128
128
|
|
|
129
|
-
Creates a fetch wrapper that injects
|
|
129
|
+
Creates a fetch wrapper that injects the stored Bearer token (plus
|
|
130
|
+
`X-Tenant-ID` and `Accept-Language`) into API requests:
|
|
130
131
|
|
|
131
132
|
```tsx
|
|
132
|
-
const authedFetch = createAuthenticatedFetch(
|
|
133
|
+
const authedFetch = createAuthenticatedFetch();
|
|
134
|
+
|
|
135
|
+
// For fetches whose target URL comes from view metadata (`provider: 'api'`
|
|
136
|
+
// data sources), restrict credential injection to the current page's origin
|
|
137
|
+
// so the platform token never leaks to third-party hosts:
|
|
138
|
+
const apiProviderFetch = createAuthenticatedFetch({ sameOriginOnly: true });
|
|
133
139
|
```
|
|
134
140
|
|
|
135
141
|
## Preview Mode
|
|
@@ -24,6 +24,18 @@ export declare const ActiveOrganizationStorage: {
|
|
|
24
24
|
set(orgId: string): void;
|
|
25
25
|
clear(): void;
|
|
26
26
|
};
|
|
27
|
+
export interface CreateAuthenticatedFetchOptions {
|
|
28
|
+
/**
|
|
29
|
+
* When true, requests whose URL resolves to a different origin than the
|
|
30
|
+
* current page are passed through to the bare global fetch — no
|
|
31
|
+
* Authorization, X-Tenant-ID, or Accept-Language headers are attached.
|
|
32
|
+
*
|
|
33
|
+
* Use this for fetches whose target URL comes from view metadata
|
|
34
|
+
* (`provider: 'api'` data sources): those may point at third-party hosts
|
|
35
|
+
* that must never see the platform bearer token.
|
|
36
|
+
*/
|
|
37
|
+
sameOriginOnly?: boolean;
|
|
38
|
+
}
|
|
27
39
|
/**
|
|
28
40
|
* Creates an authenticated fetch wrapper that injects the Bearer token
|
|
29
41
|
* from localStorage into every request to the ObjectStack API.
|
|
@@ -42,5 +54,5 @@ export declare const ActiveOrganizationStorage: {
|
|
|
42
54
|
* });
|
|
43
55
|
* ```
|
|
44
56
|
*/
|
|
45
|
-
export declare function createAuthenticatedFetch(): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
57
|
+
export declare function createAuthenticatedFetch(options?: CreateAuthenticatedFetchOptions): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
46
58
|
//# sourceMappingURL=createAuthenticatedFetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthenticatedFetch.d.ts","sourceRoot":"","sources":["../src/createAuthenticatedFetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID;;;GAGG;AACH,eAAO,MAAM,yBAAyB;kBACd,MAAM,GAAG,IAAI;WAE5B,MAAM,GAAG,IAAI;eAST,MAAM,GAAG,IAAI;aASf,IAAI;CAQd,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"createAuthenticatedFetch.d.ts","sourceRoot":"","sources":["../src/createAuthenticatedFetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID;;;GAGG;AACH,eAAO,MAAM,yBAAyB;kBACd,MAAM,GAAG,IAAI;WAE5B,MAAM,GAAG,IAAI;eAST,MAAM,GAAG,IAAI;aASf,IAAI;CAQd,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,CAAC,EAAE,+BAA+B,GACxC,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0CrE"}
|
|
@@ -42,6 +42,17 @@ export const ActiveOrganizationStorage = {
|
|
|
42
42
|
catch { /* SSR / test */ }
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
|
+
/** True when `url` resolves to a different origin than the current page. */
|
|
46
|
+
function isCrossOrigin(url) {
|
|
47
|
+
if (typeof window === 'undefined' || !window.location)
|
|
48
|
+
return true;
|
|
49
|
+
try {
|
|
50
|
+
return new URL(url, window.location.href).origin !== window.location.origin;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
45
56
|
/**
|
|
46
57
|
* Creates an authenticated fetch wrapper that injects the Bearer token
|
|
47
58
|
* from localStorage into every request to the ObjectStack API.
|
|
@@ -60,10 +71,13 @@ export const ActiveOrganizationStorage = {
|
|
|
60
71
|
* });
|
|
61
72
|
* ```
|
|
62
73
|
*/
|
|
63
|
-
export function createAuthenticatedFetch() {
|
|
74
|
+
export function createAuthenticatedFetch(options) {
|
|
64
75
|
return async (input, init) => {
|
|
65
76
|
const headers = new Headers(init?.headers);
|
|
66
77
|
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
78
|
+
if (options?.sameOriginOnly && isCrossOrigin(url)) {
|
|
79
|
+
return fetch(input, init);
|
|
80
|
+
}
|
|
67
81
|
const isApiCall = /\/api\//i.test(url);
|
|
68
82
|
const token = TokenStorage.get();
|
|
69
83
|
if (token && isApiCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/auth",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Authentication system for Object UI with AuthProvider, useAuth hook, AuthGuard, and form components.",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"better-auth": "^1.6.23",
|
|
34
|
-
"@object-ui/types": "16.
|
|
34
|
+
"@object-ui/types": "16.1.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "19.2.17",
|