@blimu/client 0.6.3 → 1.1.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.
Files changed (54) hide show
  1. package/README.md +26 -79
  2. package/dist/client.d.mts +15 -59
  3. package/dist/client.d.ts +15 -59
  4. package/dist/client.js +1085 -110
  5. package/dist/client.js.map +1 -0
  6. package/dist/client.mjs +1112 -4
  7. package/dist/client.mjs.map +1 -0
  8. package/dist/index.d.mts +10 -3
  9. package/dist/index.d.ts +10 -3
  10. package/dist/index.js +1227 -133
  11. package/dist/index.js.map +1 -0
  12. package/dist/index.mjs +1317 -20
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/{schema-jwKwV_Bm.d.mts → schema-B4iFbKly.d.mts} +4 -15
  15. package/dist/{schema-jwKwV_Bm.d.ts → schema-B4iFbKly.d.ts} +4 -15
  16. package/dist/schema.d.mts +2 -1
  17. package/dist/schema.d.ts +2 -1
  18. package/dist/schema.js +1 -1
  19. package/dist/schema.js.map +1 -0
  20. package/dist/schema.mjs +1 -1
  21. package/dist/schema.mjs.map +1 -0
  22. package/dist/schema.zod-CyY7RTSY.d.mts +48 -0
  23. package/dist/schema.zod-CyY7RTSY.d.ts +48 -0
  24. package/dist/schema.zod.d.mts +2 -0
  25. package/dist/schema.zod.d.ts +2 -0
  26. package/dist/schema.zod.js +76 -0
  27. package/dist/schema.zod.js.map +1 -0
  28. package/dist/schema.zod.mjs +47 -0
  29. package/dist/schema.zod.mjs.map +1 -0
  30. package/dist/services/auth.d.mts +3 -25
  31. package/dist/services/auth.d.ts +3 -25
  32. package/dist/services/auth.js +7 -10
  33. package/dist/services/auth.js.map +1 -0
  34. package/dist/services/auth.mjs +59 -5
  35. package/dist/services/auth.mjs.map +1 -0
  36. package/dist/services/entitlements.d.mts +3 -11
  37. package/dist/services/entitlements.d.ts +3 -11
  38. package/dist/services/entitlements.js +8 -7
  39. package/dist/services/entitlements.js.map +1 -0
  40. package/dist/services/entitlements.mjs +28 -5
  41. package/dist/services/entitlements.mjs.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/utils.d.mts +2 -0
  44. package/dist/utils.d.ts +2 -0
  45. package/dist/utils.js +1078 -4
  46. package/dist/utils.js.map +1 -0
  47. package/dist/utils.mjs +1092 -5
  48. package/dist/utils.mjs.map +1 -0
  49. package/package.json +18 -40
  50. package/dist/chunk-7SBLH5KM.mjs +0 -6
  51. package/dist/chunk-ATZGLDGF.mjs +0 -143
  52. package/dist/chunk-ENXZU3RF.mjs +0 -30
  53. package/dist/chunk-LZ27JJ4R.mjs +0 -25
  54. package/dist/chunk-YGEJFE6U.mjs +0 -65
package/README.md CHANGED
@@ -17,94 +17,43 @@ import { BlimuClient } from '@blimu/client';
17
17
 
18
18
  // Create a new client
