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