@oumla/sdk 0.0.3 → 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/README.md +2 -2
- package/dist/index.d.ts +100 -317
- package/dist/index.js +256 -381
- package/dist/index.mjs +256 -381
- package/package.json +1 -3
package/dist/index.mjs
CHANGED
|
@@ -38,74 +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
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* A generic method to make requests to the Oumla API.
|
|
67
|
-
* Keep it simple for now, could be enhanced later.
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
httpRequest(args) {
|
|
71
|
-
return __async(this, null, function* () {
|
|
72
|
-
var _a;
|
|
73
|
-
if (args.body && args.schema) {
|
|
74
|
-
this.parseInput(args.body, args.schema);
|
|
75
|
-
}
|
|
76
|
-
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
77
|
-
const URL2 = `${this.baseUrl}${args.path}${paginationOpts}`;
|
|
78
|
-
const config = {
|
|
79
|
-
headers: {
|
|
80
|
-
"x-api-key": `Bearer ${this.apiKey}`,
|
|
81
|
-
"Content-Type": "application/json"
|
|
82
|
-
},
|
|
83
|
-
method: args.method || void 0,
|
|
84
|
-
// GET is the default in fetch
|
|
85
|
-
body: args.body ? JSON.stringify(args.body) : void 0
|
|
86
|
-
};
|
|
87
|
-
const res = yield fetch(URL2, config);
|
|
88
|
-
if (!res.ok) {
|
|
89
|
-
if ((_a = res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
90
|
-
const errorResponse2 = yield res.json();
|
|
91
|
-
throw new HttpError(errorResponse2);
|
|
92
|
-
}
|
|
93
|
-
const errorResponse = {
|
|
94
|
-
message: yield res.text(),
|
|
95
|
-
status: res.status,
|
|
96
|
-
success: false,
|
|
97
|
-
path: args.path
|
|
98
|
-
};
|
|
99
|
-
throw new HttpError(errorResponse);
|
|
100
|
-
}
|
|
101
|
-
return yield res.json();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
parseInput(input, schema) {
|
|
105
|
-
schema.parse(input);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
41
|
// node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
110
42
|
var util;
|
|
111
43
|
(function(util2) {
|
|
@@ -3744,8 +3676,129 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3744
3676
|
ZodError
|
|
3745
3677
|
});
|
|
3746
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
|
+
|
|
3747
3800
|
// src/schemas.ts
|
|
3748
|
-
var NetworkSchema = z.enum(["BTC", "ETH"]);
|
|
3801
|
+
var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
|
|
3749
3802
|
var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
|
|
3750
3803
|
var GetWalletsSchema = z.object({
|
|
3751
3804
|
reference: z.string()
|
|
@@ -3779,7 +3832,8 @@ var GetTransactionsSchema = z.object({
|
|
|
3779
3832
|
}).partial();
|
|
3780
3833
|
var GenerateAddressSchema = z.object({
|
|
3781
3834
|
network: NetworkSchema,
|
|
3782
|
-
reference: z.string()
|
|
3835
|
+
reference: z.string(),
|
|
3836
|
+
clientShare: z.string()
|
|
3783
3837
|
});
|
|
3784
3838
|
var GetAddressesSchema = z.object({
|
|
3785
3839
|
baseUrl: z.string(),
|
|
@@ -3809,9 +3863,10 @@ var GetInsightsSchema = z.object({
|
|
|
3809
3863
|
});
|
|
3810
3864
|
var CreateTransactionSchema = z.object({
|
|
3811
3865
|
to: z.string(),
|
|
3812
|
-
amount: z.
|
|
3866
|
+
amount: z.string(),
|
|
3813
3867
|
from: z.array(z.string()),
|
|
3814
|
-
network: NetworkSchema
|
|
3868
|
+
network: NetworkSchema,
|
|
3869
|
+
clientShare: z.string()
|
|
3815
3870
|
});
|
|
3816
3871
|
var GetOrganizationSchema = z.object({
|
|
3817
3872
|
baseUrl: z.string(),
|
|
@@ -3823,335 +3878,155 @@ var GetOrganizationDashboardSchema = z.object({
|
|
|
3823
3878
|
});
|
|
3824
3879
|
|
|
3825
3880
|
// src/client.ts
|
|
3826
|
-
var
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
*
|
|
3834
|
-
* @param {string} args.reference - The reference of the profile
|
|
3835
|
-
* @param {string} args.network - The network to generate a wallet for
|
|
3836
|
-
*
|
|
3837
|
-
* @example
|
|
3838
|
-
* ``` ts
|
|
3839
|
-
*
|
|
3840
|
-
* const wallet = await client.generateWallet({
|
|
3841
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3842
|
-
* network: 'BTC',
|
|
3843
|
-
* });
|
|
3844
|
-
*
|
|
3845
|
-
* ```
|
|
3846
|
-
*
|
|
3847
|
-
* @returns {Types.TGenerateWalletResponse} - The generated wallet or an error
|
|
3848
|
-
*
|
|
3849
|
-
*/
|
|
3850
|
-
generateWallet(args) {
|
|
3851
|
-
return __async(this, null, function* () {
|
|
3852
|
-
return yield this.httpRequest({
|
|
3853
|
-
method: "POST",
|
|
3854
|
-
path: "/api/v1/wallets/generate",
|
|
3855
|
-
body: args,
|
|
3856
|
-
schema: GenerateWalletSchema
|
|
3857
|
-
});
|
|
3881
|
+
var _Oumla = class extends Base {
|
|
3882
|
+
// 1 hour
|
|
3883
|
+
constructor(opts) {
|
|
3884
|
+
super({
|
|
3885
|
+
apiKey: opts.apiKey,
|
|
3886
|
+
baseUrl: opts.baseUrl,
|
|
3887
|
+
env: opts.env
|
|
3858
3888
|
});
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
*
|
|
3877
|
-
* @returns {Types.TGetWalletsResponse} - The wallets for the organization
|
|
3878
|
-
*
|
|
3879
|
-
*/
|
|
3880
|
-
getWallets(args, pagination) {
|
|
3881
|
-
return __async(this, null, function* () {
|
|
3882
|
-
if (args == null ? void 0 : args.reference) {
|
|
3883
|
-
return yield this.httpRequest({
|
|
3884
|
-
path: `/api/v1/wallets/profile/${args.reference}`,
|
|
3889
|
+
// Update this with each release
|
|
3890
|
+
this.lastUpdateCheck = 0;
|
|
3891
|
+
this.UPDATE_CHECK_INTERVAL = 60 * 60 * 1e3;
|
|
3892
|
+
this.wallets = {
|
|
3893
|
+
generate: (args) => __async(this, null, function* () {
|
|
3894
|
+
return this.httpRequest({
|
|
3895
|
+
path: "/api/v1/wallets/generate",
|
|
3896
|
+
method: "POST",
|
|
3897
|
+
body: args,
|
|
3898
|
+
schema: GenerateWalletSchema
|
|
3899
|
+
});
|
|
3900
|
+
}),
|
|
3901
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3902
|
+
const path = (args == null ? void 0 : args.reference) ? `/api/v1/wallets/profile/${args.reference}` : "/api/v1/wallets/organization";
|
|
3903
|
+
return this.httpRequest({
|
|
3904
|
+
path,
|
|
3905
|
+
method: "GET",
|
|
3885
3906
|
pagination
|
|
3886
3907
|
});
|
|
3887
|
-
}
|
|
3888
|
-
|
|
3889
|
-
|
|
3908
|
+
})
|
|
3909
|
+
};
|
|
3910
|
+
this.addresses = {
|
|
3911
|
+
generate: (args) => __async(this, null, function* () {
|
|
3912
|
+
return this.httpRequest({
|
|
3913
|
+
path: "/api/v1/address/generate",
|
|
3914
|
+
method: "POST",
|
|
3915
|
+
body: args,
|
|
3916
|
+
schema: GenerateAddressSchema
|
|
3917
|
+
});
|
|
3918
|
+
}),
|
|
3919
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3920
|
+
const path = (args == null ? void 0 : args.reference) ? `/api/v1/addresses/${args.reference}` : "/api/v1/addresses/organization";
|
|
3921
|
+
return this.httpRequest({
|
|
3922
|
+
path,
|
|
3923
|
+
method: "GET",
|
|
3890
3924
|
pagination
|
|
3891
3925
|
});
|
|
3892
|
-
}
|
|
3893
|
-
}
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
* network: 'BTC',
|
|
3908
|
-
* });
|
|
3909
|
-
*
|
|
3910
|
-
* ```
|
|
3911
|
-
*
|
|
3912
|
-
* @returns {Types.TGenerateAddressResponse} - The generated address
|
|
3913
|
-
*/
|
|
3914
|
-
generateAddress(args) {
|
|
3915
|
-
return __async(this, null, function* () {
|
|
3916
|
-
return yield this.httpRequest({
|
|
3917
|
-
method: "POST",
|
|
3918
|
-
path: "/api/v1/address/generate",
|
|
3919
|
-
body: args,
|
|
3920
|
-
schema: GenerateAddressSchema
|
|
3921
|
-
});
|
|
3922
|
-
});
|
|
3923
|
-
}
|
|
3924
|
-
/**
|
|
3925
|
-
*
|
|
3926
|
-
* Get addresses
|
|
3927
|
-
*
|
|
3928
|
-
* @param {string} args.reference - The reference of the profile, Optional
|
|
3929
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
3930
|
-
* @example
|
|
3931
|
-
* ``` ts
|
|
3932
|
-
*
|
|
3933
|
-
* const addresses = await client.getAddresses({
|
|
3934
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3935
|
-
* },
|
|
3936
|
-
* {
|
|
3937
|
-
* skip: 0,
|
|
3938
|
-
* take: 3,
|
|
3939
|
-
* }
|
|
3940
|
-
* );
|
|
3941
|
-
*
|
|
3942
|
-
* ```
|
|
3943
|
-
*
|
|
3944
|
-
* @returns {Types.TGetProfileAddressesResponse} - The addresses for the profile
|
|
3945
|
-
*/
|
|
3946
|
-
getAddresses(args, pagination) {
|
|
3947
|
-
return __async(this, null, function* () {
|
|
3948
|
-
if (args == null ? void 0 : args.reference) {
|
|
3949
|
-
return yield this.httpRequest({
|
|
3950
|
-
path: `/api/v1/addresses/${args.reference}`,
|
|
3926
|
+
})
|
|
3927
|
+
};
|
|
3928
|
+
this.profiles = {
|
|
3929
|
+
create: (args) => __async(this, null, function* () {
|
|
3930
|
+
return this.httpRequest({
|
|
3931
|
+
path: "/api/v1/profiles",
|
|
3932
|
+
method: "POST",
|
|
3933
|
+
body: args,
|
|
3934
|
+
schema: CreateProfileSchema
|
|
3935
|
+
});
|
|
3936
|
+
}),
|
|
3937
|
+
get: (pagination) => __async(this, null, function* () {
|
|
3938
|
+
return this.httpRequest({
|
|
3939
|
+
path: "/api/v1/profiles",
|
|
3940
|
+
method: "GET",
|
|
3951
3941
|
pagination
|
|
3952
3942
|
});
|
|
3953
|
-
}
|
|
3954
|
-
|
|
3955
|
-
|
|
3943
|
+
})
|
|
3944
|
+
};
|
|
3945
|
+
this.organization = {
|
|
3946
|
+
get: () => __async(this, null, function* () {
|
|
3947
|
+
return this.httpRequest({
|
|
3948
|
+
path: "/api/v1/organizations",
|
|
3949
|
+
method: "GET"
|
|
3950
|
+
});
|
|
3951
|
+
}),
|
|
3952
|
+
volume: () => __async(this, null, function* () {
|
|
3953
|
+
return this.httpRequest({
|
|
3954
|
+
path: "/api/v1/statistics/organization/volume",
|
|
3955
|
+
method: "GET"
|
|
3956
|
+
});
|
|
3957
|
+
}),
|
|
3958
|
+
insights: () => __async(this, null, function* () {
|
|
3959
|
+
return this.httpRequest({
|
|
3960
|
+
path: "/api/v1/statistics/organization/insights",
|
|
3961
|
+
method: "GET"
|
|
3962
|
+
});
|
|
3963
|
+
})
|
|
3964
|
+
};
|
|
3965
|
+
this.transactions = {
|
|
3966
|
+
create: (args) => __async(this, null, function* () {
|
|
3967
|
+
return this.httpRequest({
|
|
3968
|
+
path: "/api/v1/withdraw/address",
|
|
3969
|
+
method: "POST",
|
|
3970
|
+
body: args,
|
|
3971
|
+
schema: CreateTransactionSchema
|
|
3972
|
+
});
|
|
3973
|
+
}),
|
|
3974
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3975
|
+
let path = "/api/v1/transactions/organization";
|
|
3976
|
+
if (args == null ? void 0 : args.address) {
|
|
3977
|
+
path = `/api/v1/transactions/address/${args.address}`;
|
|
3978
|
+
} else if (args == null ? void 0 : args.wallet) {
|
|
3979
|
+
path = `/api/v1/transactions/wallet/${args.wallet}`;
|
|
3980
|
+
} else if (args == null ? void 0 : args.reference) {
|
|
3981
|
+
path = `/api/v1/transactions/profile/${args.reference}`;
|
|
3982
|
+
}
|
|
3983
|
+
return this.httpRequest({
|
|
3984
|
+
path,
|
|
3985
|
+
method: "GET",
|
|
3956
3986
|
pagination
|
|
3957
3987
|
});
|
|
3958
|
-
}
|
|
3959
|
-
}
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
*
|
|
3965
|
-
* @example
|
|
3966
|
-
* ``` ts
|
|
3967
|
-
*
|
|
3968
|
-
* const organization = await client.getOrganization();
|
|
3969
|
-
*
|
|
3970
|
-
* ```
|
|
3971
|
-
*
|
|
3972
|
-
* @returns {Types.TGetOrganizationResponse} - The organization's information
|
|
3973
|
-
*/
|
|
3974
|
-
getOrganization() {
|
|
3975
|
-
return __async(this, null, function* () {
|
|
3976
|
-
return yield this.httpRequest({
|
|
3977
|
-
path: "/api/v1/organizations"
|
|
3978
|
-
});
|
|
3979
|
-
});
|
|
3980
|
-
}
|
|
3981
|
-
/**
|
|
3982
|
-
*
|
|
3983
|
-
* Create a profile
|
|
3984
|
-
*
|
|
3985
|
-
* @param {string} args.reference - The reference of the profile
|
|
3986
|
-
* @param {Types.TCreateProfileArgs['type']} args.type - The type of the profile
|
|
3987
|
-
*
|
|
3988
|
-
* @example
|
|
3989
|
-
* ``` ts
|
|
3990
|
-
*
|
|
3991
|
-
* const profile = await client.createProfile({
|
|
3992
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3993
|
-
* type: 'User',
|
|
3994
|
-
* });
|
|
3995
|
-
*
|
|
3996
|
-
* ```
|
|
3997
|
-
*
|
|
3998
|
-
* @returns {Types.TCreateProfileResponse} - The created profile
|
|
3999
|
-
*/
|
|
4000
|
-
createProfile(args) {
|
|
4001
|
-
return __async(this, null, function* () {
|
|
4002
|
-
return yield this.httpRequest({
|
|
4003
|
-
method: "POST",
|
|
4004
|
-
path: "/api/v1/profiles",
|
|
4005
|
-
body: args,
|
|
4006
|
-
schema: CreateProfileSchema
|
|
4007
|
-
});
|
|
4008
|
-
});
|
|
4009
|
-
}
|
|
4010
|
-
/**
|
|
4011
|
-
*
|
|
4012
|
-
* Get the profiles for an organization
|
|
4013
|
-
*
|
|
4014
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
4015
|
-
*
|
|
4016
|
-
* @example
|
|
4017
|
-
* ``` ts
|
|
4018
|
-
*
|
|
4019
|
-
* const profiles = await client.getProfiles({
|
|
4020
|
-
* skip: 0,
|
|
4021
|
-
* take: 3,
|
|
4022
|
-
* });
|
|
4023
|
-
*
|
|
4024
|
-
* ```
|
|
4025
|
-
*
|
|
4026
|
-
* @returns {Types.TGetProfilesResponse} - The profiles for the organization
|
|
4027
|
-
*/
|
|
4028
|
-
getProfiles(pagination) {
|
|
4029
|
-
return __async(this, null, function* () {
|
|
4030
|
-
return yield this.httpRequest({
|
|
4031
|
-
path: "/api/v1/profiles",
|
|
4032
|
-
pagination
|
|
4033
|
-
});
|
|
4034
|
-
});
|
|
3988
|
+
})
|
|
3989
|
+
};
|
|
3990
|
+
this.apiKey = opts.apiKey;
|
|
3991
|
+
this.baseUrl = opts.baseUrl || "https://api.oumla.com";
|
|
3992
|
+
this.env = opts.env || "testnet";
|
|
3993
|
+
this.initialize();
|
|
4035
3994
|
}
|
|
4036
|
-
|
|
4037
|
-
*
|
|
4038
|
-
* Get the volume for an organization
|
|
4039
|
-
*
|
|
4040
|
-
* @example
|
|
4041
|
-
* ``` ts
|
|
4042
|
-
*
|
|
4043
|
-
* const volume = await client.getVolume();
|
|
4044
|
-
*
|
|
4045
|
-
* ```
|
|
4046
|
-
*
|
|
4047
|
-
* @returns {Types.TGetVolumeResponse} - The volume of the organization
|
|
4048
|
-
*/
|
|
4049
|
-
getVolume() {
|
|
3995
|
+
initialize() {
|
|
4050
3996
|
return __async(this, null, function* () {
|
|
4051
|
-
|
|
4052
|
-
path: "/api/v1/statistics/organization/volume"
|
|
4053
|
-
});
|
|
3997
|
+
yield this.checkForUpdates();
|
|
4054
3998
|
});
|
|
4055
3999
|
}
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
* @example
|
|
4061
|
-
* ``` ts
|
|
4062
|
-
*
|
|
4063
|
-
* const insights = await client.getInsights();
|
|
4064
|
-
*
|
|
4065
|
-
* ```
|
|
4066
|
-
*
|
|
4067
|
-
* @returns {Types.TGetInsightsResponse} - The insights of the organization
|
|
4068
|
-
*/
|
|
4069
|
-
getInsights() {
|
|
4070
|
-
return __async(this, null, function* () {
|
|
4071
|
-
return yield this.httpRequest({
|
|
4072
|
-
path: "/api/v1/statistics/organization/insights"
|
|
4073
|
-
});
|
|
4074
|
-
});
|
|
4000
|
+
getCustomHeaders() {
|
|
4001
|
+
return {
|
|
4002
|
+
"x-sdk-version": _Oumla.CURRENT_VERSION
|
|
4003
|
+
};
|
|
4075
4004
|
}
|
|
4076
|
-
|
|
4077
|
-
*
|
|
4078
|
-
* Get the all the transactions or transactions for an address, wallet or reference
|
|
4079
|
-
*
|
|
4080
|
-
* By providing more than one option, only one will be used.
|
|
4081
|
-
*
|
|
4082
|
-
* @param {string} [args.address] - The address to get transactions for
|
|
4083
|
-
* @param {string} [args.wallet] - The wallet to get transactions for
|
|
4084
|
-
* @param {string} [args.reference] - The reference to get transactions for
|
|
4085
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
4086
|
-
*
|
|
4087
|
-
* @example
|
|
4088
|
-
* ``` ts
|
|
4089
|
-
*
|
|
4090
|
-
* const transactionsByAddress = await client.getTransactions({
|
|
4091
|
-
* address: 'ADDRESS',
|
|
4092
|
-
* });
|
|
4093
|
-
*
|
|
4094
|
-
* ```
|
|
4095
|
-
*
|
|
4096
|
-
* @returns {Types.TGetTransactionsResponse} - The transactions
|
|
4097
|
-
*
|
|
4098
|
-
*/
|
|
4099
|
-
getTransactions(args, pagination) {
|
|
4005
|
+
checkForUpdates() {
|
|
4100
4006
|
return __async(this, null, function* () {
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
pagination
|
|
4110
|
-
});
|
|
4111
|
-
} else if (args == null ? void 0 : args.reference) {
|
|
4112
|
-
return yield this.httpRequest({
|
|
4113
|
-
path: `/api/v1/transactions/profile/${args.reference}`,
|
|
4114
|
-
pagination
|
|
4115
|
-
});
|
|
4116
|
-
} else {
|
|
4117
|
-
return yield this.httpRequest({
|
|
4118
|
-
path: "/api/v1/transactions/organization",
|
|
4119
|
-
pagination
|
|
4007
|
+
const now = Date.now();
|
|
4008
|
+
if (now - this.lastUpdateCheck < this.UPDATE_CHECK_INTERVAL) {
|
|
4009
|
+
return;
|
|
4010
|
+
}
|
|
4011
|
+
try {
|
|
4012
|
+
const response = yield this.httpRequest({
|
|
4013
|
+
path: "/api/v1/sdk-version",
|
|
4014
|
+
method: "GET"
|
|
4120
4015
|
});
|
|
4016
|
+
if (response.latestVersion !== _Oumla.CURRENT_VERSION) {
|
|
4017
|
+
console.log(
|
|
4018
|
+
`A new version (${response.latestVersion}) of the Oumla SDK is available. Please update.`
|
|
4019
|
+
);
|
|
4020
|
+
}
|
|
4021
|
+
this.lastUpdateCheck = now;
|
|
4022
|
+
} catch (error) {
|
|
4023
|
+
console.error("Failed to check for updates:", error);
|
|
4121
4024
|
}
|
|
4122
4025
|
});
|
|
4123
4026
|
}
|
|
4124
|
-
/**
|
|
4125
|
-
* create transaction
|
|
4126
|
-
*
|
|
4127
|
-
* @param args.from - the address or addresses to transfer from
|
|
4128
|
-
* @param args.to - The desired address to transfer to
|
|
4129
|
-
* @param args.amount - The amount to transfer
|
|
4130
|
-
*
|
|
4131
|
-
* @example
|
|
4132
|
-
*
|
|
4133
|
-
* ``` ts
|
|
4134
|
-
*
|
|
4135
|
-
* const transfer = await client.transfer({
|
|
4136
|
-
* from: '0x...',
|
|
4137
|
-
* to: '0x...',
|
|
4138
|
-
* reference: '0x...',
|
|
4139
|
-
* amount: 100,
|
|
4140
|
-
* });
|
|
4141
|
-
*
|
|
4142
|
-
* ```
|
|
4143
|
-
*/
|
|
4144
|
-
createTransaction(args) {
|
|
4145
|
-
return __async(this, null, function* () {
|
|
4146
|
-
return yield this.httpRequest({
|
|
4147
|
-
method: "POST",
|
|
4148
|
-
path: "/api/v1/withdraw/address",
|
|
4149
|
-
body: args,
|
|
4150
|
-
schema: CreateTransactionSchema
|
|
4151
|
-
});
|
|
4152
|
-
});
|
|
4153
|
-
}
|
|
4154
4027
|
};
|
|
4028
|
+
var Oumla = _Oumla;
|
|
4029
|
+
Oumla.CURRENT_VERSION = "1.0.0";
|
|
4155
4030
|
|
|
4156
4031
|
// src/types.ts
|
|
4157
4032
|
var ProfileType = /* @__PURE__ */ ((ProfileType2) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oumla/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Oumla SDK is the fastest way to integrate with blockchain networks",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@changesets/cli": "^2.27.1",
|
|
11
11
|
"@types/node": "^18.14.0",
|
|
12
|
-
"@types/superagent": "^4.1.18",
|
|
13
|
-
"superagent": "^8.1.2",
|
|
14
12
|
"tsup": "^6.7.0",
|
|
15
13
|
"typescript": "5.0.4",
|
|
16
14
|
"vitest": "^1.1.3",
|