@passlock/client 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +2 -2
  2. package/README.template.md +2 -2
  3. package/dist/index.d.ts +235 -31
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +237 -36
  6. package/dist/index.js.map +1 -1
  7. package/dist/internal/index.d.ts +4 -0
  8. package/dist/internal/index.d.ts.map +1 -0
  9. package/dist/internal/index.js +4 -0
  10. package/dist/internal/index.js.map +1 -0
  11. package/dist/{shared → internal}/network.d.ts +19 -16
  12. package/dist/internal/network.d.ts.map +1 -0
  13. package/dist/{shared → internal}/network.js +41 -24
  14. package/dist/internal/network.js.map +1 -0
  15. package/dist/{shared → internal}/promise.d.ts +2 -2
  16. package/dist/internal/promise.d.ts.map +1 -0
  17. package/dist/{shared → internal}/promise.js +2 -2
  18. package/dist/internal/promise.js.map +1 -0
  19. package/dist/internal/tenancy.d.ts.map +1 -0
  20. package/dist/internal/tenancy.js.map +1 -0
  21. package/dist/{logger/index.d.ts → logger.d.ts} +19 -4
  22. package/dist/logger.d.ts.map +1 -0
  23. package/dist/{logger/index.js → logger.js} +23 -8
  24. package/dist/logger.js.map +1 -0
  25. package/dist/{shared/options.d.ts → options.d.ts} +4 -0
  26. package/dist/options.d.ts.map +1 -0
  27. package/dist/{shared/options.js.map → options.js.map} +1 -1
  28. package/dist/passkey/authentication/authentication.d.ts +145 -0
  29. package/dist/passkey/authentication/authentication.d.ts.map +1 -0
  30. package/dist/passkey/{authentication.js → authentication/authentication.js} +70 -52
  31. package/dist/passkey/authentication/authentication.js.map +1 -0
  32. package/dist/passkey/errors.d.ts +150 -15
  33. package/dist/passkey/errors.d.ts.map +1 -1
  34. package/dist/passkey/errors.js +209 -8
  35. package/dist/passkey/errors.js.map +1 -1
  36. package/dist/passkey/registration/registration.d.ts +149 -0
  37. package/dist/passkey/registration/registration.d.ts.map +1 -0
  38. package/dist/passkey/{registration.js → registration/registration.js} +46 -36
  39. package/dist/passkey/registration/registration.js.map +1 -0
  40. package/dist/passkey/shared.d.ts +10 -2
  41. package/dist/passkey/shared.d.ts.map +1 -1
  42. package/dist/passkey/signals/signals.d.ts +160 -0
  43. package/dist/passkey/signals/signals.d.ts.map +1 -0
  44. package/dist/passkey/{signals.js → signals/signals.js} +123 -84
  45. package/dist/passkey/signals/signals.js.map +1 -0
  46. package/dist/passkey/support.d.ts +15 -0
  47. package/dist/passkey/support.d.ts.map +1 -1
  48. package/dist/passkey/support.js +16 -1
  49. package/dist/passkey/support.js.map +1 -1
  50. package/dist/principal.d.ts +19 -0
  51. package/dist/principal.d.ts.map +1 -0
  52. package/dist/principal.js +2 -0
  53. package/dist/principal.js.map +1 -0
  54. package/dist/safe.d.ts +267 -0
  55. package/dist/safe.d.ts.map +1 -0
  56. package/dist/safe.js +275 -0
  57. package/dist/safe.js.map +1 -0
  58. package/package.json +22 -20
  59. package/dist/logger/index.d.ts.map +0 -1
  60. package/dist/logger/index.js.map +0 -1
  61. package/dist/passkey/authentication.d.ts +0 -118
  62. package/dist/passkey/authentication.d.ts.map +0 -1
  63. package/dist/passkey/authentication.js.map +0 -1
  64. package/dist/passkey/authentication.test.d.ts +0 -2
  65. package/dist/passkey/authentication.test.d.ts.map +0 -1
  66. package/dist/passkey/authentication.test.js +0 -157
  67. package/dist/passkey/authentication.test.js.map +0 -1
  68. package/dist/passkey/registration.d.ts +0 -136
  69. package/dist/passkey/registration.d.ts.map +0 -1
  70. package/dist/passkey/registration.js.map +0 -1
  71. package/dist/passkey/registration.test.d.ts +0 -2
  72. package/dist/passkey/registration.test.d.ts.map +0 -1
  73. package/dist/passkey/registration.test.js +0 -161
  74. package/dist/passkey/registration.test.js.map +0 -1
  75. package/dist/passkey/signals.d.ts +0 -113
  76. package/dist/passkey/signals.d.ts.map +0 -1
  77. package/dist/passkey/signals.js.map +0 -1
  78. package/dist/shared/network.d.ts.map +0 -1
  79. package/dist/shared/network.js.map +0 -1
  80. package/dist/shared/options.d.ts.map +0 -1
  81. package/dist/shared/promise.d.ts.map +0 -1
  82. package/dist/shared/promise.js.map +0 -1
  83. package/dist/shared/tenancy.d.ts.map +0 -1
  84. package/dist/shared/tenancy.js.map +0 -1
  85. package/dist/surface.test.d.ts +0 -2
  86. package/dist/surface.test.d.ts.map +0 -1
  87. package/dist/surface.test.js +0 -38
  88. package/dist/surface.test.js.map +0 -1
  89. package/dist/unsafe.d.ts +0 -41
  90. package/dist/unsafe.d.ts.map +0 -1
  91. package/dist/unsafe.js +0 -52
  92. package/dist/unsafe.js.map +0 -1
  93. /package/dist/{shared → internal}/tenancy.d.ts +0 -0
  94. /package/dist/{shared → internal}/tenancy.js +0 -0
  95. /package/dist/{shared/options.js → options.js} +0 -0
