@passlock/client 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +14 -16
  2. package/README.template.md +14 -16
  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 +245 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +253 -3
  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 +82 -66
  33. package/dist/passkey/authentication/authentication.d.ts.map +1 -1
  34. package/dist/passkey/authentication/authentication.js +67 -49
  35. package/dist/passkey/authentication/authentication.js.map +1 -1
  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 +81 -72
  41. package/dist/passkey/registration/registration.d.ts.map +1 -1
  42. package/dist/passkey/registration/registration.js +42 -35
  43. package/dist/passkey/registration/registration.js.map +1 -1
  44. package/dist/passkey/{types.d.ts → shared.d.ts} +9 -3
  45. package/dist/passkey/shared.d.ts.map +1 -0
  46. package/dist/passkey/shared.js +2 -0
  47. package/dist/passkey/shared.js.map +1 -0
  48. package/dist/passkey/signals/signals.d.ts +93 -35
  49. package/dist/passkey/signals/signals.d.ts.map +1 -1
  50. package/dist/passkey/signals/signals.js +197 -90
  51. package/dist/passkey/signals/signals.js.map +1 -1
  52. package/dist/passkey/support.d.ts +15 -0
  53. package/dist/passkey/support.d.ts.map +1 -1
  54. package/dist/passkey/support.js +16 -1
  55. package/dist/passkey/support.js.map +1 -1
  56. package/dist/principal.d.ts +16 -0
  57. package/dist/principal.d.ts.map +1 -0
  58. package/dist/principal.js +2 -0
  59. package/dist/principal.js.map +1 -0
  60. package/dist/safe.d.ts +247 -0
  61. package/dist/safe.d.ts.map +1 -0
  62. package/dist/safe.js +254 -0
  63. package/dist/safe.js.map +1 -0
  64. package/package.json +26 -21
  65. package/dist/logger/index.d.ts.map +0 -1
  66. package/dist/logger/index.js.map +0 -1
  67. package/dist/passkey/authentication/authentication.test.d.ts +0 -2
  68. package/dist/passkey/authentication/authentication.test.d.ts.map +0 -1
  69. package/dist/passkey/authentication/authentication.test.js +0 -157
  70. package/dist/passkey/authentication/authentication.test.js.map +0 -1
  71. package/dist/passkey/authentication/index.d.ts +0 -21
  72. package/dist/passkey/authentication/index.d.ts.map +0 -1
  73. package/dist/passkey/authentication/index.js +0 -22
  74. package/dist/passkey/authentication/index.js.map +0 -1
  75. package/dist/passkey/index.d.ts +0 -6
  76. package/dist/passkey/index.d.ts.map +0 -1
  77. package/dist/passkey/index.js +0 -6
  78. package/dist/passkey/index.js.map +0 -1
  79. package/dist/passkey/registration/index.d.ts +0 -19
  80. package/dist/passkey/registration/index.d.ts.map +0 -1
  81. package/dist/passkey/registration/index.js +0 -20
  82. package/dist/passkey/registration/index.js.map +0 -1
  83. package/dist/passkey/registration/registration.test.d.ts +0 -2
  84. package/dist/passkey/registration/registration.test.d.ts.map +0 -1
  85. package/dist/passkey/registration/registration.test.js +0 -161
  86. package/dist/passkey/registration/registration.test.js.map +0 -1
  87. package/dist/passkey/signals/index.d.ts +0 -9
  88. package/dist/passkey/signals/index.d.ts.map +0 -1
  89. package/dist/passkey/signals/index.js +0 -19
  90. package/dist/passkey/signals/index.js.map +0 -1
  91. package/dist/passkey/types.d.ts.map +0 -1
  92. package/dist/passkey/types.js +0 -2
  93. package/dist/passkey/types.js.map +0 -1
  94. package/dist/shared/network.d.ts.map +0 -1
  95. package/dist/shared/network.js.map +0 -1
  96. package/dist/shared/options.d.ts.map +0 -1
  97. package/dist/shared/promise.d.ts.map +0 -1
  98. package/dist/shared/promise.js.map +0 -1
  99. package/dist/shared/tenancy.d.ts.map +0 -1
  100. package/dist/shared/tenancy.js.map +0 -1
  101. /package/dist/{shared → internal}/tenancy.d.ts +0 -0
  102. /package/dist/{shared → internal}/tenancy.js +0 -0
  103. /package/dist/{shared/options.js → options.js} +0 -0
