@krak-stack/auth 0.2.18 → 0.2.19

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.
@@ -218,13 +218,16 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
218
218
  readonly createdAt: Schema.Date;
219
219
  readonly updatedAt: Schema.Date;
220
220
  }>>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"listOrganizations", "GET", "/admin/organizations", never, Schema.toCodecStringTree<Schema.Struct<{
221
- readonly page: Schema.Int;
222
- readonly pageSize: Schema.Int;
221
+ readonly page: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
222
+ readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
223
223
  readonly globalFilter: Schema.optional<Schema.String>;
224
- readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
225
- readonly id: Schema.NonEmptyString;
226
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
227
- }>>, Schema.String, never, never>, never, never>>;
224
+ readonly sort: Schema.optional<Schema.declare<readonly {
225
+ readonly id: string;
226
+ readonly direction: "asc" | "desc";
227
+ }[], readonly {
228
+ readonly id: string;
229
+ readonly direction: "asc" | "desc";
230
+ }[]>>;
228
231
  readonly projectId: Schema.optional<Schema.String>;
229
232
  }>>, never, never, Schema.toCodecJson<Schema.Struct<{
230
233
  readonly data: Schema.$Array<Schema.Struct<{
@@ -256,13 +259,16 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
256
259
  readonly pageCount: Schema.Int;
257
260
  }>;
258
261
  }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"listUsers", "GET", "/admin/users", never, Schema.toCodecStringTree<Schema.Struct<{
259
- readonly page: Schema.Int;
260
- readonly pageSize: Schema.Int;
262
+ readonly page: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
263
+ readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
261
264
  readonly globalFilter: Schema.optional<Schema.String>;
262
- readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
263
- readonly id: Schema.NonEmptyString;
264
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
265
- }>>, Schema.String, never, never>, never, never>>;
265
+ readonly sort: Schema.optional<Schema.declare<readonly {
266
+ readonly id: string;
267
+ readonly direction: "asc" | "desc";
268
+ }[], readonly {
269
+ readonly id: string;
270
+ readonly direction: "asc" | "desc";
271
+ }[]>>;
266
272
  readonly projectId: Schema.optional<Schema.String>;
267
273
  }>>, never, never, Schema.toCodecJson<Schema.Struct<{
268
274
  readonly data: Schema.$Array<Schema.Struct<{
@@ -1,13 +1,16 @@
1
1
  import { Schema } from "effect";
2
2
  import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload } from "../server/schema.js";
3
3
  export declare const AdminListQuery: Schema.Struct<{
4
- readonly page: Schema.Int;
5
- readonly pageSize: Schema.Int;
4
+ readonly page: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
5
+ readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optionalKey<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
6
6
  readonly globalFilter: Schema.optional<Schema.String>;
7
- readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
8
- readonly id: Schema.NonEmptyString;
9
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
10
- }>>, Schema.String, never, never>, never, never>>;
7
+ readonly sort: Schema.optional<Schema.declare<readonly {
8
+ readonly id: string;
9
+ readonly direction: "asc" | "desc";
10
+ }[], readonly {
11
+ readonly id: string;
12
+ readonly direction: "asc" | "desc";
13
+ }[]>>;
11
14
  readonly projectId: Schema.optional<Schema.String>;
12
15
  }>;
13
16
  export declare const AdminProjectPreview: Schema.Struct<{
@@ -229,4 +232,3 @@ export type AdminUpdateApiKeyPayload = typeof AdminUpdateApiKeyPayload.Type;
229
232
  export type AdminCreateOrganizationPayload = typeof AdminCreateOrganizationPayload.Type;
230
233
  export type AdminUpdateOrganizationPayload = typeof AdminUpdateOrganizationPayload.Type;
231
234
  export { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, };
232
- export { SortParamsFromString } from "../query.js";
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { ApiKeyPermissionGrant } from "../access.js";
3
- import { PaginatedResponse, Query } from "../query.js";
3
+ import { PaginatedResponse, Query } from "@krak-stack/registry/query";
4
4
  import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, } from "../server/schema.js";
5
5
  export const AdminListQuery = Schema.Struct({
6
6
  ...Query.fields,
@@ -312,4 +312,3 @@ export const PaginatedAdminOrganizations = PaginatedResponse(AdminOrganization).
312
312
  description: "Paginated administrative organization list response.",
313
313
  });
314
314
  export { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, };
