@passlock/client 0.9.30 → 2.0.0-beta.1

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 (180) hide show
  1. package/README.md +14 -86
  2. package/README.template.md +16 -88
  3. package/dist/index.d.ts +4 -206
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +2 -158
  6. package/dist/index.js.map +1 -1
  7. package/dist/logger/index.d.ts +24 -0
  8. package/dist/logger/index.d.ts.map +1 -0
  9. package/dist/logger/index.js +47 -0
  10. package/dist/logger/index.js.map +1 -0
  11. package/dist/network.d.ts +39 -0
  12. package/dist/network.d.ts.map +1 -0
  13. package/dist/network.js +83 -0
  14. package/dist/network.js.map +1 -0
  15. package/dist/passkey/authentication/index.d.ts +21 -0
  16. package/dist/passkey/authentication/index.d.ts.map +1 -0
  17. package/dist/passkey/authentication/index.js +22 -0
  18. package/dist/passkey/authentication/index.js.map +1 -0
  19. package/dist/passkey/authentication/micro.d.ts +71 -0
  20. package/dist/passkey/authentication/micro.d.ts.map +1 -0
  21. package/dist/passkey/authentication/micro.js +107 -0
  22. package/dist/passkey/authentication/micro.js.map +1 -0
  23. package/dist/passkey/index.d.ts +7 -0
  24. package/dist/passkey/index.d.ts.map +1 -0
  25. package/dist/passkey/index.js +5 -0
  26. package/dist/passkey/index.js.map +1 -0
  27. package/dist/passkey/registration/index.d.ts +19 -0
  28. package/dist/passkey/registration/index.d.ts.map +1 -0
  29. package/dist/passkey/registration/index.js +20 -0
  30. package/dist/passkey/registration/index.js.map +1 -0
  31. package/dist/passkey/registration/micro.d.ts +101 -0
  32. package/dist/passkey/registration/micro.d.ts.map +1 -0
  33. package/dist/passkey/registration/micro.js +126 -0
  34. package/dist/passkey/registration/micro.js.map +1 -0
  35. package/dist/passkey/shared.d.ts +24 -0
  36. package/dist/passkey/shared.d.ts.map +1 -0
  37. package/dist/passkey/shared.js +10 -0
  38. package/dist/passkey/shared.js.map +1 -0
  39. package/dist/passkey/support.d.ts +3 -0
  40. package/dist/passkey/support.d.ts.map +1 -0
  41. package/dist/passkey/support.js +4 -0
  42. package/dist/passkey/support.js.map +1 -0
  43. package/dist/passkey/types.d.ts +26 -0
  44. package/dist/passkey/types.d.ts.map +1 -0
  45. package/dist/passkey/types.js +2 -0
  46. package/dist/passkey/types.js.map +1 -0
  47. package/dist/promise.d.ts +15 -0
  48. package/dist/promise.d.ts.map +1 -0
  49. package/dist/promise.js +46 -0
  50. package/dist/promise.js.map +1 -0
  51. package/dist/shared.d.ts +15 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +2 -0
  54. package/dist/shared.js.map +1 -0
  55. package/dist/tenancy.d.ts +8 -0
  56. package/dist/tenancy.d.ts.map +1 -0
  57. package/dist/tenancy.js +4 -0
  58. package/dist/tenancy.js.map +1 -0
  59. package/package.json +52 -58
  60. package/LICENSE +0 -21
  61. package/dist/authentication/authenticate.d.ts +0 -24
  62. package/dist/authentication/authenticate.fixture.d.ts +0 -52
  63. package/dist/authentication/authenticate.fixture.js +0 -50
  64. package/dist/authentication/authenticate.fixture.js.map +0 -1
  65. package/dist/authentication/authenticate.js +0 -73
  66. package/dist/authentication/authenticate.js.map +0 -1
  67. package/dist/capabilities/capabilities.d.ts +0 -19
  68. package/dist/capabilities/capabilities.js +0 -37
  69. package/dist/capabilities/capabilities.js.map +0 -1
  70. package/dist/connection/connection.d.ts +0 -15
  71. package/dist/connection/connection.fixture.d.ts +0 -10
  72. package/dist/connection/connection.fixture.js +0 -13
  73. package/dist/connection/connection.fixture.js.map +0 -1
  74. package/dist/connection/connection.js +0 -23
  75. package/dist/connection/connection.js.map +0 -1
  76. package/dist/effect.d.ts +0 -26
  77. package/dist/effect.js +0 -78
  78. package/dist/effect.js.map +0 -1
  79. package/dist/email/email.d.ts +0 -70
  80. package/dist/email/email.fixture.d.ts +0 -46
  81. package/dist/email/email.fixture.js +0 -25
  82. package/dist/email/email.fixture.js.map +0 -1
  83. package/dist/email/email.js +0 -83
  84. package/dist/email/email.js.map +0 -1
  85. package/dist/event/event.d.ts +0 -8
  86. package/dist/event/event.js +0 -23
  87. package/dist/event/event.js.map +0 -1
  88. package/dist/logging/eventLogger.d.ts +0 -17
  89. package/dist/logging/eventLogger.js +0 -38
  90. package/dist/logging/eventLogger.js.map +0 -1
  91. package/dist/registration/register.d.ts +0 -27
  92. package/dist/registration/register.fixture.d.ts +0 -53
  93. package/dist/registration/register.fixture.js +0 -66
  94. package/dist/registration/register.fixture.js.map +0 -1
  95. package/dist/registration/register.js +0 -78
  96. package/dist/registration/register.js.map +0 -1
  97. package/dist/rpc/authentication.d.ts +0 -8
  98. package/dist/rpc/authentication.js +0 -16
  99. package/dist/rpc/authentication.js.map +0 -1
  100. package/dist/rpc/client.d.ts +0 -30
  101. package/dist/rpc/client.js +0 -101
  102. package/dist/rpc/client.js.map +0 -1
  103. package/dist/rpc/config.d.ts +0 -15
  104. package/dist/rpc/config.js +0 -6
  105. package/dist/rpc/config.js.map +0 -1
  106. package/dist/rpc/connection.d.ts +0 -8
  107. package/dist/rpc/connection.js +0 -15
  108. package/dist/rpc/connection.js.map +0 -1
  109. package/dist/rpc/registration.d.ts +0 -8
  110. package/dist/rpc/registration.js +0 -16
  111. package/dist/rpc/registration.js.map +0 -1
  112. package/dist/rpc/social.d.ts +0 -10
  113. package/dist/rpc/social.js +0 -18
  114. package/dist/rpc/social.js.map +0 -1
  115. package/dist/rpc/user.d.ts +0 -8
  116. package/dist/rpc/user.js +0 -19
  117. package/dist/rpc/user.js.map +0 -1
  118. package/dist/social/social.d.ts +0 -24
  119. package/dist/social/social.fixture.d.ts +0 -46
  120. package/dist/social/social.fixture.js +0 -31
  121. package/dist/social/social.fixture.js.map +0 -1
  122. package/dist/social/social.js +0 -39
  123. package/dist/social/social.js.map +0 -1
  124. package/dist/storage/storage.d.ts +0 -56
  125. package/dist/storage/storage.fixture.d.ts +0 -4
  126. package/dist/storage/storage.fixture.js +0 -10
  127. package/dist/storage/storage.fixture.js.map +0 -1
  128. package/dist/storage/storage.js +0 -111
  129. package/dist/storage/storage.js.map +0 -1
  130. package/dist/test/fixtures.d.ts +0 -15
  131. package/dist/test/fixtures.js +0 -56
  132. package/dist/test/fixtures.js.map +0 -1
  133. package/dist/tsconfig.tsbuildinfo +0 -1
  134. package/dist/user/user.d.ts +0 -25
  135. package/dist/user/user.fixture.d.ts +0 -12
  136. package/dist/user/user.fixture.js +0 -20
  137. package/dist/user/user.fixture.js.map +0 -1
  138. package/dist/user/user.js +0 -38
  139. package/dist/user/user.js.map +0 -1
  140. package/dist/version.d.ts +0 -1
  141. package/dist/version.js +0 -2
  142. package/dist/version.js.map +0 -1
  143. package/src/authentication/authenticate.fixture.ts +0 -73
  144. package/src/authentication/authenticate.test.ts +0 -249
  145. package/src/authentication/authenticate.ts +0 -149
  146. package/src/capabilities/capabilities.ts +0 -83
  147. package/src/connection/connection.fixture.ts +0 -20
  148. package/src/connection/connection.test.ts +0 -60
  149. package/src/connection/connection.ts +0 -51
  150. package/src/effect.ts +0 -280
  151. package/src/email/email.fixture.ts +0 -44
  152. package/src/email/email.test.ts +0 -186
  153. package/src/email/email.ts +0 -148
  154. package/src/event/event.node.test.ts +0 -21
  155. package/src/event/event.test.ts +0 -37
  156. package/src/event/event.ts +0 -25
  157. package/src/index.ts +0 -407
  158. package/src/logging/eventLogger.test.ts +0 -104
  159. package/src/logging/eventLogger.ts +0 -41
  160. package/src/registration/register.fixture.ts +0 -96
  161. package/src/registration/register.test.ts +0 -216
  162. package/src/registration/register.ts +0 -158
  163. package/src/rpc/authentication.ts +0 -43
  164. package/src/rpc/client.ts +0 -174
  165. package/src/rpc/config.ts +0 -18
  166. package/src/rpc/connection.ts +0 -30
  167. package/src/rpc/registration.ts +0 -41
  168. package/src/rpc/social.ts +0 -45
  169. package/src/rpc/user.ts +0 -57
  170. package/src/social/social.fixture.ts +0 -45
  171. package/src/social/social.test.ts +0 -179
  172. package/src/social/social.ts +0 -82
  173. package/src/storage/storage.fixture.ts +0 -16
  174. package/src/storage/storage.test.ts +0 -206
  175. package/src/storage/storage.ts +0 -168
  176. package/src/test/fixtures.ts +0 -70
  177. package/src/user/user.fixture.ts +0 -33
  178. package/src/user/user.test.ts +0 -84
  179. package/src/user/user.ts +0 -73
  180. package/src/version.ts +0 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ in README.template.md and outputs to README.md