@@ -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
@@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,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,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,cAAuB,CAAA;IAC9B,OAAO,CAAQ;IACf,GAAG,CAAQ;IAEpB,YAAY,EAAE,OAAO,EAAE,GAAG,EAAoC;QAC5D,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,cAAc,GAAG,cAAc,CAAA;;AAGxC;;;;;;GAMG;AAEH,MAAM,gBAAgB,GAAG,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAGlD;CAAG;AAEN,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,QAAQ,GAAG,gBAAgB,GAG5B,EAAoB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ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Q;gBACX,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;aACjB,CAAC,CACH,CAAA;QACH,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAA;QAChE,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CACtB,IAAI,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,MA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AC,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,7 +1,14 @@
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
13
  console.debug(message, optionalArgs);
7
14
  }),
@@ -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,EAA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,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;;AAGH,MAAM,QAAQ,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC,OAAe,EAAE,EAAE,CACxD,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;IACd,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IACpD,CAAC;AACH,CAAC,CAAC,CAAA;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAA0B;IAChD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,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":""}
@@ -1,81 +1,73 @@
1
- import type { PasslockOptions } from "../../shared/options";
2
- import type { UserVerification } from "../types";
3
1
  import * as Helper from "@simplewebauthn/browser";
4
2
  import { type AuthenticationResponseJSON, type PublicKeyCredentialRequestOptionsJSON } from "@simplewebauthn/browser";
5
- import { Context, Micro } from "effect";
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";
6
7
  import { Logger } from "../../logger";
7
- import { Endpoint, type UnexpectedError } from "../../shared/network";
8
- import { TenancyId } from "../../shared/tenancy";
9
- import { OtherPasskeyError, PasskeysUnsupportedError } from "../errors";
10
- interface OptionsResponse {
11
- sessionToken: string;
12
- optionsJSON: PublicKeyCredentialRequestOptionsJSON;
13
- }
14
- declare const AuthenticationHelper_base: Context.TagClass<AuthenticationHelper, "AuthenticationHelper", {
15
- browserSupportsWebAuthn: typeof Helper.browserSupportsWebAuthn;
16
- startAuthentication: typeof Helper.startAuthentication;
17
- }>;
18
- export declare class AuthenticationHelper extends AuthenticationHelper_base {
19
- static Default: {
20
- browserSupportsWebAuthn: typeof Helper.browserSupportsWebAuthn;
21
- startAuthentication: typeof Helper.startAuthentication;
22
- };
23
- }
24
- export declare const authenticationEvent: readonly ["optionsRequest", "getCredential", "verifyCredential"];
25
- export type AuthenticationEvent = (typeof authenticationEvent)[number];
26
- export type OnEventFn = (event: AuthenticationEvent) => void;
8
+ import type { PasslockOptions } from "../../options";
9
+ import { OtherPasskeyError, PasskeyNotFoundError, PasskeyUnsupportedError } from "../errors";
10
+ import type { Millis, UserVerification } from "../shared";
11
+ /**
12
+ * Passkey authentication options
13
+ *
14
+ * @category Passkeys (core)
15
+ */
27
16
  export interface AuthenticationOptions extends PasslockOptions {
28
- /**
29
- * Passlock userId. Essentially a shortcut to look up any
30
- * registered passkeys (allowCredentials) for a given user.
31
- */
32
- userId?: string | undefined;
33
17
  /**
34
18
  * Restrict the passkey(s) the device presents to the user to a given set
35
19
  *
36
- * @see {@link https://passlock.dev/passkeys/authentication/#allowcredentials|allowCredentials}
20
+ * @see {@link https://passlock.dev/passkeys/allow-credentials/|allowCredentials}
37
21
  */
38
22
  allowCredentials?: Array<string> | undefined;
39
23
  /**
40
- * Whether the device should re-authenticate the user locally before registering the passkey.
24
+ * Whether the device should re-authenticate the user locally before
25
+ * authenticating with a passkey.
41
26
  *
42
27
  * @see {@link https://passlock.dev/passkeys/user-verification/|userVerification}
43
28
  */
44
29
  userVerification?: UserVerification | undefined;
45
30
  /**
46
31
  * Use browser autofill.
32
+ *
33
+ * @see {@link https://passlock.dev/passkeys/autofill/|autofill}
47
34
  */
48
- autofill?: boolean;
35
+ autofill?: boolean | undefined;
49
36
  /**
50
37
  * Receive notifications about key stages in the authentication process.
51
38
  * For example, you might use event notifications to toggle loading icons or
52
39
  * to disable certain form fields.
40
+ *
53
41
  * @param event
54
- * @returns
42
+ * @returns Nothing.
43
+ */
44
+ onEvent?: OnAuthenticationEvent | undefined;
45
+ /**
46
+ * Abort the operation after N milliseconds
55
47
  */
56
- onEvent?: OnEventFn;
57
- timeout?: number | undefined;
48
+ timeout?: Millis | undefined;
58
49
  }
