@passlock/node 2.0.0-beta.2 → 2.0.0-beta.5

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.
Files changed (65) hide show
  1. package/dist/effects/index.d.ts +5 -0
  2. package/dist/effects/index.d.ts.map +1 -0
  3. package/dist/effects/index.js +5 -0
  4. package/dist/effects/index.js.map +1 -0
  5. package/dist/index.d.ts +4 -3
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +4 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/passkey/effects.d.ts +24 -0
  10. package/dist/passkey/effects.d.ts.map +1 -0
  11. package/dist/passkey/effects.js +87 -0
  12. package/dist/passkey/effects.js.map +1 -0
  13. package/dist/passkey/index.d.ts +64 -0
  14. package/dist/passkey/index.d.ts.map +1 -0
  15. package/dist/passkey/index.js +58 -0
  16. package/dist/passkey/index.js.map +1 -0
  17. package/dist/principal/effects.d.ts +18 -0
  18. package/dist/principal/effects.d.ts.map +1 -0
  19. package/dist/principal/effects.js +64 -0
  20. package/dist/principal/effects.js.map +1 -0
  21. package/dist/principal/index.d.ts +10 -9
  22. package/dist/principal/index.d.ts.map +1 -1
  23. package/dist/principal/index.js +7 -26
  24. package/dist/principal/index.js.map +1 -1
  25. package/dist/schemas/errors.d.ts +68 -0
  26. package/dist/schemas/errors.d.ts.map +1 -0
  27. package/dist/schemas/errors.js +34 -0
  28. package/dist/schemas/errors.js.map +1 -0
  29. package/dist/schemas/index.d.ts +5 -0
  30. package/dist/schemas/index.d.ts.map +1 -0
  31. package/dist/schemas/index.js +5 -0
  32. package/dist/schemas/index.js.map +1 -0
  33. package/dist/schemas/passkey.d.ts +63 -0
  34. package/dist/schemas/passkey.d.ts.map +1 -0
  35. package/dist/schemas/passkey.js +59 -0
  36. package/dist/schemas/passkey.js.map +1 -0
  37. package/dist/schemas/principal.d.ts +48 -0
  38. package/dist/schemas/principal.d.ts.map +1 -0
  39. package/dist/schemas/principal.js +46 -0
  40. package/dist/schemas/principal.js.map +1 -0
  41. package/dist/schemas/signup.d.ts +13 -0
  42. package/dist/schemas/signup.d.ts.map +1 -0
  43. package/dist/schemas/signup.js +11 -0
  44. package/dist/schemas/signup.js.map +1 -0
  45. package/dist/shared.d.ts +4 -22
  46. package/dist/shared.d.ts.map +1 -1
  47. package/dist/shared.js +2 -11
  48. package/dist/shared.js.map +1 -1
  49. package/dist/testUtils.d.ts +11 -0
  50. package/dist/testUtils.d.ts.map +1 -0
  51. package/dist/testUtils.js +25 -0
  52. package/dist/testUtils.js.map +1 -0
  53. package/package.json +26 -27
  54. package/dist/principal/effect.d.ts +0 -53
  55. package/dist/principal/effect.d.ts.map +0 -1
  56. package/dist/principal/effect.js +0 -78
  57. package/dist/principal/effect.js.map +0 -1
  58. package/dist/user/effect.d.ts +0 -18
  59. package/dist/user/effect.d.ts.map +0 -1
  60. package/dist/user/effect.js +0 -27
  61. package/dist/user/effect.js.map +0 -1
  62. package/dist/user/index.d.ts +0 -18
  63. package/dist/user/index.d.ts.map +0 -1
  64. package/dist/user/index.js +0 -36
  65. package/dist/user/index.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ export * from "../passkey/effects.js";