package/README.md CHANGED
@@ -36,7 +36,7 @@ in README.template.md and outputs to README.md
36
36
 
37
37
  Powerful features including signals and related origin requests...
38
38
 
39
- 1. **🔓 No lock-in**
39
+ 1. **🔓 No lock-in**
40
40
  Framework agnostic. Standards compliant.
41
41
 
42
42
  2. **🔑 Related origins (domain migration)**
@@ -48,7 +48,7 @@ Works out of the box with sensible defaults.
48
48
  4. **📱 Credential management**
49
49
  Programmatically manage passkeys on end user devices
50
50
 
51
- 5. **💪 Powerful**
51
+ 5. **💪 Powerful**
52
52
  User verification, autofill, roaming authenticators and more.
53
53
 
54
54
  ## More information
@@ -36,7 +36,7 @@ in README.template.md and outputs to README.md
36
36
 
37
37
  Powerful features including signals and related origin requests...
38
38
 
39
- 1. **🔓 No lock-in**
39
+ 1. **🔓 No lock-in**
40
40
  Framework agnostic. Standards compliant.
41
41
 
42
42
  2. **🔑 Related origins (domain migration)**
@@ -48,7 +48,7 @@ Works out of the box with sensible defaults.
48
48
  4. **📱 Credential management**
49
49
  Programmatically manage passkeys on end user devices
50
50
 
51
- 5. **💪 Powerful**
51
+ 5. **💪 Powerful**
52
52
  User verification, autofill, roaming authenticators and more.
53
53
 
54
54
  ## More information
package/dist/index.d.ts CHANGED
@@ -1,41 +1,245 @@
1
- import type { AuthenticationError, AuthenticationOptions, AuthenticationSuccess, PasskeyNotFound } from "./passkey/authentication";
2
- import type { CredentialMapping, DeletionError, SyncError, UpdateError, UpdateUserDetails } from "./passkey/signals";
3
- import type { PasslockOptions } from "./shared/options";
1
+ /**
2
+ * _unsafe_ functions that could throw an error. Be sure to catch errors and use one of the
3
+ * type guards to narrow the thrown error down to a specific type.
4
+ *
5
+ * @categoryDescription Passkeys (core)
6
+ * Creating, authenticating, updating and deleting passkeys. {@link registerPasskey}
7
+ * and {@link authenticatePasskey} are the key functions.
8
+ *
9
+ * @categoryDescription Passkeys (other)
10
+ * Testing for browser capabilities related to passkeys, type guards and other utilities.
11
+ *
12
+ * @showCategories
13
+ * @module unsafe
14
+ */
4
15
  import { Logger } from "./logger";
5
- import { type RegistrationError, type RegistrationOptions, type RegistrationSuccess } from "./passkey/registration";
6
- export type { PasslockOptions } from "./shared/options";
7
- export { ConsoleLogger, EventLogger, LogEvent, Logger, LogLevel } from "./logger";
16
+ import type { AuthenticationOptions, AuthenticationSuccess } from "./passkey/authentication/authentication";
17
+ import type { RegistrationOptions, RegistrationSuccess } from "./passkey/registration/registration";
18
+ import type { DeleteCredentialOptions, DeletePasskeyOptions, DeleteSuccess, PrunePasskeyOptions, PruningSuccess, UpdateCredentialOptions, UpdatePasskeyOptions, UpdateSuccess } from "./passkey/signals/signals";
19
+ import type { OrphanedPasskeyError } from "./safe";
8
20
  /**
9
- * Register a passkey on the local device and store the
10
- * associated public key in your Passlock vault.
21
+ * Registers a passkey on the user's device, then saves the server-side component in your vault.
22
+ * If successful, this function returns both a `code` and an `id_token` (JWT).
23
+ * Send either value to your backend for verification.
24
+ * See [register a passkey](https://passlock.dev/passkeys/registration/) in the documentation.
25
+ *
11
26
  * @param options
12
- * @returns
27
+ *
28
+ * @returns A successful registration payload.
29
+ *
30
+ * @see {@link isRegistrationSuccess}
31
+ * @see {@link isPasskeyUnsupportedError}
32
+ * @see {@link isDuplicatePasskeyError}
33
+ * @see {@link isOtherPasskeyError}
34
+ *
35
+ * @throws {@link RegistrationError} (alias to a union of potential errors)
36
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
37
+ * @throws {@link DuplicatePasskeyError} if `excludeCredentials` includes a passkey that already exists on the device
38
+ * @throws {@link OtherPasskeyError} typically a low level failure
39
+ * @throws {@link NetworkError}
40
+ *
41
+ * @example
42
+ * // from your Passlock console settings
43
+ * const tenancyId = "myTenancyId";
44
+ * const username = "jdoe@gmail.com";
45
+ *
46
+ * try {
47
+ * const result = await registerPasskey({ tenancyId, username });
48
+ * // send this to your backend for verification
49
+ * console.log(result.code);
50
+ * } catch (error) {
51
+ * if (isPasskeyUnsupportedError(error)) {
52
+ * alert("passkeys not supported on this device");
53
+ * } else {
54
+ * console.log(error);
55
+ * }
56
+ * }
57
+ *
58
+ * @category Passkeys (core)
13
59
  */
