@passlock/client 2.0.1 → 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 (99) hide show
  1. package/README.md +2 -2
  2. package/README.template.md +2 -2
  3. package/dist/errors.d.ts +4 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +14 -0
  6. package/dist/errors.js.map +1 -0
  7. package/dist/index.d.ts +236 -31
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +236 -34
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/index.d.ts +4 -0
  12. package/dist/internal/index.d.ts.map +1 -0
  13. package/dist/internal/index.js +4 -0
  14. package/dist/internal/index.js.map +1 -0
  15. package/dist/{shared → internal}/network.d.ts +19 -16
  16. package/dist/internal/network.d.ts.map +1 -0
  17. package/dist/{shared → internal}/network.js +40 -25
  18. package/dist/internal/network.js.map +1 -0
  19. package/dist/{shared → internal}/promise.d.ts +2 -2
  20. package/dist/internal/promise.d.ts.map +1 -0
  21. package/dist/{shared → internal}/promise.js +2 -2
  22. package/dist/internal/promise.js.map +1 -0
  23. package/dist/internal/tenancy.d.ts.map +1 -0
  24. package/dist/internal/tenancy.js.map +1 -0
  25. package/dist/{logger/index.d.ts → logger.d.ts} +19 -4
  26. package/dist/logger.d.ts.map +1 -0
  27. package/dist/{logger/index.js → logger.js} +19 -4
  28. package/dist/logger.js.map +1 -0
  29. package/dist/{shared/options.d.ts → options.d.ts} +4 -0
  30. package/dist/options.d.ts.map +1 -0
  31. package/dist/{shared/options.js.map → options.js.map} +1 -1
  32. package/dist/passkey/authentication/authentication.d.ts +134 -0
  33. package/dist/passkey/authentication/authentication.d.ts.map +1 -0
  34. package/dist/passkey/{authentication.js → authentication/authentication.js} +68 -50
  35. package/dist/passkey/authentication/authentication.js.map +1 -0
  36. package/dist/passkey/errors.d.ts +158 -16
  37. package/dist/passkey/errors.d.ts.map +1 -1
  38. package/dist/passkey/errors.js +214 -6
  39. package/dist/passkey/errors.js.map +1 -1
  40. package/dist/passkey/registration/registration.d.ts +145 -0
  41. package/dist/passkey/registration/registration.d.ts.map +1 -0
  42. package/dist/passkey/{registration.js → registration/registration.js} +43 -36
  43. package/dist/passkey/registration/registration.js.map +1 -0
  44. package/dist/passkey/shared.d.ts +8 -2
  45. package/dist/passkey/shared.d.ts.map +1 -1
  46. package/dist/passkey/signals/signals.d.ts +103 -0
  47. package/dist/passkey/signals/signals.d.ts.map +1 -0
  48. package/dist/passkey/{signals.js → signals/signals.js} +69 -71
  49. package/dist/passkey/signals/signals.js.map +1 -0
  50. package/dist/passkey/support.d.ts +15 -0
  51. package/dist/passkey/support.d.ts.map +1 -1
  52. package/dist/passkey/support.js +16 -1
  53. package/dist/passkey/support.js.map +1 -1
  54. package/dist/principal.d.ts +16 -0
  55. package/dist/principal.d.ts.map +1 -0
  56. package/dist/principal.js +2 -0
  57. package/dist/principal.js.map +1 -0
  58. package/dist/safe.d.ts +247 -0
  59. package/dist/safe.d.ts.map +1 -0
  60. package/dist/safe.js +254 -0
  61. package/dist/safe.js.map +1 -0
  62. package/package.json +21 -19
  63. package/dist/logger/index.d.ts.map +0 -1
  64. package/dist/logger/index.js.map +0 -1
  65. package/dist/passkey/authentication.d.ts +0 -118
  66. package/dist/passkey/authentication.d.ts.map +0 -1
  67. package/dist/passkey/authentication.js.map +0 -1
  68. package/dist/passkey/authentication.test.d.ts +0 -2
  69. package/dist/passkey/authentication.test.d.ts.map +0 -1
  70. package/dist/passkey/authentication.test.js +0 -157
  71. package/dist/passkey/authentication.test.js.map +0 -1
  72. package/dist/passkey/registration.d.ts +0 -136
  73. package/dist/passkey/registration.d.ts.map +0 -1
  74. package/dist/passkey/registration.js.map +0 -1
  75. package/dist/passkey/registration.test.d.ts +0 -2
  76. package/dist/passkey/registration.test.d.ts.map +0 -1
  77. package/dist/passkey/registration.test.js +0 -161
  78. package/dist/passkey/registration.test.js.map +0 -1
  79. package/dist/passkey/signals.d.ts +0 -113
  80. package/dist/passkey/signals.d.ts.map +0 -1
  81. package/dist/passkey/signals.js.map +0 -1
  82. package/dist/shared/network.d.ts.map +0 -1
  83. package/dist/shared/network.js.map +0 -1
  84. package/dist/shared/options.d.ts.map +0 -1
  85. package/dist/shared/promise.d.ts.map +0 -1
  86. package/dist/shared/promise.js.map +0 -1
  87. package/dist/shared/tenancy.d.ts.map +0 -1
  88. package/dist/shared/tenancy.js.map +0 -1
  89. package/dist/surface.test.d.ts +0 -2
  90. package/dist/surface.test.d.ts.map +0 -1
  91. package/dist/surface.test.js +0 -38
  92. package/dist/surface.test.js.map +0 -1
  93. package/dist/unsafe.d.ts +0 -41
  94. package/dist/unsafe.d.ts.map +0 -1
  95. package/dist/unsafe.js +0 -52
  96. package/dist/unsafe.js.map +0 -1
  97. /package/dist/{shared → internal}/tenancy.d.ts +0 -0
  98. /package/dist/{shared → internal}/tenancy.js +0 -0
  99. /package/dist/{shared/options.js → options.js} +0 -0
