@passlock/node 2.0.0 → 2.0.2

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 (66) hide show
  1. package/README.md +0 -1
  2. package/README.template.md +0 -1
  3. package/dist/effect.d.ts +7 -0
  4. package/dist/effect.d.ts.map +1 -0
  5. package/dist/effect.js +4 -0
  6. package/dist/effect.js.map +1 -0
  7. package/dist/errors.d.ts +71 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +25 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/index.d.ts +89 -4
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +84 -4
  14. package/dist/index.js.map +1 -1
  15. package/dist/passkey/passkey.d.ts +116 -0
  16. package/dist/passkey/passkey.d.ts.map +1 -0
  17. package/dist/passkey/{effects.js → passkey.js} +45 -21
  18. package/dist/passkey/passkey.js.map +1 -0
  19. package/dist/principal/principal.d.ts +11 -7
  20. package/dist/principal/principal.d.ts.map +1 -1
  21. package/dist/principal/principal.js +8 -8
  22. package/dist/principal/principal.js.map +1 -1
  23. package/dist/safe.d.ts +136 -0
  24. package/dist/safe.d.ts.map +1 -0
  25. package/dist/safe.js +130 -0
  26. package/dist/safe.js.map +1 -0
  27. package/dist/schemas/errors.d.ts +22 -65
  28. package/dist/schemas/errors.d.ts.map +1 -1
  29. package/dist/schemas/errors.js +56 -6
  30. package/dist/schemas/errors.js.map +1 -1
  31. package/dist/schemas/passkey.d.ts +19 -21
  32. package/dist/schemas/passkey.d.ts.map +1 -1
  33. package/dist/schemas/passkey.js +23 -17
  34. package/dist/schemas/passkey.js.map +1 -1
  35. package/dist/schemas/principal.d.ts +46 -6
  36. package/dist/schemas/principal.d.ts.map +1 -1
  37. package/dist/schemas/principal.js +6 -6
  38. package/dist/schemas/principal.js.map +1 -1
  39. package/dist/schemas/satisfy.d.ts +2 -0
  40. package/dist/schemas/satisfy.d.ts.map +1 -0
  41. package/dist/schemas/satisfy.js +2 -0
  42. package/dist/schemas/satisfy.js.map +1 -0
  43. package/dist/shared.d.ts +3 -5
  44. package/dist/shared.d.ts.map +1 -1
  45. package/dist/shared.js +0 -3
  46. package/dist/shared.js.map +1 -1
  47. package/package.json +32 -26
  48. package/dist/effects/index.d.ts +0 -5
  49. package/dist/effects/index.d.ts.map +0 -1
  50. package/dist/effects/index.js +0 -5
  51. package/dist/effects/index.js.map +0 -1
  52. package/dist/passkey/effects.d.ts +0 -24
  53. package/dist/passkey/effects.d.ts.map +0 -1
  54. package/dist/passkey/effects.js.map +0 -1
  55. package/dist/passkey/index.d.ts +0 -64
  56. package/dist/passkey/index.d.ts.map +0 -1
  57. package/dist/passkey/index.js +0 -58
  58. package/dist/passkey/index.js.map +0 -1
  59. package/dist/principal/index.d.ts +0 -43
  60. package/dist/principal/index.d.ts.map +0 -1
  61. package/dist/principal/index.js +0 -41
  62. package/dist/principal/index.js.map +0 -1
  63. package/dist/testUtils.d.ts +0 -11
  64. package/dist/testUtils.d.ts.map +0 -1
  65. package/dist/testUtils.js +0 -25
  66. package/dist/testUtils.js.map +0 -1
package/README.md CHANGED
@@ -42,5 +42,4 @@ Node 22+
42
42
 