14
- export declare const registerPasskey: (options: RegistrationOptions, logger?: typeof Logger.Service) => Promise<RegistrationSuccess | RegistrationError>;
15
- export type { RegistrationError, RegistrationOptions, RegistrationSuccess, } from "./passkey/registration";
16
- export { isOtherPasskeyError, isPasskeyUnsupported, OtherPasskeyError, PasskeyUnsupportedError, } from "./passkey/errors";
17
- export { DuplicatePasskeyError, isDuplicatePasskey, isRegistrationSuccess, } from "./passkey/registration";
18
- export { isUnexpectedError, UnexpectedError } from "./shared/network";
60
+ export declare const registerPasskey: (options: RegistrationOptions,
61
+ /** @hidden */
62
+ logger?: typeof Logger.Service) => Promise<RegistrationSuccess>;
19
63
  /**
20
- * Trigger local passkey authentication then verify the passkey in the Passlock vault.
21
- * Returns a code and id_token that can be exchanged/decoded in your backend.
64
+ * Asks the client to present a passkey, which is then verified against the server-side component in your vault.
65
+ * If successful, this function returns both a `code` and an `id_token` (JWT). Send either value to your backend for verification.
66
+ * See
67
+ * [authenticate a passkey](https://passlock.dev/passkeys/authentication/) in the documentation.
22
68
  *
23
69
  * @param options
24
- * @returns
70
+ *
71
+ * @returns A successful authentication payload.
72
+ *
73
+ * @see {@link isAuthenticationSuccess}
74
+ * @see {@link isPasskeyUnsupportedError}
75
+ * @see {@link isOrphanedPasskeyError}
76
+ * @see {@link isOtherPasskeyError}
77
+ *
78
+ * @throws {@link AuthenticationError} (alias to a union of potential errors)
79
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
80
+ * @throws {@link OrphanedPasskeyError} if the passkey is orphaned i.e. deleted from the vault but still present on the local device
81
+ * @throws {@link OtherPasskeyError} typically a low level failure
82
+ * @throws {@link NetworkError}
83
+ *
84
+ * @example
85
+ * // from your Passlock console settings
86
+ * const tenancyId = "myTenancyId";
87
+ *
88
+ * try {
89
+ * const result = await authenticatePasskey({ tenancyId });
90
+ * // send this to your backend for verification
91
+ * console.log(result.code);
92
+ * } catch (error) {
93
+ * if (isPasskeyUnsupportedError(error)) {
94
+ * alert("passkeys not supported on this device");
95
+ * } else {
96
+ * console.log(error);
97
+ * }
98
+ * }
99
+ *
100
+ * @category Passkeys (core)
101
+ */
102
+ export declare const authenticatePasskey: (options: AuthenticationOptions,
103
+ /** @hidden */
104
+ logger?: typeof Logger.Service) => Promise<AuthenticationSuccess>;
105
+ /**
106
+ * Attempt to update the username or display name for a passkey (client-side only).
107
+ *
108
+ * Useful if the user has changed their account identifier. For example, they register
109
+ * using jdoe@gmail.com but later change their account username to jdoe@yahoo.com.
110
+ * Even after you update their account details in your backend, their local password
111
+ * manager will continue to display jdoe@gmail.com.
112
+ *
113
+ * By calling this function and supplying a new username/display name, their local
114
+ * password manager will align with their updated account identifier.
115
+ *
116
+ * @param options You will typically supply a target `passkeyId` via {@link UpdatePasskeyOptions}. {@link UpdateCredentialOptions} is for advanced use cases.
117
+ * @returns Update status
118
+ * @see {@link isUpdateError}
119
+ * @throws {@link UpdateError} if the passkey cannot be updated
120
+ *
121
+ * @example
122
+ * // from your Passlock console settings
123
+ * const tenancyId = "myTenancyId";
124
+ * const passkeyId = "myPasskeyId";
125
+ * const username = "newUsername@gmail.com";
126
+ * const displayName = "New Account Name";
127
+ *
128
+ * try {
129
+ * const result = await updatePasskey({ tenancyId, passkeyId, username, displayName });
130
+ * console.log("passkey updated");
131
+ * } catch (error) {
132
+ * console.log(error);
133
+ * }
134
+ *
135
+ * @category Passkeys (core)
136
+ */
137
+ export declare const updatePasskey: (options: UpdatePasskeyOptions | UpdateCredentialOptions,
138
+ /** @hidden */
139
+ logger?: typeof Logger.Service) => Promise<UpdateSuccess>;
140
+ /**
141
+ * Attempts to delete a passkey from a local device. There are two scenarios in which this function proves useful:
142
+ *
143
+ * 1. **Deleting a passkey**. Use the `@passlock/node` package or make vanilla REST calls from your
144
+ * backend to delete the server-side component, then use this function to delete the client-side component.
145
+ *
146
+ * 2. **Missing passkey**. The user tried to present a passkey, but the server-side component could not be found.
147
+ * Remove the passkey from the local device to prevent it happening again.
148
+ *
149
+ * See [deleting passkeys](https://passlock.dev/passkeys/passkey-removal/) and
150
+ * [handling missing passkeys](https://passlock.dev/handling-missing-passkeys/) in the documentation.
151
+ *
152
+ * @param options You typically pass a {@link DeletePasskeyOptions}, the other types are for advanced edge-cases.
153
+ * @returns A {@link DeleteSuccess} payload if the passkey is deleted.
154
+ * @see {@link isDeleteError}
155
+ * @throws {@link DeleteError} if the passkey cannot be deleted
156
+ *
157
+ * @example
158
+ * // from your Passlock console settings
159
+ * const tenancyId = "myTenancyId";
160
+ * const passkeyId = "myPasskeyId";
161
+ *
162
+ * try {
163
+ * const result = await deletePasskey({ tenancyId, passkeyId });
164
+ * console.log("passkey deleted");
165
+ * } catch (error) {
166
+ * console.log(error);
167
+ * }
168
+ *
169
+ * @category Passkeys (core)
170
+ */
171
+ export declare const deletePasskey: (options: DeletePasskeyOptions | DeleteCredentialOptions | OrphanedPasskeyError,
172
+ /** @hidden */
173
+ logger?: typeof Logger.Service) => Promise<DeleteSuccess>;
174
+ /**
175
+ * Attempt to prune local passkeys by keeping only the passkey IDs you trust.
176
+ *
177
+ * This is useful when your backend is the source of truth for which passkeys
178
+ * should still exist for a given account on this device.
179
+ *
180
+ * @param options Pass the passkeys you want to retain.
181
+ * @returns A {@link PruningSuccess} payload if local passkeys were pruned.
182
+ * @see {@link isPruningError}
183
+ *
184
+ * @throws {@link PruningError}
185
+ *
186
+ * @example
187
+ * // from your Passlock console settings
188
+ * const tenancyId = "myTenancyId";
189
+ * const allowablePasskeyIds = ["passkey-1", "passkey-2"];
190
+ *
191
+ * try {
192
+ * const result = await prunePasskeys({ tenancyId, allowablePasskeyIds });
193
+ * console.log("local passkeys pruned", result);
194
+ * } catch (error) {
195
+ * if (isPruningError(error)) {
196
+ * console.log(error.code);
197
+ * } else {
198
+ * console.log(error);
199
+ * }
200
+ * }
201
+ *
202
+ * @category Passkeys (core)
203
+ */
204
+ export declare const prunePasskeys: (options: PrunePasskeyOptions,
205
+ /** @hidden */
206
+ logger?: typeof Logger.Service) => Promise<PruningSuccess>;
207
+ /**
208
+ * Does the local device support programmatic passkey deletion
209
+ *
210
+ * @returns `true` if local passkey deletion is supported.
211
+ *
212
+ * @category Passkeys (other)
213
+ */
214
+ export declare const isPasskeyDeleteSupport: () => boolean;
215
+ /**
216
+ * Does the local device support programmatic passkey pruning
217
+ *
218
+ * @returns `true` if local passkey pruning is supported.
219
+ *
220
+ * @category Passkeys (other)
221
+ */
222
+ export declare const isPasskeyPruningSupport: () => boolean;
223
+ /**
224
+ * Does the local device support programmatic passkey updates
225
+ *
226
+ * @returns `true` if local passkey updates are supported.
227
+ *
228
+ * @category Passkeys (other)
25
229
  */