59
- export declare const fetchOptions: (options: Omit<AuthenticationOptions, keyof PasslockOptions>) => Micro.Micro<OptionsResponse, UnexpectedError, Logger | Endpoint | TenancyId>;
60
- declare const AuthenticationSuccessTag: "AuthenticationSuccess";
61
- type AuthenticationSuccessTag = typeof AuthenticationSuccessTag;
50
+ export declare const AuthenticationSuccessTag: "AuthenticationSuccess";
51
+ export type AuthenticationSuccessTag = typeof AuthenticationSuccessTag;
62
52
  /**
63
- * Represents the outcome of a successfull passkey authentication.
53
+ * Represents the outcome of a successful passkey authentication.
64
54
  * Submit the code and/or id_token to your backend, then either
65
55
  * exchange the code with the passlock REST API or decode and
66
56
  * verify the id_token (JWT).
67
57
  *
68
- * Note: The @passlock/node library includes utilities to do this
69
- * for you.
58
+ * Note: The @passlock/node library includes utilities to do
59
+ * this for you.
60
+ *
61
+ * @category Passkeys (core)
70
62
  */
71
- export interface AuthenticationSuccess {
72
- _tag: AuthenticationSuccessTag;
73
- principal: {
74
- authenticatorId: string;
75
- userId: string;
76
- };
63
+ export type AuthenticationSuccess = {
64
+ /**
65
+ * Discriminator for use in a discriminated union.
66
+ */
67
+ _tag: "AuthenticationSuccess";
68
+ principal: Principal;
77
69
  /**
78
- * A signed JWT representing the newly registered passkey.
70
+ * A signed JWT representing the authenticated passkey.
79
71
  * Decode and verify this in your backend or use one of the @passlock/node
80
72
  * helper utilities.
81
73
  *
@@ -83,36 +75,60 @@ export interface AuthenticationSuccess {
83
75
  */
84
76
  id_token: string;
85
77
  /**
86
- * Call the Passlock API to exchange this code for details about the newly
87
- * registered passkey.
78
+ * Call the Passlock API to exchange this code for details about the
79
+ * authenticated passkey.
88
80
  *
89
- * @see {@link https://passlock.dev/principal/code-exchange//|code exchange}
81
+ * @see {@link https://passlock.dev/principal/code-exchange/|code exchange}
90
82
  */
91
83
  code: string;
92
- }
84
+ };
85
+ /**
86
+ * Type guard to narrow something down to an AuthenticationSuccess
87
+ *
88
+ * @param payload
89
+ * @returns `true` if the payload is an {@link AuthenticationSuccess}.
90
+ *
91
+ * @category Passkeys (other)
92
+ */
93
93
  export declare const isAuthenticationSuccess: (payload: unknown) => payload is AuthenticationSuccess;