package/dist/index.js CHANGED
@@ -1,52 +1,254 @@
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, updating, authenticating and deleting passkeys.
7
+ *
8
+ * @categoryDescription Passkeys (other)
9
+ * Testing for browser capabilities related to passkeys, type guards and other utilities.
10
+ *
11
+ * @showCategories
12
+ * @module unsafe
13
+ */
1
14
  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";
15
+ import { runToPromiseUnsafe } from "./internal";
16
+ import { eventLogger, Logger } from "./logger";
17
+ import { AuthenticationHelper, authenticatePasskey as authenticatePasskeyM, } from "./passkey/authentication/authentication";
18
+ import { RegistrationHelper, registerPasskey as registerPasskeyM, } from "./passkey/registration/registration";
19
+ import { deletePasskey as deletePasskeyM, isPasskeyDeleteSupport as isPasskeyDeleteSupportM, isPasskeyPruningSupport as isPasskeyPruningSupportM, isPasskeyUpdateSupport as isPasskeyUpdateSupportM, prunePasskeys as prunePasskeysM, signalCredentialRemoval, updatePasskey as updatePasskeyM, } from "./passkey/signals/signals";
8
20
  /* Registration */
9
21
  /**
10
- * Register a passkey on the local device and store the
11
- * associated public key in your Passlock vault.
22
+ * Registers a passkey on the user's device, then saves the server-side component in your vault.
23
+ * If successful, this function returns a `code` or `id_token` (JWT). The code and/or jwt should
24
+ * be sent to your backend for verification. See
25
+ * [register a passkey](https://passlock.dev/passkeys/registration/) in the documentation.
26
+ *
12
27
  * @param options
13
- * @returns
28
+ *
29
+ * @returns A successful registration payload.
30
+ *
31
+ * @see {@link isRegistrationSuccess}
32
+ * @see {@link isPasskeyUnsupportedError}
33
+ * @see {@link isDuplicatePasskeyError}
34
+ * @see {@link isOtherPasskeyError}
35
+ *
36
+ * @throws {@link RegistrationError} (alias to a union of potential errors)
37
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
38
+ * @throws {@link DuplicatePasskeyError} if `allowCredentials` includes a passkey that already exists on the device
39
+ * @throws {@link OtherPasskeyError} typically a low level failure
40
+ * @throws {@link NetworkError}
41
+ *
42
+ * @example
43
+ * // from your Passlock console settings
44
+ * const tenancyId = "myTenancyId";
45
+ * const username = "jdoe@gmail.com";
46
+ *
47
+ * try {
48
+ * const result = await registerPasskey({ tenancyId, username });
49
+ * // send this to your backend for verification
50
+ * console.log(result.code);
51
+ * } catch (error) {
52
+ * if (isPasskeyUnsupportedError(error)) {
53
+ * alert("passkeys not supported on this device");
54
+ * } else {
55
+ * console.error(error);
56
+ * }
57
+ * }
58
+ *
59
+ * @category Passkeys (core)
14
60
  */
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";
61
+ export const registerPasskey = async (options,
62
+ /** @hidden */
63
+ logger = eventLogger) => pipe(registerPasskeyM(options), Micro.provideService(RegistrationHelper, RegistrationHelper.Default), Micro.provideService(Logger, logger), runToPromiseUnsafe);
19
64
  /* Authentication */