26
- export declare const authenticatePasskey: (options: AuthenticationOptions, logger?: typeof Logger.Service) => Promise<AuthenticationSuccess | AuthenticationError>;
27
- export type { AuthenticationError, AuthenticationOptions, AuthenticationSuccess, PasskeyNotFound, } from "./passkey/authentication";
28
- export { isAuthenticationSuccess, isPasskeyNotFound, } from "./passkey/authentication";
29
- export declare const isPasskeyDeletionSupport: () => boolean;
30
- export declare const isPasskeySyncSupport: () => boolean;
31
230
  export declare const isPasskeyUpdateSupport: () => boolean;
32
- export declare const deletePasskey: (identifiers: string | CredentialMapping | PasskeyNotFound, options: PasslockOptions, logger?: typeof Logger.Service) => Promise<boolean | DeletionError>;
33
- export type { CredentialMapping } from "./passkey/signals";
34
- export { DeletionError, isDeletionError } from "./passkey/signals";
35
- export declare const syncPasskeys: (passkeyIds: Array<string>, options: PasslockOptions, logger?: typeof Logger.Service) => Promise<boolean | SyncError>;
36
- export { isSyncError, SyncError } from "./passkey/signals";
37
- export declare const updateUserDetails: (options: UpdateUserDetails, logger?: typeof Logger.Service) => Promise<boolean | UpdateError>;
38
- export type { UpdateUserDetails } from "./passkey/signals";
39
- export { isUpdateError, UpdateError } from "./passkey/signals";
40
- export { isAutofillSupport, isPasskeySupport } from "./passkey/support";
231
+ export { isNetworkError, NetworkError } from "./internal/network";
232
+ export { LogEvent, Logger, LogLevel, } from "./logger";
233
+ export type { PasslockOptions } from "./options";
234
+ export type { AuthenticationError, AuthenticationEvent, AuthenticationEvents, AuthenticationOptions, AuthenticationSuccess, OnAuthenticationEvent, } from "./passkey/authentication/authentication";
235
+ export { AuthenticationHelper, isAuthenticationSuccess, } from "./passkey/authentication/authentication";
236
+ export type { ErrorCode } from "./passkey/errors";
237
+ export { DeleteError, DuplicatePasskeyError, isDeleteError, isDuplicatePasskeyError, isOrphanedPasskeyError, isOtherPasskeyError, isPasskeyUnsupportedError, isPruningError, isUpdateError, OrphanedPasskeyError, OtherPasskeyError, PasskeyUnsupportedError, PruningError, UpdateError, } from "./passkey/errors";
238
+ export type { OnRegistrationEvent, RegistrationError, RegistrationEvent, RegistrationOptions, RegistrationSuccess, } from "./passkey/registration/registration";
239
+ export { isRegistrationSuccess, RegistrationHelper, } from "./passkey/registration/registration";
240
+ export type { UserVerification } from "./passkey/shared";
241
+ export type { CredentialMapping, DeleteCredentialOptions, DeletePasskeyOptions, DeleteSuccess, PrunePasskeyOptions, PruningSuccess, UpdateCredentialOptions, UpdatePasskeyOptions, UpdateSuccess, } from "./passkey/signals/signals";
242
+ export { isDeleteSuccess, isPruningSuccess, isUpdateSuccess, } from "./passkey/signals/signals";
243
+ export { isAutofillSupport, isPasskeySupport, } from "./passkey/support";
244
+ export type { Principal } from "./principal";
41
245
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EAChB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,WAAW,EACX,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAe,MAAM,EAAE,MAAM,UAAU,CAAA;AAK9C,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAEzB,MAAM,wBAAwB,CAAA;AAY/B,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAIjF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,mBAAmB,EAC5B,SAAQ,OAAO,MAAM,CAAC,OAAqB,KAC1C,OAAO,CAAC,mBAAmB,GAAG,iBAAiB,CAM/C,CAAA;AAEH,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,wBAAwB,CAAA;A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,mBAAmB,GACpB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qCAAqC,CAAA;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js CHANGED
@@ -1,52 +1,253 @@
1
+ /**
2
+ * _unsafe_ functions that could throw an error. Be sure to catch errors and use one of the
3
+ * type guards to narrow the thrown error down to a specific type.
4
+ *
5
+ * @categoryDescription Passkeys (core)
6
+ * Creating, authenticating, updating and deleting passkeys. {@link registerPasskey}
7
+ * and {@link authenticatePasskey} are the key functions.
8
+ *
9
+ * @categoryDescription Passkeys (other)
10
+ * Testing for browser capabilities related to passkeys, type guards and other utilities.
11
+ *
12
+ * @showCategories
13
+ * @module unsafe
14
+ */
1
15
  import { Micro, pipe } from "effect";