19
19
  const client = new BlimuClient({
20
- baseURL: 'https://api.example.com',
20
+ baseURL: 'https://api.blimu.dev',
21
21
  timeoutMs: 10000,
22
- retry: { retries: 2, backoffMs: 300, retryOn: [429, 500, 502, 503, 504] },
23
- // Environment-based baseURL (optional)
24
- env: 'sandbox',
25
- envBaseURLs: {
26
- sandbox: 'https://api-sandbox.example.com',
27
- production: 'https://api.example.com',
22
+ retry: {
23
+ retries: 2,
24
+ strategy: 'exponential',
25
+ backoffMs: 300,
26
+ retryOn: [429, 500, 502, 503, 504],
27
+ },
28
+ // Auth configuration
29
+ auth: {
30
+ strategies: [
31
+ {
32
+ type: 'bearer',
33
+ token: process.env.API_TOKEN,
34
+ },
35
+ ],
28
36
  },
29
- // Auth (generic API Key or Bearer header)
30
- accessToken: process.env.API_TOKEN,
31
- headerName: 'access_token', // or 'Authorization' (defaults to Authorization: Bearer <token>)
32
37
  });
38
+
33
39
  // Example: Logout and invalidate session
34
40
  try {
35
41
  const result = await client.auth.logout();
36
42
  console.log('Result:', result);
37
43
  } catch (error) {
38
- // ApiError with structured data
44
+ // FetchError with structured data
45
+ console.error(error);
46
+ }
47
+ // Example: List entitlements for a tenant and all its sub-resources
48
+ try {
49
+ const result = await client.entitlements.listForTenant('tenantResourceId');
50
+ console.log('Result:', result);
51
+ } catch (error) {
52
+ // FetchError with structured data
39
53
  console.error(error);
40
54
  }
41
55
  ```
42
56
 
43
- ## Environment & Auth
44
-
45
- ```typescript
46
- const client = new BlimuClient({
47
- env: 'sandbox',
48
- envBaseURLs: {
49
- sandbox: 'https://api-sandbox.example.com',
50
- production: 'https://api.example.com',
51
- },
52
- accessToken: async () => process.env.API_TOKEN!,
53
- headerName: 'access_token',
54
- });
55
- client.setAccessToken('new-token');
56
- ```
57
-
58
- ## Pagination
59
-
60
- ```typescript
61
- import { listAll } from '@blimu/client';
62
-
63
- const allPayments = await listAll((query) => client.payment.listPayments(query), { limit: 100 });
64
- ```
65
-
66
- ## Interceptors
67
-
68
- ```typescript
69
- const client = new BlimuClient({
70
- onRequest: ({ url, init }) => console.debug('->', init.method, url),
71
- onResponse: ({ response }) => console.debug('<-', response.status),
72
- onError: (err) => console.warn('request error', err),
73
- });
74
- ```
75
-
76
- ## Authentication
77
-
78
- This SDK supports the following authentication methods:
79
-
80
- ### Bearer
81
-
82
- Bearer token authentication:
83
-
84
- ```typescript
85
- const client = new BlimuClient({
86
- bearer: 'your-bearer-token',
87
- });
88
- ```
89
-
90
- ## Subpath imports
91
-
92
- ```typescript
93
- import { PaymentService, Schema } from '@blimu/client';
94
- ```
95
-
96
- ## Available Services
97
-
98
- ### AuthService
99
-
100
- - **logout**: POST /v1/auth/logout - Logout and invalidate session
101
- - **refresh**: POST /v1/auth/refresh - Refresh session token
102
- - **getSession**: GET /v1/auth/session - Get current session
103
-
104
- ### EntitlementsService
105
-
106
- - **listForTenant**: GET /v1/client/entitlements/list-for-tenant/{tenantResourceId} - List entitlements for a tenant and all its sub-resources
107
-
108
57
  ## TypeScript Support
109
58
 
110
59
  This SDK is written in TypeScript and provides full type safety:
@@ -117,8 +66,6 @@ const client = new BlimuClient({
117
66
  });
118
67
 
119
68
  // All methods are fully typed
120
- const result: unknown = await client.auth.logout(/* ... */);
121
-
122
69
  // Schema types are available
123
70
  const data: Schema.EntitlementType = {
124
71
  // Fully typed object
@@ -138,7 +85,7 @@ import { fetch } from 'undici';
138
85
  import { BlimuClient } from '@blimu/client';
139
86
 
140
87
  const client = new BlimuClient({
141
- baseURL: 'https://api.example.com',
88
+ baseURL: 'https://api.blimu.dev',
142
89
  fetch,
143
90
  });
144
91
  ```
package/dist/client.d.mts CHANGED
@@ -1,68 +1,24 @@
1
- type ClientOption = {
2
- baseURL?: string;
3
- headers?: Record<string, string>;
4
- timeoutMs?: number;
5
- retry?: {
6
- retries: number;
7
- backoffMs: number;
8
- retryOn?: number[];
9
- };
10
- onRequest?: (ctx: {
11
- url: string;
12
- init: RequestInit & {
13
- path: string;
14
- method: string;
15
- query?: Record<string, any>;
16
- headers: Headers;
17
- };
18
- attempt: number;
19
- }) => void | Promise<void>;
20
- onResponse?: (ctx: {
21
- url: string;
22
- init: RequestInit & {
23
- path: string;
24
- method: string;
25
- query?: Record<string, any>;
26
- headers: Headers;
27
- };
28
- attempt: number;
29
- response: Response;
30
- }) => void | Promise<void>;
31
- onError?: (err: unknown, ctx: {
32
- url: string;
33
- init: RequestInit & {
34
- path: string;
35
- method: string;
36
- query?: Record<string, any>;
37
- };
38
- attempt: number;
39
- }) => void | Promise<void>;
40
- env?: 'sandbox' | 'production';
41
- envBaseURLs?: {
42
- sandbox: string;
43
- production: string;
44
- };
45
- accessToken?: string | undefined | (() => string | undefined | Promise<string | undefined>);
46
- headerName?: string;
47
- bearer?: string;
48
- fetch?: typeof fetch;
49
- credentials?: RequestCredentials;
1
+ import { FetchClientConfig, FetchClient } from '@blimu/fetch';
2
+ export { FetchError } from '@blimu/fetch';
3
+
4
+ type ClientOption = FetchClientConfig & {
5
+ bearer?: string | (() => string | undefined | Promise<string | undefined>);
50
6
  };
51
- declare class FetchError<T = unknown> extends Error {
52
- readonly status: number;
53
- readonly data?: T | undefined;
54
- readonly headers?: Headers | undefined;
55
- constructor(message: string, status: number, data?: T | undefined, headers?: Headers | undefined);
56
- }
57
- declare class CoreClient {
58
- private cfg;
7
+
8
+ declare class CoreClient extends FetchClient {
59
9
  constructor(cfg?: ClientOption);
60
- setAccessToken(token: string | undefined | (() => string | undefined | Promise<string | undefined>)): void;
61
10
  request(init: RequestInit & {
62
11
  path: string;
63
12
  method: string;
64
13
  query?: Record<string, any>;
65
14
  }): Promise<any>;
15
+ requestStream<T = any>(init: RequestInit & {
16
+ path: string;
17
+ method: string;
18
+ query?: Record<string, any>;
19
+ contentType: string;
20
+ streamingFormat?: 'sse' | 'ndjson' | 'chunked';
21
+ }): AsyncGenerator<T, void, unknown>;
66
22
  }
67
23
 
68
- export { type ClientOption, CoreClient, FetchError };
24
+ export { type ClientOption, CoreClient };
package/dist/client.d.ts CHANGED
@@ -1,68 +1,24 @@
1
- type ClientOption = {
2
- baseURL?: string;
3
- headers?: Record<string, string>;
4
- timeoutMs?: number;
5
- retry?: {
6
- retries: number;
7
- backoffMs: number;
8
- retryOn?: number[];
9
- };
10
- onRequest?: (ctx: {
11
- url: string;
12
- init: RequestInit & {
13
- path: string;
14
- method: string;
15
- query?: Record<string, any>;
16
- headers: Headers;
17
- };
18
- attempt: number;
19
- }) => void | Promise<void>;
20
- onResponse?: (ctx: {
21
- url: string;
22
- init: RequestInit & {
23
- path: string;
24
- method: string;
25
- query?: Record<string, any>;
26
- headers: Headers;
27
- };
28
- attempt: number;
29
- response: Response;
30
- }) => void | Promise<void>;
31
- onError?: (err: unknown, ctx: {
32
- url: string;
33
- init: RequestInit & {
34
- path: string;
35
- method: string;
36
- query?: Record<string, any>;
37
- };
38
- attempt: number;
39
- }) => void | Promise<void>;
40
- env?: 'sandbox' | 'production';
41
- envBaseURLs?: {
42
- sandbox: string;
43
- production: string;
44
- };
45
- accessToken?: string | undefined | (() => string | undefined | Promise<string | undefined>);
46
- headerName?: string;
47
- bearer?: string;
48
- fetch?: typeof fetch;
49
- credentials?: RequestCredentials;
1
+ import { FetchClientConfig, FetchClient } from '@blimu/fetch';
2
+ export { FetchError } from '@blimu/fetch';
3
+
4
+ type ClientOption = FetchClientConfig & {
5
+ bearer?: string | (() => string | undefined | Promise<string | undefined>);
50
6
  };
51
- declare class FetchError<T = unknown> extends Error {
52
- readonly status: number;
53
- readonly data?: T | undefined;
54
- readonly headers?: Headers | undefined;
55
- constructor(message: string, status: number, data?: T | undefined, headers?: Headers | undefined);
56
- }
57
- declare class CoreClient {
58
- private cfg;
7
+
8
+ declare class CoreClient extends FetchClient {
59
9
  constructor(cfg?: ClientOption);
60
- setAccessToken(token: string | undefined | (() => string | undefined | Promise<string | undefined>)): void;
61
10
  request(init: RequestInit & {
62
11
  path: string;
63
12
  method: string;
64
13
  query?: Record<string, any>;
65
14
  }): Promise<any>;
15
+ requestStream<T = any>(init: RequestInit & {
16
+ path: string;
17
+ method: string;
18
+ query?: Record<string, any>;
19
+ contentType: string;
20
+ streamingFormat?: 'sse' | 'ndjson' | 'chunked';
21
+ }): AsyncGenerator<T, void, unknown>;
66
22
  }
67
23
 
68
- export { type ClientOption, CoreClient, FetchError };
24
+ export { type ClientOption, CoreClient };