@polaris-auth/client 0.7.0 → 0.8.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polaris-auth/client",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Typed TypeScript client for Polaris for PHP, generated from the route manifest",
5
5
  "keywords": [
6
6
  "polaris",
@@ -22,7 +22,10 @@
22
22
  "openapi",
23
23
  "openapi-fetch",
24
24
  "typescript",
25
- "client"
25
+ "client",
26
+ "passkey",
27
+ "webauthn",
28
+ "social-login"
26
29
  ],
27
30
  "homepage": "https://github.com/univeros/polaris-core/tree/main/packages/client-ts#readme",
28
31
  "bugs": "https://github.com/univeros/polaris-core/issues",
@@ -57,12 +60,14 @@
57
60
  "generate": "php ../../bin/polaris manifest --format=openapi --bootstrap=polaris.php > openapi.json && openapi-typescript openapi.json -o src/schema.d.ts && node scripts/generate-namespaces.mjs",
58
61
  "typecheck": "tsc --noEmit",
59
62
  "build": "tsc -p tsconfig.build.json",
60
- "test": "vitest run"
63
+ "test": "vitest run",
64
+ "e2e": "playwright test"
61
65
  },
62
66
  "dependencies": {
63
67
  "openapi-fetch": "^0.17.0"
64
68
  },
