@oumla/sdk 0.0.3 → 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/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
- * A generic method to make requests to the Oumla API.
67
- * Keep it simple for now, could be enhanced later.
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
- "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
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);
@@ -3745,7 +3743,7 @@ var z = /* @__PURE__ */ Object.freeze({
3745
3743
  });
3746
3744
 
3747
3745
  // src/schemas.ts
3748
- var NetworkSchema = z.enum(["BTC", "ETH"]);
3746
+ var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
3749
3747
  var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
3750
3748
  var GetWalletsSchema = z.object({
3751
3749
  reference: z.string()
@@ -3779,7 +3777,8 @@ var GetTransactionsSchema = z.object({
3779
3777
  }).partial();
3780
3778
  var GenerateAddressSchema = z.object({
3781
3779
  network: NetworkSchema,
3782
- reference: z.string()
3780
+ reference: z.string(),
3781
+ clientShare: z.string()
3783
3782
  });
3784
3783
  var GetAddressesSchema = z.object({
3785
3784
  baseUrl: z.string(),
@@ -3811,7 +3810,8 @@ var CreateTransactionSchema = z.object({
3811
3810
  to: z.string(),
3812
3811
  amount: z.number(),
3813
3812
  from: z.array(z.string()),
3814
- network: NetworkSchema
3813
+ network: NetworkSchema,
3814
+ clientShare: z.string()
3815
3815
  });
3816
3816
  var GetOrganizationSchema = z.object({
3817
3817
  baseUrl: z.string(),
@@ -3823,335 +3823,155 @@ var GetOrganizationDashboardSchema = z.object({
3823
3823
  });
3824
3824
 
3825
3825
  // src/client.ts
3826
- var Oumla = class extends Base {
3827
- constructor(configs) {
3828
- super(configs);
3829
- }
3830
- /**
3831
- *
3832
- * Generate a wallet for a profile
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
- });
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
3858
3833
  });
3859
- }
3860
- /**
3861
- *
3862
- * Get wallets for an organization
3863
- *
3864
- * @param {string} args.reference - The reference of the profile
3865
- * @param {Types.TPagination} [pagination] - Pagination options
3866
- *
3867
- * @example
3868
- * ``` ts
3869
- *
3870
- * const wallets = await client.getWallets({
3871
- * skip: 0,
3872
- * take: 3,
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}`,
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",
3885
3851
  pagination
3886
3852
  });
3887
- } else {
3888
- return yield this.httpRequest({
3889
- path: "/api/v1/wallets/organization",
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",
3890
3869
  pagination
3891
3870
  });
3892
- }
3893
- });
3894
- }
3895
- /**
3896
- *
3897
- * Generate an address for a profile
3898
- *
3899
- * @param {string} args.reference - The reference of the profile
3900
- * @param {string} args.network - The network to generate an address for
3901
- *
3902
- * @example
3903
- * ``` ts
3904
- *
3905
- * const address = await client.generateAddress({
3906
- * reference: 'PROFILE_REFERENCE',
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}`,
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",
3951
3886
  pagination
3952
3887
  });
3953
- } else {
3954
- return yield this.httpRequest({
3955
- path: "/api/v1/addresses/organization",
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",
3956
3931
  pagination
3957
3932
  });
3958
- }
3959
- });
3960
- }
3961
- /**
3962
- *
3963
- * Get the organization's information
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
- });
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();
4035
3939
  }
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() {
3940
+ initialize() {
4050
3941
  return __async(this, null, function* () {
4051
- return yield this.httpRequest({
4052
- path: "/api/v1/statistics/organization/volume"
4053
- });
3942
+ yield this.checkForUpdates();
4054
3943
  });
4055
3944
  }
4056
- /**
4057
- *
4058
- * Get the insights for an organization
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
- });
3945
+ getCustomHeaders() {
3946
+ return {
3947
+ "x-sdk-version": _Oumla.CURRENT_VERSION
3948
+ };
4075
3949
  }
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) {
3950
+ checkForUpdates() {
4100
3951
  return __async(this, null, function* () {
4101
- if (args == null ? void 0 : args.address) {
4102
- return yield this.httpRequest({
4103
- path: `/api/v1/transactions/address/${args.address}`,
4104
- pagination
4105
- });
4106
- } else if (args == null ? void 0 : args.wallet) {
4107
- return yield this.httpRequest({
4108
- path: `/api/v1/transactions/wallet/${args.wallet}`,
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
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"
4120
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);
4121
3969
  }
4122
3970
  });
4123
3971
  }
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
3972
  };
3973
+ var Oumla = _Oumla;
3974
+ Oumla.CURRENT_VERSION = "1.0.0";
4155
3975
 
4156
3976
  // src/types.ts
4157
3977
  var ProfileType = /* @__PURE__ */ ((ProfileType2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oumla/sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
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",