@oumla/sdk 0.0.4 → 0.0.5
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/dist/index.d.ts +5 -3
- package/dist/index.js +122 -67
- package/dist/index.mjs +122 -67
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ declare const GetInsightsSchema: z.ZodObject<{
|
|
|
157
157
|
}>;
|
|
158
158
|
declare const CreateTransactionSchema: z.ZodObject<{
|
|
159
159
|
to: z.ZodString;
|
|
160
|
-
amount: z.
|
|
160
|
+
amount: z.ZodString;
|
|
161
161
|
from: z.ZodArray<z.ZodString, "many">;
|
|
162
162
|
network: z.ZodEnum<["BTC", "ETH", "tBTC", "tETH"]>;
|
|
163
163
|
clientShare: z.ZodString;
|
|
@@ -165,13 +165,13 @@ declare const CreateTransactionSchema: z.ZodObject<{
|
|
|
165
165
|
network: "BTC" | "ETH" | "tBTC" | "tETH";
|
|
166
166
|
clientShare: string;
|
|
167
167
|
to: string;
|
|
168
|
-
amount:
|
|
168
|
+
amount: string;
|
|
169
169
|
from: string[];
|
|
170
170
|
}, {
|
|
171
171
|
network: "BTC" | "ETH" | "tBTC" | "tETH";
|
|
172
172
|
clientShare: string;
|
|
173
173
|
to: string;
|
|
174
|
-
amount:
|
|
174
|
+
amount: string;
|
|
175
175
|
from: string[];
|
|
176
176
|
}>;
|
|
177
177
|
declare const GetOrganizationSchema: z.ZodObject<{
|
|
@@ -429,6 +429,8 @@ declare abstract class Base {
|
|
|
429
429
|
constructor(configs: TBaseConfigs);
|
|
430
430
|
protected getCustomHeaders(): Record<string, string>;
|
|
431
431
|
protected httpRequest<T>(args: THttpRequestArgs): Promise<T>;
|
|
432
|
+
private handleHttpError;
|
|
433
|
+
private createStructuredError;
|
|
432
434
|
private parseInput;
|
|
433
435
|
}
|
|
434
436
|
|
package/dist/index.js
CHANGED
|
@@ -63,72 +63,6 @@ __export(src_exports, {
|
|
|
63
63
|
});
|
|
64
64
|
module.exports = __toCommonJS(src_exports);
|
|
65
65
|
|
|
66
|
-
// src/httpError.ts
|
|
67
|
-
var HttpError = class extends Error {
|
|
68
|
-
constructor(error) {
|
|
69
|
-
super(error.message || "An HTTP error occurred");
|
|
70
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
71
|
-
this.name = "HttpError";
|
|
72
|
-
this.status = error.status || 502;
|
|
73
|
-
this.success = error.success || false;
|
|
74
|
-
this.path = error.path || "/";
|
|
75
|
-
Error.captureStackTrace(this, this.constructor);
|
|
76
|
-
}
|
|
77
|
-
toString() {
|
|
78
|
-
return `${this.name}: ${this.message} - Status: ${this.status} - Success: ${this.success}`;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/base.ts
|
|
83
|
-
var Base = class {
|
|
84
|
-
constructor(configs) {
|
|
85
|
-
this.apiKey = configs.apiKey;
|
|
86
|
-
this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
|
|
87
|
-
this.env = configs.env || "testnet";
|
|
88
|
-
}
|
|
89
|
-
// Add this method to get custom headers
|
|
90
|
-
getCustomHeaders() {
|
|
91
|
-
return {};
|
|
92
|
-
}
|
|
93
|
-
httpRequest(args) {
|
|
94
|
-
return __async(this, null, function* () {
|
|
95
|
-
var _a;
|
|
96
|
-
if (args.body && args.schema) {
|
|
97
|
-
this.parseInput(args.body, args.schema);
|
|
98
|
-
}
|
|
99
|
-
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
100
|
-
const URL2 = `${this.baseUrl}${args.path}${paginationOpts}`;
|
|
101
|
-
const headers = __spreadValues(__spreadValues({
|
|
102
|
-
"x-api-key": `Bearer ${this.apiKey}`,
|
|
103
|
-
"Content-Type": "application/json"
|
|
104
|
-
}, this.getCustomHeaders()), args.headers);
|
|
105
|
-
const config = {
|
|
106
|
-
headers,
|
|
107
|
-
method: args.method || "GET",
|
|
108
|
-
body: args.body ? JSON.stringify(args.body) : void 0
|
|
109
|
-
};
|
|
110
|
-
const res = yield fetch(URL2, config);
|
|
111
|
-
if (!res.ok) {
|
|
112
|
-
if ((_a = res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
113
|
-
const errorResponse2 = yield res.json();
|
|
114
|
-
throw new HttpError(errorResponse2);
|
|
115
|
-
}
|
|
116
|
-
const errorResponse = {
|
|
117
|
-
message: yield res.text(),
|
|
118
|
-
status: res.status,
|
|
119
|
-
success: false,
|
|
120
|
-
path: args.path
|
|
121
|
-
};
|
|
122
|
-
throw new HttpError(errorResponse);
|
|
123
|
-
}
|
|
124
|
-
return yield res.json();
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
parseInput(input, schema) {
|
|
128
|
-
schema.parse(input);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
66
|
// node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
133
67
|
var util;
|
|
134
68
|
(function(util2) {
|
|
@@ -3767,6 +3701,127 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3767
3701
|
ZodError
|
|
3768
3702
|
});
|
|
3769
3703
|
|
|
3704
|
+
// src/httpError.ts
|
|
3705
|
+
var HttpError = class extends Error {
|
|
3706
|
+
constructor(error) {
|
|
3707
|
+
super(error.message || "An HTTP error occurred");
|
|
3708
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
3709
|
+
this.name = "HttpError";
|
|
3710
|
+
this.status = error.status || 502;
|
|
3711
|
+
this.success = error.success || false;
|
|
3712
|
+
this.path = error.path || "/";
|
|
3713
|
+
Error.captureStackTrace(this, this.constructor);
|
|
3714
|
+
}
|
|
3715
|
+
toString() {
|
|
3716
|
+
return `${this.name}: ${this.message} - Status: ${this.status} - Success: ${this.success}`;
|
|
3717
|
+
}
|
|
3718
|
+
};
|
|
3719
|
+
|
|
3720
|
+
// src/base.ts
|
|
3721
|
+
var Base = class {
|
|
3722
|
+
constructor(configs) {
|
|
3723
|
+
this.apiKey = configs.apiKey;
|
|
3724
|
+
this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
|
|
3725
|
+
this.env = configs.env || "testnet";
|
|
3726
|
+
}
|
|
3727
|
+
getCustomHeaders() {
|
|
3728
|
+
return {};
|
|
3729
|
+
}
|
|
3730
|
+
httpRequest(args) {
|
|
3731
|
+
return __async(this, null, function* () {
|
|
3732
|
+
try {
|
|
3733
|
+
if (args.body && args.schema) {
|
|
3734
|
+
this.parseInput(args.body, args.schema);
|
|
3735
|
+
}
|
|
3736
|
+
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
3737
|
+
const URL2 = `${this.baseUrl}${args.path}${paginationOpts}`;
|
|
3738
|
+
const headers = __spreadValues(__spreadValues({
|
|
3739
|
+
"x-api-key": `Bearer ${this.apiKey}`,
|
|
3740
|
+
"Content-Type": "application/json"
|
|
3741
|
+
}, this.getCustomHeaders()), args.headers);
|
|
3742
|
+
const config = {
|
|
3743
|
+
headers,
|
|
3744
|
+
method: args.method || "GET",
|
|
3745
|
+
body: args.body ? JSON.stringify(args.body) : void 0
|
|
3746
|
+
};
|
|
3747
|
+
const res = yield fetch(URL2, config);
|
|
3748
|
+
if (!res.ok) {
|
|
3749
|
+
const structuredError = yield this.handleHttpError(res, args.path);
|
|
3750
|
+
throw new HttpError(structuredError);
|
|
3751
|
+
}
|
|
3752
|
+
return yield res.json();
|
|
3753
|
+
} catch (error) {
|
|
3754
|
+
if (error instanceof HttpError) {
|
|
3755
|
+
throw error;
|
|
3756
|
+
} else if (error instanceof z.ZodError) {
|
|
3757
|
+
throw this.createStructuredError(
|
|
3758
|
+
"ValidationError",
|
|
3759
|
+
"Input validation failed",
|
|
3760
|
+
400,
|
|
3761
|
+
args.path,
|
|
3762
|
+
error.errors
|
|
3763
|
+
);
|
|
3764
|
+
} else {
|
|
3765
|
+
throw this.createStructuredError(
|
|
3766
|
+
"UnknownError",
|
|
3767
|
+
"An unexpected error occurred",
|
|
3768
|
+
500,
|
|
3769
|
+
args.path,
|
|
3770
|
+
error
|
|
3771
|
+
);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
handleHttpError(res, path) {
|
|
3777
|
+
return __async(this, null, function* () {
|
|
3778
|
+
var _a;
|
|
3779
|
+
const status = res.status;
|
|
3780
|
+
let errorType;
|
|
3781
|
+
let message;
|
|
3782
|
+
let details;
|
|
3783
|
+
if ((_a = res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
3784
|
+
const errorResponse = yield res.json();
|
|
3785
|
+
message = errorResponse.message;
|
|
3786
|
+
details = errorResponse;
|
|
3787
|
+
} else {
|
|
3788
|
+
message = yield res.text();
|
|
3789
|
+
}
|
|
3790
|
+
switch (status) {
|
|
3791
|
+
case 400:
|
|
3792
|
+
case 402:
|
|
3793
|
+
errorType = "ValidationError";
|
|
3794
|
+
break;
|
|
3795
|
+
case 401:
|
|
3796
|
+
case 403:
|
|
3797
|
+
errorType = "AuthenticationError";
|
|
3798
|
+
break;
|
|
3799
|
+
case 404:
|
|
3800
|
+
errorType = "NotFoundError";
|
|
3801
|
+
break;
|
|
3802
|
+
case 500:
|
|
3803
|
+
errorType = "ServerError";
|
|
3804
|
+
break;
|
|
3805
|
+
default:
|
|
3806
|
+
errorType = "UnknownError";
|
|
3807
|
+
}
|
|
3808
|
+
return this.createStructuredError(
|
|
3809
|
+
errorType,
|
|
3810
|
+
message,
|
|
3811
|
+
status,
|
|
3812
|
+
path,
|
|
3813
|
+
details
|
|
3814
|
+
);
|
|
3815
|
+
});
|
|
3816
|
+
}
|
|
3817
|
+
createStructuredError(type, message, status, path, details) {
|
|
3818
|
+
return { type, message, status, path, details };
|
|
3819
|
+
}
|
|
3820
|
+
parseInput(input, schema) {
|
|
3821
|
+
schema.parse(input);
|
|
3822
|
+
}
|
|
3823
|
+
};
|
|
3824
|
+
|
|
3770
3825
|
// src/schemas.ts
|
|
3771
3826
|
var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
|
|
3772
3827
|
var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
|
|
@@ -3833,7 +3888,7 @@ var GetInsightsSchema = z.object({
|
|
|
3833
3888
|
});
|
|
3834
3889
|
var CreateTransactionSchema = z.object({
|
|
3835
3890
|
to: z.string(),
|
|
3836
|
-
amount: z.
|
|
3891
|
+
amount: z.string(),
|
|
3837
3892
|
from: z.array(z.string()),
|
|
3838
3893
|
network: NetworkSchema,
|
|
3839
3894
|
clientShare: z.string()
|
package/dist/index.mjs
CHANGED
|
@@ -38,72 +38,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
// src/httpError.ts
|
|
42
|
-
var HttpError = class extends Error {
|
|
43
|
-
constructor(error) {
|
|
44
|
-
super(error.message || "An HTTP error occurred");
|
|
45
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
46
|
-
this.name = "HttpError";
|
|
47
|
-
this.status = error.status || 502;
|
|
48
|
-
this.success = error.success || false;
|
|
49
|
-
this.path = error.path || "/";
|
|
50
|
-
Error.captureStackTrace(this, this.constructor);
|
|
51
|
-
}
|
|
52
|
-
toString() {
|
|
53
|
-
return `${this.name}: ${this.message} - Status: ${this.status} - Success: ${this.success}`;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/base.ts
|
|
58
|
-
var Base = class {
|
|
59
|
-
constructor(configs) {
|
|
60
|
-
this.apiKey = configs.apiKey;
|
|
61
|
-
this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
|
|
62
|
-
this.env = configs.env || "testnet";
|
|
63
|
-
}
|
|
64
|
-
// Add this method to get custom headers
|
|
65
|
-
getCustomHeaders() {
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
httpRequest(args) {
|
|
69
|
-
return __async(this, null, function* () {
|
|
70
|
-
var _a;
|
|
71
|
-
if (args.body && args.schema) {
|
|
72
|
-
this.parseInput(args.body, args.schema);
|
|
73
|
-
}
|
|
74
|
-
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
75
|
-
const URL2 = `${this.baseUrl}${args.path}${paginationOpts}`;
|
|
76
|
-
const headers = __spreadValues(__spreadValues({
|
|
77
|
-
"x-api-key": `Bearer ${this.apiKey}`,
|
|
78
|
-
"Content-Type": "application/json"
|
|
79
|
-
}, this.getCustomHeaders()), args.headers);
|
|
80
|
-
const config = {
|
|
81
|
-
headers,
|
|
82
|
-
method: args.method || "GET",
|
|
83
|
-
body: args.body ? JSON.stringify(args.body) : void 0
|
|
84
|
-
};
|
|
85
|
-
const res = yield fetch(URL2, config);
|
|
86
|
-
if (!res.ok) {
|
|
87
|
-
if ((_a = res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
88
|
-
const errorResponse2 = yield res.json();
|
|
89
|
-
throw new HttpError(errorResponse2);
|
|
90
|
-
}
|
|
91
|
-
const errorResponse = {
|
|
92
|
-
message: yield res.text(),
|
|
93
|
-
status: res.status,
|
|
94
|
-
success: false,
|
|
95
|
-
path: args.path
|
|
96
|
-
};
|
|
97
|
-
throw new HttpError(errorResponse);
|
|
98
|
-
}
|
|
99
|
-
return yield res.json();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
parseInput(input, schema) {
|
|
103
|
-
schema.parse(input);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
41
|
// node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
108
42
|
var util;
|
|
109
43
|
(function(util2) {
|
|
@@ -3742,6 +3676,127 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3742
3676
|
ZodError
|
|
3743
3677
|
});
|
|
3744
3678
|
|
|
3679
|
+
// src/httpError.ts
|
|
3680
|
+
var HttpError = class extends Error {
|
|
3681
|
+
constructor(error) {
|
|
3682
|
+
super(error.message || "An HTTP error occurred");
|
|
3683
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
3684
|
+
this.name = "HttpError";
|
|
3685
|
+
this.status = error.status || 502;
|
|
3686
|
+
this.success = error.success || false;
|
|
3687
|
+
this.path = error.path || "/";
|
|
3688
|
+
Error.captureStackTrace(this, this.constructor);
|
|
3689
|
+
}
|
|
3690
|
+
toString() {
|
|
3691
|
+
return `${this.name}: ${this.message} - Status: ${this.status} - Success: ${this.success}`;
|
|
3692
|
+
}
|
|
3693
|
+
};
|
|
3694
|
+
|
|
3695
|
+
// src/base.ts
|
|
3696
|
+
var Base = class {
|
|
3697
|
+
constructor(configs) {
|
|
3698
|
+
this.apiKey = configs.apiKey;
|
|
3699
|
+
this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
|
|
3700
|
+
this.env = configs.env || "testnet";
|
|
3701
|
+
}
|
|
3702
|
+
getCustomHeaders() {
|
|
3703
|
+
return {};
|
|
3704
|
+
}
|
|
3705
|
+
httpRequest(args) {
|
|
3706
|
+
return __async(this, null, function* () {
|
|
3707
|
+
try {
|
|
3708
|
+
if (args.body && args.schema) {
|
|
3709
|
+
this.parseInput(args.body, args.schema);
|
|
3710
|
+
}
|
|
3711
|
+
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
3712
|
+
const URL2 = `${this.baseUrl}${args.path}${paginationOpts}`;
|
|
3713
|
+
const headers = __spreadValues(__spreadValues({
|
|
3714
|
+
"x-api-key": `Bearer ${this.apiKey}`,
|
|
3715
|
+
"Content-Type": "application/json"
|
|
3716
|
+
}, this.getCustomHeaders()), args.headers);
|
|
3717
|
+
const config = {
|
|
3718
|
+
headers,
|
|
3719
|
+
method: args.method || "GET",
|
|
3720
|
+
body: args.body ? JSON.stringify(args.body) : void 0
|
|
3721
|
+
};
|
|
3722
|
+
const res = yield fetch(URL2, config);
|
|
3723
|
+
if (!res.ok) {
|
|
3724
|
+
const structuredError = yield this.handleHttpError(res, args.path);
|
|
3725
|
+
throw new HttpError(structuredError);
|
|
3726
|
+
}
|
|
3727
|
+
return yield res.json();
|
|
3728
|
+
} catch (error) {
|
|
3729
|
+
if (error instanceof HttpError) {
|
|
3730
|
+
throw error;
|
|
3731
|
+
} else if (error instanceof z.ZodError) {
|
|
3732
|
+
throw this.createStructuredError(
|
|
3733
|
+
"ValidationError",
|
|
3734
|
+
"Input validation failed",
|
|
3735
|
+
400,
|
|
3736
|
+
args.path,
|
|
3737
|
+
error.errors
|
|
3738
|
+
);
|
|
3739
|
+
} else {
|
|
3740
|
+
throw this.createStructuredError(
|
|
3741
|
+
"UnknownError",
|
|
3742
|
+
"An unexpected error occurred",
|
|
3743
|
+
500,
|
|
3744
|
+
args.path,
|
|
3745
|
+
error
|
|
3746
|
+
);
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
});
|
|
3750
|
+
}
|
|
3751
|
+
handleHttpError(res, path) {
|
|
3752
|
+
return __async(this, null, function* () {
|
|
3753
|
+
var _a;
|
|
3754
|
+
const status = res.status;
|
|
3755
|
+
let errorType;
|
|
3756
|
+
let message;
|
|
3757
|
+
let details;
|
|
3758
|
+
if ((_a = res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
3759
|
+
const errorResponse = yield res.json();
|
|
3760
|
+
message = errorResponse.message;
|
|
3761
|
+
details = errorResponse;
|
|
3762
|
+
} else {
|
|
3763
|
+
message = yield res.text();
|
|
3764
|
+
}
|
|
3765
|
+
switch (status) {
|
|
3766
|
+
case 400:
|
|
3767
|
+
case 402:
|
|
3768
|
+
errorType = "ValidationError";
|
|
3769
|
+
break;
|
|
3770
|
+
case 401:
|
|
3771
|
+
case 403:
|
|
3772
|
+
errorType = "AuthenticationError";
|
|
3773
|
+
break;
|
|
3774
|
+
case 404:
|
|
3775
|
+
errorType = "NotFoundError";
|
|
3776
|
+
break;
|
|
3777
|
+
case 500:
|
|
3778
|
+
errorType = "ServerError";
|
|
3779
|
+
break;
|
|
3780
|
+
default:
|
|
3781
|
+
errorType = "UnknownError";
|
|
3782
|
+
}
|
|
3783
|
+
return this.createStructuredError(
|
|
3784
|
+
errorType,
|
|
3785
|
+
message,
|
|
3786
|
+
status,
|
|
3787
|
+
path,
|
|
3788
|
+
details
|
|
3789
|
+
);
|
|
3790
|
+
});
|
|
3791
|
+
}
|
|
3792
|
+
createStructuredError(type, message, status, path, details) {
|
|
3793
|
+
return { type, message, status, path, details };
|
|
3794
|
+
}
|
|
3795
|
+
parseInput(input, schema) {
|
|
3796
|
+
schema.parse(input);
|
|
3797
|
+
}
|
|
3798
|
+
};
|
|
3799
|
+
|
|
3745
3800
|
// src/schemas.ts
|
|
3746
3801
|
var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
|
|
3747
3802
|
var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
|
|
@@ -3808,7 +3863,7 @@ var GetInsightsSchema = z.object({
|
|
|
3808
3863
|
});
|
|
3809
3864
|
var CreateTransactionSchema = z.object({
|
|
3810
3865
|
to: z.string(),
|
|
3811
|
-
amount: z.
|
|
3866
|
+
amount: z.string(),
|
|
3812
3867
|
from: z.array(z.string()),
|
|
3813
3868
|
network: NetworkSchema,
|
|
3814
3869
|
clientShare: z.string()
|