@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/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,EAC/B,wBAAwB,IAAI,yBAAyB,EACrD,oBAAoB,IAAI,qBAAqB,EAC7C,sBAAsB,IAAI,uBAAuB,EACjD,uBAAuB,EACvB,YAAY,IAAI,aAAa,EAC7B,iBAAiB,IAAI,kBAAkB,GACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAG/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MA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BAAuB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAC1C,IAAI,CAAC,wBAAwB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CACzC,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;AAE9C,gBAAgB;AAEhB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EACL,QAAQ,EACR,MAAM,EACN,QAAQ,GACT,MAAM,UAAU,CAAA;AAUjB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,WAAW,GACZ,MAAM,kBAAkB,CAAA;AAQzB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qCAAqC,CAAA;AAa5C,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,2BAA2B,CAAA;AAClC,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: "@error/Network";
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,gBAAgB,CAAS;IACzC,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;;uBAmBsB,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,38 @@
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 = "@error/Network";
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
21
  * 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
- /**
22
+ * Successful responses are expected to be JSON.
23
+ * For non-2xx responses this function first attempts to parse JSON so typed
24
+ * API errors can be returned, and falls back to a generic network error when
25
+ * parsing fails.
26
+ *
9
27
  * TODO Consider Effect RPC/HttpClient
10
28
  */
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
- }
29
+ const DEFAULT_ENDPOINT = "https://api.passlock.dev";
16
30
  /**
17
31
  * Passlock API endpoint
18
32
  */
19
33
  export class Endpoint extends Context.Tag("Endpoint")() {
20
34
  }