315
- export { SortParamsFromString } from "../query.js";
package/dist/api.d.ts CHANGED
@@ -2158,13 +2158,16 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
2158
2158
  readonly createdAt: import("effect/Schema").Date;
2159
2159
  readonly updatedAt: import("effect/Schema").Date;
2160
2160
  }>>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listOrganizations", "GET", "/api/auth/admin/organizations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2161
- readonly page: import("effect/Schema").Int;
2162
- readonly pageSize: import("effect/Schema").Int;
2161
+ readonly page: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
2162
+ readonly pageSize: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
2163
2163
  readonly globalFilter: import("effect/Schema").optional<import("effect/Schema").String>;
2164
- readonly sort: import("effect/Schema").optional<import("effect/Schema").decodeTo<import("effect/Schema").String, import("effect/Schema").decodeTo<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2165
- readonly id: import("effect/Schema").NonEmptyString;
2166
- readonly direction: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"asc">, import("effect/Schema").Literal<"desc">]>;
2167
- }>>, import("effect/Schema").String, never, never>, never, never>>;
2164
+ readonly sort: import("effect/Schema").optional<import("effect/Schema").declare<readonly {
2165
+ readonly id: string;
2166
+ readonly direction: "asc" | "desc";
2167
+ }[], readonly {
2168
+ readonly id: string;
2169
+ readonly direction: "asc" | "desc";
2170
+ }[]>>;
2168
2171
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
2169
2172
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2170
2173
  readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
@@ -2196,13 +2199,16 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
2196
2199
  readonly pageCount: import("effect/Schema").Int;
2197
2200
  }>;
2198
2201
  }>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsers", "GET", "/api/auth/admin/users", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
2199
- readonly page: import("effect/Schema").Int;
2200
- readonly pageSize: import("effect/Schema").Int;
2202
+ readonly page: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
2203
+ readonly pageSize: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
2201
2204
  readonly globalFilter: import("effect/Schema").optional<import("effect/Schema").String>;
2202
- readonly sort: import("effect/Schema").optional<import("effect/Schema").decodeTo<import("effect/Schema").String, import("effect/Schema").decodeTo<import("effect/Schema").$Array<import("effect/Schema").Struct<{
2203
- readonly id: import("effect/Schema").NonEmptyString;
2204
- readonly direction: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"asc">, import("effect/Schema").Literal<"desc">]>;
2205
- }>>, import("effect/Schema").String, never, never>, never, never>>;
2205
+ readonly sort: import("effect/Schema").optional<import("effect/Schema").declare<readonly {
2206
+ readonly id: string;
2207
+ readonly direction: "asc" | "desc";
2208
+ }[], readonly {
2209
+ readonly id: string;
2210
+ readonly direction: "asc" | "desc";
2211
+ }[]>>;
2206
2212
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
2207
2213
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2208
2214
  readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
@@ -6,11 +6,12 @@ import { Atom, AsyncResult } from "effect/reactivity";
6
6
  import { Building2, Pencil, Trash2, UserCog } from "lucide-react";
7
7
  import { useEffect, useState } from "react";
8
8
  import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
9
- import { Query, SortParamsFromString, } from "@krak-stack/registry/query";
9
+ import { Query } from "@krak-stack/registry/query";
10
10
  import { ErrorMessage } from "@krak-stack/registry/effect-form";
11
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
12
12
  import { Badge } from "@/components/ui/badge";
13
13
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
14
+ import { AdminListQuery } from "../admin/schema.js";
14
15
  import { normalizeOrganizationRoles } from "../roles.js";
15
16
  import { AdminOrganizationForm } from "./admin-organization-form.js";
16
17
  import { authClientApi, authHttpClient } from "./auth-client-api.js";
@@ -97,31 +98,10 @@ const organizationDisplay = (organization, locale, baseUrl) => {
97
98
  };
98
99
  };
99
100
  const AdminOrganizationsFamilyKey = Schema.fromJsonString(Schema.Struct({
100
- query: Schema.Struct({
101
- page: Schema.Number,
102
- pageSize: Schema.Number,
103
- globalFilter: Schema.optional(Schema.String),
104
- sort: Schema.optional(Schema.String),
105
- projectId: Schema.optional(Schema.String),
106
- }),
101
+ query: AdminListQuery,
107
102
  reloadKey: Schema.Number,
108
103
  })).annotate({ identifier: "AdminOrganizationsFamilyKey" });