2
- import { EventLogger, Logger } from "./logger";
3
- import { AuthenticationHelper, authenticatePasskey as authenticatePasskeyM, } from "./passkey/authentication";
4
- import { RegistrationHelper, registerPasskey as registerPasskeyM, } from "./passkey/registration";
5
- import { deletePasskey as deletePasskeyM, isPasskeyDeletionSupport as isPasskeyDeletionSupportM, isPasskeySyncSupport as isPasskeySyncSupportM, isPasskeyUpdateSupport as isPasskeyUpdateSupportM, signalCredentialRemoval, syncPasskeys as syncPasskeysM, updateUserDetails as updateUserDetailsM, } from "./passkey/signals";
6
- import { runToPromise } from "./shared/promise";
7
- export { ConsoleLogger, EventLogger, LogEvent, Logger, LogLevel } from "./logger";
16
+ import { runToPromiseUnsafe } from "./internal";
17
+ import { eventLogger, Logger } from "./logger";
18
+ import { AuthenticationHelper, authenticatePasskey as authenticatePasskeyM, } from "./passkey/authentication/authentication";
19
+ import { RegistrationHelper, registerPasskey as registerPasskeyM, } from "./passkey/registration/registration";
20
+ import { deletePasskey as deletePasskeyM, isPasskeyDeleteSupport as isPasskeyDeleteSupportM, isPasskeyPruningSupport as isPasskeyPruningSupportM, isPasskeyUpdateSupport as isPasskeyUpdateSupportM, prunePasskeys as prunePasskeysM, updatePasskey as updatePasskeyM, } from "./passkey/signals/signals";
8
21
  /* Registration */