94
- export interface PasskeyNotFound {
95
- _tag: "@error/PasskeyNotFound";
96
- message: string;
97
- credentialId: string;
98
- rpId: string;
99
- }
100
- export declare const isPasskeyNotFound: (payload: unknown) => payload is PasskeyNotFound;
94
+ export declare const fetchOptions: (options: Omit<AuthenticationOptions, keyof PasslockOptions>) => Micro.Micro<OptionsResponse, NetworkError, Endpoint | TenancyId | Logger>;
95
+ export type OptionsResponse = {
96
+ sessionToken: string;
97
+ optionsJSON: PublicKeyCredentialRequestOptionsJSON;
98
+ };
99
+ export declare const isOptionsResponse: (payload: unknown) => payload is OptionsResponse;
101
100
  export declare const startAuthentication: (optionsJSON: PublicKeyCredentialRequestOptionsJSON, { useBrowserAutofill, onEvent, }: {
102
101
  useBrowserAutofill: boolean;
103
- onEvent?: OnEventFn | undefined;
104
- }) => Micro.Micro<Helper.AuthenticationResponseJSON, PasskeysUnsupportedError | OtherPasskeyError, Logger | AuthenticationHelper>;
102
+ onEvent?: OnAuthenticationEvent | undefined;
103
+ }) => Micro.Micro<Helper.AuthenticationResponseJSON, PasskeyUnsupportedError | OtherPasskeyError, Logger | AuthenticationHelper>;
105
104
  export declare const verifyCredential: (sessionToken: string, response: AuthenticationResponseJSON, { onEvent }: {
106
- onEvent?: OnEventFn | undefined;
107
- }) => Micro.Micro<AuthenticationSuccess, UnexpectedError | PasskeyNotFound, Logger | Endpoint | TenancyId>;
108
- export type AuthenticationError = PasskeysUnsupportedError | OtherPasskeyError | PasskeyNotFound | UnexpectedError;
105
+ onEvent?: OnAuthenticationEvent | undefined;
106
+ }) => Micro.Micro<AuthenticationSuccess, NetworkError | PasskeyNotFoundError, Endpoint | TenancyId | Logger>;
107
+ /**
108
+ * Potential errors associated with Passkey authentication
109
+ *
110
+ * @category Passkeys (errors)
111
+ */
112
+ export type AuthenticationError = PasskeyUnsupportedError | OtherPasskeyError | PasskeyNotFoundError | NetworkError;
109
113
  /**
110
- * Trigger local passkey authentication then verify the passkey in the Passlock vault.
114
+ * Trigger local passkey authentication then verify the passkey in your Passlock vault.
111
115
  * Returns a code and id_token that can be exchanged/decoded in your backend.
112
116
  *
113
117
  * @param options
114
- * @returns
118
+ * @returns A Micro effect that resolves with {@link AuthenticationSuccess} or
119
+ * fails with {@link AuthenticationError}.
115
120
  */
116
121
  export declare const authenticatePasskey: (options: AuthenticationOptions) => Micro.Micro<AuthenticationSuccess, AuthenticationError, Logger | AuthenticationHelper>;
117
- export {};
122
+ /**
123
+ * Type of the authentication event
124
+ */
125
+ export declare const AuthenticationEvent: readonly ["optionsRequest", "getCredential", "verifyCredential"];
126
+ /**
127
+ * @category Passkeys (other)
128
+ */
129
+ export type AuthenticationEvent = (typeof AuthenticationEvent)[number];
130
+ /**
131
+ * @category Passkeys (other)
132
+ */
133
+ export type OnAuthenticationEvent = (event: AuthenticationEvent) => void;
118
134
  //# sourceMappingURL=authentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/passkey/authentication/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAA;AACjD,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,qCAAqC,EAE3C,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAQ,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAiB,QAAQ,EAAe,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEvE,UAAU,eAAe;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,qCAAqC,CAAA;CACnD;;6BAK4B,OAAO,MAAM,CAAC,uBAAuB;yBACzC,OAAO,MAAM,CAAC,mBAAmB;;AAJ1D,qBAAa,oBAAqB,SAAQ,yBAMvC;IACD,MAAM,CAAC,OAAO;;;MAGiC;CAChD;AAgBD,eAAO,MAAM,mBAAmB,kEAAmE,CAAA;AAEnG,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAA;AAE5D,MAAM,WAAW,qBAAsB,SAAQ,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