@polaris-auth/client 0.6.1 → 0.7.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,7 +1,31 @@
1
1
  {
2
2
  "name": "@polaris-auth/client",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Typed TypeScript client for Polaris for PHP, generated from the route manifest",
5
+ "keywords": [
6
+ "polaris",
7
+ "authentication",
8
+ "auth",
9
+ "mfa",
10
+ "totp",
11
+ "jwt",
12
+ "oauth",
13
+ "sso",
14
+ "scim",
15
+ "rbac",
16
+ "organizations",
17
+ "multi-tenant",
18
+ "php",
19
+ "laravel",
20
+ "symfony",
21
+ "yii",
22
+ "openapi",
23
+ "openapi-fetch",
24
+ "typescript",
25
+ "client"
26
+ ],
27
+ "homepage": "https://github.com/univeros/polaris-core/tree/main/packages/client-ts#readme",
28
+ "bugs": "https://github.com/univeros/polaris-core/issues",
5
29
  "license": "MIT",
6
30
  "author": {
7
31
  "name": "2am.tech",
@@ -9,7 +33,7 @@
9
33
  },
10
34
  "repository": {
11
35
  "type": "git",
12
- "url": "https://github.com/univeros/polaris-core.git",
36
+ "url": "git+https://github.com/univeros/polaris-core.git",
13
37
  "directory": "packages/client-ts"
14
38
  },
15
39
  "type": "module",
@@ -0,0 +1,16 @@
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 `anonymous` plugin's routes as methods of `client.anonymous`. */
7
+ export function anonymous(client: Client<paths>) {
8
+ return {
9
+ /** POST /anonymous/convert: Convert the guest into an account */
10
+ convert: (...init: Init<"/anonymous/convert", "post">) => client.POST("/anonymous/convert", ...init),
11
+ /** POST /anonymous/sign-in: Sign in as a guest */
12
+ signIn: (...init: Init<"/anonymous/sign-in", "post">) => client.POST("/anonymous/sign-in", ...init),
13
+ };
14
+ }
15
+
16
+ export type AnonymousApi = ReturnType<typeof anonymous>;
package/src/index.ts CHANGED
@@ -1,25 +1,33 @@
1
1
  import createOpenApiClient, { type Client, type ClientOptions } from "openapi-fetch";
2
2
  import { admin, type AdminApi } from "./admin.js";
3
+ import { anonymous, type AnonymousApi } from "./anonymous.js";
3
4
  import { audit, type AuditApi } from "./audit.js";
4
5
  import { challengeRetry, type ChallengeOptions } from "./challenge.js";
6
+ import { multiSession, type MultiSessionApi } from "./multi-session.js";
7
+ import { passwordless, type PasswordlessApi } from "./passwordless.js";
5
8
  import { sentinel, type SentinelApi } from "./sentinel.js";
6
9
  import { scim, type ScimApi } from "./scim.js";
7
10
  import { sso, type SsoApi } from "./sso.js";
11
+ import { username, type UsernameApi } from "./username.js";
8
12
  import type { components, paths } from "./schema.js";
9
13
 
10
14
  export type { components, operations, paths } from "./schema.js";
11
15
  export { admin, type AdminApi } from "./admin.js";
16
+ export { anonymous, type AnonymousApi } from "./anonymous.js";
12
17
  export { audit, type AuditApi } from "./audit.js";
13
18
  export { challengeRetry, type ChallengeOptions } from "./challenge.js";
19
+ export { multiSession, type MultiSessionApi } from "./multi-session.js";
20
+ export { passwordless, type PasswordlessApi } from "./passwordless.js";
14
21
  export { sentinel, type SentinelApi } from "./sentinel.js";
15
22
  export { scim, type ScimApi } from "./scim.js";
16
23
  export { sso, type SsoApi } from "./sso.js";
24
+ export { username, type UsernameApi } from "./username.js";
17
25
 
18
26
  /** The `{ error, message }` envelope every non-2xx response of a core route carries. */
19
27
  export type ErrorBody = components["schemas"]["Error"];
20
28
  /** The `{ errors: [...] }` envelope of a core route's 422. */
21
29
  export type ValidationErrorBody = components["schemas"]["ValidationError"];
22
- /** The RFC 9457 problem document every non-2xx response of a plugin route (`audit`, `admin`, `sentinel`, `sso`, `scim`) carries. */
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. */
23
31
  export type ProblemBody = components["schemas"]["Problem"];
24
32
 
25
33
  export interface PolarisClientOptions extends ClientOptions {
@@ -48,6 +56,17 @@ export interface PolarisClient extends Client<paths> {
48
56
  readonly sso: SsoApi;
49
57
  /** The `polaris/scim` routes: the organization's connections, the operators' list, and the SCIM server itself for a directory client. */
50
58
  readonly scim: ScimApi;
59
+ /** The `polaris/passwordless` routes: `client.passwordless.magicLinkSend()`, `magicLinkExchange()`, `emailOtpSend()`, `emailOtpVerify()`, `phoneSend()`, `phoneVerify()`, `oneTimeTokenGenerate()`, ... */
60
+ readonly passwordless: PasswordlessApi;
61
+ /** The `polaris/username` routes: `client.username.signIn()` (a username or an email) and `update()`. */
62
+ readonly username: UsernameApi;
63
+ /** The `polaris/anonymous` routes: `client.anonymous.signIn()` for a guest and `convert()` once it has an account. */
64
+ readonly anonymous: AnonymousApi;
65
+ /**
66
+ * The `polaris/multi-session` routes: `client.multiSession.list()`, `switch()`, `revoke()`, `lastMethod()`.
67
+ * The device travels as the `X-Polaris-Device` header a sign-in answers (or the HttpOnly cookie in a browser).
68
+ */
69
+ readonly multiSession: MultiSessionApi;
51
70
  /** A new client on the same options bound to another token (null for anonymous); this one is unchanged. */
52
71
  withToken(token: string | null): PolarisClient;
53
72
  }
@@ -55,7 +74,8 @@ export interface PolarisClient extends Client<paths> {
55
74
  /**
56
75
  * An `openapi-fetch` client typed by `paths` (generated from `polaris manifest --format=openapi`), so
57
76
  * `client.POST("/auth/login", { body })` checks the body and types `data` and `error`; the plugins' routes
58
- * are also methods of `client.audit`, `client.admin`, `client.sentinel`, `client.sso` and `client.scim`; `challenge.captcha`
77
+ * 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`
59
79
  * answers a sentinel captcha challenge with one retry. No refresh loop and no storage: when to refresh
60
80
  * and where to keep tokens is the application's policy.
61
81
  */
@@ -82,6 +102,10 @@ export function createClient(options: PolarisClientOptions): PolarisClient {
82
102
  sentinel: sentinel(client),
83
103
  sso: sso(client),
84
104
  scim: scim(client),
105
+ passwordless: passwordless(client),
106
+ username: username(client),
107
+ anonymous: anonymous(client),
108
+ multiSession: multiSession(client),
85
109
  withToken: (next: string | null) => createClient({ ...options, token: next }),
86
110
  };
87
111
  }
@@ -0,0 +1,20 @@
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 `multi-session` plugin's routes as methods of `client.multiSession`. */
7
+ export function multiSession(client: Client<paths>) {
8
+ return {
9
+ /** GET /multi-session/last-method: Read the device's last sign-in method */
10
+ lastMethod: (...init: Init<"/multi-session/last-method", "get">) => client.GET("/multi-session/last-method", ...init),
11
+ /** GET /multi-session/list: List the accounts signed in on this device */
12
+ list: (...init: Init<"/multi-session/list", "get">) => client.GET("/multi-session/list", ...init),
13
+ /** DELETE /multi-session/{sessionId}: Sign one account out of this device */
14
+ revoke: (...init: Init<"/multi-session/{sessionId}", "delete">) => client.DELETE("/multi-session/{sessionId}", ...init),
15
+ /** POST /multi-session/switch: Switch to another account signed in on this device */
16
+ switch: (...init: Init<"/multi-session/switch", "post">) => client.POST("/multi-session/switch", ...init),
17
+ };
18
+ }
19
+
20
+ export type MultiSessionApi = ReturnType<typeof multiSession>;
@@ -0,0 +1,38 @@
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 `passwordless` plugin's routes as methods of `client.passwordless`. */
7
+ export function passwordless(client: Client<paths>) {
8
+ return {
9
+ /** POST /email-otp/reset-password: Reset the password with an email code */
10
+ emailOtpResetPassword: (...init: Init<"/email-otp/reset-password", "post">) => client.POST("/email-otp/reset-password", ...init),
11
+ /** POST /email-otp/send: Send an email code */
12
+ emailOtpSend: (...init: Init<"/email-otp/send", "post">) => client.POST("/email-otp/send", ...init),
13
+ /** POST /email-otp/verify: Sign in with an email code */
14
+ emailOtpVerify: (...init: Init<"/email-otp/verify", "post">) => client.POST("/email-otp/verify", ...init),
15
+ /** POST /email-otp/verify-email: Verify the email with a code */
16
+ emailOtpVerifyEmail: (...init: Init<"/email-otp/verify-email", "post">) => client.POST("/email-otp/verify-email", ...init),
17
+ /** POST /magic-link/exchange: Exchange the magic link's code for the session */
18
+ magicLinkExchange: (...init: Init<"/magic-link/exchange", "post">) => client.POST("/magic-link/exchange", ...init),
19
+ /** POST /magic-link/send: Send a magic link */
20
+ magicLinkSend: (...init: Init<"/magic-link/send", "post">) => client.POST("/magic-link/send", ...init),
21
+ /** GET /magic-link/verify: Open a magic link */
22
+ magicLinkVerify: (...init: Init<"/magic-link/verify", "get">) => client.GET("/magic-link/verify", ...init),
23
+ /** POST /one-time-token/generate: Generate a one-time token */
24
+ oneTimeTokenGenerate: (...init: Init<"/one-time-token/generate", "post">) => client.POST("/one-time-token/generate", ...init),
25
+ /** POST /one-time-token/verify: Sign in with a one-time token */
26
+ oneTimeTokenVerify: (...init: Init<"/one-time-token/verify", "post">) => client.POST("/one-time-token/verify", ...init),
27
+ /** POST /phone/add: Add a phone number */
28
+ phoneAdd: (...init: Init<"/phone/add", "post">) => client.POST("/phone/add", ...init),
29
+ /** POST /phone/confirm: Confirm a phone number */
30
+ phoneConfirm: (...init: Init<"/phone/confirm", "post">) => client.POST("/phone/confirm", ...init),
31
+ /** POST /phone/send: Send a phone sign-in code */
32
+ phoneSend: (...init: Init<"/phone/send", "post">) => client.POST("/phone/send", ...init),
33
+ /** POST /phone/verify: Sign in with a phone code */
34
+ phoneVerify: (...init: Init<"/phone/verify", "post">) => client.POST("/phone/verify", ...init),
35
+ };
36
+ }
37
+
38
+ export type PasswordlessApi = ReturnType<typeof passwordless>;