@krak-stack/auth 0.2.2 → 0.2.4

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 CHANGED
@@ -49,7 +49,7 @@ Use `AuthMiddleware.layer()` to provide request headers and configuration in an
49
49
 
50
50
  ## React Components
51
51
 
52
- The component bundle uses the peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. The server-only entry points have a smaller integration boundary.
52
+ The component bundle uses the optional peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. Install the component peers used by your application; server-only consumers only need `effect`.
53
53
 
54
54
  When components are configured, register their Tailwind source:
55
55
 
@@ -4,7 +4,6 @@ import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
4
4
  import { Effect, Schema } from "effect";
5
5
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
6
  import { useState } from "react";
7
- import { toast } from "sonner";
8
7
  import { ImageField, SingleSearchableSelectField, SubmitButton, SubmitError, TextField, } from "@krak-stack/registry/effect-form";
9
8
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
10
9
  import { AdminCreateOrganizationPayload, } from "../admin/schema.js";
@@ -19,7 +18,6 @@ const defaultMessages = {
19
18
  organization_create_description: "Create an organization that can be used for authentication membership.",
20
19
  organization_create_error: "Unable to create organization.",
21
20
  organization_create_title: "Create organization",
22
- organization_created_toast: "Organization created.",
23
21
  organization_edit_title: "Edit organization",
24
22
  organization_field_logo_url: "Logo",
25
23
  organization_parent: "Parent organization",
@@ -30,7 +28,6 @@ const defaultMessages = {
30
28
  organization_slug: "Slug",
31
29
  organization_slug_description: "Leave blank to generate one from the name.",
32
30
  organization_update_error: "Unable to update organization.",
33
- organization_updated_toast: "Organization updated.",
34
31
  },
35
32
  fr: {
36
33
  admin_organization_edit_description: "Mettez à jour les détails canoniques de l'organisation {name}.",
@@ -39,7 +36,6 @@ const defaultMessages = {
39
36
  organization_create_description: "Créez une organisation utilisable pour les adhésions d'authentification.",
40
37
  organization_create_error: "Impossible de créer l'organisation.",
41
38
  organization_create_title: "Créer une organisation",
42
- organization_created_toast: "Organisation créée.",
43
39
  organization_edit_title: "Modifier l'organisation",
44
40
  organization_field_logo_url: "Logo",
45
41
  organization_parent: "Organisation parente",
@@ -50,7 +46,6 @@ const defaultMessages = {
50
46
  organization_slug: "Slug",
51
47
  organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
52
48
  organization_update_error: "Impossible de mettre à jour l'organisation.",
53
- organization_updated_toast: "Organisation mise à jour.",
54
49
  },
55
50
  };
56
51
  const labels = (locale) => defaultMessages[locale];
@@ -127,9 +122,6 @@ export function AdminOrganizationForm({ organization, onClose, onSaved, }) {
127
122
  useAtomSubscribe(form.submit, (result) => {
128
123
  if (!AsyncResult.isSuccess(result))
129
124
  return;
130
- toast.success(organization
131
- ? m.organization_updated_toast
132
- : m.organization_created_toast);
133
125
  onSaved(result.value);
134
126
  onClose();
135
127
  });
@@ -4,7 +4,6 @@ import { Cause, Effect, Schema } from "effect";
4
4
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
5
  import { Building2, Pencil, Trash2 } from "lucide-react";
6
6
  import { useState } from "react";
7
- import { toast } from "sonner";
8
7
  import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
9
8
  import { SortParamsFromString, } from "@krak-stack/registry/query";
10
9
  import { ErrorMessage } from "@krak-stack/registry/effect-form";
@@ -28,7 +27,6 @@ const defaultMessages = {
28
27
  organization_delete_description: "Are you sure you want to delete {name}? This action cannot be undone.",
29
28
  organization_delete_error: "Unable to delete organization.",
30
29
  organization_delete_title: "Delete organization",
31
- organization_deleted_toast: "Organization deleted.",
32
30
  organization_fetch_error: "Unable to load organizations.",
33
31
  },
34
32
  fr: {
@@ -44,7 +42,6 @@ const defaultMessages = {
44
42
  organization_delete_description: "Êtes-vous sûr de vouloir supprimer {name} ? Cette action est irréversible.",
45
43
  organization_delete_error: "Impossible de supprimer l'organisation.",
46
44
  organization_delete_title: "Supprimer l'organisation",
47
- organization_deleted_toast: "Organisation supprimée.",
48
45
  organization_fetch_error: "Impossible de charger les organisations.",
49
46
  },
50
47
  };
@@ -166,7 +163,6 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
166
163
  setLocalSearch(nextSearch);
167
164
  }
168
165
  }, status: { loading: isLoading } }), editingOrganization ? (_jsx(AdminOrganizationForm, { organization: editingOrganization, onClose: () => setEditingOrganization(null), onSaved: () => setRefreshKey((current) => current + 1) })) : null, deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
