@edifice.io/rest-client-base 2.5.4-develop-pedago.20251218111023

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.
@@ -0,0 +1,447 @@
1
+ var y = Object.defineProperty;
2
+ var g = (n, t, r) => t in n ? y(n, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[t] = r;
3
+ var h = (n, t, r) => g(n, typeof t != "symbol" ? t + "" : t, r);
4
+ import { ApiProperty as T, ApiPropertyOptional as P } from "@nestjs/swagger";
5
+ class f extends Error {
6
+ /**
7
+ * Create a new API error
8
+ * @param response The original HTTP response
9
+ * @param message Optional custom error message
10
+ */
11
+ constructor(r, e) {
12
+ super(
13
+ e || `API request failed: ${r.status} ${r.statusText}`
14
+ );
15
+ h(this, "_response");
16
+ h(this, "_jsonData", null);
17
+ h(this, "_textData", null);
18
+ this.name = "ApiError", this._response = r, Object.setPrototypeOf(this, f.prototype);
19
+ }
20
+ /**
21
+ * Get the original Response object
22
+ * @returns The original Response
23
+ */
24
+ response() {
25
+ return this._response;
26
+ }
27
+ /**
28
+ * Get the HTTP status code
29
+ * @returns The numeric status code (e.g., 404, 500)
30
+ */
31
+ status() {
32
+ return this._response.status;
33
+ }
34
+ /**
35
+ * Get the HTTP status text
36
+ * @returns The status text (e.g., "Not Found", "Internal Server Error")
37
+ */
38
+ statusText() {
39
+ return this._response.statusText;
40
+ }
41
+ /**
42
+ * Get the response body as JSON
43
+ * @returns Parsed JSON data or null if not available
44
+ * @throws If the response body isn't valid JSON
45
+ */
46
+ async json() {
47
+ if (this._jsonData === null)
48
+ try {
49
+ const r = this._response.clone();
50
+ this._jsonData = await r.json();
51
+ } catch {
52
+ this._jsonData = null;
53
+ }
54
+ return this._jsonData;
55
+ }
56
+ /**
57
+ * Get the response body as text
58
+ * @returns Text content or empty string if not available
59
+ */
60
+ async text() {
61
+ if (this._textData === null)
62
+ try {
63
+ const r = this._response.clone();
64
+ this._textData = await r.text();
65
+ } catch {
66
+ this._textData = "";
67
+ }
68
+ return this._textData;
69
+ }
70
+ }
71
+ class _ {
72
+ constructor(t = fetch) {
73
+ this.fetchImpl = t;
74
+ }
75
+ async handleResponse(t) {
76
+ if (!t.ok)
77
+ throw new f(t);
78
+ const r = t.headers.get("content-type");
79
+ return r && r.includes("application/json") ? await t.json() : {};
80
+ }
81
+ async get(t, r) {
82
+ const e = await this.fetchImpl(t, {
83
+ method: "GET",
84
+ headers: r,
85
+ credentials: "include"
86
+ });
87
+ return this.handleResponse(e);
88
+ }
89
+ async post(t, r, e) {
90
+ const s = await this.fetchImpl(t, {
91
+ method: "POST",
92
+ headers: {
93
+ "Content-Type": "application/json",
94
+ ...e
95
+ },
96
+ body: JSON.stringify(r),
97
+ credentials: "include"
98
+ });
99
+ return this.handleResponse(s);
100
+ }
101
+ async put(t, r, e) {
102
+ const s = await this.fetchImpl(t, {
103
+ method: "PUT",
104
+ headers: {
105
+ "Content-Type": "application/json",
106
+ ...e
107
+ },
108
+ body: JSON.stringify(r),
109
+ credentials: "include"
110
+ });
111
+ return this.handleResponse(s);
112
+ }
113
+ async patch(t, r, e) {
114
+ const s = await this.fetchImpl(t, {
115
+ method: "PATCH",
116
+ headers: {
117
+ "Content-Type": "application/json",
118
+ ...e
119
+ },
120
+ body: JSON.stringify(r),
121
+ credentials: "include"
122
+ });
123
+ return this.handleResponse(s);
124
+ }
125
+ async delete(t, r) {
126
+ const e = await this.fetchImpl(t, {
127
+ method: "DELETE",
128
+ headers: r,
129
+ credentials: "include"
130
+ });
131
+ return this.handleResponse(e);
132
+ }
133
+ async deleteWithBody(t, r, e) {
134
+ const s = await this.fetchImpl(t, {
135
+ method: "DELETE",
136
+ headers: {
137
+ "Content-Type": "application/json",
138
+ ...e
139
+ },
140
+ body: JSON.stringify(r),
141
+ credentials: "include"
142
+ });
143
+ return this.handleResponse(s);
144
+ }
145
+ }
146
+ class M {
147
+ constructor(t) {
148
+ this.httpService = t;
149
+ }
150
+ async get(t, r) {
151
+ const e = r ? { headers: r } : void 0;
152
+ return this.httpService.get(t, e);
153
+ }
154
+ async post(t, r, e) {
155
+ const s = e ? { headers: e } : void 0;
156
+ return this.httpService.postJson(t, r, s);
157
+ }
158
+ async put(t, r, e) {
159
+ const s = e ? { headers: e } : void 0;
160
+ return this.httpService.putJson(t, r, s);
161
+ }
162
+ async patch(t, r, e) {
163
+ const s = e ? { headers: e } : void 0;
164
+ return this.httpService.patchJson(t, r, s);
165
+ }
166
+ async delete(t, r) {
167
+ const e = r ? { headers: r } : void 0;
168
+ return this.httpService.delete(t, e);
169
+ }
170
+ async deleteWithBody(t, r, e) {
171
+ return this.httpService.deleteJson(t, r);
172
+ }
173
+ }
174
+ class x {
175
+ /**
176
+ * Creates a new API client instance
177
+ *
178
+ * @param options Configuration options
179
+ * @param options.baseUrl Base URL for API requests
180
+ * @param options.defaultHeaders Default headers for all requests
181
+ * @param options.fetchImpl Custom fetch implementation (deprecated, use httpAdapter)
182
+ * @param options.httpService Edifice HttpService instance (from odeServices.http())
183
+ * @param options.httpAdapter Custom HTTP adapter implementation
184
+ *
185
+ * @example
186
+ * // With Edifice HttpService
187
+ * import { odeServices } from '@edifice.io/client';
188
+ *
189
+ * const client = new CommunityClient({
190
+ * httpService: odeServices.http(),
191
+ * defaultHeaders: {
192
+ * 'X-Custom-Header': 'value'
193
+ * }
194
+ * });
195
+ */
196
+ constructor(t = {}) {
197
+ /**
198
+ * Base URL for all API requests
199
+ * @protected
200
+ */
201
+ h(this, "baseUrl");
202
+ /**
203
+ * Default headers included with all requests
204
+ * @protected
205
+ */
206
+ h(this, "defaultHeaders");
207
+ /**
208
+ * HTTP adapter for making requests
209
+ * @protected
210
+ */
211
+ h(this, "httpAdapter");
212
+ this.baseUrl = t.baseUrl || "", this.defaultHeaders = t.defaultHeaders || {}, t.httpAdapter ? this.httpAdapter = t.httpAdapter : t.httpService ? this.httpAdapter = new M(t.httpService) : this.httpAdapter = new _(t.fetchImpl || fetch);
213
+ }
214
+ /**
215
+ * Performs a GET request
216
+ * @param endpoint API endpoint path
217
+ * @param queryParams URL query parameters
218
+ * @param options Request options
219
+ * @returns Promise resolving to the response data
220
+ */
221
+ async get(t, r, e) {
222
+ const s = this.buildUrl(t, r);
223
+ return this.httpAdapter.get(s, this.buildHeaders(e == null ? void 0 : e.headers));
224
+ }
225
+ /**
226
+ * Performs a POST request
227
+ * @param endpoint API endpoint path
228
+ * @param body Request body
229
+ * @param queryParams Optional URL query parameters
230
+ * @param options Request options
231
+ * @returns Promise resolving to the response data
232
+ */
233
+ async post(t, r, e, s) {
234
+ const a = this.buildUrl(t, e);
235
+ return this.httpAdapter.post(
236
+ a,
237
+ r,
238
+ this.buildHeaders(s == null ? void 0 : s.headers)
239
+ );
240
+ }
241
+ /**
242
+ * Performs a PUT request
243
+ * @param endpoint API endpoint path
244
+ * @param body Request body
245
+ * @param queryParams Optional URL query parameters
246
+ * @param options Request options
247
+ * @returns Promise resolving to the response data
248
+ */
249
+ async put(t, r, e, s) {
250
+ const a = this.buildUrl(t, e);
251
+ return this.httpAdapter.put(
252
+ a,
253
+ r,
254
+ this.buildHeaders(s == null ? void 0 : s.headers)
255
+ );
256
+ }
257
+ /**
258
+ * Performs a PATCH request
259
+ * @param endpoint API endpoint path
260
+ * @param body Request body
261
+ * @param queryParams Optional URL query parameters
262
+ * @param options Request options
263
+ * @returns Promise resolving to the response data
264
+ */
265
+ async patch(t, r, e, s) {
266
+ const a = this.buildUrl(t, e);
267
+ return this.httpAdapter.patch(
268
+ a,
269
+ r,
270
+ this.buildHeaders(s == null ? void 0 : s.headers)
271
+ );
272
+ }
273
+ /**
274
+ * Performs a DELETE request
275
+ * @param endpoint API endpoint path
276
+ * @param queryParams Optional URL query parameters
277
+ * @param options Request options
278
+ * @returns Promise resolving when the request is complete
279
+ */
280
+ async delete(t, r, e) {
281
+ const s = this.buildUrl(t, r);
282
+ return this.httpAdapter.delete(s, this.buildHeaders(e == null ? void 0 : e.headers));
283
+ }
284
+ /**
285
+ * Performs a DELETE request with body
286
+ * @param endpoint API endpoint path
287
+ * @param body Request body
288
+ * @param queryParams Optional URL query parameters
289
+ * @param options Request options
290
+ * @returns Promise resolving to the response data
291
+ */
292
+ async deleteWithBody(t, r, e, s) {
293
+ const a = this.buildUrl(t, e);
294
+ return this.httpAdapter.deleteWithBody(
295
+ a,
296
+ r,
297
+ this.buildHeaders(s == null ? void 0 : s.headers)
298
+ );
299
+ }
300
+ /**
301
+ * Builds complete URL from endpoint and query parameters
302
+ * @param endpoint API endpoint path
303
+ * @param queryParams Optional query parameters
304
+ * @returns Complete URL
305
+ * @protected
306
+ */
307
+ buildUrl(t, r) {
308
+ let e = `${this.baseUrl}${t}`;
309
+ return e.startsWith("//") && (e = e.replace(/^\/\//, "/")), r && r.toString() && (e += `?${r.toString()}`), e;
310
+ }
311
+ /**
312
+ * Builds headers for a request by combining default and request-specific headers
313
+ * @param additionalHeaders Optional additional headers
314
+ * @returns Combined headers
315
+ * @protected
316
+ */
317
+ buildHeaders(t) {
318
+ return {
319
+ ...this.defaultHeaders,
320
+ ...t
321
+ };
322
+ }
323
+ }
324
+ var o;
325
+ (function(n) {
326
+ n[n.PLAIN_TO_CLASS = 0] = "PLAIN_TO_CLASS", n[n.CLASS_TO_PLAIN = 1] = "CLASS_TO_PLAIN", n[n.CLASS_TO_CLASS = 2] = "CLASS_TO_CLASS";
327
+ })(o || (o = {}));
328
+ var S = (
329
+ /** @class */
330
+ function() {
331
+ function n() {
332
+ this._typeMetadatas = /* @__PURE__ */ new Map(), this._transformMetadatas = /* @__PURE__ */ new Map(), this._exposeMetadatas = /* @__PURE__ */ new Map(), this._excludeMetadatas = /* @__PURE__ */ new Map(), this._ancestorsMap = /* @__PURE__ */ new Map();
333
+ }
334
+ return n.prototype.addTypeMetadata = function(t) {
335
+ this._typeMetadatas.has(t.target) || this._typeMetadatas.set(t.target, /* @__PURE__ */ new Map()), this._typeMetadatas.get(t.target).set(t.propertyName, t);
336
+ }, n.prototype.addTransformMetadata = function(t) {
337
+ this._transformMetadatas.has(t.target) || this._transformMetadatas.set(t.target, /* @__PURE__ */ new Map()), this._transformMetadatas.get(t.target).has(t.propertyName) || this._transformMetadatas.get(t.target).set(t.propertyName, []), this._transformMetadatas.get(t.target).get(t.propertyName).push(t);
338
+ }, n.prototype.addExposeMetadata = function(t) {
339
+ this._exposeMetadatas.has(t.target) || this._exposeMetadatas.set(t.target, /* @__PURE__ */ new Map()), this._exposeMetadatas.get(t.target).set(t.propertyName, t);
340
+ }, n.prototype.addExcludeMetadata = function(t) {
341
+ this._excludeMetadatas.has(t.target) || this._excludeMetadatas.set(t.target, /* @__PURE__ */ new Map()), this._excludeMetadatas.get(t.target).set(t.propertyName, t);
342
+ }, n.prototype.findTransformMetadatas = function(t, r, e) {
343
+ return this.findMetadatas(this._transformMetadatas, t, r).filter(function(s) {
344
+ return !s.options || s.options.toClassOnly === !0 && s.options.toPlainOnly === !0 ? !0 : s.options.toClassOnly === !0 ? e === o.CLASS_TO_CLASS || e === o.PLAIN_TO_CLASS : s.options.toPlainOnly === !0 ? e === o.CLASS_TO_PLAIN : !0;
345
+ });
346
+ }, n.prototype.findExcludeMetadata = function(t, r) {
347
+ return this.findMetadata(this._excludeMetadatas, t, r);
348
+ }, n.prototype.findExposeMetadata = function(t, r) {
349
+ return this.findMetadata(this._exposeMetadatas, t, r);
350
+ }, n.prototype.findExposeMetadataByCustomName = function(t, r) {
351
+ return this.getExposedMetadatas(t).find(function(e) {
352
+ return e.options && e.options.name === r;
353
+ });
354
+ }, n.prototype.findTypeMetadata = function(t, r) {
355
+ return this.findMetadata(this._typeMetadatas, t, r);
356
+ }, n.prototype.getStrategy = function(t) {
357
+ var r = this._excludeMetadatas.get(t), e = r && r.get(void 0), s = this._exposeMetadatas.get(t), a = s && s.get(void 0);
358
+ return e && a || !e && !a ? "none" : e ? "excludeAll" : "exposeAll";
359
+ }, n.prototype.getExposedMetadatas = function(t) {
360
+ return this.getMetadata(this._exposeMetadatas, t);
361
+ }, n.prototype.getExcludedMetadatas = function(t) {
362
+ return this.getMetadata(this._excludeMetadatas, t);
363
+ }, n.prototype.getExposedProperties = function(t, r) {
364
+ return this.getExposedMetadatas(t).filter(function(e) {
365
+ return !e.options || e.options.toClassOnly === !0 && e.options.toPlainOnly === !0 ? !0 : e.options.toClassOnly === !0 ? r === o.CLASS_TO_CLASS || r === o.PLAIN_TO_CLASS : e.options.toPlainOnly === !0 ? r === o.CLASS_TO_PLAIN : !0;
366
+ }).map(function(e) {
367
+ return e.propertyName;
368
+ });
369
+ }, n.prototype.getExcludedProperties = function(t, r) {
370
+ return this.getExcludedMetadatas(t).filter(function(e) {
371
+ return !e.options || e.options.toClassOnly === !0 && e.options.toPlainOnly === !0 ? !0 : e.options.toClassOnly === !0 ? r === o.CLASS_TO_CLASS || r === o.PLAIN_TO_CLASS : e.options.toPlainOnly === !0 ? r === o.CLASS_TO_PLAIN : !0;
372
+ }).map(function(e) {
373
+ return e.propertyName;
374
+ });
375
+ }, n.prototype.clear = function() {
376
+ this._typeMetadatas.clear(), this._exposeMetadatas.clear(), this._excludeMetadatas.clear(), this._ancestorsMap.clear();
377
+ }, n.prototype.getMetadata = function(t, r) {
378
+ var e = t.get(r), s;
379
+ e && (s = Array.from(e.values()).filter(function(l) {
380
+ return l.propertyName !== void 0;
381
+ }));
382
+ for (var a = [], i = 0, p = this.getAncestors(r); i < p.length; i++) {
383
+ var c = p[i], d = t.get(c);
384
+ if (d) {
385
+ var u = Array.from(d.values()).filter(function(l) {
386
+ return l.propertyName !== void 0;
387
+ });
388
+ a.push.apply(a, u);
389
+ }
390
+ }
391
+ return a.concat(s || []);
392
+ }, n.prototype.findMetadata = function(t, r, e) {
393
+ var s = t.get(r);
394
+ if (s) {
395
+ var a = s.get(e);
396
+ if (a)
397
+ return a;
398
+ }
399
+ for (var i = 0, p = this.getAncestors(r); i < p.length; i++) {
400
+ var c = p[i], d = t.get(c);
401
+ if (d) {
402
+ var u = d.get(e);
403
+ if (u)
404
+ return u;
405
+ }
406
+ }
407
+ }, n.prototype.findMetadatas = function(t, r, e) {
408
+ var s = t.get(r), a;
409
+ s && (a = s.get(e));
410
+ for (var i = [], p = 0, c = this.getAncestors(r); p < c.length; p++) {
411
+ var d = c[p], u = t.get(d);
412
+ u && u.has(e) && i.push.apply(i, u.get(e));
413
+ }
414
+ return i.slice().reverse().concat((a || []).slice().reverse());
415
+ }, n.prototype.getAncestors = function(t) {
416
+ if (!t)
417
+ return [];
418
+ if (!this._ancestorsMap.has(t)) {
419
+ for (var r = [], e = Object.getPrototypeOf(t.prototype.constructor); typeof e.prototype < "u"; e = Object.getPrototypeOf(e.prototype.constructor))
420
+ r.push(e);
421
+ this._ancestorsMap.set(t, r);
422
+ }
423
+ return this._ancestorsMap.get(t);
424
+ }, n;
425
+ }()
426
+ ), A = new S();
427
+ function O(n, t) {
428
+ return t === void 0 && (t = {}), function(r, e) {
429
+ var s = Reflect.getMetadata("design:type", r, e);
430
+ A.addTypeMetadata({
431
+ target: r.constructor,
432
+ propertyName: e,
433
+ reflectedType: s,
434
+ typeFunction: n,
435
+ options: t
436
+ });
437
+ };
438
+ }
439
+ export {
440
+ f as ApiError,
441
+ T as ApiProperty,
442
+ P as ApiPropertyOptional,
443
+ x as BaseApiClient,
444
+ _ as FetchAdapter,
445
+ M as HttpServiceAdapter,
446
+ O as Type
447
+ };
@@ -0,0 +1,92 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { ApiPropertyOptional } from '@nestjs/swagger';
3
+ import { ApiPropertyOptions } from '@nestjs/swagger';
4
+ import { odeServices } from '@edifice.io/client';
5
+ import { Type } from 'class-transformer';
6
+
7
+ export declare interface ApiClientOptions {
8
+ baseUrl?: string;
9
+ defaultHeaders?: Record<string, string>;
10
+ fetchImpl?: typeof fetch;
11
+ httpService?: HttpService_2;
12
+ httpAdapter?: HttpAdapter;
13
+ }
14
+
15
+ export declare class ApiError extends Error {
16
+ private _response;
17
+ private _jsonData;
18
+ private _textData;
19
+ constructor(response: Response, message?: string);
20
+ response(): Response;
21
+ status(): number;
22
+ statusText(): string;
23
+ json(): Promise<unknown>;
24
+ text(): Promise<string>;
25
+ }
26
+
27
+ export { ApiProperty }
28
+
29
+ export { ApiPropertyOptional }
30
+
31
+ export { ApiPropertyOptions }
32
+
33
+ export declare abstract class BaseApiClient {
34
+ protected readonly baseUrl: string;
35
+ protected readonly defaultHeaders: Record<string, string>;
36
+ protected readonly httpAdapter: HttpAdapter;
37
+ constructor(options?: ApiClientOptions);
38
+ protected get<T>(endpoint: string, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
39
+ protected post<T, U = unknown>(endpoint: string, body: U, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
40
+ protected put<T, U = unknown>(endpoint: string, body: U, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
41
+ protected patch<T, U = unknown>(endpoint: string, body: U, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
42
+ protected delete<T = void>(endpoint: string, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
43
+ protected deleteWithBody<T, U = unknown>(endpoint: string, body: U, queryParams?: URLSearchParams, options?: RequestOptions): Promise<T>;
44
+ protected buildUrl(endpoint: string, queryParams?: URLSearchParams): string;
45
+ protected buildHeaders(additionalHeaders?: Record<string, string>): Record<string, string>;
46
+ }
47
+
48
+ export declare class FetchAdapter implements HttpAdapter {
49
+ private readonly fetchImpl;
50
+ constructor(fetchImpl?: typeof fetch);
51
+ private handleResponse;
52
+ get<T>(url: string, headers?: Record<string, string>): Promise<T>;
53
+ post<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
54
+ put<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
55
+ patch<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
56
+ delete<T>(url: string, headers?: Record<string, string>): Promise<T>;
57
+ deleteWithBody<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
58
+ }
59
+
60
+ export declare type FetchFunction = typeof fetch;
61
+
62
+ export declare interface HttpAdapter {
63
+ get<T>(url: string, headers?: Record<string, string>): Promise<T>;
64
+ post<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
65
+ put<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
66
+ patch<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
67
+ delete<T>(url: string, headers?: Record<string, string>): Promise<T>;
68
+ deleteWithBody<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
69
+ }
70
+
71
+ declare type HttpService = ReturnType<typeof odeServices.http>;
72
+
73
+ declare type HttpService_2 = ReturnType<typeof odeServices.http>;
74
+
75
+ export declare class HttpServiceAdapter implements HttpAdapter {
76
+ private readonly httpService;
77
+ constructor(httpService: HttpService);
78
+ get<T>(url: string, headers?: Record<string, string>): Promise<T>;
79
+ post<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
80
+ put<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
81
+ patch<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
82
+ delete<T>(url: string, headers?: Record<string, string>): Promise<T>;
83
+ deleteWithBody<T>(url: string, body: unknown, headers?: Record<string, string>): Promise<T>;
84
+ }
85
+
86
+ export declare interface RequestOptions {
87
+ headers?: Record<string, string>;
88
+ }
89
+
90
+ export { Type }
91
+
92
+ export { }