8
8
  </a>
9
9
  </div>
10
10
 
11
- <h1 align="center">Passkeys, Social Login & More</h1>
11
+ <h1 align="center">Passkey Authentication for Typescript apps</h1>
12
12
 
13
13
  <div align="center">
14
14
  <picture align="center">
@@ -16,18 +16,17 @@ in README.template.md and outputs to README.md
16
16
  <img align="center" width=550 height=50 src="https://passlock-assets.b-cdn.net/images/client-repo-banner.svg" />
17
17
  </picture>
18
18
  <p align="center">
19
- Typescript library for next generation authentication. <br/>
20
- Passkeys, Apple login, Google one-tap and more..
19
+ Next generation passkey authentication for Astro, Svelte(kit), Angular and other frameworks.
21
20
  <br />
22
21
  <a href="https://passlock.dev"><strong>Project website »</strong></a>
23
22
  <br />
24
23
  <a href="https://github.com/passlock-dev/passlock">GitHub</a>
25
24
  ·
26
- <a href="https://d1rl0ue18b0151.cloudfront.net">Demo</a>
25
+ <a href="https://passlock.dev">Documentation</a>
27
26
  ·
28
- <a href="https://docs.passlock.dev">Documentation</a>
27
+ <a href="https://passlock.dev/getting-started/">Quick start</a>
29
28
  ·