9
22
  /**
10
- * Register a passkey on the local device and store the
11
- * associated public key in your Passlock vault.
23
+ * Registers a passkey on the user's device, then saves the server-side component in your vault.
24
+ * If successful, this function returns both a `code` and an `id_token` (JWT).
25
+ * Send either value to your backend for verification.
26
+ * See [register a passkey](https://passlock.dev/passkeys/registration/) in the documentation.
27
+ *
12
28
  * @param options
13
- * @returns
29
+ *
30
+ * @returns A successful registration payload.
31
+ *
32
+ * @see {@link isRegistrationSuccess}
33
+ * @see {@link isPasskeyUnsupportedError}
34
+ * @see {@link isDuplicatePasskeyError}
35
+ * @see {@link isOtherPasskeyError}
36
+ *
37
+ * @throws {@link RegistrationError} (alias to a union of potential errors)
38
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
39
+ * @throws {@link DuplicatePasskeyError} if `excludeCredentials` includes a passkey that already exists on the device
40
+ * @throws {@link OtherPasskeyError} typically a low level failure
41
+ * @throws {@link NetworkError}
42
+ *
43
+ * @example
44
+ * // from your Passlock console settings
45
+ * const tenancyId = "myTenancyId";
46
+ * const username = "jdoe@gmail.com";
47
+ *
48
+ * try {
49
+ * const result = await registerPasskey({ tenancyId, username });
50
+ * // send this to your backend for verification
51
+ * console.log(result.code);
52
+ * } catch (error) {
53
+ * if (isPasskeyUnsupportedError(error)) {
54
+ * alert("passkeys not supported on this device");
55
+ * } else {
56
+ * console.log(error);
57
+ * }
58
+ * }
59
+ *
60
+ * @category Passkeys (core)
14
61
  */
15
- export const registerPasskey = async (options, logger = EventLogger) => pipe(registerPasskeyM(options), Micro.provideService(Logger, logger), Micro.provideService(RegistrationHelper, RegistrationHelper.Default), runToPromise);
16
- export { isOtherPasskeyError, isPasskeyUnsupported, OtherPasskeyError, PasskeyUnsupportedError, } from "./passkey/errors";
17
- export { DuplicatePasskeyError, isDuplicatePasskey, isRegistrationSuccess, } from "./passkey/registration";
18
- export { isUnexpectedError, UnexpectedError } from "./shared/network";
62
+ export const registerPasskey = async (options,
63
+ /** @hidden */
64
+ logger = eventLogger) => pipe(registerPasskeyM(options), Micro.provideService(RegistrationHelper, RegistrationHelper.Default), Micro.provideService(Logger, logger), runToPromiseUnsafe);
19
65
  /* Authentication */
