@podosoft/podokit-api-client 0.6.1 → 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/README.md CHANGED
@@ -6,8 +6,10 @@ through this single entry point — never with a raw `fetch`.
6
6
  - `client.auth` — the [better-auth](https://better-auth.com) client (email/password,
7
7
  sessions, the `signupApproved` user field, and the admin plugin: `listUsers`,
8
8
  `updateUser`, `banUser`, `setRole`, `listUserSessions`, …).
9
- - `client.get/post/put/patch/del` — the app's REST endpoints, parsing the standard
10
- error envelope and throwing `ApiError` on failure.
9
+ - `client.get/post/put/patch/del` — the app's JSON REST endpoints, parsing the
10
+ standard error envelope and throwing `ApiError` on failure.
11
+ - `client.postForm` — multipart uploads with the browser-managed boundary and the
12
+ same credentials and error handling.
11
13
 
12
14
  ```ts
13
15
  import { createApiClient } from "@podosoft/podokit-api-client";
@@ -20,6 +22,11 @@ await api.auth.signIn.email({ email, password });
20
22
  // Server-side (SSR): point at the internal backend and forward cookies
21
23
  const api = createApiClient({ baseUrl: process.env.BACKEND_INTERNAL_URL, fetch });
22
24
  const session = await api.auth.getSession();
25
+
26
+ // Multipart upload
27
+ const form = new FormData();
28
+ form.set("file", imageFile);
29
+ await api.postForm("/account/profile-image", form);
23
30
  ```
24
31
 
25
32
  ## Options
@@ -35,3 +42,5 @@ const session = await api.auth.getSession();
35
42
  Errors are thrown as `ApiError` (`code`, `message`, `statusCode`, `details`).
36
43
  `PUBLIC_SIGNUP_DISABLED` and `SIGNUP_APPROVAL_REQUIRED` are re-exported for
37
44
  provider-independent registration-policy handling.