30
- <a href="https://docs.passlock.dev/docs/tutorial/introduction">Tutorial</a>
29
+ <a href="https://passlock.dev/#demo">Demo</a>
31
30
  </p>
32
31
  </div>
33
32
 
@@ -35,96 +34,25 @@ in README.template.md and outputs to README.md
35
34
 
36
35
  ## Features
37
36
 
38
- Passkeys and the WebAuthn API are quite complex. I've taken an opinionated approach to simplify things for you. Following the 80/20 principle, I've tried to focus on the features most valuable to developers and users.
37
+ Passkeys and the WebAuthn API are quite complex. We've tried to simplify things for you, whilst still offering you the power and flexibility of the underlying APIs.
39
38
 
40
- 1. **🔐 Primary or secondary authentication** - 2FA or a complete replacement for passwords
39
+ 1. **💪 Powerful** - We expose the full WebAuthn/Passkey featureset including user verification, autofil, backup/sync and more
41
40
 
42
- 2. **🚀 Social login** - Supporting Apple & Google. GitHub coming soon..
41
+ 2. **🫆 Biometrics** - Passlock allows you to add biometric authentication to your webapps
43
42
 
44
- 3. **☝🏻 Biometrics** - Frictionless facial or fingerprint recognition for your webapps
43
+ 3. **👌 Headless components** - Giving you 100% control over the UI
45
44
 
46
- 4. **🖥️ Management console** - Suspend users, disable or revoke passkeys and more..
45
+ 4. **🧰 Framework agnostic** - Passlock works with all major frontend & backend frameworks
47
46
 
48
- 5. **🕵️ Audit trail** - View a full audit trail for each user
47
+ 5. **👩‍💻 Dev console** - Something not working? check the unified client/server dev console
49
48
 
50
- 6. **🖥️ Dev console** - Something not working? check the web console for details
49
+ 6. **🖥️ Management console** - Suspend or revoke access for users, passkeys and more..
51
50
 
