@passlock/node 2.0.0-beta.2 → 2.0.0-beta.3
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/effects/index.d.ts +5 -0
- package/dist/effects/index.d.ts.map +1 -0
- package/dist/effects/index.js +5 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/passkey/effects.d.ts +18 -0
- package/dist/passkey/effects.d.ts.map +1 -0
- package/dist/passkey/effects.js +61 -0
- package/dist/passkey/effects.js.map +1 -0
- package/dist/passkey/index.d.ts +50 -0
- package/dist/passkey/index.d.ts.map +1 -0
- package/dist/passkey/index.js +45 -0
- package/dist/passkey/index.js.map +1 -0
- package/dist/principal/effects.d.ts +18 -0
- package/dist/principal/effects.d.ts.map +1 -0
- package/dist/principal/effects.js +64 -0
- package/dist/principal/effects.js.map +1 -0
- package/dist/principal/index.d.ts +10 -9
- package/dist/principal/index.d.ts.map +1 -1
- package/dist/principal/index.js +7 -26
- package/dist/principal/index.js.map +1 -1
- package/dist/schemas/errors.d.ts +68 -0
- package/dist/schemas/errors.d.ts.map +1 -0
- package/dist/schemas/errors.js +34 -0
- package/dist/schemas/errors.js.map +1 -0
- package/dist/schemas/index.d.ts +5 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +5 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/passkey.d.ts +127 -0
- package/dist/schemas/passkey.d.ts.map +1 -0
- package/dist/schemas/passkey.js +96 -0
- package/dist/schemas/passkey.js.map +1 -0
- package/dist/schemas/principal.d.ts +48 -0
- package/dist/schemas/principal.d.ts.map +1 -0
- package/dist/schemas/principal.js +50 -0
- package/dist/schemas/principal.js.map +1 -0
- package/dist/schemas/signup.d.ts +13 -0
- package/dist/schemas/signup.d.ts.map +1 -0
- package/dist/schemas/signup.js +11 -0
- package/dist/schemas/signup.js.map +1 -0
- package/dist/shared.d.ts +0 -20
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -12
- package/dist/shared.js.map +1 -1
- package/dist/testUtils.d.ts +11 -0
- package/dist/testUtils.d.ts.map +1 -0
- package/dist/testUtils.js +25 -0
- package/dist/testUtils.js.map +1 -0
- package/package.json +26 -27
- package/dist/principal/effect.d.ts +0 -53
- package/dist/principal/effect.d.ts.map +0 -1
- package/dist/principal/effect.js +0 -78
- package/dist/principal/effect.js.map +0 -1
- package/dist/user/effect.d.ts +0 -18
- package/dist/user/effect.d.ts.map +0 -1
- package/dist/user/effect.js +0 -27
- package/dist/user/effect.js.map +0 -1
- package/dist/user/index.d.ts +0 -18
- package/dist/user/index.d.ts.map +0 -1
- package/dist/user/index.js +0 -36
- package/dist/user/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/effects/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/effects/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA","sourcesContent":["export * from \"../passkey/effects.js\"\nexport * from \"../principal/effects.js\"\nexport * from \"../schemas/index.js\"\nexport * from \"../shared.js\"\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from "./passkey/index.js";
|
|
2
|
+
export * from "./principal/index.js";
|
|
3
|
+
export * from "./schemas/index.js";
|
|
4
|
+
export * from "./shared.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./passkey/index.js";
|
|
2
|
+
export * from "./principal/index.js";
|
|
3
|
+
export * from "./schemas/index.js";
|
|
4
|
+
export * from "./shared.js";
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA","sourcesContent":["export * from \"./passkey/index.js\"\nexport * from \"./principal/index.js\"\nexport * from \"./schemas/index.js\"\nexport * from \"./shared.js\"\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AuthorizedApiOptions } from "../shared.js";
|
|
2
|
+
import { HttpClient } from "@effect/platform";
|
|
3
|
+
import { Effect, type Layer } from "effect";
|
|
4
|
+
import { Forbidden, NotFound } from "../schemas/errors.js";
|
|
5
|
+
import { Passkey } from "../schemas/passkey.js";
|
|
6
|
+
export type GetPasskeyOptions = AuthorizedApiOptions;
|
|
7
|
+
export declare const getPasskey: (authenticatorId: string, options: GetPasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
|
|
8
|
+
export type { GetPasskeyOptions as GetAuthenticatorOptions, Passkey };
|
|
9
|
+
type DeleteAuthenticatorOptions = AuthorizedApiOptions;
|
|
10
|
+
export declare const deletePasskey: (authenticatorId: string, request: DeleteAuthenticatorOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<void, NotFound | Forbidden>;
|
|
11
|
+
export type { DeleteAuthenticatorOptions };
|
|
12
|
+
interface AssignUserRequest extends AuthorizedApiOptions {
|
|
13
|
+
userId: string;
|
|
14
|
+
passkeyId: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const assignUser: (request: AssignUserRequest, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
|
|
17
|
+
export type { AssignUserRequest };
|
|
18
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/passkey/effects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAEL,UAAU,EAGX,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAuB,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAI/C,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,CAAA;AAEpD,eAAO,MAAM,UAAU,GACrB,iBAAiB,MAAM,EACvB,SAAS,iBAAiB,EAC1B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAiC3C,CAAA;AAEH,YAAY,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,OAAO,EAAE,CAAA;AAIrE,KAAK,0BAA0B,GAAG,oBAAoB,CAAA;AAEtD,eAAO,MAAM,aAAa,GACxB,iBAAiB,MAAM,EACvB,SAAS,0BAA0B,EACnC,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAiCxC,CAAA;AAEH,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAI1C,UAAU,iBAAkB,SAAQ,oBAAoB;IACtD,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,UAAU,GACrB,SAAS,iBAAiB,EAC1B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAmC3C,CAAA;AAEH,YAAY,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse, } from "@effect/platform";
|
|
2
|
+
import { Effect, Match, pipe, Schema } from "effect";
|
|
3
|
+
import { Forbidden, NotFound } from "../schemas/errors.js";
|
|
4
|
+
import { Passkey } from "../schemas/passkey.js";
|
|
5
|
+
export const getPasskey = (authenticatorId, options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
|
|
6
|
+
const client = yield* HttpClient.HttpClient;
|
|
7
|
+
const baseUrl = options.endpoint ?? "https://api.passlock.dev";
|
|
8
|
+
const { tenancyId } = options;
|
|
9
|
+
const url = new URL(`/${tenancyId}/passkeys/${authenticatorId}`, baseUrl);
|
|
10
|
+
const response = yield* HttpClientRequest.get(url, {
|
|
11
|
+
headers: { Authorization: `Bearer ${options.apiKey}` },
|
|
12
|
+
}).pipe(client.execute);
|
|
13
|
+
const encoded = yield* HttpClientResponse.matchStatus(response, {
|
|
14
|
+
"2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
|
|
15
|
+
orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
|
|
16
|
+
});
|
|
17
|
+
return yield* pipe(Match.value(encoded), Match.tag("Passkey", (data) => Effect.succeed(data)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.tag("@error/NotFound", (err) => Effect.fail(err)), Match.exhaustive);
|
|
18
|
+
}), Effect.catchTags({
|
|
19
|
+
ParseError: (err) => Effect.die(err),
|
|
20
|
+
RequestError: (err) => Effect.die(err),
|
|
21
|
+
ResponseError: (err) => Effect.die(err),
|
|
22
|
+
}), Effect.provide(httpClient));
|
|
23
|
+
export const deletePasskey = (authenticatorId, request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
|
|
24
|
+
const client = yield* HttpClient.HttpClient;
|
|
25
|
+
const baseUrl = request.endpoint ?? "https://api.passlock.dev";
|
|
26
|
+
const { tenancyId } = request;
|
|
27
|
+
const url = new URL(`/${tenancyId}/passkeys/${authenticatorId}`, baseUrl);
|
|
28
|
+
const response = yield* HttpClientRequest.del(url, {
|
|
29
|
+
headers: { Authorization: `Bearer ${request.apiKey}` },
|
|
30
|
+
}).pipe(client.execute);
|
|
31
|
+
const encoded = yield* HttpClientResponse.matchStatus(response, {
|
|
32
|
+
"2xx": () => Effect.succeed(null),
|
|
33
|
+
orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
|
|
34
|
+
});
|
|
35
|
+
yield* pipe(Match.value(encoded), Match.when(Match.null, () => Effect.void), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.tag("@error/NotFound", (err) => Effect.fail(err)), Match.exhaustive);
|
|
36
|
+
}), Effect.catchTags({
|
|
37
|
+
ParseError: (err) => Effect.die(err),
|
|
38
|
+
RequestError: (err) => Effect.die(err),
|
|
39
|
+
ResponseError: (err) => Effect.die(err),
|
|
40
|
+
}), Effect.provide(httpClient));
|
|
41
|
+
export const assignUser = (request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
|
|
42
|
+
const client = yield* HttpClient.HttpClient;
|
|
43
|
+
const baseUrl = request.endpoint ?? "https://api.passlock.dev";
|
|
44
|
+
const { userId, passkeyId } = request;
|
|
45
|
+
const { tenancyId } = request;
|
|
46
|
+
const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
|
|
47
|
+
const response = yield* HttpClientRequest.patch(url, {
|
|
48
|
+
headers: { Authorization: `Bearer ${request.apiKey}` },
|
|
49
|
+
}).pipe(HttpClientRequest.bodyJson({ userId }), Effect.flatMap(client.execute));
|
|
50
|
+
const encoded = yield* HttpClientResponse.matchStatus(response, {
|
|
51
|
+
"2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
|
|
52
|
+
orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),
|
|
53
|
+
});
|
|
54
|
+
return yield* pipe(Match.value(encoded), Match.tag("Passkey", (passkey) => Effect.succeed(passkey)), Match.tag("@error/NotFound", (err) => Effect.fail(err)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.exhaustive);
|
|
55
|
+
}), Effect.catchTags({
|
|
56
|
+
HttpBodyError: (err) => Effect.die(err),
|
|
57
|
+
ParseError: (err) => Effect.die(err),
|
|
58
|
+
RequestError: (err) => Effect.die(err),
|
|
59
|
+
ResponseError: (err) => Effect.die(err),
|
|
60
|
+
}), Effect.provide(httpClient));
|
|
61
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../src/passkey/effects.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EA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B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EACpB,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAC1D,KAAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvD,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACxD,KAAK,CAAC,UAAU,CACjB,CAAA;AACH,CAAC,CAAC,EACF,MAAM,CAAC,SAAS,CAAC;IACf,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;IACvC,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;IACpC,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;IACtC,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;CACxC,CAAC,EACF,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAC3B,CAAA","sourcesContent":["import type { AuthorizedApiOptions } from \"../shared.js\"\nimport {\n FetchHttpClient,\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from \"@effect/platform\"\nimport { Effect, type Layer, Match, pipe, Schema } from \"effect\"\nimport { Forbidden, NotFound } from \"../schemas/errors.js\"\nimport { Passkey } from \"../schemas/passkey.js\"\n\n/* Get Passkey */\n\nexport type GetPasskeyOptions = AuthorizedApiOptions\n\nexport const getPasskey = (\n authenticatorId: string,\n options: GetPasskeyOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<Passkey, NotFound | Forbidden> =>\n pipe(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const baseUrl = options.endpoint ?? \"https://api.passlock.dev\"\n const { tenancyId } = options\n\n const url = new URL(`/${tenancyId}/passkeys/${authenticatorId}`, baseUrl)\n\n const response = yield* HttpClientRequest.get(url, {\n headers: { Authorization: `Bearer ${options.apiKey}` },\n }).pipe(client.execute)\n\n const encoded = yield* HttpClientResponse.matchStatus(response, {\n \"2xx\": () => HttpClientResponse.schemaBodyJson(Passkey)(response),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),\n })\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"Passkey\", (data) => Effect.succeed(data)),\n Match.tag(\"@error/Forbidden\", (err) => Effect.fail(err)),\n Match.tag(\"@error/NotFound\", (err) => Effect.fail(err)),\n Match.exhaustive\n )\n }),\n Effect.catchTags({\n ParseError: (err) => Effect.die(err),\n RequestError: (err) => Effect.die(err),\n ResponseError: (err) => Effect.die(err),\n }),\n Effect.provide(httpClient)\n )\n\nexport type { GetPasskeyOptions as GetAuthenticatorOptions, Passkey }\n\n/* Delete Passkey */\n\ntype DeleteAuthenticatorOptions = AuthorizedApiOptions\n\nexport const deletePasskey = (\n authenticatorId: string,\n request: DeleteAuthenticatorOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<void, NotFound | Forbidden> =>\n pipe(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const baseUrl = request.endpoint ?? \"https://api.passlock.dev\"\n const { tenancyId } = request\n\n const url = new URL(`/${tenancyId}/passkeys/${authenticatorId}`, baseUrl)\n\n const response = yield* HttpClientRequest.del(url, {\n headers: { Authorization: `Bearer ${request.apiKey}` },\n }).pipe(client.execute)\n\n const encoded = yield* HttpClientResponse.matchStatus(response, {\n \"2xx\": () => Effect.succeed(null),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),\n })\n\n yield* pipe(\n Match.value(encoded),\n Match.when(Match.null, () => Effect.void),\n Match.tag(\"@error/Forbidden\", (err) => Effect.fail(err)),\n Match.tag(\"@error/NotFound\", (err) => Effect.fail(err)),\n Match.exhaustive\n )\n }),\n Effect.catchTags({\n ParseError: (err) => Effect.die(err),\n RequestError: (err) => Effect.die(err),\n ResponseError: (err) => Effect.die(err),\n }),\n Effect.provide(httpClient)\n )\n\nexport type { DeleteAuthenticatorOptions }\n\n/* Assign User */\n\ninterface AssignUserRequest extends AuthorizedApiOptions {\n userId: string\n passkeyId: string\n}\n\nexport const assignUser = (\n request: AssignUserRequest,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<Passkey, NotFound | Forbidden> =>\n pipe(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const baseUrl = request.endpoint ?? \"https://api.passlock.dev\"\n const { userId, passkeyId } = request\n const { tenancyId } = request\n\n const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl)\n\n const response = yield* HttpClientRequest.patch(url, {\n headers: { Authorization: `Bearer ${request.apiKey}` },\n }).pipe(HttpClientRequest.bodyJson({ userId }), Effect.flatMap(client.execute))\n\n const encoded = yield* HttpClientResponse.matchStatus(response, {\n \"2xx\": () => HttpClientResponse.schemaBodyJson(Passkey)(response),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),\n })\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"Passkey\", (passkey) => Effect.succeed(passkey)),\n Match.tag(\"@error/NotFound\", (err) => Effect.fail(err)),\n Match.tag(\"@error/Forbidden\", (err) => Effect.fail(err)),\n Match.exhaustive\n )\n }),\n Effect.catchTags({\n HttpBodyError: (err) => Effect.die(err),\n ParseError: (err) => Effect.die(err),\n RequestError: (err) => Effect.die(err),\n ResponseError: (err) => Effect.die(err),\n }),\n Effect.provide(httpClient)\n )\n\nexport type { AssignUserRequest }\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Forbidden, NotFound } from "../schemas/errors.js";
|
|
2
|
+
import type { AssignUserRequest, DeleteAuthenticatorOptions, GetAuthenticatorOptions, Passkey } from "./effects.js";
|
|
3
|
+
/**
|
|
4
|
+
* Call the Passlock backend API to assign a userId to an authenticator
|
|
5
|
+
* @param request
|
|
6
|
+
* @param request
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const assignUser: (request: AssignUserRequest) => Promise<Passkey | NotFound | Forbidden>;
|
|
10
|
+
/**
|
|
11
|
+
* Call the Passlock backend API to assign a userId to an authenticator
|
|
12
|
+
* @param request
|
|
13
|
+
* @param request
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const assignUserUnsafe: (request: AssignUserRequest) => Promise<Passkey>;
|
|
17
|
+
/**
|
|
18
|
+
* Call the Passlock backend API to delete an authenticator
|
|
19
|
+
* @param options
|
|
20
|
+
* @param options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const deletePasskey: (passkeyId: string, options: DeleteAuthenticatorOptions) => Promise<{
|
|
24
|
+
passkeyId: string;
|
|
25
|
+
} | Forbidden | NotFound>;
|
|
26
|
+
/**
|
|
27
|
+
* Call the Passlock backend API to delete an authenticator
|
|
28
|
+
* @param options
|
|
29
|
+
* @param options
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare const deletePasskeyUnsafe: (passkeyId: string, options: DeleteAuthenticatorOptions) => Promise<{
|
|
33
|
+
passkeyId: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Call the Passlock backend API to fetch an authenticator
|
|
37
|
+
* @param request
|
|
38
|
+
* @param request
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare const getPasskey: (authenticatorId: string, options: GetAuthenticatorOptions) => Promise<Passkey | Forbidden | NotFound>;
|
|
42
|
+
/**
|
|
43
|
+
* Call the Passlock backend API to fetch an authenticator
|
|
44
|
+
* @param request
|
|
45
|
+
* @param request
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare const getPasskeyUnsafe: (authenticatorId: string, options: GetAuthenticatorOptions) => Promise<Passkey>;
|
|
49
|
+
export type { AssignUserRequest, DeleteAuthenticatorOptions, GetAuthenticatorOptions, Passkey, } from "./effects.js";
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/passkey/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,uBAAuB,EACvB,OAAO,EACR,MAAM,cAAc,CAAA;AAQrB;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,iBAAiB,KAAG,OAAO,CAAC,OAAO,GAAG,QAAQ,GAAG,SAAS,CAK3F,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,OAAO,CAAC,OAAO,CAC9B,CAAA;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,MAAM,EACjB,SAAS,0BAA0B,KAClC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAAG,QAAQ,CAMpD,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,MAAM,EACjB,SAAS,0BAA0B,KAClC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CACuD,CAAA;AAEvF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,iBAAiB,MAAM,EACvB,SAAS,uBAAuB,KAC/B,OAAO,CAAC,OAAO,GAAG,SAAS,GAAG,QAAQ,CAKtC,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,iBAAiB,MAAM,EACvB,SAAS,uBAAuB,KAC/B,OAAO,CAAC,OAAO,CAAmE,CAAA;AAErF,YAAY,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,uBAAuB,EACvB,OAAO,GACR,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Effect, identity, pipe } from "effect";
|
|
2
|
+
import { assignUser as assignUserE, deletePasskey as deletePasskeyE, getPasskey as getPasskeyE, } from "./effects.js";
|
|
3
|
+
/**
|
|
4
|
+
* Call the Passlock backend API to assign a userId to an authenticator
|
|
5
|
+
* @param request
|
|
6
|
+
* @param request
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const assignUser = (request) => pipe(assignUserE(request), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
|
|
10
|
+
/**
|
|
11
|
+
* Call the Passlock backend API to assign a userId to an authenticator
|
|
12
|
+
* @param request
|
|
13
|
+
* @param request
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export const assignUserUnsafe = (request) => pipe(assignUserE(request), Effect.runPromise);
|
|
17
|
+
/**
|
|
18
|
+
* Call the Passlock backend API to delete an authenticator
|
|
19
|
+
* @param options
|
|
20
|
+
* @param options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export const deletePasskey = (passkeyId, options) => pipe(deletePasskeyE(passkeyId, options), Effect.as({ passkeyId }), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
|
|
24
|
+
/**
|
|
25
|
+
* Call the Passlock backend API to delete an authenticator
|
|
26
|
+
* @param options
|
|
27
|
+
* @param options
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export const deletePasskeyUnsafe = (passkeyId, options) => pipe(deletePasskeyE(passkeyId, options), Effect.as({ passkeyId }), Effect.runPromise);
|
|
31
|
+
/**
|
|
32
|
+
* Call the Passlock backend API to fetch an authenticator
|
|
33
|
+
* @param request
|
|
34
|
+
* @param request
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export const getPasskey = (authenticatorId, options) => pipe(getPasskeyE(authenticatorId, options), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
|
|
38
|
+
/**
|
|
39
|
+
* Call the Passlock backend API to fetch an authenticator
|
|
40
|
+
* @param request
|
|
41
|
+
* @param request
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export const getPasskeyUnsafe = (authenticatorId, options) => pipe(getPasskeyE(authenticatorId, options), Effect.runPromise);
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/passkey/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EACL,UAAU,IAAI,WAAW,EACzB,aAAa,IAAI,cAAc,EAC/B,UAAU,IAAI,WAAW,GAC1B,MAAM,cAAc,CAAA;AAErB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAA0B,EAA2C,EAAE,CAChG,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA0B,EAAoB,EAAE,CAC/E,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,SAAiB,EACjB,OAAmC,EACoB,EAAE,CACzD,IAAI,CACF,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,EAClC,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EACxB,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAiB,EACjB,OAAmC,EACH,EAAE,CAClC,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAEvF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,eAAuB,EACvB,OAAgC,EACS,EAAE,CAC3C,IAAI,CACF,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,EACrC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,eAAuB,EACvB,OAAgC,EACd,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA","sourcesContent":["import type { Forbidden, NotFound } from \"../schemas/errors.js\"\nimport type {\n AssignUserRequest,\n DeleteAuthenticatorOptions,\n GetAuthenticatorOptions,\n Passkey,\n} from \"./effects.js\"\nimport { Effect, identity, pipe } from \"effect\"\nimport {\n assignUser as assignUserE,\n deletePasskey as deletePasskeyE,\n getPasskey as getPasskeyE,\n} from \"./effects.js\"\n\n/**\n * Call the Passlock backend API to assign a userId to an authenticator\n * @param request\n * @param request\n * @returns\n */\nexport const assignUser = (request: AssignUserRequest): Promise<Passkey | NotFound | Forbidden> =>\n pipe(\n assignUserE(request),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise\n )\n\n/**\n * Call the Passlock backend API to assign a userId to an authenticator\n * @param request\n * @param request\n * @returns\n */\nexport const assignUserUnsafe = (request: AssignUserRequest): Promise<Passkey> =>\n pipe(assignUserE(request), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to delete an authenticator\n * @param options\n * @param options\n * @returns\n */\nexport const deletePasskey = (\n passkeyId: string,\n options: DeleteAuthenticatorOptions\n): Promise<{ passkeyId: string } | Forbidden | NotFound> =>\n pipe(\n deletePasskeyE(passkeyId, options),\n Effect.as({ passkeyId }),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise\n )\n\n/**\n * Call the Passlock backend API to delete an authenticator\n * @param options\n * @param options\n * @returns\n */\nexport const deletePasskeyUnsafe = (\n passkeyId: string,\n options: DeleteAuthenticatorOptions\n): Promise<{ passkeyId: string }> =>\n pipe(deletePasskeyE(passkeyId, options), Effect.as({ passkeyId }), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to fetch an authenticator\n * @param request\n * @param request\n * @returns\n */\nexport const getPasskey = (\n authenticatorId: string,\n options: GetAuthenticatorOptions\n): Promise<Passkey | Forbidden | NotFound> =>\n pipe(\n getPasskeyE(authenticatorId, options),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise\n )\n\n/**\n * Call the Passlock backend API to fetch an authenticator\n * @param request\n * @param request\n * @returns\n */\nexport const getPasskeyUnsafe = (\n authenticatorId: string,\n options: GetAuthenticatorOptions\n): Promise<Passkey> => pipe(getPasskeyE(authenticatorId, options), Effect.runPromise)\n\nexport type {\n AssignUserRequest,\n DeleteAuthenticatorOptions,\n GetAuthenticatorOptions,\n Passkey,\n} from \"./effects.js\"\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ApiOptions, AuthorizedApiOptions } from "../shared.js";
|
|
2
|
+
import { HttpClient } from "@effect/platform";
|
|
3
|
+
import { Effect, type Layer } from "effect";
|
|
4
|
+
import { Forbidden, InvalidCode } from "../schemas/errors.js";
|
|
5
|
+
import { ExtendedPrincipal, type Principal } from "../schemas/principal.js";
|
|
6
|
+
type ExchangeCodeOptions = AuthorizedApiOptions;
|
|
7
|
+
export declare const exchangeCode: (code: string, options: ExchangeCodeOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<ExtendedPrincipal, InvalidCode | Forbidden>;
|
|
8
|
+
type VerifyTokenOptions = ApiOptions;
|
|
9
|
+
declare const VerificationFailure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
10
|
+
readonly _tag: "@error/VerificationFailure";
|
|
11
|
+
} & Readonly<A>;
|
|
12
|
+
export declare class VerificationFailure extends VerificationFailure_base<{
|
|
13
|
+
message: string;
|
|
14
|
+
}> {
|
|
15
|
+
}
|
|
16
|
+
export declare const verifyIdToken: (token: string, options: VerifyTokenOptions) => Effect.Effect<Principal, VerificationFailure>;
|
|
17
|
+
export type { ExchangeCodeOptions, Principal, VerifyTokenOptions };
|
|
18
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/principal/effects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAmB,UAAU,EAAsB,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAQ,MAAM,EAAE,KAAK,KAAK,EAAuB,MAAM,QAAQ,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAW,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEpF,KAAK,mBAAmB,GAAG,oBAAoB,CAAA;AAE/C,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,SAAS,mBAAmB,EAC5B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,GAAG,SAAS,CAmCxD,CAAA;AAEH,KAAK,kBAAkB,GAAG,UAAU,CAAA;;;;AAWpC,qBAAa,mBAAoB,SAAQ,yBAA+C;IACtF,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC;CAAG;AAEL,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,EACb,SAAS,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAyC5C,CAAA;AAEH,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FetchHttpClient, HttpClient, HttpClientResponse } from "@effect/platform";
|
|
2
|
+
import { Data, Effect, Match, pipe, Schema } from "effect";
|
|
3
|
+
import * as jose from "jose";
|
|
4
|
+
import { Forbidden, InvalidCode } from "../schemas/errors.js";
|
|
5
|
+
import { ExtendedPrincipal, IdToken } from "../schemas/principal.js";
|
|
6
|
+
export const exchangeCode = (code, options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
|
|
7
|
+
const client = yield* HttpClient.HttpClient;
|
|
8
|
+
const baseUrl = options.endpoint ?? "https://api.passlock.dev";
|
|
9
|
+
const { tenancyId } = options;
|
|
10
|
+
const url = new URL(`/${tenancyId}/principal/${code}`, baseUrl);
|
|
11
|
+
const response = yield* pipe(client.get(url, {
|
|
12
|
+
headers: { Authorization: `Bearer ${options.apiKey}` },
|
|
13
|
+
}));
|
|
14
|
+
const encoded = yield* HttpClientResponse.matchStatus(response, {
|
|
15
|
+
"2xx": () => HttpClientResponse.schemaBodyJson(ExtendedPrincipal)(response),
|
|
16
|
+
orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(InvalidCode, Forbidden))(response),
|
|
17
|
+
});
|
|
18
|
+
return yield* pipe(Match.value(encoded), Match.tag("ExtendedPrincipal", (principal) => Effect.succeed(principal)), Match.tag("@error/InvalidCode", (err) => Effect.fail(err)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.exhaustive);
|
|
19
|
+
}), Effect.catchTags({
|
|
20
|
+
ParseError: (err) => Effect.die(err),
|
|
21
|
+
RequestError: (err) => Effect.die(err),
|
|
22
|
+
ResponseError: (err) => Effect.die(err),
|
|
23
|
+
}), Effect.provide(httpClient));
|
|
24
|
+
const createJwks = (endpoint) => Effect.sync(() => {
|
|
25
|
+
const baseUrl = endpoint ?? "https://api.passlock.dev";
|
|
26
|
+
return jose.createRemoteJWKSet(new URL("/.well-known/jwks.json", baseUrl));
|
|
27
|
+
});
|
|
28
|
+
const createCachedRemoteJwks = pipe(Effect.cachedFunction(createJwks), Effect.runSync);
|
|
29
|
+
export class VerificationFailure extends Data.TaggedError("@error/VerificationFailure") {
|
|
30
|
+
}
|
|
31
|
+
export const verifyIdToken = (token, options) => pipe(Effect.gen(function* () {
|
|
32
|
+
const JWKS = yield* createCachedRemoteJwks(options.endpoint);
|
|
33
|
+
const { payload } = yield* Effect.tryPromise({
|
|
34
|
+
catch: (err) => {
|
|
35
|
+
console.error(err);
|
|
36
|
+
return err instanceof Error
|
|
37
|
+
? new VerificationFailure({ message: err.message })
|
|
38
|
+
: new VerificationFailure({ message: String(err) });
|
|
39
|
+
},
|
|
40
|
+
try: () => jose.jwtVerify(token, JWKS, {
|
|
41
|
+
audience: options.tenancyId,
|
|
42
|
+
issuer: "passlock.dev",
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
const idToken = yield* Schema.decodeUnknown(IdToken)({
|
|
46
|
+
...payload,
|
|
47
|
+
_tag: "IdToken",
|
|
48
|
+
});
|
|
49
|
+
const principal = {
|
|
50
|
+
_tag: "Principal",
|
|
51
|
+
id: idToken["jti"],
|
|
52
|
+
authenticatorId: idToken["a:id"],
|
|
53
|
+
authenticatorType: "passkey",
|
|
54
|
+
createdAt: idToken.iat * 1000,
|
|
55
|
+
expiresAt: idToken.exp * 1000,
|
|
56
|
+
passkey: {
|
|
57
|
+
userVerified: idToken["pk:uv"],
|
|
58
|
+
verified: true,
|
|
59
|
+
},
|
|
60
|
+
userId: idToken.sub,
|
|
61
|
+
};
|
|
62
|
+
return principal;
|
|
63
|
+
}), Effect.catchTag("ParseError", (err) => Effect.die(err)));
|
|
64
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../src/principal/effects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAc,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAkB,MAAM,yBAAyB,CAAA;AAIpF,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAY,EACZ,OAA4B,EAC5B,aAAiD,eAAe,CAAC,KAAK,EACX,EAAE,CAC7D,IAAI,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAA;IAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,IAAI,0BAA0B,CAAA;IAC9D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAE7B,MAAM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AAG,CAAC,EAAE,CAAC,CAAA;QACvD,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CACR,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE;YAC1B,QAAQ,EAAE,OAAO,CAAC,SAAS;YAC3B,MAAM,EAAE,cAAc;SACvB,CAAC;KACL,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACnD,GAAG,OAAO;QACV,IAAI,EAAE,SAAS;KAChB,CAAC,CAAA;IAEF,MAAM,SAAS,GAAc;QAC3B,IAAI,EAAE,WAAW;QACjB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC;QAClB,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC;QAChC,iBAAiB,EAAE,SAAS;QAC5B,SAAS,EAAE,OAAO,CAAC,GAAG,GAAG,IAAI;QAC7B,SAAS,EAAE,OAAO,CAAC,GAAG,GAAG,IAAI;QAC7B,OAAO,EAAE;YACP,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC;YAC9B,QAAQ,EAAE,IAAI;SACf;QACD,MAAM,EAAE,OAAO,CAAC,GAAG;KACpB,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAC,EACF,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CACxD,CAAA","sourcesContent":["import type { ApiOptions, AuthorizedApiOptions } from \"../shared.js\"\nimport { FetchHttpClient, HttpClient, HttpClientResponse } from \"@effect/platform\"\nimport { Data, Effect, type Layer, Match, pipe, Schema } from \"effect\"\nimport * as jose from \"jose\"\nimport { Forbidden, InvalidCode } from \"../schemas/errors.js\"\nimport { ExtendedPrincipal, IdToken, type Principal } from \"../schemas/principal.js\"\n\ntype ExchangeCodeOptions = AuthorizedApiOptions\n\nexport const exchangeCode = (\n code: string,\n options: ExchangeCodeOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<ExtendedPrincipal, InvalidCode | Forbidden> =>\n pipe(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n const baseUrl = options.endpoint ?? \"https://api.passlock.dev\"\n const { tenancyId } = options\n\n const url = new URL(`/${tenancyId}/principal/${code}`, baseUrl)\n\n const response = yield* pipe(\n client.get(url, {\n headers: { Authorization: `Bearer ${options.apiKey}` },\n })\n )\n\n const encoded = yield* HttpClientResponse.matchStatus(response, {\n \"2xx\": () => HttpClientResponse.schemaBodyJson(ExtendedPrincipal)(response),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(InvalidCode, Forbidden))(response),\n })\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"ExtendedPrincipal\", (principal) => Effect.succeed(principal)),\n Match.tag(\"@error/InvalidCode\", (err) => Effect.fail(err)),\n Match.tag(\"@error/Forbidden\", (err) => Effect.fail(err)),\n Match.exhaustive\n )\n }),\n Effect.catchTags({\n ParseError: (err) => Effect.die(err),\n RequestError: (err) => Effect.die(err),\n ResponseError: (err) => Effect.die(err),\n }),\n Effect.provide(httpClient)\n )\n\ntype VerifyTokenOptions = ApiOptions\n\nconst createJwks = (endpoint?: string) =>\n Effect.sync(() => {\n const baseUrl = endpoint ?? \"https://api.passlock.dev\"\n\n return jose.createRemoteJWKSet(new URL(\"/.well-known/jwks.json\", baseUrl))\n })\n\nconst createCachedRemoteJwks = pipe(Effect.cachedFunction(createJwks), Effect.runSync)\n\nexport class VerificationFailure extends Data.TaggedError(\"@error/VerificationFailure\")<{\n message: string\n}> {}\n\nexport const verifyIdToken = (\n token: string,\n options: VerifyTokenOptions\n): Effect.Effect<Principal, VerificationFailure> =>\n pipe(\n Effect.gen(function* () {\n const JWKS = yield* createCachedRemoteJwks(options.endpoint)\n\n const { payload } = yield* Effect.tryPromise({\n catch: (err) => {\n console.error(err)\n return err instanceof Error\n ? new VerificationFailure({ message: err.message })\n : new VerificationFailure({ message: String(err) })\n },\n try: () =>\n jose.jwtVerify(token, JWKS, {\n audience: options.tenancyId,\n issuer: \"passlock.dev\",\n }),\n })\n\n const idToken = yield* Schema.decodeUnknown(IdToken)({\n ...payload,\n _tag: \"IdToken\",\n })\n\n const principal: Principal = {\n _tag: \"Principal\",\n id: idToken[\"jti\"],\n authenticatorId: idToken[\"a:id\"],\n authenticatorType: \"passkey\",\n createdAt: idToken.iat * 1000,\n expiresAt: idToken.exp * 1000,\n passkey: {\n userVerified: idToken[\"pk:uv\"],\n verified: true,\n },\n userId: idToken.sub,\n }\n\n return principal\n }),\n Effect.catchTag(\"ParseError\", (err) => Effect.die(err))\n )\n\nexport type { ExchangeCodeOptions, Principal, VerifyTokenOptions }\n"]}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import { type
|
|
4
|
-
export type { VerificationError, Principal } from "./effect.js";
|
|
5
|
-
export { isPrincipal } from "./effect.js";
|
|
1
|
+
import type { Forbidden, InvalidCode } from "../schemas/errors.js";
|
|
2
|
+
import type { ExtendedPrincipal, Principal } from "../schemas/principal.js";
|
|
3
|
+
import { type ExchangeCodeOptions, type VerificationFailure, type VerifyTokenOptions } from "./effects.js";
|
|
6
4
|
/**
|
|
7
5
|
* Call the Passlock backend API to exchange a code for a Principal
|
|
8
6
|
* @param code
|
|
9
7
|
* @package options
|
|
10
8
|
* @returns
|
|
11
9
|
*/
|
|
12
|
-
export declare const exchangeCode: (code: string, options:
|
|
10
|
+
export declare const exchangeCode: (code: string, options: ExchangeCodeOptions) => Promise<ExtendedPrincipal | Forbidden | InvalidCode>;
|
|
13
11
|
/**
|
|
14
12
|
* Call the Passlock backend API to exchange a code for a Principal
|
|
15
13
|
* @param code
|
|
16
14
|
* @package options
|
|
17
15
|
* @returns
|
|
18
16
|
*/
|
|
19
|
-
export declare const exchangeCodeUnsafe: (code: string, options:
|
|
17
|
+
export declare const exchangeCodeUnsafe: (code: string, options: ExchangeCodeOptions) => Promise<ExtendedPrincipal>;
|
|
20
18
|
/**
|
|
21
19
|
* Decode and verify a Passlock idToken.
|
|
22
20
|
* Note: This will make a network call to the passlock.dev/.well-known/jwks.json
|
|
@@ -27,7 +25,7 @@ export declare const exchangeCodeUnsafe: (code: string, options: AuthorizedApiOp
|
|
|
27
25
|
* @param options
|
|
28
26
|
* @returns
|
|
29
27
|
*/
|
|
30
|
-
export declare const verifyIdToken: (token: string, options:
|
|
28
|
+
export declare const verifyIdToken: (token: string, options: VerifyTokenOptions) => Promise<Principal | VerificationFailure>;
|
|
31
29
|
/**
|
|
32
30
|
* Decode and verify a Passlock idToken.
|
|
33
31
|
* Note: This will make a network call to the passlock.dev/.well-known/jwks.json
|
|
@@ -38,5 +36,8 @@ export declare const verifyIdToken: (token: string, options: ApiOptions) => Prom
|
|
|
38
36
|
* @param options
|
|
39
37
|
* @returns
|
|
40
38
|
*/
|
|
41
|
-
export declare const verifyIdTokenUnsafe: (token: string, options:
|
|
39
|
+
export declare const verifyIdTokenUnsafe: (token: string, options: VerifyTokenOptions) => Promise<Principal>;
|
|
40
|
+
export type { InvalidCode } from "../schemas/errors.js";
|
|
41
|
+
export type { ExchangeCodeOptions, Principal, VerificationFailure, VerifyTokenOptions, } from "./effects.js";
|
|
42
|
+
export * from "../schemas/principal.js";
|
|
42
43
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/principal/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/principal/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAG3E,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAExB,MAAM,cAAc,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,SAAS,mBAAmB,KAC3B,OAAO,CAAC,iBAAiB,GAAG,SAAS,GAAG,WAAW,CAMnD,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,MAAM,MAAM,EACZ,SAAS,mBAAmB,KAC3B,OAAO,CAAC,iBAAiB,CACkE,CAAA;AAE9F;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,EACb,SAAS,kBAAkB,KAC1B,OAAO,CAAC,SAAS,GAAG,mBAAmB,CAKvC,CAAA;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,SAAS,kBAAkB,KAC1B,OAAO,CAAC,SAAS,CAC4E,CAAA;AAEhG,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,YAAY,EACV,mBAAmB,EACnB,SAAS,EACT,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAA;AACrB,cAAc,yBAAyB,CAAA"}
|
package/dist/principal/index.js
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
import { FetchHttpClient } from "@effect/platform";
|
|
2
|
-
import { Effect,
|
|
3
|
-
import { exchangeCode as exchangeCodeE, verifyIdToken as verifyIdTokenE, } from "./
|
|
4
|
-
import { UnexpectedError, } from "../shared.js";
|
|
5
|
-
export { isPrincipal } from "./effect.js";
|
|
2
|
+
import { Effect, identity, pipe } from "effect";
|
|
3
|
+
import { exchangeCode as exchangeCodeE, verifyIdToken as verifyIdTokenE, } from "./effects.js";
|
|
6
4
|
/**
|
|
7
5
|
* Call the Passlock backend API to exchange a code for a Principal
|
|
8
6
|
* @param code
|
|
9
7
|
* @package options
|
|
10
8
|
* @returns
|
|
11
9
|
*/
|
|
12
|
-
export const exchangeCode = (code, options) => pipe(exchangeCodeE(code, options), Effect.
|
|
13
|
-
ParseError: (err) => Effect.die(err),
|
|
14
|
-
RequestError: (err) => Effect.die(err),
|
|
15
|
-
ResponseError: (err) => Effect.die(err),
|
|
16
|
-
}), Effect.match({
|
|
17
|
-
onSuccess: identity,
|
|
18
|
-
onFailure: identity,
|
|
19
|
-
}), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
|
|
10
|
+
export const exchangeCode = (code, options) => pipe(exchangeCodeE(code, options), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
|
|
20
11
|
/**
|
|
21
12
|
* Call the Passlock backend API to exchange a code for a Principal
|
|
22
13
|
* @param code
|
|
23
14
|
* @package options
|
|
24
15
|
* @returns
|
|
25
16
|
*/
|
|
26
|
-
export const exchangeCodeUnsafe = (code, options) => pipe(exchangeCodeE(code, options), Effect.
|
|
27
|
-
onLeft: (err) => pipe(Match.value(err), Match.tag("ParseError", (err) => new UnexpectedError(err)), Match.tag("RequestError", (err) => new UnexpectedError(err)), Match.tag("ResponseError", (err) => new UnexpectedError(err)), Match.tag("@error/InvalidCode", (err) => new UnexpectedError(err)), Match.tag("@error/Forbidden", ({ _tag }) => new UnexpectedError({ _tag, message: "Forbidden" })), Match.exhaustive, (serverError) => Promise.reject(serverError)),
|
|
28
|
-
onRight: (success) => Promise.resolve(success),
|
|
29
|
-
})));
|
|
17
|
+
export const exchangeCodeUnsafe = (code, options) => pipe(exchangeCodeE(code, options), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
|
|
30
18
|
/**
|
|
31
19
|
* Decode and verify a Passlock idToken.
|
|
32
20
|
* Note: This will make a network call to the passlock.dev/.well-known/jwks.json
|
|
@@ -37,12 +25,7 @@ export const exchangeCodeUnsafe = (code, options) => pipe(exchangeCodeE(code, op
|
|
|
37
25
|
* @param options
|
|
38
26
|
* @returns
|
|
39
27
|
*/
|
|
40
|
-
export const verifyIdToken = (token, options) => pipe(verifyIdTokenE(token, options), Effect.
|
|
41
|
-
ParseError: (err) => Effect.die(err),
|
|
42
|
-
}), Effect.match({
|
|
43
|
-
onSuccess: identity,
|
|
44
|
-
onFailure: identity,
|
|
45
|
-
}), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
|
|
28
|
+
export const verifyIdToken = (token, options) => pipe(verifyIdTokenE(token, options), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
|
|
46
29
|
/**
|
|
47
30
|
* Decode and verify a Passlock idToken.
|
|
48
31
|
* Note: This will make a network call to the passlock.dev/.well-known/jwks.json
|
|
@@ -53,8 +36,6 @@ export const verifyIdToken = (token, options) => pipe(verifyIdTokenE(token, opti
|
|
|
53
36
|
* @param options
|
|
54
37
|
* @returns
|
|
55
38
|
*/
|
|
56
|
-
export const verifyIdTokenUnsafe = (token, options) => pipe(verifyIdTokenE(token, options), Effect.
|
|
57
|
-
|
|
58
|
-
onRight: (success) => Promise.resolve(success),
|
|
59
|
-
})));
|
|
39
|
+
export const verifyIdTokenUnsafe = (token, options) => pipe(verifyIdTokenE(token, options), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
|
|
40
|
+
export * from "../schemas/principal.js";
|
|
60
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/principal/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/principal/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAEL,YAAY,IAAI,aAAa,EAG7B,aAAa,IAAI,cAAc,GAChC,MAAM,cAAc,CAAA;AAErB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAY,EACZ,OAA4B,EAC0B,EAAE,CACxD,IAAI,CACF,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,EAC5B,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EACrC,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,IAAY,EACZ,OAA4B,EACA,EAAE,CAC9B,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE9F;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAa,EACb,OAA2B,EACe,EAAE,CAC5C,IAAI,CACF,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,EAC9B,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAa,EACb,OAA2B,EACP,EAAE,CACtB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAShG,cAAc,yBAAyB,CAAA","sourcesContent":["import type { Forbidden, InvalidCode } from \"../schemas/errors.js\"\nimport type { ExtendedPrincipal, Principal } from \"../schemas/principal.js\"\nimport { FetchHttpClient } from \"@effect/platform\"\nimport { Effect, identity, pipe } from \"effect\"\nimport {\n type ExchangeCodeOptions,\n exchangeCode as exchangeCodeE,\n type VerificationFailure,\n type VerifyTokenOptions,\n verifyIdToken as verifyIdTokenE,\n} from \"./effects.js\"\n\n/**\n * Call the Passlock backend API to exchange a code for a Principal\n * @param code\n * @package options\n * @returns\n */\nexport const exchangeCode = (\n code: string,\n options: ExchangeCodeOptions\n): Promise<ExtendedPrincipal | Forbidden | InvalidCode> =>\n pipe(\n exchangeCodeE(code, options),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.provide(FetchHttpClient.layer),\n Effect.runPromise\n )\n\n/**\n * Call the Passlock backend API to exchange a code for a Principal\n * @param code\n * @package options\n * @returns\n */\nexport const exchangeCodeUnsafe = (\n code: string,\n options: ExchangeCodeOptions\n): Promise<ExtendedPrincipal> =>\n pipe(exchangeCodeE(code, options), Effect.provide(FetchHttpClient.layer), Effect.runPromise)\n\n/**\n * Decode and verify a Passlock idToken.\n * Note: This will make a network call to the passlock.dev/.well-known/jwks.json\n * endpoint to fetch the relevant public key. The response will be cached, however\n * bear in mind that for something like AWS lambda it will make the call on every\n * cold start so might actually be slower than {@link exchangeCode}\n * @param token\n * @param options\n * @returns\n */\nexport const verifyIdToken = (\n token: string,\n options: VerifyTokenOptions\n): Promise<Principal | VerificationFailure> =>\n pipe(\n verifyIdTokenE(token, options),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise\n )\n\n/**\n * Decode and verify a Passlock idToken.\n * Note: This will make a network call to the passlock.dev/.well-known/jwks.json\n * endpoint to fetch the relevant public key. The response will be cached, however\n * bear in mind that for something like AWS lambda it will make the call on every\n * cold start so might actually be slower than {@link exchangeCode}\n * @param token\n * @param options\n * @returns\n */\nexport const verifyIdTokenUnsafe = (\n token: string,\n options: VerifyTokenOptions\n): Promise<Principal> =>\n pipe(verifyIdTokenE(token, options), Effect.provide(FetchHttpClient.layer), Effect.runPromise)\n\nexport type { InvalidCode } from \"../schemas/errors.js\"\nexport type {\n ExchangeCodeOptions,\n Principal,\n VerificationFailure,\n VerifyTokenOptions,\n} from \"./effects.js\"\nexport * from \"../schemas/principal.js\"\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare const Unauthorized_base: Schema.TaggedErrorClass<Unauthorized, "@error/Unauthorized", {
|
|
3
|
+
readonly _tag: Schema.tag<"@error/Unauthorized">;
|
|
4
|
+
}>;
|
|
5
|
+
export declare class Unauthorized extends Unauthorized_base {
|
|
6
|
+
}
|
|
7
|
+
declare const Forbidden_base: Schema.TaggedErrorClass<Forbidden, "@error/Forbidden", {
|
|
8
|
+
readonly _tag: Schema.tag<"@error/Forbidden">;
|
|
9
|
+
}>;
|
|
10
|
+
export declare class Forbidden extends Forbidden_base {
|
|
11
|
+
}
|
|
12
|
+
declare const InvalidCode_base: Schema.TaggedErrorClass<InvalidCode, "@error/InvalidCode", {
|
|
13
|
+
readonly _tag: Schema.tag<"@error/InvalidCode">;
|
|
14
|
+
} & {
|
|
15
|
+
message: typeof Schema.String;
|
|
16
|
+
}>;
|
|
17
|
+
export declare class InvalidCode extends InvalidCode_base {
|
|
18
|
+
}
|
|
19
|
+
declare const InvalidTenancy_base: Schema.TaggedErrorClass<InvalidTenancy, "@error/InvalidTenancy", {
|
|
20
|
+
readonly _tag: Schema.tag<"@error/InvalidTenancy">;
|
|
21
|
+
} & {
|
|
22
|
+
message: typeof Schema.String;
|
|
23
|
+
}>;
|
|
24
|
+
export declare class InvalidTenancy extends InvalidTenancy_base {
|
|
25
|
+
}
|
|
26
|
+
declare const PasskeyNotFound_base: Schema.TaggedErrorClass<PasskeyNotFound, "@error/PasskeyNotFound", {
|
|
27
|
+
readonly _tag: Schema.tag<"@error/PasskeyNotFound">;
|
|
28
|
+
} & {
|
|
29
|
+
credentialId: typeof Schema.String;
|
|
30
|
+
message: typeof Schema.String;
|
|
31
|
+
rpId: typeof Schema.String;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* We need the credentialId and rpId to feed into the
|
|
35
|
+
* client's signalCredentialRemoval function
|
|
36
|
+
*/
|
|
37
|
+
export declare class PasskeyNotFound extends PasskeyNotFound_base {
|
|
38
|
+
}
|
|
39
|
+
declare const NotFound_base: Schema.TaggedErrorClass<NotFound, "@error/NotFound", {
|
|
40
|
+
readonly _tag: Schema.tag<"@error/NotFound">;
|
|
41
|
+
} & {
|
|
42
|
+
message: typeof Schema.String;
|
|
43
|
+
}>;
|
|
44
|
+
export declare class NotFound extends NotFound_base {
|
|
45
|
+
}
|
|
46
|
+
declare const InvalidEmail_base: Schema.TaggedErrorClass<InvalidEmail, "@error/InvalidEmail", {
|
|
47
|
+
readonly _tag: Schema.tag<"@error/InvalidEmail">;
|
|
48
|
+
} & {
|
|
49
|
+
message: typeof Schema.String;
|
|
50
|
+
}>;
|
|
51
|
+
export declare class InvalidEmail extends InvalidEmail_base {
|
|
52
|
+
}
|
|
53
|
+
declare const DuplicateEmail_base: Schema.TaggedErrorClass<DuplicateEmail, "@error/DuplicateEmail", {
|
|
54
|
+
readonly _tag: Schema.tag<"@error/DuplicateEmail">;
|
|
55
|
+
} & {
|
|
56
|
+
message: typeof Schema.String;
|
|
57
|
+
}>;
|
|
58
|
+
export declare class DuplicateEmail extends DuplicateEmail_base {
|
|
59
|
+
}
|
|
60
|
+
declare const BadRequest_base: Schema.TaggedErrorClass<BadRequest, "@error/BadRequest", {
|
|
61
|
+
readonly _tag: Schema.tag<"@error/BadRequest">;
|
|
62
|
+
} & {
|
|
63
|
+
message: typeof Schema.String;
|
|
64
|
+
}>;
|
|
65
|
+
export declare class BadRequest extends BadRequest_base {
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/schemas/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;;;;AAE/B,qBAAa,YAAa,SAAQ,iBAA6D;CAAG;;;;AAElG,qBAAa,SAAU,SAAQ,cAAuD;CAAG;;;;;;AAEzF,qBAAa,WAAY,SAAQ,gBAKhC;CAAG;;;;;;AAEJ,qBAAa,cAAe,SAAQ,mBAElC;CAAG;;;;;;;;AAEL;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;;;;;;AAEJ,qBAAa,QAAS,SAAQ,aAE5B;CAAG;;;;;;AAEL,qBAAa,YAAa,SAAQ,iBAGjC;CAAG;;;;;;AAEJ,qBAAa,cAAe,SAAQ,mBAGnC;CAAG;;;;;;AAEJ,qBAAa,UAAW,SAAQ,eAG/B;CAAG"}
|