65
69
  "devDependencies": {
70
+ "@playwright/test": "^1.56.1",
66
71
  "@types/node": "^22.20.2",
67
72
  "openapi-typescript": "^7.13.0",
68
73
  "typescript": "^5.9.3",
package/src/index.ts CHANGED
@@ -4,9 +4,11 @@ import { anonymous, type AnonymousApi } from "./anonymous.js";
4
4
  import { audit, type AuditApi } from "./audit.js";
5
5
  import { challengeRetry, type ChallengeOptions } from "./challenge.js";
6
6
  import { multiSession, type MultiSessionApi } from "./multi-session.js";
7
+ import { passkey, type PasskeyApi } from "./passkey.js";
7
8
  import { passwordless, type PasswordlessApi } from "./passwordless.js";
8
9
  import { sentinel, type SentinelApi } from "./sentinel.js";
9
10
  import { scim, type ScimApi } from "./scim.js";
11
+ import { social, type SocialApi } from "./social.js";
10
12
  import { sso, type SsoApi } from "./sso.js";
11
13
  import { username, type UsernameApi } from "./username.js";
12
14
  import type { components, paths } from "./schema.js";
@@ -17,17 +19,20 @@ export { anonymous, type AnonymousApi } from "./anonymous.js";
17
19
  export { audit, type AuditApi } from "./audit.js";
18
20
  export { challengeRetry, type ChallengeOptions } from "./challenge.js";
19
21
  export { multiSession, type MultiSessionApi } from "./multi-session.js";
22
+ export { passkey, type PasskeyApi } from "./passkey.js";
20
23
  export { passwordless, type PasswordlessApi } from "./passwordless.js";
21
24
  export { sentinel, type SentinelApi } from "./sentinel.js";
22
25
  export { scim, type ScimApi } from "./scim.js";
26
+ export { social, type SocialApi } from "./social.js";
23
27
  export { sso, type SsoApi } from "./sso.js";
24
28
  export { username, type UsernameApi } from "./username.js";
29
+ export { registerPasskey, signInWithPasskey, passkeyAssertion, passkeyAutofillAvailable, type SignInWithPasskeyOptions } from "./webauthn.js";
25
30
 
26
31
  /** The `{ error, message }` envelope every non-2xx response of a core route carries. */
27
32
  export type ErrorBody = components["schemas"]["Error"];
28
33
  /** The `{ errors: [...] }` envelope of a core route's 422. */
29
34
  export type ValidationErrorBody = components["schemas"]["ValidationError"];
30
- /** The RFC 9457 problem document every non-2xx response of a plugin route (`audit`, `admin`, `sentinel`, `sso`, `scim`, `passwordless`, `username`, `anonymous`, `multi-session`) carries. */
35
+ /** The RFC 9457 problem document every non-2xx response of a plugin route (`audit`, `admin`, `sentinel`, `sso`, `scim`, `passwordless`, `username`, `anonymous`, `multi-session`, `social`, `passkey`) carries. */
31
36
  export type ProblemBody = components["schemas"]["Problem"];
32
37
 
33
38
  export interface PolarisClientOptions extends ClientOptions {
@@ -67,6 +72,10 @@ export interface PolarisClient extends Client<paths> {
67
72
  * The device travels as the `X-Polaris-Device` header a sign-in answers (or the HttpOnly cookie in a browser).
68
73
  */
69
74
  readonly multiSession: MultiSessionApi;
75
+ /** The `polaris/social` routes: `client.social.start()`, `exchange()`, `oneTap()`, `accounts()`, `link()`, `unlink()`, `token()`. */
76
+ readonly social: SocialApi;
77
+ /** The `polaris/passkey` routes (`registerOptions()`, `registerVerify()`, `authenticateOptions()`, `authenticateVerify()`, `list()`, `rename()`, `delete()`); `registerPasskey()` and `signInWithPasskey()` run the browser ceremonies. */
78
+ readonly passkey: PasskeyApi;
70
79
  /** A new client on the same options bound to another token (null for anonymous); this one is unchanged. */
71
80
  withToken(token: string | null): PolarisClient;
72
81
  }
@@ -75,7 +84,7 @@ export interface PolarisClient extends Client<paths> {
75
84
  * An `openapi-fetch` client typed by `paths` (generated from `polaris manifest --format=openapi`), so
76
85
  * `client.POST("/auth/login", { body })` checks the body and types `data` and `error`; the plugins' routes
77
86
  * are also methods of `client.audit`, `client.admin`, `client.sentinel`, `client.sso`, `client.scim`, `client.passwordless`,
78
- * `client.username`, `client.anonymous` and `client.multiSession`; `challenge.captcha`
87
+ * `client.username`, `client.anonymous`, `client.multiSession`, `client.social` and `client.passkey`; `challenge.captcha`
79
88
  * answers a sentinel captcha challenge with one retry. No refresh loop and no storage: when to refresh
80
89
  * and where to keep tokens is the application's policy.
81
90
  */
@@ -106,6 +115,8 @@ export function createClient(options: PolarisClientOptions): PolarisClient {
106
115
  username: username(client),
107
116
  anonymous: anonymous(client),
108
117
  multiSession: multiSession(client),
118
+ social: social(client),
119
+ passkey: passkey(client),
109
120
  withToken: (next: string | null) => createClient({ ...options, token: next }),
110
121
  };
111
122
  }
package/src/passkey.ts ADDED
@@ -0,0 +1,26 @@
1
+ /* Generated by scripts/generate-namespaces.mjs from openapi.json; do not edit. */
2
+ import type { Client } from "openapi-fetch";
3
+ import type { paths } from "./schema.js";
4
+ import type { Init } from "./namespace.js";
5
+
6
+ /** The `passkey` plugin's routes as methods of `client.passkey`. */
7
+ export function passkey(client: Client<paths>) {
8
+ return {
9
+ /** POST /passkey/authenticate/options: Start a passkey sign-in */
10
+ authenticateOptions: (...init: Init<"/passkey/authenticate/options", "post">) => client.POST("/passkey/authenticate/options", ...init),
11
+ /** POST /passkey/authenticate/verify: Sign in with a passkey */
12
+ authenticateVerify: (...init: Init<"/passkey/authenticate/verify", "post">) => client.POST("/passkey/authenticate/verify", ...init),
13
+ /** DELETE /passkey/{id}: Remove a passkey */
14
+ delete: (...init: Init<"/passkey/{id}", "delete">) => client.DELETE("/passkey/{id}", ...init),
15
+ /** GET /passkey/list: List your passkeys */
16
+ list: (...init: Init<"/passkey/list", "get">) => client.GET("/passkey/list", ...init),
17
+ /** POST /passkey/register/options: Start registering a passkey */
18
+ registerOptions: (...init: Init<"/passkey/register/options", "post">) => client.POST("/passkey/register/options", ...init),
19
+ /** POST /passkey/register/verify: Finish registering a passkey */
20
+ registerVerify: (...init: Init<"/passkey/register/verify", "post">) => client.POST("/passkey/register/verify", ...init),
21
+ /** PATCH /passkey/{id}: Rename a passkey */
22
+ rename: (...init: Init<"/passkey/{id}", "patch">) => client.PATCH("/passkey/{id}", ...init),
23
+ };
24
+ }
25
+
26
+ export type PasskeyApi = ReturnType<typeof passkey>;