@seliseblocks/client 0.1.0-beta.0 → 0.1.0-beta.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.
@@ -234,9 +234,13 @@ export declare class BlocksAuthenticationClient {
234
234
  */
235
235
  accessToken(): Promise<string | undefined>;
236
236
  /**
237
- * What: checks whether `accessToken()` currently resolves a non-empty token.
238
- * Why: apps may need a lightweight UI/session guard before rendering protected areas.
239
- * How: use it as a convenience only; real authorization still comes from Blocks API responses and IAM permissions.
237
+ * What: validates the current session against IAM through `GET /iam/v4/auth/me`.
238
+ * Why: a caller-owned `accessToken` may be absent by design -- IAM's hosted IdP flow sets the
239
+ * session as a Secure, httpOnly cookie by default, so checking for a local token would report
240
+ * "signed out" even when the browser holds a valid session cookie. IAM is the source of truth.
241
+ * How: checks the raw response status rather than `userInfo()` -- `json()` intentionally never
242
+ * throws on non-2xx (auth endpoints can return protocol-shaped error bodies), so a 401 there
243
+ * would otherwise resolve as if the call had succeeded.
240
244
  */
241
245
  isAuthenticated(): Promise<boolean>;
242
246
  /**
@@ -1,7 +1,7 @@
1
1
  export class BlocksAuthenticationClient {
2
2
  clientConfig;
3
3
  fetchImpl;
4
- constructor(clientConfig, fetchImpl = globalThis.fetch) {
4
+ constructor(clientConfig, fetchImpl = globalThis.fetch?.bind(globalThis)) {
5
5
  this.clientConfig = clientConfig;
6
6
  this.fetchImpl = fetchImpl;
7
7
  if (!this.fetchImpl)
@@ -332,12 +332,22 @@ export class BlocksAuthenticationClient {
332
332
  : this.clientConfig.accessToken;
333
333
  }
334
334
  /**
335
- * What: checks whether `accessToken()` currently resolves a non-empty token.
336
- * Why: apps may need a lightweight UI/session guard before rendering protected areas.
337
- * How: use it as a convenience only; real authorization still comes from Blocks API responses and IAM permissions.
335
+ * What: validates the current session against IAM through `GET /iam/v4/auth/me`.
336
+ * Why: a caller-owned `accessToken` may be absent by design -- IAM's hosted IdP flow sets the
337
+ * session as a Secure, httpOnly cookie by default, so checking for a local token would report
338
+ * "signed out" even when the browser holds a valid session cookie. IAM is the source of truth.
339
+ * How: checks the raw response status rather than `userInfo()` -- `json()` intentionally never
340
+ * throws on non-2xx (auth endpoints can return protocol-shaped error bodies), so a 401 there
341
+ * would otherwise resolve as if the call had succeeded.
338
342
  */
339
343
  async isAuthenticated() {
340
- return Boolean(await this.accessToken());
344
+ try {
345
+ const response = await this.raw("/iam/v4/auth/me", { method: "GET" });
346
+ return response.ok;
347
+ }
348
+ catch {
349
+ return false;
350
+ }
341
351
  }
342
352
  /**
343
353
  * What: sends a JSON Auth/IdPController request and returns the parsed response body.
@@ -385,6 +395,9 @@ export class BlocksAuthenticationClient {
385
395
  }
386
396
  return this.fetchImpl(url, {
387
397
  body: options.body,
398
+ // IAM's hosted IdP flow sets the session as a Secure, httpOnly cookie by default;
399
+ // without this the browser never sends it back on subsequent Auth/IdP requests.
400
+ credentials: "include",
388
401
  headers,
389
402
  method: options.method
390
403
  });
@@ -3,7 +3,7 @@ export class BlocksHttpClient {
3
3
  config;
4
4
  auth;
5
5
  fetchImpl;
6
- constructor(config, auth, fetchImpl = globalThis.fetch) {
6
+ constructor(config, auth, fetchImpl = globalThis.fetch?.bind(globalThis)) {
7
7
  this.config = config;
8
8
  this.auth = auth;
9
9
  this.fetchImpl = fetchImpl;
@@ -26,6 +26,9 @@ export class BlocksHttpClient {
26
26
  }
27
27
  const response = await this.fetchImpl(url, {
28
28
  body: rawBody ?? (options.body === undefined ? undefined : JSON.stringify(options.body)),
29
+ // IAM's hosted IdP flow sets the session as a Secure, httpOnly cookie by default;
30
+ // without this the browser never sends it back on subsequent Blocks API calls.
31
+ credentials: "include",
29
32
  headers,
30
33
  method: options.method ?? (options.body === undefined ? "GET" : "POST")
31
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seliseblocks/client",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "Framework-neutral TypeScript client SDK for SELISE Blocks frontend applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",