169
- toast.success(m.organization_deleted_toast);
170
166
  setDeletingOrganization(null);
171
167
  setRefreshKey((current) => current + 1);
172
168
  } })) : null] }));
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * as Roles from "./roles.js";
4
4
  export { AuthClientApi, AuthServiceApi } from "./api.js";
5
5
  export { AuthService, type AuthServiceLayerOptions } from "./service.js";
6
6
  export { AuthClientConfig } from "./config.js";
7
- export { proxyAuthRequest } from "./server/proxy.js";
7
+ export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./server/proxy.js";
8
8
  export * as Auth from "./auth/api.group.js";
9
9
  export * as Extra from "./extra/api.group.js";
10
10
  export * as Server from "./server/index.js";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export * as Roles from "./roles.js";
4
4
  export { AuthClientApi, AuthServiceApi } from "./api.js";
5
5
  export { AuthService } from "./service.js";
6
6
  export { AuthClientConfig } from "./config.js";
7
- export { proxyAuthRequest } from "./server/proxy.js";
7
+ export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./server/proxy.js";
8
8
  export * as Auth from "./auth/api.group.js";
9
9
  export * as Extra from "./extra/api.group.js";
10
10
  export * as Server from "./server/index.js";
@@ -2,7 +2,7 @@ export { AuthService } from "../service.js";
2
2
  export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service.js";
3
3
  export { AuthClientConfig } from "../config.js";
4
4
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
5
- export { proxyAuthRequest } from "./proxy.js";
5
+ export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./proxy.js";
6
6
  export type { ProxyAuthRequestOptions } from "./proxy.js";
7
7
  export { ActorRequired } from "./actor.js";
8
8
  export type { ActorConstraint } from "./actor.js";
@@ -1,7 +1,7 @@
1
1
  export { AuthService } from "../service.js";
2
2
  export { AuthClientConfig } from "../config.js";
3
3
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
4
- export { proxyAuthRequest } from "./proxy.js";
4
+ export { proxyAuthHttpEffect, proxyAuthRequest, proxyAuthRequestEffect, } from "./proxy.js";
5
5
  export { ActorRequired } from "./actor.js";
6
6
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
7
7
  export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