2
+ export * from "../principal/effects.js";
3
+ export * from "../schemas/index.js";
4
+ export * from "../shared.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -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,5 @@
1
+ export * from "../passkey/effects.js";
2
+ export * from "../principal/effects.js";
3
+ export * from "../schemas/index.js";
4
+ export * from "../shared.js";
5
+ //# sourceMappingURL=index.js.map
@@ -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 type { ApiOptions, AuthorizedApiOptions } from "./shared.js";
2
- export { type Principal, isPrincipal, exchangeCode, exchangeCodeUnsafe, verifyIdToken, verifyIdTokenUnsafe, } from "./principal/index.js";
3
- export { type AssignUserRequest, type AssignedUser, assignUserUnsafe, } from "./user/index.js";
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EACL,KAAK,SAAS,EACd,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
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 { isPrincipal, exchangeCode, exchangeCodeUnsafe, verifyIdToken, verifyIdTokenUnsafe, } from "./principal/index.js";
2
- export { assignUserUnsafe, } from "./user/index.js";
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":"AAEA,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAGL,gBAAgB,GACjB,MAAM,iBAAiB,CAAC","sourcesContent":["export type { ApiOptions, AuthorizedApiOptions } from \"./shared.js\";\n\nexport {\n type Principal,\n isPrincipal,\n exchangeCode,\n exchangeCodeUnsafe,\n verifyIdToken,\n verifyIdTokenUnsafe,\n} from \"./principal/index.js\";\n\nexport {\n type AssignUserRequest,\n type AssignedUser,\n assignUserUnsafe,\n} from \"./user/index.js\";\n"]}
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,24 @@
1
+ import type { AuthenticatedTenancyOptions } from "../shared.js";
2
+ import { HttpClient } from "@effect/platform";
3
+ import { Effect, type Layer, Stream } from "effect";
4
+ import { Forbidden, NotFound } from "../schemas/errors.js";
5
+ import { FindAllPasskeys } from "../schemas/index.js";
6
+ import { DeletedPasskey, Passkey, type PasskeySummary } from "../schemas/passkey.js";
7
+ export type GetPasskeyOptions = AuthenticatedTenancyOptions;
8
+ export declare const getPasskey: (authenticatorId: string, options: GetPasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
9
+ export type { GetPasskeyOptions as GetAuthenticatorOptions, Passkey };
10
+ type DeleteAuthenticatorOptions = AuthenticatedTenancyOptions;
11
+ export declare const deletePasskey: (passkeyId: string, request: DeleteAuthenticatorOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<DeletedPasskey, NotFound | Forbidden>;
12
+ export type { DeleteAuthenticatorOptions };
13
+ interface AssignUserRequest extends AuthenticatedTenancyOptions {
14
+ userId: string;
15
+ passkeyId: string;
16
+ }
17
+ export declare const assignUser: (request: AssignUserRequest, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
18
+ export type { AssignUserRequest };
19
+ export interface ListPasskeyOptions extends AuthenticatedTenancyOptions {
20
+ cursor?: string;
21
+ }
22
+ export declare const listPasskeysStream: (options: AuthenticatedTenancyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Stream.Stream<PasskeySummary, Forbidden>;
23
+ export declare const listPasskeys: (options: ListPasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<FindAllPasskeys, Forbidden>;
24
+ //# 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,2BAA2B,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAEL,UAAU,EAGX,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAS,MAAM,EAAE,KAAK,KAAK,EAA+B,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAIpF,MAAM,MAAM,iBAAiB,GAAG,2BAA2B,CAAA;AAE3D,eAAO,MAAM,UA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MAAM,CAAC,eAAe,EAAE,SAAS,CAkCxC,CAAA"}
@@ -0,0 +1,87 @@
1
+ import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse, } from "@effect/platform";
2
+ import { Chunk, Effect, Match, Option, pipe, Schema, Stream } from "effect";
3
+ import { Forbidden, NotFound } from "../schemas/errors.js";
4
+ import { FindAllPasskeys } from "../schemas/index.js";
5
+ import { DeletedPasskey, Passkey } from "../schemas/passkey.js";
6
+ export const getPasskey = (authenticatorId, 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}/passkeys/${authenticatorId}`, baseUrl);
11
+ const response = yield* HttpClientRequest.get(url, {
12
+ headers: { Authorization: `Bearer ${options.apiKey}` },
13
+ }).pipe(client.execute);
14
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
15
+ "2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
16
+ orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
17
+ });
18
+ 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);
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
+ export const deletePasskey = (passkeyId, request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
25
+ const client = yield* HttpClient.HttpClient;
26
+ const baseUrl = request.endpoint ?? "https://api.passlock.dev";
27
+ const { tenancyId } = request;
28
+ const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
29
+ const response = yield* HttpClientRequest.del(url, {
30
+ headers: { Authorization: `Bearer ${request.apiKey}` },
31
+ }).pipe(client.execute);
32
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
33
+ "2xx": () => HttpClientResponse.schemaBodyJson(DeletedPasskey)(response),
34
+ orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
35
+ });
36
+ return yield* pipe(Match.value(encoded), Match.tag("DeletedPasskey", (deletedPasskey) => Effect.succeed(deletedPasskey)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.tag("@error/NotFound", (err) => Effect.fail(err)), Match.exhaustive);
37
+ }), Effect.catchTags({
38
+ ParseError: (err) => Effect.die(err),
39
+ RequestError: (err) => Effect.die(err),
40
+ ResponseError: (err) => Effect.die(err),
41
+ }), Effect.provide(httpClient));
42
+ export const assignUser = (request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
43
+ const client = yield* HttpClient.HttpClient;
44
+ const baseUrl = request.endpoint ?? "https://api.passlock.dev";
45
+ const { userId, passkeyId } = request;
46
+ const { tenancyId } = request;
47
+ const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
48
+ const response = yield* HttpClientRequest.patch(url, {
49
+ headers: { Authorization: `Bearer ${request.apiKey}` },
50
+ }).pipe(HttpClientRequest.bodyJson({ userId }), Effect.flatMap(client.execute));
51
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
52
+ "2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
53
+ orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),
54
+ });
55
+ 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);
56
+ }), Effect.catchTags({
57
+ HttpBodyError: (err) => Effect.die(err),
58
+ ParseError: (err) => Effect.die(err),
59
+ RequestError: (err) => Effect.die(err),
60
+ ResponseError: (err) => Effect.die(err),
61
+ }), Effect.provide(httpClient));
62
+ export const listPasskeysStream = (options, httpClient = FetchHttpClient.layer) => pipe(Stream.paginateChunkEffect(null, (cursor) => pipe(listPasskeys(cursor ? { ...options, cursor } : options, httpClient), Effect.map((result) => [
63
+ Chunk.fromIterable(result.records),
64
+ Option.fromNullable(result.cursor),
65
+ ]))));
66
+ export const listPasskeys = (options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
67
+ const client = yield* HttpClient.HttpClient;
68
+ const baseUrl = options.endpoint ?? "https://api.passlock.dev";
69
+ const { tenancyId } = options;
70
+ const url = new URL(`/${tenancyId}/passkeys/`, baseUrl);
71
+ if (options.cursor) {
72
+ url.searchParams.append("cursor", options.cursor);
73
+ }
74
+ const response = yield* HttpClientRequest.get(url, {
75
+ headers: { Authorization: `Bearer ${options.apiKey}` },
76
+ }).pipe(client.execute);
77
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
78
+ "2xx": () => HttpClientResponse.schemaBodyJson(FindAllPasskeys)(response),
79
+ orElse: () => HttpClientResponse.schemaBodyJson(Forbidden)(response),
80
+ });
81
+ return yield* pipe(Match.value(encoded), Match.tag("FindAllPasskeys", (data) => Effect.succeed(data)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.exhaustive);
82
+ }), Effect.catchTags({
83
+ ParseError: (err) => Effect.die(err),
84
+ RequestError: (err) => Effect.die(err),
85
+ ResponseError: (err) => Effect.die(err),
86
+ }), Effect.provide(httpClient));
87
+ //# 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,EAAE,KAAK,EAAE,MAAM,EAAc,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ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,CAAC;KACrE,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,CAAC,IAAI,CAChB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EACpB,KAAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAC5D,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,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 { AuthenticatedTenancyOptions } from \"../shared.js\"\nimport {\n FetchHttpClient,\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from \"@effect/platform\"\nimport { Chunk, Effect, type Layer, Match, Option, pipe, Schema, Stream } from \"effect\"\nimport { Forbidden, NotFound } from \"../schemas/errors.js\"\nimport { FindAllPasskeys } from \"../schemas/index.js\"\nimport { DeletedPasskey, Passkey, type PasskeySummary } from \"../schemas/passkey.js\"\n\n/* Get Passkey */\n\nexport type GetPasskeyOptions = AuthenticatedTenancyOptions\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 = AuthenticatedTenancyOptions\n\nexport const deletePasskey = (\n passkeyId: string,\n request: DeleteAuthenticatorOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<DeletedPasskey, 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/${passkeyId}`, 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\": () => HttpClientResponse.schemaBodyJson(DeletedPasskey)(response),\n orElse: () =>\n HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),\n })\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"DeletedPasskey\", (deletedPasskey) => Effect.succeed(deletedPasskey)),\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 AuthenticatedTenancyOptions {\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\n/* List Passkeys */\n\nexport interface ListPasskeyOptions extends AuthenticatedTenancyOptions {\n cursor?: string\n}\n\nexport const listPasskeysStream = (\n options: AuthenticatedTenancyOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Stream.Stream<PasskeySummary, Forbidden> =>\n pipe(\n Stream.paginateChunkEffect(null as string | null, (cursor) =>\n pipe(\n listPasskeys(cursor ? { ...options, cursor } : options, httpClient),\n Effect.map((result) => [\n Chunk.fromIterable(result.records),\n Option.fromNullable(result.cursor),\n ])\n )\n )\n )\n\nexport const listPasskeys = (\n options: ListPasskeyOptions,\n httpClient: Layer.Layer<HttpClient.HttpClient> = FetchHttpClient.layer\n): Effect.Effect<FindAllPasskeys, 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/`, baseUrl)\n if (options.cursor) {\n url.searchParams.append(\"cursor\", options.cursor)\n }\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(FindAllPasskeys)(response),\n orElse: () => HttpClientResponse.schemaBodyJson(Forbidden)(response),\n })\n\n return yield* pipe(\n Match.value(encoded),\n Match.tag(\"FindAllPasskeys\", (data) => Effect.succeed(data)),\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"]}
@@ -0,0 +1,64 @@
1
+ import type { Forbidden, NotFound } from "../schemas/errors.js";
2
+ import type { DeletedPasskey, FindAllPasskeys, PasskeySummary } from "../schemas/passkey.js";
3
+ import type { AuthenticatedTenancyOptions } from "../shared.js";
4
+ import type { AssignUserRequest, DeleteAuthenticatorOptions, GetAuthenticatorOptions, ListPasskeyOptions, Passkey } from "./effects.js";
5
+ /**
6
+ * Call the Passlock backend API to assign a userId to an authenticator
7
+ * @param request
8
+ * @param request
9
+ * @returns
10
+ */
11
+ export declare const assignUser: (request: AssignUserRequest) => Promise<Passkey | NotFound | Forbidden>;
12
+ /**
13
+ * Call the Passlock backend API to assign a userId to an authenticator
14
+ * @param request
15
+ * @param request
16
+ * @returns
17
+ */
18
+ export declare const assignUserUnsafe: (request: AssignUserRequest) => Promise<Passkey>;
19
+ /**
20
+ * Call the Passlock backend API to delete an authenticator
21
+ * @param options
22
+ * @param options
23
+ * @returns
24
+ */
25
+ export declare const deletePasskey: (passkeyId: string, options: DeleteAuthenticatorOptions) => Promise<DeletedPasskey | 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 authenticatorId
45
+ * @param options
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
+ /**
51
+ * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.
52
+ * @param options
53
+ * @returns
54
+ */
55
+ export declare const listPasskeys: (options: ListPasskeyOptions) => Promise<FindAllPasskeys | Forbidden>;
56
+ /**
57
+ * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.
58
+ * @param options
59
+ * @returns
60
+ */
61
+ export declare const listPasskeysUnsafe: (options: ListPasskeyOptions) => Promise<FindAllPasskeys>;
62
+ export declare const listPasskeysStream: (options: AuthenticatedTenancyOptions) => ReadableStream<PasskeySummary>;
63
+ export type { ListPasskeyOptions } from "./effects.js";
64
+ //# 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,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC5F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,OAAO,EACR,MAAM,cAAc,CAAA;AAUrB;;;;;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,cAAc,GAAG,SAAS,GAAG,QAAQ,CAK7C,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;AAErB;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,kBAAkB,KAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAK3F,CAAA;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,kBAAkB,KAAG,OAAO,CAAC,eAAe,CACvC,CAAA;AAEjD,eAAO,MAAM,kBAAkB,GAC7B,SAAS,2BAA2B,KACnC,cAAc,CAAC,cAAc,CACiD,CAAA;AAEjF,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,58 @@
1
+ import { Effect, identity, pipe, Stream } from "effect";
2
+ import { assignUser as assignUserE, deletePasskey as deletePasskeyE, getPasskey as getPasskeyE, listPasskeys as listPasskeysE, listPasskeysStream as listPasskeysStreamE, } 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.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 authenticatorId
41
+ * @param options
42
+ * @returns
43
+ */
44
+ export const getPasskeyUnsafe = (authenticatorId, options) => pipe(getPasskeyE(authenticatorId, options), Effect.runPromise);
45
+ /**
46
+ * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.
47
+ * @param options
48
+ * @returns
49
+ */
50
+ export const listPasskeys = (options) => pipe(listPasskeysE(options), Effect.match({ onFailure: identity, onSuccess: identity }), Effect.runPromise);
51
+ /**
52
+ * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.
53
+ * @param options
54
+ * @returns
55
+ */
56
+ export const listPasskeysUnsafe = (options) => pipe(listPasskeysE(options), Effect.runPromise);
57
+ export const listPasskeysStream = (options) => pipe(listPasskeysStreamE(options), (stream) => Stream.toReadableStream(stream));
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/passkey/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,EACL,UAAU,IAAI,WAAW,EACzB,aAA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AAQ,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;AASrF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAA2B,EAAwC,EAAE,CAChG,IAAI,CACF,aAAa,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAC1D,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAA2B,EAA4B,EAAE,CAC1F,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAoC,EACJ,EAAE,CAClC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA","sourcesContent":["import type { Forbidden, NotFound } from \"../schemas/errors.js\"\nimport type { DeletedPasskey, FindAllPasskeys, PasskeySummary } from \"../schemas/passkey.js\"\nimport type { AuthenticatedTenancyOptions } from \"../shared.js\"\nimport type {\n AssignUserRequest,\n DeleteAuthenticatorOptions,\n GetAuthenticatorOptions,\n ListPasskeyOptions,\n Passkey,\n} from \"./effects.js\"\nimport { Effect, identity, pipe, Stream } from \"effect\"\nimport {\n assignUser as assignUserE,\n deletePasskey as deletePasskeyE,\n getPasskey as getPasskeyE,\n listPasskeys as listPasskeysE,\n listPasskeysStream as listPasskeysStreamE,\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<DeletedPasskey | Forbidden | NotFound> =>\n pipe(\n deletePasskeyE(passkeyId, options),\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 authenticatorId\n * @param options\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\n/**\n * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.\n * @param options\n * @returns\n */\nexport const listPasskeys = (options: ListPasskeyOptions): Promise<FindAllPasskeys | Forbidden> =>\n pipe(\n listPasskeysE(options),\n Effect.match({ onFailure: identity, onSuccess: identity }),\n Effect.runPromise\n )\n\n/**\n * List passkeys for the given tenancy. Note this could return a cursor, in which case the function chould be called with the given cursor.\n * @param options\n * @returns\n */\nexport const listPasskeysUnsafe = (options: ListPasskeyOptions): Promise<FindAllPasskeys> =>\n pipe(listPasskeysE(options), Effect.runPromise)\n\nexport const listPasskeysStream = (\n options: AuthenticatedTenancyOptions\n): ReadableStream<PasskeySummary> =>\n pipe(listPasskeysStreamE(options), (stream) => Stream.toReadableStream(stream))\n\nexport type { ListPasskeyOptions } from \"./effects.js\"\n"]}
@@ -0,0 +1,18 @@
1
+ import type { AuthenticatedTenancyOptions, TenancyOptions } 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 = AuthenticatedTenancyOptions;
7
+ export declare const exchangeCode: (code: string, options: ExchangeCodeOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<ExtendedPrincipal, InvalidCode | Forbidden>;
8
+ type VerifyTokenOptions = TenancyOptions;
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,2BAA2B,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC/E,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,2BAA2B,CAAA;AAEtD,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,cAAc,CAAA;;;;AAWxC,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,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,SAAS,cAA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AAG,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 { AuthenticatedTenancyOptions, TenancyOptions } 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 = AuthenticatedTenancyOptions\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 = TenancyOptions\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 { type Principal } from "./effect.js";
2
- import type { VerificationError, InvalidCode } from "./effect.js";
3
- import { type Forbidden, type ApiOptions, type AuthorizedApiOptions } from "../shared.js";
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: AuthorizedApiOptions) => Promise<Principal | Forbidden | InvalidCode>;
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: AuthorizedApiOptions) => Promise<Principal>;
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: ApiOptions) => Promise<Principal | VerificationError>;
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: ApiOptions) => Promise<Principal>;
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":"AAGA,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,UAAU,EACf,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,SAAS,oBAAoB,KAC5B,OAAO,CAAC,SAA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AC4E,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"}
@@ -1,32 +1,20 @@
1
1
  import { FetchHttpClient } from "@effect/platform";
2
- import { Effect, Either, identity, Match, pipe } from "effect";
3
- import { exchangeCode as exchangeCodeE, verifyIdToken as verifyIdTokenE, } from "./effect.js";
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.catchTags({
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.either, Effect.provide(FetchHttpClient.layer), Effect.runPromise, (p) => p.then((response) => Either.match(response, {
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.catchTags({
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.either, Effect.provide(FetchHttpClient.layer), Effect.runPromise, (p) => p.then((response) => Either.match(response, {
57
- onLeft: (err) => Promise.reject(new UnexpectedError(err)),
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