20
66
  /**
21
- * Trigger local passkey authentication then verify the passkey in the Passlock vault.
22
- * Returns a code and id_token that can be exchanged/decoded in your backend.
67
+ * Asks the client to present a passkey, which is then verified against the server-side component in your vault.
68
+ * If successful, this function returns both a `code` and an `id_token` (JWT). Send either value to your backend for verification.
69
+ * See
70
+ * [authenticate a passkey](https://passlock.dev/passkeys/authentication/) in the documentation.
23
71
  *
24
72
  * @param options
25
- * @returns
73
+ *
74
+ * @returns A successful authentication payload.
75
+ *
76
+ * @see {@link isAuthenticationSuccess}
77
+ * @see {@link isPasskeyUnsupportedError}
78
+ * @see {@link isOrphanedPasskeyError}
79
+ * @see {@link isOtherPasskeyError}
80
+ *
81
+ * @throws {@link AuthenticationError} (alias to a union of potential errors)
82
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
83
+ * @throws {@link OrphanedPasskeyError} if the passkey is orphaned i.e. deleted from the vault but still present on the local device
84
+ * @throws {@link OtherPasskeyError} typically a low level failure
85
+ * @throws {@link NetworkError}
86
+ *
87
+ * @example
88
+ * // from your Passlock console settings
89
+ * const tenancyId = "myTenancyId";
90
+ *
91
+ * try {
92
+ * const result = await authenticatePasskey({ tenancyId });
93
+ * // send this to your backend for verification
94
+ * console.log(result.code);
95
+ * } catch (error) {
96
+ * if (isPasskeyUnsupportedError(error)) {
97
+ * alert("passkeys not supported on this device");
98
+ * } else {
99
+ * console.log(error);
100
+ * }
101
+ * }
102
+ *
103
+ * @category Passkeys (core)
26
104
  */
27
- export const authenticatePasskey = (options, logger = EventLogger) => pipe(authenticatePasskeyM(options), Micro.provideService(Logger, logger), Micro.provideService(AuthenticationHelper, AuthenticationHelper.Default), runToPromise);
28
- export { isAuthenticationSuccess, isPasskeyNotFound, } from "./passkey/authentication";
105
+ export const authenticatePasskey = (options,
106
+ /** @hidden */
107
+ logger = eventLogger) => pipe(authenticatePasskeyM(options), Micro.provideService(AuthenticationHelper, AuthenticationHelper.Default), Micro.provideService(Logger, logger), runToPromiseUnsafe);
29
108
  /* Signals */
