@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.js CHANGED
@@ -86,12 +86,10 @@ var Base = class {
86
86
  this.baseUrl = configs.baseUrl || "https://sandbox.oumla.com";
87
87
  this.env = configs.env || "testnet";
88
88
  }
89
- /**
90
- *
91
- * A generic method to make requests to the Oumla API.
92
- * Keep it simple for now, could be enhanced later.
93
- *
94
- */
89
+ // Add this method to get custom headers
90
+ getCustomHeaders() {
91
+ return {};
92
+ }
95
93
  httpRequest(args) {
96
94
  return __async(this, null, function* () {
97
95
  var _a;
@@ -100,13 +98,13 @@ var Base = class {
100
98
  }
101
99
  const paginationOpts = args.pagination ? `?skip=${args.pagination.skip || 0}&take=${args.pagination.take || 10}` : "";
102
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);
103
105
  const config = {
104
- headers: {
105
- "x-api-key": `Bearer ${this.apiKey}`,
106
- "Content-Type": "application/json"
107
- },
108
- method: args.method || void 0,
109
- // GET is the default in fetch
106
+ headers,
107
+ method: args.method || "GET",
110
108
  body: args.body ? JSON.stringify(args.body) : void 0
111
109
  };
112
110
  const res = yield fetch(URL2, config);
@@ -3770,7 +3768,7 @@ var z = /* @__PURE__ */ Object.freeze({
3770
3768
  });
3771
3769
 
3772
3770
  // src/schemas.ts
3773
- var NetworkSchema = z.enum(["BTC", "ETH"]);
3771
+ var NetworkSchema = z.enum(["BTC", "ETH", "tBTC", "tETH"]);
3774
3772
  var ProfileTypeSchema = z.enum(["User", "Department", "Merchant"]);
3775
3773
  var GetWalletsSchema = z.object({
3776
3774
  reference: z.string()
@@ -3804,7 +3802,8 @@ var GetTransactionsSchema = z.object({
3804
3802
  }).partial();
3805
3803
  var GenerateAddressSchema = z.object({
3806
3804
  network: NetworkSchema,
3807
- reference: z.string()
3805
+ reference: z.string(),
3806
+ clientShare: z.string()
3808
3807
  });
3809
3808
  var GetAddressesSchema = z.object({
3810
3809
  baseUrl: z.string(),
@@ -3836,7 +3835,8 @@ var CreateTransactionSchema = z.object({
3836
3835
  to: z.string(),
3837
3836
  amount: z.number(),
3838
3837
  from: z.array(z.string()),
3839
- network: NetworkSchema
3838
+ network: NetworkSchema,
3839
+ clientShare: z.string()
3840
3840
  });
3841
3841
  var GetOrganizationSchema = z.object({
3842
3842
  baseUrl: z.string(),
@@ -3848,335 +3848,155 @@ var GetOrganizationDashboardSchema = z.object({
3848
3848
  });
3849
3849
 
3850
3850
  // src/client.ts
3851
- var Oumla = class extends Base {
3852
- constructor(configs) {
3853
- super(configs);
3854
- }
3855
- /**
3856
- *
3857
- * Generate a wallet for a profile
3858
- *
3859
- * @param {string} args.reference - The reference of the profile
3860
- * @param {string} args.network - The network to generate a wallet for
3861
- *
3862
- * @example
3863
- * ``` ts
3864
- *
3865
- * const wallet = await client.generateWallet({
3866
- * reference: 'PROFILE_REFERENCE',
3867
- * network: 'BTC',
3868
- * });
3869
- *
3870
- * ```
3871
- *
3872
- * @returns {Types.TGenerateWalletResponse} - The generated wallet or an error
3873
- *
3874
- */
3875
- generateWallet(args) {
3876
- return __async(this, null, function* () {
3877
- return yield this.httpRequest({
3878
- method: "POST",
3879
- path: "/api/v1/wallets/generate",
3880
- body: args,
3881
- schema: GenerateWalletSchema
3882
- });
3851
+ var _Oumla = class extends Base {
3852
+ // 1 hour
3853
+ constructor(opts) {
3854
+ super({
3855
+ apiKey: opts.apiKey,
3856
+ baseUrl: opts.baseUrl,
3857
+ env: opts.env
3883
3858
  });
3884
- }
3885
- /**
3886
- *
3887
- * Get wallets for an organization
3888
- *
3889
- * @param {string} args.reference - The reference of the profile
3890
- * @param {Types.TPagination} [pagination] - Pagination options
3891
- *
3892
- * @example
3893
- * ``` ts
3894
- *
3895
- * const wallets = await client.getWallets({
3896
- * skip: 0,
3897
- * take: 3,
3898
- * });
3899
- *
3900
- * ```
3901
- *
3902
- * @returns {Types.TGetWalletsResponse} - The wallets for the organization
3903
- *
3904
- */
3905
- getWallets(args, pagination) {
3906
- return __async(this, null, function* () {
3907
- if (args == null ? void 0 : args.reference) {
3908
- return yield this.httpRequest({
3909
- path: `/api/v1/wallets/profile/${args.reference}`,
3859
+ // Update this with each release
3860
+ this.lastUpdateCheck = 0;
3861
+ this.UPDATE_CHECK_INTERVAL = 60 * 60 * 1e3;
3862
+ this.wallets = {
3863
+ generate: (args) => __async(this, null, function* () {
3864
+ return this.httpRequest({
3865
+ path: "/api/v1/wallets/generate",
3866
+ method: "POST",
3867
+ body: args,
3868
+ schema: GenerateWalletSchema
3869
+ });
3870
+ }),
3871
+ get: (args, pagination) => __async(this, null, function* () {
3872
+ const path = (args == null ? void 0 : args.reference) ? `/api/v1/wallets/profile/${args.reference}` : "/api/v1/wallets/organization";
3873
+ return this.httpRequest({
3874
+ path,
3875
+ method: "GET",
3910
3876
  pagination
3911
3877
  });
3912
- } else {
3913
- return yield this.httpRequest({
3914
- path: "/api/v1/wallets/organization",
3878
+ })
3879
+ };
3880
+ this.addresses = {
3881
+ generate: (args) => __async(this, null, function* () {
3882
+ return this.httpRequest({
3883
+ path: "/api/v1/address/generate",
3884
+ method: "POST",
3885
+ body: args,
3886
+ schema: GenerateAddressSchema
3887
+ });
3888
+ }),
3889
+ get: (args, pagination) => __async(this, null, function* () {
3890
+ const path = (args == null ? void 0 : args.reference) ? `/api/v1/addresses/${args.reference}` : "/api/v1/addresses/organization";
3891
+ return this.httpRequest({
3892
+ path,
3893
+ method: "GET",
3915
3894
  pagination
3916
3895
  });
3917
- }
3918
- });
3919
- }
3920
- /**
3921
- *
3922
- * Generate an address for a profile
3923
- *
3924
- * @param {string} args.reference - The reference of the profile
3925
- * @param {string} args.network - The network to generate an address for
3926
- *
3927
- * @example
3928
- * ``` ts
3929
- *
3930
- * const address = await client.generateAddress({
3931
- * reference: 'PROFILE_REFERENCE',
3932
- * network: 'BTC',
3933
- * });
3934
- *
3935
- * ```
3936
- *
3937
- * @returns {Types.TGenerateAddressResponse} - The generated address
3938
- */
3939
- generateAddress(args) {
3940
- return __async(this, null, function* () {
3941
- return yield this.httpRequest({
3942
- method: "POST",
3943
- path: "/api/v1/address/generate",
3944
- body: args,
3945
- schema: GenerateAddressSchema
3946
- });
3947
- });
3948
- }
3949
- /**
3950
- *
3951
- * Get addresses
3952
- *
3953
- * @param {string} args.reference - The reference of the profile, Optional
3954
- * @param {Types.TPagination} [pagination] - Pagination options
3955
- * @example
3956
- * ``` ts
3957
- *
3958
- * const addresses = await client.getAddresses({
3959
- * reference: 'PROFILE_REFERENCE',
3960
- * },
3961
- * {
3962
- * skip: 0,
3963
- * take: 3,
3964
- * }
3965
- * );
3966
- *
3967
- * ```
3968
- *
3969
- * @returns {Types.TGetProfileAddressesResponse} - The addresses for the profile
3970
- */
3971
- getAddresses(args, pagination) {
3972
- return __async(this, null, function* () {
3973
- if (args == null ? void 0 : args.reference) {
3974
- return yield this.httpRequest({
3975
- path: `/api/v1/addresses/${args.reference}`,
3896
+ })
3897
+ };
3898
+ this.profiles = {
3899
+ create: (args) => __async(this, null, function* () {
3900
+ return this.httpRequest({
3901
+ path: "/api/v1/profiles",
3902
+ method: "POST",
3903
+ body: args,
3904
+ schema: CreateProfileSchema
3905
+ });
3906
+ }),
3907
+ get: (pagination) => __async(this, null, function* () {
3908
+ return this.httpRequest({
3909
+ path: "/api/v1/profiles",
3910
+ method: "GET",
3976
3911
  pagination
3977
3912
  });
3978
- } else {
3979
- return yield this.httpRequest({
3980
- path: "/api/v1/addresses/organization",
3913
+ })
3914
+ };
3915
+ this.organization = {
3916
+ get: () => __async(this, null, function* () {
3917
+ return this.httpRequest({
3918
+ path: "/api/v1/organizations",
3919
+ method: "GET"
3920
+ });
3921
+ }),
3922
+ volume: () => __async(this, null, function* () {
3923
+ return this.httpRequest({
3924
+ path: "/api/v1/statistics/organization/volume",
3925
+ method: "GET"
3926
+ });
3927
+ }),
3928
+ insights: () => __async(this, null, function* () {
3929
+ return this.httpRequest({
3930
+ path: "/api/v1/statistics/organization/insights",
3931
+ method: "GET"
3932
+ });
3933
+ })
3934
+ };
3935
+ this.transactions = {
3936
+ create: (args) => __async(this, null, function* () {
3937
+ return this.httpRequest({
3938
+ path: "/api/v1/withdraw/address",
3939
+ method: "POST",
3940
+ body: args,
3941
+ schema: CreateTransactionSchema
3942
+ });
3943
+ }),
3944
+ get: (args, pagination) => __async(this, null, function* () {
3945
+ let path = "/api/v1/transactions/organization";
3946
+ if (args == null ? void 0 : args.address) {
3947
+ path = `/api/v1/transactions/address/${args.address}`;
3948
+ } else if (args == null ? void 0 : args.wallet) {
3949
+ path = `/api/v1/transactions/wallet/${args.wallet}`;
3950
+ } else if (args == null ? void 0 : args.reference) {
3951
+ path = `/api/v1/transactions/profile/${args.reference}`;
3952
+ }
3953
+ return this.httpRequest({
3954
+ path,
3955
+ method: "GET",
3981
3956
  pagination
3982
3957
  });
3983
- }
3984
- });
3985
- }
3986
- /**
3987
- *
3988
- * Get the organization's information
3989
- *
3990
- * @example
3991
- * ``` ts
3992
- *
3993
- * const organization = await client.getOrganization();
3994
- *
3995
- * ```
3996
- *
3997
- * @returns {Types.TGetOrganizationResponse} - The organization's information
3998
- */
3999
- getOrganization() {
4000
- return __async(this, null, function* () {
4001
- return yield this.httpRequest({
4002
- path: "/api/v1/organizations"
4003
- });
4004
- });
4005
- }
4006
- /**
4007
- *
4008
- * Create a profile
4009
- *
4010
- * @param {string} args.reference - The reference of the profile
4011
- * @param {Types.TCreateProfileArgs['type']} args.type - The type of the profile
4012
- *
4013
- * @example
4014
- * ``` ts
4015
- *
4016
- * const profile = await client.createProfile({
4017
- * reference: 'PROFILE_REFERENCE',
4018
- * type: 'User',
4019
- * });
4020
- *
4021
- * ```
4022
- *
4023
- * @returns {Types.TCreateProfileResponse} - The created profile
4024
- */
4025
- createProfile(args) {
4026
- return __async(this, null, function* () {
4027
- return yield this.httpRequest({
4028
- method: "POST",
4029
- path: "/api/v1/profiles",
4030
- body: args,
4031
- schema: CreateProfileSchema
4032
- });
4033
- });
4034
- }
4035
- /**
4036
- *
4037
- * Get the profiles for an organization
4038
- *
4039
- * @param {Types.TPagination} [pagination] - Pagination options
4040
- *
4041
- * @example
4042
- * ``` ts
4043
- *
4044
- * const profiles = await client.getProfiles({
4045
- * skip: 0,
4046
- * take: 3,
4047
- * });
4048
- *
4049
- * ```
4050
- *
4051
- * @returns {Types.TGetProfilesResponse} - The profiles for the organization
4052
- */
4053
- getProfiles(pagination) {
4054
- return __async(this, null, function* () {
4055
- return yield this.httpRequest({
4056
- path: "/api/v1/profiles",
4057
- pagination
4058
- });
4059
- });
3958
+ })
3959
+ };
3960
+ this.apiKey = opts.apiKey;
3961
+ this.baseUrl = opts.baseUrl || "https://api.oumla.com";
3962
+ this.env = opts.env || "testnet";
3963
+ this.initialize();
4060
3964
  }
4061
- /**
4062
- *
4063
- * Get the volume for an organization
4064
- *
4065
- * @example
4066
- * ``` ts
4067
- *
4068
- * const volume = await client.getVolume();
4069
- *
4070
- * ```
4071
- *
4072
- * @returns {Types.TGetVolumeResponse} - The volume of the organization
4073
- */
4074
- getVolume() {
3965
+ initialize() {
4075
3966
  return __async(this, null, function* () {
4076
- return yield this.httpRequest({
4077
- path: "/api/v1/statistics/organization/volume"
4078
- });
3967
+ yield this.checkForUpdates();
4079
3968
  });
4080
3969
  }
4081
- /**
4082
- *
4083
- * Get the insights for an organization
4084
- *
4085
- * @example
4086
- * ``` ts
4087
- *
4088
- * const insights = await client.getInsights();
4089
- *
4090
- * ```
4091
- *
4092
- * @returns {Types.TGetInsightsResponse} - The insights of the organization
4093
- */
4094
- getInsights() {
4095
- return __async(this, null, function* () {
4096
- return yield this.httpRequest({
4097
- path: "/api/v1/statistics/organization/insights"
4098
- });
4099
- });
3970
+ getCustomHeaders() {
3971
+ return {
3972
+ "x-sdk-version": _Oumla.CURRENT_VERSION
3973
+ };
4100
3974
  }
4101
- /**
4102
- *
4103
- * Get the all the transactions or transactions for an address, wallet or reference
4104
- *
4105
- * By providing more than one option, only one will be used.
4106
- *
4107
- * @param {string} [args.address] - The address to get transactions for
4108
- * @param {string} [args.wallet] - The wallet to get transactions for
4109
- * @param {string} [args.reference] - The reference to get transactions for
4110
- * @param {Types.TPagination} [pagination] - Pagination options
4111
- *
4112
- * @example
4113
- * ``` ts
4114
- *
4115
- * const transactionsByAddress = await client.getTransactions({
4116
- * address: 'ADDRESS',
4117
- * });
4118
- *
4119
- * ```
4120
- *
4121
- * @returns {Types.TGetTransactionsResponse} - The transactions
4122
- *
4123
- */
4124
- getTransactions(args, pagination) {
3975
+ checkForUpdates() {
4125
3976
  return __async(this, null, function* () {
4126
- if (args == null ? void 0 : args.address) {
4127
- return yield this.httpRequest({
4128
- path: `/api/v1/transactions/address/${args.address}`,
4129
- pagination
4130
- });
4131
- } else if (args == null ? void 0 : args.wallet) {
4132
- return yield this.httpRequest({
4133
- path: `/api/v1/transactions/wallet/${args.wallet}`,
4134
- pagination
4135
- });
4136
- } else if (args == null ? void 0 : args.reference) {
4137
- return yield this.httpRequest({
4138
- path: `/api/v1/transactions/profile/${args.reference}`,
4139
- pagination
4140
- });
4141
- } else {
4142
- return yield this.httpRequest({
4143
- path: "/api/v1/transactions/organization",
4144
- pagination
3977
+ const now = Date.now();
3978
+ if (now - this.lastUpdateCheck < this.UPDATE_CHECK_INTERVAL) {
3979
+ return;
3980
+ }
3981
+ try {
3982
+ const response = yield this.httpRequest({
3983
+ path: "/api/v1/sdk-version",
3984
+ method: "GET"
4145
3985
  });
3986
+ if (response.latestVersion !== _Oumla.CURRENT_VERSION) {
3987
+ console.log(
3988
+ `A new version (${response.latestVersion}) of the Oumla SDK is available. Please update.`
3989
+ );
3990
+ }
3991
+ this.lastUpdateCheck = now;
3992
+ } catch (error) {
3993
+ console.error("Failed to check for updates:", error);
4146
3994
  }
4147
3995
  });
4148
3996
  }
4149
- /**
4150
- * create transaction
4151
- *
4152
- * @param args.from - the address or addresses to transfer from
4153
- * @param args.to - The desired address to transfer to
4154
- * @param args.amount - The amount to transfer
4155
- *
4156
- * @example
4157
- *
4158
- * ``` ts
4159
- *
4160
- * const transfer = await client.transfer({
4161
- * from: '0x...',
4162
- * to: '0x...',
4163
- * reference: '0x...',
4164
- * amount: 100,
4165
- * });
4166
- *
4167
- * ```
4168
- */
4169
- createTransaction(args) {
4170
- return __async(this, null, function* () {
4171
- return yield this.httpRequest({
4172
- method: "POST",
4173
- path: "/api/v1/withdraw/address",
4174
- body: args,
4175
- schema: CreateTransactionSchema
4176
- });
4177
- });
4178
- }
4179
3997
  };
3998
+ var Oumla = _Oumla;
3999
+ Oumla.CURRENT_VERSION = "1.0.0";
4180
4000
 
4181
4001
  // src/types.ts
4182
4002
  var ProfileType = /* @__PURE__ */ ((ProfileType2) => {