109
- const organizationsQuery = (search, projectId) => {
110
- let query = {
111
- page: search.page ?? 0,
112
- pageSize: search.pageSize ?? 10,
113
- };
114
- if (search.globalFilter)
115
- query = { ...query, globalFilter: search.globalFilter };
116
- if (search.sort)
117
- query = {
118
- ...query,
119
- sort: Schema.encodeSync(SortParamsFromString)(search.sort),
120
- };
121
- if (projectId)
122
- query = { ...query, projectId };
123
- return query;
124
- };
104
+ const organizationsQuery = (search, projectId) => projectId ? { ...search, projectId } : search;
125
105
  const adminOrganizationsFamilyKey = (search, projectId, reloadKey) => JSON.stringify({
126
106
  query: organizationsQuery(search, projectId),
127
107
  reloadKey,
@@ -6,11 +6,12 @@ import { Effect, Schema } from "effect";
6
6
  import { Ban, Loader2, ShieldOff, UserCog, UserIcon } from "lucide-react";
7
7
  import { useEffect, useState } from "react";
8
8
  import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
9
- import { Query, SortParamsFromString, } from "@krak-stack/registry/query";
9
+ import { Query } from "@krak-stack/registry/query";
10
10
  import { ErrorMessage } from "@krak-stack/registry/effect-form";
11
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
12
12
  import { Badge } from "@/components/ui/badge";
13
13
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
14
+ import { AdminListQuery } from "../admin/schema.js";
14
15
  import { notifyAuthChange } from "./auth-atoms.js";
15
16
  import { authClientApi, authHttpClient } from "./auth-client-api.js";
16
17
  import { useKrakstackAuth } from "./auth-provider.js";
@@ -82,31 +83,10 @@ const initials = (name) => name
82
83
  .toUpperCase();
83
84
  const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
84
85
  const AdminUsersFamilyKey = Schema.fromJsonString(Schema.Struct({
85
- query: Schema.Struct({
86
- page: Schema.Number,
87
- pageSize: Schema.Number,
88
- globalFilter: Schema.optional(Schema.String),
89
- sort: Schema.optional(Schema.String),
90
- projectId: Schema.optional(Schema.String),
91
- }),
86
+ query: AdminListQuery,
92
87
  reloadKey: Schema.Number,
93
88
  })).annotate({ identifier: "AdminUsersFamilyKey" });
94
- const adminUsersQuery = (search, projectId) => {
95
- let query = {
96
- page: search.page ?? 0,
97
- pageSize: search.pageSize ?? 10,
98
- };
99
- if (search.globalFilter)
100
- query = { ...query, globalFilter: search.globalFilter };
101
- if (search.sort)
102
- query = {
103
- ...query,
104
- sort: Schema.encodeSync(SortParamsFromString)(search.sort),
105
- };
106
- if (projectId)
107
- query = { ...query, projectId };
108
- return query;
109
- };
89
+ const adminUsersQuery = (search, projectId) => projectId ? { ...search, projectId } : search;
110
90
  const adminUsersFamilyKey = (search, projectId, reloadKey) => JSON.stringify({ query: adminUsersQuery(search, projectId), reloadKey });
111
91
  const usersAtom = Atom.family((baseUrl) => Atom.family((key) => {
112
92
  const { query, reloadKey } = Schema.decodeUnknownSync(AdminUsersFamilyKey)(key);
@@ -232,13 +232,16 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
232
232
  readonly updatedAt: import("effect/Schema").Date;
233
233
  }>>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
234
234
  readonly listOrganizations: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listOrganizations", "GET", "/api/auth/admin/organizations", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
235
- readonly page: import("effect/Schema").Int;
236
- readonly pageSize: import("effect/Schema").Int;
235
+ readonly page: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
236
+ readonly pageSize: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
237
237
  readonly globalFilter: import("effect/Schema").optional<import("effect/Schema").String>;
238
- readonly sort: import("effect/Schema").optional<import("effect/Schema").decodeTo<import("effect/Schema").String, import("effect/Schema").decodeTo<import("effect/Schema").$Array<import("effect/Schema").Struct<{
239
- readonly id: import("effect/Schema").NonEmptyString;
240
- readonly direction: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"asc">, import("effect/Schema").Literal<"desc">]>;
241
- }>>, import("effect/Schema").String, never, never>, never, never>>;
238
+ readonly sort: import("effect/Schema").optional<import("effect/Schema").declare<readonly {
239
+ readonly id: string;
240
+ readonly direction: "asc" | "desc";
241
+ }[], readonly {
242
+ readonly id: string;
243
+ readonly direction: "asc" | "desc";
244
+ }[]>>;
242
245
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
243
246
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
244
247
  readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
@@ -271,13 +274,16 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
271
274
  }>;
272
275
  }>>, import("effect/Schema").toCodecJson<typeof import("effect/http-api/HttpApiError").Unauthorized | typeof import("effect/http-api/HttpApiError").Forbidden | typeof import("effect/http-api/HttpApiError").InternalServerError>, never, never>, never, never>;
273
276
  readonly listUsers: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"listUsers", "GET", "/api/auth/admin/users", never, import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
274
- readonly page: import("effect/Schema").Int;
275
- readonly pageSize: import("effect/Schema").Int;
277
+ readonly page: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
278
+ readonly pageSize: import("effect/Schema").decodeTo<import("effect/Schema").Int, import("effect/Schema").optionalKey<import("effect/Schema").Union<readonly [import("effect/Schema").Number, import("effect/Schema").NumberFromString]>>, never, never>;
276
279
  readonly globalFilter: import("effect/Schema").optional<import("effect/Schema").String>;
277
- readonly sort: import("effect/Schema").optional<import("effect/Schema").decodeTo<import("effect/Schema").String, import("effect/Schema").decodeTo<import("effect/Schema").$Array<import("effect/Schema").Struct<{
278
- readonly id: import("effect/Schema").NonEmptyString;
279
- readonly direction: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"asc">, import("effect/Schema").Literal<"desc">]>;
280
- }>>, import("effect/Schema").String, never, never>, never, never>>;
280
+ readonly sort: import("effect/Schema").optional<import("effect/Schema").declare<readonly {
281
+ readonly id: string;
282
+ readonly direction: "asc" | "desc";
283
+ }[], readonly {
284
+ readonly id: string;
285
+ readonly direction: "asc" | "desc";
286
+ }[]>>;
281
287
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
282
288
  }>>, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
