@blimu/client 0.5.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 ADDED
@@ -0,0 +1,167 @@
1
+ # Blimu TypeScript SDK
2
+
3
+ This is an auto-generated TypeScript/JavaScript SDK for the Blimu API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @blimu/client
9
+ # or
10
+ yarn add @blimu/client
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { BlimuClient } from '@blimu/client';
17
+
18
+ // Create a new client
19
+ const client = new BlimuClient({
20
+ baseURL: 'https://api.example.com',
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',
28
+ },
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
+ });
33
+ // Example: Logout and invalidate session
34
+ try {
35
+ const result = await client.auth.logout();
36
+ console.log('Result:', result);
37
+ } catch (error) {
38
+ // ApiError with structured data
39
+ console.error(error);
40
+ }
41
+ ```
42
+
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
+ ## TypeScript Support
105
+
106
+ This SDK is written in TypeScript and provides full type safety:
107
+
108
+ ```typescript
109
+ import { BlimuClient, Schema } from '@blimu/client';
110
+
111
+ const client = new BlimuClient({
112
+ /* config */
113
+ });
114
+
115
+ // All methods are fully typed
116
+ const result: unknown = await client.auth.logout(/* ... */);
117
+
118
+ // Schema types are available
119
+ const data: Schema.RefreshResponse = {
120
+ // Fully typed object
121
+ };
122
+ ```
123
+
124
+ ## Node.js Usage
125
+
126
+ For Node.js environments, you may need to provide a fetch implementation:
127
+
128
+ ```bash
129
+ npm install undici
130
+ ```
131
+
132
+ ```typescript
133
+ import { fetch } from 'undici';
134
+ import { BlimuClient } from '@blimu/client';
135
+
136
+ const client = new BlimuClient({
137
+ baseURL: 'https://api.example.com',
138
+ fetch,
139
+ });
140
+ ```
141
+
142
+ ## Models and Types
143
+
144
+ The SDK includes the following TypeScript interfaces:
145
+
146
+ - **RefreshResponse**
147
+ - **SessionResponse**
148
+
149
+ All types are available under the `Schema` namespace:
150
+
151
+ ```typescript
152
+ import { Schema } from '@blimu/client';
153
+
154
+ // Use any model type
155
+ const user: Schema.User = {
156
+ /* ... */
157
+ };
158
+ ```
159
+
160
+ ## Contributing
161
+
162
+ This SDK is auto-generated. Please do not edit the generated files directly.
163
+ If you find issues, please report them in the main project repository.
164
+
165
+ ## License
166
+
167
+ This SDK is generated from the Blimu API specification.
@@ -0,0 +1,6 @@
1
+ // src/schema.ts
2
+ var schema_exports = {};
3
+
4
+ export {
5
+ schema_exports
6
+ };
@@ -0,0 +1,122 @@
1
+ // src/client.ts
2
+ var FetchError = class extends Error {
3
+ constructor(message, status, data, headers) {
4
+ super(message);
5
+ this.status = status;
6
+ this.data = data;
7
+ this.headers = headers;
8
+ this.name = "FetchError";
9
+ }
10
+ };
11
+ var CoreClient = class {
12
+ constructor(cfg = {}) {
13
+ this.cfg = cfg;
14
+ if (!this.cfg.baseURL) {
15
+ if (this.cfg.env && this.cfg.envBaseURLs) {
16
+ this.cfg.baseURL = this.cfg.env === "production" ? this.cfg.envBaseURLs.production : this.cfg.envBaseURLs.sandbox;
17
+ } else {
18
+ this.cfg.baseURL = "https://api.blimu.dev";
19
+ }
20
+ }
21
+ }
22
+ setAccessToken(token) {
23
+ this.cfg.accessToken = token;
24
+ }
25
+ async request(init) {
26
+ let normalizedPath = init.path || "";
27
+ if (normalizedPath.length > 1 && normalizedPath.endsWith("/")) {
28
+ normalizedPath = normalizedPath.slice(0, -1);
29
+ }
30
+ const url = new URL((this.cfg.baseURL || "") + normalizedPath);
31
+ if (init.query) {
32
+ Object.entries(init.query).forEach(([k, v]) => {
33
+ if (v === void 0 || v === null) return;
34
+ if (Array.isArray(v)) v.forEach((vv) => url.searchParams.append(k, String(vv)));
35
+ else url.searchParams.set(k, String(v));
36
+ });
37
+ }
38
+ const headers = new Headers({
39
+ ...this.cfg.headers || {},
40
+ ...init.headers
41
+ });
42
+ if (this.cfg.accessToken) {
43
+ const token = typeof this.cfg.accessToken === "function" ? await this.cfg.accessToken() : this.cfg.accessToken;
44
+ if (token != null) {
45
+ const name = this.cfg.headerName || "Authorization";
46
+ if (name.toLowerCase() === "authorization") headers.set(name, `Bearer ${String(token)}`);
47
+ else headers.set(name, String(token));
48
+ }
49
+ }
50
+ if (this.cfg.bearer) headers.set("Authorization", `Bearer ${this.cfg.bearer}`);
51
+ const doFetch = async (attempt) => {
52
+ const requestHeaders = new Headers(headers);
53
+ const fetchInit = {
54
+ ...init,
55
+ headers: requestHeaders
56
+ };
57
+ if (this.cfg.onRequest)
58
+ await this.cfg.onRequest({ url: url.toString(), init: fetchInit, attempt });
59
+ let controller;
60
+ let timeoutId;
61
+ if (this.cfg.timeoutMs && typeof AbortController !== "undefined") {
62
+ controller = new AbortController();
63
+ fetchInit.signal = controller.signal;
64
+ timeoutId = setTimeout(() => controller?.abort(), this.cfg.timeoutMs);
65
+ }
66
+ try {
67
+ const res = await (this.cfg.fetch || fetch)(url.toString(), fetchInit);
68
+ if (this.cfg.onResponse)
69
+ await this.cfg.onResponse({
70
+ url: url.toString(),
71
+ init: fetchInit,
72
+ attempt,
73
+ response: res
74
+ });
75
+ const ct = res.headers.get("content-type") || "";
76
+ let parsed;
77
+ if (ct.includes("application/json")) {
78
+ parsed = await res.json();
79
+ } else if (ct.startsWith("text/")) {
80
+ parsed = await res.text();
81
+ } else {
82
+ parsed = await res.arrayBuffer();
83
+ }
84
+ if (!res.ok) {
85
+ throw new FetchError(`HTTP ${res.status}`, res.status, parsed, res.headers);
86
+ }
87
+ return parsed;
88
+ } catch (err) {
89
+ if (this.cfg.onError) await this.cfg.onError(err, { url: url.toString(), init, attempt });
90
+ throw err;
91
+ } finally {
92
+ if (timeoutId) clearTimeout(timeoutId);
93
+ }
94
+ };
95
+ const retries = this.cfg.retry?.retries ?? 0;
96
+ const baseBackoff = this.cfg.retry?.backoffMs ?? 300;
97
+ const retryOn = this.cfg.retry?.retryOn ?? [429, 500, 502, 503, 504];
98
+ let lastError;
99
+ for (let attempt = 0; attempt <= retries; attempt++) {
100
+ try {
101
+ return await doFetch(attempt);
102
+ } catch (err) {
103
+ const status = err?.status;
104
+ const shouldRetry = status ? retryOn.includes(status) : true;
105
+ if (attempt < retries && shouldRetry) {
106
+ const delay = baseBackoff * Math.pow(2, attempt);
107
+ await new Promise((r) => setTimeout(r, delay));
108
+ lastError = err;
109
+ continue;
110
+ }
111
+ if (err instanceof FetchError) throw err;
112
+ throw new FetchError(err?.message || "Network error", status ?? 0);
113
+ }
114
+ }
115
+ throw lastError;
116
+ }
117
+ };
118
+
119
+ export {
120
+ FetchError,
121
+ CoreClient
122
+ };
@@ -0,0 +1,25 @@
1
+ // src/utils.ts
2
+ async function* paginate(fetchPage, initialQuery = {}, pageSize = 100) {
3
+ let offset = Number(initialQuery.offset ?? 0);
4
+ const limit = Number(initialQuery.limit ?? pageSize);
5
+ const baseQuery = { ...initialQuery };
6
+ while (true) {
7
+ const page = await fetchPage({ ...baseQuery, limit, offset });
8
+ const items = page.data ?? [];
9
+ for (const item of items) {
10
+ yield item;
11
+ }
12
+ if (!page.hasMore || items.length < limit) break;
13
+ offset += limit;
14
+ }
15
+ }
16
+ async function listAll(fetchPage, query = {}, pageSize = 100) {
17
+ const out = [];
18
+ for await (const item of paginate(fetchPage, query, pageSize)) out.push(item);
19
+ return out;
20
+ }
21
+
22
+ export {
23
+ paginate,
24
+ listAll
25
+ };
@@ -0,0 +1,43 @@
1
+ // src/services/auth.ts
2
+ var AuthService = class {
3
+ constructor(core) {
4
+ this.core = core;
5
+ }
6
+ /**
7
+ * POST /v1/auth/logout
8
+ * @summary Logout and invalidate session
9
+ */
10
+ logout(init) {
11
+ return this.core.request({
12
+ method: "POST",
13
+ path: `/v1/auth/logout`,
14
+ ...init || {}
15
+ });
16
+ }
17
+ /**
18
+ * POST /v1/auth/refresh
19
+ * @summary Refresh session token
20
+ */
21
+ refresh(init) {
22
+ return this.core.request({
23
+ method: "POST",
24
+ path: `/v1/auth/refresh`,
25
+ ...init || {}
26
+ });
27
+ }
28
+ /**
29
+ * GET /v1/auth/session
30
+ * @summary Get current session
31
+ */
32
+ getSession(init) {
33
+ return this.core.request({
34
+ method: "GET",
35
+ path: `/v1/auth/session`,
36
+ ...init || {}
37
+ });
38
+ }
39
+ };
40
+
41
+ export {
42
+ AuthService
43
+ };
@@ -0,0 +1,67 @@
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
+ };
50
+ declare class FetchError<T = unknown> extends Error {
51
+ readonly status: number;
52
+ readonly data?: T | undefined;
53
+ readonly headers?: Headers | undefined;
54
+ constructor(message: string, status: number, data?: T | undefined, headers?: Headers | undefined);
55
+ }
56
+ declare class CoreClient {
57
+ private cfg;
58
+ constructor(cfg?: ClientOption);
59
+ setAccessToken(token: string | undefined | (() => string | undefined | Promise<string | undefined>)): void;
60
+ request(init: RequestInit & {
61
+ path: string;
62
+ method: string;
63
+ query?: Record<string, any>;
64
+ }): Promise<any>;
65
+ }
66
+
67
+ export { type ClientOption, CoreClient, FetchError };
@@ -0,0 +1,67 @@
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
+ };
50
+ declare class FetchError<T = unknown> extends Error {
51
+ readonly status: number;
52
+ readonly data?: T | undefined;
53
+ readonly headers?: Headers | undefined;
54
+ constructor(message: string, status: number, data?: T | undefined, headers?: Headers | undefined);
55
+ }
56
+ declare class CoreClient {
57
+ private cfg;
58
+ constructor(cfg?: ClientOption);
59
+ setAccessToken(token: string | undefined | (() => string | undefined | Promise<string | undefined>)): void;
60
+ request(init: RequestInit & {
61
+ path: string;
62
+ method: string;
63
+ query?: Record<string, any>;
64
+ }): Promise<any>;
65
+ }
66
+
67
+ export { type ClientOption, CoreClient, FetchError };
package/dist/client.js ADDED
@@ -0,0 +1,146 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/client.ts
20
+ var client_exports = {};
21
+ __export(client_exports, {
22
+ CoreClient: () => CoreClient,
23
+ FetchError: () => FetchError
24
+ });
25
+ module.exports = __toCommonJS(client_exports);
26
+ var FetchError = class extends Error {
27
+ constructor(message, status, data, headers) {
28
+ super(message);
29
+ this.status = status;
30
+ this.data = data;
31
+ this.headers = headers;
32
+ this.name = "FetchError";
33
+ }
34
+ };
35
+ var CoreClient = class {
36
+ constructor(cfg = {}) {
37
+ this.cfg = cfg;
38
+ if (!this.cfg.baseURL) {
39
+ if (this.cfg.env && this.cfg.envBaseURLs) {
40
+ this.cfg.baseURL = this.cfg.env === "production" ? this.cfg.envBaseURLs.production : this.cfg.envBaseURLs.sandbox;
41
+ } else {
42
+ this.cfg.baseURL = "https://api.blimu.dev";
43
+ }
44
+ }
45
+ }
46
+ setAccessToken(token) {
47
+ this.cfg.accessToken = token;
48
+ }
49
+ async request(init) {
50
+ let normalizedPath = init.path || "";
51
+ if (normalizedPath.length > 1 && normalizedPath.endsWith("/")) {
52
+ normalizedPath = normalizedPath.slice(0, -1);
53
+ }
54
+ const url = new URL((this.cfg.baseURL || "") + normalizedPath);
55
+ if (init.query) {
56
+ Object.entries(init.query).forEach(([k, v]) => {
57
+ if (v === void 0 || v === null) return;
58
+ if (Array.isArray(v)) v.forEach((vv) => url.searchParams.append(k, String(vv)));
59
+ else url.searchParams.set(k, String(v));
60
+ });
61
+ }
62
+ const headers = new Headers({
63
+ ...this.cfg.headers || {},
64
+ ...init.headers
65
+ });
66
+ if (this.cfg.accessToken) {
67
+ const token = typeof this.cfg.accessToken === "function" ? await this.cfg.accessToken() : this.cfg.accessToken;
68
+ if (token != null) {
69
+ const name = this.cfg.headerName || "Authorization";
70
+ if (name.toLowerCase() === "authorization") headers.set(name, `Bearer ${String(token)}`);
71
+ else headers.set(name, String(token));
72
+ }
73
+ }
74
+ if (this.cfg.bearer) headers.set("Authorization", `Bearer ${this.cfg.bearer}`);
75
+ const doFetch = async (attempt) => {
76
+ const requestHeaders = new Headers(headers);
77
+ const fetchInit = {
78
+ ...init,
79
+ headers: requestHeaders
80
+ };
81
+ if (this.cfg.onRequest)
82
+ await this.cfg.onRequest({ url: url.toString(), init: fetchInit, attempt });
83
+ let controller;
84
+ let timeoutId;
85
+ if (this.cfg.timeoutMs && typeof AbortController !== "undefined") {
86
+ controller = new AbortController();
87
+ fetchInit.signal = controller.signal;
88
+ timeoutId = setTimeout(() => controller?.abort(), this.cfg.timeoutMs);
89
+ }
90
+ try {
91
+ const res = await (this.cfg.fetch || fetch)(url.toString(), fetchInit);
92
+ if (this.cfg.onResponse)
93
+ await this.cfg.onResponse({
94
+ url: url.toString(),
95
+ init: fetchInit,
96
+ attempt,
97
+ response: res
98
+ });
99
+ const ct = res.headers.get("content-type") || "";
100
+ let parsed;
101
+ if (ct.includes("application/json")) {
102
+ parsed = await res.json();
103
+ } else if (ct.startsWith("text/")) {
104
+ parsed = await res.text();
105
+ } else {
106
+ parsed = await res.arrayBuffer();
107
+ }
108
+ if (!res.ok) {
109
+ throw new FetchError(`HTTP ${res.status}`, res.status, parsed, res.headers);
110
+ }
111
+ return parsed;
112
+ } catch (err) {
113
+ if (this.cfg.onError) await this.cfg.onError(err, { url: url.toString(), init, attempt });
114
+ throw err;
115
+ } finally {
116
+ if (timeoutId) clearTimeout(timeoutId);
117
+ }
118
+ };
119
+ const retries = this.cfg.retry?.retries ?? 0;
120
+ const baseBackoff = this.cfg.retry?.backoffMs ?? 300;
121
+ const retryOn = this.cfg.retry?.retryOn ?? [429, 500, 502, 503, 504];
122
+ let lastError;
123
+ for (let attempt = 0; attempt <= retries; attempt++) {
124
+ try {
125
+ return await doFetch(attempt);
126
+ } catch (err) {
127
+ const status = err?.status;
128
+ const shouldRetry = status ? retryOn.includes(status) : true;
129
+ if (attempt < retries && shouldRetry) {
130
+ const delay = baseBackoff * Math.pow(2, attempt);
131
+ await new Promise((r) => setTimeout(r, delay));
132
+ lastError = err;
133
+ continue;
134
+ }
135
+ if (err instanceof FetchError) throw err;
136
+ throw new FetchError(err?.message || "Network error", status ?? 0);
137
+ }
138
+ }
139
+ throw lastError;
140
+ }
141
+ };
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ CoreClient,
145
+ FetchError
146
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ CoreClient,
3
+ FetchError
4
+ } from "./chunk-GA44NLBR.mjs";
5
+ export {
6
+ CoreClient,
7
+ FetchError
8
+ };
@@ -0,0 +1,13 @@
1
+ import { ClientOption, FetchError } from './client.mjs';
2
+ import { AuthService } from './services/auth.mjs';
3
+ export { PaginableQuery, listAll, paginate } from './utils.mjs';
4
+ export { s as Schema } from './schema-C3_USjmu.mjs';
5
+
6
+ declare class Blimu {
7
+ readonly auth: AuthService;
8
+ constructor(options?: ClientOption);
9
+ }
10
+
11
+ declare const BlimuError: typeof FetchError;
12
+
13
+ export { AuthService, Blimu, BlimuError, ClientOption, FetchError };
@@ -0,0 +1,13 @@
1
+ import { ClientOption, FetchError } from './client.js';
2
+ import { AuthService } from './services/auth.js';
3
+ export { PaginableQuery, listAll, paginate } from './utils.js';
4
+ export { s as Schema } from './schema-C3_USjmu.js';
5
+
6
+ declare class Blimu {
7
+ readonly auth: AuthService;
8
+ constructor(options?: ClientOption);
9
+ }
10
+
11
+ declare const BlimuError: typeof FetchError;
12
+
13
+ export { AuthService, Blimu, BlimuError, ClientOption, FetchError };
package/dist/index.js ADDED
@@ -0,0 +1,231 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ AuthService: () => AuthService,
23
+ Blimu: () => Blimu,
24
+ BlimuError: () => BlimuError,
25
+ FetchError: () => FetchError,
26
+ Schema: () => schema_exports,
27
+ listAll: () => listAll,
28
+ paginate: () => paginate
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+
32
+ // src/client.ts
33
+ var FetchError = class extends Error {
34
+ constructor(message, status, data, headers) {
35
+ super(message);
36
+ this.status = status;
37
+ this.data = data;
38
+ this.headers = headers;
39
+ this.name = "FetchError";
40
+ }
41
+ };
42
+ var CoreClient = class {
43
+ constructor(cfg = {}) {
44
+ this.cfg = cfg;
45
+ if (!this.cfg.baseURL) {
46
+ if (this.cfg.env && this.cfg.envBaseURLs) {
47
+ this.cfg.baseURL = this.cfg.env === "production" ? this.cfg.envBaseURLs.production : this.cfg.envBaseURLs.sandbox;
48
+ } else {
49
+ this.cfg.baseURL = "https://api.blimu.dev";
50
+ }
51
+ }
52
+ }
53
+ setAccessToken(token) {
54
+ this.cfg.accessToken = token;
55
+ }
56
+ async request(init) {
57
+ let normalizedPath = init.path || "";
58
+ if (normalizedPath.length > 1 && normalizedPath.endsWith("/")) {
59
+ normalizedPath = normalizedPath.slice(0, -1);
60
+ }
61
+ const url = new URL((this.cfg.baseURL || "") + normalizedPath);
62
+ if (init.query) {
63
+ Object.entries(init.query).forEach(([k, v]) => {
64
+ if (v === void 0 || v === null) return;
65
+ if (Array.isArray(v)) v.forEach((vv) => url.searchParams.append(k, String(vv)));
66
+ else url.searchParams.set(k, String(v));
67
+ });
68
+ }
69
+ const headers = new Headers({
70
+ ...this.cfg.headers || {},
71
+ ...init.headers
72
+ });
73
+ if (this.cfg.accessToken) {
74
+ const token = typeof this.cfg.accessToken === "function" ? await this.cfg.accessToken() : this.cfg.accessToken;
75
+ if (token != null) {
76
+ const name = this.cfg.headerName || "Authorization";
77
+ if (name.toLowerCase() === "authorization") headers.set(name, `Bearer ${String(token)}`);
78
+ else headers.set(name, String(token));
79
+ }
80
+ }
81
+ if (this.cfg.bearer) headers.set("Authorization", `Bearer ${this.cfg.bearer}`);
82
+ const doFetch = async (attempt) => {
83
+ const requestHeaders = new Headers(headers);
84
+ const fetchInit = {
85
+ ...init,
86
+ headers: requestHeaders
87
+ };
88
+ if (this.cfg.onRequest)
89
+ await this.cfg.onRequest({ url: url.toString(), init: fetchInit, attempt });
90
+ let controller;
91
+ let timeoutId;
92
+ if (this.cfg.timeoutMs && typeof AbortController !== "undefined") {
93
+ controller = new AbortController();
94
+ fetchInit.signal = controller.signal;
95
+ timeoutId = setTimeout(() => controller?.abort(), this.cfg.timeoutMs);
96
+ }
97
+ try {
98
+ const res = await (this.cfg.fetch || fetch)(url.toString(), fetchInit);
99
+ if (this.cfg.onResponse)
100
+ await this.cfg.onResponse({
101
+ url: url.toString(),
102
+ init: fetchInit,
103
+ attempt,
104
+ response: res
105
+ });
106
+ const ct = res.headers.get("content-type") || "";
107
+ let parsed;
108
+ if (ct.includes("application/json")) {
109
+ parsed = await res.json();
110
+ } else if (ct.startsWith("text/")) {
111
+ parsed = await res.text();
112
+ } else {
113
+ parsed = await res.arrayBuffer();
114
+ }
115
+ if (!res.ok) {
116
+ throw new FetchError(`HTTP ${res.status}`, res.status, parsed, res.headers);
117
+ }
118
+ return parsed;
119
+ } catch (err) {
120
+ if (this.cfg.onError) await this.cfg.onError(err, { url: url.toString(), init, attempt });
121
+ throw err;
122
+ } finally {
123
+ if (timeoutId) clearTimeout(timeoutId);
124
+ }
125
+ };
126
+ const retries = this.cfg.retry?.retries ?? 0;
127
+ const baseBackoff = this.cfg.retry?.backoffMs ?? 300;
128
+ const retryOn = this.cfg.retry?.retryOn ?? [429, 500, 502, 503, 504];
129
+ let lastError;
130
+ for (let attempt = 0; attempt <= retries; attempt++) {
131
+ try {
132
+ return await doFetch(attempt);
133
+ } catch (err) {
134
+ const status = err?.status;
135
+ const shouldRetry = status ? retryOn.includes(status) : true;
136
+ if (attempt < retries && shouldRetry) {
137
+ const delay = baseBackoff * Math.pow(2, attempt);
138
+ await new Promise((r) => setTimeout(r, delay));
139
+ lastError = err;
140
+ continue;
141
+ }
142
+ if (err instanceof FetchError) throw err;
143
+ throw new FetchError(err?.message || "Network error", status ?? 0);
144
+ }
145
+ }
146
+ throw lastError;
147
+ }
148
+ };
149
+
150
+ // src/services/auth.ts
151
+ var AuthService = class {
152
+ constructor(core) {
153
+ this.core = core;
154
+ }
155
+ /**
156
+ * POST /v1/auth/logout
157
+ * @summary Logout and invalidate session
158
+ */
159
+ logout(init) {
160
+ return this.core.request({
161
+ method: "POST",
162
+ path: `/v1/auth/logout`,
163
+ ...init || {}
164
+ });
165
+ }
166
+ /**
167
+ * POST /v1/auth/refresh
168
+ * @summary Refresh session token
169
+ */
170
+ refresh(init) {
171
+ return this.core.request({
172
+ method: "POST",
173
+ path: `/v1/auth/refresh`,
174
+ ...init || {}
175
+ });
176
+ }
177
+ /**
178
+ * GET /v1/auth/session
179
+ * @summary Get current session
180
+ */
181
+ getSession(init) {
182
+ return this.core.request({
183
+ method: "GET",
184
+ path: `/v1/auth/session`,
185
+ ...init || {}
186
+ });
187
+ }
188
+ };
189
+
190
+ // src/utils.ts
191
+ async function* paginate(fetchPage, initialQuery = {}, pageSize = 100) {
192
+ let offset = Number(initialQuery.offset ?? 0);
193
+ const limit = Number(initialQuery.limit ?? pageSize);
194
+ const baseQuery = { ...initialQuery };
195
+ while (true) {
196
+ const page = await fetchPage({ ...baseQuery, limit, offset });
197
+ const items = page.data ?? [];
198
+ for (const item of items) {
199
+ yield item;
200
+ }
201
+ if (!page.hasMore || items.length < limit) break;
202
+ offset += limit;
203
+ }
204
+ }
205
+ async function listAll(fetchPage, query = {}, pageSize = 100) {
206
+ const out = [];
207
+ for await (const item of paginate(fetchPage, query, pageSize)) out.push(item);
208
+ return out;
209
+ }
210
+
211
+ // src/schema.ts
212
+ var schema_exports = {};
213
+
214
+ // src/index.ts
215
+ var Blimu = class {
216
+ constructor(options) {
217
+ const core = new CoreClient(options);
218
+ this.auth = new AuthService(core);
219
+ }
220
+ };
221
+ var BlimuError = FetchError;
222
+ // Annotate the CommonJS export names for ESM import in node:
223
+ 0 && (module.exports = {
224
+ AuthService,
225
+ Blimu,
226
+ BlimuError,
227
+ FetchError,
228
+ Schema,
229
+ listAll,
230
+ paginate
231
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import {
2
+ CoreClient,
3
+ FetchError
4
+ } from "./chunk-GA44NLBR.mjs";
5
+ import {
6
+ schema_exports
7
+ } from "./chunk-7SBLH5KM.mjs";
8
+ import {
9
+ listAll,
10
+ paginate
11
+ } from "./chunk-LZ27JJ4R.mjs";
12
+ import {
13
+ AuthService
14
+ } from "./chunk-UTMQXMDQ.mjs";
15
+
16
+ // src/index.ts
17
+ var Blimu = class {
18
+ constructor(options) {
19
+ const core = new CoreClient(options);
20
+ this.auth = new AuthService(core);
21
+ }
22
+ };
23
+ var BlimuError = FetchError;
24
+ export {
25
+ AuthService,
26
+ Blimu,
27
+ BlimuError,
28
+ FetchError,
29
+ schema_exports as Schema,
30
+ listAll,
31
+ paginate
32
+ };
@@ -0,0 +1,23 @@
1
+ type Enum<T> = T[keyof T];
2
+ interface RefreshResponse {
3
+ sessionToken: string;
4
+ }
5
+ interface SessionResponse {
6
+ isAuthenticated: boolean;
7
+ user: {
8
+ email: string;
9
+ emailVerified: boolean;
10
+ firstName: string | null;
11
+ id: string;
12
+ lastName: string | null;
13
+ } | null;
14
+ }
15
+
16
+ type schema_Enum<T> = Enum<T>;
17
+ type schema_RefreshResponse = RefreshResponse;
18
+ type schema_SessionResponse = SessionResponse;
19
+ declare namespace schema {
20
+ export type { schema_Enum as Enum, schema_RefreshResponse as RefreshResponse, schema_SessionResponse as SessionResponse };
21
+ }
22
+
23
+ export { type Enum as E, type RefreshResponse as R, type SessionResponse as S, schema as s };
@@ -0,0 +1,23 @@
1
+ type Enum<T> = T[keyof T];
2
+ interface RefreshResponse {
3
+ sessionToken: string;
4
+ }
5
+ interface SessionResponse {
6
+ isAuthenticated: boolean;
7
+ user: {
8
+ email: string;
9
+ emailVerified: boolean;
10
+ firstName: string | null;
11
+ id: string;
12
+ lastName: string | null;
13
+ } | null;
14
+ }
15
+
16
+ type schema_Enum<T> = Enum<T>;
17
+ type schema_RefreshResponse = RefreshResponse;
18
+ type schema_SessionResponse = SessionResponse;
19
+ declare namespace schema {
20
+ export type { schema_Enum as Enum, schema_RefreshResponse as RefreshResponse, schema_SessionResponse as SessionResponse };
21
+ }
22
+
23
+ export { type Enum as E, type RefreshResponse as R, type SessionResponse as S, schema as s };
@@ -0,0 +1 @@
1
+ export { E as Enum, R as RefreshResponse, S as SessionResponse } from './schema-C3_USjmu.mjs';
@@ -0,0 +1 @@
1
+ export { E as Enum, R as RefreshResponse, S as SessionResponse } from './schema-C3_USjmu.js';
package/dist/schema.js ADDED
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/schema.ts
16
+ var schema_exports = {};
17
+ module.exports = __toCommonJS(schema_exports);
@@ -0,0 +1 @@
1
+ import "./chunk-7SBLH5KM.mjs";
@@ -0,0 +1,12 @@
1
+ import { CoreClient } from '../client.mjs';
2
+ import { R as RefreshResponse, S as SessionResponse } from '../schema-C3_USjmu.mjs';
3
+
4
+ declare class AuthService {
5
+ private core;
6
+ constructor(core: CoreClient);
7
+ logout(init?: Omit<RequestInit, 'method' | 'body'>): Promise<unknown>;
8
+ refresh(init?: Omit<RequestInit, 'method' | 'body'>): Promise<RefreshResponse>;
9
+ getSession(init?: Omit<RequestInit, 'method' | 'body'>): Promise<SessionResponse>;
10
+ }
11
+
12
+ export { AuthService };
@@ -0,0 +1,12 @@
1
+ import { CoreClient } from '../client.js';
2
+ import { R as RefreshResponse, S as SessionResponse } from '../schema-C3_USjmu.js';
3
+
4
+ declare class AuthService {
5
+ private core;
6
+ constructor(core: CoreClient);
7
+ logout(init?: Omit<RequestInit, 'method' | 'body'>): Promise<unknown>;
8
+ refresh(init?: Omit<RequestInit, 'method' | 'body'>): Promise<RefreshResponse>;
9
+ getSession(init?: Omit<RequestInit, 'method' | 'body'>): Promise<SessionResponse>;
10
+ }
11
+
12
+ export { AuthService };
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/services/auth.ts
20
+ var auth_exports = {};
21
+ __export(auth_exports, {
22
+ AuthService: () => AuthService
23
+ });
24
+ module.exports = __toCommonJS(auth_exports);
25
+ var AuthService = class {
26
+ constructor(core) {
27
+ this.core = core;
28
+ }
29
+ /**
30
+ * POST /v1/auth/logout
31
+ * @summary Logout and invalidate session
32
+ */
33
+ logout(init) {
34
+ return this.core.request({
35
+ method: "POST",
36
+ path: `/v1/auth/logout`,
37
+ ...init || {}
38
+ });
39
+ }
40
+ /**
41
+ * POST /v1/auth/refresh
42
+ * @summary Refresh session token
43
+ */
44
+ refresh(init) {
45
+ return this.core.request({
46
+ method: "POST",
47
+ path: `/v1/auth/refresh`,
48
+ ...init || {}
49
+ });
50
+ }
51
+ /**
52
+ * GET /v1/auth/session
53
+ * @summary Get current session
54
+ */
55
+ getSession(init) {
56
+ return this.core.request({
57
+ method: "GET",
58
+ path: `/v1/auth/session`,
59
+ ...init || {}
60
+ });
61
+ }
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ AuthService
66
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ AuthService
3
+ } from "../chunk-UTMQXMDQ.mjs";
4
+ export {
5
+ AuthService
6
+ };
@@ -0,0 +1,18 @@
1
+ type PaginableQuery = {
2
+ limit?: number;
3
+ offset?: number;
4
+ } & Record<string, unknown>;
5
+ declare function paginate<T>(fetchPage: (query?: any, init?: Omit<RequestInit, 'method' | 'body'>) => Promise<{
6
+ data?: T[];
7
+ hasMore?: boolean;
8
+ limit?: number;
9
+ offset?: number;
10
+ }>, initialQuery?: PaginableQuery, pageSize?: number): AsyncGenerator<T, void, unknown>;
11
+ declare function listAll<T>(fetchPage: (query?: any, init?: Omit<RequestInit, 'method' | 'body'>) => Promise<{
12
+ data?: T[];
13
+ hasMore?: boolean;
14
+ limit?: number;
15
+ offset?: number;
16
+ }>, query?: PaginableQuery, pageSize?: number): Promise<T[]>;
17
+
18
+ export { type PaginableQuery, listAll, paginate };
@@ -0,0 +1,18 @@
1
+ type PaginableQuery = {
2
+ limit?: number;
3
+ offset?: number;
4
+ } & Record<string, unknown>;
5
+ declare function paginate<T>(fetchPage: (query?: any, init?: Omit<RequestInit, 'method' | 'body'>) => Promise<{
6
+ data?: T[];
7
+ hasMore?: boolean;
8
+ limit?: number;
9
+ offset?: number;
10
+ }>, initialQuery?: PaginableQuery, pageSize?: number): AsyncGenerator<T, void, unknown>;
11
+ declare function listAll<T>(fetchPage: (query?: any, init?: Omit<RequestInit, 'method' | 'body'>) => Promise<{
12
+ data?: T[];
13
+ hasMore?: boolean;
14
+ limit?: number;
15
+ offset?: number;
16
+ }>, query?: PaginableQuery, pageSize?: number): Promise<T[]>;
17
+
18
+ export { type PaginableQuery, listAll, paginate };
package/dist/utils.js ADDED
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ listAll: () => listAll,
23
+ paginate: () => paginate
24
+ });
25
+ module.exports = __toCommonJS(utils_exports);
26
+ async function* paginate(fetchPage, initialQuery = {}, pageSize = 100) {
27
+ let offset = Number(initialQuery.offset ?? 0);
28
+ const limit = Number(initialQuery.limit ?? pageSize);
29
+ const baseQuery = { ...initialQuery };
30
+ while (true) {
31
+ const page = await fetchPage({ ...baseQuery, limit, offset });
32
+ const items = page.data ?? [];
33
+ for (const item of items) {
34
+ yield item;
35
+ }
36
+ if (!page.hasMore || items.length < limit) break;
37
+ offset += limit;
38
+ }
39
+ }
40
+ async function listAll(fetchPage, query = {}, pageSize = 100) {
41
+ const out = [];
42
+ for await (const item of paginate(fetchPage, query, pageSize)) out.push(item);
43
+ return out;
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ listAll,
48
+ paginate
49
+ });
package/dist/utils.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ listAll,
3
+ paginate
4
+ } from "./chunk-LZ27JJ4R.mjs";
5
+ export {
6
+ listAll,
7
+ paginate
8
+ };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@blimu/client",
3
+ "version": "0.5.0",
4
+ "description": "TypeScript SDK for Blimu API (auto-generated)",
5
+ "repository": "https://github.com/blimu/blimu-ts",
6
+ "author": "viniciusdacal",
7
+ "license": "MIT",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "dist/**"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.mjs"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ }
26
+ },
27
+ "./services/*": {
28
+ "types": "./dist/services/*.d.ts",
29
+ "import": "./dist/services/*.mjs",
30
+ "require": "./dist/services/*.js"
31
+ },
32
+ "./schema": {
33
+ "import": {
34
+ "types": "./dist/schema.d.ts",
35
+ "default": "./dist/schema.mjs"
36
+ },
37
+ "require": {
38
+ "types": "./dist/schema.d.ts",
39
+ "default": "./dist/schema.js"
40
+ }
41
+ },
42
+ "./client": {
43
+ "import": {
44
+ "types": "./dist/client.d.ts",
45
+ "default": "./dist/client.mjs"
46
+ },
47
+ "require": {
48
+ "types": "./dist/client.d.ts",
49
+ "default": "./dist/client.js"
50
+ }
51
+ },
52
+ "./utils": {
53
+ "import": {
54
+ "types": "./dist/utils.d.ts",
55
+ "default": "./dist/utils.mjs"
56
+ },
57
+ "require": {
58
+ "types": "./dist/utils.d.ts",
59
+ "default": "./dist/utils.js"
60
+ }
61
+ }
62
+ },
63
+ "scripts": {
64
+ "build": "tsup src/index.ts src/services/*.ts src/schema.ts src/client.ts src/utils.ts --format cjs,esm --dts",
65
+ "typecheck": "tsc -p tsconfig.json --noEmit",
66
+ "lint": "eslint .",
67
+ "format": "eslint --fix . && prettier --write .",
68
+ "prepublishOnly": "npm run build && npm run typecheck || true"
69
+ },
70
+ "devDependencies": {
71
+ "tsup": "^8.5.1"
72
+ }
73
+ }