20
65
  /**
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.
66
+ * Asks the client to present a passkey, which is then verified against the server-side component in your vault.
67
+ * If successful, this function returns a `code` or `id_token` (JWT). The code and/or jwt should
68
+ * be sent to your backend for verification. See
69
+ * [authenticate a passkey](https://passlock.dev/passkeys/authentication/) in the documentation.
23
70
  *
24
71
  * @param options
25
- * @returns
72
+ *
73
+ * @returns A successful authentication payload.
74
+ *
75
+ * @see {@link isAuthenticationSuccess}
76
+ * @see {@link isPasskeyUnsupportedError}
77
+ * @see {@link isPasskeyNotFoundError}
78
+ * @see {@link isOtherPasskeyError}
79
+ *
80
+ * @throws {@link AuthenticationError} (alias to a union of potential errors)
81
+ * @throws {@link PasskeyUnsupportedError} if the device does not support passkeys
82
+ * @throws {@link PasskeyNotFoundError} if the passkey is orhpaned i.e. deleted from the vault but still present on the local device
83
+ * @throws {@link OtherPasskeyError} typically a low level failure
84
+ * @throws {@link NetworkError}
85
+ *
86
+ * @example
87
+ * // from your Passlock console settings
88
+ * const tenancyId = "myTenancyId";
89
+ *
90
+ * try {
91
+ * const result = await authenticatePasskey({ tenancyId });
92
+ * // send this to your backend for verification
93
+ * console.log(result.code);
94
+ * } catch (error) {
95
+ * if (isPasskeyUnsupportedError(error)) {
96
+ * alert("passkeys not supported on this device");
97
+ * } else {
98
+ * console.error(error);
99
+ * }
100
+ * }
101
+ *
102
+ * @category Passkeys (core)
26
103
  */
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";
104
+ export const authenticatePasskey = (options,
105
+ /** @hidden */
106
+ logger = eventLogger) => pipe(authenticatePasskeyM(options), Micro.provideService(AuthenticationHelper, AuthenticationHelper.Default), Micro.provideService(Logger, logger), runToPromiseUnsafe);
29
107
  /* 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) => {
108
+ /**
109
+ * Attempt to update the username or display name for a passkey (client-side only).
110
+ *
111
+ * Useful if the user has changed their account identifier. For example, they register
112
+ * using jdoe@gmail.com but later change their account username to jdoe@yahoo.com.
113
+ * Even after you update their account details in your backend, their local password
114
+ * manager will continue to display jdoe@gmail.com.
115
+ *
116
+ * By calling this function and supplying a new username/display name, their local
117
+ * password manager will align with their updated account identifier.
118
+ *
119
+ * @param options
120
+ * @returns Update status
121
+ * @see {@link isUpdateError}
122
+ * @throws {@link UpdateError} if the passkey cannot be updated
123
+ *
124
+ * @example
125
+ * // from your Passlock console settings
126
+ * const tenancyId = "myTenancyId";
127
+ * const passkeyId = "myPasskeyId";
128
+ * const username = "newUsername@gmail.com";
129
+ * const displayName = "New Account Name";
130
+ *
131
+ * try {
132
+ * const result = await updatePasskey({ tenancyId, passkeyId, username, displayName });
133
+ * console.log("passkey updated");
134
+ * } catch (error) {
135
+ * console.error(error);
136
+ * }
137
+ *
138
+ * @category Passkeys (core)
139
+ */
140
+ export const updatePasskey = (options,
141
+ /** @hidden */
142
+ logger = eventLogger) => {
143
+ const micro = updatePasskeyM(options);
144
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
145
+ };
146
+ /**
147
+ * Attempts to delete a passkey from a local device. There are two scenarios in which this function proves useful:
148
+ *
149
+ * 1. **Deleting a passkey**. Use the `@passlock/node` package or make vanilla REST calls from your
150
+ * backend to delete the server-side component, then use this function to delete the client-side component.
151
+ *
152
+ * 2. **Missing passkey**. The user tried to present a passkey, but the server-side component could not be found.
153
+ * Remove the passkey from the local device to prevent it happening again.
154
+ *
155
+ * See [deleting passkeys](https://passlock.dev/passkeys/passkey-removal/) and
156
+ * [handling missing passkeys](https://passlock.dev/handling-missing-passkeys/) in the documentation.
157
+ *
158
+ * @param identifiers Passkey identifier or credential mapping.
159
+ * @param options Passlock tenancy and endpoint options.
160
+ * @returns Delete status
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(passkeyId, { tenancyId });
171
+ * console.log("passkey deleted");
172
+ * } catch (error) {
173
+ * console.error(error);
174
+ * }
175
+ *
176
+ * @category Passkeys (core)
177
+ */
178
+ export const deletePasskey = (identifiers, options,
179
+ /** @hidden */
180
+ logger = eventLogger) => {
34
181
  const micro = typeof identifiers === "string"
35
182
  ? deletePasskeyM(identifiers, options)
36
183
  : signalCredentialRemoval(identifiers);
37
- return pipe(micro, Micro.provideService(Logger, logger), runToPromise);
184
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
38
185
  };
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);
43
- };
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);
186
+ /**
187
+ * Attempt to prune local passkeys by keeping only the passkey IDs you trust.
188
+ *
189
+ * This is useful when your backend is the source of truth for which passkeys
190
+ * should still exist for a given account on this device.
191
+ *
192
+ * @param passkeyIds IDs to keep on-device.
193
+ * @param options Passlock tenancy and endpoint options.
194
+ * @returns `true` if local passkeys were pruned.
195
+ * @see {@link isPruningError}
196
+ *
197
+ * @throws {@link PruningError}
198
+ *
199
+ * @example
200
+ * // from your Passlock console settings
201
+ * const tenancyId = "myTenancyId";
202
+ * const activePasskeyIds = ["passkey-1", "passkey-2"];
203
+ *
204
+ * try {
205
+ * const result = await prunePasskeys(activePasskeyIds, { tenancyId });
206
+ * console.log("local passkeys pruned", result);
207
+ * } catch (error) {
208
+ * if (isPruningError(error)) {
209
+ * console.error(error.code);
210
+ * } else {
211
+ * console.error(error);
212
+ * }
213
+ * }
214
+ *
215
+ * @category Passkeys (core)
216
+ */
217
+ export const prunePasskeys = (passkeyIds, options,
218
+ /** @hidden */
219
+ logger = eventLogger) => {
220
+ const micro = prunePasskeysM(passkeyIds, options);
221
+ return pipe(micro, Micro.provideService(Logger, logger), runToPromiseUnsafe);
48
222
  };
