@polaris-auth/client 0.8.0 → 0.9.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.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Typed TypeScript client for Polaris for PHP, generated from the route manifest",
5
5
  "keywords": [
6
6
  "polaris",
@@ -25,7 +25,17 @@
25
25
  "client",
26
26
  "passkey",
27
27
  "webauthn",
28
- "social-login"
28
+ "social-login",
29
+ "api-keys",
30
+ "oauth2",
31
+ "oauth2-server",
32
+ "oidc",
33
+ "openid-connect",
34
+ "pkce",
35
+ "dpop",
36
+ "device-flow",
37
+ "ciba",
38
+ "token-exchange"
29
39
  ],
30
40
  "homepage": "https://github.com/univeros/polaris-core/tree/main/packages/client-ts#readme",
31
41
  "bugs": "https://github.com/univeros/polaris-core/issues",
@@ -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 `api-keys` plugin's routes as methods of `client.apiKeys`. */
7
+ export function apiKeys(client: Client<paths>) {
8
+ return {
9
+ /** POST /api-keys: Create an API key */
10
+ create: (...init: Init<"/api-keys", "post">) => client.POST("/api-keys", ...init),
11
+ /** DELETE /api-keys/{id}: Revoke an API key */
12
+ delete: (...init: Init<"/api-keys/{id}", "delete">) => client.DELETE("/api-keys/{id}", ...init),
13
+ /** GET /api-keys: List API keys */
14
+ list: (...init: Init<"/api-keys", "get">) => client.GET("/api-keys", ...init),
15
+ /** GET /api-keys/{id}: Read an API key */
16
+ read: (...init: Init<"/api-keys/{id}", "get">) => client.GET("/api-keys/{id}", ...init),
17
+ /** POST /api-keys/{id}/rotate: Rotate an API key */
18
+ rotate: (...init: Init<"/api-keys/{id}/rotate", "post">) => client.POST("/api-keys/{id}/rotate", ...init),
19
+ /** PATCH /api-keys/{id}: Update an API key */
20
+ update: (...init: Init<"/api-keys/{id}", "patch">) => client.PATCH("/api-keys/{id}", ...init),
21
+ /** POST /api-keys/verify: Verify an API key */
22
+ verify: (...init: Init<"/api-keys/verify", "post">) => client.POST("/api-keys/verify", ...init),
23
+ };
24
+ }
25
+
26
+ export type ApiKeysApi = ReturnType<typeof apiKeys>;
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ import { passwordless, type PasswordlessApi } from "./passwordless.js";
9
9
  import { sentinel, type SentinelApi } from "./sentinel.js";
10
10
  import { scim, type ScimApi } from "./scim.js";
11
11
  import { social, type SocialApi } from "./social.js";
12
+ import { apiKeys, type ApiKeysApi } from "./api-keys.js";
13
+ import { oauth, type OauthApi } from "./oauth.js";
12
14
  import { sso, type SsoApi } from "./sso.js";
13
15
  import { username, type UsernameApi } from "./username.js";
14
16
  import type { components, paths } from "./schema.js";
@@ -24,6 +26,8 @@ export { passwordless, type PasswordlessApi } from "./passwordless.js";
24
26
  export { sentinel, type SentinelApi } from "./sentinel.js";
25
27
  export { scim, type ScimApi } from "./scim.js";
26
28
  export { social, type SocialApi } from "./social.js";
29
+ export { apiKeys, type ApiKeysApi } from "./api-keys.js";
30
+ export { oauth, type OauthApi } from "./oauth.js";
27
31
  export { sso, type SsoApi } from "./sso.js";
28
32
  export { username, type UsernameApi } from "./username.js";
29
33
  export { registerPasskey, signInWithPasskey, passkeyAssertion, passkeyAutofillAvailable, type SignInWithPasskeyOptions } from "./webauthn.js";