43
43
  Please see the [Quick start guide](https://passlock.dev/getting-started/)
44
44
 
45
- [contact]: https://passlock.dev/contact
46
45
  [client]: https://www.npmjs.com/package/@passlock/client
@@ -42,5 +42,4 @@ Node 22+
42
42
 
43
43
  Please see the [Quick start guide](#{TUTORIAL}#)
44
44
 
45
- [contact]: https://passlock.dev/contact
46
45
  [client]: https://www.npmjs.com/package/@passlock/client
@@ -0,0 +1,7 @@
1
+ export type { AssignUserOptions as AssignUserRequest, ListPasskeyOptions, } from "./passkey/passkey.js";
2
+ export { assignUser, deletePasskey, getPasskey, listPasskeys, } from "./passkey/passkey.js";
3
+ export type {} from "./principal/principal.js";
4
+ export { exchangeCode, VerificationFailure, verifyIdToken, } from "./principal/principal.js";
5
+ export * from "./schemas/index.js";
6
+ export type { AuthenticatedOptions, PasslockOptions, } from "./shared.js";
7
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,IAAI,iBAAiB,EACtC,kBAAkB,GACnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC9C,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,GACd,MAAM,0BAA0B,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,YAAY,EACV,oBAAoB,EACpB,eAAe,GAChB,MAAM,aAAa,CAAA"}
package/dist/effect.js ADDED
@@ -0,0 +1,4 @@
1
+ export { assignUser, deletePasskey, getPasskey, listPasskeys, } from "./passkey/passkey.js";
2
+ export { exchangeCode, VerificationFailure, verifyIdToken, } from "./principal/principal.js";
3
+ export * from "./schemas/index.js";
4
+ //# sourceMappingURL=effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.js","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,GACd,MAAM,0BAA0B,CAAA;AACjC,cAAc,oBAAoB,CAAA","sourcesContent":["export type {\n AssignUserOptions as AssignUserRequest,\n ListPasskeyOptions,\n} from \"./passkey/passkey.js\"\nexport {\n assignUser,\n deletePasskey,\n getPasskey,\n listPasskeys,\n} from \"./passkey/passkey.js\"\nexport type {} from \"./principal/principal.js\"\nexport {\n exchangeCode,\n VerificationFailure,\n verifyIdToken,\n} from \"./principal/principal.js\"\nexport * from \"./schemas/index.js\"\nexport type {\n AuthenticatedOptions,\n PasslockOptions,\n} from \"./shared.js\"\n"]}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @category Authentication
3
+ */
4
+ export type Unauthorized = {
5
+ _tag: "@error/Unauthorized";
6
+ message: string;
7
+ };
8
+ export declare const isUnauthorized: (payload: unknown) => payload is Unauthorized;
9
+ /**
10
+ * @category Authentication
11
+ */
12
+ export type Forbidden = {
13
+ _tag: "@error/Forbidden";
14
+ message: string;
15
+ };
16
+ export declare const isForbidden: (payload: unknown) => payload is Forbidden;
17
+ /**
18
+ * @category Principal
19
+ */
20
+ export type InvalidCode = {
21
+ _tag: "@error/InvalidCode";
22
+ message: string;
23
+ };
24
+ export declare const isInvalidCode: (payload: unknown) => payload is InvalidCode;
25
+ /**
26
+ * @category Principal
27
+ */
28
+ export type VerificationFailure = {
29
+ _tag: "@error/VerificationFailure";
30
+ message: string;
31
+ };
32
+ export declare const isVerificationFailure: (payload: unknown) => payload is VerificationFailure;
33
+ export type InvalidTenancy = {
34
+ _tag: "@error/InvalidTenancy";
35
+ message: string;
36
+ };
37
+ export declare const isInvalidTenancy: (payload: unknown) => payload is InvalidTenancy;
38
+ /**
39
+ * Error payload returned when a passkey cannot be found for a given
40
+ * authentication attempt.
41
+ *
42
+ * @category Passkeys
43
+ */
44
+ export type PasskeyNotFound = {
45
+ _tag: "@error/PasskeyNotFound";
46
+ message: string;
47
+ credentialId: string;
48
+ rpId: string;
49
+ };
50
+ export declare const isPasskeyNotFound: (payload: unknown) => payload is PasskeyNotFound;
51
+ export type NotFound = {
52
+ _tag: "@error/NotFound";
53
+ message: string;
54
+ };
55
+ export declare const isNotFound: (payload: unknown) => payload is NotFound;
56
+ export type InvalidEmail = {
57
+ _tag: "@error/InvalidEmail";
58
+ message: string;
59
+ };
60
+ export declare const isInvalidEmail: (payload: unknown) => payload is InvalidEmail;
61
+ export type DuplicateEmail = {
62
+ _tag: "@error/DuplicateEmail";
63
+ message: string;
64
+ };
65
+ export declare const isDuplicateEmail: (payload: unknown) => payload is DuplicateEmail;
66
+ export type BadRequest = {
67
+ _tag: "@error/BadRequest";
68
+ message: string;
69
+ };
70
+ export declare const isBadRequest: (payload: unknown) => payload is BadRequest;
71
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,qBAAqB,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,cAAc,YAnBf,OAAO,KAAG,OAAO,gBAmB8C,CAAA;AAI3E;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,kBAAkB,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,WAAW,YA/BZ,OAAO,KAAG,OAAO,aA+BqC,CAAA;AAIlE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,oBAAoB,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,YA3Cd,OAAO,KAAG,OAAO,eA2C2C,CAAA;AAIxE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,4BAA4B,CAAA;IAClC,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,qBAAqB,YAvDtB,OAAO,KAAG,OAAO,uBAyD5B,CAAA;AAID,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,uBAAuB,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,gBAAgB,YAlEjB,OAAO,KAAG,OAAO,kBAoE5B,CAAA;AAID;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,wBAAwB,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,iBAAiB,YArFlB,OAAO,KAAG,OAAO,mBAuF5B,CAAA;AAID,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,iBAAiB,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,UAAU,YAhGX,OAAO,KAAG,OAAO,YAgGkC,CAAA;AAI/D,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,qBAAqB,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,cAAc,YAzGf,OAAO,KAAG,OAAO,gBAyG8C,CAAA;AAI3E,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,uBAAuB,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,gBAAgB,YAlHjB,OAAO,KAAG,OAAO,kBAoH5B,CAAA;AAID,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,mBAAmB,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,YAAY,YA7Hb,OAAO,KAAG,OAAO,cA6HwC,CAAA"}
package/dist/errors.js ADDED
@@ -0,0 +1,25 @@
1
+ /* Unauthorized */
2
+ const isTagged = (tag) => (payload) => {
3
+ if (typeof payload !== "object")
4
+ return false;
5
+ if (payload === null)
6
+ return false;
7
+ if (!("_tag" in payload))
8
+ return false;
9
+ if (typeof payload._tag !== "string")
10
+ return false;
11
+ if (payload._tag !== tag)
12
+ return false;
13
+ return true;
14
+ };
15
+ export const isUnauthorized = isTagged("@error/Unauthorized");
16
+ export const isForbidden = isTagged("@error/Forbidden");
17
+ export const isInvalidCode = isTagged("@error/InvalidCode");
18
+ export const isVerificationFailure = isTagged("@error/VerificationFailure");
19
+ export const isInvalidTenancy = isTagged("@error/InvalidTenancy");
20
+ export const isPasskeyNotFound = isTagged("@error/PasskeyNotFound");
21
+ export const isNotFound = isTagged("@error/NotFound");
22
+ export const isInvalidEmail = isTagged("@error/InvalidEmail");
23
+ export const isDuplicateEmail = isTagged("@error/DuplicateEmail");
24
+ export const isBadRequest = isTagged("@error/BadRequest");
25
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,MAAM,QAAQ,GACZ,CAA6B,GAAc,EAAE,EAAE,CAC/C,CAAC,OAAgB,EAAgB,EAAE;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7C,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAElC,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IACtC,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAClD,IAAI,OAAO,CAAC,IAAI,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAUH,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAe,qBAAqB,CAAC,CAAA;AAY3E,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAY,kBAAkB,CAAC,CAAA;AAYlE,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAc,oBAAoB,CAAC,CAAA;AAYxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAAQ,CAC3C,4BAA4B,CAC7B,CAAA;AASD,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CACtC,uBAAuB,CACxB,CAAA;AAiBD,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CACvC,wBAAwB,CACzB,CAAA;AASD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAW,iBAAiB,CAAC,CAAA;AAS/D,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAe,qBAAqB,CAAC,CAAA;AAS3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CACtC,uBAAuB,CACxB,CAAA;AASD,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAa,mBAAmB,CAAC,CAAA","sourcesContent":["/* Unauthorized */\n\nconst isTagged =\n <A extends { _tag: string }>(tag: A[\"_tag\"]) =>\n (payload: unknown): payload is A => {\n if (typeof payload !== \"object\") return false\n if (payload === null) return false\n\n if (!(\"_tag\" in payload)) return false\n if (typeof payload._tag !== \"string\") return false\n if (payload._tag !== tag) return false\n\n return true\n }\n\n/**\n * @category Authentication\n */\nexport type Unauthorized = {\n _tag: \"@error/Unauthorized\"\n message: string\n}\n\nexport const isUnauthorized = isTagged<Unauthorized>(\"@error/Unauthorized\")\n\n/* Forbidden */\n\n/**\n * @category Authentication\n */\nexport type Forbidden = {\n _tag: \"@error/Forbidden\"\n message: string\n}\n\nexport const isForbidden = isTagged<Forbidden>(\"@error/Forbidden\")\n\n/* InvalidCode */\n\n/**\n * @category Principal\n */\nexport type InvalidCode = {\n _tag: \"@error/InvalidCode\"\n message: string\n}\n\nexport const isInvalidCode = isTagged<InvalidCode>(\"@error/InvalidCode\")\n\n/* VerificationFailure */\n\n/**\n * @category Principal\n */\nexport type VerificationFailure = {\n _tag: \"@error/VerificationFailure\"\n message: string\n}\n\nexport const isVerificationFailure = isTagged<VerificationFailure>(\n \"@error/VerificationFailure\"\n)\n\n/* InvalidTenancy */\n\nexport type InvalidTenancy = {\n _tag: \"@error/InvalidTenancy\"\n message: string\n}\n\nexport const isInvalidTenancy = isTagged<InvalidTenancy>(\n \"@error/InvalidTenancy\"\n)\n\n/* PasskeyNotFound */\n\n/**\n * Error payload returned when a passkey cannot be found for a given\n * authentication attempt.\n *\n * @category Passkeys\n */\nexport type PasskeyNotFound = {\n _tag: \"@error/PasskeyNotFound\"\n message: string\n credentialId: string\n rpId: string\n}\n\nexport const isPasskeyNotFound = isTagged<PasskeyNotFound>(\n \"@error/PasskeyNotFound\"\n)\n\n/* NotFound */\n\nexport type NotFound = {\n _tag: \"@error/NotFound\"\n message: string\n}\n\nexport const isNotFound = isTagged<NotFound>(\"@error/NotFound\")\n\n/* InvalidEmail */\n\nexport type InvalidEmail = {\n _tag: \"@error/InvalidEmail\"\n message: string\n}\n\nexport const isInvalidEmail = isTagged<InvalidEmail>(\"@error/InvalidEmail\")\n\n/* DuplicateEmail */\n\nexport type DuplicateEmail = {\n _tag: \"@error/DuplicateEmail\"\n message: string\n}\n\nexport const isDuplicateEmail = isTagged<DuplicateEmail>(\n \"@error/DuplicateEmail\"\n)\n\n/* BadRequest */\n\nexport type BadRequest = {\n _tag: \"@error/BadRequest\"\n message: string\n}\n\nexport const isBadRequest = isTagged<BadRequest>(\"@error/BadRequest\")\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,90 @@
1
- export * from "./passkey/index.js";
2
- export * from "./principal/index.js";
3
- export * from "./schemas/index.js";
4
- export * from "./shared.js";
1
+ /**
2
+ * Unsafe functions that could potentially throw errors.
3
+ *
4
+ * @categoryDescription Passkeys
5
+ * Functions and related types for managing passkeys
6
+ *
7
+ * @showCategories
8
+ *
9
+ * @module unsafe
10
+ */
11
+ import type { AssignUserOptions, DeletedPasskey, DeletePasskeyOptions, FindAllPasskeys, GetPasskeyOptions, ListPasskeyOptions, Passkey, UpdatePasskeyOptions } from "./passkey/passkey.js";
12
+ import type { ExchangeCodeOptions, VerifyIdTokenOptions } from "./principal/principal.js";
13
+ import type { ExtendedPrincipal, Principal } from "./schemas/principal.js";
14
+ /**
15
+ * Call the Passlock backend API to assign a userId to an authenticator
16
+ *
17
+ * @param request
18
+ * @returns A promise resolving to the updated passkey.
19
+ * @throws {@link NotFound} if passkey does not exist
20
+ * @throws {@link Forbidden} if the Tenancy ID or API key is invalid
21
+ *
22
+ * @category Passkeys
23
+ */
24
+ export declare const assignUser: (request: AssignUserOptions) => Promise<Passkey>;
25
+ /**
26
+ * Call the Passlock backend API to update passkey properties
27
+ *
28
+ * @param request
29
+ * @returns A promise resolving to the updated passkey.
30
+ *
31
+ * @category Passkeys
32
+ */
33
+ export declare const updatePasskey: (request: UpdatePasskeyOptions) => Promise<Passkey>;
34
+ /**
35
+ * Call the Passlock backend API to delete an authenticator
36
+ *
37
+ * @param options
38
+ * @returns A promise resolving to the deleted passkey payload.
39
+ *
40
+ * @category Passkeys
41
+ */
42
+ export declare const deletePasskey: (options: DeletePasskeyOptions) => Promise<DeletedPasskey>;
43
+ /**
44
+ * Call the Passlock backend API to fetch an authenticator
45
+ * @param options
46
+ * @returns A promise resolving to the passkey.
47
+ */
48
+ export declare const getPasskey: (options: GetPasskeyOptions) => Promise<Passkey>;
49
+ /**
50
+ * List passkeys for the given tenancy. Note this could return a cursor,
51
+ * in which case the function should be called again with the given cursor.
52
+ *
53
+ * @param options
54
+ * @returns A promise resolving to a page of passkey summaries.
55
+ *
56
+ * @category Passkeys
57
+ */
58
+ export declare const listPasskeys: (options: ListPasskeyOptions) => Promise<FindAllPasskeys>;
59
+ /**
60
+ * Call the Passlock backend API to exchange a code for a Principal
61
+ *
62
+ * @param options
63
+ * @returns A promise resolving to an extended principal.
64
+ *
65
+ * @category Principal
66
+ */
67
+ export declare const exchangeCode: (options: ExchangeCodeOptions) => Promise<ExtendedPrincipal>;
68
+ /**
69
+ * Decode and verify a Passlock idToken.
70
+ * Note: This will make a network call to the passlock.dev/.well-known/jwks.json
71
+ * endpoint to fetch the relevant public key. The response will be cached, however
72
+ * bear in mind that for something like AWS lambda it will make the call on every
73
+ * cold start so might actually be slower than {@link exchangeCode}
74
+ *
75
+ * @param options
76
+ * @returns A promise resolving to the verified principal.
77
+ *
78
+ * @category Principal
79
+ */
80
+ export declare const verifyIdToken: (options: VerifyIdTokenOptions) => Promise<Principal>;
81
+ export type { BadRequest, DuplicateEmail, Forbidden, InvalidCode, InvalidEmail, InvalidTenancy, NotFound, PasskeyNotFound, Unauthorized, VerificationFailure, } from "./errors.js";
82
+ export { isBadRequest, isDuplicateEmail, isForbidden, isInvalidCode, isInvalidEmail, isInvalidTenancy, isNotFound, isPasskeyNotFound, isUnauthorized, isVerificationFailure, } from "./errors.js";
83
+ export type { AssignUserOptions, Credential, DeletedPasskey, DeletePasskeyOptions, FindAllPasskeys, GetPasskeyOptions, ListPasskeyOptions, Passkey, PasskeySummary, Platform, UpdatePasskeyOptions, } from "./passkey/passkey.js";
84
+ export { isDeletedPasskey, isPasskey, isPasskeySummary, } from "./passkey/passkey.js";
85
+ export type { ExchangeCodeOptions, VerifyIdTokenOptions, } from "./principal/principal.js";
86
+ export type { CredentialDeviceType, Transports, } from "./schemas/passkey.js";
87
+ export type { ExtendedPrincipal, Principal } from "./schemas/principal.js";
88
+ export { isExtendedPrincipal, isPrincipal } from "./schemas/principal.js";
89
+ export type { AuthenticatedOptions, PasslockOptions, } from "./shared.js";
5
90
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,OAAO,EACP,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAQ7B,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,0BAA0B,CAAA;AAKjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA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B,SAAS,EACT,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACV,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EACV,oBAAoB,EACpB,UAAU,GACX,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzE,YAAY,EACV,oBAAoB,EACpB,eAAe,GAChB,MAAM,aAAa,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,85 @@
1
- export * from "./passkey/index.js";
2
- export * from "./principal/index.js";
3
- export * from "./schemas/index.js";
4
- export * from "./shared.js";
1
+ /**
2
+ * Unsafe functions that could potentially throw errors.
3
+ *
4
+ * @categoryDescription Passkeys
5
+ * Functions and related types for managing passkeys
6
+ *
7
+ * @showCategories
8
+ *
9
+ * @module unsafe
10
+ */
11
+ import { FetchHttpClient } from "@effect/platform";
12
+ import { Effect, pipe } from "effect";
13
+ import { assignUser as assignUserE, deletePasskey as deletePasskeyE, getPasskey as getPasskeyE, listPasskeys as listPasskeysE, updatePasskey as updatePasskeyE, } from "./passkey/passkey.js";
14
+ import { exchangeCode as exchangeCodeE, verifyIdToken as verifyIdTokenE, } from "./principal/principal.js";
15
+ /**
16
+ * Call the Passlock backend API to assign a userId to an authenticator
17
+ *
18
+ * @param request
19
+ * @returns A promise resolving to the updated passkey.
20
+ * @throws {@link NotFound} if passkey does not exist
21
+ * @throws {@link Forbidden} if the Tenancy ID or API key is invalid
22
+ *
23
+ * @category Passkeys
24
+ */
25
+ export const assignUser = (request) => pipe(assignUserE(request), Effect.runPromise);
26
+ /**
27
+ * Call the Passlock backend API to update passkey properties
28
+ *
29
+ * @param request
30
+ * @returns A promise resolving to the updated passkey.
31
+ *
32
+ * @category Passkeys
33
+ */
34
+ export const updatePasskey = (request) => pipe(updatePasskeyE(request), Effect.runPromise);
35
+ /**
36
+ * Call the Passlock backend API to delete an authenticator
37
+ *
38
+ * @param options
39
+ * @returns A promise resolving to the deleted passkey payload.
40
+ *
41
+ * @category Passkeys
42
+ */
43
+ export const deletePasskey = (options) => pipe(deletePasskeyE(options), Effect.runPromise);
44
+ /**
45
+ * Call the Passlock backend API to fetch an authenticator
46
+ * @param options
47
+ * @returns A promise resolving to the passkey.
48
+ */
49
+ export const getPasskey = (options) => pipe(getPasskeyE(options), Effect.runPromise);
50
+ /**
51
+ * List passkeys for the given tenancy. Note this could return a cursor,
52
+ * in which case the function should be called again with the given cursor.
53
+ *
54
+ * @param options
55
+ * @returns A promise resolving to a page of passkey summaries.
56
+ *
57
+ * @category Passkeys
58
+ */
59
+ export const listPasskeys = (options) => pipe(listPasskeysE(options), Effect.runPromise);
60
+ /**
61
+ * Call the Passlock backend API to exchange a code for a Principal
62
+ *
63
+ * @param options
64
+ * @returns A promise resolving to an extended principal.
65
+ *
66
+ * @category Principal
67
+ */
68
+ export const exchangeCode = (options) => pipe(exchangeCodeE(options), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
69
+ /**
70
+ * Decode and verify a Passlock idToken.
71
+ * Note: This will make a network call to the passlock.dev/.well-known/jwks.json
72
+ * endpoint to fetch the relevant public key. The response will be cached, however
73
+ * bear in mind that for something like AWS lambda it will make the call on every
74
+ * cold start so might actually be slower than {@link exchangeCode}
75
+ *
76
+ * @param options
77
+ * @returns A promise resolving to the verified principal.
78
+ *
79
+ * @category Principal
80
+ */
81
+ export const verifyIdToken = (options) => pipe(verifyIdTokenE(options), Effect.provide(FetchHttpClient.layer), Effect.runPromise);
82
+ export { isBadRequest, isDuplicateEmail, isForbidden, isInvalidCode, isInvalidEmail, isInvalidTenancy, isNotFound, isPasskeyNotFound, isUnauthorized, isVerificationFailure, } from "./errors.js";
83
+ export { isDeletedPasskey, isPasskey, isPasskeySummary, } from "./passkey/passkey.js";
84
+ export { isExtendedPrincipal, isPrincipal } from "./schemas/principal.js";
5
85
  //# 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":"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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAWrC,OAAO,EACL,UAAU,IAAI,WAAW,EACzB,aAAa,IAAI,cAAc,EAC/B,UAAU,IAAI,WAAW,EACzB,YAAY,IAAI,aAAa,EAC7B,aAAa,IAAI,cAAc,GAChC,MAAM,sBAAsB,CAAA;AAK7B,OAAO,EACL,YAAY,IAAI,aAAa,EAC7B,aAAa,IAAI,cAAc,GAChC,MAAM,0BAA0B,CAAA;AAGjC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAA0B,EAAoB,EAAE,CACzE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAA6B,EACX,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAEvE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAA6B,EACJ,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAA0B,EAAoB,EAAE,CACzE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE/C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAA2B,EACD,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAA4B,EACA,EAAE,CAC9B,IAAI,CACF,aAAa,CAAC,OAAO,CAAC,EACtB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EACrC,MAAM,CAAC,UAAU,CAClB,CAAA;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAA6B,EACT,EAAE,CACtB,IAAI,CACF,cAAc,CAAC,OAAO,CAAC,EACvB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EACrC,MAAM,CAAC,UAAU,CAClB,CAAA;AAgBH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAA;AAcpB,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,gBAAgB,GACjB,MAAM,sBAAsB,CAAA;AAU7B,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA","sourcesContent":["/**\n * Unsafe functions that could potentially throw errors.\n *\n * @categoryDescription Passkeys\n * Functions and related types for managing passkeys\n *\n * @showCategories\n *\n * @module unsafe\n */\n\nimport { FetchHttpClient } from \"@effect/platform\"\nimport { Effect, pipe } from \"effect\"\nimport type {\n AssignUserOptions,\n DeletedPasskey,\n DeletePasskeyOptions,\n FindAllPasskeys,\n GetPasskeyOptions,\n ListPasskeyOptions,\n Passkey,\n UpdatePasskeyOptions,\n} from \"./passkey/passkey.js\"\nimport {\n assignUser as assignUserE,\n deletePasskey as deletePasskeyE,\n getPasskey as getPasskeyE,\n listPasskeys as listPasskeysE,\n updatePasskey as updatePasskeyE,\n} from \"./passkey/passkey.js\"\nimport type {\n ExchangeCodeOptions,\n VerifyIdTokenOptions,\n} from \"./principal/principal.js\"\nimport {\n exchangeCode as exchangeCodeE,\n verifyIdToken as verifyIdTokenE,\n} from \"./principal/principal.js\"\nimport type { ExtendedPrincipal, Principal } from \"./schemas/principal.js\"\n\n/**\n * Call the Passlock backend API to assign a userId to an authenticator\n *\n * @param request\n * @returns A promise resolving to the updated passkey.\n * @throws {@link NotFound} if passkey does not exist\n * @throws {@link Forbidden} if the Tenancy ID or API key is invalid\n *\n * @category Passkeys\n */\nexport const assignUser = (request: AssignUserOptions): Promise<Passkey> =>\n pipe(assignUserE(request), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to update passkey properties\n *\n * @param request\n * @returns A promise resolving to the updated passkey.\n *\n * @category Passkeys\n */\nexport const updatePasskey = (\n request: UpdatePasskeyOptions\n): Promise<Passkey> => pipe(updatePasskeyE(request), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to delete an authenticator\n *\n * @param options\n * @returns A promise resolving to the deleted passkey payload.\n *\n * @category Passkeys\n */\nexport const deletePasskey = (\n options: DeletePasskeyOptions\n): Promise<DeletedPasskey> => pipe(deletePasskeyE(options), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to fetch an authenticator\n * @param options\n * @returns A promise resolving to the passkey.\n */\nexport const getPasskey = (options: GetPasskeyOptions): Promise<Passkey> =>\n pipe(getPasskeyE(options), Effect.runPromise)\n\n/**\n * List passkeys for the given tenancy. Note this could return a cursor,\n * in which case the function should be called again with the given cursor.\n *\n * @param options\n * @returns A promise resolving to a page of passkey summaries.\n *\n * @category Passkeys\n */\nexport const listPasskeys = (\n options: ListPasskeyOptions\n): Promise<FindAllPasskeys> => pipe(listPasskeysE(options), Effect.runPromise)\n\n/**\n * Call the Passlock backend API to exchange a code for a Principal\n *\n * @param options\n * @returns A promise resolving to an extended principal.\n *\n * @category Principal\n */\nexport const exchangeCode = (\n options: ExchangeCodeOptions\n): Promise<ExtendedPrincipal> =>\n pipe(\n exchangeCodeE(options),\n Effect.provide(FetchHttpClient.layer),\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 *\n * @param options\n * @returns A promise resolving to the verified principal.\n *\n * @category Principal\n */\nexport const verifyIdToken = (\n options: VerifyIdTokenOptions\n): Promise<Principal> =>\n pipe(\n verifyIdTokenE(options),\n Effect.provide(FetchHttpClient.layer),\n Effect.runPromise\n )\n\n/* Re-exports */\n\nexport type {\n BadRequest,\n DuplicateEmail,\n Forbidden,\n InvalidCode,\n InvalidEmail,\n InvalidTenancy,\n NotFound,\n PasskeyNotFound,\n Unauthorized,\n VerificationFailure,\n} from \"./errors.js\"\nexport {\n isBadRequest,\n isDuplicateEmail,\n isForbidden,\n isInvalidCode,\n isInvalidEmail,\n isInvalidTenancy,\n isNotFound,\n isPasskeyNotFound,\n isUnauthorized,\n isVerificationFailure,\n} from \"./errors.js\"\nexport type {\n AssignUserOptions,\n Credential,\n DeletedPasskey,\n DeletePasskeyOptions,\n FindAllPasskeys,\n GetPasskeyOptions,\n ListPasskeyOptions,\n Passkey,\n PasskeySummary,\n Platform,\n UpdatePasskeyOptions,\n} from \"./passkey/passkey.js\"\nexport {\n isDeletedPasskey,\n isPasskey,\n isPasskeySummary,\n} from \"./passkey/passkey.js\"\nexport type {\n ExchangeCodeOptions,\n VerifyIdTokenOptions,\n} from \"./principal/principal.js\"\nexport type {\n CredentialDeviceType,\n Transports,\n} from \"./schemas/passkey.js\"\nexport type { ExtendedPrincipal, Principal } from \"./schemas/principal.js\"\nexport { isExtendedPrincipal, isPrincipal } from \"./schemas/principal.js\"\nexport type {\n AuthenticatedOptions,\n PasslockOptions,\n} from \"./shared.js\"\n"]}
@@ -0,0 +1,116 @@
1
+ import { HttpClient } from "@effect/platform";
2
+ import { Effect, type Layer, Stream } from "effect";
3
+ import { Forbidden, NotFound } from "../schemas/index.js";
4
+ import { type CredentialDeviceType, type Transports } from "../schemas/passkey.js";
5
+ import type { AuthenticatedOptions } from "../shared.js";
6
+ /**
7
+ * WebAuthn specific passkey data
8
+ */
9
+ export type Credential = {
10
+ id: string;
11
+ userId: string;
12
+ username: string;
13
+ aaguid: string;
14
+ backedUp: boolean;
15
+ counter: number;
16
+ deviceType: CredentialDeviceType;
17
+ transports: ReadonlyArray<Transports>;
18
+ publicKey: Uint8Array<ArrayBufferLike>;
19
+ };
20
+ /**
21
+ * Passkeys are usually synced across devices **but only within
22
+ * a specific platform/ecosystem** e.g. a passkey created on Apple
23
+ * devices would typically be synced across devices sharing the same
24
+ * iCloud ID.
25
+ *
26
+ * However, if the user also wants to sign in from their Windows
27
+ * or Android/Chrome devices they will need an additional passkey.
28
+ * Therefore when listing the passkeys registered to a user's account
29
+ * it's a good idea to tell them which platform the passkeys relate to.
30
+ *
31
+ * We've also included links to icons (SVG) so you can give your users
32
+ * a quick visual indication.
33
+ */
34
+ export type Platform = {
35
+ name?: string | undefined;
36
+ icon?: string | undefined;
37
+ };
38
+ /**
39
+ * The server-side component of a passkey
40
+ *
41
+ * @category Passkeys
42
+ */
43
+ export type Passkey = {
44
+ _tag: "Passkey";
45
+ /**
46
+ * Not to be confused with the credential.id
47
+ */
48
+ id: string;
49
+ /**
50
+ * Not to be confused with the credential.userId
51
+ */
52
+ userId?: string | undefined;
53
+ enabled: boolean;
54
+ credential: Credential;
55
+ platform?: Platform | undefined;
56
+ lastUsed?: number | undefined;
57
+ createdAt: number;
58
+ updatedAt: number;
59
+ };
60
+ export declare const isPasskey: (payload: unknown) => payload is Passkey;
61
+ export type PasskeySummary = {
62
+ readonly _tag: "PasskeySummary";
63
+ readonly id: string;
64
+ readonly userId: string;
65
+ readonly enabled: boolean;
66
+ readonly credential: {
67
+ readonly id: string;
68
+ readonly userId: string;
69
+ };
70
+ readonly lastUsed?: number | undefined;
71
+ readonly createdAt: number;
72
+ };
73
+ export declare const isPasskeySummary: (payload: unknown) => payload is PasskeySummary;
74
+ export type FindAllPasskeys = {
75
+ readonly _tag: "FindAllPasskeys";
76
+ readonly cursor: string | null;
77
+ readonly records: ReadonlyArray<PasskeySummary>;
78
+ };
79
+ export type DeletedPasskey = {
80
+ readonly _tag: "DeletedPasskey";
81
+ readonly id: string;
82
+ readonly credentialId: string;
83
+ readonly rpId: string;
84
+ };
85
+ export declare const isDeletedPasskey: (payload: unknown) => payload is DeletedPasskey;
86
+ export interface GetPasskeyOptions extends AuthenticatedOptions {
87
+ passkeyId: string;
88
+ }
89
+ export declare const getPasskey: (options: GetPasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
90
+ export interface DeletePasskeyOptions extends AuthenticatedOptions {
91
+ passkeyId: string;
92
+ }
93
+ export declare const deletePasskey: (options: DeletePasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<DeletedPasskey, NotFound | Forbidden>;
94
+ /**
95
+ * @category Passkeys
96
+ */
97
+ export interface AssignUserOptions extends AuthenticatedOptions {
98
+ passkeyId: string;
99
+ /**
100
+ * Custom User ID to align with your own systems
101
+ */
102
+ userId: string;
103
+ }
104
+ export declare const assignUser: (options: AssignUserOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
105
+ export interface UpdatePasskeyOptions extends AuthenticatedOptions {
106
+ passkeyId: string;
107
+ userId?: string;
108
+ username?: string;
109
+ }
110
+ export declare const updatePasskey: (options: UpdatePasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<Passkey, NotFound | Forbidden>;
111
+ export declare const listPasskeysStream: (options: AuthenticatedOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Stream.Stream<PasskeySummary, Forbidden>;
112
+ export interface ListPasskeyOptions extends AuthenticatedOptions {
113
+ cursor?: string;
114
+ }
115
+ export declare const listPasskeys: (options: ListPasskeyOptions, httpClient?: Layer.Layer<HttpClient.HttpClient>) => Effect.Effect<FindAllPasskeys, Forbidden>;
116
+ //# sourceMappingURL=passkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkey.d.ts","sourceRoot":"","sources":["../../src/passkey/passkey.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAGX,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAEL,MAAM,EACN,KAAK,KAAK,EAKV,MAAM,EACP,MAAM,QAAQ,CAAA;AAEf,OAAO,EAAyB,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EACL,KAAK,oBAAoB,EAIzB,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAExD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,oBAAoB,CAAA;IAChC,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;IACrC,SAAS,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;CACvC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAA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CAAA;AAEH,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IAChE,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,aAAa,GACxB,SAAS,oBAAoB,EAC7B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAwC3C,CAAA;AAIH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,oBAAoB,EAC7B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAWvC,CAAA;AAEH,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,YAAY,GACvB,SAAS,kBAAkB,EAC3B,aAAY,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAyB,KACrE,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAmCxC,CAAA"}
@@ -1,18 +1,20 @@
1
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* () {
2
+ import { Chunk, Effect, Match, Option, pipe, Schema, Stream, } from "effect";
3
+ import { FindAllPasskeysSchema, Forbidden, NotFound } from "../schemas/index.js";
4
+ import { DeletedPasskeySchema, PasskeySchema, PasskeySummarySchema, } from "../schemas/passkey.js";
5
+ export const isPasskey = (payload) => Schema.is(PasskeySchema)(payload);
6
+ export const isPasskeySummary = (payload) => Schema.is(PasskeySummarySchema)(payload);
7
+ export const isDeletedPasskey = (payload) => Schema.is(DeletedPasskeySchema)(payload);
8
+ export const getPasskey = (options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
7
9
  const client = yield* HttpClient.HttpClient;
8
10
  const baseUrl = options.endpoint ?? "https://api.passlock.dev";
9
- const { tenancyId } = options;
10
- const url = new URL(`/${tenancyId}/passkeys/${authenticatorId}`, baseUrl);
11
+ const { tenancyId, passkeyId } = options;
12
+ const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
11
13
  const response = yield* HttpClientRequest.get(url, {
12
14
  headers: { Authorization: `Bearer ${options.apiKey}` },
13
15
  }).pipe(client.execute);
14
16
  const encoded = yield* HttpClientResponse.matchStatus(response, {
15
- "2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
17
+ "2xx": () => HttpClientResponse.schemaBodyJson(PasskeySchema)(response),
16
18
  orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
17
19
  });
18
20
  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);
@@ -21,16 +23,16 @@ export const getPasskey = (authenticatorId, options, httpClient = FetchHttpClien
21
23
  RequestError: (err) => Effect.die(err),
22
24
  ResponseError: (err) => Effect.die(err),
23
25
  }), Effect.provide(httpClient));
24
- export const deletePasskey = (passkeyId, request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
26
+ export const deletePasskey = (options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
25
27
  const client = yield* HttpClient.HttpClient;
26
- const baseUrl = request.endpoint ?? "https://api.passlock.dev";
27
- const { tenancyId } = request;
28
+ const baseUrl = options.endpoint ?? "https://api.passlock.dev";
29
+ const { tenancyId, passkeyId } = options;
28
30
  const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
29
31
  const response = yield* HttpClientRequest.del(url, {
30
- headers: { Authorization: `Bearer ${request.apiKey}` },
32
+ headers: { Authorization: `Bearer ${options.apiKey}` },
31
33
  }).pipe(client.execute);
32
34
  const encoded = yield* HttpClientResponse.matchStatus(response, {
33
- "2xx": () => HttpClientResponse.schemaBodyJson(DeletedPasskey)(response),
35
+ "2xx": () => HttpClientResponse.schemaBodyJson(DeletedPasskeySchema)(response),
34
36
  orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(Forbidden, NotFound))(response),
35
37
  });
36
38
  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);
@@ -39,17 +41,38 @@ export const deletePasskey = (passkeyId, request, httpClient = FetchHttpClient.l
39
41
  RequestError: (err) => Effect.die(err),
40
42
  ResponseError: (err) => Effect.die(err),
41
43
  }), Effect.provide(httpClient));
42
- export const assignUser = (request, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
44
+ // TODO reuse updatePasskey
45
+ export const assignUser = (options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
43
46
  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 baseUrl = options.endpoint ?? "https://api.passlock.dev";
48
+ const { userId, passkeyId } = options;
49
+ const { tenancyId } = options;
47
50
  const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
48
51
  const response = yield* HttpClientRequest.patch(url, {
49
- headers: { Authorization: `Bearer ${request.apiKey}` },
52
+ headers: { Authorization: `Bearer ${options.apiKey}` },
50
53
  }).pipe(HttpClientRequest.bodyJson({ userId }), Effect.flatMap(client.execute));
51
54
  const encoded = yield* HttpClientResponse.matchStatus(response, {
52
- "2xx": () => HttpClientResponse.schemaBodyJson(Passkey)(response),
55
+ "2xx": () => HttpClientResponse.schemaBodyJson(PasskeySchema)(response),
56
+ orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),
57
+ });
58
+ 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);
59
+ }), Effect.catchTags({
60
+ HttpBodyError: (err) => Effect.die(err),
61
+ ParseError: (err) => Effect.die(err),
62
+ RequestError: (err) => Effect.die(err),
63
+ ResponseError: (err) => Effect.die(err),
64
+ }), Effect.provide(httpClient));
65
+ export const updatePasskey = (options, httpClient = FetchHttpClient.layer) => pipe(Effect.gen(function* () {
66
+ const client = yield* HttpClient.HttpClient;
67
+ const baseUrl = options.endpoint ?? "https://api.passlock.dev";
68
+ const { userId, passkeyId, username } = options;
69
+ const { tenancyId } = options;
70
+ const url = new URL(`/${tenancyId}/passkeys/${passkeyId}`, baseUrl);
71
+ const response = yield* HttpClientRequest.patch(url, {
72
+ headers: { Authorization: `Bearer ${options.apiKey}` },
73
+ }).pipe(HttpClientRequest.bodyJson({ userId, username }), Effect.flatMap(client.execute));
74
+ const encoded = yield* HttpClientResponse.matchStatus(response, {
75
+ "2xx": () => HttpClientResponse.schemaBodyJson(PasskeySchema)(response),
53
76
  orElse: () => HttpClientResponse.schemaBodyJson(Schema.Union(NotFound, Forbidden))(response),
54
77
  });
55
78
  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);
@@ -59,6 +82,7 @@ export const assignUser = (request, httpClient = FetchHttpClient.layer) => pipe(
59
82
  RequestError: (err) => Effect.die(err),
60
83
  ResponseError: (err) => Effect.die(err),
61
84
  }), Effect.provide(httpClient));
85
+ /* List Passkeys */
62
86
  export const listPasskeysStream = (options, httpClient = FetchHttpClient.layer) => pipe(Stream.paginateChunkEffect(null, (cursor) => pipe(listPasskeys(cursor ? { ...options, cursor } : options, httpClient), Effect.map((result) => [
63
87
  Chunk.fromIterable(result.records),
64
88
  Option.fromNullable(result.cursor),
@@ -75,7 +99,7 @@ export const listPasskeys = (options, httpClient = FetchHttpClient.layer) => pip
75
99
  headers: { Authorization: `Bearer ${options.apiKey}` },
76
100
  }).pipe(client.execute);
77
101
  const encoded = yield* HttpClientResponse.matchStatus(response, {
78
- "2xx": () => HttpClientResponse.schemaBodyJson(FindAllPasskeys)(response),
102
+ "2xx": () => HttpClientResponse.schemaBodyJson(FindAllPasskeysSchema)(response),
79
103
  orElse: () => HttpClientResponse.schemaBodyJson(Forbidden)(response),
80
104
  });
81
105
  return yield* pipe(Match.value(encoded), Match.tag("FindAllPasskeys", (data) => Effect.succeed(data)), Match.tag("@error/Forbidden", (err) => Effect.fail(err)), Match.exhaustive);
@@ -84,4 +108,4 @@ export const listPasskeys = (options, httpClient = FetchHttpClient.layer) => pip
84
108
  RequestError: (err) => Effect.die(err),
85
109
  ResponseError: (err) => Effect.die(err),
86
110
  }), Effect.provide(httpClient));
87
- //# sourceMappingURL=effects.js.map
111
+ //# sourceMappingURL=passkey.js.map