45
+ The profile-image policy, response type, and stable validation error codes are
46
+ also re-exported so account UIs can display the exact limits enforced by the API.
package/dist/index.d.ts CHANGED
@@ -20,7 +20,8 @@ export interface ApiClientOptions {
20
20
  */
21
21
  export type { Capabilities } from "@podosoft/podokit-contracts";
22
22
  /** Stable authentication policy error codes re-exported for browser clients. */
23
- export { PUBLIC_SIGNUP_DISABLED, SIGNUP_APPROVAL_REQUIRED, } from "@podosoft/podokit-contracts";
23
+ export { PROFILE_IMAGE_DIMENSIONS_INVALID, PROFILE_IMAGE_NOT_FOUND, PROFILE_IMAGE_POLICY, PROFILE_IMAGE_REQUIRED, PROFILE_IMAGE_TOO_LARGE, PROFILE_IMAGE_TYPE_INVALID, PUBLIC_SIGNUP_DISABLED, SIGNUP_APPROVAL_REQUIRED, } from "@podosoft/podokit-contracts";
24
+ export type { ProfileImageMimeType, ProfileImageResponse, } from "@podosoft/podokit-contracts";
24
25
  /** Error thrown when the API returns the standard error envelope or a non-2xx status. */
25
26
  export declare class ApiError extends Error {
26
27
  readonly code: string;
@@ -34,8 +35,10 @@ export declare class ApiError extends Error {
34
35
  *
35
36
  * - `client.auth` is the better-auth client (email/password, sessions, and the
36
37
  * admin plugin: `client.auth.admin.listUsers()`, `banUser`, `setRole`, ...).
37
- * - `client.get/post/put/patch/del` call the app's REST endpoints and parse the
38
- * standard error envelope, throwing {@link ApiError} on failure.
38
+ * - `client.get/post/put/patch/del` call the app's JSON REST endpoints and parse
39
+ * the standard error envelope, throwing {@link ApiError} on failure.
40
+ * - `client.postForm` sends multipart `FormData` without overriding the browser's
41
+ * boundary-aware content type.
39
42
  */
40
43
  export declare function createApiClient(options?: ApiClientOptions): {
41
44
  /** The better-auth client (auth + admin plugin), created on first access. */
@@ -2577,9 +2580,7 @@ export declare function createApiClient(options?: ApiClientOptions): {
2577
2580
  email: string;
2578
2581
  emailVerified: boolean;
2579
2582
  name: string;
2580
- image
2581
- /** Error thrown when the API returns the standard error envelope or a non-2xx status. */
2582
- ? /** Error thrown when the API returns the standard error envelope or a non-2xx status. */: string | null | undefined;
2583
+ image?: string | null | undefined;
2583
2584
  };
2584
2585
  }[]>;
2585
2586
  setActiveSession: import("better-call").StrictEndpoint<"/multi-session/set-active", {
@@ -5266,6 +5267,7 @@ export declare function createApiClient(options?: ApiClientOptions): {
5266
5267
  put: <T>(path: string, body?: unknown) => Promise<T>;
5267
5268
  patch: <T>(path: string, body?: unknown) => Promise<T>;
5268
5269
  del: <T>(path: string) => Promise<T>;
5270
+ postForm: <T>(path: string, body: FormData) => Promise<T>;
5269
5271
  };
5270
5272
  /** The client returned by {@link createApiClient}. */
5271
5273
  export type ApiClient = ReturnType<typeof createApiClient>;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { adminClient, twoFactorClient, magicLinkClient, emailOTPClient, username
3
3
  import { apiKeyClient } from "@better-auth/api-key/client";
4
4
  import { passkeyClient } from "@better-auth/passkey/client";
5
5
  /** Stable authentication policy error codes re-exported for browser clients. */
6
- export { PUBLIC_SIGNUP_DISABLED, SIGNUP_APPROVAL_REQUIRED, } from "@podosoft/podokit-contracts";
6
+ export { PROFILE_IMAGE_DIMENSIONS_INVALID, PROFILE_IMAGE_NOT_FOUND, PROFILE_IMAGE_POLICY, PROFILE_IMAGE_REQUIRED, PROFILE_IMAGE_TOO_LARGE, PROFILE_IMAGE_TYPE_INVALID, PUBLIC_SIGNUP_DISABLED, SIGNUP_APPROVAL_REQUIRED, } from "@podosoft/podokit-contracts";
7
7
  /** Error thrown when the API returns the standard error envelope or a non-2xx status. */
8
8
  export class ApiError extends Error {
9
9
  code;
@@ -33,8 +33,10 @@ function toApiError(data, response) {
33
33
  *
34
34
  * - `client.auth` is the better-auth client (email/password, sessions, and the
35
35
  * admin plugin: `client.auth.admin.listUsers()`, `banUser`, `setRole`, ...).
36
- * - `client.get/post/put/patch/del` call the app's REST endpoints and parse the
37
- * standard error envelope, throwing {@link ApiError} on failure.
36
+ * - `client.get/post/put/patch/del` call the app's JSON REST endpoints and parse
37
+ * the standard error envelope, throwing {@link ApiError} on failure.
38
+ * - `client.postForm` sends multipart `FormData` without overriding the browser's
39
+ * boundary-aware content type.
38
40
  */
39
41
  export function createApiClient(options = {}) {
40
42
  const baseUrl = options.baseUrl ?? "";
@@ -91,6 +93,19 @@ export function createApiClient(options = {}) {
91
93
  }
92
94
  return data;
93
95
  }
96
+ async function formRequest(method, path, body) {
97
+ const response = await doFetch(`${baseUrl}${apiBasePath}${path}`, {
98
+ method,
99
+ credentials,
100
+ body,
101
+ });
102
+ const text = await response.text();
103
+ const data = text ? JSON.parse(text) : undefined;
104
+ if (!response.ok) {
105
+ throw toApiError(data, response);
106
+ }
107
+ return data;
108
+ }
94
109
  return {
95
110
  /** The better-auth client (auth + admin plugin), created on first access. */
96
111
  get auth() {
@@ -103,5 +118,6 @@ export function createApiClient(options = {}) {
103
118
  put: (path, body) => request("PUT", path, body),
104
119
  patch: (path, body) => request("PATCH", path, body),
105
120
  del: (path) => request("DELETE", path),
121
+ postForm: (path, body) => formRequest("POST", path, body),
106
122
  };
107
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podosoft/podokit-api-client",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "Typed API client for PodoKit backends: better-auth (auth + admin) plus a standard error-envelope request layer.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "provenance": true
30
30
  },
31
31
  "dependencies": {
32
- "@podosoft/podokit-contracts": "^0.2.1",
32
+ "@podosoft/podokit-contracts": "^0.4.0",
33
33
  "better-auth": "^1.6.23",
34
34
  "@better-auth/api-key": "^1.6.23",
35
35
  "@better-auth/passkey": "^1.6.23"