@@ -1,4 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import { HttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
1
3
  export interface ProxyAuthRequestOptions {
2
4
  cookieDomain?: string;
3
5
  }
4
6
  export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Promise<Response>;
7
+ export declare const proxyAuthRequestEffect: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Effect.Effect<HttpServerResponse.HttpServerResponse, import("effect/unstable/http/HttpClientError").HttpClientError, HttpClient.HttpClient>;
8
+ export declare const proxyAuthHttpEffect: (baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Effect.Effect<HttpServerResponse.HttpServerResponse, import("effect/unstable/http/HttpClientError").HttpClientError | import("effect/unstable/http/HttpServerError").RequestError, HttpClient.HttpClient | HttpServerRequest.HttpServerRequest>;
@@ -1,5 +1,9 @@
1
+ import { Effect } from "effect";
2
+ import { Cookies, FetchHttpClient, Headers as HttpHeaders, HttpClient, HttpClientRequest, HttpServerRequest, HttpServerResponse, } from "effect/unstable/http";
1
3
  const blockedRequestHeaders = [
2
4
  "accept-encoding",
5
+ "b3",
6
+ "baggage",
3
7
  "connection",
4
8
  "content-length",
5
9
  "forwarded",
@@ -9,11 +13,18 @@ const blockedRequestHeaders = [
9
13
  "proxy-authorization",
10
14
  "te",
11
15
  "trailer",
16
+ "traceparent",
17
+ "tracestate",
12
18
  "transfer-encoding",
13
19
  "upgrade",
14
20
  "cdn-loop",
15
21
  "x-krakstack-forwarded-host",
16
22
  "x-krakstack-forwarded-proto",
23
+ "x-b3-flags",
24
+ "x-b3-parentspanid",
25
+ "x-b3-sampled",
26
+ "x-b3-spanid",
27
+ "x-b3-traceid",
17
28
  ];
18
29
  const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
19
30
  const normalizedCookieDomain = (domain) => domain
@@ -75,7 +86,7 @@ const proxyHeaders = (request) => {
75
86
  }
76
87
  return headers;
77
88
  };
78
- export const proxyAuthRequest = async (request, baseUrl, options) => {
89
+ const proxyRequest = (request, baseUrl) => {
79
90
  const target = new URL(request.url);
80
91
  const authUrl = new URL(baseUrl);
81
92
  const init = {
@@ -89,8 +100,28 @@ export const proxyAuthRequest = async (request, baseUrl, options) => {
89
100
  if (request.method !== "GET" && request.method !== "HEAD") {
90
101
  init.body = request.body;
91
102
  }
92
- const response = await fetch(new Request(target, init), {
103
+ return new Request(target, init);
104
+ };
105
+ export const proxyAuthRequest = async (request, baseUrl, options) => {
106
+ const response = await fetch(proxyRequest(request, baseUrl), {
93
107
  redirect: "manual",
94
108
  });
95
109
  return proxyResponse(request, response, options);
96
110
  };
111
+ export const proxyAuthRequestEffect = (request, baseUrl, options) => Effect.gen(function* () {
112
+ const response = yield* HttpClient.execute(HttpClientRequest.fromWeb(proxyRequest(request, baseUrl))).pipe(Effect.provideService(FetchHttpClient.RequestInit, {
113
+ redirect: "manual",
114
+ }));
115
+ const cookieDomain = sharedCookieDomain(request, options);
116
+ const cookies = Cookies.fromSetCookie(Cookies.toSetCookieHeaders(response.cookies).map((cookie) => cookieForDomain(cookie, cookieDomain)));
117
+ return HttpServerResponse.stream(response.stream, {
118
+ status: response.status,
119
+ headers: HttpHeaders.remove(response.headers, "set-cookie"),
120
+ cookies,
121
+ });
122
+ });
123
+ export const proxyAuthHttpEffect = (baseUrl, options) => Effect.gen(function* () {
124
+ const request = yield* HttpServerRequest.HttpServerRequest;
125
+ const webRequest = yield* HttpServerRequest.toWeb(request);
126
+ return yield* proxyAuthRequestEffect(webRequest, baseUrl, options);
127
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -74,19 +74,41 @@
74
74
  "prepack": "bun run build",
75
75
  "type:check": "tsc -p tsconfig.json --noEmit"
76
76
  },
77
- "dependencies": {
78
- "@krak-stack/registry": "0.1.24",
79
- "react-qr-code": "^2.2.0"
80
- },
81
77
  "peerDependencies": {
82
78
  "@effect/atom-react": "4.0.0-rc.112",
79
+ "@krak-stack/registry": "^0.1.25",
83
80
  "@lucas-barake/effect-form-react": "^0.26.0-beta.5",
84
81
  "@tanstack/react-router": "^1.170.15",
85
- "@tanstack/react-table": "^9.1.2",
86
82
  "effect": "4.0.0-rc.112",
87
83
  "input-otp": "^1.4.2",
88
- "lucide-react": "^1.17.0",
89
- "react": "^19.2.7",
90
- "sonner": "^2.0.7"
84
+ "lucide-react": "^1.18.0",
85
+ "react": "^19.2.0",
86
+ "react-qr-code": "^2.2.0"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "@effect/atom-react": {
90
+ "optional": true
91
+ },
92
+ "@krak-stack/registry": {
93
+ "optional": true
94
+ },
95
+ "@lucas-barake/effect-form-react": {
96
+ "optional": true
97
+ },
98
+ "@tanstack/react-router": {
99
+ "optional": true
100
+ },
101
+ "input-otp": {
102
+ "optional": true
103
+ },
104
+ "lucide-react": {
105
+ "optional": true
106
+ },
107
+ "react": {
108
+ "optional": true
109
+ },
110
+ "react-qr-code": {
111
+ "optional": true
112
+ }
91
113
  }
92
114
  }