@oumla/sdk 0.0.2 → 0.0.4
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 +95 -314
- package/dist/index.js +250 -378
- package/dist/index.mjs +250 -378
- package/package.json +4 -6
package/dist/index.mjs
CHANGED
|
@@ -61,12 +61,10 @@ var Base = class {
|
|
|
61
61
|
this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
|
|
62
62
|
this.env = configs.env || "testnet";
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
64
|
+
// Add this method to get custom headers
|
|
65
|
+
getCustomHeaders() {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
70
68
|
httpRequest(args) {
|
|
71
69
|
return __async(this, null, function* () {
|
|
72
70
|
var _a;
|
|
@@ -75,13 +73,13 @@ var Base = class {
|
|
|
75
73
|
}
|
|
76
74
|
const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
|
|
77
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);
|
|
78
80
|
const config = {
|
|
79
|
-
headers
|
|
80
|
-
|
|
81
|
-
"Content-Type": "application/json"
|
|
82
|
-
},
|
|
83
|
-
method: args.method || void 0,
|
|
84
|
-
// GET is the default in fetch
|
|
81
|
+
headers,
|
|
82
|
+
method: args.method || "GET",
|
|
85
83
|
body: args.body ? JSON.stringify(args.body) : void 0
|
|
86
84
|
};
|
|
87
85
|
const res = yield fetch(URL2, config);
|
|
@@ -106,7 +104,7 @@ var Base = class {
|
|
|
106
104
|
}
|
|
107
105
|
};
|
|
108
106
|
|
|
109
|
-
// node_modules/.pnpm/zod@3.
|
|
107
|
+
// node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
|
|
110
108
|
var util;
|
|
111
109
|
(function(util2) {
|
|
112
110
|
util2.assertEqual = (val) => val;
|
|
@@ -528,7 +526,7 @@ var ParseStatus = class {
|
|
|
528
526
|
status.dirty();
|
|
529
527
|
if (value.status === "dirty")
|
|
530
528
|
status.dirty();
|
|
531
|
-
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
|
529
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
532
530
|
finalObject[key.value] = value.value;
|
|
533
531
|
}
|
|
534
532
|
}
|
|
@@ -631,6 +629,7 @@ var ZodType = class {
|
|
|
631
629
|
this.catch = this.catch.bind(this);
|
|
632
630
|
this.describe = this.describe.bind(this);
|
|
633
631
|
this.pipe = this.pipe.bind(this);
|
|
632
|
+
this.readonly = this.readonly.bind(this);
|
|
634
633
|
this.isNullable = this.isNullable.bind(this);
|
|
635
634
|
this.isOptional = this.isOptional.bind(this);
|
|
636
635
|
}
|
|
@@ -836,6 +835,9 @@ var ZodType = class {
|
|
|
836
835
|
pipe(target) {
|
|
837
836
|
return ZodPipeline.create(this, target);
|
|
838
837
|
}
|
|
838
|
+
readonly() {
|
|
839
|
+
return ZodReadonly.create(this);
|
|
840
|
+
}
|
|
839
841
|
isOptional() {
|
|
840
842
|
return this.safeParse(void 0).success;
|
|
841
843
|
}
|
|
@@ -845,10 +847,11 @@ var ZodType = class {
|
|
|
845
847
|
};
|
|
846
848
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
847
849
|
var cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
848
|
-
var ulidRegex =
|
|
849
|
-
var uuidRegex = /^
|
|
850
|
-
var emailRegex = /^(
|
|
851
|
-
var
|
|
850
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
851
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
852
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
853
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
854
|
+
var emojiRegex;
|
|
852
855
|
var ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
|
853
856
|
var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
|
854
857
|
var datetimeRegex = (args) => {
|
|
@@ -882,23 +885,6 @@ function isValidIP(ip, version) {
|
|
|
882
885
|
return false;
|
|
883
886
|
}
|
|
884
887
|
var ZodString = class extends ZodType {
|
|
885
|
-
constructor() {
|
|
886
|
-
super(...arguments);
|
|
887
|
-
this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), __spreadValues({
|
|
888
|
-
validation,
|
|
889
|
-
code: ZodIssueCode.invalid_string
|
|
890
|
-
}, errorUtil.errToObj(message)));
|
|
891
|
-
this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
|
|
892
|
-
this.trim = () => new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
893
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
894
|
-
}));
|
|
895
|
-
this.toLowerCase = () => new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
896
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
897
|
-
}));
|
|
898
|
-
this.toUpperCase = () => new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
899
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
900
|
-
}));
|
|
901
|
-
}
|
|
902
888
|
_parse(input) {
|
|
903
889
|
if (this._def.coerce) {
|
|
904
890
|
input.data = String(input.data);
|
|
@@ -983,6 +969,9 @@ var ZodString = class extends ZodType {
|
|
|
983
969
|
status.dirty();
|
|
984
970
|
}
|
|
985
971
|
} else if (check.kind === "emoji") {
|
|
972
|
+
if (!emojiRegex) {
|
|
973
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
974
|
+
}
|
|
986
975
|
if (!emojiRegex.test(input.data)) {
|
|
987
976
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
988
977
|
addIssueToContext(ctx, {
|
|
@@ -1119,6 +1108,12 @@ var ZodString = class extends ZodType {
|
|
|
1119
1108
|
}
|
|
1120
1109
|
return { status: status.value, value: input.data };
|
|
1121
1110
|
}
|
|
1111
|
+
_regex(regex, validation, message) {
|
|
1112
|
+
return this.refinement((data) => regex.test(data), __spreadValues({
|
|
1113
|
+
validation,
|
|
1114
|
+
code: ZodIssueCode.invalid_string
|
|
1115
|
+
}, errorUtil.errToObj(message)));
|
|
1116
|
+
}
|
|
1122
1117
|
_addCheck(check) {
|
|
1123
1118
|
return new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
1124
1119
|
checks: [...this._def.checks, check]
|
|
@@ -1207,6 +1202,28 @@ var ZodString = class extends ZodType {
|
|
|
1207
1202
|
value: len
|
|
1208
1203
|
}, errorUtil.errToObj(message)));
|
|
1209
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* @deprecated Use z.string().min(1) instead.
|
|
1207
|
+
* @see {@link ZodString.min}
|
|
1208
|
+
*/
|
|
1209
|
+
nonempty(message) {
|
|
1210
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1211
|
+
}
|
|
1212
|
+
trim() {
|
|
1213
|
+
return new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
1214
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1215
|
+
}));
|
|
1216
|
+
}
|
|
1217
|
+
toLowerCase() {
|
|
1218
|
+
return new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
1219
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1220
|
+
}));
|
|
1221
|
+
}
|
|
1222
|
+
toUpperCase() {
|
|
1223
|
+
return new ZodString(__spreadProps(__spreadValues({}, this._def), {
|
|
1224
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1225
|
+
}));
|
|
1226
|
+
}
|
|
1210
1227
|
get isDatetime() {
|
|
1211
1228
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1212
1229
|
}
|
|
@@ -2745,6 +2762,12 @@ var ZodRecord = class extends ZodType {
|
|
|
2745
2762
|
}
|
|
2746
2763
|
};
|
|
2747
2764
|
var ZodMap = class extends ZodType {
|
|
2765
|
+
get keySchema() {
|
|
2766
|
+
return this._def.keyType;
|
|
2767
|
+
}
|
|
2768
|
+
get valueSchema() {
|
|
2769
|
+
return this._def.valueType;
|
|
2770
|
+
}
|
|
2748
2771
|
_parse(input) {
|
|
2749
2772
|
const { status, ctx } = this._processInputParams(input);
|
|
2750
2773
|
if (ctx.parsedType !== ZodParsedType.map) {
|
|
@@ -2935,27 +2958,31 @@ var ZodFunction = class extends ZodType {
|
|
|
2935
2958
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
2936
2959
|
const fn = ctx.data;
|
|
2937
2960
|
if (this._def.returns instanceof ZodPromise) {
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
error
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2961
|
+
const me = this;
|
|
2962
|
+
return OK(function(...args) {
|
|
2963
|
+
return __async(this, null, function* () {
|
|
2964
|
+
const error = new ZodError([]);
|
|
2965
|
+
const parsedArgs = yield me._def.args.parseAsync(args, params).catch((e) => {
|
|
2966
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
2967
|
+
throw error;
|
|
2968
|
+
});
|
|
2969
|
+
const result = yield Reflect.apply(fn, this, parsedArgs);
|
|
2970
|
+
const parsedReturns = yield me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
2971
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
2972
|
+
throw error;
|
|
2973
|
+
});
|
|
2974
|
+
return parsedReturns;
|
|
2948
2975
|
});
|
|
2949
|
-
|
|
2950
|
-
}));
|
|
2976
|
+
});
|
|
2951
2977
|
} else {
|
|
2952
|
-
|
|
2953
|
-
|
|
2978
|
+
const me = this;
|
|
2979
|
+
return OK(function(...args) {
|
|
2980
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
2954
2981
|
if (!parsedArgs.success) {
|
|
2955
2982
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2956
2983
|
}
|
|
2957
|
-
const result = fn
|
|
2958
|
-
const parsedReturns =
|
|
2984
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
2985
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
2959
2986
|
if (!parsedReturns.success) {
|
|
2960
2987
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2961
2988
|
}
|
|
@@ -3169,8 +3196,28 @@ var ZodEffects = class extends ZodType {
|
|
|
3169
3196
|
_parse(input) {
|
|
3170
3197
|
const { status, ctx } = this._processInputParams(input);
|
|
3171
3198
|
const effect = this._def.effect || null;
|
|
3199
|
+
const checkCtx = {
|
|
3200
|
+
addIssue: (arg) => {
|
|
3201
|
+
addIssueToContext(ctx, arg);
|
|
3202
|
+
if (arg.fatal) {
|
|
3203
|
+
status.abort();
|
|
3204
|
+
} else {
|
|
3205
|
+
status.dirty();
|
|
3206
|
+
}
|
|
3207
|
+
},
|
|
3208
|
+
get path() {
|
|
3209
|
+
return ctx.path;
|
|
3210
|
+
}
|
|
3211
|
+
};
|
|
3212
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3172
3213
|
if (effect.type === "preprocess") {
|
|
3173
|
-
const processed = effect.transform(ctx.data);
|
|
3214
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3215
|
+
if (ctx.common.issues.length) {
|
|
3216
|
+
return {
|
|
3217
|
+
status: "dirty",
|
|
3218
|
+
value: ctx.data
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3174
3221
|
if (ctx.common.async) {
|
|
3175
3222
|
return Promise.resolve(processed).then((processed2) => {
|
|
3176
3223
|
return this._def.schema._parseAsync({
|
|
@@ -3187,20 +3234,6 @@ var ZodEffects = class extends ZodType {
|
|
|
3187
3234
|
});
|
|
3188
3235
|
}
|
|
3189
3236
|
}
|
|
3190
|
-
const checkCtx = {
|
|
3191
|
-
addIssue: (arg) => {
|
|
3192
|
-
addIssueToContext(ctx, arg);
|
|
3193
|
-
if (arg.fatal) {
|
|
3194
|
-
status.abort();
|
|
3195
|
-
} else {
|
|
3196
|
-
status.dirty();
|
|
3197
|
-
}
|
|
3198
|
-
},
|
|
3199
|
-
get path() {
|
|
3200
|
-
return ctx.path;
|
|
3201
|
-
}
|
|
3202
|
-
};
|
|
3203
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3204
3237
|
if (effect.type === "refinement") {
|
|
3205
3238
|
const executeRefinement = (acc) => {
|
|
3206
3239
|
const result = effect.refinement(acc, checkCtx);
|
|
@@ -3473,6 +3506,21 @@ var ZodPipeline = class extends ZodType {
|
|
|
3473
3506
|
});
|
|
3474
3507
|
}
|
|
3475
3508
|
};
|
|
3509
|
+
var ZodReadonly = class extends ZodType {
|
|
3510
|
+
_parse(input) {
|
|
3511
|
+
const result = this._def.innerType._parse(input);
|
|
3512
|
+
if (isValid(result)) {
|
|
3513
|
+
result.value = Object.freeze(result.value);
|
|
3514
|
+
}
|
|
3515
|
+
return result;
|
|
3516
|
+
}
|
|
3517
|
+
};
|
|
3518
|
+
ZodReadonly.create = (type, params) => {
|
|
3519
|
+
return new ZodReadonly(__spreadValues({
|
|
3520
|
+
innerType: type,
|
|
3521
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly
|
|
3522
|
+
}, processCreateParams(params)));
|
|
3523
|
+
};
|
|
3476
3524
|
var custom = (check, params = {}, fatal) => {
|
|
3477
3525
|
if (check)
|
|
3478
3526
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
@@ -3526,6 +3574,7 @@ var ZodFirstPartyTypeKind;
|
|
|
3526
3574
|
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
3527
3575
|
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
3528
3576
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
3577
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
3529
3578
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3530
3579
|
var instanceOfType = (cls, params = {
|
|
3531
3580
|
message: `Input not instance of ${cls.name}`
|
|
@@ -3639,6 +3688,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3639
3688
|
BRAND,
|
|
3640
3689
|
ZodBranded,
|
|
3641
3690
|
ZodPipeline,
|
|
3691
|
+
ZodReadonly,
|
|
3642
3692
|
custom,
|
|
3643
3693
|
Schema: ZodType,
|
|
3644
3694
|
ZodSchema: ZodType,
|
|
@@ -3693,7 +3743,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3693
3743
|
});
|
|
3694
3744
|
|
|
3695
3745
|
// src/schemas.ts
|
|
3696
|
-
var NetworkSchema = z.enum(["BTC", "ETH"]);
|
|
3746
|
+
var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
|
|
3697
3747
|
var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
|
|
3698
3748
|
var GetWalletsSchema = z.object({
|
|
3699
3749
|
reference: z.string()
|
|
@@ -3727,7 +3777,8 @@ var GetTransactionsSchema = z.object({
|
|
|
3727
3777
|
}).partial();
|
|
3728
3778
|
var GenerateAddressSchema = z.object({
|
|
3729
3779
|
network: NetworkSchema,
|
|
3730
|
-
reference: z.string()
|
|
3780
|
+
reference: z.string(),
|
|
3781
|
+
clientShare: z.string()
|
|
3731
3782
|
});
|
|
3732
3783
|
var GetAddressesSchema = z.object({
|
|
3733
3784
|
baseUrl: z.string(),
|
|
@@ -3759,7 +3810,8 @@ var CreateTransactionSchema = z.object({
|
|
|
3759
3810
|
to: z.string(),
|
|
3760
3811
|
amount: z.number(),
|
|
3761
3812
|
from: z.array(z.string()),
|
|
3762
|
-
network: NetworkSchema
|
|
3813
|
+
network: NetworkSchema,
|
|
3814
|
+
clientShare: z.string()
|
|
3763
3815
|
});
|
|
3764
3816
|
var GetOrganizationSchema = z.object({
|
|
3765
3817
|
baseUrl: z.string(),
|
|
@@ -3771,335 +3823,155 @@ var GetOrganizationDashboardSchema = z.object({
|
|
|
3771
3823
|
});
|
|
3772
3824
|
|
|
3773
3825
|
// src/client.ts
|
|
3774
|
-
var
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
*
|
|
3782
|
-
* @param {string} args.reference - The reference of the profile
|
|
3783
|
-
* @param {string} args.network - The network to generate a wallet for
|
|
3784
|
-
*
|
|
3785
|
-
* @example
|
|
3786
|
-
* ``` ts
|
|
3787
|
-
*
|
|
3788
|
-
* const wallet = await client.generateWallet({
|
|
3789
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3790
|
-
* network: 'BTC',
|
|
3791
|
-
* });
|
|
3792
|
-
*
|
|
3793
|
-
* ```
|
|
3794
|
-
*
|
|
3795
|
-
* @returns {Types.TGenerateWalletResponse} - The generated wallet or an error
|
|
3796
|
-
*
|
|
3797
|
-
*/
|
|
3798
|
-
generateWallet(args) {
|
|
3799
|
-
return __async(this, null, function* () {
|
|
3800
|
-
return yield this.httpRequest({
|
|
3801
|
-
method: "POST",
|
|
3802
|
-
path: "/api/v1/wallets/generate",
|
|
3803
|
-
body: args,
|
|
3804
|
-
schema: GenerateWalletSchema
|
|
3805
|
-
});
|
|
3826
|
+
var _Oumla = class extends Base {
|
|
3827
|
+
// 1 hour
|
|
3828
|
+
constructor(opts) {
|
|
3829
|
+
super({
|
|
3830
|
+
apiKey: opts.apiKey,
|
|
3831
|
+
baseUrl: opts.baseUrl,
|
|
3832
|
+
env: opts.env
|
|
3806
3833
|
});
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
*
|
|
3825
|
-
* @returns {Types.TGetWalletsResponse} - The wallets for the organization
|
|
3826
|
-
*
|
|
3827
|
-
*/
|
|
3828
|
-
getWallets(args, pagination) {
|
|
3829
|
-
return __async(this, null, function* () {
|
|
3830
|
-
if (args == null ? void 0 : args.reference) {
|
|
3831
|
-
return yield this.httpRequest({
|
|
3832
|
-
path: `/api/v1/wallets/profile/${args.reference}`,
|
|
3834
|
+
// Update this with each release
|
|
3835
|
+
this.lastUpdateCheck = 0;
|
|
3836
|
+
this.UPDATE_CHECK_INTERVAL = 60 * 60 * 1e3;
|
|
3837
|
+
this.wallets = {
|
|
3838
|
+
generate: (args) => __async(this, null, function* () {
|
|
3839
|
+
return this.httpRequest({
|
|
3840
|
+
path: "/api/v1/wallets/generate",
|
|
3841
|
+
method: "POST",
|
|
3842
|
+
body: args,
|
|
3843
|
+
schema: GenerateWalletSchema
|
|
3844
|
+
});
|
|
3845
|
+
}),
|
|
3846
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3847
|
+
const path = (args == null ? void 0 : args.reference) ? `/api/v1/wallets/profile/${args.reference}` : "/api/v1/wallets/organization";
|
|
3848
|
+
return this.httpRequest({
|
|
3849
|
+
path,
|
|
3850
|
+
method: "GET",
|
|
3833
3851
|
pagination
|
|
3834
3852
|
});
|
|
3835
|
-
}
|
|
3836
|
-
|
|
3837
|
-
|
|
3853
|
+
})
|
|
3854
|
+
};
|
|
3855
|
+
this.addresses = {
|
|
3856
|
+
generate: (args) => __async(this, null, function* () {
|
|
3857
|
+
return this.httpRequest({
|
|
3858
|
+
path: "/api/v1/address/generate",
|
|
3859
|
+
method: "POST",
|
|
3860
|
+
body: args,
|
|
3861
|
+
schema: GenerateAddressSchema
|
|
3862
|
+
});
|
|
3863
|
+
}),
|
|
3864
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3865
|
+
const path = (args == null ? void 0 : args.reference) ? `/api/v1/addresses/${args.reference}` : "/api/v1/addresses/organization";
|
|
3866
|
+
return this.httpRequest({
|
|
3867
|
+
path,
|
|
3868
|
+
method: "GET",
|
|
3838
3869
|
pagination
|
|
3839
3870
|
});
|
|
3840
|
-
}
|
|
3841
|
-
}
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
* network: 'BTC',
|
|
3856
|
-
* });
|
|
3857
|
-
*
|
|
3858
|
-
* ```
|
|
3859
|
-
*
|
|
3860
|
-
* @returns {Types.TGenerateAddressResponse} - The generated address
|
|
3861
|
-
*/
|
|
3862
|
-
generateAddress(args) {
|
|
3863
|
-
return __async(this, null, function* () {
|
|
3864
|
-
return yield this.httpRequest({
|
|
3865
|
-
method: "POST",
|
|
3866
|
-
path: "/api/v1/address/generate",
|
|
3867
|
-
body: args,
|
|
3868
|
-
schema: GenerateAddressSchema
|
|
3869
|
-
});
|
|
3870
|
-
});
|
|
3871
|
-
}
|
|
3872
|
-
/**
|
|
3873
|
-
*
|
|
3874
|
-
* Get addresses
|
|
3875
|
-
*
|
|
3876
|
-
* @param {string} args.reference - The reference of the profile, Optional
|
|
3877
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
3878
|
-
* @example
|
|
3879
|
-
* ``` ts
|
|
3880
|
-
*
|
|
3881
|
-
* const addresses = await client.getAddresses({
|
|
3882
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3883
|
-
* },
|
|
3884
|
-
* {
|
|
3885
|
-
* skip: 0,
|
|
3886
|
-
* take: 3,
|
|
3887
|
-
* }
|
|
3888
|
-
* );
|
|
3889
|
-
*
|
|
3890
|
-
* ```
|
|
3891
|
-
*
|
|
3892
|
-
* @returns {Types.TGetProfileAddressesResponse} - The addresses for the profile
|
|
3893
|
-
*/
|
|
3894
|
-
getAddresses(args, pagination) {
|
|
3895
|
-
return __async(this, null, function* () {
|
|
3896
|
-
if (args == null ? void 0 : args.reference) {
|
|
3897
|
-
return yield this.httpRequest({
|
|
3898
|
-
path: `/api/v1/addresses/${args.reference}`,
|
|
3871
|
+
})
|
|
3872
|
+
};
|
|
3873
|
+
this.profiles = {
|
|
3874
|
+
create: (args) => __async(this, null, function* () {
|
|
3875
|
+
return this.httpRequest({
|
|
3876
|
+
path: "/api/v1/profiles",
|
|
3877
|
+
method: "POST",
|
|
3878
|
+
body: args,
|
|
3879
|
+
schema: CreateProfileSchema
|
|
3880
|
+
});
|
|
3881
|
+
}),
|
|
3882
|
+
get: (pagination) => __async(this, null, function* () {
|
|
3883
|
+
return this.httpRequest({
|
|
3884
|
+
path: "/api/v1/profiles",
|
|
3885
|
+
method: "GET",
|
|
3899
3886
|
pagination
|
|
3900
3887
|
});
|
|
3901
|
-
}
|
|
3902
|
-
|
|
3903
|
-
|
|
3888
|
+
})
|
|
3889
|
+
};
|
|
3890
|
+
this.organization = {
|
|
3891
|
+
get: () => __async(this, null, function* () {
|
|
3892
|
+
return this.httpRequest({
|
|
3893
|
+
path: "/api/v1/organizations",
|
|
3894
|
+
method: "GET"
|
|
3895
|
+
});
|
|
3896
|
+
}),
|
|
3897
|
+
volume: () => __async(this, null, function* () {
|
|
3898
|
+
return this.httpRequest({
|
|
3899
|
+
path: "/api/v1/statistics/organization/volume",
|
|
3900
|
+
method: "GET"
|
|
3901
|
+
});
|
|
3902
|
+
}),
|
|
3903
|
+
insights: () => __async(this, null, function* () {
|
|
3904
|
+
return this.httpRequest({
|
|
3905
|
+
path: "/api/v1/statistics/organization/insights",
|
|
3906
|
+
method: "GET"
|
|
3907
|
+
});
|
|
3908
|
+
})
|
|
3909
|
+
};
|
|
3910
|
+
this.transactions = {
|
|
3911
|
+
create: (args) => __async(this, null, function* () {
|
|
3912
|
+
return this.httpRequest({
|
|
3913
|
+
path: "/api/v1/withdraw/address",
|
|
3914
|
+
method: "POST",
|
|
3915
|
+
body: args,
|
|
3916
|
+
schema: CreateTransactionSchema
|
|
3917
|
+
});
|
|
3918
|
+
}),
|
|
3919
|
+
get: (args, pagination) => __async(this, null, function* () {
|
|
3920
|
+
let path = "/api/v1/transactions/organization";
|
|
3921
|
+
if (args == null ? void 0 : args.address) {
|
|
3922
|
+
path = `/api/v1/transactions/address/${args.address}`;
|
|
3923
|
+
} else if (args == null ? void 0 : args.wallet) {
|
|
3924
|
+
path = `/api/v1/transactions/wallet/${args.wallet}`;
|
|
3925
|
+
} else if (args == null ? void 0 : args.reference) {
|
|
3926
|
+
path = `/api/v1/transactions/profile/${args.reference}`;
|
|
3927
|
+
}
|
|
3928
|
+
return this.httpRequest({
|
|
3929
|
+
path,
|
|
3930
|
+
method: "GET",
|
|
3904
3931
|
pagination
|
|
3905
3932
|
});
|
|
3906
|
-
}
|
|
3907
|
-
}
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
*
|
|
3913
|
-
* @example
|
|
3914
|
-
* ``` ts
|
|
3915
|
-
*
|
|
3916
|
-
* const organization = await client.getOrganization();
|
|
3917
|
-
*
|
|
3918
|
-
* ```
|
|
3919
|
-
*
|
|
3920
|
-
* @returns {Types.TGetOrganizationResponse} - The organization's information
|
|
3921
|
-
*/
|
|
3922
|
-
getOrganization() {
|
|
3923
|
-
return __async(this, null, function* () {
|
|
3924
|
-
return yield this.httpRequest({
|
|
3925
|
-
path: "/api/v1/organizations"
|
|
3926
|
-
});
|
|
3927
|
-
});
|
|
3928
|
-
}
|
|
3929
|
-
/**
|
|
3930
|
-
*
|
|
3931
|
-
* Create a profile
|
|
3932
|
-
*
|
|
3933
|
-
* @param {string} args.reference - The reference of the profile
|
|
3934
|
-
* @param {Types.TCreateProfileArgs['type']} args.type - The type of the profile
|
|
3935
|
-
*
|
|
3936
|
-
* @example
|
|
3937
|
-
* ``` ts
|
|
3938
|
-
*
|
|
3939
|
-
* const profile = await client.createProfile({
|
|
3940
|
-
* reference: 'PROFILE_REFERENCE',
|
|
3941
|
-
* type: 'User',
|
|
3942
|
-
* });
|
|
3943
|
-
*
|
|
3944
|
-
* ```
|
|
3945
|
-
*
|
|
3946
|
-
* @returns {Types.TCreateProfileResponse} - The created profile
|
|
3947
|
-
*/
|
|
3948
|
-
createProfile(args) {
|
|
3949
|
-
return __async(this, null, function* () {
|
|
3950
|
-
return yield this.httpRequest({
|
|
3951
|
-
method: "POST",
|
|
3952
|
-
path: "/api/v1/profiles",
|
|
3953
|
-
body: args,
|
|
3954
|
-
schema: CreateProfileSchema
|
|
3955
|
-
});
|
|
3956
|
-
});
|
|
3957
|
-
}
|
|
3958
|
-
/**
|
|
3959
|
-
*
|
|
3960
|
-
* Get the profiles for an organization
|
|
3961
|
-
*
|
|
3962
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
3963
|
-
*
|
|
3964
|
-
* @example
|
|
3965
|
-
* ``` ts
|
|
3966
|
-
*
|
|
3967
|
-
* const profiles = await client.getProfiles({
|
|
3968
|
-
* skip: 0,
|
|
3969
|
-
* take: 3,
|
|
3970
|
-
* });
|
|
3971
|
-
*
|
|
3972
|
-
* ```
|
|
3973
|
-
*
|
|
3974
|
-
* @returns {Types.TGetProfilesResponse} - The profiles for the organization
|
|
3975
|
-
*/
|
|
3976
|
-
getProfiles(pagination) {
|
|
3977
|
-
return __async(this, null, function* () {
|
|
3978
|
-
return yield this.httpRequest({
|
|
3979
|
-
path: "/api/v1/profiles",
|
|
3980
|
-
pagination
|
|
3981
|
-
});
|
|
3982
|
-
});
|
|
3933
|
+
})
|
|
3934
|
+
};
|
|
3935
|
+
this.apiKey = opts.apiKey;
|
|
3936
|
+
this.baseUrl = opts.baseUrl || "https://api.oumla.com";
|
|
3937
|
+
this.env = opts.env || "testnet";
|
|
3938
|
+
this.initialize();
|
|
3983
3939
|
}
|
|
3984
|
-
|
|
3985
|
-
*
|
|
3986
|
-
* Get the volume for an organization
|
|
3987
|
-
*
|
|
3988
|
-
* @example
|
|
3989
|
-
* ``` ts
|
|
3990
|
-
*
|
|
3991
|
-
* const volume = await client.getVolume();
|
|
3992
|
-
*
|
|
3993
|
-
* ```
|
|
3994
|
-
*
|
|
3995
|
-
* @returns {Types.TGetVolumeResponse} - The volume of the organization
|
|
3996
|
-
*/
|
|
3997
|
-
getVolume() {
|
|
3940
|
+
initialize() {
|
|
3998
3941
|
return __async(this, null, function* () {
|
|
3999
|
-
|
|
4000
|
-
path: "/api/v1/statistics/organization/volume"
|
|
4001
|
-
});
|
|
3942
|
+
yield this.checkForUpdates();
|
|
4002
3943
|
});
|
|
4003
3944
|
}
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
* @example
|
|
4009
|
-
* ``` ts
|
|
4010
|
-
*
|
|
4011
|
-
* const insights = await client.getInsights();
|
|
4012
|
-
*
|
|
4013
|
-
* ```
|
|
4014
|
-
*
|
|
4015
|
-
* @returns {Types.TGetInsightsResponse} - The insights of the organization
|
|
4016
|
-
*/
|
|
4017
|
-
getInsights() {
|
|
4018
|
-
return __async(this, null, function* () {
|
|
4019
|
-
return yield this.httpRequest({
|
|
4020
|
-
path: "/api/v1/statistics/organization/insights"
|
|
4021
|
-
});
|
|
4022
|
-
});
|
|
3945
|
+
getCustomHeaders() {
|
|
3946
|
+
return {
|
|
3947
|
+
"x-sdk-version": _Oumla.CURRENT_VERSION
|
|
3948
|
+
};
|
|
4023
3949
|
}
|
|
4024
|
-
|
|
4025
|
-
*
|
|
4026
|
-
* Get the all the transactions or transactions for an address, wallet or reference
|
|
4027
|
-
*
|
|
4028
|
-
* By providing more than one option, only one will be used.
|
|
4029
|
-
*
|
|
4030
|
-
* @param {string} [args.address] - The address to get transactions for
|
|
4031
|
-
* @param {string} [args.wallet] - The wallet to get transactions for
|
|
4032
|
-
* @param {string} [args.reference] - The reference to get transactions for
|
|
4033
|
-
* @param {Types.TPagination} [pagination] - Pagination options
|
|
4034
|
-
*
|
|
4035
|
-
* @example
|
|
4036
|
-
* ``` ts
|
|
4037
|
-
*
|
|
4038
|
-
* const transactionsByAddress = await client.getTransactions({
|
|
4039
|
-
* address: 'ADDRESS',
|
|
4040
|
-
* });
|
|
4041
|
-
*
|
|
4042
|
-
* ```
|
|
4043
|
-
*
|
|
4044
|
-
* @returns {Types.TGetTransactionsResponse} - The transactions
|
|
4045
|
-
*
|
|
4046
|
-
*/
|
|
4047
|
-
getTransactions(args, pagination) {
|
|
3950
|
+
checkForUpdates() {
|
|
4048
3951
|
return __async(this, null, function* () {
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
pagination
|
|
4058
|
-
});
|
|
4059
|
-
} else if (args == null ? void 0 : args.reference) {
|
|
4060
|
-
return yield this.httpRequest({
|
|
4061
|
-
path: `/api/v1/transactions/profile/${args.reference}`,
|
|
4062
|
-
pagination
|
|
4063
|
-
});
|
|
4064
|
-
} else {
|
|
4065
|
-
return yield this.httpRequest({
|
|
4066
|
-
path: "/api/v1/transactions/organization",
|
|
4067
|
-
pagination
|
|
3952
|
+
const now = Date.now();
|
|
3953
|
+
if (now - this.lastUpdateCheck < this.UPDATE_CHECK_INTERVAL) {
|
|
3954
|
+
return;
|
|
3955
|
+
}
|
|
3956
|
+
try {
|
|
3957
|
+
const response = yield this.httpRequest({
|
|
3958
|
+
path: "/api/v1/sdk-version",
|
|
3959
|
+
method: "GET"
|
|
4068
3960
|
});
|
|
3961
|
+
if (response.latestVersion !== _Oumla.CURRENT_VERSION) {
|
|
3962
|
+
console.log(
|
|
3963
|
+
`A new version (${response.latestVersion}) of the Oumla SDK is available. Please update.`
|
|
3964
|
+
);
|
|
3965
|
+
}
|
|
3966
|
+
this.lastUpdateCheck = now;
|
|
3967
|
+
} catch (error) {
|
|
3968
|
+
console.error("Failed to check for updates:", error);
|
|
4069
3969
|
}
|
|
4070
3970
|
});
|
|
4071
3971
|
}
|
|
4072
|
-
/**
|
|
4073
|
-
* create transaction
|
|
4074
|
-
*
|
|
4075
|
-
* @param args.from - the address or addresses to transfer from
|
|
4076
|
-
* @param args.to - The desired address to transfer to
|
|
4077
|
-
* @param args.amount - The amount to transfer
|
|
4078
|
-
*
|
|
4079
|
-
* @example
|
|
4080
|
-
*
|
|
4081
|
-
* ``` ts
|
|
4082
|
-
*
|
|
4083
|
-
* const transfer = await client.transfer({
|
|
4084
|
-
* from: '0x...',
|
|
4085
|
-
* to: '0x...',
|
|
4086
|
-
* reference: '0x...',
|
|
4087
|
-
* amount: 100,
|
|
4088
|
-
* });
|
|
4089
|
-
*
|
|
4090
|
-
* ```
|
|
4091
|
-
*/
|
|
4092
|
-
createTransaction(args) {
|
|
4093
|
-
return __async(this, null, function* () {
|
|
4094
|
-
return yield this.httpRequest({
|
|
4095
|
-
method: "POST",
|
|
4096
|
-
path: "/api/v1/withdraw/address",
|
|
4097
|
-
body: args,
|
|
4098
|
-
schema: CreateTransactionSchema
|
|
4099
|
-
});
|
|
4100
|
-
});
|
|
4101
|
-
}
|
|
4102
3972
|
};
|
|
3973
|
+
var Oumla = _Oumla;
|
|
3974
|
+
Oumla.CURRENT_VERSION = "1.0.0";
|
|
4103
3975
|
|
|
4104
3976
|
// src/types.ts
|
|
4105
3977
|
var ProfileType = /* @__PURE__ */ ((ProfileType2) => {
|