49
- export { isUpdateError, UpdateError } from "./passkey/signals";
50
223
  /* Support */
51
- export { isAutofillSupport, isPasskeySupport } from "./passkey/support";
224
+ /**
225
+ * Does the local device support programmatic passkey deletion
226
+ *
227
+ * @returns `true` if local passkey deletion is supported.
228
+ *
229
+ * @category Passkeys (other)
230
+ */
231
+ export const isPasskeyDeleteSupport = () => pipe(isPasskeyDeleteSupportM, Micro.runSync);
232
+ /**
233
+ * Does the local device support programmatic passkey pruning
234
+ *
235
+ * @returns `true` if local passkey pruning is supported.
236
+ *
237
+ * @category Passkeys (other)
238
+ */
239
+ export const isPasskeyPruningSupport = () => pipe(isPasskeyPruningSupportM, Micro.runSync);
240
+ /**
241
+ * Does the local device support programmatic passkey updates
242
+ *
243
+ * @returns `true` if local passkey updates are supported.
244
+ *
245
+ * @category Passkeys (other)
246
+ */
247
+ export const isPasskeyUpdateSupport = () => pipe(isPasskeyUpdateSupportM, Micro.runSync);
248
+ export { isNetworkError } from "./internal/network";
249
+ export { LogEvent, Logger, LogLevel, } from "./logger";
250
+ export { AuthenticationHelper, isAuthenticationSuccess, } from "./passkey/authentication/authentication";
251
+ export { DeleteError, DuplicatePasskeyError, isDeleteError, isDuplicatePasskeyError, isOtherPasskeyError, isPasskeyNotFoundError, isPasskeyUnsupportedError, isPruningError, isUpdateError, OtherPasskeyError, PasskeyNotFoundError, PasskeyUnsupportedError, PruningError, UpdateError, } from "./passkey/errors";
252
+ export { isRegistrationSuccess, RegistrationHelper, } from "./passkey/registration/registration";
253
+ export { isAutofillSupport, isPasskeySupport, } from "./passkey/support";
52
254
  //# 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":"AAcA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EACL,oBAAoB,EACpB,mBAAmB,IAAI,oBAAoB,GAC5C,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAEL,kBAAkB,EAGlB,eAAe,IAAI,gBAAgB,GACpC,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,aAAa,IAAI,cAAc,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,MAAM,qCAAqC,CAAA;AAM5C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from "./network";
