@oapiex/sdk-kit 0.1.1

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,528 @@
1
+ import { _ as CountryCodeRestricted, a as InitOptions, c as Response, d as UnifiedResponse, f as UserConfig, g as CountryCode, h as XGenericObject, i as ErrorResponse, l as ResponseStatus, m as ValidationErrorResponse, n as AuthResponse, o as NormalPagination, p as ValidationError, r as CursorPagination, s as PageInfoMeta, t as AuthErrorResponse, u as SuccessResponse, v as CurrencyCode } from "./index-sMTTpEJS.js";
2
+ import "dotenv/config";
3
+ import * as axios0 from "axios";
4
+ import { RawAxiosRequestHeaders } from "axios";
5
+
6
+ //#region src/Exceptions/BadRequestException.d.ts
7
+ declare class BadRequestException extends Error {
8
+ statusCode: number;
9
+ type: string;
10
+ code: string | number;
11
+ data: ValidationErrorResponse;
12
+ constructor(data?: ValidationErrorResponse);
13
+ }
14
+ //#endregion
15
+ //#region src/types.d.ts
16
+ interface RuntimeSdkParameterManifest {
17
+ name: string;
18
+ accessor: string;
19
+ in: 'query' | 'header' | 'path';
20
+ required: boolean;
21
+ }
22
+ interface RuntimeSdkOperationManifest {
23
+ path: string;
24
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
25
+ methodName: string;
26
+ summary?: string;
27
+ operationId?: string;
28
+ responseType: string;
29
+ inputType: string;
30
+ queryType: string;
31
+ headerType: string;
32
+ paramsType: string;
33
+ hasBody: boolean;
34
+ bodyRequired: boolean;
35
+ pathParams: RuntimeSdkParameterManifest[];
36
+ queryParams: RuntimeSdkParameterManifest[];
37
+ headerParams: RuntimeSdkParameterManifest[];
38
+ }
39
+ interface RuntimeSdkGroupManifest {
40
+ className: string;
41
+ propertyName: string;
42
+ operations: RuntimeSdkOperationManifest[];
43
+ }
44
+ interface RuntimeSdkManifest {
45
+ groups: RuntimeSdkGroupManifest[];
46
+ }
47
+ interface RuntimeSdkBundle<TApi$1 = unknown> {
48
+ document: unknown;
49
+ manifest: RuntimeSdkManifest;
50
+ __api?: TApi$1;
51
+ }
52
+ type RuntimeSdkMethodMap<TOperations$1> = TOperations$1 extends readonly unknown[] ? UnionToIntersection<RuntimeSdkMethodNamespace<TOperations$1[number]>> : Record<string, never>;
53
+ type RuntimeSdkMethodNamespace<TOperation> = TOperation extends {
54
+ methodName: infer TMethodName extends string;
55
+ } ? { [TKey in TMethodName]: (...args: any[]) => Promise<unknown> } : Record<string, never>;
56
+ type RuntimeSdkGroupMap<TGroups$1> = TGroups$1 extends readonly unknown[] ? UnionToIntersection<RuntimeSdkGroupNamespace<TGroups$1[number]>> : Record<string, never>;
57
+ type RuntimeSdkGroupNamespace<TGroup> = TGroup extends {
58
+ propertyName: infer TPropertyName extends string;
59
+ operations: infer TOperations;
60
+ } ? { [TKey in TPropertyName]: RuntimeSdkMethodMap<TOperations> } : Record<string, never>;
61
+ type InferRuntimeSdkApiFromManifest<TBundle> = TBundle extends {
62
+ manifest: {
63
+ groups: infer TGroups;
64
+ };
65
+ } ? RuntimeSdkGroupMap<TGroups> : never;
66
+ type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
67
+ type InferRuntimeSdkApi<TBundle> = '__api' extends keyof TBundle ? TBundle extends {
68
+ __api?: infer TApi;
69
+ } ? TApi : InferRuntimeSdkApiFromManifest<TBundle> : InferRuntimeSdkApiFromManifest<TBundle>;
70
+ //#endregion
71
+ //#region src/Builder.d.ts
72
+ declare class Builder {
73
+ private static baseUrls;
74
+ /**
75
+ * Flutterwave Environment
76
+ */
77
+ static environment?: 'sandbox' | 'live';
78
+ constructor();
79
+ /**
80
+ * Sets the environment for the builder
81
+ *
82
+ * @param env
83
+ */
84
+ static setEnvironment(env: 'sandbox' | 'live'): void;
85
+ /**
86
+ * Gets the base url based on environment
87
+ *
88
+ * @returns
89
+ */
90
+ static baseUrl(): string;
91
+ /**
92
+ * Builds a full url based on endpoint provided
93
+ *
94
+ * @param endpoint
95
+ * @returns
96
+ */
97
+ static buildUrl(...endpoint: string[]): string;
98
+ /**
99
+ * Builds parameters for query or path
100
+ *
101
+ * @param params
102
+ * @param type
103
+ * @returns
104
+ */
105
+ static buildParams(params: XGenericObject, type?: 'query' | 'path'): string;
106
+ /**
107
+ * Assigns parameters to url {placeholders} based on type
108
+ *
109
+ * @param url
110
+ * @param params
111
+ * @param type
112
+ *
113
+ * @returns
114
+ */
115
+ static assignParamsToUrl(url: string, params: XGenericObject, type?: 'query' | 'path'): string;
116
+ /**
117
+ * Builds the target url by assigning both path and query parameters
118
+ *
119
+ * @param path
120
+ * @param params
121
+ * @param queryParams
122
+ * @returns
123
+ */
124
+ static buildTargetUrl(path: string, params?: XGenericObject, queryParams?: XGenericObject): string;
125
+ /**
126
+ * Encrypts specified keys in the input object and returns a new object with
127
+ * encrypted values.
128
+ *
129
+ * @param input The input object containing the data to be encrypted.
130
+ * @param keysToEncrypt The keys in the input object that should be encrypted.
131
+ * @param outputMapping A mapping of input keys to output keys for the encrypted values.
132
+ * @returns A new object with the specified keys encrypted.
133
+ */
134
+ static encryptDetails<X extends XGenericObject>(input: Partial<X>, keysToEncrypt?: (keyof X)[], outputMapping?: Partial<Record<keyof X, string>>): Promise<X>;
135
+ /**
136
+ * Encrypts data using AES-GCM encryption
137
+ * @param data
138
+ * @param token
139
+ * @param nonce
140
+ * @returns
141
+ */
142
+ static encryptAES(data: string, token: string, nonce: string): Promise<string>;
143
+ }
144
+ //#endregion
145
+ //#region src/Core.d.ts
146
+ declare class Core {
147
+ static apiClass: typeof BaseApi;
148
+ debugLevel: number;
149
+ /**
150
+ * Client ID
151
+ */
152
+ private clientId;
153
+ /**
154
+ * Client Secret
155
+ */
156
+ private clientSecret;
157
+ /**
158
+ * Flutterwave Environment
159
+ */
160
+ private environment;
161
+ private accessValidator?;
162
+ /**
163
+ * API Instance
164
+ */
165
+ api: BaseApi;
166
+ /**
167
+ * Builder Instance
168
+ */
169
+ builder: typeof Builder;
170
+ /**
171
+ * Creates an instance of Core.
172
+ *
173
+ * @param clientId
174
+ * @param clientSecret
175
+ * @param encryptionKey
176
+ */
177
+ constructor(clientId?: InitOptions);
178
+ constructor(clientId?: string, clientSecret?: string, encryptionKey?: string, env?: 'sandbox' | 'live');
179
+ protected createApi(): BaseApi;
180
+ /**
181
+ * Initializes the Core instance
182
+ *
183
+ * @param clientId
184
+ * @param clientSecret
185
+ * @param encryptionKey
186
+ * @param accessToken
187
+ * @returns
188
+ */
189
+ init(clientId?: InitOptions): this;
190
+ init(clientId?: string, clientSecret?: string, encryptionKey?: string, env?: 'sandbox' | 'live'): this;
191
+ /**
192
+ * Set the debug level
193
+ *
194
+ * @param level
195
+ * @returns
196
+ */
197
+ debug(level?: number): this;
198
+ /**
199
+ * Get the current environment
200
+ *
201
+ * @returns
202
+ */
203
+ getEnvironment(): "sandbox" | "live";
204
+ /**
205
+ * Set access validator function
206
+ *
207
+ * @param validator Function to validate access
208
+ */
209
+ setAccessValidator(validator: (...args: any[]) => Promise<boolean | string>): void;
210
+ /**
211
+ * Validates access using the provided access validator function
212
+ *
213
+ * @throws Error if validation fails
214
+ */
215
+ validateAccess(): Promise<void>;
216
+ /**
217
+ * Use a manifest bundle to create the API instance
218
+ *
219
+ * @param bundle
220
+ * @returns
221
+ */
222
+ useDocument<TBundle extends RuntimeSdkBundle>(bundle: TBundle): this & {
223
+ api: BaseApi & InferRuntimeSdkApi<TBundle>;
224
+ };
225
+ /**
226
+ * Use a manifest bundle to create the API instance (alias for useDocument).
227
+ *
228
+ * @param bundle
229
+ * @returns
230
+ */
231
+ useSdk<TBundle extends RuntimeSdkBundle>(bundle: TBundle): this & {
232
+ api: BaseApi & InferRuntimeSdkApi<TBundle>;
233
+ };
234
+ }
235
+ //#endregion
236
+ //#region src/Exceptions/ForbiddenRequestException.d.ts
237
+ declare class ForbiddenRequestException extends Error {
238
+ statusCode: number;
239
+ type: string;
240
+ code: string | number;
241
+ data: ErrorResponse;
242
+ constructor(data?: ErrorResponse);
243
+ }
244
+ //#endregion
245
+ //#region src/Exceptions/UnauthorizedRequestException.d.ts
246
+ declare class UnauthorizedRequestException extends Error {
247
+ statusCode: number;
248
+ type: string;
249
+ code: string | number;
250
+ data: ErrorResponse;
251
+ constructor(data?: ErrorResponse);
252
+ }
253
+ //#endregion
254
+ //#region src/Exceptions/HttpException.d.ts
255
+ declare class HttpException extends Error {
256
+ data: UnifiedResponse;
257
+ statusCode: number;
258
+ parent?: Error;
259
+ constructor(data: UnifiedResponse, statusCode?: number, parent?: Error);
260
+ /**
261
+ * Create an exception from status code
262
+ *
263
+ * @param code
264
+ * @param data
265
+ */
266
+ static fromCode(code: number, data: Required<UnifiedResponse>, parent?: Error): BadRequestException | UnauthorizedRequestException | HttpException | ForbiddenRequestException;
267
+ }
268
+ //#endregion
269
+ //#region src/Apis/BaseApi.d.ts
270
+ declare class BaseApi {
271
+ #private;
272
+ private lastException?;
273
+ /**
274
+ * Create a BaseApi instance
275
+ *
276
+ * @param coreInstance Core instance
277
+ */
278
+ constructor(coreInstance: Core);
279
+ /**
280
+ * Get the owning core instance for SDK-specific API bootstrapping.
281
+ */
282
+ protected get core(): Core;
283
+ /**
284
+ * Hook for SDK-specific API registration.
285
+ */
286
+ protected boot(): void;
287
+ /**
288
+ * Set access validator function
289
+ *
290
+ * @param validator
291
+ */
292
+ setAccessValidator(validator: (...args: any[]) => Promise<boolean | string>): void;
293
+ /**
294
+ * Get the last exception
295
+ *
296
+ * @returns
297
+ */
298
+ getLastException(): BadRequestException | ForbiddenRequestException | UnauthorizedRequestException | HttpException | undefined;
299
+ /**
300
+ * Set the last exception
301
+ *
302
+ * @param exception
303
+ */
304
+ setLastException(exception: BadRequestException | ForbiddenRequestException | UnauthorizedRequestException | HttpException): void;
305
+ /**
306
+ * Initialize BaseApi and its sub-APIs
307
+ *
308
+ * @param coreInstance Core instance
309
+ * @returns
310
+ */
311
+ static initialize<T extends BaseApi>(this: new (coreInstance: Core) => T, coreInstance: Core): T;
312
+ }
313
+ //#endregion
314
+ //#region src/global.d.ts
315
+ declare global {
316
+ interface String {
317
+ /**
318
+ * Convert a string to Kebab Case
319
+ *
320
+ * @returns
321
+ */
322
+ toKebabCase(): string;
323
+ /**
324
+ * Convert a string to camel Case
325
+ *
326
+ * @returns
327
+ */
328
+ toCamelCase(): string;
329
+ /**
330
+ * Convert a string to Pascal Case
331
+ *
332
+ * @returns
333
+ */
334
+ toPascalCase(): string;
335
+ /**
336
+ * Convert a string to Snake Case
337
+ *
338
+ * @returns
339
+ */
340
+ toSnakeCase(): string;
341
+ /**
342
+ * Convert a string to Title Case
343
+ *
344
+ * @returns
345
+ */
346
+ toTitleCase(): string;
347
+ /**
348
+ * Convert a string to Clean Case
349
+ * We will format a string by replacing underscores and hyphens with spaces,
350
+ * capitalizing the first letter of every word,
351
+ * converting camelCase to spaced words,
352
+ * and trimming any leading or trailing spaces.
353
+ * If a sentence is only two letters long we will make it uppercase.
354
+ *
355
+ * @returns
356
+ */
357
+ toCleanCase(): string;
358
+ /**
359
+ * Convert a string to Slug Case
360
+ *
361
+ * @returns
362
+ */
363
+ toSlug(separator?: string): string;
364
+ /**
365
+ * Truncate a string to n characters
366
+ *
367
+ * @param n
368
+ */
369
+ truncate(n: number): string;
370
+ }
371
+ }
372
+ //#endregion
373
+ //#region src/Http.d.ts
374
+ declare class Http {
375
+ private headers;
376
+ private body?;
377
+ /**
378
+ * Bearer token
379
+ */
380
+ private static bearerToken;
381
+ /**
382
+ * Debug level
383
+ */
384
+ private static debugLevel;
385
+ private static apiInstance;
386
+ /**
387
+ * Creates an instance of Http.
388
+ *
389
+ * @param method
390
+ * @param url
391
+ * @param headers
392
+ * @param body
393
+ */
394
+ constructor(headers?: RawAxiosRequestHeaders, body?: any | undefined);
395
+ /**
396
+ * Set the debug level
397
+ *
398
+ * @param debug
399
+ */
400
+ static setDebugLevel(level?: number): void;
401
+ /**
402
+ * Set the API instance
403
+ *
404
+ * @param api
405
+ */
406
+ static setApiInstance(api: BaseApi): void;
407
+ /**
408
+ * Set the bearer token
409
+ *
410
+ * @param token
411
+ */
412
+ static setBearerToken(token: string): void;
413
+ setDefaultHeaders(defaults: Record<string, string>): void;
414
+ getHeaders(): RawAxiosRequestHeaders;
415
+ getBody(): any;
416
+ axiosApi(): axios0.AxiosInstance;
417
+ /**
418
+ * Makes a GET request
419
+ *
420
+ * @param url
421
+ * @param headers
422
+ * @param params
423
+ * @returns
424
+ */
425
+ static get<R = any, M extends XGenericObject = XGenericObject>(url: string, params?: XGenericObject, headers?: RawAxiosRequestHeaders): Promise<UnifiedResponse<R, M>>;
426
+ /**
427
+ *
428
+ *
429
+ * @param url
430
+ * @param headers
431
+ * @param params
432
+ * @returns
433
+ */
434
+ static send<R = any, M extends XGenericObject = XGenericObject>(url: string, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', body?: any, headers?: RawAxiosRequestHeaders, params?: XGenericObject): Promise<UnifiedResponse<R, M>>;
435
+ /**
436
+ * Create an HttpException from status and error
437
+ *
438
+ * @param status
439
+ * @param error
440
+ * @returns
441
+ */
442
+ private static exception;
443
+ }
444
+ //#endregion
445
+ //#region src/RuntimeSdk.d.ts
446
+ declare const createRuntimeApi: <TBundle extends {
447
+ manifest: RuntimeSdkManifest;
448
+ }>(core: Core, bundle: TBundle) => BaseApi & InferRuntimeSdkApi<TBundle>;
449
+ declare const createSdk: <TBundle extends RuntimeSdkBundle>(bundle: TBundle, options: InitOptions) => Core & {
450
+ api: BaseApi & InferRuntimeSdkApi<TBundle>;
451
+ };
452
+ //#endregion
453
+ //#region src/utilities/helpers.d.ts
454
+ /**
455
+ * Takes a value like the one prodvided in a destructuring assignment where for instance
456
+ * a single value might have been provided as opposed to an array of values and
457
+ * normalizes it.
458
+ *
459
+ * Examples:
460
+ * Definition:
461
+ * (...value: string[]) => normalizeValue(value)
462
+ *
463
+ * Usage:
464
+ * normalizeValue('singleValue') // returns ['singleValue']
465
+ * normalizeValue('value1', 'value2') // returns ['value1', 'value2']
466
+ * normalizeValue(['value1', 'value2']) // returns ['value1', 'value2']
467
+ *
468
+ * @param value
469
+ * @returns
470
+ */
471
+ declare const normalizeValue: <T>(value: T | T[]) => T[];
472
+ /**
473
+ * Builds a full url based on endpoint provided
474
+ *
475
+ * @param baseUrl
476
+ * @param endpoint
477
+ *
478
+ * @returns
479
+ */
480
+ declare const buildUrl: (baseUrl: string, ...endpoint: string[]) => string;
481
+ //#endregion
482
+ //#region src/utilities/Manager.d.ts
483
+ declare const defaultConfig: UserConfig;
484
+ declare let globalConfig: UserConfig;
485
+ declare const defineConfig: (config: Partial<UserConfig>) => UserConfig;
486
+ //#endregion
487
+ //#region src/utilities/WebhookValidator.d.ts
488
+ declare class WebhookValidator<Options extends XGenericObject = XGenericObject> {
489
+ private secretHash?;
490
+ algorithm: 'sha256' | 'sha512' | 'sha1';
491
+ encoding: 'base64' | 'hex';
492
+ /**
493
+ * @param secretHash
494
+ * @param options
495
+ */
496
+ constructor(secretHash?: string | undefined, options?: Options);
497
+ /**
498
+ * Validate webhook signature
499
+ * @param rawBody - Raw request body as string
500
+ * @param signature - Signature from request header
501
+ * @returns {boolean} - True if signature is valid
502
+ */
503
+ validate(rawBody: string, signature: string): boolean;
504
+ /**
505
+ * Generate signature for testing/verification
506
+ * @param rawBody - Raw request body as string
507
+ * @returns {string} - Generated signature
508
+ */
509
+ generateSignature(rawBody: string): string;
510
+ /**
511
+ * Async version of validate (for large payloads)
512
+ *
513
+ * @param rawBody
514
+ * @param signature
515
+ * @returns {Promise<boolean>}
516
+ */
517
+ validateAsync(rawBody: string, signature: string): boolean;
518
+ /**
519
+ * Get current configuration
520
+ */
521
+ getConfig(): {
522
+ algorithm: "sha256" | "sha512" | "sha1";
523
+ encoding: "base64" | "hex";
524
+ secretHashLength: number | undefined;
525
+ };
526
+ }
527
+ //#endregion
528
+ export { AuthErrorResponse, AuthResponse, BadRequestException, BaseApi, Builder, Core, CountryCode, CountryCodeRestricted, CurrencyCode, CursorPagination, ErrorResponse, ForbiddenRequestException, Http, HttpException, InferRuntimeSdkApi, InitOptions, NormalPagination, PageInfoMeta, Response, ResponseStatus, RuntimeSdkBundle, RuntimeSdkGroupManifest, RuntimeSdkManifest, RuntimeSdkOperationManifest, RuntimeSdkParameterManifest, SuccessResponse, UnauthorizedRequestException, UnifiedResponse, UserConfig, ValidationError, ValidationErrorResponse, WebhookValidator, XGenericObject, buildUrl, createRuntimeApi, createSdk, defaultConfig, defineConfig, globalConfig, normalizeValue };