21
- export const buildEndpoint = ({ endpoint = DefaultEndpoint, }) => Endpoint.of({ endpoint });
35
+ export const makeEndpoint = ({ endpoint = DEFAULT_ENDPOINT, }) => Endpoint.of({ endpoint });
22
36
  const isErrorResponse = (payload) => {
23
37
  if (typeof payload !== "object")
24
38
  return false;
@@ -37,8 +51,9 @@ const isErrorResponse = (payload) => {
37
51
  /**
38
52
  * Make a fetch request and parse the response using the provided
39
53
  * responsePredicate function.
40
- * @param param0
41
- * @returns
54
+ *
55
+ * @param options Request options.
56
+ * @returns A Micro effect that resolves with the typed response payload.
42
57
  */
43
58
  export const makeRequest = ({ url, payload, responsePredicate, errorPredicate = (res) => false, label, }) => Micro.gen(function* () {
44
59
  const isUnderTest = typeof process !== "undefined" && process.env.VITEST === "true";
@@ -50,15 +65,15 @@ export const makeRequest = ({ url, payload, responsePredicate, errorPredicate =
50
65
  ...(isUnderTest ? { Origin: "http://localhost:3000" } : {}),
51
66
  };
52
67
  const body = JSON.stringify(payload);
53
- const networkError = new UnexpectedError({
68
+ const networkError = new NetworkError({
54
69
  message: "Fetch failed",
55
70
  url: String(url),
56
71
  });
57
- const parseError = new UnexpectedError({
72
+ const parseError = new NetworkError({
58
73
  message: "Unable to parse JSON response",
59
74
  url: String(url),
60
75
  });
61
- const invalidResponsePayload = new UnexpectedError({
76
+ const invalidResponsePayload = new NetworkError({
62
77
  message: `Invalid ${label} response`,
63
78
  url: String(url),
64
79
  });
@@ -70,33 +85,35 @@ export const makeRequest = ({ url, payload, responsePredicate, errorPredicate =
70
85
  const isJsonResponse = contentType === "application/json";
71
86
  if (!fetchResponse.ok && isJsonResponse) {
72
87
  const apiError = yield* Micro.tryPromise({
73
- catch: () => parseError,
74
88
  try: () => fetchResponse.json(),
89
+ catch: () => parseError,
75
90
  });
76
91
  if (errorPredicate(apiError, fetchResponse.status)) {
77
92
  return yield* Micro.fail(apiError);
78
93
  }
79
94
  else if (isErrorResponse(apiError)) {
80
- return yield* new UnexpectedError({
95
+ return yield* Micro.fail(new NetworkError({
81
96
  ...apiError,
82
97
  url: String(url),
83
- });
98
+ }));
84
99
  }
85
100
  else {
86
- return yield* parseError;
101
+ return yield* Micro.fail(parseError);
87
102
  }
88
103
  }
89
104
  else if (!fetchResponse.ok) {
90
105
  const message = yield* Micro.promise(() => fetchResponse.text());
91
- return yield* new UnexpectedError({
106
+ return yield* Micro.fail(new NetworkError({
92
107
  message,
93
108
  url: String(url),
94
- });
109
+ }));
95
110
  }
96
111
  const json = yield* Micro.tryPromise({
97
- catch: () => parseError,
98
112
  try: () => fetchResponse.json(),
113
+ catch: () => parseError,
99
114
  });
100
- return responsePredicate(json) ? json : yield* invalidResponsePayload;
115
+ return responsePredicate(json)
116
+ ? json
117
+ : yield* Micro.fail(invalidResponsePayload);
101
118
  });
102
119
  //# 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,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAA2B,EAAE;IAC1E,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7C,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAClC,OAAO,OAAO,YAAY,YAAY,CAAA;AACxC,CAAC,CAAA;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,GAAG,gBAAyB,CAAA;IAChC,OAAO,CAAQ;IACf,GAAG,CAAQ;IAEpB,YAAY,EAAE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AC,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"}
@@ -1,18 +1,25 @@
1
1
  import { Context, Micro } from "effect";
2
- export class Logger extends Context.Tag("Logger")() {
2
+ /**
3
+ * Allows us to plug in specific implementations.
4
+ * @see consoleLogger and eventLogger
5
+ */
6
+ export class Logger extends Context.Tag("ClientLogger")() {
3
7
  }
4
- export const ConsoleLogger = {
8
+ /**
9
+ * Logs to the JS console
10
+ */
11
+ export const consoleLogger = {
5
12
  logDebug: (message, ...optionalArgs) => Micro.sync(() => {
6
- console.debug(message, optionalArgs);
13
+ console.log(message, optionalArgs);
7
14
  }),
8
15
  logError: (message, ...optionalArgs) => Micro.sync(() => {
9
- console.error(message, optionalArgs);
16
+ console.log(message, optionalArgs);
10
17
  }),
11
18
  logInfo: (message, ...optionalArgs) => Micro.sync(() => {
12
- console.info(message, optionalArgs);
19
+ console.log(message, optionalArgs);
13
20
  }),
14
21
  logWarn: (message, ...optionalArgs) => Micro.sync(() => {
15
- console.warn(message, optionalArgs);
22
+ console.log(message, optionalArgs);
16
23
  }),
17
24
  };
18
25
  export var LogLevel;
@@ -22,6 +29,9 @@ export var LogLevel;
22
29
  LogLevel["ERROR"] = "ERROR";
23
30
  LogLevel["WARN"] = "WARN";
24
31
  })(LogLevel || (LogLevel = {}));
32
+ /**
33
+ * Custom event representing a log message
34
+ */
25
35
  export class LogEvent extends Event {
26
36
  #message;
27
37
  #level;
@@ -43,10 +53,15 @@ const logEvent = (level) => (message) => Micro.sync(() => {
43
53
  window.dispatchEvent(new LogEvent(message, level));
44
54
  }
45
55
  });
46
- export const EventLogger = {
56
+ /**
57
+ * Fires JS events instead of writing to the console.
58
+ * Hook into it by listening for PasslockLogEvent events
59
+ * @see LogEvent
60
+ */
61
+ export const eventLogger = {
47
62
  logDebug: logEvent(LogLevel.DEBUG),
48
63
  logError: logEvent(LogLevel.ERROR),
49
64
  logInfo: logEvent(LogLevel.INFO),
50
65
  logWarn: logEvent(LogLevel.WARN),
51
66
  };
52
- //# sourceMappingURL=index.js.map
67
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEvC;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAQpD;CAAG;AAEN;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,QAAQ,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACtE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACpC,CAAC,CAAC;IAEJ,QAAQ,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACtE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACpC,CAAC,CAAC;IAEJ,OAAO,EAAE,CAAC,OAAwB,EAAE,GAAG,YAA4B,EAAE,EAAE,CACrE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,GAA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AAQ,CAAC,KAAK,CAAC;IAClC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;IAChC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;CACjC,CAAA"}
@@ -10,6 +10,10 @@ export interface PasslockOptions {
10
10
  * environment will have a different tenancyId to prod.
11
11
  */
12
12
  tenancyId: string;
13
+ /**
14
+ * Currently used for testing, but also required to support
15
+ * multi-region deployments and on-premise self-hosted setups.
16
+ */
13
17
  endpoint?: string;
14
18
  }
15
19
  //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/shared/options.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,145 @@
1
+ import * as Helper from "@simplewebauthn/browser";
2
+ import { type AuthenticationResponseJSON, type PublicKeyCredentialRequestOptionsJSON } from "@simplewebauthn/browser";
3
+ import { Micro } from "effect";
4
+ import type { Principal } from "src/principal";
5
+ import { Endpoint, TenancyId } from "../../internal";
6
+ import type { NetworkError } from "../../internal/network";
7
+ import { Logger } from "../../logger";
8
+ import type { PasslockOptions } from "../../options";
9
+ import { OrphanedPasskeyError, OtherPasskeyError, PasskeyUnsupportedError } from "../errors";
10
+ import type { Millis, UserVerification } from "../shared";
11
+ /**
12
+ * Passkey authentication options
13
+ *
14
+ * @see {@link authenticatePasskey}
15
+ *
16
+ * @category Passkeys (core)
17
+ */
18
+ export interface AuthenticationOptions extends PasslockOptions {
19
+ /**
20
+ * Restrict the passkey(s) the device presents to the user to a given set
21
+ *
22
+ * @see {@link https://passlock.dev/passkeys/allow-credentials/ allowCredentials (main docs)}
23
+ */
24
+ allowCredentials?: Array<string> | undefined;
25
+ /**
26
+ * Whether the device should re-authenticate the user locally before
27
+ * authenticating with a passkey.
28
+ *
29
+ * @see {@link https://passlock.dev/passkeys/user-verification/ userVerification (main docs)}
30
+ */
31
+ userVerification?: UserVerification | undefined;
32
+ /**
33
+ * Use browser autofill.
34
+ *
35
+ * @see {@link https://passlock.dev/passkeys/autofill/ autofill (main docs)}
36
+ */
37
+ autofill?: boolean | undefined;
38
+ /**
39
+ * Receive notifications about key stages in the authentication process.
40
+ * For example, you might use event notifications to toggle loading icons or
41
+ * to disable certain form fields.
42
+ */
43
+ onEvent?: OnAuthenticationEvent | undefined;
44
+ /**
45
+ * Abort the operation after N milliseconds
46
+ */
47
+ timeout?: Millis | undefined;
48
+ }
49
+ export declare const AuthenticationSuccessTag: "AuthenticationSuccess";
50
+ export type AuthenticationSuccessTag = typeof AuthenticationSuccessTag;
51
+ /**
52
+ * Represents the outcome of a successful passkey authentication.
53
+ * Submit the `code` and/or `id_token` to your backend, then either
54
+ * exchange the code with the Passlock REST API or decode and
55
+ * verify the id_token (JWT). **note:** The @passlock/node library
56
+ * includes utilities for this.
57
+ *
58
+ * @see {@link isAuthenticationSuccess}
59
+ *
60
+ * @category Passkeys (core)
61
+ */
62
+ export type AuthenticationSuccess = {
63
+ /**
64
+ * Discriminator for use in a discriminated union.
65
+ */
66
+ _tag: "AuthenticationSuccess";
67
+ principal: Principal;
68
+ /**
69
+ * A signed JWT representing the authenticated passkey.
70
+ * Decode and verify this in your backend or use one of the @passlock/node
71
+ * helper utilities.
72
+ *
73
+ * @see {@link https://passlock.dev/principal/idtoken-verification/|id_token}
74
+ */
75
+ id_token: string;
76
+ /**
77
+ * Call the Passlock API to exchange this code for details about the
78
+ * authenticated passkey.
79
+ *
80
+ * @see {@link https://passlock.dev/principal/code-exchange/|code exchange}
81
+ */
82
+ code: string;
83
+ };
84
+ /**
85
+ * Type guard to narrow something down to an {@link AuthenticationSuccess}
86
+ *
87
+ * @param payload
88
+ * @returns `true` if the payload is an {@link AuthenticationSuccess}.
89
+ *
90
+ * @category Passkeys (other)
91
+ */
92
+ export declare const isAuthenticationSuccess: (payload: unknown) => payload is AuthenticationSuccess;
93
+ export declare const fetchOptions: (options: Omit<AuthenticationOptions, keyof PasslockOptions>) => Micro.Micro<OptionsResponse, NetworkError, Endpoint | TenancyId | Logger>;
94
+ export type OptionsResponse = {
95
+ sessionToken: string;
96
+ optionsJSON: PublicKeyCredentialRequestOptionsJSON;
97
+ };
98
+ export declare const isOptionsResponse: (payload: unknown) => payload is OptionsResponse;
99
+ export declare const startAuthentication: (optionsJSON: PublicKeyCredentialRequestOptionsJSON, { useBrowserAutofill, onEvent, }: {
100
+ useBrowserAutofill: boolean;
101
+ onEvent?: OnAuthenticationEvent | undefined;
102
+ }) => Micro.Micro<Helper.AuthenticationResponseJSON, PasskeyUnsupportedError | OtherPasskeyError, Logger | AuthenticationHelper>;
103
+ export declare const verifyCredential: (sessionToken: string, response: AuthenticationResponseJSON, { onEvent }: {
104
+ onEvent?: OnAuthenticationEvent | undefined;
105
+ }) => Micro.Micro<AuthenticationSuccess, NetworkError | OrphanedPasskeyError, Endpoint | TenancyId | Logger>;
106
+ /**
107
+ * Potential errors associated with Passkey authentication
108
+ *
109
+ * @category Passkeys (errors)
110
+ */
111
+ export type AuthenticationError = PasskeyUnsupportedError | OtherPasskeyError | OrphanedPasskeyError | NetworkError;
112
+ /**
113
+ * Trigger local passkey authentication then verify the passkey in your Passlock vault.
114
+ * Returns a code and id_token that can be exchanged/decoded in your backend.
115
+ *
116
+ * @param options
117
+ * @returns A Micro effect that resolves with {@link AuthenticationSuccess} or
118
+ * fails with {@link AuthenticationError}.
119
+ */
120
+ export declare const authenticatePasskey: (options: AuthenticationOptions) => Micro.Micro<AuthenticationSuccess, AuthenticationError, Logger | AuthenticationHelper>;
121
+ /**
122
+ * Type of the authentication event
123
+ *
124
+ * @category Passkeys (other)
125
+ */
126
+ export declare const AuthenticationEvents: readonly ["optionsRequest", "getCredential", "verifyCredential"];
127
+ /**
128
+ * Type of the authentication event
129
+ *
130
+ * @category Passkeys (other)
131
+ */
132
+ export type AuthenticationEvent = "optionsRequest" | "getCredential" | "verifyCredential";
133
+ /**
134
+ * Allows you to hook into key lifecycle events.
135
+ *
136
+ * Most commonly used when {@link authenticatePasskey}
137
+ * is called with {@link AuthenticationOptions#autofill}.
138
+ * When autofill is applied the browser will wait for user interaction. By listening
139
+ * for the `verifyCredential` {@link AuthenticationEvent} you know when the user has
140
+ * presented a passkey so you can disable forms/toggle loading icons etc.
141
+ *
142
+ * @category Passkeys (other)
143
+ */
144
+ export type OnAuthenticationEvent = (event: AuthenticationEvent) => void;
145
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/passkey/authentication/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACjD,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,qCAAqC,EAE3C,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAW,KAAK,EAAQ,MAAM,QAAQ,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAA6B,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,WAAW,CA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