@gaganref/confect-server 10.3.1-fork.68 → 10.3.1-fork.69
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/dist/Auth.d.ts +19 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +11 -1
- package/dist/Auth.js.map +1 -1
- package/package.json +2 -2
- package/src/Auth.ts +26 -0
package/dist/Auth.d.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
import type { Auth as ConvexAuth, MutationAuth as ConvexMutationAuth, SignJwtOptions } from "convex/server";
|
|
1
|
+
import type { Auth as ConvexAuth, MutationAuth as ConvexMutationAuth, SignJwtOptions, UserIdentity } from "convex/server";
|
|
2
2
|
import * as Context from "effect/Context";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
5
|
import * as Schema from "effect/Schema";
|
|
6
6
|
import type * as DatabaseSchema from "./DatabaseSchema.js";
|
|
7
7
|
declare const Auth_base: Context.ServiceClass<Auth, "@confect/server/Auth", {
|
|
8
|
-
getUserIdentity: Effect.Effect<
|
|
8
|
+
getUserIdentity: Effect.Effect<UserIdentity, NoUserIdentityFoundError, never>;
|
|
9
9
|
}>;
|
|
10
10
|
export declare class Auth extends Auth_base {
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The outcome of Convex's identity verification for the current request.
|
|
14
|
+
*/
|
|
15
|
+
export type Identity = {
|
|
16
|
+
readonly _tag: "Absent";
|
|
17
|
+
} | {
|
|
18
|
+
readonly _tag: "Valid";
|
|
19
|
+
readonly identity: UserIdentity;
|
|
20
|
+
} | {
|
|
21
|
+
readonly _tag: "Invalid";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Read HTTP identity without failing for missing or rejected credentials.
|
|
25
|
+
* Convex verifies the credential. Rejected reads expose no token or error
|
|
26
|
+
* detail.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getUserIdentity: Effect.Effect<Identity, never, Auth>;
|
|
12
29
|
export declare const layer: (auth: ConvexAuth) => Layer.Layer<Auth, never, never>;
|
|
13
30
|
declare const MutationAuth_base: Context.ServiceClass<MutationAuth, "@confect/server/Auth/MutationAuth", {
|
|
14
31
|
readonly signJwt: (options: SignJwtOptions) => Effect.Effect<string>;
|
package/dist/Auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../src/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,IAAI,UAAU,EAClB,YAAY,IAAI,kBAAkB,EAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../src/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,IAAI,UAAU,EAClB,YAAY,IAAI,kBAAkB,EAClC,cAAc,EACd,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;;;;AAgB3D,qBAAa,IAAK,SAAQ,SAEzB;CAAG;AAEJ;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAUhE,CAAC;AAEF,eAAO,MAAM,KAAK,SAAU,UAAU,oCAAoC,CAAC;;sBAQrD,CAAC,OAAO,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;;AANxE;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAKM;CAAG;AAE3C;;GAEG;AACH,eAAO,MAAM,aAAa,SAAU,kBAAkB,4CAGlD,CAAC;AAEL,MAAM,MAAM,SAAS,CAAC,MAAM,SAAS,cAAc,CAAC,MAAM,IACxD,MAAM,CAAC,MAAM,CAAC,SAAS,WAAW,GAAG,KAAK,GAAG,IAAI,CAAC;AAEpD,eAAO,MAAM,cAAc,GAAI,MAAM,SAAS,cAAc,CAAC,MAAM,UACzD,MAAM,QACR,UAAU,KACf,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAKK,CAAC;;AAEtC,qBAAa,wBAAyB,SAAQ,6BAG7C;IACC,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF"}
|
package/dist/Auth.js
CHANGED
|
@@ -11,6 +11,7 @@ var Auth_exports = /* @__PURE__ */ __exportAll({
|
|
|
11
11
|
Auth: () => Auth,
|
|
12
12
|
MutationAuth: () => MutationAuth,
|
|
13
13
|
NoUserIdentityFoundError: () => NoUserIdentityFoundError,
|
|
14
|
+
getUserIdentity: () => getUserIdentity,
|
|
14
15
|
layer: () => layer,
|
|
15
16
|
layerForTarget: () => layerForTarget,
|
|
16
17
|
mutationLayer: () => mutationLayer
|
|
@@ -20,6 +21,15 @@ const make = (auth) => ({ getUserIdentity: Effect.promise(() => auth.getUserIden
|
|
|
20
21
|
onSome: Effect.succeed
|
|
21
22
|
})))) });
|
|
22
23
|
var Auth = class extends Context.Service()("@confect/server/Auth") {};
|
|
24
|
+
/**
|
|
25
|
+
* Read HTTP identity without failing for missing or rejected credentials.
|
|
26
|
+
* Convex verifies the credential. Rejected reads expose no token or error
|
|
27
|
+
* detail.
|
|
28
|
+
*/
|
|
29
|
+
const getUserIdentity = Auth.pipe(Effect.flatMap((auth) => auth.getUserIdentity.pipe(Effect.map((identity) => ({
|
|
30
|
+
_tag: "Valid",
|
|
31
|
+
identity
|
|
32
|
+
})), Effect.catchTag("NoUserIdentityFoundError", () => Effect.succeed({ _tag: "Absent" })), Effect.catchDefect(() => Effect.succeed({ _tag: "Invalid" })))));
|
|
23
33
|
const layer = (auth) => Layer.succeed(Auth, make(auth));
|
|
24
34
|
/**
|
|
25
35
|
* Mutation-only deployment signing, available in applications and components.
|
|
@@ -36,6 +46,6 @@ var NoUserIdentityFoundError = class extends Schema.TaggedError()("NoUserIdentit
|
|
|
36
46
|
}
|
|
37
47
|
};
|
|
38
48
|
//#endregion
|
|
39
|
-
export { Auth, Auth_exports, MutationAuth, NoUserIdentityFoundError, layer, layerForTarget, mutationLayer };
|
|
49
|
+
export { Auth, Auth_exports, MutationAuth, NoUserIdentityFoundError, getUserIdentity, layer, layerForTarget, mutationLayer };
|
|
40
50
|
|
|
41
51
|
//# sourceMappingURL=Auth.js.map
|
package/dist/Auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.js","names":[],"sources":["../src/Auth.ts"],"sourcesContent":["import type {\n Auth as ConvexAuth,\n MutationAuth as ConvexMutationAuth,\n SignJwtOptions,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport { flow } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\n\nconst make = (auth: ConvexAuth) => ({\n getUserIdentity: Effect.promise(() => auth.getUserIdentity()).pipe(\n Effect.andThen(\n flow(\n Option.fromNullishOr,\n Option.match({\n onNone: () => Effect.fail(new NoUserIdentityFoundError()),\n onSome: Effect.succeed,\n }),\n ),\n ),\n ),\n});\n\nexport class Auth extends Context.Service<Auth, ReturnType<typeof make>>()(\n \"@confect/server/Auth\",\n) {}\n\nexport const layer = (auth: ConvexAuth) => Layer.succeed(Auth, make(auth));\n\n/**\n * Mutation-only deployment signing, available in applications and components.\n */\nexport class MutationAuth extends Context.Service<\n MutationAuth,\n {\n readonly signJwt: (options: SignJwtOptions) => Effect.Effect<string>;\n }\n>()(\"@confect/server/Auth/MutationAuth\") {}\n\n/**\n * SDK rejections remain defects, as with the other native auth operations.\n */\nexport const mutationLayer = (auth: ConvexMutationAuth) =>\n Layer.succeed(MutationAuth, {\n signJwt: (options) => Effect.promise(() => auth.signJwt(options)),\n });\n\nexport type ForTarget<Target extends DatabaseSchema.Target> =\n Target[\"kind\"] extends \"component\" ? never : Auth;\n\nexport const layerForTarget = <Target extends DatabaseSchema.Target>(\n target: Target,\n auth: ConvexAuth,\n): Layer.Layer<ForTarget<Target>> =>\n Match.value(target.kind).pipe(\n Match.when(\"app\", () => layer(auth)),\n Match.when(\"component\", () => Layer.empty),\n Match.exhaustive,\n ) as Layer.Layer<ForTarget<Target>>;\n\nexport class NoUserIdentityFoundError extends Schema.TaggedError<NoUserIdentityFoundError>()(\n \"NoUserIdentityFoundError\",\n {},\n) {\n override get message(): string {\n return \"No user identity found\";\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Auth.js","names":[],"sources":["../src/Auth.ts"],"sourcesContent":["import type {\n Auth as ConvexAuth,\n MutationAuth as ConvexMutationAuth,\n SignJwtOptions,\n UserIdentity,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport { flow } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\n\nconst make = (auth: ConvexAuth) => ({\n getUserIdentity: Effect.promise(() => auth.getUserIdentity()).pipe(\n Effect.andThen(\n flow(\n Option.fromNullishOr,\n Option.match({\n onNone: () => Effect.fail(new NoUserIdentityFoundError()),\n onSome: Effect.succeed,\n }),\n ),\n ),\n ),\n});\n\nexport class Auth extends Context.Service<Auth, ReturnType<typeof make>>()(\n \"@confect/server/Auth\",\n) {}\n\n/**\n * The outcome of Convex's identity verification for the current request.\n */\nexport type Identity =\n | { readonly _tag: \"Absent\" }\n | { readonly _tag: \"Valid\"; readonly identity: UserIdentity }\n | { readonly _tag: \"Invalid\" };\n\n/**\n * Read HTTP identity without failing for missing or rejected credentials.\n * Convex verifies the credential. Rejected reads expose no token or error\n * detail.\n */\nexport const getUserIdentity: Effect.Effect<Identity, never, Auth> = Auth.pipe(\n Effect.flatMap((auth) =>\n auth.getUserIdentity.pipe(\n Effect.map((identity): Identity => ({ _tag: \"Valid\", identity })),\n Effect.catchTag(\"NoUserIdentityFoundError\", () =>\n Effect.succeed<Identity>({ _tag: \"Absent\" }),\n ),\n Effect.catchDefect(() => Effect.succeed<Identity>({ _tag: \"Invalid\" })),\n ),\n ),\n);\n\nexport const layer = (auth: ConvexAuth) => Layer.succeed(Auth, make(auth));\n\n/**\n * Mutation-only deployment signing, available in applications and components.\n */\nexport class MutationAuth extends Context.Service<\n MutationAuth,\n {\n readonly signJwt: (options: SignJwtOptions) => Effect.Effect<string>;\n }\n>()(\"@confect/server/Auth/MutationAuth\") {}\n\n/**\n * SDK rejections remain defects, as with the other native auth operations.\n */\nexport const mutationLayer = (auth: ConvexMutationAuth) =>\n Layer.succeed(MutationAuth, {\n signJwt: (options) => Effect.promise(() => auth.signJwt(options)),\n });\n\nexport type ForTarget<Target extends DatabaseSchema.Target> =\n Target[\"kind\"] extends \"component\" ? never : Auth;\n\nexport const layerForTarget = <Target extends DatabaseSchema.Target>(\n target: Target,\n auth: ConvexAuth,\n): Layer.Layer<ForTarget<Target>> =>\n Match.value(target.kind).pipe(\n Match.when(\"app\", () => layer(auth)),\n Match.when(\"component\", () => Layer.empty),\n Match.exhaustive,\n ) as Layer.Layer<ForTarget<Target>>;\n\nexport class NoUserIdentityFoundError extends Schema.TaggedError<NoUserIdentityFoundError>()(\n \"NoUserIdentityFoundError\",\n {},\n) {\n override get message(): string {\n return \"No user identity found\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAM,QAAQ,UAAsB,EAClC,iBAAiB,OAAO,cAAc,KAAK,gBAAgB,CAAC,CAAC,CAAC,KAC5D,OAAO,QACL,KACE,OAAO,eACP,OAAO,MAAM;CACX,cAAc,OAAO,KAAK,IAAI,yBAAyB,CAAC;CACxD,QAAQ,OAAO;AACjB,CAAC,CACH,CACF,CACF,EACF;AAEA,IAAa,OAAb,cAA0B,QAAQ,QAAuC,CAAC,CACxE,sBACF,CAAC,CAAC,CAAC;;;;;;AAeH,MAAa,kBAAwD,KAAK,KACxE,OAAO,SAAS,SACd,KAAK,gBAAgB,KACnB,OAAO,KAAK,cAAwB;CAAE,MAAM;CAAS;AAAS,EAAE,GAChE,OAAO,SAAS,kCACd,OAAO,QAAkB,EAAE,MAAM,SAAS,CAAC,CAC7C,GACA,OAAO,kBAAkB,OAAO,QAAkB,EAAE,MAAM,UAAU,CAAC,CAAC,CACxE,CACF,CACF;AAEA,MAAa,SAAS,SAAqB,MAAM,QAAQ,MAAM,KAAK,IAAI,CAAC;;;;AAKzE,IAAa,eAAb,cAAkC,QAAQ,QAKxC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC;;;;AAK1C,MAAa,iBAAiB,SAC5B,MAAM,QAAQ,cAAc,EAC1B,UAAU,YAAY,OAAO,cAAc,KAAK,QAAQ,OAAO,CAAC,EAClE,CAAC;AAKH,MAAa,kBACX,QACA,SAEA,MAAM,MAAM,OAAO,IAAI,CAAC,CAAC,KACvB,MAAM,KAAK,aAAa,MAAM,IAAI,CAAC,GACnC,MAAM,KAAK,mBAAmB,MAAM,KAAK,GACzC,MAAM,UACR;AAEF,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,4BACA,CAAC,CACH,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO;CACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaganref/confect-server",
|
|
3
|
-
"version": "10.3.1-fork.
|
|
3
|
+
"version": "10.3.1-fork.69",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@effect/ai-openai-compat": "4.0.4",
|
|
6
6
|
"@effect/ai-openrouter": "4.0.4"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.
|
|
9
|
+
"@confect/core": "npm:@gaganref/confect-core@10.3.1-fork.69",
|
|
10
10
|
"@effect/platform-node": ">=4.0.0 <4.1.0",
|
|
11
11
|
"convex": "^1.49.0",
|
|
12
12
|
"effect": ">=4.0.4 <4.1.0"
|
package/src/Auth.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
Auth as ConvexAuth,
|
|
3
3
|
MutationAuth as ConvexMutationAuth,
|
|
4
4
|
SignJwtOptions,
|
|
5
|
+
UserIdentity,
|
|
5
6
|
} from "convex/server";
|
|
6
7
|
import * as Context from "effect/Context";
|
|
7
8
|
import { flow } from "effect/Function";
|
|
@@ -30,6 +31,31 @@ export class Auth extends Context.Service<Auth, ReturnType<typeof make>>()(
|
|
|
30
31
|
"@confect/server/Auth",
|
|
31
32
|
) {}
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The outcome of Convex's identity verification for the current request.
|
|
36
|
+
*/
|
|
37
|
+
export type Identity =
|
|
38
|
+
| { readonly _tag: "Absent" }
|
|
39
|
+
| { readonly _tag: "Valid"; readonly identity: UserIdentity }
|
|
40
|
+
| { readonly _tag: "Invalid" };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Read HTTP identity without failing for missing or rejected credentials.
|
|
44
|
+
* Convex verifies the credential. Rejected reads expose no token or error
|
|
45
|
+
* detail.
|
|
46
|
+
*/
|
|
47
|
+
export const getUserIdentity: Effect.Effect<Identity, never, Auth> = Auth.pipe(
|
|
48
|
+
Effect.flatMap((auth) =>
|
|
49
|
+
auth.getUserIdentity.pipe(
|
|
50
|
+
Effect.map((identity): Identity => ({ _tag: "Valid", identity })),
|
|
51
|
+
Effect.catchTag("NoUserIdentityFoundError", () =>
|
|
52
|
+
Effect.succeed<Identity>({ _tag: "Absent" }),
|
|
53
|
+
),
|
|
54
|
+
Effect.catchDefect(() => Effect.succeed<Identity>({ _tag: "Invalid" })),
|
|
55
|
+
),
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
|
|
33
59
|
export const layer = (auth: ConvexAuth) => Layer.succeed(Auth, make(auth));
|
|
34
60
|
|
|
35
61
|
/**
|