@@ -32,7 +36,7 @@ export { registerPasskey, signInWithPasskey, passkeyAssertion, passkeyAutofillAv
32
36
  export type ErrorBody = components["schemas"]["Error"];
33
37
  /** The `{ errors: [...] }` envelope of a core route's 422. */
34
38
  export type ValidationErrorBody = components["schemas"]["ValidationError"];
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. */
39
+ /** 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`, `api-keys`, `oauth`) carries. */
36
40
  export type ProblemBody = components["schemas"]["Problem"];
37
41
 
38
42
  export interface PolarisClientOptions extends ClientOptions {
@@ -76,6 +80,10 @@ export interface PolarisClient extends Client<paths> {
76
80
  readonly social: SocialApi;
77
81
  /** The `polaris/passkey` routes (`registerOptions()`, `registerVerify()`, `authenticateOptions()`, `authenticateVerify()`, `list()`, `rename()`, `delete()`); `registerPasskey()` and `signInWithPasskey()` run the browser ceremonies. */
78
82
  readonly passkey: PasskeyApi;
83
+ /** The `polaris/api-keys` routes: `client.apiKeys.list()`, `create()`, `read()`, `update()`, `delete()`, `rotate()`, `verify()`. A key goes in `Authorization: Bearer pk_...` like a session token. */
84
+ readonly apiKeys: ApiKeysApi;
85
+ /** The `polaris/oauth-provider` routes: `client.oauth.authorize()`, `decision()`, `token()`, `userinfo()`, `revoke()`, `introspect()`, `register()`, the device, CIBA, consent, client-management and discovery methods. */
86
+ readonly oauth: OauthApi;
79
87
  /** A new client on the same options bound to another token (null for anonymous); this one is unchanged. */
80
88
  withToken(token: string | null): PolarisClient;
81
89
  }
@@ -84,7 +92,7 @@ export interface PolarisClient extends Client<paths> {
84
92
  * An `openapi-fetch` client typed by `paths` (generated from `polaris manifest --format=openapi`), so
85
93
  * `client.POST("/auth/login", { body })` checks the body and types `data` and `error`; the plugins' routes
86
94
  * are also methods of `client.audit`, `client.admin`, `client.sentinel`, `client.sso`, `client.scim`, `client.passwordless`,
87
- * `client.username`, `client.anonymous`, `client.multiSession`, `client.social` and `client.passkey`; `challenge.captcha`
95
+ * `client.username`, `client.anonymous`, `client.multiSession`, `client.social`, `client.passkey`, `client.apiKeys` and `client.oauth`; `challenge.captcha`
88
96
  * answers a sentinel captcha challenge with one retry. No refresh loop and no storage: when to refresh
89
97
  * and where to keep tokens is the application's policy.
90
98
  */
@@ -117,6 +125,8 @@ export function createClient(options: PolarisClientOptions): PolarisClient {
117
125
  multiSession: multiSession(client),
118
126
  social: social(client),
119
127
  passkey: passkey(client),
128
+ apiKeys: apiKeys(client),
129
+ oauth: oauth(client),
120
130
  withToken: (next: string | null) => createClient({ ...options, token: next }),
121
131
  };
122
132
  }
package/src/oauth.ts ADDED
@@ -0,0 +1,64 @@
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 `oauth` plugin's routes as methods of `client.oauth`. */
7
+ export function oauth(client: Client<paths>) {
8
+ return {
9
+ /** POST /admin/oauth/clients: Register an OAuth client as an operator */
10
+ adminCreateClient: (...init: Init<"/admin/oauth/clients", "post">) => client.POST("/admin/oauth/clients", ...init),
11
+ /** DELETE /admin/oauth/clients/{id}: Delete an OAuth client as an operator */
12
+ adminDeleteClient: (...init: Init<"/admin/oauth/clients/{id}", "delete">) => client.DELETE("/admin/oauth/clients/{id}", ...init),
13
+ /** GET /admin/oauth/clients: List every OAuth client */
14
+ adminListClients: (...init: Init<"/admin/oauth/clients", "get">) => client.GET("/admin/oauth/clients", ...init),
15
+ /** GET /.well-known/oauth-authorization-server: Authorization server metadata */
16
+ authorizationServer: (...init: Init<"/.well-known/oauth-authorization-server", "get">) => client.GET("/.well-known/oauth-authorization-server", ...init),
17
+ /** GET /oauth2/authorize: Start an authorization (consent) request */
18
+ authorize: (...init: Init<"/oauth2/authorize", "get">) => client.GET("/oauth2/authorize", ...init),
19
+ /** POST /oauth2/ciba: Backchannel authentication request */
20
+ ciba: (...init: Init<"/oauth2/ciba", "post">) => client.POST("/oauth2/ciba", ...init),
21
+ /** POST /oauth2/ciba/{id}/decide: Approve or refuse a backchannel request */
22
+ cibaDecide: (...init: Init<"/oauth2/ciba/{id}/decide", "post">) => client.POST("/oauth2/ciba/{id}/decide", ...init),
23
+ /** GET /oauth2/ciba/pending: List pending backchannel requests */
24
+ cibaPending: (...init: Init<"/oauth2/ciba/pending", "get">) => client.GET("/oauth2/ciba/pending", ...init),
25
+ /** DELETE /oauth2/consents/{clientId}: Revoke a consent */
26
+ consentRevoke: (...init: Init<"/oauth2/consents/{clientId}", "delete">) => client.DELETE("/oauth2/consents/{clientId}", ...init),
27
+ /** GET /oauth2/consents: List your consents */
28
+ consentsList: (...init: Init<"/oauth2/consents", "get">) => client.GET("/oauth2/consents", ...init),
29
+ /** POST /orgs/{id}/oauth/clients: Register an OAuth client for the organization */
30
+ createClient: (...init: Init<"/orgs/{id}/oauth/clients", "post">) => client.POST("/orgs/{id}/oauth/clients", ...init),
31
+ /** POST /oauth2/authorize/decision: Approve or refuse an authorization request */
32
+ decision: (...init: Init<"/oauth2/authorize/decision", "post">) => client.POST("/oauth2/authorize/decision", ...init),
33
+ /** DELETE /orgs/{id}/oauth/clients/{clientId}: Delete an OAuth client of the organization */
34
+ deleteClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "delete">) => client.DELETE("/orgs/{id}/oauth/clients/{clientId}", ...init),
35
+ /** POST /oauth2/device/approve: Approve or refuse a device */
36
+ deviceApprove: (...init: Init<"/oauth2/device/approve", "post">) => client.POST("/oauth2/device/approve", ...init),
37
+ /** POST /oauth2/device/code: Start the device flow */
38
+ deviceCode: (...init: Init<"/oauth2/device/code", "post">) => client.POST("/oauth2/device/code", ...init),
39
+ /** GET /oauth2/device/verify: Read the device behind a user code */
40
+ deviceVerify: (...init: Init<"/oauth2/device/verify", "get">) => client.GET("/oauth2/device/verify", ...init),
41
+ /** POST /oauth2/introspect: Introspect a token */
42
+ introspect: (...init: Init<"/oauth2/introspect", "post">) => client.POST("/oauth2/introspect", ...init),
43
+ /** GET /orgs/{id}/oauth/clients: List the organization's OAuth clients */
44
+ listClients: (...init: Init<"/orgs/{id}/oauth/clients", "get">) => client.GET("/orgs/{id}/oauth/clients", ...init),
45
+ /** GET /.well-known/openid-configuration: OpenID Connect Discovery */
46
+ openIdConfiguration: (...init: Init<"/.well-known/openid-configuration", "get">) => client.GET("/.well-known/openid-configuration", ...init),
47
+ /** GET /orgs/{id}/oauth/clients/{clientId}: Read an OAuth client of the organization */
48
+ readClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "get">) => client.GET("/orgs/{id}/oauth/clients/{clientId}", ...init),
49
+ /** POST /oauth2/register: Register a client (RFC 7591) */
50
+ register: (...init: Init<"/oauth2/register", "post">) => client.POST("/oauth2/register", ...init),
51
+ /** POST /oauth2/revoke: Revoke a token */
52
+ revoke: (...init: Init<"/oauth2/revoke", "post">) => client.POST("/oauth2/revoke", ...init),
53
+ /** POST /oauth2/token: Issue tokens */
54
+ token: (...init: Init<"/oauth2/token", "post">) => client.POST("/oauth2/token", ...init),
55
+ /** PATCH /orgs/{id}/oauth/clients/{clientId}: Update an OAuth client of the organization */
56
+ updateClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "patch">) => client.PATCH("/orgs/{id}/oauth/clients/{clientId}", ...init),
57
+ /** GET /oauth2/userinfo: The user's OpenID claims */
58
+ userinfo: (...init: Init<"/oauth2/userinfo", "get">) => client.GET("/oauth2/userinfo", ...init),
59
+ /** POST /oauth2/userinfo: The user's OpenID claims (POST) */
60
+ userinfoPost: (...init: Init<"/oauth2/userinfo", "post">) => client.POST("/oauth2/userinfo", ...init),
61
+ };
62
+ }
63
+
64
+ export type OauthApi = ReturnType<typeof oauth>;