52
- 7. **👌 Headless components** - You have 100% control over the UI
53
-
54
- ## Screenshots
55
-
56
- ![SvelteKit template using this library](https://passlock-assets.b-cdn.net/images/preline.dark.png)
57
- <p align="center">Demo app using this library for passkey and social login</p>
58
-
59
- ![Passlock user profile](https://passlock-assets.b-cdn.net/images/console.png)
60
- <p align="center">Viewing a user's authentication activity on their profile page</p>
61
-
62
- ## Usage
63
-
64
- ### Register a passkey
65
-
66
- ```typescript
67
- import { Passlock, PasslockError } from '@passlock/client'
68
-
69
- // you can find these details in the settings area of your Passlock console
70
- const tenancyId = '...'
71
- const clientId = '...'
72
-
73
- const passlock = new Passlock({ tenancyId, clientId })
74
-
75
- // to register a new passkey, call registerPasskey(). We're using placeholders for
76
- // the user data. You should grab this from an HTML form, React store, Redux etc.
77
- const [email, givenName, familyName] = ["jdoe@gmail.com", "John", "Doe"]
78
-
79
- // Passlock doesn't throw but instead returns a union: result | error
80
- const result = await passlock.registerPasskey({ email, givenName, familyName })
81
-
82
- // ensure we're error free
83
- if (!PasslockError.isError(result)) {
84
- // send the token to your backend (json/fetch or hidden form field etc)
85
- console.log('Token: %s', result.token)
86
- }
87
- ```
88
-
89
- ### Authenticate using a passkey
90
-
91
- ```typescript
92
- import { Passlock, PasslockError } from '@passlock/client'
93
-
94
- const tenancyId = '...'
95
- const clientId = '...'
96
-
97
- const passlock = new Passlock({ tenancyId, clientId })
98
- const result = await passlock.authenticatePasskey()
99
-
100
- if (!PasslockError.isError(result)) {
101
- // send the token to your backend for verification
102
- console.log('Token: %s', result.token)
103
- }
104
- ```
105
-
106
- ### Backend verification
107
-
108
- Verify the token and obtain the passkey registration or authentication details. You can make a simple GET request to `https://api.passlock.dev/{tenancyId}/token/{token}` or use the [@passlock/node][node] library:
109
-
110
- ```typescript
111
- import { Passlock } from '@passlock/node'
112
-
113
- // API Keys can be found in your passlock console
114
- const passlock = new Passlock({ tenancyId, apiKey })
115
-
116
- // token comes from your frontend
117
- const principal = await passlock.fetchPrincipal({ token })
118
-
119
- // get the user id
120
- console.log(principal.user.id)
121
- ```
51
+ 7. **🕵️‍♂️ Audit trail** - View a full audit trail for each passkey and user
122
52
 
123
53
  ## More information
124
54
 
125
- Please see the [tutorial][tutorial] and [documentation][docs]
55
+ Please see the [tutorial](https://passlock.dev/getting-started/) and [documentation](https://passlock.dev)
126
56
 
127
57
  [contact]: https://passlock.dev/contact
128
- [tutorial]: https://docs.passlock.dev/docs/tutorial/introduction
129
- [docs]: https://docs.passlock.dev
130
58
  [node]: https://www.npmjs.com/package/@passlock/node
@@ -8,26 +8,25 @@ in README.template.md and outputs to README.md
8
8
  </a>
9
9
  </div>
10
10
 
11
- <h1 align="center">Passkeys, Social Login & More</h1>
11
+ <h1 align="center">Passkey Authentication for Typescript apps</h1>
12
12
 
13
13
  <div align="center">
14
14
  <picture align="center">
15
- <source srcset="#{ASSETS_CDN}#/images/client-repo-banner.dark.svg" media="(prefers-color-scheme: dark)" />
16
- <img align="center" width=550 height=50 src="#{ASSETS_CDN}#/images/client-repo-banner.svg" />
15
+ <source srcset="#{ASSETS}#/images/client-repo-banner.dark.svg" media="(prefers-color-scheme: dark)" />
16
+ <img align="center" width=550 height=50 src="#{ASSETS}#/images/client-repo-banner.svg" />
17
17
  </picture>
18
18
  <p align="center">
19
- Typescript library for next generation authentication. <br/>
20
- Passkeys, Apple login, Google one-tap and more..
19
+ Next generation passkey authentication for Astro, Svelte(kit), Angular and other frameworks.
21
20
  <br />
22
21
  <a href="#{PASSLOCK_SITE}#"><strong>Project website »</strong></a>
23
22
  <br />
24
23
  <a href="#{GITHUB_REPO}#">GitHub</a>
25
24
  ·
26
- <a href="#{PRELINE_DEMO_SITE}#">Demo</a>
27
- ·
28
25
  <a href="#{DOCS}#">Documentation</a>
29
26
  ·
30
- <a href="#{TUTORIAL}#">Tutorial</a>
27
+ <a href="#{TUTORIAL}#">Quick start</a>
28
+ ·
29
+ <a href="#{DEMO}#">Demo</a>
31
30
  </p>
32
31
  </div>
33
32
 
@@ -35,96 +34,25 @@ in README.template.md and outputs to README.md
35
34
 
36
35
  ## Features
37
36
 
38
- Passkeys and the WebAuthn API are quite complex. I've taken an opinionated approach to simplify things for you. Following the 80/20 principle, I've tried to focus on the features most valuable to developers and users.
39
-
40
- 1. **🔐 Primary or secondary authentication** - 2FA or a complete replacement for passwords
41
-
42
- 2. **🚀 Social login** - Supporting Apple & Google. GitHub coming soon..
43
-
44
- 3. **☝🏻 Biometrics** - Frictionless facial or fingerprint recognition for your webapps
45
-
46
- 4. **🖥️ Management console** - Suspend users, disable or revoke passkeys and more..
47
-
48
- 5. **🕵️ Audit trail** - View a full audit trail for each user
49
-
50
- 6. **🖥️ Dev console** - Something not working? check the web console for details
51
-
52
- 7. **👌 Headless components** - You have 100% control over the UI
53
-
54
- ## Screenshots
55
-
56
- ![SvelteKit template using this library](#{ASSETS_CDN}#/images/preline.dark.png)
57
- <p align="center">Demo app using this library for passkey and social login</p>
58
-
59
- ![Passlock user profile](#{ASSETS_CDN}#/images/console.png)
60
- <p align="center">Viewing a user's authentication activity on their profile page</p>
61
-
62
- ## Usage
63
-
64
- ### Register a passkey
65
-
66
- ```typescript
67
- import { Passlock, PasslockError } from '@passlock/client'
68
-
69
- // you can find these details in the settings area of your Passlock console
70
- const tenancyId = '...'
71
- const clientId = '...'
72
-
73
- const passlock = new Passlock({ tenancyId, clientId })
74
-
75
- // to register a new passkey, call registerPasskey(). We're using placeholders for
76
- // the user data. You should grab this from an HTML form, React store, Redux etc.
77
- const [email, givenName, familyName] = ["jdoe@gmail.com", "John", "Doe"]
78
-
79
- // Passlock doesn't throw but instead returns a union: result | error
80
- const result = await passlock.registerPasskey({ email, givenName, familyName })
81
-
82
- // ensure we're error free
83
- if (!PasslockError.isError(result)) {
84
- // send the token to your backend (json/fetch or hidden form field etc)
85
- console.log('Token: %s', result.token)
86
- }
87
- ```
88
-
89
- ### Authenticate using a passkey
90
-
91
- ```typescript
92
- import { Passlock, PasslockError } from '@passlock/client'
93
-
94
- const tenancyId = '...'
95
- const clientId = '...'
96
-
97
- const passlock = new Passlock({ tenancyId, clientId })
98
- const result = await passlock.authenticatePasskey()
37
+ Passkeys and the WebAuthn API are quite complex. We've tried to simplify things for you, whilst still offering you the power and flexibility of the underlying APIs.
99
38
 
100
- if (!PasslockError.isError(result)) {
101
- // send the token to your backend for verification
102
- console.log('Token: %s', result.token)
103
- }
104
- ```
39
+ 1. **💪 Powerful** - We expose the full WebAuthn/Passkey featureset including user verification, autofil, backup/sync and more
105
40
 
106
- ### Backend verification
41
+ 2. **🫆 Biometrics** - Passlock allows you to add biometric authentication to your webapps
107
42
 
108
- Verify the token and obtain the passkey registration or authentication details. You can make a simple GET request to `https://api.passlock.dev/{tenancyId}/token/{token}` or use the [@passlock/node][node] library:
43
+ 3. **👌 Headless components** - Giving you 100% control over the UI
109
44
 
110
- ```typescript
111
- import { Passlock } from '@passlock/node'
45
+ 4. **🧰 Framework agnostic** - Passlock works with all major frontend & backend frameworks
112
46
 
113
- // API Keys can be found in your passlock console
114
- const passlock = new Passlock({ tenancyId, apiKey })
47
+ 5. **👩‍💻 Dev console** - Something not working? check the unified client/server dev console
115
48
 
116
- // token comes from your frontend
117
- const principal = await passlock.fetchPrincipal({ token })
49
+ 6. **🖥️ Management console** - Suspend or revoke access for users, passkeys and more..
118
50
 
119
- // get the user id
120
- console.log(principal.user.id)
121
- ```
51
+ 7. **🕵️‍♂️ Audit trail** - View a full audit trail for each passkey and user
122
52
 
123
53
  ## More information
124
54
 
125
- Please see the [tutorial][tutorial] and [documentation][docs]
55
+ Please see the [tutorial](#{TUTORIAL}#) and [documentation](#{DOCS}#)
126
56
 
127
57
  [contact]: https://passlock.dev/contact
128
- [tutorial]: https://docs.passlock.dev/docs/tutorial/introduction
129
- [docs]: https://docs.passlock.dev
130
58
  [node]: https://www.npmjs.com/package/@passlock/node
package/dist/index.d.ts CHANGED
@@ -1,206 +1,4 @@
1
- import { ErrorCode } from '@passlock/shared/dist/error/error.js';
2
- import type { VerifyEmail } from '@passlock/shared/dist/schema/email.js';
3
- import type { UserVerification } from '@passlock/shared/dist/schema/passkey.js';
4
- import { type Principal, type UserPrincipal } from '@passlock/shared/dist/schema/principal.js';
5
- import type { VerifyRequest } from './email/email.js';
6
- import type { Provider } from './social/social.js';
7
- import { type AuthType, type StoredToken } from './storage/storage.js';
8
- import type { Email, ResendEmail } from './user/user.js';
9
- export type Options = {
10
- signal?: AbortSignal;
11
- };
12
- export type { VerifyEmail } from '@passlock/shared/dist/schema/email.js';
13
- export type { UserVerification } from '@passlock/shared/dist/schema/passkey.js';
14
- export type { Principal, UserPrincipal } from '@passlock/shared/dist/schema/principal.js';
15
- export type { VerifyRequest } from './email/email.js';
16
- export type { AuthType, StoredToken } from './storage/storage.js';
17
- export type { Email } from './user/user.js';
18
- export type PasslockProps = {
19
- tenancyId: string;
20
- clientId: string;
21
- endpoint?: string;
22
- };
23
- export type RegistrationRequest = {
24
- email: string;
25
- givenName?: string;
26
- familyName?: string;
27
- userVerification?: UserVerification;
28
- verifyEmail?: VerifyEmail;
29
- };
30
- export type AuthenticationRequest = {
31
- email?: string;
32
- userVerification?: UserVerification;
33
- };
34
- export type RegisterOidcReq = {
35
- provider: Provider;
36
- idToken: string;
37
- givenName?: string;
38
- familyName?: string;
39
- nonce: string;
40
- };
41
- export type AuthenticateOidcReq = {
42
- provider: Provider;
43
- idToken: string;
44
- nonce: string;
45
- };
46
- export { ErrorCode } from '@passlock/shared/dist/error/error.js';
47
- export declare class PasslockError extends Error {
48
- readonly code: ErrorCode;
49
- readonly detail: string | undefined;
50
- constructor(message: string, code: ErrorCode, detail?: string);
51
- static readonly isError: (error: unknown) => error is PasslockError;
52
- }
53
- export declare class PasslockUnsafe {
54
- private readonly runtime;
55
- constructor(props: PasslockProps);
56
- static isPrincipal: (value: unknown) => value is Principal;
57
- static isUserPrincipal: (value: unknown) => value is UserPrincipal;
58
- private readonly runPromise;
59
- preConnect: (options?: Options) => Promise<void>;
60
- isPasskeySupport: () => Promise<boolean>;
61
- isExistingUser: (email: Email, options?: Options) => Promise<boolean>;
62
- registerPasskey: (request: RegistrationRequest, options?: Options) => Promise<Principal>;
63
- authenticatePasskey: (request: AuthenticationRequest, options?: Options) => Promise<Principal>;
64
- registerOidc: (request: RegisterOidcReq, options?: Options) => Promise<{
65
- readonly email?: string;
66
- readonly givenName?: string;
67
- readonly familyName?: string;
68
- readonly emailVerified?: boolean;
69
- readonly user?: {
70
- readonly id: string;
71
- readonly email: string;
72
- readonly givenName: string;
73
- readonly familyName: string;
74
- readonly emailVerified: boolean;
75
- };
76
- readonly iss: string;
77
- readonly aud: string;
78
- readonly sub: string;
79
- readonly iat: Date;
80
- readonly nbf: Date;
81
- readonly exp: Date;
82
- readonly jti: string;
83
- readonly token: string;
84
- readonly userVerified: boolean;
85
- readonly authType: "email" | "apple" | "google" | "passkey";
86
- readonly authId: string;
87
- readonly authStatement: {
88
- readonly userVerified: boolean;
89
- readonly authType: "email" | "apple" | "google" | "passkey";
90
- readonly authTimestamp: Date;
91
- };
92
- readonly expireAt: Date;
93
- }>;
94
- authenticateOidc: (request: AuthenticateOidcReq, options?: Options) => Promise<{
95
- readonly email?: string;
96
- readonly givenName?: string;
97
- readonly familyName?: string;
98
- readonly emailVerified?: boolean;
99
- readonly user?: {
100
- readonly id: string;
101
- readonly email: string;
102
- readonly givenName: string;
103
- readonly familyName: string;
104
- readonly emailVerified: boolean;
105
- };
106
- readonly iss: string;
107
- readonly aud: string;
108
- readonly sub: string;
109
- readonly iat: Date;
110
- readonly nbf: Date;
111
- readonly exp: Date;
112
- readonly jti: string;
113
- readonly token: string;
114
- readonly userVerified: boolean;
115
- readonly authType: "email" | "apple" | "google" | "passkey";
116
- readonly authId: string;
117
- readonly authStatement: {
118
- readonly userVerified: boolean;
119
- readonly authType: "email" | "apple" | "google" | "passkey";
120
- readonly authTimestamp: Date;
121
- };
122
- readonly expireAt: Date;
123
- }>;
124
- verifyEmailCode: (request: VerifyRequest, options?: Options) => Promise<Principal>;
125
- resendVerificationEmail: (request: ResendEmail, options?: Options) => Promise<void>;
126
- verifyEmailLink: (options?: Options) => Promise<Principal>;
127
- getSessionToken: (authType: AuthType) => StoredToken | undefined;
128
- clearExpiredTokens: () => void;
129
- }
130
- export declare class Passlock {
131
- private readonly runtime;
132
- constructor(props: PasslockProps);
133
- static isPrincipal: (value: unknown) => value is Principal;
134
- static isUserPrincipal: (value: unknown) => value is UserPrincipal;
135
- private readonly runPromise;
136
- preConnect: (options?: Options) => Promise<boolean | PasslockError>;
137
- isPasskeySupport: () => Promise<boolean>;
138
- isExistingUser: (email: Email, options?: Options) => Promise<boolean | PasslockError>;
139
- registerPasskey: (request: RegistrationRequest, options?: Options) => Promise<Principal | PasslockError>;
140
- authenticatePasskey: (request?: AuthenticationRequest, options?: Options) => Promise<Principal | PasslockError>;
141
- registerOidc: (request: RegisterOidcReq, options?: Options) => Promise<{
142
- readonly email?: string;
143
- readonly givenName?: string;
144
- readonly familyName?: string;
145
- readonly emailVerified?: boolean;
146
- readonly user?: {
147
- readonly id: string;
148
- readonly email: string;
149
- readonly givenName: string;
150
- readonly familyName: string;
151
- readonly emailVerified: boolean;
152
- };
153
- readonly iss: string;
154
- readonly aud: string;
155
- readonly sub: string;
156
- readonly iat: Date;
157
- readonly nbf: Date;
158
- readonly exp: Date;
159
- readonly jti: string;
160
- readonly token: string;
161
- readonly userVerified: boolean;
162
- readonly authType: "email" | "apple" | "google" | "passkey";
163
- readonly authId: string;
164
- readonly authStatement: {
165
- readonly userVerified: boolean;
166
- readonly authType: "email" | "apple" | "google" | "passkey";
167
- readonly authTimestamp: Date;
168
- };
169
- readonly expireAt: Date;
170
- } | PasslockError>;
171
- authenticateOidc: (request: AuthenticateOidcReq, options?: Options) => Promise<{
172
- readonly email?: string;
173
- readonly givenName?: string;
174
- readonly familyName?: string;
175
- readonly emailVerified?: boolean;
176
- readonly user?: {
177
- readonly id: string;
178
- readonly email: string;
179
- readonly givenName: string;
180
- readonly familyName: string;
181
- readonly emailVerified: boolean;
182
- };
183
- readonly iss: string;
184
- readonly aud: string;
185
- readonly sub: string;
186
- readonly iat: Date;
187
- readonly nbf: Date;
188
- readonly exp: Date;
189
- readonly jti: string;
190
- readonly token: string;
191
- readonly userVerified: boolean;
192
- readonly authType: "email" | "apple" | "google" | "passkey";
193
- readonly authId: string;
194
- readonly authStatement: {
195
- readonly userVerified: boolean;
196
- readonly authType: "email" | "apple" | "google" | "passkey";
197
- readonly authTimestamp: Date;
198
- };
199
- readonly expireAt: Date;
200
- } | PasslockError>;
201
- verifyEmailCode: (request: VerifyRequest, options?: Options) => Promise<Principal | PasslockError>;
202
- verifyEmailLink: (options?: Options) => Promise<Principal | PasslockError>;
203
- resendVerificationEmail: (request: ResendEmail, options?: Options) => Promise<boolean | PasslockError>;
204
- getSessionToken: (authType: AuthType) => Promise<StoredToken | undefined>;
205
- clearExpiredTokens: () => void;
206
- }
1
+ export * from "./passkey/index";
2
+ export type { PasslockOptions } from "./shared";
3
+ export { UnexpectedError, isUnexpectedError } from "./network";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAEhC,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,159 +1,3 @@
1
- import { Effect as E, Layer as L, Layer, Option as O, Runtime, Scope, pipe } from 'effect';
2
- import { dual } from 'effect/Function';
3
- import { ErrorCode } from '@passlock/shared/dist/error/error.js';
4
- import { isPrincipal, isUserPrincipal, } from '@passlock/shared/dist/schema/principal.js';
5
- import { allRequirements, authenticateOidc, authenticatePasskey, clearExpiredTokens, getSessionToken, isExistingUser, isPasskeySupport, preConnect, registerOidc, registerPasskey, resendVerificationEmail, verifyEmailCode, verifyEmailLink, } from './effect.js';
6
- import { RpcConfig } from './rpc/config.js';
7
- import { BrowserStorage, StorageService, } from './storage/storage.js';
8
- import { PASSLOCK_CLIENT_VERSION } from './version.js';
9
- const nonEmpty = (text) => {
10
- const trimmed = text.trim();
11
- if (trimmed.length > 0)
12
- return O.some(trimmed);
13
- return O.none();
14
- };
15
- const toRpcRegistrationRequest = (request) => {
16
- return {
17
- email: request.email,
18
- givenName: pipe(O.fromNullable(request.givenName), O.flatMap(nonEmpty)),
19
- familyName: pipe(O.fromNullable(request.familyName), O.flatMap(nonEmpty)),
20
- userVerification: O.fromNullable(request.userVerification),
21
- verifyEmail: O.fromNullable(request.verifyEmail),
22
- };
23
- };
24
- const toRpcAuthenticationRequest = (request) => {
25
- return {
26
- email: O.fromNullable(request.email),
27
- userVerification: O.fromNullable(request.userVerification),
28
- };
29
- };
30
- const toRpcRegisterOidcReq = (request) => {
31
- return {
32
- provider: request.provider,
33
- idToken: request.idToken,
34
- givenName: pipe(O.fromNullable(request.givenName), O.flatMap(nonEmpty)),
35
- familyName: pipe(O.fromNullable(request.familyName), O.flatMap(nonEmpty)),
36
- nonce: request.nonce,
37
- };
38
- };
39
- const toRpcAuthenticateOidcReq = (request) => {
40
- return {
41
- provider: request.provider,
42
- idToken: request.idToken,
43
- nonce: request.nonce,
44
- };
45
- };
46
- export { ErrorCode } from '@passlock/shared/dist/error/error.js';
47
- export class PasslockError extends Error {
48
- code;
49
- detail;
50
- constructor(message, code, detail) {
51
- super(message);
52
- this.code = code;
53
- this.detail = detail;
54
- }
55
- static isError = (error) => {
56
- return typeof error === 'object' && error !== null && error instanceof PasslockError;
57
- };
58
- }
59
- const hasMessage = (defect) => {
60
- return (typeof defect === 'object' &&
61
- defect !== null &&
62
- 'message' in defect &&
63
- typeof defect['message'] === 'string');
64
- };
65
- const transformErrors = (effect) => {
66
- const withErrorHandling = E.catchTags(effect, {
67
- NotSupported: e => E.succeed(new PasslockError(e.message, ErrorCode.NotSupported)),
68
- BadRequest: e => E.succeed(new PasslockError(e.message, ErrorCode.BadRequest, e.detail)),
69
- Duplicate: e => E.succeed(new PasslockError(e.message, ErrorCode.Duplicate, e.detail)),
70
- Unauthorized: e => E.succeed(new PasslockError(e.message, ErrorCode.Unauthorized, e.detail)),
71
- Forbidden: e => E.succeed(new PasslockError(e.message, ErrorCode.Forbidden, e.detail)),
72
- Disabled: e => E.succeed(new PasslockError(e.message, ErrorCode.Disabled, e.detail)),
73
- NotFound: e => E.succeed(new PasslockError(e.message, ErrorCode.NotFound, e.detail)),
74
- });
75
- const sandboxed = E.sandbox(withErrorHandling);
76
- const withSandboxing = E.catchTags(sandboxed, {
77
- Die: ({ defect }) => {
78
- return hasMessage(defect)
79
- ? E.succeed(new PasslockError(defect.message, ErrorCode.InternalServerError))
80
- : E.succeed(new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError));
81
- },
82
- Interrupt: () => {
83
- console.error('Interrupt');
84
- return E.succeed(new PasslockError('Operation aborted', ErrorCode.InternalBrowserError));
85
- },
86
- Sequential: errors => {
87
- console.error(errors);
88
- return E.succeed(new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError));
89
- },
90
- Parallel: errors => {
91
- console.error(errors);
92
- return E.succeed(new PasslockError('Sorry, something went wrong', ErrorCode.InternalServerError));
93
- },
94
- });
95
- return E.unsandbox(withSandboxing);
96
- };
97
- export class PasslockUnsafe {
98
- runtime;
99
- constructor(props) {
100
- const config = Layer.succeed(RpcConfig, RpcConfig.of(props));
101
- const storage = Layer.succeed(BrowserStorage, BrowserStorage.of(globalThis.localStorage));
102
- const allLayers = pipe(allRequirements, L.provide(config), L.provide(storage), L.merge(config));
103
- const scope = E.runSync(Scope.make());
104
- this.runtime = E.runSync(Layer.toRuntime(allLayers).pipe(Scope.extend(scope)));
105
- E.runSync(E.logDebug(`Passlock version: ${PASSLOCK_CLIENT_VERSION}`));
106
- }
107
- static isPrincipal = (value) => isPrincipal(value);
108
- static isUserPrincipal = (value) => isUserPrincipal(value);
109
- runPromise = dual(2, (effect, options) => pipe(transformErrors(effect), E.flatMap(result => (PasslockError.isError(result) ? E.fail(result) : E.succeed(result))), effect => Runtime.runPromise(this.runtime)(effect, options)));
110
- preConnect = (options) => pipe(preConnect(), this.runPromise(options));
111
- isPasskeySupport = () => pipe(isPasskeySupport, effect => Runtime.runPromise(this.runtime)(effect));
112
- isExistingUser = (email, options) => pipe(isExistingUser(email), this.runPromise(options));
113
- registerPasskey = (request, options) => pipe(registerPasskey(toRpcRegistrationRequest(request)), this.runPromise(options));
114
- authenticatePasskey = (request, options) => pipe(authenticatePasskey(toRpcAuthenticationRequest(request)), this.runPromise(options));
115
- registerOidc = (request, options) => pipe(registerOidc(toRpcRegisterOidcReq(request)), this.runPromise(options));
116
- authenticateOidc = (request, options) => pipe(authenticateOidc(toRpcAuthenticateOidcReq(request)), this.runPromise(options));
117
- verifyEmailCode = (request, options) => pipe(verifyEmailCode(request), this.runPromise(options));
118
- resendVerificationEmail = (request, options) => pipe(resendVerificationEmail(request), this.runPromise(options));
119
- verifyEmailLink = (options) => pipe(verifyEmailLink, this.runPromise(options));
120
- getSessionToken = (authType) => pipe(getSessionToken(authType), E.orElseSucceed(() => undefined), effect => Runtime.runSync(this.runtime)(effect));
121
- clearExpiredTokens = () => {
122
- pipe(clearExpiredTokens, effect => {
123
- Runtime.runSync(this.runtime)(effect);
124
- });
125
- };
126
- }
127
- export class Passlock {
128
- runtime;
129
- constructor(props) {
130
- const config = Layer.succeed(RpcConfig, RpcConfig.of(props));
131
- const storage = Layer.succeed(BrowserStorage, BrowserStorage.of(globalThis.localStorage));
132
- const allLayers = pipe(allRequirements, L.provide(config), L.provide(storage), L.merge(config));
133
- const scope = E.runSync(Scope.make());
134
- this.runtime = E.runSync(Layer.toRuntime(allLayers).pipe(Scope.extend(scope)));
135
- E.runSync(E.logDebug(`Passlock version: ${PASSLOCK_CLIENT_VERSION}`));
136
- }
137
- static isPrincipal = (value) => isPrincipal(value);
138
- static isUserPrincipal = (value) => isUserPrincipal(value);
139
- runPromise = dual(2, (effect, options) => pipe(transformErrors(effect), effect => Runtime.runPromise(this.runtime)(effect, options)));
140
- preConnect = async (options) => {
141
- return pipe(preConnect(), E.as(true), this.runPromise(options));
142
- };
143
- isPasskeySupport = () => pipe(isPasskeySupport, effect => Runtime.runPromise(this.runtime)(effect));
144
- isExistingUser = (email, options) => pipe(isExistingUser(email), this.runPromise(options));
145
- registerPasskey = (request, options) => pipe(registerPasskey(toRpcRegistrationRequest(request)), this.runPromise(options));
146
- authenticatePasskey = (request = {}, options) => pipe(toRpcAuthenticationRequest(request), authenticatePasskey, this.runPromise(options));
147
- registerOidc = (request, options) => pipe(registerOidc(toRpcRegisterOidcReq(request)), this.runPromise(options));
148
- authenticateOidc = (request, options) => pipe(authenticateOidc(request), this.runPromise(options));
149
- verifyEmailCode = (request, options) => pipe(verifyEmailCode(request), this.runPromise(options));
150
- verifyEmailLink = (options) => pipe(verifyEmailLink, this.runPromise(options));
151
- resendVerificationEmail = (request, options) => pipe(resendVerificationEmail(request), E.as(true), this.runPromise(options));
152
- getSessionToken = (authType) => pipe(getSessionToken(authType), E.orElseSucceed(() => undefined), effect => E.runPromise(effect));
153
- clearExpiredTokens = () => {
154
- pipe(StorageService, E.flatMap(service => service.clearExpiredTokens), effect => {
155
- Runtime.runSync(this.runtime)(effect);
156
- });
157
- };
158
- }
1
+ export * from "./passkey/index";
2
+ export { UnexpectedError, isUnexpectedError } from "./network";
159
3
  //# sourceMappingURL=index.js.map