283
289
  readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./schema.js";
2
- export * as Query from "./query.js";
3
2
  export * as Roles from "./roles.js";
4
3
  export { AuthClientApi, AuthServiceApi } from "./api.js";
5
4
  export { AuthService, type AuthServiceLayerOptions } from "./service.js";
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./schema.js";
2
- export * as Query from "./query.js";
3
2
  export * as Roles from "./roles.js";
4
3
  export { AuthClientApi, AuthServiceApi } from "./api.js";
5
4
  export { AuthService } from "./service.js";
@@ -4,6 +4,8 @@ import { AuthProxyError } from "./proxy-origin.js";
4
4
  export interface ProxyAuthRequestOptions {
5
5
  cookieDomain?: string;
6
6
  apiKey?: Redacted.Redacted<string>;
7
+ /** For proxyAuthHttpEffect only; enable behind an ingress that overwrites x-forwarded-proto. */
8
+ trustForwardedProto?: boolean;
7
9
  }
8
10
  export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Promise<Response>;
9
11
  export declare const proxyAuthRequestEffect: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Effect.Effect<HttpServerResponse.HttpServerResponse, AuthProxyError, HttpClient.HttpClient>;
@@ -1,6 +1,7 @@
1
- import { Effect } from "effect";
1
+ import { Effect, Schema } from "effect";
2
2
  import { Cookies, FetchHttpClient, Headers as HttpHeaders, HttpClient, HttpClientRequest, HttpServerRequest, HttpServerResponse, } from "effect/http";
3
3
  import { AuthProxyError, authProxyKeyHeader, proxyOriginHeaders, } from "./proxy-origin.js";