2
+ export * from "./promise";
3
+ export * from "./tenancy";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from "./network";
2
+ export * from "./promise";
3
+ export * from "./tenancy";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
@@ -1,13 +1,14 @@
1
1
  import { Context, Micro } from "effect";
2
- export declare const isUnexpectedError: (err: unknown) => err is UnexpectedError;
3
- declare const UnexpectedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Micro.YieldableError & {
4
- readonly _tag: "@error/UnexpectedError";
5
- } & Readonly<A>;
6
- export declare class UnexpectedError extends UnexpectedError_base<{
2
+ export declare const isNetworkError: (payload: unknown) => payload is NetworkError;
3
+ export declare class NetworkError extends Error {
4
+ readonly _tag: "NetworkError";
7
5
  readonly message: string;
8
6
  readonly url: string;
9
- }> {
10
- static isUnexpectedError: (err: unknown) => err is UnexpectedError;
7
+ constructor({ message, url }: {
8
+ message: string;
9
+ url: string;
10
+ });
11
+ static isNetworkError: (payload: unknown) => payload is NetworkError;
11
12
  }
12
13
  declare const Endpoint_base: Context.TagClass<Endpoint, "Endpoint", {
13
14
  readonly endpoint: string;
@@ -17,16 +18,10 @@ declare const Endpoint_base: Context.TagClass<Endpoint, "Endpoint", {
17
18
  */
18
19
  export declare class Endpoint extends Endpoint_base {
19
20
  }
20
- export declare const buildEndpoint: ({ endpoint, }: {
21
+ export declare const makeEndpoint: ({ endpoint, }: {
21
22
  endpoint?: string;
22
23
  }) => Endpoint["Type"];
23
- /**
24
- * Make a fetch request and parse the response using the provided
25
- * responsePredicate function.
26
- * @param param0
27
- * @returns
28
- */
29
- export declare const makeRequest: <A extends object, E = never>({ url, payload, responsePredicate, errorPredicate, label, }: {
24
+ export type RequestOptions<A extends object, E = never> = {
30
25
  url: URL;
31
26
  /** Request payload */
32
27
  payload: object;
@@ -36,6 +31,14 @@ export declare const makeRequest: <A extends object, E = never>({ url, payload,
36
31
  errorPredicate?: (res: unknown, status: number) => res is E;
37
32
  /** For logging/error reporting */
38
33
  label: string;
39
- }) => Micro.Micro<A, E | UnexpectedError>;
34
+ };
35
+ /**
36
+ * Make a fetch request and parse the response using the provided
37
+ * responsePredicate function.
38
+ *
39
+ * @param options Request options.
40
+ * @returns A Micro effect that resolves with the typed response payload.
41
+ */
42
+ export declare const makeRequest: <A extends object, E = never>({ url, payload, responsePredicate, errorPredicate, label, }: RequestOptions<A, E>) => Micro.Micro<A, E | NetworkError>;
40
43
  export {};
41
44
  //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/internal/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEvC,eAAO,MAAM,cAAc,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,YAI5D,CAAA;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAG,cAAc,CAAS;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;gBAER,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAM9D,MAAM,CAAC,cAAc,YAjBiB,OAAO,KAAG,OAAO,IAAI,YAAY,CAiBjC;CACvC;;uBAiBsB,MAAM;;AAL7B;;GAEG;AACH,qBAAa,QAAS,SAAQ,aAG3B;CAAG;AAEN,eAAO,MAAM,YAAY,GAAI,eAE1B;IACD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,KAAG,QAAQ,CAAC,MAAM,CAA8B,CAAA;AAwBjD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,GAAG,KAAK,IAAI;IACxD,GAAG,EAAE,GAAG,CAAA;IAER,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAA;IAEf,0BAA0B;IAC1B,iBAAiB,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,GAAG,IAAI,CAAC,CAAA;IAE7C,gCAAgC;IAChC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,GAAG,IAAI,CAAC,CAAA;IAE3D,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,GAAG,KAAK,EAAE,6DAMtD,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,YAAY,CA0ErD,CAAA"}
@@ -1,24 +1,36 @@
1
1
  import { Context, Micro } from "effect";
2
+ export const isNetworkError = (payload) => {
3
+ if (typeof payload !== "object")
4
+ return false;
5
+ if (payload === null)
6
+ return false;
7
+ return payload instanceof NetworkError;
8
+ };
9
+ export class NetworkError extends Error {
10
+ _tag = "NetworkError";
11
+ message;
12
+ url;
13
+ constructor({ message, url }) {
14
+ super();
15
+ this.message = message;
16
+ this.url = url;
17
+ }
18
+ static isNetworkError = isNetworkError;
19
+ }
2
20
  /**
3
- * Make a request to the Passlock API endpoint.
4
- * Assumes the response is JSON and any errors
5
- * have a non-200 status code, are also JSON and
6
- * include message and _tag fields.
7
- */
8
- /**
21
+ * Make a request to the Passlock API endpoint. Assumes the response is
22
+ * JSON and any errors have a non-200 status code, are also JSON and include
23
+ * message and _tag fields.
24
+ *
9
25
  * TODO Consider Effect RPC/HttpClient
10
26
  */
11
- const DefaultEndpoint = "https://api.passlock.dev";
12
- export const isUnexpectedError = (err) => err instanceof UnexpectedError;
13
- export class UnexpectedError extends Micro.TaggedError("@error/UnexpectedError") {
14
- static isUnexpectedError = isUnexpectedError;
15
- }
27
+ const DEFAULT_ENDPOINT = "https://api.passlock.dev";
16
28
  /**
17
29
  * Passlock API endpoint
18
30
  */
19
31
  export class Endpoint extends Context.Tag("Endpoint")() {
20
32
  }
21
- export const buildEndpoint = ({ endpoint = DefaultEndpoint, }) => Endpoint.of({ endpoint });
33
+ export const makeEndpoint = ({ endpoint = DEFAULT_ENDPOINT, }) => Endpoint.of({ endpoint });
22
34
  const isErrorResponse = (payload) => {
23
35
  if (typeof payload !== "object")
24
36
  return false;
@@ -37,8 +49,9 @@ const isErrorResponse = (payload) => {
37
49
  /**
38
50
  * Make a fetch request and parse the response using the provided
39
51
  * responsePredicate function.
40
- * @param param0
41
- * @returns
52
+ *
53
+ * @param options Request options.
54
+ * @returns A Micro effect that resolves with the typed response payload.
42
55
  */
43
56
  export const makeRequest = ({ url, payload, responsePredicate, errorPredicate = (res) => false, label, }) => Micro.gen(function* () {
44
57
  const isUnderTest = typeof process !== "undefined" && process.env.VITEST === "true";
@@ -50,15 +63,15 @@ export const makeRequest = ({ url, payload, responsePredicate, errorPredicate =
50
63
  ...(isUnderTest ? { Origin: "http://localhost:3000" } : {}),
51
64
  };
52
65
  const body = JSON.stringify(payload);
53
- const networkError = new UnexpectedError({
66
+ const networkError = new NetworkError({
54
67
  message: "Fetch failed",
55
68
  url: String(url),
56
69
  });
57
- const parseError = new UnexpectedError({
70
+ const parseError = new NetworkError({
58
71
  message: "Unable to parse JSON response",
59
72
  url: String(url),
60
73
  });
61
- const invalidResponsePayload = new UnexpectedError({
74
+ const invalidResponsePayload = new NetworkError({
62
75
  message: `Invalid ${label} response`,
63
76
  url: String(url),
64
77
  });
@@ -70,33 +83,35 @@ export const makeRequest = ({ url, payload, responsePredicate, errorPredicate =
70
83
  const isJsonResponse = contentType === "application/json";
71
84
  if (!fetchResponse.ok && isJsonResponse) {
72
85
  const apiError = yield* Micro.tryPromise({
73
- catch: () => parseError,
74
86
  try: () => fetchResponse.json(),
87
+ catch: () => parseError,
75
88
  });
76
89
  if (errorPredicate(apiError, fetchResponse.status)) {
77
90
  return yield* Micro.fail(apiError);
78
91
  }
79
92
  else if (isErrorResponse(apiError)) {
80
- return yield* new UnexpectedError({
93
+ return yield* Micro.fail(new NetworkError({
81
94
  ...apiError,
82
95
  url: String(url),
83
- });
96
+ }));
84
97
  }
85
98
  else {
86
- return yield* parseError;
99
+ return yield* Micro.fail(parseError);
87
100
  }
88
101
  }
89
102
  else if (!fetchResponse.ok) {
90
103
  const message = yield* Micro.promise(() => fetchResponse.text());
91
- return yield* new UnexpectedError({
104
+ return yield* Micro.fail(new NetworkError({
92
105
  message,
93
106
  url: String(url),
94
- });
107
+ }));
95
108
  }
96
109
  const json = yield* Micro.tryPromise({
97
- catch: () => parseError,
98
110
  try: () => fetchResponse.json(),
111
+ catch: () => parseError,
99
112
  });
100
- return responsePredicate(json) ? json : yield* invalidResponsePayload;
113
+ return responsePredicate(json)
114
+ ? json
115
+ : yield* Micro.fail(invalidResponsePayload);
101
116
  });
102
117
  //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/internal/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEvC,MAAM,CA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AAI,YAAY,CAAC;YACf,OAAO;YACP,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;SACjB,CAAC,CACH,CAAA;IACH,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;QACnC,GAAG,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,EAAsB;QACnD,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU;KACxB,CAAC,CAAA;IAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAC5B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;AAC/C,CAAC,CAAC,CAAA"}
@@ -3,13 +3,13 @@ import { Micro } from "effect";
3
3
  * Run a Micro and return a success or failure.
4
4
  * Note: function could still throw for an unexpected error.
5
5
  * @param micro
6
- * @returns
6
+ * @returns Promise resolving to either the success value or error value.
7
7
  */
8
8
  export declare const runToPromise: <A, E>(micro: Micro.Micro<A, E>) => Promise<A | E>;
9
9
  /**
10
10
  * Run a Micro and return a success or throw an error
11
11
  * @param micro
12
- * @returns
12
+ * @returns Promise resolving to the success value.
13
13
  */
14
14
  export declare const runToPromiseUnsafe: <A, E>(micro: Micro.Micro<A, E>) => Promise<A>;
15
15
  //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/internal/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAQ,MAAM,QAAQ,CAAA;AAGtD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,EAAE,CAAC,EACrC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KACvB,OAAO,CAAC,CAAC,GAAG,CAAC,CAOf,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAU,CAAC,EAAE,CAAC,EAC3C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KACvB,OAAO,CAAC,CAAC,CAqBX,CAAA"}
@@ -4,7 +4,7 @@ import { error } from "effect/Brand";
4
4
  * Run a Micro and return a success or failure.
5
5
  * Note: function could still throw for an unexpected error.
6
6
  * @param micro
7
- * @returns
7
+ * @returns Promise resolving to either the success value or error value.
8
8
  */
9
9
  export const runToPromise = async (micro) => {
10
10
  const either = await pipe(micro, Micro.either, Micro.runPromise);
@@ -16,7 +16,7 @@ export const runToPromise = async (micro) => {
16
16
  /**
17
17
  * Run a Micro and return a success or throw an error
18
18
  * @param micro
19
- * @returns
19
+ * @returns Promise resolving to the success value.
20
20
  */
21
21
  export const runToPromiseUnsafe = async (micro) => {
22
22
  const exit = await Micro.runPromiseExit(micro);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/internal/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,KAAwB,EACR,EAAE;IAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IAEhE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,QAAQ;KAClB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,KAAwB,EACZ,EAAE;IACd,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAE9C,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAA;IAEhD,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,KAAK,CAAA;QAClB,CAAC;;YAAM,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAClD,CAAC;IAED,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,YAAY,KAAK,EAAE,CAAC;YACvC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;QACzB,CAAC;;YAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAEpE,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;;QAC7D,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;AAC1C,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy.d.ts","sourceRoot":"","sources":["../../src/internal/tenancy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;;wBAIR,MAAM;;AAF9B,qBAAa,SAAU,SAAQ,cAG5B;CAAG"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy.js","sourceRoot":"","sources":["../../src/internal/tenancy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhC,MAAM,OAAO,SAAU,SAAQ,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAGpD;CAAG"}
@@ -1,19 +1,29 @@
1
1
  import { Context, Micro } from "effect";
2
- declare const Logger_base: Context.TagClass<Logger, "Logger", {
2
+ declare const Logger_base: Context.TagClass<Logger, "ClientLogger", {
3
3
  readonly logDebug: (message: string) => Micro.Micro<void>;
4
4
  readonly logInfo: (message: string) => Micro.Micro<void>;
5
5
  readonly logWarn: (message: string) => Micro.Micro<void>;
6
6
  readonly logError: (message: string) => Micro.Micro<void>;
7
7
  }>;
8
+ /**
9
+ * Allows us to plug in specific implementations.
10
+ * @see consoleLogger and eventLogger
11
+ */
8
12
  export declare class Logger extends Logger_base {
9
13
  }
10
- export declare const ConsoleLogger: typeof Logger.Service;
14
+ /**
15
+ * Logs to the JS console
16
+ */
17
+ export declare const consoleLogger: typeof Logger.Service;
11
18
  export declare enum LogLevel {
12
19
  DEBUG = "DEBUG",
13
20
  INFO = "INFO",
14
21
  ERROR = "ERROR",
15
22
  WARN = "WARN"
16
23
  }
24
+ /**
25
+ * Custom event representing a log message
26
+ */
17
27
  export declare class LogEvent extends Event {
18
28
  #private;
19
29
  static name: string;
@@ -21,6 +31,11 @@ export declare class LogEvent extends Event {
21
31
  get message(): string;
22
32
  get level(): LogLevel;
23
33
  }
24
- export declare const EventLogger: typeof Logger.Service;
34
+ /**
35
+ * Fires JS events instead of writing to the console.
36
+ * Hook into it by listening for PasslockLogEvent events
37
+ * @see LogEvent
38
+ */
39
+ export declare const eventLogger: typeof Logger.Service;
25
40
  export {};
26
- //# sourceMappingURL=index.d.ts.map
41
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;;uBAShB,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;sBACvC,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;sBACtC,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;uBACrC,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;;AAV7D;;;GAGG;AACH,qBAAa,MAAO,SAAQ,WAQzB;CAAG;AAEN;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC,OAoBzC,CAAA;AAED,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;;IAIjC,MAAM,CAAC,IAAI,SAAqB;gBAEpB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ;IAM5C,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,KAAK,IAAI,QAAQ,CAEpB;CACF;AASD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC,OAKvC,CAAA"}