30
- export const isPasskeyDeletionSupport = () => pipe(isPasskeyDeletionSupportM, Micro.runSync);
31
- export const isPasskeySyncSupport = () => pipe(isPasskeySyncSupportM, Micro.runSync);
32
- export const isPasskeyUpdateSupport = () => pipe(isPasskeyUpdateSupportM, Micro.runSync);
33
- export const deletePasskey = (identifiers, options, logger = EventLogger) => {
34
- const micro = typeof identifiers === "string"
35
- ? deletePasskeyM(identifiers, options)
36
- : signalCredentialRemoval(identifiers);
37
- return pipe(micro, Micro.provideService(Logger, logger), runToPromise);
109
+ /**
110
+ * Attempt to update the username or display name for a passkey (client-side only).
111
+ *
112
+ * Useful if the user has changed their account identifier. For example, they register
113
+ * using jdoe@gmail.com but later change their account username to jdoe@yahoo.com.
114
+ * Even after you update their account details in your backend, their local password
115
+ * manager will continue to display jdoe@gmail.com.
116
+ *
117
+ * By calling this function and supplying a new username/display name, their local
118
+ * password manager will align with their updated account identifier.
119
+ *
120
+ * @param options You will typically supply a target `passkeyId` via {@link UpdatePasskeyOptions}. {@link UpdateCredentialOptions} is for advanced use cases.
121
+ * @returns Update status
122
+ * @see {@link isUpdateError}
123
+ * @throws {@link UpdateError} if the passkey cannot be updated
124
+ *
125
+ * @example
126
+ * // from your Passlock console settings
127
+ * const tenancyId = "myTenancyId";
128
+ * const passkeyId = "myPasskeyId";
129
+ * const username = "newUsername@gmail.com";
130
+ * const displayName = "New Account Name";
131
+ *
132
+ * try {
133
+ * const result = await updatePasskey({ tenancyId, passkeyId, username, displayName });
134
+ * console.log("passkey updated");
135
+ * } catch (error) {
136
+ * console.log(error);
137
+ * }
138
+ *
139
+ * @category Passkeys (core)
140
+ */
141
+ export const updatePasskey = (options,
142
+ /** @hidden */
143
+ logger = eventLogger) => {
144
+ const micro = updatePasskeyM(options);
145
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
38
146
  };
39
- export { DeletionError, isDeletionError } from "./passkey/signals";
40
- export const syncPasskeys = (passkeyIds, options, logger = EventLogger) => {
41
- const micro = syncPasskeysM(passkeyIds, options);
42
- return pipe(micro, Micro.provideService(Logger, logger), runToPromise);
147
+ /**
148
+ * Attempts to delete a passkey from a local device. There are two scenarios in which this function proves useful:
149
+ *
150
+ * 1. **Deleting a passkey**. Use the `@passlock/node` package or make vanilla REST calls from your
151
+ * backend to delete the server-side component, then use this function to delete the client-side component.
152
+ *
153
+ * 2. **Missing passkey**. The user tried to present a passkey, but the server-side component could not be found.
154
+ * Remove the passkey from the local device to prevent it happening again.
155
+ *
156
+ * See [deleting passkeys](https://passlock.dev/passkeys/passkey-removal/) and
157
+ * [handling missing passkeys](https://passlock.dev/handling-missing-passkeys/) in the documentation.
158
+ *
159
+ * @param options You typically pass a {@link DeletePasskeyOptions}, the other types are for advanced edge-cases.
160
+ * @returns A {@link DeleteSuccess} payload if the passkey is deleted.
161
+ * @see {@link isDeleteError}
162
+ * @throws {@link DeleteError} if the passkey cannot be deleted
163
+ *
164
+ * @example
165
+ * // from your Passlock console settings
166
+ * const tenancyId = "myTenancyId";
167
+ * const passkeyId = "myPasskeyId";
168
+ *
169
+ * try {
170
+ * const result = await deletePasskey({ tenancyId, passkeyId });
171
+ * console.log("passkey deleted");
172
+ * } catch (error) {
173
+ * console.log(error);
174
+ * }
175
+ *
176
+ * @category Passkeys (core)
177
+ */
178
+ export const deletePasskey = (options,
179
+ /** @hidden */
180
+ logger = eventLogger) => {
181
+ const micro = deletePasskeyM(options);
182
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
43
183
  };
44
- export { isSyncError, SyncError } from "./passkey/signals";
45
- export const updateUserDetails = (options, logger = EventLogger) => {
46
- const micro = updateUserDetailsM(options);
47
- return pipe(micro, Micro.provideService(Logger, logger), runToPromise);
184
+ /**
185
+ * Attempt to prune local passkeys by keeping only the passkey IDs you trust.
186
+ *
187
+ * This is useful when your backend is the source of truth for which passkeys
188
+ * should still exist for a given account on this device.
189
+ *
190
+ * @param options Pass the passkeys you want to retain.
191
+ * @returns A {@link PruningSuccess} payload if local passkeys were pruned.
192
+ * @see {@link isPruningError}
193
+ *
194
+ * @throws {@link PruningError}
195
+ *
196
+ * @example
197
+ * // from your Passlock console settings
198
+ * const tenancyId = "myTenancyId";
199
+ * const allowablePasskeyIds = ["passkey-1", "passkey-2"];
200
+ *
201
+ * try {
202
+ * const result = await prunePasskeys({ tenancyId, allowablePasskeyIds });
203
+ * console.log("local passkeys pruned", result);
204
+ * } catch (error) {
205
+ * if (isPruningError(error)) {
206
+ * console.log(error.code);
207
+ * } else {
208
+ * console.log(error);
209
+ * }
210
+ * }
211
+ *
212
+ * @category Passkeys (core)
213
+ */
214
+ export const prunePasskeys = (options,
215
+ /** @hidden */
216
+ logger = eventLogger) => {
217
+ const micro = prunePasskeysM(options);
218
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
48
219
  };
49
- export { isUpdateError, UpdateError } from "./passkey/signals";
50
220
  /* Support */
51
- export { isAutofillSupport, isPasskeySupport } from "./passkey/support";
221
+ /**
222
+ * Does the local device support programmatic passkey deletion
223
+ *
224
+ * @returns `true` if local passkey deletion is supported.
225
+ *
226
+ * @category Passkeys (other)
227
+ */
228
+ export const isPasskeyDeleteSupport = () => pipe(isPasskeyDeleteSupportM, Micro.runSync);
229
+ /**
230
+ * Does the local device support programmatic passkey pruning
231
+ *
232
+ * @returns `true` if local passkey pruning is supported.
233
+ *
234
+ * @category Passkeys (other)
235
+ */
236
+ export const isPasskeyPruningSupport = () => pipe(isPasskeyPruningSupportM, Micro.runSync);
237
+ /**
238
+ * Does the local device support programmatic passkey updates
239
+ *
240
+ * @returns `true` if local passkey updates are supported.
241
+ *
242
+ * @category Passkeys (other)
243
+ */
244
+ export const isPasskeyUpdateSupport = () => pipe(isPasskeyUpdateSupportM, Micro.runSync);
245
+ /* Re-exports */
246
+ export { isNetworkError, NetworkError } from "./internal/network";
247
+ export { LogEvent, Logger, LogLevel, } from "./logger";
248
+ export { AuthenticationHelper, isAuthenticationSuccess, } from "./passkey/authentication/authentication";
249
+ export { DeleteError, DuplicatePasskeyError, isDeleteError, isDuplicatePasskeyError, isOrphanedPasskeyError, isOtherPasskeyError, isPasskeyUnsupportedError, isPruningError, isUpdateError, OrphanedPasskeyError, OtherPasskeyError, PasskeyUnsupportedError, PruningError, UpdateError, } from "./passkey/errors";
250
+ export { isRegistrationSuccess, RegistrationHelper, } from "./passkey/registration/registration";
251
+ export { isDeleteSuccess, isPruningSuccess, isUpdateSuccess, } from "./passkey/signals/signals";
252
+ export { isAutofillSupport, isPasskeySupport, } from "./passkey/support";
52
253
  //# sourceMappingURL=index.js.map