4
+ import { AuthProxyOrigin } from "./schema.js";
4
5
  const blockedRequestHeaders = [
5
6
  "accept-encoding",
6
7
  "b3",
@@ -128,5 +129,13 @@ export const proxyAuthRequestEffect = (request, baseUrl, options) => Effect.gen(
128
129
  export const proxyAuthHttpEffect = (baseUrl, options) => Effect.gen(function* () {
129
130
  const request = yield* HttpServerRequest.HttpServerRequest;
130
131
  const webRequest = yield* HttpServerRequest.toWeb(request);
131
- return yield* proxyAuthRequestEffect(webRequest, baseUrl, options);
132
+ if (!options?.trustForwardedProto) {
133
+ return yield* proxyAuthRequestEffect(webRequest, baseUrl, options);
134
+ }
135
+ // toWeb can return the original Web Request with the internal HTTP URL.
136
+ // Trust only the configured ingress protocol, never forwarded host headers.
137
+ const url = new URL(webRequest.url);
138
+ const protocol = yield* Schema.decodeUnknownEffect(AuthProxyOrigin.fields.protocol)(request.headers["x-forwarded-proto"] ?? url.protocol.slice(0, -1)).pipe(Effect.mapError(() => new AuthProxyError({ reason: "invalid" })));
139
+ url.protocol = `${protocol}:`;
140
+ return yield* proxyAuthRequestEffect(new Request(url, webRequest), baseUrl, options);
132
141
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -27,10 +27,6 @@
27
27
  "types": "./dist/schema.d.ts",
28
28
  "default": "./dist/schema.js"
29
29
  },
30
- "./query": {
31
- "types": "./dist/query.d.ts",
32
- "default": "./dist/query.js"
33
- },
34
30
  "./roles": {
35
31
  "types": "./dist/roles.d.ts",
36
32
  "default": "./dist/roles.js"
@@ -72,8 +68,7 @@
72
68
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
73
69
  "build:watch": "rm -rf dist && tsc -p tsconfig.build.json --watch --preserveWatchOutput",
74
70
  "dev": "bun run build:watch",
75
- "prepack": "bun run build",
76
- "type:check": "tsc -p tsconfig.json --noEmit"
71
+ "prepack": "bun run build"
77
72
  },
78
73
  "dependencies": {
79
74
  "@effect/atom-react": "^4.0.0",
@@ -81,10 +76,10 @@
81
76
  "react-qr-code": "^2.2.0"
82
77
  },
83
78
  "devDependencies": {
84
- "@krak-stack/registry": "0.1.36"
79
+ "@krak-stack/registry": "0.1.39"
85
80
  },
86
81
  "peerDependencies": {
87
- "@krak-stack/registry": "^0.1.36",
82
+ "@krak-stack/registry": "^0.1.39",
88
83
  "@tanstack/react-router": "^1.170.15",
89
84
  "effect": "^4.0.0",
90
85
  "input-otp": "^1.5.0",
package/dist/query.d.ts DELETED
@@ -1,49 +0,0 @@
1
- import { Schema } from "effect";
2
- export type SortDirection = "asc" | "desc";
3
- export interface SortState {
4
- readonly id: string;
5
- readonly desc: boolean;
6
- }
7
- export interface SortParam {
8
- readonly id: string;
9
- readonly direction: SortDirection;
10
- }
11
- export declare const SortDirection: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
12
- export declare const SortParam: Schema.Struct<{
13
- readonly id: Schema.NonEmptyString;
14
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
15
- }>;
16
- export declare const SortParamFromString: Schema.decodeTo<Schema.Struct<{
17
- readonly id: Schema.NonEmptyString;
18
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
19
- }>, Schema.String, never, never>;
20
- export declare const SortParamsFromString: Schema.decodeTo<Schema.$Array<Schema.Struct<{
21
- readonly id: Schema.NonEmptyString;
22
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
23
- }>>, Schema.String, never, never>;
24
- export declare const Query: Schema.Struct<{
25
- readonly page: Schema.Int;
26
- readonly pageSize: Schema.Int;
27
- readonly globalFilter: Schema.optional<Schema.String>;
28
- readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
29
- readonly id: Schema.NonEmptyString;
30
- readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
31
- }>>, Schema.String, never, never>, never, never>>;
32
- }>;
33
- export type QueryType = typeof Query.Type;
34
- export declare const PaginationMeta: Schema.Struct<{
35
- readonly page: Schema.Int;
36
- readonly pageSize: Schema.Int;
37
- readonly total: Schema.Int;
38
- readonly pageCount: Schema.Int;
39
- }>;
40
- export type PaginationMetaType = typeof PaginationMeta.Type;
41
- export declare const PaginatedResponse: <S extends Schema.Top>(items: S) => Schema.Struct<{
42
- readonly data: Schema.$Array<S>;
43
- readonly meta: Schema.Struct<{
44
- readonly page: Schema.Int;
45
- readonly pageSize: Schema.Int;
46
- readonly total: Schema.Int;
47
- readonly pageCount: Schema.Int;
48
- }>;
49
- }>;
package/dist/query.js DELETED
@@ -1,114 +0,0 @@
1
- import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
2
- const parseSortParam = (sort) => {
3
- const id = sort.startsWith("-") ? sort.slice(1) : sort;
4
- if (!id || id.includes(",") || id.includes(":")) {
5
- return null;
6
- }
7
- return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
8
- };
9
- export const SortDirection = Schema.Union([
10
- Schema.Literal("asc"),
11
- Schema.Literal("desc"),
12
- ]).annotate({
13
- identifier: "SortDirection",
14
- title: "Sort Direction",
15
- description: "Sort direction for list query results.",
16
- examples: ["asc", "desc"],
17
- });
18
- export const SortParam = Schema.Struct({
19
- id: Schema.NonEmptyString,
20
- direction: SortDirection,
21
- }).annotate({
22
- identifier: "SortParam",
23
- title: "Sort Parameter",
24
- description: "Decoded sort parameter with a field id and direction.",
25
- examples: [{ id: "name", direction: "asc" }],
26
- });
27
- export const SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformEffect({
28
- decode: (sort) => {
29
- const sortParam = parseSortParam(sort);
30
- if (!sortParam) {
31
- return Effect.fail(new SchemaIssue.InvalidValue({
32
- message: 'Expected sort in the format "field" or "-field"',
33
- }, sort));
34
- }
35
- return Effect.succeed(sortParam);
36
- },
37
- encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id),
38
- })), Schema.annotate({
39
- identifier: "SortParamFromString",
40
- title: "Sort Parameter From String",
41
- description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
42
- examples: [{ id: "name", direction: "asc" }],
43
- }));
44
- export const SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformEffect({
45
- decode: (sort) => {
46
- const parts = sort.split(",");
47
- const sortParams = [];
48
- for (const part of parts) {
49
- const sortParam = parseSortParam(part);
50
- if (!sortParam) {
51
- return Effect.fail(new SchemaIssue.InvalidValue({
52
- message: 'Expected sort in the format "field,-otherField"',
53
- }, sort));
54
- }
55
- sortParams.push(sortParam);
56
- }
57
- return Effect.succeed(sortParams);
58
- },
59
- encode: (sort) => Effect.succeed(sort
60
- .map((part) => Schema.encodeSync(SortParamFromString)(part))
61
- .join(",")),
62
- })), Schema.annotate({
63
- identifier: "SortParamsFromString",
64
- title: "Sort Parameters From String",
65
- description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
66
- examples: [
67
- [
68
- { id: "name", direction: "desc" },
69
- { id: "createdAt", direction: "asc" },
70
- ],
71
- ],
72
- }));
73
- const SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
74
- decode: (sort) => Schema.encodeSync(SortParamsFromString)(sort),
75
- encode: (sort) => Schema.decodeUnknownSync(SortParamsFromString)(sort),
76
- })), Schema.annotate({
77
- identifier: "SortParamSearch",
78
- title: "Sort Search Parameter",
79
- description: 'Search parameter sort value normalized to the compact "-field,otherField" URL format.',
80
- examples: ["-name,createdAt"],
81
- }));
82
- export const Query = Schema.Struct({
83
- page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
84
- pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
85
- globalFilter: Schema.optional(Schema.String),
86
- sort: Schema.optional(SortParamSearch),
87
- }).annotate({
88
- identifier: "Query",
89
- title: "Query",
90
- description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
91
- examples: [
92
- {
93
- page: 0,
94
- pageSize: 10,
95
- globalFilter: "housing",
96
- sort: "-name,createdAt",
97
- },
98
- ],
99
- });
100
- export const PaginationMeta = Schema.Struct({
101
- page: Schema.Int,
102
- pageSize: Schema.Int,
103
- total: Schema.Int,
104
- pageCount: Schema.Int,
105
- }).annotate({
106
- identifier: "PaginationMeta",
107
- title: "Pagination Metadata",
108
- description: "Pagination metadata returned with a paginated list response.",
109
- examples: [{ page: 0, pageSize: 10, total: 125, pageCount: 13 }],
110
- });
111
- export const PaginatedResponse = (items) => Schema.Struct({
112
- data: Schema.Array(items),
113
- meta: PaginationMeta,
114
- });